Browse Source

Merge pull request #258 from nigelgbanks/7.x-filename-conventions

7.x filename conventions and coding standards compliance
pull/259/head
Jonathan Green 12 years ago
parent
commit
c5758322eb
  1. 45
      includes/add_datastream.form.inc
  2. 20
      includes/authtokens.inc
  3. 14
      includes/breadcrumb.inc
  4. 12
      includes/datastream.inc
  5. 35
      includes/delete_datastream.form.inc
  6. 6
      includes/delete_object.form.inc
  7. 64
      includes/dublin_core.inc
  8. 64
      includes/ingest.form.inc
  9. 3
      includes/ingest.menu.inc
  10. 61
      includes/mime_detect.inc
  11. 30
      includes/object.entity_controller.inc
  12. 28
      includes/object_properties.form.inc
  13. 154
      includes/solution_packs.inc
  14. 26
      includes/tuque.inc
  15. 0
      includes/tuque_wrapper.inc
  16. 73
      includes/utilities.inc
  17. 12
      islandora.info
  18. 4
      islandora.install
  19. 139
      islandora.module
  20. 9
      islandora.rules.inc
  21. 6
      tests/authtokens.test
  22. 0
      tests/hooks.test
  23. 3
      tests/islandora_test.info
  24. 0
      tests/islandora_test.module
  25. 0
      tests/web_test_case.inc
  26. 5
      theme/islandora-object-edit.tpl.php
  27. 2
      theme/islandora-object.tpl.php
  28. 72
      theme/theme.inc

45
includes/add_datastream.form.inc

@ -2,7 +2,6 @@
/** /**
* @file * @file
*
* Functions for generating/validating/submitting the add datastream form. * 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['object'] = $object;
$form_state['datastream_requirements'] = islandora_get_missing_datastreams_requirements($object); $form_state['datastream_requirements'] = islandora_get_missing_datastreams_requirements($object);
$unused_datastreams = array_keys($form_state['datastream_requirements']); $unused_datastreams = array_keys($form_state['datastream_requirements']);
$unused_datastreams = array_map(function($o) { return "'$o'"; }, $unused_datastreams); $unused_datastreams = "'" . implode("', '", $unused_datastreams) . "'";
$unused_datastreams = implode(', ', $unused_datastreams);
$upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize'));
return array( return array(
'#redirect' => "islandora/object/{$object->id}", '#redirect' => "islandora/object/{$object->id}",
'#attributes' => array( '#attributes' => array(
'enctype' => 'multipart/form-data' 'enctype' => 'multipart/form-data',
), ),
'fieldset' => array( 'fieldset' => array(
'#type' => 'fieldset', '#type' => 'fieldset',
@ -41,12 +39,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#collapsed' => FALSE, '#collapsed' => FALSE,
'dsid' => array( 'dsid' => array(
'#title' => 'Datastream ID', '#title' => 'Datastream ID',
'#description' => t('An ID for this stream that is unique to this object.' . '#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: <b>@unused_dsids</b>.", array('@unused_dsids' => $unused_datastreams)),
'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: ' .
'<b>@unused_dsids</b>.',
array('@unused_dsids' => $unused_datastreams)
), ),
'#type' => 'textfield', '#type' => 'textfield',
'#size' => 64, '#size' => 64,
@ -57,7 +50,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'islandora_add_datastream_form_field_starts_with_a_letter', 'islandora_add_datastream_form_field_starts_with_a_letter',
'islandora_add_datastream_form_field_is_valid_dsid', 'islandora_add_datastream_form_field_is_valid_dsid',
), ),
'#autocomplete_path' => "islandora/object/{$object->id}/manage/datastreams/add/autocomplete" '#autocomplete_path' => "islandora/object/{$object->id}/manage/datastreams/add/autocomplete",
), ),
'label' => array( 'label' => array(
'#title' => 'Datastream Label', '#title' => 'Datastream Label',
@ -66,7 +59,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#maxlength' => 64, '#maxlength' => 64,
'#description' => t('A Human readable label'), '#description' => t('A Human readable label'),
'#type' => 'textfield', '#type' => 'textfield',
'#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash') '#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash'),
), ),
'file' => array( 'file' => array(
'#type' => 'managed_file', '#type' => 'managed_file',
@ -78,15 +71,14 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#upload_location' => 'temporary://', '#upload_location' => 'temporary://',
'#upload_validators' => array( '#upload_validators' => array(
'file_validate_extensions' => array(NULL), 'file_validate_extensions' => array(NULL),
// Assume its specified in MB // Assume its specified in MB.
'file_validate_size' => array($upload_size * 1024 * 1024), 'file_validate_size' => array($upload_size * 1024 * 1024),
), ),
), ),
'submit' => array( 'submit' => array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Add Datastream') '#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 * Checks if the given form field contains a valid datastream ID.
* datastream id.
* *
* @param array $element * @param array $element
* The form field to check. * 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 * Checks if the given datastream requires the upload to be a certian MIME type.
* certian MIME type.
* *
* @param array $form * @param array $form
* The Drupal 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 * Adds the new datastream based on the submitted values.
* datastreams at the moment. *
* Only creates managed datastreams at the moment.
* *
* @param array $form * @param array $form
* The Drupal form. * The Drupal form.
@ -200,9 +191,11 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) {
$ds->setContentFromFile($path); $ds->setContentFromFile($path);
$object->ingestDatastream($ds); $object->ingestDatastream($ds);
file_delete($file); file_delete($file);
} catch (exception $e) { }
catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); 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; return;
} }
drupal_set_message(t("Successfully Added Datastream!")); 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. * Callback for an autocomplete field in the admin add datastream form.
*
* It lists the missing required (may be optional) datastreams. * It lists the missing required (may be optional) datastreams.
* *
* @param FedoraObject $object * @param FedoraObject $object
@ -225,7 +219,10 @@ function islandora_add_datastream_form_autocomplete_callback(FedoraObject $objec
$dsids = array_combine($dsids, $dsids); $dsids = array_combine($dsids, $dsids);
$query = trim($query); $query = trim($query);
if (!empty($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); drupal_json_output($dsids);
} }

20
includes/islandora_authtokens.inc → includes/authtokens.inc

@ -1,9 +1,11 @@
<?php <?php
/** /**
* @file * @file
* Library functions for handling authentication tokens. * Handles the generation and validation of authentication tokens.
* These are to be used when dealing with applications *
* such as Djatoka that do not pass through credentials. * These are to be used when dealing with applications such as Djatoka that do
* not pass through credentials.
*/ */
// Token lifespan(seconds): after this duration the token expires. // Token lifespan(seconds): after this duration the token expires.
@ -12,6 +14,7 @@ define('TOKEN_TIMEOUT', 300);
/** /**
* Request Islandora to construct an object/datastream authentication token. * Request Islandora to construct an object/datastream authentication token.
*
* This token can later be turned in for access to the requested object or * This token can later be turned in for access to the requested object or
* datastream. * datastream.
* *
@ -19,7 +22,7 @@ define('TOKEN_TIMEOUT', 300);
* The Fedora PID to generate the token for. * The Fedora PID to generate the token for.
* @param string $dsid * @param string $dsid
* The Fedora datastream ID to generate the token for. * The Fedora datastream ID to generate the token for.
* @param integer $uses * @param int $uses
* Defaults to 1. * Defaults to 1.
* The number of uses the token should be used for. There are * The number of uses the token should be used for. There are
* times when this should be greater than 1: ie. Djatoka needs * times when this should be greater than 1: ie. Djatoka needs
@ -53,10 +56,11 @@ function islandora_get_object_token($pid, $dsid, $uses = 1) {
} }
/** /**
* Submit a token to islandora for authentication. Supply islandora with the * Submit a token to islandora for authentication.
* token and the object/datastream it is for and you will receive access if *
* authentication passes. Tokens can only be redeemed in a short window after * Supply islandora with the token and the object/datastream it is for and you
* their creation. * will receive access if authentication passes. Tokens can only be redeemed
* in a short window after their creation.
* *
* @param string $pid * @param string $pid
* The PID of the object to retrieve. * The PID of the object to retrieve.

14
includes/breadcrumb.inc

@ -2,16 +2,16 @@
/** /**
* @file * @file
*
* This file contains functions to create breadcrumbs on Islandora object pages. * This file contains functions to create breadcrumbs on Islandora object pages.
*/ */
/** /**
* Get an array of links to be passed to drupal_set_breadcrumb(). This is used * Get an array of links to be passed to drupal_set_breadcrumb().
* for generating the bread-crumbs for the view object page. *
* This is used for generating the bread-crumbs for the view object page.
* *
* Each link in the bread-crumbs represents a member of the given objects ancestry * Each link in the bread-crumbs represents a member of the given objects
* which is identified by any of the following RELS-EXT terms * ancestry which is identified by any of the following RELS-EXT terms
* (isMemberOf,isMemberOfCollection,isPartOf). * (isMemberOf,isMemberOfCollection,isPartOf).
* *
* @param FedoraObject $object * @param FedoraObject $object
@ -51,8 +51,8 @@ function islandora_get_breadcrumbs($object) {
* The fedora repository. * The fedora repository.
*/ */
function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) { function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) {
// Before executing the query, we hve a base case of accessing the // Before executing the query, we have a base case of accessing the top-level
// top-level collection // collection.
static $max_level = 10; static $max_level = 10;
static $level = -1; static $level = -1;

12
includes/datastream.inc

@ -2,9 +2,7 @@
/** /**
* @file * @file
* * Contains the admin form and callback functions for datastream manipulations.
* This file contains the admin form and callback functions for datastream
* manipulations.
*/ */
/** /**
@ -25,7 +23,7 @@ function islandora_download_datastream(FedoraDatastream $datastream) {
* *
* @param FedoraDatastream $datastream * @param FedoraDatastream $datastream
* The datastream to view/download. * The datastream to view/download.
* @param boolean $download * @param bool $download
* If TRUE the file is download to the user computer for viewing otherwise it * If TRUE the file is download to the user computer for viewing otherwise it
* will attempt to display in the browser natively. * will attempt to display in the browser natively.
*/ */
@ -117,12 +115,14 @@ function islandora_edit_datastream(FedoraDatastream $datastream) {
drupal_set_message(t('There are no edit methods specified for this datastream.')); drupal_set_message(t('There are no edit methods specified for this datastream.'));
drupal_goto("islandora/object/{$object->id}/manage/datastreams"); drupal_goto("islandora/object/{$object->id}/manage/datastreams");
break; break;
case 1: case 1:
// One registry implementation, go there // One registry implementation, go there.
drupal_goto($edit_registry[0]['url']); drupal_goto($edit_registry[0]['url']);
break; break;
default: default:
// Multiple edit routes registered // Multiple edit routes registered.
return islandora_edit_datastream_registry_render($edit_registry); return islandora_edit_datastream_registry_render($edit_registry);
} }
} }

