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
*
* Functions for generating/validating/submitting the add datastream form.
*/
@ -26,13 +25,12 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
$form_state['object'] = $object;
$form_state['datastream_requirements'] = islandora_get_missing_datastreams_requirements($object);
$unused_datastreams = array_keys($form_state['datastream_requirements']);
$unused_datastreams = array_map(function($o) { return "'$o'"; }, $unused_datastreams);
$unused_datastreams = implode(', ', $unused_datastreams);
$unused_datastreams = "'" . implode("', '", $unused_datastreams) . "'";
$upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize'));
return array(
'#redirect' => "islandora/object/{$object->id}",
'#attributes' => array(
'enctype' => 'multipart/form-data'
'enctype' => 'multipart/form-data',
),
'fieldset' => array(
'#type' => 'fieldset',
@ -41,12 +39,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#collapsed' => FALSE,
'dsid' => array(
'#title' => 'Datastream ID',
'#description' => t('An ID for this stream that is unique to this object.' .
'Must start with a letter and contain only alphanumeric ' .
'characters and dashes and underscores. Datastreams that ' .
'are defined by the content model don\'t currently exist: ' .
'<b>@unused_dsids</b>.',
array('@unused_dsids' => $unused_datastreams)
'#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)),
),
'#type' => 'textfield',
'#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_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(
'#title' => 'Datastream Label',
@ -66,7 +59,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#maxlength' => 64,
'#description' => t('A Human readable label'),
'#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(
'#type' => 'managed_file',
@ -78,15 +71,14 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#upload_location' => 'temporary://',
'#upload_validators' => array(
'file_validate_extensions' => array(NULL),
// Assume its specified in MB
// Assume its specified in MB.
'file_validate_size' => array($upload_size * 1024 * 1024),
),
),
'submit' => array(
'#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
* datastream id.
* Checks if the given form field contains a valid datastream ID.
*
* @param array $element
* The form field to check.
@ -157,8 +148,7 @@ function islandora_add_datastream_form_field_does_not_contain_a_forward_slash(ar
}
/**
* Checks if the given datastream id requires that the upload file be of a
* certian MIME type.
* Checks if the given datastream requires the upload to be a certian MIME type.
*
* @param array $form
* The Drupal form.
@ -180,8 +170,9 @@ function islandora_add_datastream_form_validate(array $form, array &$form_state)
}
/**
* Adds the new datastream based on the submitted values, only creates managed
* datastreams at the moment.
* Adds the new datastream based on the submitted values.
*
* Only creates managed datastreams at the moment.
*
* @param array $form
* The Drupal form.
@ -200,9 +191,11 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) {
$ds->setContentFromFile($path);
$object->ingestDatastream($ds);
file_delete($file);
} catch (exception $e) {
}
catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
file_delete($file); // Make sure to delete anyways.
// Make sure to delete anyways.
file_delete($file);
return;
}
drupal_set_message(t("Successfully Added Datastream!"));
@ -210,6 +203,7 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) {
/**
* Callback for an autocomplete field in the admin add datastream form.
*
* It lists the missing required (may be optional) datastreams.
*
* @param FedoraObject $object
@ -225,7 +219,10 @@ function islandora_add_datastream_form_autocomplete_callback(FedoraObject $objec
$dsids = array_combine($dsids, $dsids);
$query = trim($query);
if (!empty($query)) {
$dsids = array_filter($dsids, function($id) use($query) { return stripos($id, $query) !== FALSE; });
$filter = function($id) use($query) {
return stripos($id, $query) !== FALSE;
};
$dsids = array_filter($dsids, $filter);
}
drupal_json_output($dsids);
}

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

@ -1,9 +1,11 @@
<?php
/**
* @file
* Library functions for handling authentication tokens.
* These are to be used when dealing with applications
* such as Djatoka that do not pass through credentials.
* 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.
*/
// 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.
*
* This token can later be turned in for access to the requested object or
* datastream.
*
@ -19,7 +22,7 @@ define('TOKEN_TIMEOUT', 300);
* The Fedora PID to generate the token for.
* @param string $dsid
* The Fedora datastream ID to generate the token for.
* @param integer $uses
* @param int $uses
* Defaults to 1.
* The number of uses the token should be used for. There are
* 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
* 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
* their creation.
* Submit a token to islandora for authentication.
*
* Supply islandora with the 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 their creation.
*
* @param string $pid
* The PID of the object to retrieve.

14
includes/breadcrumb.inc

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

12
includes/datastream.inc

@ -2,9 +2,7 @@
/**
* @file
*
* This file contains the admin form and callback functions for datastream
* manipulations.
* Contains the admin form and callback functions for datastream manipulations.
*/
/**
@ -25,7 +23,7 @@ function islandora_download_datastream(FedoraDatastream $datastream) {
*
* @param FedoraDatastream $datastream
* 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
* 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_goto("islandora/object/{$object->id}/manage/datastreams");
break;
case 1:
// One registry implementation, go there
// One registry implementation, go there.
drupal_goto($edit_registry[0]['url']);
break;
default:
// Multiple edit routes registered
// Multiple edit routes registered.
return islandora_edit_datastream_registry_render($edit_registry);
}
}

35
includes/delete_datastream.form.inc

@ -2,9 +2,7 @@
/**
* @file
*
* This file contains the admin (confirmation) form and callback functions to
* delete/purge a datastream.
* The admin/confirmation form to delete/purge a datastream.
*/
/**
@ -32,19 +30,18 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Fedor
}
/**
* Submit handler for the delete datastream form. Purges/Delete's the given
* FedoraDatastream if possible.
* Submit handler for the delete datastream form.
*
* Purges/Delete's the given FedoraDatastream if possible.
*
* The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to
* whether the given FedoraDatastream
* should be: blocked from purging; state set to 'Deleted'; or purged.
*
* @see islandora_delete_datastream().
*
* @param string $object_id
* ID of the object
* @param string $datastream_id
* ID of the datastream
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_delete_datastream_form_submit(array $form, array &$form_state) {
$datastream = $form_state['datastream'];
@ -53,14 +50,22 @@ function islandora_delete_datastream_form_submit(array $form, array &$form_state
$deleted = FALSE;
try {
$deleted = islandora_delete_datastream($datastream);
} catch (Exception $e) {
drupal_set_message(t('Error deleting %s datastream from object %o %e', array('%s' => $datastream_id, '%o' => $object->label, '%e' => $e->getMessage())), 'error');
}
catch (Exception $e) {
drupal_set_message(t('Error deleting %s datastream from object %o %e', array(
'%s' => $datastream_id,
'%o' => $object->label,
'%e' => $e->getMessage())), 'error');
}
if ($deleted) {
drupal_set_message(t('%d datastream sucessfully deleted from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->label)));
drupal_set_message(t('%d datastream sucessfully deleted from Islandora object %o', array(
'%d' => $datastream_id,
'%o' => $object->label)));
}
else {
drupal_set_message(t('Error deleting %s datastream from object %o', array('%s' => $datastream_id, '%o' => $object->label)), 'error');
drupal_set_message(t('Error deleting %s datastream from object %o', array(
'%s' => $datastream_id,
'%o' => $object->label)), 'error');
}
$form_state['redirect'] = "islandora/object/{$object->id}";
}

6
includes/delete_object.form.inc

@ -2,9 +2,7 @@
/**
* @file
*
* This file contains the admin (confirmation) form and callback functions to
* purge an object.
* The admin/confirmation form to purge an object.
*/
/**
@ -32,7 +30,7 @@ function islandora_delete_object_form(array $form, array &$form_state, FedoraObj
}
/**
* Delete's the object in questionGives deloption of deleting or purging and object.
* Delete's the given object.
*
* @param array $form
* The Drupal form.

64
includes/dublin_core.inc

@ -2,9 +2,9 @@
/**
* @file
* Implements a simple class for working with Dublin Core data.
*
* Implements a simple class for working with Dublin Core data and exporting it
* back to XML. Inspiration and design shamelessly stolen from the pyfedora
* Inspiration and design shamelessly stolen from the pyfedora
* project at http://pypi.python.org/pypi/pyfedora/0.1.0
*/
@ -33,34 +33,40 @@ class DublinCore {
public $owner;
/**
* Constructs a DublinCore object from a Fedora_Item object and populates the
* $dc array.
* Constructor.
*
* @param string $dc_xml
* The Dublin Core XML.
*/
function DublinCore($dc_xml = NULL) {
public function __construct($dc_xml = NULL) {
if (!empty($dc_xml)) {
$this->dc = self::import_from_xml_string($dc_xml);
$this->dc = self::importFromXMLString($dc_xml);
}
}
/**
* Add Elements
* @param <type> $element_name
* @param <type> $value
* Add an element.
*
* @param string $element_name
* The name of the element to add.
* @param string $value
* The value of the element to add.
*/
function add_element($element_name, $value) {
public function addElement($element_name, $value) {
if (is_string($value) && is_array($this->dc[$element_name])) {
$this->dc[$element_name][] = $value;
}
}
/**
* Replace the given DC element with the values in $values
* @param string $elemnt_name
* @param array $values
* Replace the given DC element with the given values.
*
* @param string $element_name
* The name of the elements to set.
* @param mixed $values
* The values of the set the elements too.
*/
function set_element($element_name, $values) {
public function setElement($element_name, $values) {
if (is_array($values)) {
$this->dc[$element_name] = $values;
}
@ -70,11 +76,12 @@ class DublinCore {
}
/**
* Serialize this object to XML and return it.
* @param type $with_preamble
* @return type
* Serialize this object as an XML string.
*
* @return string
* The serialized XML.
*/
function as_xml($with_preamble = FALSE) {
public function asXML() {
$dc_xml = new DomDocument();
$oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc');
$oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
@ -95,18 +102,17 @@ class DublinCore {
}
/**
* Create dc from dict ( does nothing )
* Serializes this object as an array.
*
* @return array
* The serialized object.
*/
static function create_dc_from_dict() {
}
function as_formatted_array() {
public function asArray() {
$dc_array = array();
foreach ($this as $element) {
if (!empty($element)) {
foreach ($element as $field => $values) {
// split value if the result value is an array
// Split value if the result value is an array.
if (is_array($values)) {
$value = '';
$i = 0;
@ -135,17 +141,19 @@ class DublinCore {
/**
* Creates a new instance of the class by parsing dc_xml
* Creates a new instance of the class by parsing dc_xml.
*
* @param string $dc_xml
* Dublin Core XML.
*
* @return DublinCore
* The instantiated object.
*/
static function import_from_xml_string($dc_xml) {
public static function importFromXMLString($dc_xml) {
$dc_doc = new DomDocument();
if ($dc_doc->loadXML($dc_xml)) {
$oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*');
$new_dc = new DublinCore();
foreach ($oai_dc as $child) {
if (isset($new_dc->dc[$child->nodeName])) {
array_push($new_dc->dc[$child->nodeName], $child->nodeValue);

64
includes/ingest.form.inc

@ -2,14 +2,14 @@
/**
* @file
*
* Defines the multi-page ingest form and any relevant hooks and functions for
* defining the multi-page ingest forms.
* Defines the multi-page ingest form and any relevant hooks and functions.
*/
/**
* Ingest form build function. Initializes the form state, and builds the
* initial list of steps, excutes the current step.
* Ingest form build function.
*
* Initializes the form state, and builds the initial list of steps, excutes
* the current step.
*
* @param array $form
* The drupal form.
@ -32,9 +32,7 @@
*/
function islandora_ingest_form(array $form, array &$form_state, array $configuration) {
islandora_ingest_form_init_form_state($form_state, $configuration);
$form = islandora_ingest_form_execute_step($form, $form_state);
return $form;
}
@ -71,7 +69,9 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array
// Use namespace if ID not given.
$namespace = isset($configuration['namespace']) && !isset($id) ? $configuration['namespace'] : $id;
$label = isset($configuration['label']) ? $configuration['label'] : 'New Object';
$relationship_map = function($o) { return array('relationship' => 'isMemberOfCollection', 'pid' => $o); };
$relationship_map = function($o) {
return array('relationship' => 'isMemberOfCollection', 'pid' => $o);
};
$relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']);
$object = islandora_prepare_new_object($namespace, $label, array(), array(), $relationships);
$form_state['islandora'] = array(
@ -115,8 +115,10 @@ function islandora_ingest_get_approximate_steps(array $configuration) {
}
/**
* Executes the current step, building the form definition and appending on any
* additonal elements required for the step to function.
* Executes the current step.
*
* Builds the form definition and appends any additonal elements required for
* the step to function.
*
* @param array $form
* The drupal form.
@ -138,6 +140,7 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) {
$args = isset($step_info['args']) ? array_merge($args, $step_info['args']) : $args;
$form = call_user_func_array($step_info['form_id'], $args);
return islandora_ingest_form_stepify($form, $form_state, $step_info);
case 'batch':
// @todo Implement if possible.
break;
@ -187,11 +190,19 @@ function islandora_ingest_form_previous_button() {
// convert all required fields to use #element_validation functions, and
// Remove the need for #limit_validation_errors. Or maybe there is some
// other solution, regardless of what it is, it won't be standard.
'#limit_validation_errors' => array()
'#limit_validation_errors' => array(),
);
}
function islandora_ingest_form_get_step_number($form_state, $step_id = NULL) {
/**
* Get the current step.
*
* @param array $form_state
* The Drupal form state.
* @param string $step_id
* The ID of the step to get.
*/
function islandora_ingest_form_get_step_number(array $form_state, $step_id = NULL) {
if ($step_id === NULL) {
$step_id = islandora_ingest_form_get_step_id($form_state);
}
@ -240,7 +251,7 @@ function islandora_ingest_form_next_button(array $step_info) {
'#value' => t('Next'),
'#name' => 'next',
'#validate' => $validate,
'#submit' => $submit
'#submit' => $submit,
);
}
@ -305,7 +316,7 @@ function islandora_ingest_form_ingest_button(array $step_info) {
'#name' => 'ingest',
'#value' => t('Ingest'),
'#validate' => $validate,
'#submit' => $submit
'#submit' => $submit,
);
}
@ -324,8 +335,10 @@ function islandora_ingest_form_submit(array $form, array &$form_state) {
try {
islandora_add_object($object);
$form_state['redirect'] = "islandora/object/{$object->id}";
} catch (Exception $e) {
// If post hooks throws it may already exist at this point but may be invalid, so don't say failed :P
}
catch (Exception $e) {
// If post hooks throws it may already exist at this point but may be
// invalid, so don't say failed.
watchdog('islandora', $e->getMessage(), NULL, WATCHDOG_ERROR);
drupal_set_message(t('A problem occured while ingesting "@label" (ID: @pid), please notifiy the administrator.', array('@label' => $object->label, '@pid' => $object->id)), 'error');
}
@ -346,8 +359,7 @@ function &islandora_ingest_form_get_configuration(array &$form_state) {
}
/**
* Gets a reference to the stored NewFedoraObject's which are to be ingested
* when the final step submits.
* Gets a reference to the stored NewFedoraObject's.
*
* @param array $form_state
* The drupal form state.
@ -401,15 +413,14 @@ function islandora_ingest_form_get_step_id(array &$form_state, $step_number = NU
}
/**
* Get a reference to the step info of the given step or the current step if
* none is given.
* Get the step info of the given step or the current step if none is given.
*
* @param array $form_state
* The drupal form state.
* @param int $step
* The index of the step to get.
*
* @return integer
* @return int
* The step info of the requested step if found, NULL otherwise.
*/
function islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) {
@ -423,7 +434,12 @@ function islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) {
}
/**
* Get general storage for the given step. (or the current step)
* Get general storage for the given/current step.
*
* @param array $form_state
* The drupal form state.
* @param string $step_id
* The ID of the step.
*/
function &islandora_ingest_form_get_step_storage(array &$form_state, $step_id = NULL) {
if ($step_id === NULL) {
@ -459,7 +475,7 @@ function islandora_ingest_form_get_steps(array &$form_state) {
function islandora_ingest_form_step_form_load_include(array &$form_state) {
form_load_include($form_state, 'inc', 'islandora', 'includes/ingest.form');
$step_info = islandora_ingest_form_get_step_info($form_state);
// Load include files
// Load include files.
if (isset($step_info['file']) && isset($step_info['module'])) {
$matches = array();
preg_match('/^(.*)\.(.*)$/', $step_info['file'], $matches);
@ -490,7 +506,7 @@ function islandora_ingest_form_get_step_count(array $form_state) {
* The sort order is undefined for steps which have the same weight.
*
* @param array $form_state
* All available form_state options used to build the multi-paged ingest process.
* The Drupal form state.
*
* @return array
* The list of sorted ingest steps as defined by all implementers

3
includes/ingest.menu.inc

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

61
includes/mime_detect.inc

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

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

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

28
includes/object_properties.form.inc

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

154
includes/solution_packs.inc

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

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

@ -2,13 +2,12 @@
/**
* @file
*
* This file contains a class to include the Tuque php library.
*/
$islandora_module_path = drupal_get_path('module', 'islandora');
//do this until we expost these in a module or library
// Do this until we expose these in a module or library.
@include_once 'sites/all/libraries/tuque/Datastream.php';
@include_once 'sites/all/libraries/tuque/FedoraApi.php';
@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php';
@ -59,7 +58,15 @@ class IslandoraTuque {
*/
public $repository = NULL;
function __construct($user = NULL, $url = NULL) {
/**
* Constructor.
*
* @param array $user
* A Drupal user.
* @param string $url
* The url to the fedora instance.
*/
public function __construct($user = NULL, $url = NULL) {
if (!isset($user)) {
global $user;
}
@ -86,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');
}
static function getError() {
/**
* Displays and error for use when Tuque is not installed.
*/
public static function getError() {
$islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora');
$tuque_link = l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque');
$message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array('!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link));

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

73
includes/utilities.inc

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

12
islandora.info

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

4
islandora.install

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

139
islandora.module

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

9
islandora.rules.inc

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

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

@ -29,7 +29,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
* Test redeeming invalid tokens.
*/
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);
$this->assertTrue($token, 'Token was generated correctly.', 'Unit Tests');
// Redeem a token that doesn't exist with real pid and dsid.
@ -41,7 +41,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
* Test redeeming valid tokens.
*/
public function testRedeemValidToken() {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens');
module_load_include('inc', 'islandora', 'includes/authtokens');
// Change the current user.
global $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
// 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;
$backup = $user;
$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.
core = 7.x
package = Testing
hidden = TRUE
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
*
* islandora-object-edit.tpl.php: This is a template for objects that do not
* have a module to registered to build their display.
* The default manage datastreams view for objects.
*
* islandora_object is a fedora tuque Object
* $object->label
@ -17,7 +15,6 @@
* and each element has an array of values.
* dc.title can have none, one or many titles
* this is the case for all dc elements.
*
*/
?>
<?php print (theme_table($variables['datastream_table'])); ?>

2
theme/islandora-object.tpl.php

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

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

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