Browse Source

Merge pull request #165 from DannyJoris-islandora/7.x

coder cleanup
pull/166/merge
Jonathan Green 12 years ago
parent
commit
ca161685ec
  1. 23
      admin/islandora.admin.inc
  2. 11
      includes/breadcrumb.inc
  3. 62
      includes/datastream.inc
  4. 4
      includes/ingest-menu.inc
  5. 7
      includes/islandora.ingest.inc
  6. 10
      includes/islandora_dublin_core.inc
  7. 2
      includes/mime.detect.inc
  8. 20
      includes/object_properties.inc
  9. 5
      includes/purge.form.inc
  10. 16
      includes/tuque.inc
  11. 33
      includes/utilities.inc
  12. 26
      islandora.api.php
  13. 6
      islandora.install
  14. 26
      islandora.module
  15. 40
      theme/islandora-object-edit.tpl.php
  16. 26
      theme/islandora-object.tpl.php
  17. 11
      theme/islandora.theme.inc

23
admin/islandora.admin.inc

@ -1,11 +1,14 @@
<?php <?php
/** /**
* @file islandora.admin.inc * @file
* islandora.admin.inc: This file contains the general islandora admin form and callback functions.
*/
/**
* Create admin form * Create admin form
* @return array * @return array
*/ */
function islandora_repository_admin($form, &$form_state) { function islandora_repository_admin($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
@ -17,7 +20,7 @@ function islandora_repository_admin($form, &$form_state) {
$form = array(); $form = array();
if(isset($form_state['values']['islandora_base_url'])) { if (isset($form_state['values']['islandora_base_url'])) {
$url = $form_state['values']['islandora_base_url']; $url = $form_state['values']['islandora_base_url'];
} }
else { else {
@ -33,7 +36,7 @@ function islandora_repository_admin($form, &$form_state) {
$info = FALSE; $info = FALSE;
} }
if($info) { if ($info) {
try { try {
$dc = $connection->api->m->getDatastream('fedora-system:ContentModel-3.0', 'DC'); $dc = $connection->api->m->getDatastream('fedora-system:ContentModel-3.0', 'DC');
} }
@ -42,8 +45,8 @@ function islandora_repository_admin($form, &$form_state) {
} }
} }
if($info) { if ($info) {
if($dc) { if ($dc) {
$confirmation_message = '<img src="' . url('misc/watchdog-ok.png') . '"/>' $confirmation_message = '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Successfully connected to Fedora Server (Version !version).', array('!version' => $info['repositoryVersion'])); . t('Successfully connected to Fedora Server (Version !version).', array('!version' => $info['repositoryVersion']));
} }
@ -77,7 +80,7 @@ function islandora_repository_admin($form, &$form_state) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fedora base URL'), '#title' => t('Fedora base URL'),
'#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'), '#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST connections <br>' . $confirmation_message), '#description' => t('The URL to use for REST connections <br />' . $confirmation_message),
'#required' => TRUE, '#required' => TRUE,
'#ajax' => array( '#ajax' => array(
'callback' => 'islandora_update_url_div', 'callback' => 'islandora_update_url_div',
@ -122,19 +125,19 @@ function islandora_repository_admin($form, &$form_state) {
), ),
); );
if(isset($form_state['values']['islandora_namespace_restriction_enforced'])) { if (isset($form_state['values']['islandora_namespace_restriction_enforced'])) {
$namespaces = $form_state['values']['islandora_namespace_restriction_enforced']; $namespaces = $form_state['values']['islandora_namespace_restriction_enforced'];
} }
else { else {
$namespaces = variable_get('islandora_namespace_restriction_enforced', FALSE); $namespaces = variable_get('islandora_namespace_restriction_enforced', FALSE);
} }
if($namespaces) { if ($namespaces) {
$form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_pids_allowed'] = array( $form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_pids_allowed'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'), '#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '),
'#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos. <br> islandora: is reserved and is always allowed.'), '#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos. <br /> islandora: is reserved and is always allowed.'),
'#weight' => 0, '#weight' => 0,
); );
} }

11
includes/breadcrumb.inc

@ -1,11 +1,16 @@
<?php <?php
/**
* @file
* This file contains functions to create breadcrumbs on Islandora object pages.
*/
function islandora_get_breadcrumbs($object) { function islandora_get_breadcrumbs($object) {
$breadcrumbs = array(); $breadcrumbs = array();
islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository);
if(isset($breadcrumbs[0])) { if (isset($breadcrumbs[0])) {
unset($breadcrumbs[0]); unset($breadcrumbs[0]);
} }
@ -69,8 +74,8 @@ function islandora_get_breadcrumbs_recursive($pid, &$breadcrumbs, $repository) {
islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository);
} }
else { else {
$breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. $breadcrumbs[] = '...'; // Add an non-link, as we don't know how to get back to the root.
islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); //And render the last two links and break (on the next pass). islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); // And render the last two links and break (on the next pass).
} }
} }
} }

62
includes/datastream.inc

@ -1,11 +1,13 @@
<?php <?php
/** /**
* @file datastream.inc * @file
* This file contains the admin form and callback functions for datastream manipulations.
*/ */
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
/** /**
* Callback function to view or download a datastream.
* *
* @global object $user * @global object $user
* @param string $object_id * @param string $object_id
@ -15,12 +17,12 @@ define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
*/ */
function islandora_view_datastream($object, $dsid, $method = 'view') { function islandora_view_datastream($object, $dsid, $method = 'view') {
// if the object exists but the datastream doesn't // if the object exists but the datastream doesn't
if(!isset($object[$dsid])) { if (!isset($object[$dsid])) {
return drupal_not_found(); return drupal_not_found();
} }
header('Content-type: ' . $object[$dsid]->mimetype); header('Content-type: ' . $object[$dsid]->mimetype);
if($object[$dsid]->controlGroup == 'M' || $object[$dsid]->controlGroup == 'X') { if ($object[$dsid]->controlGroup == 'M' || $object[$dsid]->controlGroup == 'X') {
header('Content-length: ' . $object[$dsid]->size); header('Content-length: ' . $object[$dsid]->size);
} }
@ -45,7 +47,7 @@ function islandora_datastream_get_parents($islandora_object) {
} }
$collections = array_merge($collections1, $collections2); $collections = array_merge($collections1, $collections2);
foreach($collections as $collection) { foreach ($collections as $collection) {
try { try {
$pid = $collection['object']['value']; $pid = $collection['object']['value'];
$object = $repository->getObject($collection['object']['value']); $object = $repository->getObject($collection['object']['value']);
@ -55,7 +57,9 @@ function islandora_datastream_get_parents($islandora_object) {
$parent_collections[$pid]['label'] = $object->label; $parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']); $parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
} }
catch (RepositoryException $e) {} catch (RepositoryException $e) {
}
} }
return $parent_collections; return $parent_collections;
@ -94,7 +98,7 @@ function islandora_get_unused_dsids($object) {
$defined_dsids = array(); $defined_dsids = array();
if(!$object) { if (!$object) {
return $defined_dsids; return $defined_dsids;
} }
@ -168,9 +172,9 @@ function islandora_get_add_datastream_form($object, &$form_state) {
); );
if (!empty($unused_dsids)) { if (!empty($unused_dsids)) {
$dsidsForForm = array(); $dsids_for_form = array();
foreach ($unused_dsids as $key => $value) { foreach ($unused_dsids as $key => $value) {
$dsidsForForm[$key] = $key; $dsids_for_form[$key] = $key;
} }
$form['add_fieldset']['stream_id'] = array( $form['add_fieldset']['stream_id'] = array(
'#type' => 'select', '#type' => 'select',
@ -179,7 +183,7 @@ function islandora_get_add_datastream_form($object, &$form_state) {
'#weight' => '-1', '#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'), '#description' => t('Datastream IDs defined by the content model.'),
); );
$form['add_fieldset']['stream_id']['#options'] = $dsidsForForm; $form['add_fieldset']['stream_id']['#options'] = $dsids_for_form;
} }
else { else {
$form['add_fieldset']['stream_id'] = array( $form['add_fieldset']['stream_id'] = array(
@ -220,11 +224,11 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
$dsid = $form_state['values']['stream_id']; $dsid = $form_state['values']['stream_id'];
$ds_label = $form_state['values']['stream_label']; $ds_label = $form_state['values']['stream_label'];
$dformat = $mimetype->getMimeType($file); $dformat = $mimetype->getMimeType($file);
$controlGroup = "M"; $control_group = "M";
try { try {
$fedora_object = islandora_object_load($object_id); $fedora_object = islandora_object_load($object_id);
$ds = $fedora_object->constructDatastream($dsid, $controlGroup); $ds = $fedora_object->constructDatastream($dsid, $control_group);
$ds->label = $ds_label; $ds->label = $ds_label;
$ds->mimetype = $dformat; $ds->mimetype = $dformat;
$ds->setContentFromFile($file); $ds->setContentFromFile($file);
@ -235,7 +239,7 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return; return;
} }
drupal_set_message("Successfully Added Datastream!"); drupal_set_message(t("Successfully Added Datastream!"));
drupal_goto("islandora/object/$object_id"); drupal_goto("islandora/object/$object_id");
} }
@ -254,8 +258,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
return; return;
} }
$dsid = $form_state['values']['stream_id']; $dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label']; $ds_label = $form_state['values']['stream_label'];
if (strlen($dsid) > 64) { if (drupal_strlen($dsid) > 64) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.')); form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE; return FALSE;
} }
@ -263,11 +267,11 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
return FALSE; return FALSE;
} }
if (strlen($dsLabel) > 64) { if (drupal_strlen($ds_label) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.')); form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE; return FALSE;
} }
if (strpos($dsLabel, '/')) { if (strpos($ds_label, '/')) {
form_set_error('', t('Data stream Label cannot contain a "/".')); form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE; return FALSE;
} }
@ -275,7 +279,7 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
$object_id = $form_state['values']['pid']; $object_id = $form_state['values']['pid'];
$fedora_object = islandora_object_load($object_id); $fedora_object = islandora_object_load($object_id);
if(isset($fedora_object[$dsid])) { if (isset($fedora_object[$dsid])) {
form_set_error('', t('Data stream ID already exists in object.')); form_set_error('', t('Data stream ID already exists in object.'));
return FALSE; return FALSE;
} }
@ -283,7 +287,7 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
$mimetype = new MimeDetect(); $mimetype = new MimeDetect();
$object = islandora_object_load($form_state['values']['pid']); $object = islandora_object_load($form_state['values']['pid']);
$unused_dsids = islandora_get_unused_dsids($object); $unused_dsids = islandora_get_unused_dsids($object);
if(isset($unused_dsids[$dsid])) { if (isset($unused_dsids[$dsid])) {
$types_allowed = $unused_dsids[$dsid]; $types_allowed = $unused_dsids[$dsid];
$arr = array(); $arr = array();
foreach ($types_allowed as $type) { foreach ($types_allowed as $type) {
@ -356,19 +360,19 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
); );
$unused_dsids = islandora_get_unused_dsids($object); $unused_dsids = islandora_get_unused_dsids($object);
$dsidsForForm = ''; $dsids_for_form = '';
$i = 0; $i = 0;
foreach ($unused_dsids as $key => $value) { foreach ($unused_dsids as $key => $value) {
if($i++) { if ($i++) {
$dsidsForForm .= ", "; $dsids_for_form .= ", ";
} }
$dsidsForForm .= "'$key'"; $dsids_for_form .= "'$key'";
} }
$form['add_fieldset']['stream_id'] = array( $form['add_fieldset']['stream_id'] = array(
'#title' => 'Datastream ID', '#title' => 'Datastream ID',
'#required' => 'TRUE', '#required' => 'TRUE',
'#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 dont currently exist: <b>' . $dsidsForForm . '</b>.'), '#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 dont currently exist: <b>' . $dsids_for_form . '</b>.'),
'#type' => 'textfield', '#type' => 'textfield',
'#weight' => -1, '#weight' => -1,
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete", '#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",
@ -379,13 +383,13 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
function islandora_datastream_autocomplete_callback($object, $string = '') { function islandora_datastream_autocomplete_callback($object, $string = '') {
$dsids = islandora_get_unused_dsids($object); $dsids = islandora_get_unused_dsids($object);
$output = array(); $output = array();
foreach($dsids as $id => $ds) { foreach ($dsids as $id => $ds) {
if(trim($string) == '') { if (trim($string) == '') {
$output[$id] = $id; $output[$id] = $id;
} }
else { else {
$ret = stripos($id, $string); $ret = stripos($id, $string);
if($ret !== FALSE) { if ($ret !== FALSE) {
$output[$id] = $id; $output[$id] = $id;
} }
} }
@ -397,7 +401,7 @@ function islandora_datastream_get_human_readable_size($ds) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
// we return - if we don't have a size // we return - if we don't have a size
if($ds->controlGroup == 'M' || $ds->controlGroup == 'X') { if ($ds->controlGroup == 'M' || $ds->controlGroup == 'X') {
return islandora_convert_bytes_to_human_readable($ds->size); return islandora_convert_bytes_to_human_readable($ds->size);
} }
else { else {
@ -406,7 +410,7 @@ function islandora_datastream_get_human_readable_size($ds) {
} }
function islandora_datastream_get_url($ds, $type = 'download') { function islandora_datastream_get_url($ds, $type = 'download') {
if($ds->controlGroup == 'R') { if ($ds->controlGroup == 'R') {
return $ds->url; return $ds->url;
} }
else { else {
@ -417,7 +421,7 @@ function islandora_datastream_get_url($ds, $type = 'download') {
function islandora_datastream_get_delete_link($ds) { function islandora_datastream_get_delete_link($ds) {
$datastreams = module_invoke_all('islandora_undeletable_datastreams', $ds->parent->models); $datastreams = module_invoke_all('islandora_undeletable_datastreams', $ds->parent->models);
if(in_array($ds->id, $datastreams)) { if (in_array($ds->id, $datastreams)) {
return ''; return '';
} }
else { else {

4
includes/ingest-menu.inc

@ -11,7 +11,7 @@
* @param string $pid * @param string $pid
*/ */
function islandora_ingest_callback($collection_object) { function islandora_ingest_callback($collection_object) {
if(!$collection_object) { if (!$collection_object) {
return drupal_not_found(); return drupal_not_found();
} }
@ -33,7 +33,7 @@ function islandora_ingest_callback($collection_object) {
} }
} }
//@TODO: theme // @TODO: theme
function islandora_ingest_registry_render($ingest_registry) { function islandora_ingest_registry_render($ingest_registry) {
$output = array( $output = array(
'#type' => 'markup', '#type' => 'markup',

7
includes/islandora.ingest.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains ingest callback functions
*/
function islandora_ingest_get_information(AbstractFedoraObject $collection_object) { function islandora_ingest_get_information(AbstractFedoraObject $collection_object) {
$models = $collection_object->models; $models = $collection_object->models;
$collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object); $collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object);
@ -12,7 +17,7 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation
global $user; global $user;
$connection = new IslandoraTuque($user); $connection = new IslandoraTuque($user);
$object = $connection->repository->constructObject($namespace); $object = $connection->repository->constructObject($namespace);
foreach($content_models as $content_model) { foreach ($content_models as $content_model) {
$object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model['pid']); $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model['pid']);
} }
$object->relationships->add(FEDORA_RELS_EXT_URI, $relationship, $collection_pid); $object->relationships->add(FEDORA_RELS_EXT_URI, $relationship, $collection_pid);

10
includes/islandora_dublin_core.inc

@ -108,9 +108,9 @@ class Dublin_Core {
if (is_array($values)) { if (is_array($values)) {
$value = ''; $value = '';
$i = 0; $i = 0;
foreach($values as $piece) { foreach ($values as $piece) {
if(!empty($piece)) { if (!empty($piece)) {
if($i++) { if ($i++) {
$value .= ", "; $value .= ", ";
} }
$value .= $piece; $value .= $piece;
@ -121,10 +121,10 @@ class Dublin_Core {
$value = $values; $value = $values;
} }
$dc_label = explode(':', $field); $dc_label = explode(':', $field);
$element_label = ucfirst($dc_label[1]); $element_label = drupal_ucfirst($dc_label[1]);
$dc_array[$field]['label'] = $element_label; $dc_array[$field]['label'] = $element_label;
$dc_array[$field]['value'] = $value; $dc_array[$field]['value'] = $value;
$dc_array[$field]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field)); $dc_array[$field]['class'] = drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field));
} }
} }
} }

2
includes/mime.detect.inc

@ -227,7 +227,7 @@ class MimeDetect {
public function getMimetype($filename, $debug = FALSE) { public function getMimetype($filename, $debug = FALSE) {
$file_name_and_extension = explode('.', $filename); $file_name_and_extension = explode('.', $filename);
$ext = strtolower(array_pop($file_name_and_extension)); $ext = drupal_strtolower(array_pop($file_name_and_extension));
if (!empty($this->protectedMimeTypes[$ext])) { if (!empty($this->protectedMimeTypes[$ext])) {
if (TRUE === $debug) { if (TRUE === $debug) {

20
includes/object_properties.inc

@ -1,7 +1,14 @@
<?php <?php
/** /**
* may want more validation here the only restrictions i see on * @file
* Contains admin form functions for object properties
*/
/**
* Validate function for object properties admin form.
*
* @TODO: may want more validation here the only restrictions i see on
* the object label and owner is the foxml schema says they should be * the object label and owner is the foxml schema says they should be
* an xsd:string there maybe further restrictions such as length but they aren't * an xsd:string there maybe further restrictions such as length but they aren't
* defined in the schema. * defined in the schema.
@ -18,6 +25,7 @@ function islandora_edit_properties_form_validate($form, &$form_state) {
} }
/** /**
* Submit function for object properties admin form.
* *
* @param array $form * @param array $form
* @param array $form_state * @param array $form_state
@ -32,7 +40,7 @@ function islandora_edit_properties_form_submit($form, &$form_state) {
$islandora_object->owner = $owner; $islandora_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())));
} }
} }
if (isset($state) && $state != $islandora_object->state) { if (isset($state) && $state != $islandora_object->state) {
@ -40,7 +48,7 @@ function islandora_edit_properties_form_submit($form, &$form_state) {
$islandora_object->state = $state; $islandora_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())));
} }
} }
if (isset($label) && $label != $islandora_object->label) { if (isset($label) && $label != $islandora_object->label) {
@ -53,12 +61,16 @@ function islandora_edit_properties_form_submit($form, &$form_state) {
} }
} }
/**
* Callback function for object properties admin form delete button.
*/
function islandora_edit_properties_form_delete($form, &$form_state) { function islandora_edit_properties_form_delete($form, &$form_state) {
$islandora_object = $form_state['values']['pid']; $islandora_object = $form_state['values']['pid'];
drupal_goto("islandora/object/$islandora_object/delete"); drupal_goto("islandora/object/$islandora_object/delete");
} }
/** /**
* Object properties admin form.
* *
* @param array $form * @param array $form
* @param array $form_state * @param array $form_state
@ -111,5 +123,3 @@ function islandora_edit_properties_form($form, &$form_state, $object) {
); );
return $form; return $form;
} }
?>

5
includes/purge.form.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains the admin (confirmation) form and callback functions to purge an object.
*/
/** /**
* Gives the option of deleting or purging and object. * Gives the option of deleting or purging and object.
* *

16
includes/tuque.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* 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 expost these in a module or library
@ -54,14 +59,15 @@ class IslandoraTuque {
public $repository = NULL; public $repository = NULL;
function __construct($user = NULL, $url = NULL) { function __construct($user = NULL, $url = NULL) {
if(!isset($user)) { if (!isset($user)) {
global $user; global $user;
} }
if(!isset($user) || $user->uid == 0){ if (!isset($user) || $user->uid == 0) {
$user_string = 'anonymous'; $user_string = 'anonymous';
$pass_string = 'anonymous'; $pass_string = 'anonymous';
} else { }
else {
$user_string = $user->name; $user_string = $user->name;
$pass_string = $user->pass; $pass_string = $user->pass;
} }
@ -70,7 +76,7 @@ class IslandoraTuque {
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
} }
if(self::exists()) { if (self::exists()) {
$this->connection = new RepositoryConnection($url, $user_string, $pass_string); $this->connection = new RepositoryConnection($url, $user_string, $pass_string);
$this->connection->reuseConnection = TRUE; $this->connection->reuseConnection = TRUE;
$this->api = new FedoraApi($this->connection); $this->api = new FedoraApi($this->connection);
@ -87,7 +93,7 @@ class IslandoraTuque {
$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));
drupal_set_message($message, 'error', FALSE); drupal_set_message(filter_xss($message), 'error', FALSE);
} }
} }

33
includes/utilities.inc

@ -1,13 +1,17 @@
<?php <?php
/**
* @file
* Contains islandora utility functions
*/
/** /**
* Convert bytes to human readable format * Convert bytes to human readable format
* *
* @param integer bytes Size in bytes to convert * @param integer bytes Size in bytes to convert
* @return string * @return string
*/ */
function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
{
$kilobyte = 1024; $kilobyte = 1024;
$megabyte = $kilobyte * 1024; $megabyte = $kilobyte * 1024;
$gigabyte = $megabyte * 1024; $gigabyte = $megabyte * 1024;
@ -15,25 +19,26 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2)
if (($bytes >= 0) && ($bytes < $kilobyte)) { if (($bytes >= 0) && ($bytes < $kilobyte)) {
return $bytes . ' B'; return $bytes . ' B';
}
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
return round($bytes / $kilobyte, $precision) . ' KB'; return round($bytes / $kilobyte, $precision) . ' KB';
}
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
return round($bytes / $megabyte, $precision) . ' MB'; return round($bytes / $megabyte, $precision) . ' MB';
}
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
return round($bytes / $gigabyte, $precision) . ' GB'; return round($bytes / $gigabyte, $precision) . ' GB';
}
} elseif ($bytes >= $terabyte) { elseif ($bytes >= $terabyte) {
return round($bytes / $terabyte, $precision) . ' TB'; return round($bytes / $terabyte, $precision) . ' TB';
} else { }
else {
return $bytes . ' B'; return $bytes . ' B';
} }
} }
function islandora_control_group_to_human_readable($control_group) { 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':
@ -54,7 +59,7 @@ function islandora_control_group_to_human_readable($control_group) {
*/ */
function islandora_validate_pid($pid) { function islandora_validate_pid($pid) {
$valid = FALSE; $valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) { if (drupal_strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
$valid = TRUE; $valid = TRUE;
} }
@ -68,7 +73,7 @@ function islandora_validate_pid($pid) {
*/ */
function islandora_validate_dsid($dsid) { function islandora_validate_dsid($dsid) {
$valid = FALSE; $valid = FALSE;
if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) { if (drupal_strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
$valid = TRUE; $valid = TRUE;
} }

26
islandora.api.php

@ -1,11 +1,17 @@
<?php <?php
/**
* @file
* This file lists and documents all available hook functions to manipulate data.
*/
/** /**
* remove a datastream from a repository object * remove a datastream from a repository object
* @param object $fedora_object * @param object $fedora_object
* tuque FedoraObject * tuque FedoraObject
* @param string $datastream_id * @param string $datastream_id
*/ */
function hook_islandora_purge_datastream ($fedora_object, $datastream_id){} function hook_islandora_purge_datastream($fedora_object, $datastream_id) {}
/** /**
* *
@ -30,7 +36,7 @@ function hook_islandora_purge_object($islandora_object) {}
* @param type $islandora_object * @param type $islandora_object
* tuque FedoraObject * tuque FedoraObject
*/ */
function hook_islandora_view_object($islandora_object){} function hook_islandora_view_object($islandora_object) {}
/** /**
* returns an array listing object types provided by sub modules * returns an array listing object types provided by sub modules
@ -39,7 +45,7 @@ function hook_islandora_view_object($islandora_object){}
* *
* @return array * @return array
*/ */
function hook_islandora_get_types(){} function hook_islandora_get_types() {}
/** /**
* allows modules to define an object edit page by cmodel * allows modules to define an object edit page by cmodel
@ -51,7 +57,7 @@ function hook_islandora_get_types(){}
* @return string * @return string
* *
*/ */
function hook_islandora_edit_object($islandora_object){} function hook_islandora_edit_object($islandora_object) {}
/** /**
* allows modules to alter the fedora object before it is pass through the edit * allows modules to alter the fedora object before it is pass through the edit
@ -59,13 +65,13 @@ function hook_islandora_edit_object($islandora_object){}
* @param type $islandora_object * @param type $islandora_object
* a tugue FedoraObject * a tugue FedoraObject
*/ */
function islandora_islandora_edit_object_alter ($islandora_object){} function islandora_islandora_edit_object_alter($islandora_object) {}
/** /**
* creates and populates a php Fedora object. * creates and populates a php Fedora object.
*/ */
function hook_islandora_preingest_alter(){} function hook_islandora_preingest_alter() {}
/** /**
* modules can implement this hook to add or remove datastreams after an * modules can implement this hook to add or remove datastreams after an
@ -77,7 +83,7 @@ function hook_islandora_preingest_alter(){}
* @param type $islandora_object * @param type $islandora_object
* tugue FeodoraObject * tugue FeodoraObject
*/ */
function hook_islandora_postingest($islandora_object){} function hook_islandora_postingest($islandora_object) {}
/** /**
* Register potential ingest routes. Implementations should return an array containing possible routes. * Register potential ingest routes. Implementations should return an array containing possible routes.
@ -99,7 +105,7 @@ function hook_islandora_edit_datastream_registry($islandora_object, $ds_id) {}
* @param type $object * @param type $object
* a tuque FedoraObject * a tuque FedoraObject
*/ */
function hook_islandora_object_alter ($fedora_object){} function hook_islandora_object_alter($fedora_object) {}
/** /**
* insert or remove rendered elements by implementing this function * insert or remove rendered elements by implementing this function
@ -107,7 +113,7 @@ function hook_islandora_object_alter ($fedora_object){}
* @param type $arr * @param type $arr
* an arr of rendered views * an arr of rendered views
*/ */
function hook_islandora_display_alter ($arr){} function hook_islandora_display_alter($arr) {}
/** /**
* *
@ -116,5 +122,5 @@ function hook_islandora_display_alter ($arr){}
* @param array $content_models * @param array $content_models
* @param string $collection_pid * @param string $collection_pid
*/ */
function hook_islandora_ingest_pre_ingest($islandora_object, $content_models, $collection_pid){} function hook_islandora_ingest_pre_ingest($islandora_object, $content_models, $collection_pid) {}

6
islandora.install

@ -0,0 +1,6 @@
<?php
/**
* @file
* This file contains all install functions.
*/

26
islandora.module

@ -1,9 +1,9 @@
<?php <?php
/* /*
* @file islandora.module * @file
* defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
* *
* islandora.module: defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
* *
* This file is part of Islandora. * This file is part of Islandora.
* *
@ -22,7 +22,7 @@
*/ */
//Permissions // Permissions
define('FEDORA_VIEW', 'view fedora repository'); define('FEDORA_VIEW', 'view fedora repository');
define('FEDORA_METADATA_EDIT', 'edit fedora metadata'); define('FEDORA_METADATA_EDIT', 'edit fedora metadata');
define('FEDORA_ADD_DS', 'add fedora datastreams'); define('FEDORA_ADD_DS', 'add fedora datastreams');
@ -31,12 +31,12 @@ define('FEDORA_PURGE', 'delete fedora objects and datastreams');
define('FEDORA_MODIFY_STATE', 'modify fedora state'); define('FEDORA_MODIFY_STATE', 'modify fedora state');
define('FEDORA_MANAGE', 'manage fedora items'); define('FEDORA_MANAGE', 'manage fedora items');
//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');
/** /**
* Implementation of hook_menu. * Implements hook_menu().
* we need some standard entry points so we can have consistent urls for different Object actions * we need some standard entry points so we can have consistent urls for different Object actions
*/ */
function islandora_menu() { function islandora_menu() {
@ -218,7 +218,7 @@ function islandora_admin_paths() {
* @return boolean * @return boolean
*/ */
function islandora_access_callback($object = NULL, $perm = NULL) { function islandora_access_callback($object = NULL, $perm = NULL) {
if(!$object || !$perm) { if (!$object || !$perm) {
return FALSE; return FALSE;
} }
@ -228,7 +228,7 @@ function islandora_access_callback($object = NULL, $perm = NULL) {
$namespace_access = TRUE; $namespace_access = TRUE;
} }
else { else {
$pid_namespace = substr($object->id, 0, strpos($object->id, ':') + 1); //Get the namespace (with colon) $pid_namespace = substr($object->id, 0, strpos($object->id, ':') + 1); // Get the namespace (with colon)
$allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); $allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$namespace_access = in_array($pid_namespace, $allowed_namespaces); $namespace_access = in_array($pid_namespace, $allowed_namespaces);
} }
@ -258,7 +258,7 @@ function islandora_init() {
* @return string * @return string
*/ */
function islandora_edit_object($object) { function islandora_edit_object($object) {
if(!$object) { if (!$object) {
return drupal_not_found(); return drupal_not_found();
} }
drupal_alter('islandora_edit_object', $object); drupal_alter('islandora_edit_object', $object);
@ -322,7 +322,7 @@ function islandora_view_object($fedora_object = NULL) {
module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/breadcrumb');
global $user; global $user;
if(!$fedora_object) { if (!$fedora_object) {
return drupal_not_found(); return drupal_not_found();
} }
@ -431,11 +431,11 @@ function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque');
static $islandora_tuque = NULL; static $islandora_tuque = NULL;
if(!$islandora_tuque) { if (!$islandora_tuque) {
$islandora_tuque = new IslandoraTuque(); $islandora_tuque = new IslandoraTuque();
} }
if(IslandoraTuque::exists()) { if (IslandoraTuque::exists()) {
try { try {
$fedora_object = $islandora_tuque->repository->getObject($object_id); $fedora_object = $islandora_tuque->repository->getObject($object_id);
} catch (Exception $e) { } catch (Exception $e) {
@ -450,13 +450,13 @@ function islandora_object_load($object_id) {
} }
function islandora_ingest_access_callback($object, $perm) { function islandora_ingest_access_callback($object, $perm) {
if(islandora_access_callback($object, $perm) === FALSE) { if (islandora_access_callback($object, $perm) === FALSE) {
return FALSE; return FALSE;
} }
$ingest_registry = module_invoke_all('islandora_ingest_registry', $object); $ingest_registry = module_invoke_all('islandora_ingest_registry', $object);
if(count($ingest_registry) > 0) { if (count($ingest_registry) > 0) {
return TRUE; return TRUE;
} }
else { else {

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

@ -1,30 +1,9 @@
<?php <?php
/* /**
* islandora-object-edit.tpl.php * @file
* * islandora-object-edit.tpl.php: This is a template for objects that do not have
* * a module to registered to build their display.
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
?>
<?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
@ -37,14 +16,9 @@
* and each element has an array of values. dc.title can have none, one or many titles * 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. * this is the case for all dc elements.
* *
*
*
*/ */
//dsm($object);
drupal_set_title($islandora_object->label);
//print($islandora_object->label . ' ' . $islandora_object->id);
print (theme_table($variables['datastream_table']));
?> ?>
<?php drupal_set_title($islandora_object->label); ?>
<?php print (theme_table($variables['datastream_table'])); ?>

26
theme/islandora-object.tpl.php

@ -1,30 +1,8 @@
<?php <?php
/* /*
* islandora-object.tpl.php * @file
* * This is a template for objects that do not have a module to registered to build their display.
*
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
?>
<?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 - The label for this object. * $object->label - The label for this object.

11
theme/islandora.theme.inc

@ -1,5 +1,10 @@
<?php <?php
/**
* @file
* This file contains all theme and preprocess functions.
*/
/** /**
* preprocess the edit template * preprocess the edit template
* @global string $base_url * @global string $base_url
@ -72,9 +77,11 @@ function islandora_preprocess_islandora_default(&$variables) {
$datastreams[$id]['mimetype'] = $ds->mimetype; $datastreams[$id]['mimetype'] = $ds->mimetype;
$datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds); $datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds);
$datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d"); $datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d");
$datastreams[$id]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id)); $datastreams[$id]['class'] = drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id));
}
catch (RepositoryException $e) {
} }
catch (RepositoryException $e) {}
} }
$variables['datastreams'] = $datastreams; $variables['datastreams'] = $datastreams;
try { try {

Loading…
Cancel
Save