35
includes/delete_datastream.form.inc

@ -2,9 +2,7 @@
/** /**
* @file * @file
* * The admin/confirmation form to delete/purge a datastream.
* This file contains the admin (confirmation) form and callback functions 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 * Submit handler for the delete datastream form.
* FedoraDatastream if possible. *
* Purges/Delete's the given FedoraDatastream if possible.
* *
* The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to * The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to
* whether the given FedoraDatastream * whether the given FedoraDatastream
* should be: blocked from purging; state set to 'Deleted'; or purged. * should be: blocked from purging; state set to 'Deleted'; or purged.
* *
* @see islandora_delete_datastream(). * @param array $form
* * The Drupal form.
* @param string $object_id * @param array $form_state
* ID of the object * The Drupal form state.
* @param string $datastream_id
* ID of the datastream
*/ */
function islandora_delete_datastream_form_submit(array $form, array &$form_state) { function islandora_delete_datastream_form_submit(array $form, array &$form_state) {
$datastream = $form_state['datastream']; $datastream = $form_state['datastream'];
@ -53,14 +50,22 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state
$deleted = FALSE; $deleted = FALSE;
try { try {
$deleted = islandora_delete_datastream($datastream); $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) { 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 { 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}"; $form_state['redirect'] = "islandora/object/{$object->id}";
} }

6
includes/delete_object.form.inc

@ -2,9 +2,7 @@
/** /**
* @file * @file
* * The admin/confirmation form to purge an object.
* This file contains the admin (confirmation) form and callback functions 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 * @param array $form
* The Drupal form. * The Drupal form.

64
includes/dublin_core.inc

@ -2,9 +2,9 @@
/** /**
* @file * @file
* Implements a simple class for working with Dublin Core data.
* *
* Implements a simple class for working with Dublin Core data and exporting it * Inspiration and design shamelessly stolen from the pyfedora
* back to XML. Inspiration and design shamelessly stolen from the pyfedora
* project at http://pypi.python.org/pypi/pyfedora/0.1.0 * project at http://pypi.python.org/pypi/pyfedora/0.1.0
*/ */
@ -33,34 +33,40 @@ class DublinCore {
public $owner; public $owner;
/** /**
* Constructs a DublinCore object from a Fedora_Item object and populates the * Constructor.
* $dc array.
* *
* @param string $dc_xml * @param string $dc_xml
* The Dublin Core XML.
*/ */
function DublinCore($dc_xml = NULL) { public function __construct($dc_xml = NULL) {
if (!empty($dc_xml)) { if (!empty($dc_xml)) {
$this->dc = self::import_from_xml_string($dc_xml); $this->dc = self::importFromXMLString($dc_xml);
} }
} }
/** /**
* Add Elements * Add an element.
* @param <type> $element_name *
* @param <type> $value * @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])) { if (is_string($value) && is_array($this->dc[$element_name])) {
$this->dc[$element_name][] = $value; $this->dc[$element_name][] = $value;
} }
} }
/** /**
* Replace the given DC element with the values in $values * Replace the given DC element with the given values.
* @param string $elemnt_name *
* @param array $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)) { if (is_array($values)) {
$this->dc[$element_name] = $values; $this->dc[$element_name] = $values;
} }
@ -70,11 +76,12 @@ class DublinCore {
} }
/** /**
* Serialize this object to XML and return it. * Serialize this object as an XML string.
* @param type $with_preamble *
* @return type * @return string
* The serialized XML.
*/ */
function as_xml($with_preamble = FALSE) { public function asXML() {
$dc_xml = new DomDocument(); $dc_xml = new DomDocument();
$oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc'); $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/'); $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() { public function asArray() {
}
function as_formatted_array() {
$dc_array = array(); $dc_array = array();
foreach ($this as $element) { foreach ($this as $element) {
if (!empty($element)) { if (!empty($element)) {
foreach ($element as $field => $values) { 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)) { if (is_array($values)) {
$value = ''; $value = '';
$i = 0; $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 * @param string $dc_xml
* Dublin Core XML.
*
* @return DublinCore * @return DublinCore
* The instantiated object.
*/ */
static function import_from_xml_string($dc_xml) { public static function importFromXMLString($dc_xml) {
$dc_doc = new DomDocument(); $dc_doc = new DomDocument();
if ($dc_doc->loadXML($dc_xml)) { if ($dc_doc->loadXML($dc_xml)) {
$oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*'); $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*');
$new_dc = new DublinCore(); $new_dc = new DublinCore();
foreach ($oai_dc as $child) { foreach ($oai_dc as $child) {
if (isset($new_dc->dc[$child->nodeName])) { if (isset($new_dc->dc[$child->nodeName])) {
array_push($new_dc->dc[$child->nodeName], $child->nodeValue); array_push($new_dc->dc[$child->nodeName], $child->nodeValue);

64
includes/ingest.form.inc

@ -2,14 +2,14 @@
/** /**
* @file * @file
* * Defines the multi-page ingest form and any relevant hooks and functions.
* Defines the multi-page ingest form and any relevant hooks and functions for
* defining the multi-page ingest forms.
*/ */
/** /**
* Ingest form build function. Initializes the form state, and builds the * Ingest form build function.
* initial list of steps, excutes the current step. *
* Initializes the form state, and builds the initial list of steps, excutes
* the current step.
* *
* @param array $form * @param array $form
* The drupal form. * The drupal form.
@ -32,9 +32,7 @@
*/ */
function islandora_ingest_form(array $form, array &$form_state, array $configuration) { function islandora_ingest_form(array $form, array &$form_state, array $configuration) {
islandora_ingest_form_init_form_state($form_state, $configuration); islandora_ingest_form_init_form_state($form_state, $configuration);
$form = islandora_ingest_form_execute_step($form, $form_state); $form = islandora_ingest_form_execute_step($form, $form_state);
return $form; return $form;
} }
@ -71,7 +69,9 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array
// Use namespace if ID not given. // Use namespace if ID not given.
$namespace = isset($configuration['namespace']) && !isset($id) ? $configuration['namespace'] : $id; $namespace = isset($configuration['namespace']) && !isset($id) ? $configuration['namespace'] : $id;
$label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; $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']); $relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']);
$object = islandora_prepare_new_object($namespace, $label, array(), array(), $relationships); $object = islandora_prepare_new_object($namespace, $label, array(), array(), $relationships);
$form_state['islandora'] = array( $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 * Executes the current step.
* additonal elements required for the step to function. *
* Builds the form definition and appends any additonal elements required for
* the step to function.
* *
* @param array $form * @param array $form
* The drupal 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; $args = isset($step_info['args']) ? array_merge($args, $step_info['args']) : $args;
$form = call_user_func_array($step_info['form_id'], $args); $form = call_user_func_array($step_info['form_id'], $args);
return islandora_ingest_form_stepify($form, $form_state, $step_info); return islandora_ingest_form_stepify($form, $form_state, $step_info);
case 'batch': case 'batch':
// @todo Implement if possible. // @todo Implement if possible.
break; break;
@ -187,11 +190,19 @@ function islandora_ingest_form_previous_button() {
// convert all required fields to use #element_validation functions, and // convert all required fields to use #element_validation functions, and
// Remove the need for #limit_validation_errors. Or maybe there is some // Remove the need for #limit_validation_errors. Or maybe there is some
// other solution, regardless of what it is, it won't be standard. // 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) { if ($step_id === NULL) {
$step_id = islandora_ingest_form_get_step_id($form_state); $step_id = islandora_ingest_form_get_step_id($form_state);
} }
@ -240,7 +251,7 @@ function islandora_ingest_form_next_button(array $step_info) {
'#value' => t('Next'), '#value' => t('Next'),
'#name' => 'next', '#name' => 'next',
'#validate' => $validate, '#validate' => $validate,
'#submit' => $submit '#submit' => $submit,
); );
} }
@ -305,7 +316,7 @@ function islandora_ingest_form_ingest_button(array $step_info) {
'#name' => 'ingest', '#name' => 'ingest',
'#value' => t('Ingest'), '#value' => t('Ingest'),
'#validate' => $validate, '#validate' => $validate,
'#submit' => $submit '#submit' => $submit,
); );
} }
@ -324,8 +335,10 @@ function islandora_ingest_form_submit(array $form, array &$form_state) {
try { try {
islandora_add_object($object); islandora_add_object($object);
$form_state['redirect'] = "islandora/object/{$object->id}"; $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); 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'); 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 * Gets a reference to the stored NewFedoraObject's.
* when the final step submits.
* *
* @param array $form_state * @param array $form_state
* The drupal 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 * Get the step info of the given step or the current step if none is given.
* none is given.
* *
* @param array $form_state * @param array $form_state
* The drupal form state. * The drupal form state.
* @param int $step * @param int $step
* The index of the step to get. * The index of the step to get.
* *
* @return integer * @return int
* The step info of the requested step if found, NULL otherwise. * The step info of the requested step if found, NULL otherwise.
*/ */
function islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) { 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) { function &islandora_ingest_form_get_step_storage(array &$form_state, $step_id = NULL) {
if ($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) { function islandora_ingest_form_step_form_load_include(array &$form_state) {
form_load_include($form_state, 'inc', 'islandora', 'includes/ingest.form'); form_load_include($form_state, 'inc', 'islandora', 'includes/ingest.form');
$step_info = islandora_ingest_form_get_step_info($form_state); $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'])) { if (isset($step_info['file']) && isset($step_info['module'])) {
$matches = array(); $matches = array();
preg_match('/^(.*)\.(.*)$/', $step_info['file'], $matches); 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. * The sort order is undefined for steps which have the same weight.
* *
* @param array $form_state * @param array $form_state
* All available form_state options used to build the multi-paged ingest process. * The Drupal form state.
* *
* @return array * @return array
* The list of sorted ingest steps as defined by all implementers * The list of sorted ingest steps as defined by all implementers

3
includes/ingest.menu.inc

@ -2,7 +2,6 @@
/** /**
* @file * @file
*
* Ingest Menu callback hooks. * Ingest Menu callback hooks.
*/ */
@ -57,7 +56,7 @@ function islandora_ingest_get_configuration() {
* @param array $configuration * @param array $configuration
* The key value pairs that are used to build the multi-paged ingest process. * 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. * TRUE if the configuration is valid, FALSE otherwise.
*/ */
function islandora_valid_ingest_configuration(array $configuration) { function islandora_valid_ingest_configuration(array $configuration) {

61
includes/mime_detect.inc

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @file * @file
* Class for determining MIME types and file extensions.
*
* This class inspired by Chris Jean's work, here: * This class inspired by Chris Jean's work, here:
* http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/ * http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/
* *
@ -19,7 +19,6 @@
* *
* Drupal 7 will have better mime handlers. See: * Drupal 7 will have better mime handlers. See:
* http://api.drupal.org/api/function/file_default_mimetype_mapping/7 * http://api.drupal.org/api/function/file_default_mimetype_mapping/7
*
*/ */
class MimeDetect { class MimeDetect {
@ -199,7 +198,7 @@ class MimeDetect {
protected $etcMimeTypes = '/etc/mime.types'; protected $etcMimeTypes = '/etc/mime.types';
/** /**
* Construtor * Construtor.
*/ */
public function __construct() { public function __construct() {
@ -213,12 +212,11 @@ class MimeDetect {
} }
/** /**
* description: returns a mimetype associated with the file extension of * Gets MIME type associated with the give file's extension.
* $filename
* *
* @param string $filename * @param string $filename
* The filename * The filename
* @param boolean $debug * @param bool $debug
* Returns a debug array. * Returns a debug array.
* *
* @return mixed * @return mixed
@ -263,12 +261,15 @@ class MimeDetect {
} }
/** /**
* function: get_extension * Gets one valid file extension for a given MIME type.
* description: returns *one* valid file extension for a given $mime_type
* *
* @param type $mime_type * @param string $mime_type
* @param type $debug * The MIME type.
* @return type * @param bool $debug
* Generated debug information?
*
* @return string
* The file extensions associated with the given MIME type.
*/ */
public function getExtension($mime_type, $debug = FALSE) { public function getExtension($mime_type, $debug = FALSE) {
@ -296,11 +297,14 @@ class MimeDetect {
} }
/** /**
* function: systemMimetypeExtensions * Gets an associative array of MIME type and extension associations.
* 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 * Users the system mime.types file, or a local mime.types if one is found
* __constuctor). * @see MIMEDetect::__constuctor()
* return: array of mimetype => extension *
* @return array
* An associative array where the keys are MIME types and the values
* extensions.
*/ */
protected function systemMimetypeExtensions() { protected function systemMimetypeExtensions() {
$out = array(); $out = array();
@ -328,11 +332,14 @@ class MimeDetect {
} }
/** /**
* function: systemMimetypeExtensions * Gets a associative array of extensions and MIME types.
* 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 * Users the system mime.types file, or a local mime.types if one is found
* __constuctor). * @see MIMEDetect::__constuctor()
* return: array of extension => mimetype *
* @return array
* An associative array where the keys are extensions and the values
* MIME types.
*/ */
protected function systemExtensionMimetypes() { protected function systemExtensionMimetypes() {
$out = array(); $out = array();
@ -340,20 +347,22 @@ class MimeDetect {
$file = fopen($this->etcMimeTypes, 'r'); $file = fopen($this->etcMimeTypes, 'r');
while (($line = fgets($file)) !== FALSE) { while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line)); $line = trim(preg_replace('/#.*/', '', $line));
if (!$line) if (!$line) {
continue; continue;
}
$parts = preg_split('/\s+/', $line); $parts = preg_split('/\s+/', $line);
if (count($parts) == 1) if (count($parts) == 1) {
continue; continue;
}
// A single part means a mimetype without extensions, which we ignore. // A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts); $type = array_shift($parts);
foreach ($parts as $part) foreach ($parts as $part) {
$out[$part] = $type; $out[$part] = $type;
} }
}
fclose($file); fclose($file);
} }
return $out; return $out;
} }
} }

30
includes/islandora_object.entity_controller.inc → includes/object.entity_controller.inc

@ -1,13 +1,30 @@
<?php <?php
/** /**
* Very basic entity controller... * @file
* Very basic entity controller.
*/ */
class IslandoraObjectEntityController implements DrupalEntityControllerInterface { class IslandoraObjectEntityController implements DrupalEntityControllerInterface {
public function __construct($entityType) {
/**
* Constructor.
*
* @param string $entity_type
* The type of entity.
*/
public function __construct($entity_type) {
// No-op... // No-op...
} }
/**
* Load all the entities.
*
* @param array $ids
* The ID's of the entities.
* @param array $conditions
* The conditions to apply.
*/
public function load($ids = array(), $conditions = array()) { public function load($ids = array(), $conditions = array()) {
if (!empty($conditions)) { if (!empty($conditions)) {
throw new Exception('Conditions not implemented.'); throw new Exception('Conditions not implemented.');
@ -24,8 +41,13 @@ class IslandoraObjectEntityController implements DrupalEntityControllerInterface
return $loaded; return $loaded;
} }
/**
* Reset the cache.
*
* @param array $ids
* The ID's of the entities.
*/
public function resetCache(array $ids = NULL) { public function resetCache(array $ids = NULL) {
// no-op // no-op.
} }
} }

28
includes/object_properties.form.inc

@ -2,7 +2,6 @@
/** /**
* @file * @file
*
* Contains admin form functions for editing an object's properties. * Contains admin form functions for editing an object's properties.
*/ */
@ -25,18 +24,18 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor
return array( return array(
'pid' => array( 'pid' => array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => $object->id '#value' => $object->id,
), ),
'object_label' => array( 'object_label' => array(
'#title' => t('Item Label'), '#title' => t('Item Label'),
'#default_value' => $object->label, '#default_value' => $object->label,
'#required' => 'TRUE', '#required' => 'TRUE',
'#description' => t('A Human readable label'), '#description' => t('A Human readable label'),
// Double the normal length // Double the normal length.
'#size' => 120, '#size' => 120,
// Max length for a Fedora Label // Max length for a Fedora Label.
'#maxlength' => 255, '#maxlength' => 255,
'#type' => 'textfield' '#type' => 'textfield',
), ),
// @todo Make this into an autocomplete field that list the users in the // @todo Make this into an autocomplete field that list the users in the
// system as well. // system as well.
@ -45,7 +44,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor
'#default_value' => $object->owner, '#default_value' => $object->owner,
'#required' => FALSE, '#required' => FALSE,
'#description' => t('The owner id'), '#description' => t('The owner id'),
'#type' => 'textfield' '#type' => 'textfield',
), ),
'object_state' => array( 'object_state' => array(
'#title' => t('State'), '#title' => t('State'),
@ -53,18 +52,18 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor
'#required' => TRUE, '#required' => TRUE,
'#description' => t('The items state one of active, inactive or deleted'), '#description' => t('The items state one of active, inactive or deleted'),
'#type' => 'select', '#type' => 'select',
'#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted') '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'),
), ),
'submit' => array( 'submit' => array(
'#type' => 'submit', '#type' => 'submit',
'#value' => 'Update Properties' '#value' => 'Update Properties',
), ),
'delete' => array( 'delete' => array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Delete'), '#value' => t('Delete'),
'#submit' => array('islandora_object_properties_form_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 { try {
$object->owner = $owner; $object->owner = $owner;
drupal_set_message(t('Successfully updated owner %s', array('%s' => $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()))); 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 { try {
$object->state = $state; $object->state = $state;
drupal_set_message(t('Successfully updated state %s', array('%s' => $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()))); 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 { try {
$object->label = $label; $object->label = $label;
drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($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()))); form_set_error(t('Error updating label %s', array('%s' => $e->getMessage())));
} }
} }

154
includes/solution_packs.inc

@ -2,9 +2,7 @@
/** /**
* @file * @file
* * Admin and callback functions for solution pack management.
* This file contains all 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 * A solution pack form for the given module.
* their status, allowing the user to re-ingest them. *
* It lists all the given objects and their status, allowing the user to
* re-ingest them.
* *
* @param array $form * @param array $form
* The Drupal form definition. * The Drupal form definition.
@ -69,22 +69,22 @@ function islandora_solution_pack_form(array $form, array &$form_state, $solutio
'modified_datastream' => array( 'modified_datastream' => array(
'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'),
'image' => $warning_image, 'image' => $warning_image,
'button' => t("Reinstall objects") 'button' => t("Reinstall objects"),
), ),
'out_of_date' => array( 'out_of_date' => array(
'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'),
'image' => $warning_image, 'image' => $warning_image,
'button' => t("Reinstall objects") 'button' => t("Reinstall objects"),
), ),
'missing_datastream' => array( 'missing_datastream' => array(
'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'), 'solution_pack' => t('Some objects must be reinstalled. See objects list for details.'),
'image' => $warning_image, 'image' => $warning_image,
'button' => t("Reinstall objects") 'button' => t("Reinstall objects"),
), ),
'missing' => array( '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, 'image' => $warning_image,
'button' => t("Install objects") 'button' => t("Install objects"),
), ),
); );
$status_severities = array_keys($status_info); $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 = islandora_check_object_status($object);
$object_status_info = $status_info[$object_status['status']]; $object_status_info = $status_info[$object_status['status']];
$object_status_severity = array_search($object_status['status'], $status_severities); $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); $solution_pack_status_severity = max($solution_pack_status_severity, $object_status_severity);
$exists = $object_status['status'] != 'missing'; $exists = $object_status['status'] != 'missing';
$label = $exists ? l($object->label, "islandora/object/{$object->id}") : $object->label; $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( 'install_status' => array(
'#markup' => t('<strong>Object status:</strong> !image !status', array( '#markup' => t('<strong>Object status:</strong> !image !status', array(
'!image' => $solution_pack_status_info['image'], '!image' => $solution_pack_status_info['image'],
'!status' => $solution_pack_status_info['solution_pack'] '!status' => $solution_pack_status_info['solution_pack'],
)), )),
'#prefix' => '<div class="islandora-solution-pack-install-status">', '#prefix' => '<div class="islandora-solution-pack-install-status">',
'#suffix' => '</div>', '#suffix' => '</div>',
), ),
'table' => array( 'table' => array(
'#type' => 'item', '#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( 'submit' => array(
'#type' => 'submit', '#type' => 'submit',
'#name' => $solution_pack_module, '#name' => $solution_pack_module,
'#value' => $solution_pack_status_info['button'], '#value' => $solution_pack_status_info['button'],
'#attributes' => array('class' => array('islandora-solution-pack-submit')), '#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 * Batch operation to ingest/reingest required object(s).
* object(s)
* *
* @param NewFedoraObject $object * @param NewFedoraObject $object
* The object to ingest/reingest. * The object to ingest/reingest.
@ -209,16 +211,20 @@ function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject
drupal_set_message(t($msg, array( drupal_set_message(t($msg, array(
'@pid' => $pid, '@pid' => $pid,
'@label' => $label, '@label' => $label,
'!object_link' => $object_link '!object_link' => $object_link,
)), $status); )), $status);
} }
/** /**
* This is to be called from the solution pack's hook_install() * Install the given solution pack.
* and hook_uninstall() functions. It provides a convient way to have a
* solution pack's required objects ingested at install time.
* *
* @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 * The name of the module that is calling this function in its
* install/unistall hooks. * install/unistall hooks.
* @param string $op * @param string $op
@ -248,7 +254,7 @@ function islandora_install_solution_pack($module, $op = 'install') {
drupal_set_message(st($msg, array( drupal_set_message(st($msg, array(
'@module' => $module_name, '@module' => $module_name,
'!config_link' => $config_link, '!config_link' => $config_link,
'@admin_link' => $admin_link '@admin_link' => $admin_link,
)), 'error'); )), 'error');
return; return;
} }
@ -316,25 +322,25 @@ function islandora_uninstall_solution_pack($module) {
$msg .= 'and uninstall the required objects manually if necessary.'; $msg .= 'and uninstall the required objects manually if necessary.';
drupal_set_message(st($msg, array( drupal_set_message(st($msg, array(
'@module' => $module_name, '@module' => $module_name,
'!config_link' => $config_link '!config_link' => $config_link,
)), 'error'); )), 'error');
return; return;
} }
$connection = islandora_get_tuque_connection(); $connection = islandora_get_tuque_connection();
$required_objects = module_invoke($module, 'islandora_required_objects', $connection); $required_objects = module_invoke($module, 'islandora_required_objects', $connection);
$objects = $required_objects[$module]['objects']; $objects = $required_objects[$module]['objects'];
$existing_objects = array_filter($objects, function($o) use($connection) { $filter = function($o) use($connection) {
$param = "pid={$o->id}"; $param = "pid={$o->id}";
$query = $connection->api->a->findObjects('query', $param); $query = $connection->api->a->findObjects('query', $param);
return !empty($query['results']); return !empty($query['results']);
} };
); $existing_objects = array_filter($objects, $filter);
foreach ($existing_objects as $object) { foreach ($existing_objects as $object) {
$msg = '@module: Did not remove !object_link. It may be used by other sites.'; $msg = '@module: Did not remove !object_link. It may be used by other sites.';
$object_link = l($object->label, "islandora/object/{$object->id}"); $object_link = l($object->label, "islandora/object/{$object->id}");
drupal_set_message(st($msg, array( drupal_set_message(st($msg, array(
'!object_link' => $object_link, '!object_link' => $object_link,
'@module' => $module_name '@module' => $module_name,
)), 'warning'); )), 'warning');
} }
} }
@ -364,10 +370,16 @@ function islandora_check_object_status(NewFedoraObject $object_definition) {
$datastream_diff = array_diff($expected_datastreams, $existing_datastreams); $datastream_diff = array_diff($expected_datastreams, $existing_datastreams);
if (!empty($datastream_diff)) { if (!empty($datastream_diff)) {
$status_friendly = format_plural(count($datastream_diff), 'Missing Datastream: %dsids.', 'Missing Datastreams: %dsids.', array('%dsids' => implode(', ', $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); $xml_datastreams = array_filter(iterator_to_array($object_definition), $is_xml_datastream);
$out_of_date_datastreams = array(); $out_of_date_datastreams = array();
foreach ($xml_datastreams as $ds) { foreach ($xml_datastreams as $ds) {
@ -380,7 +392,11 @@ function islandora_check_object_status(NewFedoraObject $object_definition) {
if (count($out_of_date_datastreams)) { 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))); $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 // 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)) { if (count($modified_datastreams)) {
$status_friendly = format_plural(count($modified_datastreams), 'Modified Datastream: %dsids.', 'Modified Datastreams: %dsids.', array('%dsids' => implode(', ', $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. // If not anything else we can assume its up to date.
return array('status' => 'up_to_date', 'status_friendly' => t('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 * @param string $model
* The table will be populated with viewers supporting this content 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. * A form api array which defines a themed table to select a viewer.
*/ */
function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = NULL) { function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = NULL) {
$form = array(); $form = array();
// get viewers
$viewers = islandora_get_viewers($mimetype, $model); $viewers = islandora_get_viewers($mimetype, $model);
if (!empty($viewers)) { if (!empty($viewers)) {
// add option for no viewer
$no_viewer = array(); $no_viewer = array();
$no_viewer['none'] = array( $no_viewer['none'] = array(
'label' => t('None'), '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); $viewers = array_merge_recursive($no_viewer, $viewers);
} }
// get viewer settings
$viewers_config = variable_get($variable_id, array()); $viewers_config = variable_get($variable_id, array());
// viewer
$form['viewers'] = array( $form['viewers'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Viewers'), '#title' => t('Viewers'),
@ -476,43 +490,33 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model =
); );
if (!empty($viewers)) { if (!empty($viewers)) {
// viewers table
$form['viewers'][$variable_id] = array( $form['viewers'][$variable_id] = array(
'#type' => 'item', '#type' => 'item',
'#title' => t('Select a viewer'), '#title' => t('Select a viewer'),
'#description' => t('Preferred viewer for your solution pack. These may be provided by third-party modules.'), '#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, '#tree' => TRUE,
'#theme' => 'islandora_viewers_table', '#theme' => 'islandora_viewers_table',
); );
// table loop
foreach ($viewers as $name => $profile) { foreach ($viewers as $name => $profile) {
$options[$name] = ''; $options[$name] = '';
// machine name
$form['viewers'][$variable_id]['name'][$name] = array( $form['viewers'][$variable_id]['name'][$name] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => $name, '#value' => $name,
); );
// label
$form['viewers'][$variable_id]['label'][$name] = array( $form['viewers'][$variable_id]['label'][$name] = array(
'#type' => 'item', '#type' => 'item',
'#markup' => $profile['label'], '#markup' => $profile['label'],
); );
// description
$form['viewers'][$variable_id]['description'][$name] = array( $form['viewers'][$variable_id]['description'][$name] = array(
'#type' => 'item', '#type' => 'item',
'#markup' => $profile['description'], '#markup' => $profile['description'],
); );
// configuration url
$form['viewers'][$variable_id]['configuration'][$name] = array( $form['viewers'][$variable_id]['configuration'][$name] = array(
'#type' => 'item', '#type' => 'item',
'#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '', '#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '',
); );
} }
// radios
$form['viewers'][$variable_id]['default'] = array( $form['viewers'][$variable_id]['default'] = array(
'#type' => 'radios', '#type' => 'radios',
'#options' => isset($options) ? $options : array(), '#options' => isset($options) ? $options : array(),
@ -520,11 +524,9 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model =
); );
} }
else { else {
// No viewers found
$form['viewers'][$variable_id . '_no_viewers'] = array( $form['viewers'][$variable_id . '_no_viewers'] = array(
'#markup' => t('No viewers detected.'), '#markup' => t('No viewers detected.'),
); );
// remove viewers variable
variable_del($variable_id); variable_del($variable_id);
} }
return $form; return $form;
@ -552,9 +554,8 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model =
*/ */
function islandora_get_viewers($mimetype = NULL, $content_model = NULL) { function islandora_get_viewers($mimetype = NULL, $content_model = NULL) {
$viewers = array(); $viewers = array();
// get all viewers
$defined_viewers = module_invoke_all('islandora_viewer_info'); $defined_viewers = module_invoke_all('islandora_viewer_info');
// filter viewers by mimetype // Filter viewers by MIME type.
foreach ($defined_viewers as $key => $value) { foreach ($defined_viewers as $key => $value) {
$value['mimetype'] = isset($value['mimetype']) ? $value['mimetype'] : array(); $value['mimetype'] = isset($value['mimetype']) ? $value['mimetype'] : array();
$value['model'] = isset($value['model']) ? $value['model'] : 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 * Implements theme_hook().
*
* @param type $variables
* render element: $form
* Contains the form array
* @return
* rendered form element
*
* @see islandora_large_image_admin()
*/ */
function theme_islandora_viewers_table($variables) { function theme_islandora_viewers_table($variables) {
// set form
$form = $variables['form']; $form = $variables['form'];
$rows = array(); $rows = array();
foreach ($form['name'] as $key => $element) { foreach ($form['name'] as $key => $element) {
// Do not take form control structures.
if (is_array($element) && element_child($key)) { if (is_array($element) && element_child($key)) {
// set rows
$row = array(); $row = array();
$row[] = array('data' => drupal_render($form['default'][$key])); $row[] = array('data' => drupal_render($form['default'][$key]));
$row[] = array('data' => drupal_render($form['label'][$key])); $row[] = array('data' => drupal_render($form['label'][$key]));
$row[] = array('data' => drupal_render($form['description'][$key])); $row[] = array('data' => drupal_render($form['description'][$key]));
$row[] = array('data' => drupal_render($form['configuration'][$key])); $row[] = array('data' => drupal_render($form['configuration'][$key]));
// add to rows
$rows[] = array('data' => $row); $rows[] = array('data' => $row);
} }
} }
// Individual table headers.
// default | label | description | configuration
$header = array(); $header = array();
$header[] = array('data' => t('Default')); $header[] = array('data' => t('Default'));
$header[] = array('data' => t('Label')); $header[] = array('data' => t('Label'));
$header[] = array('data' => t('Description')); $header[] = array('data' => t('Description'));
$header[] = array('data' => t('Configuration')); $header[] = array('data' => t('Configuration'));
// render form
$output = ''; $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); $output .= drupal_render_children($form);
return $output; return $output;
} }
/** /**
* Gather information and return a rendered viewer * Gather information and return a rendered viewer.
* *
* @param array/string $params * @param array/string $params
* Array or string with data the module needs in order to render a full viewer * 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 * The id of the Drupal variable the viewer settings are saved in
* @param FedoraObject $fedora_object * @param FedoraObject $fedora_object
* The tuque object representing the fedora object being displayed * The tuque object representing the fedora object being displayed
* @return *
* @return string
* The callback to the viewer module. Returns a rendered viewer. Returns FALSE * The callback to the viewer module. Returns a rendered viewer. Returns FALSE
* if no viewer is set. * if no viewer is set.
*/ */
function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_object = NULL) { function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_object = NULL) {
// get viewer from settings
$settings = variable_get($variable_id, array()); $settings = variable_get($variable_id, array());
// make sure a viewer is set
if (!empty($settings) AND $settings['default'] !== 'none') { if (!empty($settings) AND $settings['default'] !== 'none') {
// get callback function
$viewer_id = islandora_get_viewer_id($variable_id); $viewer_id = islandora_get_viewer_id($variable_id);
if ($viewer_id AND $params !== NULL) { if ($viewer_id AND $params !== NULL) {
$callback = islandora_get_viewer_callback($viewer_id); $callback = islandora_get_viewer_callback($viewer_id);
// call callback function
return $callback($params, $fedora_object); 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. * Get id of the enabled viewer.
* *
* @param string $variable_id * @param string $variable_id
* The id of the Drupal variable the viewer settings are saved in * The ID of the Drupal variable the viewer settings are saved in
* @return *
* @return string
* The enabled viewer id. Returns FALSE if no viewer config is set. * The enabled viewer id. Returns FALSE if no viewer config is set.
*/ */
function islandora_get_viewer_id($variable_id) { function islandora_get_viewer_id($variable_id) {
@ -665,8 +648,9 @@ function islandora_get_viewer_id($variable_id) {
* Get callback function for a viewer. * Get callback function for a viewer.
* *
* @param string $viewer_id * @param string $viewer_id
* The ID of a viewer * The ID of a viewer.
* @return *
* @return string
* The callback function as a string as defined by the viewer. * The callback function as a string as defined by the viewer.
*/ */
function islandora_get_viewer_callback($viewer_id = NULL) { function islandora_get_viewer_callback($viewer_id = NULL) {

26
includes/islandora_tuque.inc → includes/tuque.inc

@ -2,13 +2,12 @@
/** /**
* @file * @file
*
* This file contains a class to include the Tuque php library. * This file contains a class to include the Tuque php library.
*/ */
$islandora_module_path = drupal_get_path('module', 'islandora'); $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/Datastream.php';
@include_once 'sites/all/libraries/tuque/FedoraApi.php'; @include_once 'sites/all/libraries/tuque/FedoraApi.php';
@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; @include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php';
@ -59,7 +58,15 @@ class IslandoraTuque {
*/ */
public $repository = NULL; 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)) { if (!isset($user)) {
global $user; global $user;
} }
@ -86,11 +93,20 @@ 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'); 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'); $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'); $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));

0
includes/islandora_tuque_wrapper.inc → includes/tuque_wrapper.inc

73
includes/utilities.inc

@ -2,18 +2,21 @@
/** /**
* @file * @file
* Contains islandora utility functions * Utility functions.
* *
* @todo this file should be broken out into other files. * @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? * 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 * @return string
* Human readable size.
*/ */
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) { function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
$kilobyte = 1024; $kilobyte = 1024;
@ -48,12 +51,16 @@ function islandora_control_group_to_human_readable($control_group) {
switch ($control_group) { switch ($control_group) {
case 'M': case 'M':
return '<b>M</b>anaged'; return '<b>M</b>anaged';
case 'X': case 'X':
return 'Inline <b>X</b>ML'; return 'Inline <b>X</b>ML';
case 'R': case 'R':
return '<b>R</b>edirect'; return '<b>R</b>edirect';
case 'E': case 'E':
return '<b>E</b>xternally Referenced'; return '<b>E</b>xternally Referenced';
default: default:
return $control_group; return $control_group;
} }
@ -65,7 +72,7 @@ function islandora_control_group_to_human_readable($control_group) {
* @param string $pid * @param string $pid
* The object id to check. * The object id to check.
* *
* @return boolean * @return bool
* TRUE if valid, FALSE otherwise. * TRUE if valid, FALSE otherwise.
*/ */
function islandora_is_valid_pid($pid) { function islandora_is_valid_pid($pid) {
@ -78,7 +85,7 @@ function islandora_is_valid_pid($pid) {
* @param string $dsid * @param string $dsid
* The datastream id to check. * The datastream id to check.
* *
* @return boolean * @return bool
* TRUE if valid, FALSE otherwise. * TRUE if valid, FALSE otherwise.
*/ */
function islandora_is_valid_dsid($dsid) { function islandora_is_valid_dsid($dsid) {
@ -92,7 +99,8 @@ function islandora_is_valid_dsid($dsid) {
* *
* @param string $url * @param string $url
* A url to a Fedora repository, if NULL the default is used. * 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 * Returns an array describing the repository. Returns FALSE if Fedora is down
* or if the url is incorrect. * 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(). * will be passed as arguments to module_invoke_all().
* *
* @see islandora_build_hook_list() * @see islandora_build_hook_list()
* To see how the hook list is generated.
* *
* @param string $hook * @param string $hook
* A hook to call. * A hook to call.
@ -217,10 +224,11 @@ function islandora_get_namespace($id) {
} }
/** /**
* Checks the given namespace or PID is/has an accessible namespace as defined * Checks the given namespace/PID is/has an accessible namespace.
* by the "islandora_pids_allowed" variable.
* *
* @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 * Either a PID or namespace to check for accessibility. Any string like those
* below are fine. * below are fine.
* *
@ -230,7 +238,7 @@ function islandora_get_namespace($id) {
* 'islandora:1234', * 'islandora:1234',
* @endcode * @endcode
* *
* @return boolean * @return bool
* TRUE if accessible, FALSE otherwise. * TRUE if accessible, FALSE otherwise.
*/ */
function islandora_namespace_accessible($id) { function islandora_namespace_accessible($id) {
@ -243,8 +251,9 @@ function islandora_namespace_accessible($id) {
} }
/** /**
* Gets any objects that the given object has a * Gets any objects that the given object has a parent relationship with.
* (isMemberOf, isMemberOfCollection) relationship with. *
* Parent relationships are defined as (isMemberOf, isMemberOfCollection).
* *
* This function gets its info from the RELS-EXT directly rather than through an * This function gets its info from the RELS-EXT directly rather than through an
* risearch. * 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. // @todo some logging would be nice, not sure what this throws.
return array(); 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); return array_filter($collections);
} }
/** /**
* Checks what datastreams the object already has against its required * Gets the datastreams requirments that are missing.
* datastreams as defined by its content models, and returns their intersection.
* *
* @param FedoraObject $object * @param FedoraObject $object
* The object which models will be used to determine what datastreams it * 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 * 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. * used with this object, as defined by the DS-COMPOSITE-MODEL datastreams.
* *
* For duplicate datastreams in the models, the first model defines the * For duplicate datastreams in the models, the first model defines the
* datastreams attributes regardless of what other models define. * datastreams attributes regardless of what other models define.
* This should be undefined behavior according to the documentation. * 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 * @param FedoraObject $object
* The object which models will be used to determine what datastreams it * The object which models will be used to determine what datastreams it
* should have. * should have.
* *
* @see islandora_get_required_datastreams_from_content_model() from more
* details on the return value.
*
* @return array * @return array
* The DS-COMPOSITE-MODEL defined datastreams that are required for the given * The DS-COMPOSITE-MODEL defined datastreams that are required for the given
* object. * object.
@ -336,14 +349,16 @@ function islandora_get_datastreams_requirements_from_models(array $models) {
$dsids += islandora_get_datastreams_requirements_from_content_model($model); $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']); unset($dsids['AUDIT']);
return $dsids; return $dsids;
} }
/** /**
* Checks the given content model for which datastreams are required for * Checks the given content model for which datastreams are required.
* subscribing objects, as defined by it's DS-COMPOSITE-MODEL datastream. *
* As defined by it's DS-COMPOSITE-MODEL datastream.
* *
* @todo Add support for fetching the schema information. * @todo Add support for fetching the schema information.
* *
@ -380,7 +395,7 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject
$dsids[$dsid] = array( $dsids[$dsid] = array(
'id' => $dsid, 'id' => $dsid,
'mime' => $mime, 'mime' => $mime,
'optional' => ($optional == 'true') ? TRUE : FALSE 'optional' => ($optional == 'true') ? TRUE : FALSE,
); );
} }
return $dsids; return $dsids;
@ -432,8 +447,11 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr
$label = isset($ds['label']) ? $ds['label'] : ''; $label = isset($ds['label']) ? $ds['label'] : '';
$mimetype = isset($ds['mimetype']) ? $ds['mimetype'] : 'text/xml'; $mimetype = isset($ds['mimetype']) ? $ds['mimetype'] : 'text/xml';
// Default 'Managed' // 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; $ds_uri = FALSE;
if (file_valid_uri($ds['datastream_file'])) { if (file_valid_uri($ds['datastream_file'])) {
$datastream_file = $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); $datastream->setContentFromUrl($datastream_file);
} }
break; break;
case 'X': case 'X':
$datastream->setContentFromString(file_get_contents($datastream_file)); $datastream->setContentFromString(file_get_contents($datastream_file));
break; 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 * Use anywhere we want to ensure a consitent error message when the repository
* is not accessible. * is not accessible.

12
islandora.info

@ -8,10 +8,10 @@ stylesheets[all][] = css/islandora.base.css
stylesheets[all][] = css/islandora.theme.css stylesheets[all][] = css/islandora.theme.css
files[] = includes/mime_detect.inc files[] = includes/mime_detect.inc
files[] = includes/dublin_core.inc files[] = includes/dublin_core.inc
files[] = includes/islandora_tuque.inc files[] = includes/tuque.inc
files[] = includes/islandora_tuque_wrapper.inc files[] = includes/tuque_wrapper.inc
files[] = includes/islandora_object.entity_controller.inc files[] = includes/object.entity_controller.inc
files[] = tests/islandora_web_test_case.inc files[] = tests/web_test_case.inc
files[] = tests/islandora_authtokens.test files[] = tests/authtokens.test
files[] = tests/islandora_hooks.test files[] = tests/hooks.test
php = 5.3 php = 5.3

4
islandora.install

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @file * @file
* This file contains all install related hooks. * This file contains all install related hooks.
@ -26,9 +27,6 @@ function islandora_uninstall() {
/** /**
* Implements hook_schema(). * Implements hook_schema().
*
* @return array
* The database schema for the module.
*/ */
function islandora_schema() { function islandora_schema() {
$schema['islandora_authtokens'] = array( $schema['islandora_authtokens'] = array(

139
islandora.module

@ -2,6 +2,7 @@
/** /**
* @file * @file
* Defines all the hooks this module implements.
* *
* islandora.module: defines paths (drupal menu items) as entry points and acts * islandora.module: defines paths (drupal menu items) as entry points and acts
* as a hub for dispatching tasks to other modules. * as a hub for dispatching tasks to other modules.
@ -22,10 +23,10 @@
* along with the program. If not, see <http ://www.gnu.org/licenses/>. * along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/ */
// Common datastreams // Common datastreams.
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
// Permissions // Permissions.
define('FEDORA_VIEW_OBJECTS', 'view fedora repository objects'); define('FEDORA_VIEW_OBJECTS', 'view fedora repository objects');
define('FEDORA_MANAGE_DATASTREAMS', 'view fedora repository datastreams'); define('FEDORA_MANAGE_DATASTREAMS', 'view fedora repository datastreams');
define('FEDORA_METADATA_EDIT', 'edit fedora metadata'); 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_PURGE', 'delete fedora objects and datastreams');
define('FEDORA_MANAGE_PROPERTIES', 'manage object properties'); define('FEDORA_MANAGE_PROPERTIES', 'manage object properties');
// Hooks // Hooks.
define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object');
// @todo Add Documentation. // @todo Add Documentation.
@ -108,7 +109,8 @@ function islandora_menu() {
'page arguments' => array(2), 'page arguments' => array(2),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_object_manage_access_callback', '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( $items['islandora/object/%islandora_object/manage/datastreams'] = array(
'title' => 'Datastreams', 'title' => 'Datastreams',
@ -141,7 +143,7 @@ function islandora_menu() {
'page arguments' => array('islandora_add_datastream_form', 2), 'page arguments' => array('islandora_add_datastream_form', 2),
'type' => MENU_LOCAL_ACTION, 'type' => MENU_LOCAL_ACTION,
'access callback' => 'islandora_object_access_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/manage/datastreams/add/autocomplete'] = array( $items['islandora/object/%islandora_object/manage/datastreams/add/autocomplete'] = array(
'file' => 'includes/add_datastream.form.inc', 'file' => 'includes/add_datastream.form.inc',
@ -149,7 +151,7 @@ function islandora_menu() {
'page arguments' => array(2), 'page arguments' => array(2),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_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( $items['islandora/object/%islandora_object/datastream/%islandora_datastream'] = array(
'title' => 'View datastream', 'title' => 'View datastream',
@ -225,19 +227,19 @@ function islandora_admin_paths() {
*/ */
function islandora_theme() { function islandora_theme() {
return array( return array(
// default object template // Default object template.
'islandora_default' => array( 'islandora_default' => array(
'file' => 'theme/islandora.theme.inc', 'file' => 'theme/theme.inc',
'template' => 'theme/islandora-object', 'template' => 'theme/islandora-object',
'variables' => array('islandora_object' => NULL), 'variables' => array('islandora_object' => NULL),
), ),
// default edit page // Default edit page.
'islandora_default_edit' => array( 'islandora_default_edit' => array(
'file' => 'theme/islandora.theme.inc', 'file' => 'theme/theme.inc',
'template' => 'theme/islandora-object-edit', 'template' => 'theme/islandora-object-edit',
'variables' => array('islandora_object' => NULL), 'variables' => array('islandora_object' => NULL),
), ),
// admin table for solution pack viewer selection // Admin table for solution pack viewer selection.
'islandora_viewers_table' => array( 'islandora_viewers_table' => array(
'file' => 'includes/solution_packs.inc', 'file' => 'includes/solution_packs.inc',
'render element' => 'form', 'render element' => 'form',
@ -252,31 +254,31 @@ function islandora_permission() {
return array( return array(
FEDORA_VIEW_OBJECTS => array( FEDORA_VIEW_OBJECTS => array(
'title' => t('View repository objects'), '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( FEDORA_MANAGE_DATASTREAMS => array(
'title' => t('Manage repository object datastreams'), '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( FEDORA_ADD_DS => array(
'title' => t('Add datastreams to repository objects'), '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( FEDORA_METADATA_EDIT => array(
'title' => t('Edit metadata'), '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( FEDORA_INGEST => array(
'title' => t('Create new repository objects'), '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( FEDORA_PURGE => array(
'title' => t('Permanently remove objects from the repository'), '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( FEDORA_MANAGE_PROPERTIES => array(
'title' => t('Manage object properties'), '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 * Checks whether the user can access the given object.
* permission.
* *
* Checks for object existance, accessiblitly, namespace permissions, * Checks for object existance, accessiblitly, namespace permissions,
* and user permissions * and user permissions
* *
* @see islandora_object_load() To find potential solutions to enable
* page not found errors.
*
* @param string $perm * @param string $perm
* User permission to test for. * User permission to test for.
* @param FedoraObject $object * @param FedoraObject $object
* The object to test, if NULL given the object doesn't exist or is * The object to test, if NULL given the object doesn't exist or is
* inaccessible. * inaccessible.
* *
* @return boolean * @return bool
* TRUE if the user is allowed to access this object, FALSE otherwise. * TRUE if the user is allowed to access this object, FALSE otherwise.
*/ */
function islandora_object_access_callback($perm, $object = NULL) { 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 * Checks whether the user can access the given object and datastream.
* the given permission.
* *
* Checks for object existance, accessiblitly, namespace permissions, * Checks for object existance, accessiblitly, namespace permissions,
* and user permissions * and user permissions
* *
* @see islandora_object_load() To find potential solutions to enable page
* not found errors.
*
* @param string $perm * @param string $perm
* The user permission to test for. * The user permission to test for.
* @param FedoraObject $object * @param FedoraObject $object
@ -345,7 +339,7 @@ function islandora_object_access_callback($perm, $object = NULL) {
* @param StdObject $account * @param StdObject $account
* The account to test permissions as or NULL for current user. * 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. * 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) { 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 * Checks whether the user can access the given object and datastream.
* the given permission. This function will validate and use a token if one *
* is provided in the _GET array. * This function will validate and use a token if present in the GET parameters.
* *
* Checks for object existance, accessiblitly, namespace permissions, * Checks for object existance, accessiblitly, namespace permissions,
* and user 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 * Checks whether the user can access the given object's manage tab.
* with the given array of permissions.
* *
* Checks for object existance, accessiblitly, namespace permissions, * Checks for object existance, accessiblitly, namespace permissions,
* and user permissions * and user permissions
* *
* @see islandora_object_load() To find potential solutions to enable
* page not found errors.
*
* @param array $perms * @param array $perms
* Array of user permission to test for. * Array of user permission to test for.
* @param FedoraObject $object * @param FedoraObject $object
* The object to test, if NULL given the object doesn't exist or is * The object to test, if NULL given the object doesn't exist or is
* inaccessible. * inaccessible.
* *
* @return boolean * @return bool
* TRUE if the user is allowed to access this object, FALSE otherwise. * TRUE if the user is allowed to access this object, FALSE otherwise.
*/ */
function islandora_object_manage_access_callback($perms, $object = NULL) { 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'); module_load_include('inc', 'islandora', 'includes/utilities');
drupal_set_title($object->label); drupal_set_title($object->label);
drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); drupal_set_breadcrumb(islandora_get_breadcrumbs($object));
// Optional pager parameters // Optional pager parameters.
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
$output = array(); $output = array();
@ -532,13 +522,13 @@ function islandora_default_islandora_view_object($object) {
} }
/** /**
* Just a wrapper around fetchings the IslandoraTuque object, with some very * Just a wrapper around fetchings the IslandoraTuque object.
* basic error logging.
* *
* @param $user * Includes some very basic error logging.
* The user to connect as.
* *
* @param $url * @param object $user
* The user to connect as.
* @param string $url
* The URL to connect to. * The URL to connect to.
* *
* @return IslandoraTuque * @return IslandoraTuque
@ -550,7 +540,8 @@ function islandora_get_tuque_connection($user = NULL, $url = NULL) {
if (IslandoraTuque::exists()) { if (IslandoraTuque::exists()) {
try { try {
$tuque = new IslandoraTuque($user, $url); $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'); 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 * Loads the object from the given ID if possible.
* specified in the menu path as '%islandora_object'. *
* 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 * @param string $object_id
* The pid of an object in the menu path identified by '%islandora_object'. * 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) { if ($tuque) {
try { try {
return $tuque->repository->getObject(urldecode($object_id)); return $tuque->repository->getObject(urldecode($object_id));
} catch (Exception $e) { }
catch (Exception $e) {
if ($e->getCode() == '404') { if ($e->getCode() == '404') {
return FALSE; 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 * A helper function to get a connection and return an object using a token
* for authentication. * for authentication.
* *
@ -615,7 +611,7 @@ function islandora_tokened_object_load($object_id, $map) {
if (array_key_exists('token', $_GET)) { if (array_key_exists('token', $_GET)) {
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING); $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
if ($token) { if ($token) {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/authtokens');
$token_user = islandora_validate_object_token($object_id, $map[4], $token); $token_user = islandora_validate_object_token($object_id, $map[4], $token);
$token_user = $token_user ? user_load($token_user->uid) : NULL; $token_user = $token_user ? user_load($token_user->uid) : NULL;
islandora_get_tuque_connection($token_user); islandora_get_tuque_connection($token_user);
@ -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 * This datastream load must take in arguments in a different
* order than the usual islandora_datastream_load. This is because * order than the usual islandora_datastream_load. This is because
* the function islandora_tokened_object_load needs DSID. It uses * the function islandora_tokened_object_load needs DSID. It uses
@ -642,6 +640,7 @@ function islandora_tokened_object_load($object_id, $map) {
* *
* @return FedoraDatastream * @return FedoraDatastream
* A datastream from Fedora. * A datastream from Fedora.
*
* @see islandora_datastream_load * @see islandora_datastream_load
*/ */
function islandora_tokened_datastream_load($datastream_id, $map) { function islandora_tokened_datastream_load($datastream_id, $map) {
@ -649,6 +648,8 @@ function islandora_tokened_datastream_load($datastream_id, $map) {
} }
/** /**
* Fetches a datastream object.
*
* A helper function to get an datastream specified as '%islandora_datastream' * A helper function to get an datastream specified as '%islandora_datastream'
* for the object specified in the menu path as '%islandora_object'. * for the object specified in the menu path as '%islandora_object'.
* *
@ -677,22 +678,28 @@ 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 * Content model, collection view and collection policy datastreams may now
* optionally define a version number in their top-level XML element as an * optionally define a version number in their top-level XML element as an
* attribute, as in: * attribute, as in:
* <content_model name="Collection" version="2" ... * <content_model name="Collection" version="2" ...
* *
* @param object $item * @param FedoraObject $object
* The Object the datastream belongs to.
* @param string $dsid * @param string $dsid
* The ID of the datastream.
* @param string $datastream_file * @param string $datastream_file
* @return * The datastream's content.
* int, or NULL if no version attribute was found. *
* @return int
* The datastreams version if found, NULL otherwise.
*/ */
function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL, $datastream_file = NULL) { function islandora_get_islandora_datastream_version($object = NULL, $dsid = NULL, $datastream_file = NULL) {
$return = NULL; $return = NULL;
// @TODO, need better check for $item // @TODO, need better check for $object
if ($item && $item[$dsid]) { if ($object && $object[$dsid]) {
$doc = simplexml_load_string($item[$dsid]->content); $doc = simplexml_load_string($object[$dsid]->content);
} }
elseif (!empty($datastream_file)) { elseif (!empty($datastream_file)) {
$doc = simplexml_load_file($datastream_file); $doc = simplexml_load_file($datastream_file);
@ -710,18 +717,18 @@ function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL,
*/ */
function islandora_islandora_required_objects(IslandoraTuque $connection) { function islandora_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora'); $module_path = drupal_get_path('module', 'islandora');
// Root Collection // Root Collection.
$root_collection = $connection->repository->constructObject('islandora:root'); $root_collection = $connection->repository->constructObject('islandora:root');
$root_collection->owner = 'fedoraAdmin'; $root_collection->owner = 'fedoraAdmin';
$root_collection->label = 'Top-level Collection'; $root_collection->label = 'Top-level Collection';
$root_collection->models = 'islandora:collectionCModel'; $root_collection->models = 'islandora:collectionCModel';
// Collection Policy Datastream // Collection Policy Datastream.
$datastream = $root_collection->constructDatastream('COLLECTION_POLICY', 'X'); $datastream = $root_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy'; $datastream->label = 'Collection policy';
$datastream->mimetype = 'text/xml'; $datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_collection_policy.xml", FALSE); $datastream->setContentFromFile("$module_path/xml/islandora_collection_policy.xml", FALSE);
$root_collection->ingestDatastream($datastream); $root_collection->ingestDatastream($datastream);
// TN Datastream // TN Datastream.
$datastream = $root_collection->constructDatastream('TN', 'M'); $datastream = $root_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail'; $datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png'; $datastream->mimetype = 'image/png';
@ -731,9 +738,9 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) {
'islandora' => array( 'islandora' => array(
'title' => 'Islandora', 'title' => 'Islandora',
'objects' => array( 'objects' => array(
$root_collection $root_collection,
) ),
) ),
); );
} }
@ -789,12 +796,10 @@ function islandora_delete_datastream(FedoraDatastream &$datastream) {
} }
/** /**
* Implements hook_cron() * Implements hook_cron().
*
* Removes expired authentication tokens.
*/ */
function islandora_cron() { function islandora_cron() {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/authtokens');
islandora_remove_expired_tokens(); islandora_remove_expired_tokens();
} }

9
islandora.rules.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* Does rule type stuff,
*/
/** /**
* Helper function to get reused "parameter" array. * Helper function to get reused "parameter" array.
*/ */
@ -8,8 +13,7 @@ function islandora_rules_relationship_parameter_array() {
'subject' => array( 'subject' => array(
'type' => 'islandora_object', 'type' => 'islandora_object',
'label' => t('Subject'), 'label' => t('Subject'),
'description' => t('An object of which we should check the ' . 'description' => t('An object of which we should check the relationships (The "subject" of the relationship).'),
'relationships (The "subject" of the relationship).'),
), ),
'pred_uri' => array( 'pred_uri' => array(
'type' => 'text', '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) { function islandora_object_add_relationship($sub, $pred_uri, $pred, $object, $type) {
$sub->relationships->add($pred_uri, $pred, $object, $type); $sub->relationships->add($pred_uri, $pred, $object, $type);
} }

6
tests/islandora_authtokens.test → tests/authtokens.test

@ -29,7 +29,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
* Test redeeming invalid tokens. * Test redeeming invalid tokens.
*/ */
public function testRedeemInvalidToken() { public function testRedeemInvalidToken() {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/authtokens');
$token = islandora_get_object_token('test:pid', 'woot', 1); $token = islandora_get_object_token('test:pid', 'woot', 1);
$this->assertTrue($token, 'Token was generated correctly.', 'Unit Tests'); $this->assertTrue($token, 'Token was generated correctly.', 'Unit Tests');
// Redeem a token that doesn't exist with real pid and dsid. // Redeem a token that doesn't exist with real pid and dsid.
@ -41,7 +41,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
* Test redeeming valid tokens. * Test redeeming valid tokens.
*/ */
public function testRedeemValidToken() { public function testRedeemValidToken() {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/authtokens');
// Change the current user. // Change the current user.
global $user; global $user;
$user_backup = $user; $user_backup = $user;
@ -82,7 +82,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
// Do some voodoo to get a token as the user we are connecting as // Do some voodoo to get a token as the user we are connecting as
// to do this we need to change the user we are logged in as. // to do this we need to change the user we are logged in as.
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/authtokens');
global $user; global $user;
$backup = $user; $backup = $user;
$user = $account; $user = $account;

0
tests/islandora_hooks.test → tests/hooks.test

3
tests/islandora_hooks_test.info → tests/islandora_test.info

@ -1,7 +1,6 @@
name = Islandora Hook testing name = Islandora Test Module
description = Tests Hooks. Do not enable. description = Tests Hooks. Do not enable.
core = 7.x core = 7.x
package = Testing package = Testing
hidden = TRUE hidden = TRUE
dependencies[] = islandora dependencies[] = islandora
files[] = islandora_hooks_test.module

0
tests/islandora_hooks_test.module → tests/islandora_test.module

0
tests/islandora_web_test_case.inc → tests/web_test_case.inc

5
theme/islandora-object-edit.tpl.php

@ -2,9 +2,7 @@
/** /**
* @file * @file
* * The default manage datastreams view for objects.
* islandora-object-edit.tpl.php: This is a template for objects that do not
* have a module to registered to build their display.
* *
* islandora_object is a fedora tuque Object * islandora_object is a fedora tuque Object
* $object->label * $object->label
@ -17,7 +15,6 @@
* and each element has an array of values. * and each element has an array of values.
* dc.title can have none, one or many titles * dc.title can have none, one or many titles
* this is the case for all dc elements. * this is the case for all dc elements.
*
*/ */
?> ?>
<?php print (theme_table($variables['datastream_table'])); ?> <?php print (theme_table($variables['datastream_table'])); ?>

2
theme/islandora-object.tpl.php

@ -2,6 +2,7 @@
/** /**
* @file * @file
* The default object view.
* *
* This is a template for objects that do not have a module to registered to * This is a template for objects that do not have a module to registered to
* build their display. * build their display.
@ -55,7 +56,6 @@
* foreach ($object as $ds) { * foreach ($object as $ds) {
* do something here * do something here
* } * }
*
*/ */
?> ?>
<div class="islandora-object islandora"> <div class="islandora-object islandora">

72
theme/islandora.theme.inc → theme/theme.inc

@ -2,18 +2,13 @@
/** /**
* @file * @file
*
* This file contains all theme and preprocess functions. * This file contains all theme and preprocess functions.
*/ */
/** /**
* Preprocess the edit template * Implements hook_preprocess_theme().
*
* @global string $base_url
* @param array $variables
* theme variables for the edit template
*/ */
function islandora_preprocess_islandora_default_edit(&$variables) { function islandora_preprocess_islandora_default_edit(array &$variables) {
global $base_url; global $base_url;
$islandora_object = $variables['islandora_object']; $islandora_object = $variables['islandora_object'];
$datastreams = array(); $datastreams = array();
@ -32,27 +27,55 @@ function islandora_preprocess_islandora_default_edit(&$variables) {
$rows = array(); $rows = array();
foreach ($islandora_object as $ds) { foreach ($islandora_object as $ds) {
$rows[] = array( $rows[] = array(
array('class' => 'datastream-id', 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view'))), array(
array('class' => 'datastream-label', 'data' => $ds->label), 'class' => 'datastream-id',
array('class' => 'datastream-control', 'data' => islandora_control_group_to_human_readable($ds->controlGroup)), 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view')),
array('class' => 'datastream-mime', 'data' => $ds->mimeType), ),
array('class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds)), array(
array('class' => 'datastream-download', 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download'))), 'class' => 'datastream-label',
array('class' => 'datstream-edit', 'data' => islandora_datastream_edit_get_link($ds)), 'data' => $ds->label,
array('class' => 'datastream-delete', 'data' => islandora_datastream_get_delete_link($ds)), ),
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; $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; $variables['datastream_table'] = $table;
} }
/** /**
* Preprocess for the default view template * Implements hook_preprocess_theme().
*
* @global string $base_url
* @param array $variables
*/ */
function islandora_preprocess_islandora_default(&$variables) { function islandora_preprocess_islandora_default(&$variables) {
drupal_add_js('misc/form.js'); drupal_add_js('misc/form.js');
@ -86,9 +109,10 @@ function islandora_preprocess_islandora_default(&$variables) {
$variables['datastreams'] = $datastreams; $variables['datastreams'] = $datastreams;
try { try {
$dc = $islandora_object['DC']->content; $dc = $islandora_object['DC']->content;
$dc_object = DublinCore::import_from_xml_string($dc); $dc_object = DublinCore::importFromXMLString($dc);
$dc_array = $dc_object->as_formatted_array(); $dc_array = $dc_object->asArray();
} catch (Exception $e) { }
catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); 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(); $variables['dc_array'] = isset($dc_array) ? $dc_array : array();
Loading…
Cancel
Save