From 54401f71e0d736b02e38dd8ad03c5d6bf9f58690 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 5 Apr 2013 14:24:40 -0300 Subject: [PATCH 1/8] Work around to handle the PHP-native stream wrappers. --- includes/utilities.inc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f061f72c..05c5320f 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -465,20 +465,41 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { $control_group = $ds['control_group']; } - $ds_uri = FALSE; + + $as_file = FALSE; if (file_valid_uri($ds['datastream_file'])) { + // A local file with as a Drupal file/stream wrapper URI. $datastream_file = $ds['datastream_file']; - $ds_uri = TRUE; + $as_file = TRUE; + } + elseif (is_readable($ds['datastream_file'])) { + // A local file as a filesystem path. + $datastream_file = drupal_realpath($ds['datastream_file']); + $as_file = TRUE; } else { - $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + $scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME); + if (in_array($scheme, stream_get_wrappers())) { + // A URI which gets handled by one of the PHP-native stream wrappers. + $datastream_file = $ds['datastream_file']; + $as_file = TRUE; + } + else { + // XXX: Dunno... No promises? Let's try to make a URL out of whatever + // this is. + $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( + '%file' => $datastream_file, + ), WATCHDOG_WARNING); + } } + $datastream = $object->constructDatastream($dsid, $control_group); $datastream->label = $label; $datastream->mimetype = $mimetype; switch ($control_group) { case 'M': - if ($ds_uri) { + if ($as_file) { $datastream->setContentFromFile($datastream_file); } else { @@ -490,8 +511,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromString(file_get_contents($datastream_file)); break; } + $object->ingestDatastream($datastream); } + return $object; } From 13e8839d5002c2a95b515c24c0be4b6b3958e40e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 16:36:04 -0300 Subject: [PATCH 2/8] Allow breadcrumbs to reliably be generated multiple times. --- includes/breadcrumb.inc | 88 +++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index dd8544a8..94dbd122 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -25,13 +25,8 @@ * drupal_set_breadcrumb(). */ function islandora_get_breadcrumbs($object) { - $breadcrumbs = array(); - islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); - if (isset($breadcrumbs[0])) { - // Remove the actual object. - unset($breadcrumbs[0]); - } - $breadcrumbs = array_reverse($breadcrumbs); + $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); + array_pop($breadcrumbs); return $breadcrumbs; } @@ -40,9 +35,6 @@ function islandora_get_breadcrumbs($object) { * * @todo Make fully recursive... * - * @todo Could use some clean up, can't be called multiple times safely due to - * the use of static variables. - * * @param string $pid * THe object id whose parent will be fetched for the next link. * @param array $breadcrumbs @@ -50,39 +42,44 @@ function islandora_get_breadcrumbs($object) { * @param FedoraRepository $repository * The fedora repository. */ -function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) { +function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) { // Before executing the query, we have a base case of accessing the top-level // collection. - static $max_level = 10; - static $level = -1; - - if (count($breadcrumbs) === 0) { - $level = $max_level; + if ($context === NULL) { + $context['level'] = 10; } $root = variable_get('islandora_repository_pid', 'islandora:root'); if ($pid == $root) { - $breadcrumbs[] = l(menu_get_active_title(), 'islandora'); - $breadcrumbs[] = l(t('Home'), ''); + return array( + l(t('Home'), ''), + l(menu_get_active_title(), 'islandora'), + ); } else { - $query_string = 'select $parentObject $title $content from <#ri> - where ( - $title - and $parentObject $content - and ( - $parentObject - or $parentObject - or $parentObject - ) - and $parentObject - ) - minus $content - minus $parentObject - order by $title desc'; - $results = $repository->ri->itqlQuery($query_string); + $query_string = << +WHERE { + ?object ?title ; + { + ?object ?parentObject . + } + UNION { + ?object ?parentObject . + } + UNION { + ?object ?parentObject . + } + ?parentObject . + FILTER (sameTerm(?object, )) + FILTER (!sameTerm(?object, ?parentObject)) +} +ORDER BY ?title +EOQ; + $results = $repository->ri->sparqlQuery($query_string); - if (count($results) > 0 && $level > 0) { + if (count($results) > 0 && $context['level'] > 0) { $parent = $results[0]['parentObject']['value']; $this_title = $results[0]['title']['value']; @@ -90,16 +87,23 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe $this_title = t('-'); } - $breadcrumbs[] = l($this_title, "islandora/object/$pid"); - - $level--; - islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); + $context['level']--; + return array_merge( + islandora_get_breadcrumbs_recursive($parent, $repository, $context), + array( + l($this_title, "islandora/object/$pid"), + ) + ); } else { - // Add an non-link, as we don't know how to get back to the root. - $breadcrumbs[] = '...'; - // And render the last two links and break (on the next pass). - islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); + // Add an non-link, as we don't know how to get back to the root, and + // render the last two links and break (on the next pass). + return array_merge( + islandora_get_breadcrumbs_recursive($root, $repository), + array( + '...' + ) + ); } } } From 7c9b20237bb8a2487a79040f1baed9a19ca37c10 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 16:40:08 -0300 Subject: [PATCH 3/8] Add content model dependant call of hook_islandora_object_view_alter(). --- islandora.api.php | 13 +++++++++++++ islandora.module | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 5e976194..a4fe1552 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -50,6 +50,19 @@ function hook_CMODEL_PID_islandora_view_object($object) { function hook_islandora_view_object_alter(&$object, &$rendered) { } +/** + * Alter display output if the object has the given model. + * + * @see hook_islandora_view_object_alter() + * @param FedoraObject $object + * A Tuque FedoraObject being operated on. + * @param array $rendered + * An arr of rendered views. + */ +function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { + +} + /** * Generate an object's management display. * diff --git a/islandora.module b/islandora.module index 981189bc..eafa271a 100644 --- a/islandora.module +++ b/islandora.module @@ -675,7 +675,8 @@ function islandora_view_object(FedoraObject $object) { $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $output = array(); - foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models) as $hook) { + $hooks = islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models); + foreach ($hooks as $hook) { // @todo Remove page number and size from this hook, implementers of the // hook should use drupal page handling directly. $temp = module_invoke_all($hook, $object, $page_number, $page_size); @@ -688,7 +689,7 @@ function islandora_view_object(FedoraObject $object) { $output = islandora_default_islandora_view_object($object); } arsort($output); - drupal_alter(ISLANDORA_VIEW_HOOK, $object, $output); + drupal_alter($hooks, $object, $output); return implode('', $output); } From fa569990643c0e29a42df7b73a78411b3361a1df Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:17:20 -0300 Subject: [PATCH 4/8] Revert "Work around to handle the PHP-native stream wrappers." This reverts commit 54401f71e0d736b02e38dd8ad03c5d6bf9f58690. --- includes/utilities.inc | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 05c5320f..f061f72c 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -465,41 +465,20 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { $control_group = $ds['control_group']; } - - $as_file = FALSE; + $ds_uri = FALSE; if (file_valid_uri($ds['datastream_file'])) { - // A local file with as a Drupal file/stream wrapper URI. $datastream_file = $ds['datastream_file']; - $as_file = TRUE; - } - elseif (is_readable($ds['datastream_file'])) { - // A local file as a filesystem path. - $datastream_file = drupal_realpath($ds['datastream_file']); - $as_file = TRUE; + $ds_uri = TRUE; } else { - $scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME); - if (in_array($scheme, stream_get_wrappers())) { - // A URI which gets handled by one of the PHP-native stream wrappers. - $datastream_file = $ds['datastream_file']; - $as_file = TRUE; - } - else { - // XXX: Dunno... No promises? Let's try to make a URL out of whatever - // this is. - $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( - '%file' => $datastream_file, - ), WATCHDOG_WARNING); - } + $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); } - $datastream = $object->constructDatastream($dsid, $control_group); $datastream->label = $label; $datastream->mimetype = $mimetype; switch ($control_group) { case 'M': - if ($as_file) { + if ($ds_uri) { $datastream->setContentFromFile($datastream_file); } else { @@ -511,10 +490,8 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromString(file_get_contents($datastream_file)); break; } - $object->ingestDatastream($datastream); } - return $object; } From 945d8f4188a2a6dcb4d856035d830f40f6e85a9d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:19:44 -0300 Subject: [PATCH 5/8] Revert back to iTQL query for breadcrumbs. --- includes/breadcrumb.inc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 94dbd122..497caeaa 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -57,27 +57,21 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, ); } else { - $query_string = << -WHERE { - ?object ?title ; - { - ?object ?parentObject . - } - UNION { - ?object ?parentObject . - } - UNION { - ?object ?parentObject . - } - ?parentObject . - FILTER (sameTerm(?object, )) - FILTER (!sameTerm(?object, ?parentObject)) -} -ORDER BY ?title -EOQ; - $results = $repository->ri->sparqlQuery($query_string); + $query_string = 'select $parentObject $title $content from <#ri> + where ( + $title + and $parentObject $content + and ( + $parentObject + or $parentObject + or $parentObject + ) + and $parentObject + ) + minus $content + minus $parentObject + order by $title desc'; + $results = $repository->ri->itqlQuery($query_string); if (count($results) > 0 && $context['level'] > 0) { $parent = $results[0]['parentObject']['value']; From 068535ce95f8f5680dfd252586ea30f34ba60eb3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:31:03 -0300 Subject: [PATCH 6/8] Fixes for Travis... Oops. --- includes/breadcrumb.inc | 6 ++---- islandora.api.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 497caeaa..01d4b9f7 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -36,9 +36,7 @@ function islandora_get_breadcrumbs($object) { * @todo Make fully recursive... * * @param string $pid - * THe object id whose parent will be fetched for the next link. - * @param array $breadcrumbs - * The list of existing bread-crumb links in reverse order. + * The object id whose parent will be fetched for the next link. * @param FedoraRepository $repository * The fedora repository. */ @@ -95,7 +93,7 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, return array_merge( islandora_get_breadcrumbs_recursive($root, $repository), array( - '...' + '...', ) ); } diff --git a/islandora.api.php b/islandora.api.php index a4fe1552..b47bbcdc 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -54,13 +54,13 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * Alter display output if the object has the given model. * * @see hook_islandora_view_object_alter() + * * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered * An arr of rendered views. */ function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { - } /** From f9586f9f9b05b4653b82ea733aeb289d751972bd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 8 Apr 2013 18:36:54 -0300 Subject: [PATCH 7/8] Fix where the context failed to get passed. --- includes/breadcrumb.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 01d4b9f7..5a21b86c 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -91,7 +91,7 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, // Add an non-link, as we don't know how to get back to the root, and // render the last two links and break (on the next pass). return array_merge( - islandora_get_breadcrumbs_recursive($root, $repository), + islandora_get_breadcrumbs_recursive($root, $repository, $context), array( '...', ) From 12bd3005841d4f87ed08deec52d73f01b021d9ad Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 8 Apr 2013 18:52:40 -0300 Subject: [PATCH 8/8] Flesh out inline function documentation. --- includes/breadcrumb.inc | 8 ++++++++ islandora.api.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 5a21b86c..6fdf9e4a 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -39,6 +39,14 @@ function islandora_get_breadcrumbs($object) { * The object id whose parent will be fetched for the next link. * @param FedoraRepository $repository * The fedora repository. + * @param array $context + * An associative array of context for internal use when recursing. Currently + * only used to track a single value: + * - level: The number of child-parent relationships to follow. Defaults to + * 10. + * + * @return array + * An array of links representing the breadcrumb trail, "root" first. */ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) { // Before executing the query, we have a base case of accessing the top-level diff --git a/islandora.api.php b/islandora.api.php index b47bbcdc..d1d58f4f 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -45,7 +45,7 @@ function hook_CMODEL_PID_islandora_view_object($object) { * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered - * An arr of rendered views. + * The array of rendered views. */ function hook_islandora_view_object_alter(&$object, &$rendered) { } @@ -58,7 +58,7 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered - * An arr of rendered views. + * The array of rendered views. */ function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { }