diff --git a/includes/add_datastream.form.inc b/includes/add_datastream.form.inc index f4506424..1a577fb8 100644 --- a/includes/add_datastream.form.inc +++ b/includes/add_datastream.form.inc @@ -2,7 +2,6 @@ /** * @file - * * Functions for generating/validating/submitting the add datastream form. */ @@ -26,13 +25,12 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb $form_state['object'] = $object; $form_state['datastream_requirements'] = islandora_get_missing_datastreams_requirements($object); $unused_datastreams = array_keys($form_state['datastream_requirements']); - $unused_datastreams = array_map(function($o) { return "'$o'"; }, $unused_datastreams); - $unused_datastreams = implode(', ', $unused_datastreams); - $upload_size = min((int)ini_get('post_max_size'), (int)ini_get('upload_max_filesize')); + $unused_datastreams = "'" . implode("', '", $unused_datastreams) . "'"; + $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); return array( '#redirect' => "islandora/object/{$object->id}", '#attributes' => array( - 'enctype' => 'multipart/form-data' + 'enctype' => 'multipart/form-data', ), 'fieldset' => array( '#type' => 'fieldset', @@ -41,52 +39,46 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb '#collapsed' => FALSE, 'dsid' => array( '#title' => 'Datastream ID', - '#description' => t('An ID for this stream that is unique to this object.' . - 'Must start with a letter and contain only alphanumeric ' . - 'characters and dashes and underscores. Datastreams that ' . - 'are defined by the content model don\'t currently exist: ' . - '@unused_dsids.', - array('@unused_dsids' => $unused_datastreams) - ), - '#type' => 'textfield', - '#size' => 64, - '#maxlength' => 64, - '#required' => TRUE, - '#element_validate' => array( - 'islandora_add_datastream_form_field_is_not_an_existing_datastream_id', - 'islandora_add_datastream_form_field_starts_with_a_letter', - 'islandora_add_datastream_form_field_is_valid_dsid', - ), - '#autocomplete_path' => "islandora/object/{$object->id}/manage/datastreams/add/autocomplete" - ), - 'label' => array( - '#title' => 'Datastream Label', - '#required' => TRUE, - '#size' => 64, - '#maxlength' => 64, - '#description' => t('A Human readable label'), - '#type' => 'textfield', - '#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash') + '#description' => t("An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model don't currently exist: @unused_dsids.", array('@unused_dsids' => $unused_datastreams)), ), - 'file' => array( - '#type' => 'managed_file', - '#required' => TRUE, - '#title' => t('Upload Document'), - '#size' => 48, - '#description' => t('Select a file to upload.
Files must be less than @size MB.', array('@size' => $upload_size)), - '#default_value' => isset($form_state['values']['files']) ? $form_state['values']['files'] : NULL, - '#upload_location' => 'temporary://', - '#upload_validators' => array( - 'file_validate_extensions' => array(NULL), - // Assume its specified in MB - 'file_validate_size' => array($upload_size * 1024 * 1024), - ), + '#type' => 'textfield', + '#size' => 64, + '#maxlength' => 64, + '#required' => TRUE, + '#element_validate' => array( + 'islandora_add_datastream_form_field_is_not_an_existing_datastream_id', + 'islandora_add_datastream_form_field_starts_with_a_letter', + 'islandora_add_datastream_form_field_is_valid_dsid', ), - 'submit' => array( - '#type' => 'submit', - '#value' => t('Add Datastream') + '#autocomplete_path' => "islandora/object/{$object->id}/manage/datastreams/add/autocomplete", + ), + 'label' => array( + '#title' => 'Datastream Label', + '#required' => TRUE, + '#size' => 64, + '#maxlength' => 64, + '#description' => t('A Human readable label'), + '#type' => 'textfield', + '#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash'), + ), + 'file' => array( + '#type' => 'managed_file', + '#required' => TRUE, + '#title' => t('Upload Document'), + '#size' => 48, + '#description' => t('Select a file to upload.
Files must be less than @size MB.', array('@size' => $upload_size)), + '#default_value' => isset($form_state['values']['files']) ? $form_state['values']['files'] : NULL, + '#upload_location' => 'temporary://', + '#upload_validators' => array( + 'file_validate_extensions' => array(NULL), + // Assume its specified in MB. + 'file_validate_size' => array($upload_size * 1024 * 1024), ), - ) + ), + 'submit' => array( + '#type' => 'submit', + '#value' => t('Add Datastream'), + ), ); } @@ -123,8 +115,7 @@ function islandora_add_datastream_form_field_starts_with_a_letter(array $element } /** - * Checks if the given form field contains only valid characters for a - * datastream id. + * Checks if the given form field contains a valid datastream ID. * * @param array $element * The form field to check. @@ -157,8 +148,7 @@ function islandora_add_datastream_form_field_does_not_contain_a_forward_slash(ar } /** - * Checks if the given datastream id requires that the upload file be of a - * certian MIME type. + * Checks if the given datastream requires the upload to be a certian MIME type. * * @param array $form * The Drupal form. @@ -180,8 +170,9 @@ function islandora_add_datastream_form_validate(array $form, array &$form_state) } /** - * Adds the new datastream based on the submitted values, only creates managed - * datastreams at the moment. + * Adds the new datastream based on the submitted values. + * + * Only creates managed datastreams at the moment. * * @param array $form * The Drupal form. @@ -200,9 +191,11 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) { $ds->setContentFromFile($path); $object->ingestDatastream($ds); file_delete($file); - } catch (exception $e) { + } + catch (exception $e) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); - file_delete($file); // Make sure to delete anyways. + // Make sure to delete anyways. + file_delete($file); return; } drupal_set_message(t("Successfully Added Datastream!")); @@ -210,6 +203,7 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) { /** * Callback for an autocomplete field in the admin add datastream form. + * * It lists the missing required (may be optional) datastreams. * * @param FedoraObject $object @@ -225,7 +219,10 @@ function islandora_add_datastream_form_autocomplete_callback(FedoraObject $objec $dsids = array_combine($dsids, $dsids); $query = trim($query); if (!empty($query)) { - $dsids = array_filter($dsids, function($id) use($query) { return stripos($id, $query) !== FALSE; }); + $filter = function($id) use($query) { + return stripos($id, $query) !== FALSE; + }; + $dsids = array_filter($dsids, $filter); } drupal_json_output($dsids); } diff --git a/includes/authtokens.inc b/includes/authtokens.inc index 8efc4d11..9d5783a9 100644 --- a/includes/authtokens.inc +++ b/includes/authtokens.inc @@ -1,9 +1,11 @@ id}/manage/datastreams"); break; + case 1: - // One registry implementation, go there + // One registry implementation, go there. drupal_goto($edit_registry[0]['url']); break; + default: - // Multiple edit routes registered + // Multiple edit routes registered. return islandora_edit_datastream_registry_render($edit_registry); } } diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index 9c3cd368..faf92a18 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -2,9 +2,7 @@ /** * @file - * - * This file contains the admin (confirmation) form and callback functions to - * delete/purge a datastream. + * The admin/confirmation form to delete/purge a datastream. */ /** @@ -32,19 +30,18 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Fedor } /** - * Submit handler for the delete datastream form. Purges/Delete's the given - * FedoraDatastream if possible. + * Submit handler for the delete datastream form. + * + * Purges/Delete's the given FedoraDatastream if possible. * * The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to * whether the given FedoraDatastream * should be: blocked from purging; state set to 'Deleted'; or purged. * - * @see islandora_delete_datastream(). - * - * @param string $object_id - * ID of the object - * @param string $datastream_id - * ID of the datastream + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. */ function islandora_delete_datastream_form_submit(array $form, array &$form_state) { $datastream = $form_state['datastream']; @@ -53,14 +50,22 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state $deleted = FALSE; try { $deleted = islandora_delete_datastream($datastream); - } catch (Exception $e) { - drupal_set_message(t('Error deleting %s datastream from object %o %e', array('%s' => $datastream_id, '%o' => $object->label, '%e' => $e->getMessage())), 'error'); + } + catch (Exception $e) { + drupal_set_message(t('Error deleting %s datastream from object %o %e', array( + '%s' => $datastream_id, + '%o' => $object->label, + '%e' => $e->getMessage())), 'error'); } if ($deleted) { - drupal_set_message(t('%d datastream sucessfully deleted from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->label))); + drupal_set_message(t('%d datastream sucessfully deleted from Islandora object %o', array( + '%d' => $datastream_id, + '%o' => $object->label))); } else { - drupal_set_message(t('Error deleting %s datastream from object %o', array('%s' => $datastream_id, '%o' => $object->label)), 'error'); + drupal_set_message(t('Error deleting %s datastream from object %o', array( + '%s' => $datastream_id, + '%o' => $object->label)), 'error'); } $form_state['redirect'] = "islandora/object/{$object->id}"; } diff --git a/includes/delete_object.form.inc b/includes/delete_object.form.inc index 07cc2c21..46210e3c 100644 --- a/includes/delete_object.form.inc +++ b/includes/delete_object.form.inc @@ -2,9 +2,7 @@ /** * @file - * - * This file contains the admin (confirmation) form and callback functions to - * purge an object. + * The admin/confirmation form to purge an object. */ /** @@ -32,7 +30,7 @@ function islandora_delete_object_form(array $form, array &$form_state, FedoraObj } /** - * Delete's the object in questionGives deloption of deleting or purging and object. + * Delete's the given object. * * @param array $form * The Drupal form. diff --git a/includes/dublin_core.inc b/includes/dublin_core.inc index 144bd17d..53879623 100644 --- a/includes/dublin_core.inc +++ b/includes/dublin_core.inc @@ -2,9 +2,9 @@ /** * @file + * Implements a simple class for working with Dublin Core data. * - * Implements a simple class for working with Dublin Core data and exporting it - * back to XML. Inspiration and design shamelessly stolen from the pyfedora + * Inspiration and design shamelessly stolen from the pyfedora * project at http://pypi.python.org/pypi/pyfedora/0.1.0 */ @@ -33,34 +33,40 @@ class DublinCore { public $owner; /** - * Constructs a DublinCore object from a Fedora_Item object and populates the - * $dc array. + * Constructor. * * @param string $dc_xml + * The Dublin Core XML. */ - function DublinCore($dc_xml = NULL) { + public function __construct($dc_xml = NULL) { if (!empty($dc_xml)) { - $this->dc = self::import_from_xml_string($dc_xml); + $this->dc = self::importFromXMLString($dc_xml); } } /** - * Add Elements - * @param $element_name - * @param $value + * Add an element. + * + * @param string $element_name + * The name of the element to add. + * @param string $value + * The value of the element to add. */ - function add_element($element_name, $value) { + public function addElement($element_name, $value) { if (is_string($value) && is_array($this->dc[$element_name])) { $this->dc[$element_name][] = $value; } } /** - * Replace the given DC element with the values in $values - * @param string $elemnt_name - * @param array $values + * Replace the given DC element with the given values. + * + * @param string $element_name + * The name of the elements to set. + * @param mixed $values + * The values of the set the elements too. */ - function set_element($element_name, $values) { + public function setElement($element_name, $values) { if (is_array($values)) { $this->dc[$element_name] = $values; } @@ -70,11 +76,12 @@ class DublinCore { } /** - * Serialize this object to XML and return it. - * @param type $with_preamble - * @return type + * Serialize this object as an XML string. + * + * @return string + * The serialized XML. */ - function as_xml($with_preamble = FALSE) { + public function asXML() { $dc_xml = new DomDocument(); $oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc'); $oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); @@ -95,18 +102,17 @@ class DublinCore { } /** - * Create dc from dict ( does nothing ) + * Serializes this object as an array. + * + * @return array + * The serialized object. */ - static function create_dc_from_dict() { - - } - - function as_formatted_array() { + public function asArray() { $dc_array = array(); foreach ($this as $element) { if (!empty($element)) { foreach ($element as $field => $values) { - // split value if the result value is an array + // Split value if the result value is an array. if (is_array($values)) { $value = ''; $i = 0; @@ -135,17 +141,19 @@ class DublinCore { /** - * Creates a new instance of the class by parsing dc_xml + * Creates a new instance of the class by parsing dc_xml. * * @param string $dc_xml + * Dublin Core XML. + * * @return DublinCore + * The instantiated object. */ - static function import_from_xml_string($dc_xml) { + public static function importFromXMLString($dc_xml) { $dc_doc = new DomDocument(); if ($dc_doc->loadXML($dc_xml)) { $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*'); $new_dc = new DublinCore(); - foreach ($oai_dc as $child) { if (isset($new_dc->dc[$child->nodeName])) { array_push($new_dc->dc[$child->nodeName], $child->nodeValue); diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 5d340257..420ebc87 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -2,14 +2,14 @@ /** * @file - * - * Defines the multi-page ingest form and any relevant hooks and functions for - * defining the multi-page ingest forms. + * Defines the multi-page ingest form and any relevant hooks and functions. */ /** - * Ingest form build function. Initializes the form state, and builds the - * initial list of steps, excutes the current step. + * Ingest form build function. + * + * Initializes the form state, and builds the initial list of steps, excutes + * the current step. * * @param array $form * The drupal form. @@ -32,9 +32,7 @@ */ function islandora_ingest_form(array $form, array &$form_state, array $configuration) { islandora_ingest_form_init_form_state($form_state, $configuration); - $form = islandora_ingest_form_execute_step($form, $form_state); - return $form; } @@ -71,7 +69,9 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array // Use namespace if ID not given. $namespace = isset($configuration['namespace']) && !isset($id) ? $configuration['namespace'] : $id; $label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; - $relationship_map = function($o) { return array('relationship' => 'isMemberOfCollection', 'pid' => $o); }; + $relationship_map = function($o) { + return array('relationship' => 'isMemberOfCollection', 'pid' => $o); + }; $relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']); $object = islandora_prepare_new_object($namespace, $label, array(), array(), $relationships); $form_state['islandora'] = array( @@ -115,8 +115,10 @@ function islandora_ingest_get_approximate_steps(array $configuration) { } /** - * Executes the current step, building the form definition and appending on any - * additonal elements required for the step to function. + * Executes the current step. + * + * Builds the form definition and appends any additonal elements required for + * the step to function. * * @param array $form * The drupal form. @@ -138,6 +140,7 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) { $args = isset($step_info['args']) ? array_merge($args, $step_info['args']) : $args; $form = call_user_func_array($step_info['form_id'], $args); return islandora_ingest_form_stepify($form, $form_state, $step_info); + case 'batch': // @todo Implement if possible. break; @@ -160,7 +163,7 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) { */ function islandora_ingest_form_stepify(array $form, array &$form_state, array $step_info) { $step = islandora_ingest_form_get_step_number($form_state); - + $first_step = $step > 0; $last_step = $step == (islandora_ingest_form_get_step_count($form_state) - 1); $form['prev'] = $first_step ? islandora_ingest_form_previous_button() : NULL; @@ -187,11 +190,19 @@ function islandora_ingest_form_previous_button() { // convert all required fields to use #element_validation functions, and // Remove the need for #limit_validation_errors. Or maybe there is some // other solution, regardless of what it is, it won't be standard. - '#limit_validation_errors' => array() + '#limit_validation_errors' => array(), ); } -function islandora_ingest_form_get_step_number($form_state, $step_id = NULL) { +/** + * Get the current step. + * + * @param array $form_state + * The Drupal form state. + * @param string $step_id + * The ID of the step to get. + */ +function islandora_ingest_form_get_step_number(array $form_state, $step_id = NULL) { if ($step_id === NULL) { $step_id = islandora_ingest_form_get_step_id($form_state); } @@ -215,7 +226,7 @@ function islandora_ingest_form_get_step_number($form_state, $step_id = NULL) { function islandora_ingest_form_previous_submit(array $form, array &$form_state) { $step = islandora_ingest_form_get_step_number($form_state); islandora_ingest_form_stash_info($form_state); - $step = max(array($step - 1, 0)) ; + $step = max(array($step - 1, 0)); $form_state['islandora']['step_id'] = islandora_ingest_form_get_step_id($form_state, $step); islandora_ingest_form_grab_info($form_state); $form_state['rebuild'] = TRUE; @@ -240,7 +251,7 @@ function islandora_ingest_form_next_button(array $step_info) { '#value' => t('Next'), '#name' => 'next', '#validate' => $validate, - '#submit' => $submit + '#submit' => $submit, ); } @@ -260,7 +271,7 @@ function islandora_ingest_form_next_submit(array $form, array &$form_state) { $step = islandora_ingest_form_get_step_number($form_state); drupal_static_reset('islandora_ingest_form_get_steps'); islandora_ingest_form_stash_info($form_state); - $step = min(array($step + 1, islandora_ingest_form_get_step_count($form_state) - 1)) ; + $step = min(array($step + 1, islandora_ingest_form_get_step_count($form_state) - 1)); $form_state['islandora']['step_id'] = islandora_ingest_form_get_step_id($form_state, $step); islandora_ingest_form_grab_info($form_state); $form_state['rebuild'] = TRUE; @@ -272,7 +283,7 @@ function islandora_ingest_form_next_submit(array $form, array &$form_state) { function islandora_ingest_form_stash_info(array &$form_state) { $storage = &islandora_ingest_form_get_step_storage($form_state); $storage['values'] = $form_state['values']; - unset($form_state['values']); + unset($form_state['values']); } /** @@ -280,7 +291,7 @@ function islandora_ingest_form_stash_info(array &$form_state) { */ function islandora_ingest_form_grab_info(array &$form_state) { $storage = islandora_ingest_form_get_step_storage($form_state); - $form_state['values'] = isset($storage['values'])?$storage['values']:array(); + $form_state['values'] = isset($storage['values']) ? $storage['values'] : array(); if (isset($storage['configuration'])) { $form_state['islandora']['configuration'] = $storage['configuration']; } @@ -305,7 +316,7 @@ function islandora_ingest_form_ingest_button(array $step_info) { '#name' => 'ingest', '#value' => t('Ingest'), '#validate' => $validate, - '#submit' => $submit + '#submit' => $submit, ); } @@ -324,8 +335,10 @@ function islandora_ingest_form_submit(array $form, array &$form_state) { try { islandora_add_object($object); $form_state['redirect'] = "islandora/object/{$object->id}"; - } catch (Exception $e) { - // If post hooks throws it may already exist at this point but may be invalid, so don't say failed :P + } + catch (Exception $e) { + // If post hooks throws it may already exist at this point but may be + // invalid, so don't say failed. watchdog('islandora', $e->getMessage(), NULL, WATCHDOG_ERROR); drupal_set_message(t('A problem occured while ingesting "@label" (ID: @pid), please notifiy the administrator.', array('@label' => $object->label, '@pid' => $object->id)), 'error'); } @@ -346,8 +359,7 @@ function &islandora_ingest_form_get_configuration(array &$form_state) { } /** - * Gets a reference to the stored NewFedoraObject's which are to be ingested - * when the final step submits. + * Gets a reference to the stored NewFedoraObject's. * * @param array $form_state * The drupal form state. @@ -401,15 +413,14 @@ function islandora_ingest_form_get_step_id(array &$form_state, $step_number = NU } /** - * Get a reference to the step info of the given step or the current step if - * none is given. + * Get the step info of the given step or the current step if none is given. * * @param array $form_state * The drupal form state. * @param int $step * The index of the step to get. * - * @return integer + * @return int * The step info of the requested step if found, NULL otherwise. */ function islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) { @@ -423,7 +434,12 @@ function islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) { } /** - * Get general storage for the given step. (or the current step) + * Get general storage for the given/current step. + * + * @param array $form_state + * The drupal form state. + * @param string $step_id + * The ID of the step. */ function &islandora_ingest_form_get_step_storage(array &$form_state, $step_id = NULL) { if ($step_id === NULL) { @@ -459,7 +475,7 @@ function islandora_ingest_form_get_steps(array &$form_state) { function islandora_ingest_form_step_form_load_include(array &$form_state) { form_load_include($form_state, 'inc', 'islandora', 'includes/ingest.form'); $step_info = islandora_ingest_form_get_step_info($form_state); - // Load include files + // Load include files. if (isset($step_info['file']) && isset($step_info['module'])) { $matches = array(); preg_match('/^(.*)\.(.*)$/', $step_info['file'], $matches); @@ -490,7 +506,7 @@ function islandora_ingest_form_get_step_count(array $form_state) { * The sort order is undefined for steps which have the same weight. * * @param array $form_state - * All available form_state options used to build the multi-paged ingest process. + * The Drupal form state. * * @return array * The list of sorted ingest steps as defined by all implementers @@ -515,7 +531,7 @@ function &islandora_ingest_get_steps(array &$form_state) { // Need to pass by ref... But don't really want an alter. foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; - $module_steps = (array)$function($form_state); + $module_steps = (array) $function($form_state); $steps = array_merge($steps, $module_steps); } } diff --git a/includes/ingest.menu.inc b/includes/ingest.menu.inc index ac551014..ca4f6156 100644 --- a/includes/ingest.menu.inc +++ b/includes/ingest.menu.inc @@ -2,7 +2,6 @@ /** * @file - * * Ingest Menu callback hooks. */ @@ -57,7 +56,7 @@ function islandora_ingest_get_configuration() { * @param array $configuration * The key value pairs that are used to build the multi-paged ingest process. * - * @return boolean + * @return bool * TRUE if the configuration is valid, FALSE otherwise. */ function islandora_valid_ingest_configuration(array $configuration) { diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 3807c50e..7e1fb7f7 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -1,9 +1,9 @@ extension + * Gets an associative array of MIME type and extension associations. + * + * Users the system mime.types file, or a local mime.types if one is found + * @see MIMEDetect::__constuctor() + * + * @return array + * An associative array where the keys are MIME types and the values + * extensions. */ protected function systemMimetypeExtensions() { $out = array(); @@ -328,11 +332,14 @@ class MimeDetect { } /** - * function: systemMimetypeExtensions - * 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). - * return: array of extension => mimetype + * Gets a associative array of extensions and MIME types. + * + * Users the system mime.types file, or a local mime.types if one is found + * @see MIMEDetect::__constuctor() + * + * @return array + * An associative array where the keys are extensions and the values + * MIME types. */ protected function systemExtensionMimetypes() { $out = array(); @@ -340,15 +347,18 @@ class MimeDetect { $file = fopen($this->etcMimeTypes, '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); } @@ -356,4 +366,3 @@ class MimeDetect { } } - diff --git a/includes/object.entity_controller.inc b/includes/object.entity_controller.inc index 6f58e723..d3fd6986 100644 --- a/includes/object.entity_controller.inc +++ b/includes/object.entity_controller.inc @@ -1,13 +1,30 @@ array( '#type' => 'hidden', - '#value' => $object->id + '#value' => $object->id, ), 'object_label' => array( '#title' => t('Item Label'), '#default_value' => $object->label, '#required' => 'TRUE', '#description' => t('A Human readable label'), - // Double the normal length + // Double the normal length. '#size' => 120, - // Max length for a Fedora Label + // Max length for a Fedora Label. '#maxlength' => 255, - '#type' => 'textfield' + '#type' => 'textfield', ), // @todo Make this into an autocomplete field that list the users in the // system as well. @@ -45,7 +44,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor '#default_value' => $object->owner, '#required' => FALSE, '#description' => t('The owner id'), - '#type' => 'textfield' + '#type' => 'textfield', ), 'object_state' => array( '#title' => t('State'), @@ -53,18 +52,18 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor '#required' => TRUE, '#description' => t('The items state one of active, inactive or deleted'), '#type' => 'select', - '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted') + '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'), ), 'submit' => array( '#type' => 'submit', - '#value' => 'Update Properties' + '#value' => 'Update Properties', ), 'delete' => array( '#type' => 'submit', '#value' => t('Delete'), '#submit' => array('islandora_object_properties_form_delete'), - '#limit_validation_errors' => array(array('pid')) - ) + '#limit_validation_errors' => array(array('pid')), + ), ); } @@ -85,7 +84,8 @@ function islandora_object_properties_form_submit(array $form, array &$form_state try { $object->owner = $owner; drupal_set_message(t('Successfully updated owner %s', array('%s' => $owner))); - } catch (Exception $e) { + } + catch (Exception $e) { form_set_error('object_owner', t('Error updating owner %s', array('%s' => $e->getMessage()))); } } @@ -93,7 +93,8 @@ function islandora_object_properties_form_submit(array $form, array &$form_state try { $object->state = $state; drupal_set_message(t('Successfully updated state %s', array('%s' => $state))); - } catch (Exception $e) { + } + catch (Exception $e) { form_set_error('object_state', t('Error updating state %s', array('%s' => $e->getMessage()))); } } @@ -101,7 +102,8 @@ function islandora_object_properties_form_submit(array $form, array &$form_state try { $object->label = $label; drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($label)))); - } catch (Exception $e) { + } + catch (Exception $e) { form_set_error(t('Error updating label %s', array('%s' => $e->getMessage()))); } } diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index f3e0f0e8..02952233 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -2,9 +2,7 @@ /** * @file - * - * This file contains all admin and callback functions for solution pack - * management. + * Admin and callback functions for solution pack management. */ /** @@ -36,8 +34,10 @@ function islandora_solution_packs_admin() { } /** - * A solution pack form for the given module, it lists all the given objects and - * their status, allowing the user to re-ingest them. + * A solution pack form for the given module. + * + * It lists all the given objects and their status, allowing the user to + * re-ingest them. * * @param array $form * The Drupal form definition. @@ -54,7 +54,7 @@ function islandora_solution_packs_admin() { * @return array * The Drupal form definition. */ -function islandora_solution_pack_form(array $form, array &$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) { +function islandora_solution_pack_form(array $form, array &$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) { // The order is important in terms of severity of the status, where higher // index indicates the status is more serious, this will be used to determine // what messages get displayed to the user. @@ -69,22 +69,22 @@ function islandora_solution_pack_form(array $form, array &$form_state, $solutio 'modified_datastream' => array( 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'image' => $warning_image, - 'button' => t("Reinstall objects") + 'button' => t("Reinstall objects"), ), 'out_of_date' => array( 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'image' => $warning_image, - 'button' => t("Reinstall objects") + 'button' => t("Reinstall objects"), ), 'missing_datastream' => array( 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'image' => $warning_image, - 'button' => t("Reinstall objects") + 'button' => t("Reinstall objects"), ), 'missing' => array( - 'solution_pack' => t( 'Some objects are missing and must be installed. See objects list for details.'), + 'solution_pack' => t('Some objects are missing and must be installed. See objects list for details.'), 'image' => $warning_image, - 'button' => t("Install objects") + 'button' => t("Install objects"), ), ); $status_severities = array_keys($status_info); @@ -94,7 +94,8 @@ function islandora_solution_pack_form(array $form, array &$form_state, $solutio $object_status = islandora_check_object_status($object); $object_status_info = $status_info[$object_status['status']]; $object_status_severity = array_search($object_status['status'], $status_severities); - // The solution pack status severity will be the highest severity of the objects. + // The solution pack status severity will be the highest severity of + // the objects. $solution_pack_status_severity = max($solution_pack_status_severity, $object_status_severity); $exists = $object_status['status'] != 'missing'; $label = $exists ? l($object->label, "islandora/object/{$object->id}") : $object->label; @@ -129,22 +130,24 @@ function islandora_solution_pack_form(array $form, array &$form_state, $solutio 'install_status' => array( '#markup' => t('Object status: !image !status', array( '!image' => $solution_pack_status_info['image'], - '!status' => $solution_pack_status_info['solution_pack'] + '!status' => $solution_pack_status_info['solution_pack'], )), '#prefix' => '
', '#suffix' => '
', ), 'table' => array( '#type' => 'item', - '#markup' => theme('table', array('header' => array(t('Label'), t('PID'), t('Status')), 'rows' => $table_rows)) + '#markup' => theme('table', array( + 'header' => array(t('Label'), t('PID'), t('Status')), + 'rows' => $table_rows)), ), 'submit' => array( '#type' => 'submit', '#name' => $solution_pack_module, '#value' => $solution_pack_status_info['button'], '#attributes' => array('class' => array('islandora-solution-pack-submit')), - ) - ) + ), + ), ); } @@ -175,8 +178,7 @@ function islandora_solution_pack_form_submit(array $form, array &$form_state) { } /** - * Batch operation used by the solution pack forms to ingest/reingest required - * object(s) + * Batch operation to ingest/reingest required object(s). * * @param NewFedoraObject $object * The object to ingest/reingest. @@ -209,16 +211,20 @@ function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject drupal_set_message(t($msg, array( '@pid' => $pid, '@label' => $label, - '!object_link' => $object_link + '!object_link' => $object_link, )), $status); } /** - * This is to be called from the solution pack's hook_install() - * and hook_uninstall() functions. It provides a convient way to have a - * solution pack's required objects ingested at install time. + * Install the given solution pack. * - * @param string $module_name + * This is to be called from the solution pack's hook_install() and + * hook_uninstall() functions. + * + * It provides a convient way to have a solution pack's required objects + * ingested at install time. + * + * @param string $module * The name of the module that is calling this function in its * install/unistall hooks. * @param string $op @@ -248,7 +254,7 @@ function islandora_install_solution_pack($module, $op = 'install') { drupal_set_message(st($msg, array( '@module' => $module_name, '!config_link' => $config_link, - '@admin_link' => $admin_link + '@admin_link' => $admin_link, )), 'error'); return; } @@ -264,7 +270,7 @@ function islandora_install_solution_pack($module, $op = 'install') { foreach ($objects as $object) { $query = $connection->api->a->findObjects('query', 'pid=' . $object->id); $already_exists = !empty($query['results']); - $label = $object->label; + $label = $object->label; $object_link = l($label, "islandora/object/{$object->id}"); if ($already_exists) { $object_status = islandora_check_object_status($object); @@ -313,28 +319,28 @@ function islandora_uninstall_solution_pack($module) { if (!islandora_describe_repository()) { $msg = '@module: Did not uninstall any objects. Could not connect to the '; $msg .= 'repository. Please check the settings on the !config_link page '; - $msg .= 'and uninstall the required objects manually if necessary.'; + $msg .= 'and uninstall the required objects manually if necessary.'; drupal_set_message(st($msg, array( '@module' => $module_name, - '!config_link' => $config_link + '!config_link' => $config_link, )), 'error'); return; } $connection = islandora_get_tuque_connection(); $required_objects = module_invoke($module, 'islandora_required_objects', $connection); $objects = $required_objects[$module]['objects']; - $existing_objects = array_filter($objects, function($o) use($connection) { - $param = "pid={$o->id}"; - $query = $connection->api->a->findObjects('query', $param); - return !empty($query['results']); - } - ); + $filter = function($o) use($connection) { + $param = "pid={$o->id}"; + $query = $connection->api->a->findObjects('query', $param); + return !empty($query['results']); + }; + $existing_objects = array_filter($objects, $filter); foreach ($existing_objects as $object) { $msg = '@module: Did not remove !object_link. It may be used by other sites.'; $object_link = l($object->label, "islandora/object/{$object->id}"); drupal_set_message(st($msg, array( '!object_link' => $object_link, - '@module' => $module_name + '@module' => $module_name, )), 'warning'); } } @@ -364,10 +370,16 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { $datastream_diff = array_diff($expected_datastreams, $existing_datastreams); if (!empty($datastream_diff)) { $status_friendly = format_plural(count($datastream_diff), 'Missing Datastream: %dsids.', 'Missing Datastreams: %dsids.', array('%dsids' => implode(', ', $datastream_diff))); - return array('status' => 'missing_datastream', 'status_friendly' => $status_friendly, 'data' => $datastream_diff); + return array( + 'status' => 'missing_datastream', + 'status_friendly' => $status_friendly, + 'data' => $datastream_diff, + ); } - $is_xml_datastream = function($ds) { return $ds->mimetype == 'text/xml'; }; + $is_xml_datastream = function($ds) { + return $ds->mimetype == 'text/xml'; + }; $xml_datastreams = array_filter(iterator_to_array($object_definition), $is_xml_datastream); $out_of_date_datastreams = array(); foreach ($xml_datastreams as $ds) { @@ -380,7 +392,11 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { if (count($out_of_date_datastreams)) { $status_friendly = format_plural(count($out_of_date_datastreams), 'Datastream out of date: %dsids.', 'Datastreams out of date: %dsids.', array('%dsids' => implode(', ', $out_of_date_datastreams))); - return array('status' => 'out_of_date', 'status_friendly' => $status_friendly, 'data' => $out_of_date_datastreams); + return array( + 'status' => 'out_of_date', + 'status_friendly' => $status_friendly, + 'data' => $out_of_date_datastreams, + ); } // This is a pretty heavy function, but I'm not sure a better way. If we have @@ -418,10 +434,13 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { } if (count($modified_datastreams)) { $status_friendly = format_plural(count($modified_datastreams), 'Modified Datastream: %dsids.', 'Modified Datastreams: %dsids.', array('%dsids' => implode(', ', $modified_datastreams))); - return array('status' => 'modified_datastream', 'data' => $modified_datastreams, 'status_friendly' => $status_friendly); + return array( + 'status' => 'modified_datastream', + 'data' => $modified_datastreams, + 'status_friendly' => $status_friendly, + ); } - // If not anything else we can assume its up to date. return array('status' => 'up_to_date', 'status_friendly' => t('Up-to-date')); } @@ -448,26 +467,21 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { * @param string $model * The table will be populated with viewers supporting this content model * - * @return + * @return array * A form api array which defines a themed table to select a viewer. */ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = NULL) { $form = array(); - // get viewers $viewers = islandora_get_viewers($mimetype, $model); if (!empty($viewers)) { - // add option for no viewer $no_viewer = array(); $no_viewer['none'] = array( 'label' => t('None'), - 'description' => t('Don\'t use a viewer for this solution pack.'), + 'description' => t("Don't use a viewer for this solution pack."), ); - // merge to viewers array $viewers = array_merge_recursive($no_viewer, $viewers); } - // get viewer settings $viewers_config = variable_get($variable_id, array()); - // viewer $form['viewers'] = array( '#type' => 'fieldset', '#title' => t('Viewers'), @@ -476,43 +490,33 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = ); if (!empty($viewers)) { - // viewers table $form['viewers'][$variable_id] = array( '#type' => 'item', '#title' => t('Select a viewer'), '#description' => t('Preferred viewer for your solution pack. These may be provided by third-party modules.'), - // This attribute is important to return the submitted values in a deeper - // nested arrays in '#tree' => TRUE, '#theme' => 'islandora_viewers_table', ); - // table loop foreach ($viewers as $name => $profile) { - $options[$name] = ''; - // machine name $form['viewers'][$variable_id]['name'][$name] = array( '#type' => 'hidden', '#value' => $name, ); - // label $form['viewers'][$variable_id]['label'][$name] = array( '#type' => 'item', '#markup' => $profile['label'], ); - // description $form['viewers'][$variable_id]['description'][$name] = array( '#type' => 'item', '#markup' => $profile['description'], ); - // configuration url $form['viewers'][$variable_id]['configuration'][$name] = array( '#type' => 'item', '#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '', ); } - // radios $form['viewers'][$variable_id]['default'] = array( '#type' => 'radios', '#options' => isset($options) ? $options : array(), @@ -520,11 +524,9 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = ); } else { - // No viewers found $form['viewers'][$variable_id . '_no_viewers'] = array( '#markup' => t('No viewers detected.'), ); - // remove viewers variable variable_del($variable_id); } return $form; @@ -541,20 +543,19 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = * be listed. * * @param string $mimetype - * Specify a mimetype to return only viewers that support this certain - * mimetype. + * Specify a mimetype to return only viewers that support this certain + * mimetype. * @param string $content_model - * Specify a content model to return only viewers that support the content - * model. + * Specify a content model to return only viewers that support the content + * model. * * @return array - * Viewer definitions, or FALSE if none are found. + * Viewer definitions, or FALSE if none are found. */ function islandora_get_viewers($mimetype = NULL, $content_model = NULL) { $viewers = array(); - // get all viewers $defined_viewers = module_invoke_all('islandora_viewer_info'); - // filter viewers by mimetype + // Filter viewers by MIME type. foreach ($defined_viewers as $key => $value) { $value['mimetype'] = isset($value['mimetype']) ? $value['mimetype'] : array(); $value['model'] = isset($value['model']) ? $value['model'] : array(); @@ -569,54 +570,39 @@ function islandora_get_viewers($mimetype = NULL, $content_model = NULL) { } /** - * Theme function for the admin primary display table - * - * @param type $variables - * render element: $form - * Contains the form array - * @return - * rendered form element - * - * @see islandora_large_image_admin() + * Implements theme_hook(). */ function theme_islandora_viewers_table($variables) { - // set form $form = $variables['form']; $rows = array(); - foreach ($form['name'] as $key => $element) { - // Do not take form control structures. if (is_array($element) && element_child($key)) { - // set rows $row = array(); $row[] = array('data' => drupal_render($form['default'][$key])); $row[] = array('data' => drupal_render($form['label'][$key])); $row[] = array('data' => drupal_render($form['description'][$key])); $row[] = array('data' => drupal_render($form['configuration'][$key])); - - // add to rows $rows[] = array('data' => $row); } } - - // Individual table headers. - // default | label | description | configuration $header = array(); $header[] = array('data' => t('Default')); $header[] = array('data' => t('Label')); $header[] = array('data' => t('Description')); $header[] = array('data' => t('Configuration')); - // render form $output = ''; - $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'islandora-viewers-table'))); + $output .= theme('table', array( + 'header' => $header, + 'rows' => $rows, + 'attributes' => array('id' => 'islandora-viewers-table'), + )); $output .= drupal_render_children($form); - return $output; } /** - * Gather information and return a rendered viewer + * Gather information and return a rendered viewer. * * @param array/string $params * Array or string with data the module needs in order to render a full viewer @@ -624,21 +610,17 @@ function theme_islandora_viewers_table($variables) { * The id of the Drupal variable the viewer settings are saved in * @param FedoraObject $fedora_object * The tuque object representing the fedora object being displayed - * @return + * + * @return string * The callback to the viewer module. Returns a rendered viewer. Returns FALSE * if no viewer is set. */ - function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_object = NULL) { - // get viewer from settings $settings = variable_get($variable_id, array()); - // make sure a viewer is set if (!empty($settings) AND $settings['default'] !== 'none') { - // get callback function $viewer_id = islandora_get_viewer_id($variable_id); if ($viewer_id AND $params !== NULL) { $callback = islandora_get_viewer_callback($viewer_id); - // call callback function return $callback($params, $fedora_object); } } @@ -649,8 +631,9 @@ function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_objec * Get id of the enabled viewer. * * @param string $variable_id - * The id of the Drupal variable the viewer settings are saved in - * @return + * The ID of the Drupal variable the viewer settings are saved in + * + * @return string * The enabled viewer id. Returns FALSE if no viewer config is set. */ function islandora_get_viewer_id($variable_id) { @@ -665,8 +648,9 @@ function islandora_get_viewer_id($variable_id) { * Get callback function for a viewer. * * @param string $viewer_id - * The ID of a viewer - * @return + * The ID of a viewer. + * + * @return string * The callback function as a string as defined by the viewer. */ function islandora_get_viewer_callback($viewer_id = NULL) { diff --git a/includes/tuque.inc b/includes/tuque.inc index 9da9da14..ec278192 100644 --- a/includes/tuque.inc +++ b/includes/tuque.inc @@ -2,13 +2,12 @@ /** * @file - * * This file contains a class to include the Tuque php library. */ $islandora_module_path = drupal_get_path('module', 'islandora'); -//do this until we expost these in a module or library +// Do this until we expose these in a module or library. @include_once 'sites/all/libraries/tuque/Datastream.php'; @include_once 'sites/all/libraries/tuque/FedoraApi.php'; @include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; @@ -59,7 +58,15 @@ class IslandoraTuque { */ public $repository = NULL; - function __construct($user = NULL, $url = NULL) { + /** + * Constructor. + * + * @param array $user + * A Drupal user. + * @param string $url + * The url to the fedora instance. + */ + public function __construct($user = NULL, $url = NULL) { if (!isset($user)) { global $user; } @@ -86,14 +93,23 @@ class IslandoraTuque { } } - static function exists() { + /** + * Checks if the Connection class exists. + * + * @returns bool + * TRUE if the Connection class exists FALSE otherwise. + */ + public static function exists() { return class_exists('RepositoryConnection'); } - static function getError() { + /** + * Displays and error for use when Tuque is not installed. + */ + public static function getError() { $islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora'); $tuque_link = l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque'); - $message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link)); + $message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array('!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link)); drupal_set_message(filter_xss($message), 'error', FALSE); } } diff --git a/includes/utilities.inc b/includes/utilities.inc index aa266d35..3679acf2 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -2,18 +2,21 @@ /** * @file - * Contains islandora utility functions + * Utility functions. * * @todo this file should be broken out into other files. */ /** - * Convert bytes to human readable format + * Convert bytes to human readable format. * * XXX: Shouldn't Drupal's format_size() be preferred? * - * @param integer bytes Size in bytes to convert + * @param int $bytes + * Size in bytes to convert + * * @return string + * Human readable size. */ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) { $kilobyte = 1024; @@ -48,12 +51,16 @@ function islandora_control_group_to_human_readable($control_group) { switch ($control_group) { case 'M': return 'Managed'; + case 'X': return 'Inline XML'; + case 'R': return 'Redirect'; + case 'E': return 'Externally Referenced'; + default: return $control_group; } @@ -65,7 +72,7 @@ function islandora_control_group_to_human_readable($control_group) { * @param string $pid * The object id to check. * - * @return boolean + * @return bool * TRUE if valid, FALSE otherwise. */ function islandora_is_valid_pid($pid) { @@ -78,7 +85,7 @@ function islandora_is_valid_pid($pid) { * @param string $dsid * The datastream id to check. * - * @return boolean + * @return bool * TRUE if valid, FALSE otherwise. */ function islandora_is_valid_dsid($dsid) { @@ -92,7 +99,8 @@ function islandora_is_valid_dsid($dsid) { * * @param string $url * A url to a Fedora repository, if NULL the default is used. - * @return + * + * @return array * Returns an array describing the repository. Returns FALSE if Fedora is down * or if the url is incorrect. */ @@ -119,7 +127,6 @@ function islandora_describe_repository($url = NULL) { * will be passed as arguments to module_invoke_all(). * * @see islandora_build_hook_list() - * To see how the hook list is generated. * * @param string $hook * A hook to call. @@ -182,7 +189,7 @@ function islandora_build_hook_list($hook, $refinements = array()) { */ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not - // really worry about changing the case. + // really worry about changing the case. return str_replace( // Any PID characters which are not valid in the name of a PHP function. array( @@ -217,10 +224,11 @@ function islandora_get_namespace($id) { } /** - * Checks the given namespace or PID is/has an accessible namespace as defined - * by the "islandora_pids_allowed" variable. + * Checks the given namespace/PID is/has an accessible namespace. * - * @param string $namespace + * Accessible is defined by the "islandora_pids_allowed" variable. + * + * @param string $id * Either a PID or namespace to check for accessibility. Any string like those * below are fine. * @@ -230,7 +238,7 @@ function islandora_get_namespace($id) { * 'islandora:1234', * @endcode * - * @return boolean + * @return bool * TRUE if accessible, FALSE otherwise. */ function islandora_namespace_accessible($id) { @@ -243,8 +251,9 @@ function islandora_namespace_accessible($id) { } /** - * Gets any objects that the given object has a - * (isMemberOf, isMemberOfCollection) relationship with. + * Gets any objects that the given object has a parent relationship with. + * + * Parent relationships are defined as (isMemberOf, isMemberOfCollection). * * This function gets its info from the RELS-EXT directly rather than through an * risearch. @@ -266,13 +275,15 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) { // @todo some logging would be nice, not sure what this throws. return array(); } - $collections = array_map(function($o) { return islandora_object_load($o['object']['value']); }, $collections); + $map = function($o) { + return islandora_object_load($o['object']['value']); + }; + $collections = array_map($map, $collections); return array_filter($collections); } /** - * Checks what datastreams the object already has against its required - * datastreams as defined by its content models, and returns their intersection. + * Gets the datastreams requirments that are missing. * * @param FedoraObject $object * The object which models will be used to determine what datastreams it @@ -294,21 +305,23 @@ function islandora_get_missing_datastreams_requirements(FedoraObject $object) { } /** + * Gets the required datastreams for the given object. + * * Checks the object's content model's for which datastream are expected to be * used with this object, as defined by the DS-COMPOSITE-MODEL datastreams. * * For duplicate datastreams in the models, the first model defines the * datastreams attributes regardless of what other models define. * This should be undefined behavior according to the documentation. - * @see https://wiki.duraspace.org/display/FEDORA34/Fedora+Digital+Object+Model#FedoraDigitalObjectModel-ContentModelObjectCMODEL + * + * @link https://wiki.duraspace.org/display/FEDORA34/Fedora+Digital+Object+Model#FedoraDigitalObjectModel-ContentModelObjectCMODEL @endlink + * + * @see islandora_get_required_datastreams_from_content_model() * * @param FedoraObject $object * The object which models will be used to determine what datastreams it * should have. * - * @see islandora_get_required_datastreams_from_content_model() from more - * details on the return value. - * * @return array * The DS-COMPOSITE-MODEL defined datastreams that are required for the given * object. @@ -336,14 +349,16 @@ function islandora_get_datastreams_requirements_from_models(array $models) { $dsids += islandora_get_datastreams_requirements_from_content_model($model); } } - // The AUDIT Datastream can not really be added, so it can't really be missing. + // The AUDIT Datastream can not really be added, so it can't really be + // missing. unset($dsids['AUDIT']); return $dsids; } /** - * Checks the given content model for which datastreams are required for - * subscribing objects, as defined by it's DS-COMPOSITE-MODEL datastream. + * Checks the given content model for which datastreams are required. + * + * As defined by it's DS-COMPOSITE-MODEL datastream. * * @todo Add support for fetching the schema information. * @@ -380,7 +395,7 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject $dsids[$dsid] = array( 'id' => $dsid, 'mime' => $mime, - 'optional' => ($optional == 'true') ? TRUE : FALSE + 'optional' => ($optional == 'true') ? TRUE : FALSE, ); } return $dsids; @@ -432,8 +447,11 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $label = isset($ds['label']) ? $ds['label'] : ''; $mimetype = isset($ds['mimetype']) ? $ds['mimetype'] : 'text/xml'; // Default 'Managed' - $control_group = (isset($ds['control_group']) && in_array($ds['control_group'], array('X', 'M', 'R', 'E'))) ? $ds['control_group'] : 'M'; - + $control_group = 'M'; + $groups = array('X', 'M', 'R', 'E'); + if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { + $control_group = $ds['control_group']; + } $ds_uri = FALSE; if (file_valid_uri($ds['datastream_file'])) { $datastream_file = $ds['datastream_file']; @@ -454,6 +472,7 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromUrl($datastream_file); } break; + case 'X': $datastream->setContentFromString(file_get_contents($datastream_file)); break; @@ -464,7 +483,7 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr } /** - * Displays the repository is inaccessible message + * Displays the repository is inaccessible message. * * Use anywhere we want to ensure a consitent error message when the repository * is not accessible. diff --git a/islandora.install b/islandora.install index 549f7e14..321f6f46 100644 --- a/islandora.install +++ b/islandora.install @@ -1,7 +1,8 @@ . */ -// Common datastreams +// Common datastreams. define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); -// Permissions +// Permissions. define('FEDORA_VIEW_OBJECTS', 'view fedora repository objects'); define('FEDORA_MANAGE_DATASTREAMS', 'view fedora repository datastreams'); define('FEDORA_METADATA_EDIT', 'edit fedora metadata'); @@ -34,7 +35,7 @@ define('FEDORA_INGEST', 'ingest fedora objects'); define('FEDORA_PURGE', 'delete fedora objects and datastreams'); define('FEDORA_MANAGE_PROPERTIES', 'manage object properties'); -// Hooks +// Hooks. define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); // @todo Add Documentation. @@ -108,7 +109,8 @@ function islandora_menu() { 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_object_manage_access_callback', - 'access arguments' => array(array(FEDORA_MANAGE_DATASTREAMS, FEDORA_MANAGE_PROPERTIES, FEDORA_ADD_DS), 2), + 'access arguments' => array( + array(FEDORA_MANAGE_DATASTREAMS, FEDORA_MANAGE_PROPERTIES, FEDORA_ADD_DS), 2), ); $items['islandora/object/%islandora_object/manage/datastreams'] = array( 'title' => 'Datastreams', @@ -141,7 +143,7 @@ function islandora_menu() { 'page arguments' => array('islandora_add_datastream_form', 2), 'type' => MENU_LOCAL_ACTION, 'access callback' => 'islandora_object_access_callback', - 'access arguments' => array(FEDORA_ADD_DS, 2) + 'access arguments' => array(FEDORA_ADD_DS, 2), ); $items['islandora/object/%islandora_object/manage/datastreams/add/autocomplete'] = array( 'file' => 'includes/add_datastream.form.inc', @@ -149,7 +151,7 @@ function islandora_menu() { 'page arguments' => array(2), 'type' => MENU_CALLBACK, 'access callback' => 'islandora_object_access_callback', - 'access arguments' => array(FEDORA_ADD_DS, 2) + 'access arguments' => array(FEDORA_ADD_DS, 2), ); $items['islandora/object/%islandora_object/datastream/%islandora_datastream'] = array( 'title' => 'View datastream', @@ -225,19 +227,19 @@ function islandora_admin_paths() { */ function islandora_theme() { return array( - // default object template + // Default object template. 'islandora_default' => array( 'file' => 'theme/theme.inc', 'template' => 'theme/islandora-object', 'variables' => array('islandora_object' => NULL), ), - // default edit page + // Default edit page. 'islandora_default_edit' => array( 'file' => 'theme/theme.inc', 'template' => 'theme/islandora-object-edit', 'variables' => array('islandora_object' => NULL), ), - // admin table for solution pack viewer selection + // Admin table for solution pack viewer selection. 'islandora_viewers_table' => array( 'file' => 'includes/solution_packs.inc', 'render element' => 'form', @@ -252,31 +254,31 @@ function islandora_permission() { return array( FEDORA_VIEW_OBJECTS => array( 'title' => t('View repository objects'), - 'description' => t('View objects in the repository. Note: Fedora XACML security policies may override this permission.') + 'description' => t('View objects in the repository. Note: Fedora XACML security policies may override this permission.'), ), FEDORA_MANAGE_DATASTREAMS => array( 'title' => t('Manage repository object datastreams'), - 'description' => t('Manage datastreams of objects in the repository. Note: Fedora XACML security policies may override this permission.') + 'description' => t('Manage datastreams of objects in the repository. Note: Fedora XACML security policies may override this permission.'), ), FEDORA_ADD_DS => array( 'title' => t('Add datastreams to repository objects'), - 'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.') + 'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.'), ), FEDORA_METADATA_EDIT => array( 'title' => t('Edit metadata'), - 'description' => t('Edit metadata for objects in the repository.') + 'description' => t('Edit metadata for objects in the repository.'), ), FEDORA_INGEST => array( 'title' => t('Create new repository objects'), - 'description' => t('Create new objects in the repository.') + 'description' => t('Create new objects in the repository.'), ), FEDORA_PURGE => array( 'title' => t('Permanently remove objects from the repository'), - 'description' => t('Permanently remove objects from the repository.') + 'description' => t('Permanently remove objects from the repository.'), ), FEDORA_MANAGE_PROPERTIES => array( 'title' => t('Manage object properties'), - 'description' => t('Modify object labels, owner IDs, and states.') + 'description' => t('Modify object labels, owner IDs, and states.'), ), ); } @@ -295,22 +297,18 @@ function islandora_forms($form_id) { } /** - * Checks whether the user can access the given object with the given - * permission. + * Checks whether the user can access the given object. * * Checks for object existance, accessiblitly, namespace permissions, * and user permissions * - * @see islandora_object_load() To find potential solutions to enable - * page not found errors. - * * @param string $perm * User permission to test for. * @param FedoraObject $object * The object to test, if NULL given the object doesn't exist or is * inaccessible. * - * @return boolean + * @return bool * TRUE if the user is allowed to access this object, FALSE otherwise. */ function islandora_object_access_callback($perm, $object = NULL) { @@ -325,15 +323,11 @@ function islandora_object_access_callback($perm, $object = NULL) { } /** - * Checks whether the user can access the given object and datastream with - * the given permission. + * Checks whether the user can access the given object and datastream. * * Checks for object existance, accessiblitly, namespace permissions, * and user permissions * - * @see islandora_object_load() To find potential solutions to enable page - * not found errors. - * * @param string $perm * The user permission to test for. * @param FedoraObject $object @@ -345,7 +339,7 @@ function islandora_object_access_callback($perm, $object = NULL) { * @param StdObject $account * The account to test permissions as or NULL for current user. * - * @return boolean + * @return bool * TRUE if the user is allowed to access this object, FALSE otherwise. */ function islandora_object_datastream_access_callback($perm, $object = NULL, $datastream = NULL, $account = NULL) { @@ -354,9 +348,9 @@ function islandora_object_datastream_access_callback($perm, $object = NULL, $dat } /** - * Checks whether the user can access the given object and datastream with - * the given permission. This function will validate and use a token if one - * is provided in the _GET array. + * Checks whether the user can access the given object and datastream. + * + * This function will validate and use a token if present in the GET parameters. * * Checks for object existance, accessiblitly, namespace permissions, * and user permissions @@ -380,22 +374,18 @@ function islandora_object_datastream_tokened_access_callback($perm, $object = NU } /** - * Checks whether the user can access the given object's manage tab - * with the given array of permissions. + * Checks whether the user can access the given object's manage tab. * * Checks for object existance, accessiblitly, namespace permissions, * and user permissions * - * @see islandora_object_load() To find potential solutions to enable - * page not found errors. - * * @param array $perms * Array of user permission to test for. * @param FedoraObject $object * The object to test, if NULL given the object doesn't exist or is * inaccessible. * - * @return boolean + * @return bool * TRUE if the user is allowed to access this object, FALSE otherwise. */ function islandora_object_manage_access_callback($perms, $object = NULL) { @@ -496,7 +486,7 @@ function islandora_view_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); drupal_set_title($object->label); drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); - // Optional pager parameters + // Optional pager parameters. $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $output = array(); @@ -532,13 +522,13 @@ function islandora_default_islandora_view_object($object) { } /** - * Just a wrapper around fetchings the IslandoraTuque object, with some very - * basic error logging. + * Just a wrapper around fetchings the IslandoraTuque object. * - * @param $user - * The user to connect as. + * Includes some very basic error logging. * - * @param $url + * @param object $user + * The user to connect as. + * @param string $url * The URL to connect to. * * @return IslandoraTuque @@ -550,7 +540,8 @@ function islandora_get_tuque_connection($user = NULL, $url = NULL) { if (IslandoraTuque::exists()) { try { $tuque = new IslandoraTuque($user, $url); - } catch (Exception $e) { + } + catch (Exception $e) { drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); } } @@ -562,8 +553,10 @@ function islandora_get_tuque_connection($user = NULL, $url = NULL) { } /** - * A helper function to get a connection and return an object for objects - * specified in the menu path as '%islandora_object'. + * Loads the object from the given ID if possible. + * + * Often used to get a connection and return an object for the one specified in + * the menu path as '%islandora_object'. * * @param string $object_id * The pid of an object in the menu path identified by '%islandora_object'. @@ -582,7 +575,8 @@ function islandora_object_load($object_id) { if ($tuque) { try { return $tuque->repository->getObject(urldecode($object_id)); - } catch (Exception $e) { + } + catch (Exception $e) { if ($e->getCode() == '404') { return FALSE; } @@ -599,6 +593,8 @@ function islandora_object_load($object_id) { } /** + * Load the the object using a token if passed as a GET parameter. + * * A helper function to get a connection and return an object using a token * for authentication. * @@ -625,6 +621,8 @@ function islandora_tokened_object_load($object_id, $map) { } /** + * Fetches a datastream object. + * * This datastream load must take in arguments in a different * order than the usual islandora_datastream_load. This is because * the function islandora_tokened_object_load needs DSID. It uses @@ -642,13 +640,16 @@ function islandora_tokened_object_load($object_id, $map) { * * @return FedoraDatastream * A datastream from Fedora. - * @see islandora_datastream_load + * + * @see islandora_datastream_load */ function islandora_tokened_datastream_load($datastream_id, $map) { return islandora_datastream_load($datastream_id, $map[2]); } /** + * Fetches a datastream object. + * * A helper function to get an datastream specified as '%islandora_datastream' * for the object specified in the menu path as '%islandora_object'. * @@ -677,28 +678,34 @@ function islandora_datastream_load($datastream_id, $object_id) { } /** + * Fetches the given datastream version from its datastream. + * * 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: * content); + // @TODO, need better check for $object + if ($object && $object[$dsid]) { + $doc = simplexml_load_string($object[$dsid]->content); } elseif (!empty($datastream_file)) { $doc = simplexml_load_file($datastream_file); } - if (!empty($doc) && $version = (int)$doc->attributes()->version) { + if (!empty($doc) && $version = (int) $doc->attributes()->version) { $return = $version; } @@ -710,18 +717,18 @@ function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL, */ function islandora_islandora_required_objects(IslandoraTuque $connection) { $module_path = drupal_get_path('module', 'islandora'); - // Root Collection + // Root Collection. $root_collection = $connection->repository->constructObject('islandora:root'); $root_collection->owner = 'fedoraAdmin'; $root_collection->label = 'Top-level Collection'; $root_collection->models = 'islandora:collectionCModel'; - // Collection Policy Datastream + // Collection Policy Datastream. $datastream = $root_collection->constructDatastream('COLLECTION_POLICY', 'X'); $datastream->label = 'Collection policy'; $datastream->mimetype = 'text/xml'; $datastream->setContentFromFile("$module_path/xml/islandora_collection_policy.xml", FALSE); $root_collection->ingestDatastream($datastream); - // TN Datastream + // TN Datastream. $datastream = $root_collection->constructDatastream('TN', 'M'); $datastream->label = 'Thumbnail'; $datastream->mimetype = 'image/png'; @@ -731,9 +738,9 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) { 'islandora' => array( 'title' => 'Islandora', 'objects' => array( - $root_collection - ) - ) + $root_collection, + ), + ), ); } @@ -789,9 +796,7 @@ function islandora_delete_datastream(FedoraDatastream &$datastream) { } /** - * Implements hook_cron() - * - * Removes expired authentication tokens. + * Implements hook_cron(). */ function islandora_cron() { module_load_include('inc', 'islandora', 'includes/authtokens'); diff --git a/islandora.rules.inc b/islandora.rules.inc index bda999b3..7a97e44a 100644 --- a/islandora.rules.inc +++ b/islandora.rules.inc @@ -1,5 +1,10 @@ array( 'type' => 'islandora_object', 'label' => t('Subject'), - 'description' => t('An object of which we should check the ' . - 'relationships (The "subject" of the relationship).'), + 'description' => t('An object of which we should check the relationships (The "subject" of the relationship).'), ), 'pred_uri' => array( 'type' => 'text', @@ -112,4 +116,3 @@ function islandora_object_remove_relationship($sub, $pred_uri, $pred, $object, $ function islandora_object_add_relationship($sub, $pred_uri, $pred, $object, $type) { $sub->relationships->add($pred_uri, $pred, $object, $type); } - diff --git a/theme/islandora-object-edit.tpl.php b/theme/islandora-object-edit.tpl.php index 266a1259..ea9cec64 100644 --- a/theme/islandora-object-edit.tpl.php +++ b/theme/islandora-object-edit.tpl.php @@ -2,9 +2,7 @@ /** * @file - * - * islandora-object-edit.tpl.php: This is a template for objects that do not - * have a module to registered to build their display. + * The default manage datastreams view for objects. * * islandora_object is a fedora tuque Object * $object->label @@ -17,7 +15,6 @@ * and each element has an array of values. * dc.title can have none, one or many titles * this is the case for all dc elements. - * */ ?> diff --git a/theme/islandora-object.tpl.php b/theme/islandora-object.tpl.php index 753232c5..13b40ba0 100644 --- a/theme/islandora-object.tpl.php +++ b/theme/islandora-object.tpl.php @@ -2,6 +2,7 @@ /** * @file + * The default object view. * * This is a template for objects that do not have a module to registered to * build their display. @@ -55,7 +56,6 @@ * foreach ($object as $ds) { * do something here * } - * */ ?>
diff --git a/theme/theme.inc b/theme/theme.inc index 7cac4d1a..1622d810 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -2,18 +2,13 @@ /** * @file - * * This file contains all theme and preprocess functions. */ /** - * Preprocess the edit template - * - * @global string $base_url - * @param array $variables - * theme variables for the edit template + * Implements hook_preprocess_theme(). */ -function islandora_preprocess_islandora_default_edit(&$variables) { +function islandora_preprocess_islandora_default_edit(array &$variables) { global $base_url; $islandora_object = $variables['islandora_object']; $datastreams = array(); @@ -32,27 +27,55 @@ function islandora_preprocess_islandora_default_edit(&$variables) { $rows = array(); foreach ($islandora_object as $ds) { $rows[] = array( - array('class' => 'datastream-id', 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view'))), - array('class' => 'datastream-label', 'data' => $ds->label), - array('class' => 'datastream-control', 'data' => islandora_control_group_to_human_readable($ds->controlGroup)), - array('class' => 'datastream-mime', 'data' => $ds->mimeType), - array('class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds)), - array('class' => 'datastream-download', 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download'))), - array('class' => 'datstream-edit', 'data' => islandora_datastream_edit_get_link($ds)), - array('class' => 'datastream-delete', 'data' => islandora_datastream_get_delete_link($ds)), + array( + 'class' => 'datastream-id', + 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view')), + ), + array( + 'class' => 'datastream-label', + 'data' => $ds->label, + ), + array( + 'class' => 'datastream-control', + 'data' => islandora_control_group_to_human_readable($ds->controlGroup), + ), + array( + 'class' => 'datastream-mime', + 'data' => $ds->mimeType, + ), + array( + 'class' => 'datastream-size', + 'data' => islandora_datastream_get_human_readable_size($ds), + ), + array( + 'class' => 'datastream-download', + 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download')), + ), + array( + 'class' => 'datstream-edit', + 'data' => islandora_datastream_edit_get_link($ds), + ), + array( + 'class' => 'datastream-delete', + 'data' => islandora_datastream_get_delete_link($ds), + ), ); } $caption = $islandora_object->label . ' - ' . $islandora_object->id; - $table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes); + $table = array( + 'colgroups' => NULL, + 'sticky' => TRUE, + 'empty' => 'Error loading datastreams', + 'caption' => $caption, + 'header' => $header, + 'rows' => $rows, + 'attributes' => $table_attributes, + ); $variables['datastream_table'] = $table; } - /** - * Preprocess for the default view template - * - * @global string $base_url - * @param array $variables + * Implements hook_preprocess_theme(). */ function islandora_preprocess_islandora_default(&$variables) { drupal_add_js('misc/form.js'); @@ -86,9 +109,10 @@ function islandora_preprocess_islandora_default(&$variables) { $variables['datastreams'] = $datastreams; try { $dc = $islandora_object['DC']->content; - $dc_object = DublinCore::import_from_xml_string($dc); - $dc_array = $dc_object->as_formatted_array(); - } catch (Exception $e) { + $dc_object = DublinCore::importFromXMLString($dc); + $dc_array = $dc_object->asArray(); + } + catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); } $variables['dc_array'] = isset($dc_array) ? $dc_array : array();