Browse Source

some style fixes

pull/168/head
William Panting 12 years ago
parent
commit
961d5d5f04
  1. 61
      api/fedora_utils.inc

61
api/fedora_utils.inc

@ -1,23 +1,23 @@
<?php <?php
/** /**
* @file * @file
* Base utilities used by the Islandora fedora module. * Base utilities used by the Islandora fedora module.
*/ */
if (!function_exists('str_getcsv')) { if (!function_exists('str_getcsv')) {
/** /**
* Functions that emulate php5.3 functionality for backwards compatiablity * Functions that emulate php5.3 functionality for backwards compatiablity
*
* @param type $input * @param type $input
* @param type $delimiter * @param type $delimiter
* @param type $enclosure * @param type $enclosure
* @param type $escape * @param type $escape
* @param type $eol * @param type $eol
*
* @return type * @return type
*/ */
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=NULL, $eol=NULL) { function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = NULL, $eol = NULL) {
$temp = fopen("php://memory", "rw"); $temp = fopen("php://memory", "rw");
fwrite($temp, $input); fwrite($temp, $input);
fseek($temp, 0); fseek($temp, 0);
@ -50,7 +50,7 @@ if (!function_exists('str_getcsv')) {
* @param $post * @param $post
* Whether the curl_exec is done as a "get" or a "post" * Whether the curl_exec is done as a "get" or a "post"
* *
* @return * @return mixed
* TRUE, FALSE, NULL, or the data returned from accessing the URL * TRUE, FALSE, NULL, or the data returned from accessing the URL
*/ */
function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) { function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
@ -59,7 +59,6 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
} }
/** /**
*
* Utility method to get data from a url location using curl_exec * Utility method to get data from a url location using curl_exec
* *
* This method takes a URL and three associated parameters and initializes the * This method takes a URL and three associated parameters and initializes the
@ -112,11 +111,15 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)"; $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors // Fail on errors.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s // Allow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// Times out after 90s.
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable // Return into a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable);
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass"); curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
@ -141,7 +144,8 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
/** /**
* Fedora available * Fedora available
* @return type *
* @return mixed
*/ */
function fedora_available() { function fedora_available() {
@ -151,7 +155,8 @@ function fedora_available() {
/** /**
* Resource index search available * Resource index search available
* @return type *
* @return mixed
*/ */
function risearch_available() { function risearch_available() {
@ -161,7 +166,9 @@ function risearch_available() {
/** /**
* Returns a UTF-8-encoded transcripiton of the string given in $in_str. * Returns a UTF-8-encoded transcripiton of the string given in $in_str.
*
* @param string $in_str * @param string $in_str
*
* @return string A UTF-8 encoded string. * @return string A UTF-8 encoded string.
*/ */
function fix_encoding($in_str) { function fix_encoding($in_str) {
@ -176,7 +183,9 @@ function fix_encoding($in_str) {
/** /**
* valid pid ?? * valid pid ??
*
* @param type $pid * @param type $pid
*
* @return boolean * @return boolean
*/ */
function valid_pid($pid) { function valid_pid($pid) {
@ -190,7 +199,9 @@ function valid_pid($pid) {
/** /**
* Valid Dsid ?? * Valid Dsid ??
*
* @param type $dsid * @param type $dsid
*
* @return boolean * @return boolean
*/ */
function valid_dsid($dsid) { function valid_dsid($dsid) {
@ -204,7 +215,9 @@ function valid_dsid($dsid) {
/** /**
* fixDsid ?? * fixDsid ??
*
* @param type $dsid * @param type $dsid
*
* @return string * @return string
*/ */
function fix_dsid($dsid) { function fix_dsid($dsid) {
@ -214,14 +227,17 @@ function fix_dsid($dsid) {
$replace = ''; $replace = '';
$new_dsid = preg_replace($find, $replace, $new_dsid); $new_dsid = preg_replace($find, $replace, $new_dsid);
if (strlen($new_dsid) > 63) if (strlen($new_dsid) > 63) {
$new_dsid = substr($new_dsid, -63); $new_dsid = substr($new_dsid, -63);
}
if (preg_match('/^[^a-zA-Z]/', $dsid)) if (preg_match('/^[^a-zA-Z]/', $dsid)) {
$new_dsid = 'x' . $new_dsid; $new_dsid = 'x' . $new_dsid;
}
if (strlen($new_dsid) == 0) if (strlen($new_dsid) == 0) {
$new_dsid = 'item' . rand(1, 100); $new_dsid = 'item' . rand(1, 100);
}
return $new_dsid; return $new_dsid;
} }
@ -229,9 +245,8 @@ function fix_dsid($dsid) {
/** /**
* Function: get_collections_as_option_array * Function: get_collections_as_option_array
* *
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array * @return array
* Returns an associative array of all collection objects in Fedora instance
*/ */
function get_collections_as_option_array() { function get_collections_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -254,7 +269,7 @@ function get_collections_as_option_array() {
'stream' => 'on', 'stream' => 'on',
'query' => $query, 'query' => $query,
); );
//The url function will take care of URL encoding... // The url function will take care of URL encoding.
$content = do_curl(url($url, array('query' => $options))); $content = do_curl(url($url, array('query' => $options)));
$list = explode("\n", $content); $list = explode("\n", $content);
@ -264,7 +279,8 @@ function get_collections_as_option_array() {
$trimmed_names[] = trim($namespace); $trimmed_names[] = trim($namespace);
} }
$options = array(); $options = array();
foreach ($list as $item) { //removes blanks // Removes blanks.
foreach ($list as $item) {
if ($item) { if ($item) {
$parts = explode(',', $item); $parts = explode(',', $item);
$namespace = explode(':', $parts[0]); $namespace = explode(':', $parts[0]);
@ -283,9 +299,8 @@ function get_collections_as_option_array() {
/** /**
* Function: get_content_models_as_option_array * Function: get_content_models_as_option_array
* *
* Description: Returns an associative array of all available content models in Fedora instance
*
* @return array * @return array
* associative array of all available content models in Fedora instance
*/ */
function get_content_models_as_option_array() { function get_content_models_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -311,12 +326,12 @@ function get_content_models_as_option_array() {
$list = explode("\n", $content); $list = explode("\n", $content);
array_shift($list); array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list); $list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks // Removes blanks.
foreach ($list as $item) {
if ($item) { if ($item) {
$parts = explode(',', $item); $parts = explode(',', $item);
$nameparts = explode(':', $parts[0]); $nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed)) { if (!$restricted || in_array($nameparts[0], $allowed)) {
if (!preg_match('/fedora-system/', $nameparts[0])) { if (!preg_match('/fedora-system/', $nameparts[0])) {
$options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0]; $options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0];
} }

Loading…
Cancel
Save