From 2b20e2e6321078da38ff8de01e0f16f6191e9ce0 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 12:48:48 -0300 Subject: [PATCH 1/6] some code style fixes --- MimeClass.inc | 114 +++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/MimeClass.inc b/MimeClass.inc index 97825c41..e0ba5750 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -6,26 +6,27 @@ * @file * This class inspired by Chris Jean's work, here: * http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/ - * - * It does some MIME trickery, inspired by the need to to deal with Openoffice - * and MS Office 2007 file formats -- which are often mis-interpreted by + * + * It does some MIME trickery, inspired by the need to to deal with Openoffice + * and MS Office 2007 file formats -- which are often mis-interpreted by * mime-magic, fileinfo, and the *nix `file` command. * - * In Drupal 6, we also make use of file_get_mimetype. See: + * In Drupal 6, we also make use of file_get_mimetype. See: * http://api.drupal.org/api/function/file_get_mimetype/6 * ... however this only provides a uni-directional lookup (ext->mime). * While I don't have a specific use case for a mime->extension lookup, I think * it's good to have in here. - * + * * Drupal 7 will have better mime handlers. See: * http://api.drupal.org/api/function/file_default_mimetype_mapping/7 * */ + class MimeClass { private $private_mime_types = array( - /** - * This is a shortlist of mimetypes which should catch most + /* + * This is a shortlist of mimetypes which should catch most * mimetype<-->extension lookups in the context of Islandora collections. * * It has been cut from a much longer list. @@ -33,26 +34,26 @@ class MimeClass { * Two types of mimetypes should be put in this list: * 1) Special emerging formats which may not yet be expressed in the system * mime.types file. - * 2) Heavily used mimetypes of particular importance to the Islandora - * project, as lookups against this list will be quicker and less + * 2) Heavily used mimetypes of particular importance to the Islandora + * project, as lookups against this list will be quicker and less * resource intensive than other methods. * - * Lookups are first checked against this short list. If no results are found, - * then the lookup function may move on to check other sources, namely the - * system's mime.types file. + * Lookups are first checked against this short list. + * If no results are found, then the lookup function may move + * on to check other sources, namely the system's mime.types file. * * In most cases though, this short list should suffice. - * + * * If modifying this list, please note that for promiscuous mimetypes * (those which map to multiple extensions, such as text/plain) - * The function get_extension will always return the *LAST* extension in this list, - * so you should put your preferred extension *LAST*. + * The function get_extension will always return the *LAST* extension + * in this list, so you should put your preferred extension *LAST*. * - * e.g... + * e.g... * "jpeg" => "image/jpeg", * "jpe" => "image/jpeg", * "jpg" => "image/jpeg", - * + * * $this->get_extension('image/jpeg') will always return 'jpg'. * */ @@ -89,7 +90,7 @@ class MimeClass { 'ksp' => 'application/x-kspread', 'kwt' => 'application/x-kword', 'kwd' => 'application/x-kword', - // ms office 97: + // MS office 97: 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', @@ -113,9 +114,9 @@ class MimeClass { 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', - // wordperfect (who cares?): + // Wordperfect (who cares?): 'wpd' => 'application/wordperfect', - // common and generic containers: + // Common and generic containers: 'pdf' => 'application/pdf', 'eps' => 'application/postscript', 'ps' => 'application/postscript', @@ -185,13 +186,14 @@ class MimeClass { "ogg" => "audio/ogg", "flac" => "audio/x-flac", "wav" => "audio/vnd.wave", - // compressed formats: (note: http://svn.cleancode.org/svn/email/trunk/mime.types) + /* Compressed formats: + (note: http://svn.cleancode.org/svn/email/trunk/mime.types).*/ "tgz" => "application/x-gzip", "gz" => "application/x-gzip", "tar" => "application/x-tar", "gtar" => "application/x-gtar", "zip" => "application/x-zip", - // others: + // others: 'bin' => 'application/octet-stream', ); private $private_file_extensions; @@ -204,10 +206,10 @@ class MimeClass { */ public function __construct() { - // populate the reverse shortlist: + // Populate the reverse shortlist: $this->private_file_extensions = array_flip($this->private_mime_types); - // pick up a local mime.types file if it is available + // Pick up a local mime.types file if it is available. if (is_readable('mime.types')) { $this->etc_mime_types = 'mime.types'; } @@ -219,7 +221,7 @@ class MimeClass { * for backwards-compatibility with our old mimetype class. * * @param type $filename - * @return type + * @return type */ public function getType($filename) { return $this->get_mimetype($filename); @@ -227,40 +229,47 @@ class MimeClass { /** * function: get_mimetype - * description: returns a mimetype associated with the file extension of $filename + * description: returns a mimetype associated with the + * file extension of $filename * * @param type $filename * @param type $debug - * @return type + * @return string + * mimetype associated with the file extension of $filename */ public function get_mimetype($filename, $debug = FALSE) { $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if (!empty($this->private_mime_types[$ext])) { - if (TRUE === $debug) + if (TRUE === $debug) { return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array'); + } return $this->private_mime_types[$ext]; } if (function_exists('file_get_mimetype')) { $drupal_mimetype = file_get_mimetype($filename); if ('application/octet-stream' != $drupal_mimetype) { - if (TRUE == $debug) + if (TRUE == $debug) { return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype'); + } return $drupal_mimetype; } } - if (!isset($this->system_types)) + if (!isset($this->system_types)) { $this->system_types = $this->system_extension_mime_types(); + } if (isset($this->system_types[$ext])) { - if (TRUE == $debug) + if (TRUE == $debug) { return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types'); + } return $this->system_types[$ext]; } - if (TRUE === $debug) + if (TRUE === $debug) { return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort'); + } return 'application/octet-stream'; } @@ -270,34 +279,38 @@ class MimeClass { * * @param type $mime_type * @param type $debug - * @return type + * @return type */ public function get_extension($mime_type, $debug = FALSE) { if (!empty($this->private_file_extensions[$mime_type])) { - if (TRUE == $debug) + if (TRUE == $debug) { return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array'); + } return $this->private_file_extensions[$mime_type]; } - if (!isset($this->system_exts)) + if (!isset($this->system_exts)) { $this->system_exts = $this->system_mime_type_extensions(); + } if (isset($this->system_exts[$mime_type])) { - if (TRUE == $debug) + if (TRUE == $debug) { return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types'); + } return $this->system_exts[$mime_type]; } - if (TRUE == $debug) + if (TRUE == $debug) { return array('extension' => 'bin', 'method' => 'last_resort'); + } return 'bin'; } /** * function: system_mime_type_extensions * description: populates an internal array of mimetype/extension associations - * from the system mime.types file, or a local mime.types if one is found (see - * __constuctor). + * from the system mime.types file, or a local mime.types if one is found (see + * __constuctor). * return: array of mimetype => extension */ private function system_mime_type_extensions() { @@ -306,15 +319,18 @@ class MimeClass { $file = fopen($this->etc_mime_types, 'r'); while (($line = fgets($file)) !== FALSE) { $line = trim(preg_replace('/#.*/', '', $line)); - if (!$line) + if (!$line) { continue; + } $parts = preg_split('/\s+/', $line); - if (count($parts) == 1) + if (count($parts) == 1) { continue; + } // A single part means a mimetype without extensions, which we ignore. $type = array_shift($parts); - if (!isset($out[$type])) + if (!isset($out[$type])) { $out[$type] = array_shift($parts); + } // We take the first ext from the line if many are present. } fclose($file); @@ -325,8 +341,8 @@ class MimeClass { /** * function: system_mime_type_extensions * description: populates an internal array of mimetype/extension associations - * from the system mime.types file, or a local mime.types if one is found (see - * __constuctor). + * from the system mime.types file, or a local mime.types if one is found (see + * __constuctor). * return: array of extension => mimetype */ private function system_extension_mime_types() { @@ -335,15 +351,18 @@ class MimeClass { $file = fopen($this->etc_mime_types, 'r'); while (($line = fgets($file)) !== FALSE) { $line = trim(preg_replace('/#.*/', '', $line)); - if (!$line) + if (!$line) { continue; + } $parts = preg_split('/\s+/', $line); - if (count($parts) == 1) + if (count($parts) == 1) { continue; + } // A single part means a mimetype without extensions, which we ignore. $type = array_shift($parts); - foreach ($parts as $part) + foreach ($parts as $part) { $out[$part] = $type; + } } fclose($file); } @@ -351,4 +370,3 @@ class MimeClass { } } - From 9c6a70a0f653ec40c920bf29e3ef8e09863f31c6 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 12:51:28 -0300 Subject: [PATCH 2/6] ISLANDORA-587 added json mime/extension mapping --- MimeClass.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MimeClass.inc b/MimeClass.inc index e0ba5750..d01cd9f8 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -195,7 +195,9 @@ class MimeClass { "zip" => "application/x-zip", // others: 'bin' => 'application/octet-stream', + 'json' => 'application/json', ); + private $private_file_extensions; private $system_types; private $system_exts; From 961d5d5f0402aa78b1a7e4d6b7018f2075b36195 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 14:03:19 -0300 Subject: [PATCH 3/6] some style fixes --- api/fedora_utils.inc | 153 ++++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 69 deletions(-) diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index a730d7a4..a2eaf55c 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -1,23 +1,23 @@ 63) + if (strlen($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; + } - if (strlen($new_dsid) == 0) + if (strlen($new_dsid) == 0) { $new_dsid = 'item' . rand(1, 100); + } return $new_dsid; } @@ -229,9 +245,8 @@ function fix_dsid($dsid) { /** * Function: get_collections_as_option_array * - * Description: Returns an associative array of all collection objects in Fedora instance - * * @return array + * Returns an associative array of all collection objects in Fedora instance */ function get_collections_as_option_array() { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -244,7 +259,7 @@ function get_collections_as_option_array() { and $object ) order by $title'; $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - + $options = array( 'type' => 'tuples', 'flush' => 'TRUE', @@ -254,9 +269,9 @@ function get_collections_as_option_array() { 'stream' => 'on', '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))); - + $list = explode("\n", $content); array_shift($list); $list = preg_replace('/info:fedora\//', '', $list); @@ -264,7 +279,8 @@ function get_collections_as_option_array() { $trimmed_names[] = trim($namespace); } $options = array(); - foreach ($list as $item) { //removes blanks + // Removes blanks. + foreach ($list as $item) { if ($item) { $parts = explode(',', $item); $namespace = explode(':', $parts[0]); @@ -283,46 +299,45 @@ function get_collections_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 + * associative array of all available content models in Fedora instance */ function get_content_models_as_option_array() { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); - $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); - $namespaces = explode(':', $allowed_string); - foreach ($namespaces as $namespace) { - if ($namespace) { - $allowed[] = trim($namespace); - } + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); + $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); + $namespaces = explode(':', $allowed_string); + foreach ($namespaces as $namespace) { + if ($namespace) { + $allowed[] = trim($namespace); } - $query = 'select $object $title from <#ri> - where ($object $title - and ($object - or $object ) - and $object ) - order by $title'; - - $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query="; - $content = do_curl($url . htmlentities(urlencode($query))); - $list = explode("\n", $content); - array_shift($list); - $list = preg_replace('/info:fedora\//', '', $list); - foreach ($list as $item) { //removes blanks - if ($item) { - $parts = explode(',', $item); - $nameparts = explode(':', $parts[0]); - if (!$restricted || in_array($nameparts[0], $allowed)) { + } + $query = 'select $object $title from <#ri> + where ($object $title + and ($object + or $object ) + and $object ) + order by $title'; - if (!preg_match('/fedora-system/', $nameparts[0])) { - $options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0]; - } - } + $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); + $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query="; + $content = do_curl($url . htmlentities(urlencode($query))); + $list = explode("\n", $content); + array_shift($list); + $list = preg_replace('/info:fedora\//', '', $list); + // Removes blanks. + foreach ($list as $item) { + if ($item) { + $parts = explode(',', $item); + $nameparts = explode(':', $parts[0]); + if (!$restricted || in_array($nameparts[0], $allowed)) { + if (!preg_match('/fedora-system/', $nameparts[0])) { + $options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0]; } + } } + } - return $options; -} \ No newline at end of file + return $options; +} From cc1608d8bf74a16fb1bdc07c25a66e17de51fada Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 14:28:27 -0300 Subject: [PATCH 4/6] islandora-624 created get_parent_collections_from_pid --- api/fedora_utils.inc | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index a2eaf55c..dbf28b81 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -69,7 +69,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * Various defaults are used for the parameters required by curl_exec including * the user agent and timeout. These are hard-coded. * - * @param $url + * @param string $url * URL to be accessed by the function * @param $return_to_variable * Indicates whether the resource accessed by the curl call (HTML page, @@ -80,7 +80,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * @param $post * Whether the curl_exec is done as a "get" or a "post" * - * @return + * @return mixed * an array that consists of three value or NULL if curl is not suported: * - element 0: * The value returned from the curl_exec function call. @@ -341,3 +341,33 @@ function get_content_models_as_option_array() { return $options; } + +/** + * This function will retrieve the collections that the given PID belongs to. + * + * @param string $PID + * The PID to find the parents of. + * + * @return array + * $object_PIDs the list of PIDs of the collections that the + * indicated object is a member of. + */ +function get_parent_collections_from_pid($PID) { + $query_string = 'select $parent from <#ri> + where ($object $parent + or $object $parent) + and $object \'' . $PID . '\' + order by $object'; + + $query_string = htmlentities(urlencode($query_string)); + $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); + $url .= '?type=tuples&flush=true&format=csv&limit=13000&lang=itql&stream=on&query=' . $query_string; + + $content = do_curl($url, TRUE); + + $results = explode("\n", $content); + $object_PIDs = preg_replace('/^info:fedora\/|"parent"| /', '', $results); + $object_PIDs = array_values(array_filter($object_PIDs)); + + return $object_PIDs; +} From ddfda6a5a895a18146751de171b40b6d7d0e9953 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 15:23:56 -0300 Subject: [PATCH 5/6] some code style fixes --- fedora_repository.module | 310 ++++++++++++++++++++++----------------- 1 file changed, 176 insertions(+), 134 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 1ad76e6e..1b2797e5 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -27,7 +27,7 @@ function fedora_repository_menu() { * * @param type $path * @param type $arg - * @return type + * @return type */ function fedora_repository_help($path, $arg) { switch ($path) { @@ -40,9 +40,11 @@ function fedora_repository_help($path, $arg) { /** * fedora repository purge object + * * @param type $pid * @param type $name - * @return type + * + * @return type */ function fedora_repository_purge_object($pid = NULL, $name = NULL) { if (!user_access('purge objects and datastreams')) { @@ -64,10 +66,12 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) { /** * fedora repository ingest object + * * @param type $collection_pid * @param type $collection_label * @param type $content_model - * @return type + * + * @return type */ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label = NULL, $content_model = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -106,7 +110,7 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label * @global type $base_url * @global type $user * @param array $form - * @param array $form_state + * @param array $form_state */ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { //only validate the form if the submit button was pressed (other buttons may be used for AHAH @@ -163,7 +167,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { * fedora repository ingest form validate * @param type $form * @param type $form_state - * @return type + * @return type */ function fedora_repository_ingest_form_validate($form, &$form_state) { //only validate the form if the submit button was pressed (other buttons may be used for AHAH @@ -220,7 +224,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { if (!empty($file)) { if (!in_array($dformat, $allowedMimeTypes)) { - form_set_error($ifl, + form_set_error($ifl, t('The uploaded file\'s mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed', array( '@mime' => $dformat, '@allowed' => implode(', ', $allowedMimeTypes), @@ -249,7 +253,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { * @param type $collection_pid * @param type $collection_label * @param type $content_model - * @return type + * @return type */ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collection_label = NULL, $content_model = NULL) { module_load_include('inc', 'fedora_repository', 'formClass'); @@ -266,11 +270,15 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio /** * fedora repository purge object form + * * @global type $base_url + * * @param type $form_state * @param type $pid * @param type $referrer - * @return type + * + * @return mixed + * NULL or the form array. */ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) { global $base_url; @@ -282,7 +290,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL } $form['pid'] = array( '#type' => 'hidden', - '#value' => "$pid" + '#value' => "$pid", ); if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) { $form['referrer'] = array( @@ -291,9 +299,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL ); } if (!isset($form_state['storage']['confirm'])) { -// do your normal $form definition here - - + // Do your normal $form definition here. $form['submit'] = array( '#type' => 'image_button', '#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png', @@ -303,15 +309,19 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL if (!empty($collectionPid)) { $collectionPid = $_SESSION['fedora_collection']; } -//$form['#rebuild'] = $false; return $form; } else { -// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form + /* ALSO do $form definition here. Your final submit handler + * (after user clicks Yes, I Confirm) + * will only see $form_state info defined here. + * Form you create here passed as param1 to confirm_form*/ - return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); //Had better luck leaving off last param 'name' + // Had better luck leaving off last param 'name'. + return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); } + return $form; } @@ -319,7 +329,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL * add stream * @param type $collection_pid * @param type $collectionName - * @return type + * @return type */ function add_stream($collection_pid=NULL, $collectionName=NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -345,7 +355,7 @@ function add_stream($collection_pid=NULL, $collectionName=NULL) { * @global type $base_url * @param type $form * @param type $form_state - * @return type + * @return type */ function add_stream_form_submit($form, &$form_state) { global $base_url; @@ -353,7 +363,7 @@ function add_stream_form_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; return; } - + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $pathToModule = drupal_get_path('module', 'fedora_repository'); @@ -384,7 +394,7 @@ function add_stream_form_submit($form, &$form_state) { * add stream form * @param type $form_state * @param type $pid - * @return type + * @return type */ function add_stream_form(&$form_state, $pid) { module_load_include('inc', 'fedora_repository', 'formClass'); @@ -396,7 +406,7 @@ function add_stream_form(&$form_state, $pid) { * add stream form validate * @param type $form * @param type $form_state - * @return type + * @return type */ function add_stream_form_validate($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'MimeClass'); @@ -427,14 +437,14 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_image_resolution' => array('85x85'), // 'file_validate_size' => array(30 * 1024), ); - + $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group']; if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)))) { // Move the uploaded file to Drupal's files directory. $file_path = $fileObject->filepath; file_move($file_path, 0, FILE_EXISTS_RENAME); $form_state['values']['add-stream-file-location'] = $file_path; - + $form_state['storage']['stream_url'] = file_create_url($file_path); } elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { @@ -443,10 +453,10 @@ function add_stream_form_validate($form, &$form_state) { else { form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); } - + $mimeClass = new MimeClass(); $mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']); - + if (!$controlGroup) { if ($mimetype == 'text/xml') { $form_state['storage']['control_group'] = 'X'; @@ -455,7 +465,7 @@ function add_stream_form_validate($form, &$form_state) { $form_state['storage']['control_group'] = 'M'; } } - + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } @@ -466,7 +476,7 @@ function add_stream_form_validate($form, &$form_state) { * @param type $pid * @param type $dsId * @param type $name - * @return type + * @return type */ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -487,18 +497,26 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL) return $output; } +/** + * Validates the purge object form. + * + * @param array $form + * The form to validate. + * @param array $form_state + * The state of the form to validate + */ function fedora_repository_purge_object_form_validate($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'api/fedora_collection'); $pid = $form_state['values']['pid']; - $objectHelper = new ObjectHelper(); - $contentModels = $objectHelper->get_content_models_list($pid); - foreach ($contentModels as $contentModel) { - if ($contentModel->pid == 'islandora:collectionCModel') { + $object_helper = new ObjectHelper(); + $content_models = $object_helper->get_content_models_list($pid); + foreach ($content_models as $content_model) { + if ($content_model->pid == 'islandora:collectionCModel') { $member_pids = get_related_items_as_array($pid, 'isMemberOfCollection'); if (is_array($member_pids) && ! empty($member_pids)) { - form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself.")); - return; + form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself.")); + return; } } } @@ -506,27 +524,33 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) { /** * fedora repository purge object form submit + * * @param type $form + * The submited form. * @param type $form_state - * @return type + * The state of the submitted form. */ function fedora_repository_purge_object_form_submit($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $pid = $form_state['values']['pid']; if (!isset($form_state['storage']['confirm'])) { - $form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form - $form_state['rebuild'] = TRUE; // along with this + /* This will cause the form to be rebuilt, + * entering the confirm part of the form.*/ + $form_state['storage']['confirm'] = TRUE; + // Along with this. + $form_state['rebuild'] = TRUE; } else { -// this is where you do your processing after they have pressed the confirm button + /* This is where you do your processing after + * they have pressed the confirm button.*/ $params = array( "pid" => $pid, "logMessage" => "Purged", - "force" => "" + "force" => "", ); try { - $soapHelper = new ConnectionHelper(); - $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); + $soap_helper = new ConnectionHelper(); + $client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); $object = $client->__soapCall('purgeObject', array($params)); unset($form_state['storage']['confirm']); } catch (exception $e) { @@ -538,6 +562,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) { } return; } + + // Set the form's redirect. if (!empty($form_state['values']['referrer'])) { $form_state['redirect'] = $form_state['values']['referrer']; } @@ -554,23 +580,25 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) { /** * fedora repository purge stream form + * * @param type $form_state * @param type $pid * @param type $dsId - * @return type + * + * @return type */ function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) { $form['pid'] = array( '#type' => 'hidden', - '#value' => "$pid" + '#value' => "$pid", ); $form['dsid'] = array( '#type' => 'hidden', - '#value' => "$dsId" + '#value' => "$dsId", ); $form['submit'] = array( '#type' => 'submit', - '#value' => t('Purge') + '#value' => t('Purge'), ); return $form; @@ -578,9 +606,11 @@ function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) { /** * fedora repository purge stream form submit + * * @global type $base_url + * * @param type $form - * @param array $form_state + * @param array $form_state */ function fedora_repository_purge_stream_form_submit($form, &$form_state) { global $base_url; @@ -596,6 +626,13 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) { $form_state['redirect'] = "fedora/repository/$pid"; } +/** + * + * @param unknown_type $form_state + * @param unknown_type $pid + * @param unknown_type $dsid + * @param unknown_type $label + */ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $form = array( @@ -605,7 +642,7 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $ '#value' => t('Download'), ), ); - + if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { $item = new Fedora_Item($pid); $versions = $item->get_datastream_history($dsid); @@ -618,10 +655,10 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $ else { $version_array[] = $versions->createDate; } - + if (count($version_array) > 1) { $form['#attributes'] = array( - 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;' + 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;', ); $form['version'] = array( '#type' => 'select', @@ -629,17 +666,19 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $ ); } } - + return $form; } /** * fedora repository replace stream + * * @param type $pid * @param type $dsId * @param type $dsLabel * @param type $collectionName - * @return type + * + * @return string */ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectionName = NULL) { if ($pid == NULL || $dsId == NULL) { @@ -653,11 +692,13 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectio /** * fedora repository replace stream form + * * @param type $form_state * @param type $pid * @param type $dsId * @param type $dsLabel - * @return type + * + * @return type */ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) { module_load_include('inc', 'fedora_repository', 'formClass'); @@ -669,13 +710,13 @@ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLab * fedora repository replace stream form validate * @param type $form * @param type $form_state - * @return type + * @return type */ function fedora_repository_replace_stream_form_validate($form, &$form_state) { // If a file was uploaded, process it. if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) { - // attempt to save the uploaded file + // Attempt to save the uploaded file. $file = file_save_upload('file', array(), file_directory_path()); // set error is file was not uploaded @@ -683,7 +724,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { form_set_error('file', 'Error uploading file.'); return; } - + /* ----------------------------------------------------------------- * TODO: need a better way to get mimetypes */ @@ -691,7 +732,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); $mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath); - + if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format. (XML could not be parsed)'); return; @@ -709,7 +750,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { * fedora repository replace stream form submit * @global type $base_url * @param type $form - * @param array $form_state + * @param array $form_state */ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $file = $form_state['values']['file']; @@ -717,11 +758,11 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; - - $streamUrl = ($file !== NULL) ? + + $streamUrl = ($file !== NULL) ? file_create_url($file->filepath): url($form_state['values']['reference'], array('absolute' => TRUE)); - + // Remove the original file extension from the label and add the new one // use strrpos to get the last dot if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) { @@ -744,7 +785,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { * @global type $user * @param type $pid * @param type $dsId - * @return type + * @return type */ function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -763,12 +804,12 @@ function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { } /** - * fedora repository edit qdc form + * fedora repository edit qdc form * @global type $user * @param type $form_state * @param type $pid * @param type $dsId - * @return type + * @return type */ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) { module_load_include('inc', 'fedora_repository', 'ContentModel'); @@ -786,7 +827,7 @@ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $soapHelper = new ConnectionHelper(); $client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); - + // Check if there is a custom edit metadata function defined in the content model. $output = ''; if (($cm = ContentModel::loadFromObject($pid)) !== FALSE) { @@ -799,14 +840,14 @@ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) { //currently we only edit the dc metadata. If you defined a custom form with a custom handler you are sol for now. $output = $metaDataForm->createMetaDataForm($pid, $dsId, $client, $form_state); } - + return $output; } /** * fedora repository edit qdc form validate * @param type $form - * @param boolean $form_state + * @param boolean $form_state */ function fedora_repository_edit_qdc_form_validate($form, &$form_state) { if ($form_state['storage']['xml']) { @@ -843,7 +884,8 @@ function fedora_repository_edit_qdc_form_submit($form, &$form_state) { $soap_helper = new ConnectionHelper(); $client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); - // Check the content model for a custom edit metadata form submit function. + /* Check the content model for a custom + * edit metadata form submit function.*/ if (isset($form_state['values']['pid'])) { module_load_include('inc', 'fedora_repository', 'ContentModel'); if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) { @@ -886,7 +928,7 @@ function fedora_repository_perm() { * @param type $op * @param type $node * @param type $account - * @return type + * @return type */ function fedora_repository_access($op, $node = NULL, $account = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -935,7 +977,7 @@ function makeObject($pid, $dsID) { /** * Implementation of hook_islandora_tabs(). - * + * * @param $content_models array * An array of ContentModel objects to which the current Fedora Object * subscribes. @@ -949,10 +991,10 @@ function makeObject($pid, $dsID) { */ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { $cmodels_tabs = array(); - + foreach ($content_models as $content_model) { $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); - + // Each content model may return either a tabpage array or plain HTML. If // it is HTML, stick it in a tabpage. if (is_array($content_model_fieldset)) { @@ -966,24 +1008,24 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { ); } } - + //can disable showing the object details tab in admin UI if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { // Add a 'manage object' tab for all objects, where detailed list of content is shown. // XXX: Perhaps this should be extracted into its own object? module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); $obj = new FedoraObjectDetailedContent($pid); - + $object_details = $obj->showFieldSets(); $cmodels_tabs = array_merge($cmodels_tabs, $object_details); } - + return $cmodels_tabs; } /** * Implementation of hook_islandora_tabs_alter(). - * + * * @param &$tabs array * The array of tabs/tabset to alter. * @param $params array @@ -1006,7 +1048,7 @@ function fedora_repository_islandora_tabs_alter(&$tabs, $params) { /** * Menu callback for "fedora/repository". - * + * * If user is allow, and we are given a PID and a sensical DSID, return the * datastream via the makeObject() function; otherwise, call out to the PIDs' * ContentModels and all Drupal modules for Islandora tabs. @@ -1088,29 +1130,29 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $breadcrumbs = array(); $objectHelper->getBreadcrumbs($pid, $breadcrumbs); drupal_set_breadcrumb(array_reverse($breadcrumbs)); - + drupal_set_title(truncate_utf8($item->objectProfile->objLabel, 56, TRUE, TRUE)); $content_models = $objectHelper->get_content_models_list($pid); - + //Get the tabs from all modules... $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); - + $cmodels_tabs = array( '#type' => 'tabset', ); $cmodels_tabs += $hook_tabs; - + //Assemble parameters, to pass during alter - $params = array( + $params = array( 'content_models' => $content_models, 'pid' => $pid, 'page' => $page_number, ); - + //Allow returned tabs to be altered, before return. drupal_alter('islandora_tabs', $cmodels_tabs, $params); - + return tabs_render($cmodels_tabs); } @@ -1118,7 +1160,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU * fedora repository urlencode string * FIXME: URL-encoding is not the same as HTML/XML encoding... * @param type $str - * @return type + * @return type */ function fedora_repository_urlencode_string($str) { return htmlentities($str); @@ -1133,7 +1175,7 @@ function fedora_repository_urlencode_string($str) { * @param type $dsId * @param type $label * @param type $version - * @return type + * @return type */ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -1156,7 +1198,7 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { * @param type $dsId * @param type $collection * @param type $pageNumber - * @return type + * @return type */ function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNumber = NULL) { //do security check at fedora_repository_get_items function as it has to be called there in case @@ -1170,7 +1212,7 @@ function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNum * @param type $pid * @param type $servicePid * @param type $serviceMethod - * @return type + * @return type */ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -1216,7 +1258,7 @@ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NU * * @param type $op * @param type $keys - * @return array + * @return array */ function fedora_repository_search($op = 'search', $keys = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -1299,7 +1341,7 @@ function fedora_repository_search($op = 'search', $keys = NULL) { * Display the search results * * @param type $resultData - * @return array + * @return array */ function fedora_repository_search_page($resultData) { $path = drupal_get_path('module', 'fedora_repository'); @@ -1377,7 +1419,7 @@ function fedora_repository_search_page($resultData) { * * @param type $form * @param type $form_state - * @param type $form_id + * @param type $form_id */ function fedora_repository_form_alter(&$form, &$form_state, $form_id) { // Advanced node search form @@ -1433,7 +1475,7 @@ function fedora_repository_form_alter(&$form, &$form_state, $form_id) { * Implementation of hook_search_validate() * * @param type $form - * @param type $form_state + * @param type $form_state */ function fedora_repository_search_validate($form, &$form_state) { // Initialise using any existing basic search keywords. @@ -1453,7 +1495,7 @@ function fedora_repository_search_validate($form, &$form_state) { /** * fedora repository theme - * @return type + * @return type */ function fedora_repository_theme() { return array( @@ -1481,7 +1523,7 @@ function fedora_repository_theme() { * @param type $field * @param type $startTerm * @param type $displayName - * @return type + * @return type */ function fedora_repository_list_terms($field, $startTerm = NULL, $displayName = NULL) { module_load_include('inc', 'fedora_repository', 'SearchClass'); @@ -1491,7 +1533,7 @@ function fedora_repository_list_terms($field, $startTerm = NULL, $displayName = /** * fedora repository mnpl advanced search form - * @return type + * @return type */ function fedora_repository_mnpl_advanced_search_form() { module_load_include('inc', 'fedora_repository', 'SearchClass'); @@ -1500,9 +1542,9 @@ function fedora_repository_mnpl_advanced_search_form() { } /** - * theme fedora repository mnpl advanced search form + * theme fedora repository mnpl advanced search form * @param type $form - * @return type + * @return type */ function theme_fedora_repository_mnpl_advanced_search_form($form) { module_load_include('inc', 'fedora_repository', 'SearchClass'); @@ -1514,7 +1556,7 @@ function theme_fedora_repository_mnpl_advanced_search_form($form) { * fedora repository mnpl advanced search * @param type $query * @param type $startPage - * @return type + * @return type */ function fedora_repository_mnpl_advanced_search($query, $startPage = 1) { module_load_include('inc', 'fedora_repository', 'SearchClass'); @@ -1526,7 +1568,7 @@ function fedora_repository_mnpl_advanced_search($query, $startPage = 1) { /** * fedora repository mnpl_advanced search form submit * @param type $form - * @param type $form_state + * @param type $form_state */ function fedora_repository_mnpl_advanced_search_form_submit($form, &$form_state) { $type_id = $form_state['values']['type']; @@ -1548,7 +1590,7 @@ function fedora_repository_mnpl_advanced_search_form_submit($form, &$form_state) /** * fedora repository install demo page - * @return type + * @return type */ function fedora_repository_install_demos_page() { $output = drupal_get_form('fedora_repository_demo_objects_form'); @@ -1557,7 +1599,7 @@ function fedora_repository_install_demos_page() { /** * fedora repository demo objects form - * @return string + * @return string */ function fedora_repository_demo_objects_form() { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -1590,7 +1632,7 @@ function fedora_repository_demo_objects_form() { try { $demo_objects[$available_demo] = new Fedora_Item($available_demo); } catch (exception $e) { - + } if (empty($demo_objects[$available_demo]->objectProfile)) { @@ -1650,7 +1692,7 @@ function fedora_repository_demo_objects_form() { * fedora repository demo objects form submit * @global type $base_url * @param type $form - * @param type $form_state + * @param type $form_state */ function fedora_repository_demo_objects_form_submit($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -1727,7 +1769,7 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) { $tn = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_mimetype_pdf.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); drupal_set_message(t("Successfully installed islandora:demos.", array('@base_url' => check_plain($base_url))), 'message'); } catch (exception $e) { - + } } @@ -1742,14 +1784,14 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) { try { $cmstream = $cm->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/STANDARD JPG.xml', 'ISLANDORACM', 'Content Model.xml', 'application/xml', 'X'); } catch (exception $e) { - + } $dual_res_image_collection_cmodel = new Fedora_Item('demo:DualResImageCollection'); try { $cmstream = $dual_res_image_collection_cmodel->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/COLLECTIONCM.xml', 'ISLANDORACM', 'Islandora Content Model.xml', 'application/xml', 'X'); drupal_set_message(t("Successfully installed demo:SmileyStuff collection view.", array('@base_url' => check_plain($base_url))), 'message'); } catch (exception $e) { - + } } @@ -1780,7 +1822,7 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) { /** * fedora repository required fedora objects - * @return type + * @return type */ function fedora_repository_required_fedora_objects() { // array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', int dsversion, boolean required) @@ -1834,7 +1876,7 @@ function fedora_repository_elements() { /** * fedora repository expand time * @param type $element - * @return string + * @return string */ function fedora_repository_expand_time($element) { // Default to current time, check default_value but set value so that if @@ -1877,7 +1919,7 @@ function fedora_repository_expand_time($element) { /** * fedora repository time * @param type $element - * @return type + * @return type */ function fedora_repository_time($element) { $output = '
' . $element['#children'] . '
'; @@ -1887,7 +1929,7 @@ function fedora_repository_time($element) { /** * theme fedora repository time * @param type $element - * @return type + * @return type */ function theme_fedora_repository_time($element) { $output = '
' . $element['#children'] . '
'; @@ -1898,7 +1940,7 @@ function theme_fedora_repository_time($element) { /** * fedora repository remove item from basket - * @param type $pid + * @param type $pid */ function fedora_repository_remove_item_from_basket($pid) { @@ -1923,7 +1965,7 @@ function fedora_repository_remove_item_from_basket($pid) { /** * fedora repository basket - * @return type + * @return type */ function fedora_repository_basket() { $pids = _fedora_repository_get_basket_pids(); @@ -1984,7 +2026,7 @@ function fedora_repository_basket_form($form_state, $pids) { /** * theme fedora repository basket form * @param type $form - * @return string + * @return string */ function theme_fedora_repository_basket_form($form) { $header = array( @@ -2019,7 +2061,7 @@ function theme_fedora_repository_basket_form($form) { /** * fedora repository basket form validate * @param type $form - * @param type $form_state + * @param type $form_state */ function fedora_repository_basket_form_validate($form, &$form_state) { @@ -2030,7 +2072,7 @@ function fedora_repository_basket_form_validate($form, &$form_state) { * @global type $user * @param type $form * @param type $form_state - * @return type + * @return type */ function fedora_repository_basket_form_submit($form, &$form_state) { if ($form_state['values']['op'] == $form_state['values']['remove_submit']) { @@ -2099,9 +2141,9 @@ function fedora_repository_basket_form_submit($form, &$form_state) { } /** - * Get all pids saved to the basket. + * Get all pids saved to the basket. * - * @return type + * @return type */ function _fedora_repository_get_basket_pids() { @@ -2141,7 +2183,7 @@ function _fedora_repository_empty_basket() { * fedora repository add to basket * @param type $pid * @param type $warn - * @param type $searchResultsFlag + * @param type $searchResultsFlag */ function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag = FALSE) { if ($warn && _is_added_to_basket($pid)) { @@ -2164,7 +2206,7 @@ function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag /** * fedora repository remove from basket * @param type $pid - * @return type + * @return type */ function fedora_repository_remove_from_basket($pid) { if (isset($_SESSION['basket']['unprocessed'][$pid])) { @@ -2181,7 +2223,7 @@ function fedora_repository_remove_from_basket($pid) { * theme add to basket link * @param type $pid * @param type $type - * @return type + * @return type */ function theme_add_to_basket_link($pid, $type = 'object') { $object = t($type); @@ -2208,7 +2250,7 @@ function theme_add_to_basket_link($pid, $type = 'object') { * is added to basket * @param type $pid * @param type $account - * @return type + * @return type */ function _is_added_to_basket($pid, $account = NULL) { return isset($_SESSION['basket']['unprocessed'][$pid]) || isset($_SESSION['basket']['processed'][$pid]); @@ -2218,7 +2260,7 @@ function _is_added_to_basket($pid, $account = NULL) { /** * fedora repository display schema * @param type $file - * @return type + * @return type */ function fedora_repository_display_schema($file) { $path = drupal_get_path('module', 'fedora_repository'); @@ -2235,10 +2277,10 @@ function fedora_repository_display_schema($file) { * fedora repository batch reingest object * @param type $object * @param type $context - * @return type + * @return type */ function fedora_repository_batch_reingest_object($object, &$context) { - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -2247,7 +2289,7 @@ function fedora_repository_batch_reingest_object($object, &$context) { if (!valid_pid($pid)) { return NULL; } - + // Does the object exist? If so, purge it. //dd("About to test existence of PID: $pid"); $item = new Fedora_Item($pid); @@ -2269,7 +2311,7 @@ function fedora_repository_batch_reingest_object($object, &$context) { $context['message'][] = t('%pid installed.', array('%pid' => $new_item->pid)); } } - + if (!empty($object['dsid']) && !empty($object['datastream_file'])) { $datastreams[] = array( 'dsid' => $object['dsid'], @@ -2318,11 +2360,11 @@ function fedora_repository_batch_reingest_object($object, &$context) { * Content model, collection view and collection policy datastreams may now optionally define a version * number in their top-level XML element as an attribute, as in: * attributes()->version) { $return = $version; } - + return $return; } /** * theme fedora repository solution pack list * @param type $solution_packs - * @return string + * @return string */ function theme_fedora_repository_solution_packs_list($solution_packs) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -2359,7 +2401,7 @@ function theme_fedora_repository_solution_packs_list($solution_packs) { /** * Implementation of hook_forms() * @param string $form_id - * @return array + * @return array */ function fedora_repository_forms($form_id) { $forms = array(); @@ -2396,12 +2438,12 @@ function fedora_repository_imagecache_default_presets() { /** * Actually render an image, given an arbitrary path and preset. - * + * * Note: If imagecache_external is not available, the full-sized image will be * produced... Might want to look into restricting the display size by adding * the width and height attributes to the theme('image') call, based on the * selected preset? (get the presets and figure out the size from its actions?) - * + * * @param $tn_path string * @param $imagecache_preset string * @return @@ -2425,10 +2467,10 @@ function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_ /** * Render an image, given a PID, DSID and preset. - * + * * Produces a Drupal path for the image, passes to * _fedora_repository_render_image(), and returns the result. - * + * * @see _fedora_repository_render_image() * @param $pid string * A string containing a Fedora PID. @@ -2447,7 +2489,7 @@ function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedor /** * Convenience function used in XSLT callback... - * + * * @param $string string * A string containing some markup to convert to a domnode. */ From 91927dad1a3284ac2aa74426f181ab7b03287d6c Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 11 Sep 2012 15:45:23 -0300 Subject: [PATCH 6/6] ISLANDORA-624 redirect after object purge now sending one to the first identifiable parent collection --- fedora_repository.module | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 1b2797e5..e222e237 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -306,9 +306,6 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL '#value' => t('Purge'), '#suffix' => 'Purge this object', ); - if (!empty($collectionPid)) { - $collectionPid = $_SESSION['fedora_collection']; - } return $form; } @@ -532,7 +529,11 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) { */ function fedora_repository_purge_object_form_submit($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $pid = $form_state['values']['pid']; + $parents = get_parent_collections_from_pid($pid); + if (!isset($form_state['storage']['confirm'])) { /* This will cause the form to be rebuilt, * entering the confirm part of the form.*/ @@ -563,18 +564,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) { return; } - // Set the form's redirect. - if (!empty($form_state['values']['referrer'])) { - $form_state['redirect'] = $form_state['values']['referrer']; - } - elseif (empty($collectionPid) && !empty($_SESSION['fedora_collection']) && $_SESSION['fedora_collection'] != $pid) { - $collectionPid = $_SESSION['fedora_collection']; - - $form_state['redirect'] = "fedora/repository/$collectionPid/"; - } - else { - $form_state['redirect'] = 'fedora/repository/'; - } + // Set the form's redirect to its first identifiable parent collection. + $form_state['redirect'] = "fedora/repository/$parents[0]/"; } }