From 967fcce4487b0f2d5caa7313fb4140347b3f6cb9 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 16 Oct 2012 17:18:27 -0300 Subject: [PATCH 01/13] trying to not send notcies when checking for ahah_submission --- fedora_repository.module | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 1beb9b06..d794c20c 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -123,11 +123,12 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label */ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { // Only validate the form if the submit button was pressed (other buttons may be used for AHAH. - if ($form_state['ahah_submission']) { + if (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']) { $form_state['submitted'] = FALSE; return; } + if ($form_state['storage']['xml'] && module_exists('islandora_content_model_forms')) { module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm'); $xml_form = new IngestObjectMetadataForm(); @@ -183,11 +184,12 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) { */ function fedora_repository_ingest_form_validate($form, &$form_state) { // Only validate the form if the submit button was pressed (other buttons may be used for AHAH. - if ($form_state['ahah_submission']) { + $is_ahah_submission = (array_key_exists('ahah_submission', $form_state) && $form_state['ahah_submission']); + if ($is_ahah_submission) { $form_state['submitted'] = FALSE; return; } - if (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0 && $form_state['ahah_submission'] != 1) { + if (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0 && !$is_ahah_submission) { switch ($form_state['storage']['step']) { case 1: $form_state['storage']['step']++; From 40bc0f1eb888a9a9ead331cd2cfba71afbaebc07 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 17 Oct 2012 12:14:46 -0300 Subject: [PATCH 02/13] ISLANDORA-763: Move and rename pager Moved from CollectionClass::hackPager to fedora_repository_setup_pager in PagerSetup.inc --- CollectionClass.inc | 63 ++------------------------------------------- PagerSetup.inc | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 61 deletions(-) create mode 100644 PagerSetup.inc diff --git a/CollectionClass.inc b/CollectionClass.inc index bd44bbe8..87f1f4b6 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -604,66 +604,6 @@ class CollectionClass { return $ingestObject; } - /** - * Unfortunate function, I know... - * - * Does just what it says: Hacks the default Drupal pager such that it might - * be rendered, likely with: theme('pager', array(), $per_page, $pager_name) - * (I reccomend seeing the real documentation for more detail, but the first - * array can be a list of the tags to use for first, previous, next and last - * (text in the pager), I don't believe per_page is actually used in the theme - * function, and $pager_name is an integer used to identify the pager (such - * that there can be more than one--that is, tracking different lists of - * content on a single page. You can render the exact same pager multiple - * times, say if you want one at the top and bottom of a list, using the same - * ID/pager_name. - * - * @global $pager_total array - * Numerically indexed array, where keys are the $pager_names and values - * are the number of pages in the given set, based on: ceil($total_items/$per_page); - * @global $pager_page_array array - * Numerically indexed array, where keys are the $pager_names and values - * are the page selected in the relevant set. - * @param $pager_name int - * An integer to identify the pager to affect. Do note that paging in using - * this function will add the 'page' HTTP GET parameter to the URL, with - * the value containing a comma-separated list with max($pager_name + 1) - * values--that is, if you create a single pager named '10', the 'next' - * link will look something like: 0,0,0,0,0,0,0,0,0,0,1 - * @param $per_page int - * An integer representing the number of items per page. - * @param $total_items int - * An integer representing the total number of items in the set. - * @return int - * An integer representing what the current page should be. - */ - protected static function hackPager($pager_name, $per_page = NULL, $total_items = NULL) { - global $pager_total, $pager_page_array; - - if ($per_page !== NULL && $total_items !== NULL) { - $pager_total[$pager_name] = ceil($total_items / $per_page); - } - - //XXX: Don't know that this is neccessary, to try to load all the time, or - // whether Drupal will load it automatically somewhere... Docs seems a - // a little sparse. - $page_info = explode(',', isset($_GET['page']) ? $_GET['page'] : ''); - $page = $page_info[$pager_name]; - if ($page < 0) { - $page = 0; - } - - if (!isset($pager_page_array)) { - $pager_page_array = pager_load_array($page, $pager_name, $page_info); - } - else { - $pager_page_array = pager_load_array($page, $pager_name, $pager_page_array); - } - - $page = $pager_page_array[$pager_name]; - return $page; - } - /** * Assemble results in a somewhat more logical manner... * @@ -683,10 +623,11 @@ class CollectionClass { * list of items, and another pager. */ public static function assembleCollectionView($sparql_results) { + module_load_include('inc', 'fedora_repository', 'PagerSetup'); $per_page = 20; //XXX: Make this configurable. $pager_name = 0; $total = count($sparql_results); - $pager_page = self::hackPager($pager_name, $per_page, $total); + $pager_page = fedora_repository_setup_pager($pager_name, $per_page, $total); $max_title_length = 60; $results = array(); diff --git a/PagerSetup.inc b/PagerSetup.inc new file mode 100644 index 00000000..c4fb7c32 --- /dev/null +++ b/PagerSetup.inc @@ -0,0 +1,62 @@ + Date: Wed, 17 Oct 2012 15:39:32 -0300 Subject: [PATCH 03/13] Add support to default to DC transform for Object Details if desired datastream is missing --- ObjectDetails.inc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 38409615..1dacf49f 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -72,6 +72,11 @@ function fedora_repository_object_details_XSLT($item) { } $xmlstr = $item->get_datastream_dissemination($dsid); + $default_to_dc = FALSE; + if (empty($xmlstr) && variable_get('islandora_object_details_xslt_default_dc', FALSE) && $dsid != 'DC' && $dsid != 'QDC') { + $xmlstr = $item->get_datastream_dissemination('DC'); + $default_to_dc = TRUE; + } if (empty($xmlstr)) { return t('Error - could not find datastream @dsid on object @pid
Please contact the site administrator.', array('@dsid' => $dsid, '@pid' => $item->pid)); @@ -88,7 +93,13 @@ function fedora_repository_object_details_XSLT($item) { $proc->setParameter('', 'path', $path); $input = NULL; - $xsl_file = variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'); + if (!$default_to_dc) { + $xsl_file = variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'); + } + else { + $xsl_file = 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'; + } + // set an error message in case xslt parsing fails $output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file)); if (is_readable($xsl_file)) { @@ -191,6 +202,11 @@ function fedora_repository_object_details_XSLT_config() { '#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'), '#required' => TRUE, ); + $form['config']['default_dc'] = array( + '#type' => 'checkbox', + '#title' => t("If the datastream to transform is unavailable, attempt to transform using the DC datastream"), + '#default_value' => variable_get('islandora_object_details_xslt_default_dc', FALSE), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), @@ -210,6 +226,7 @@ function fedora_repository_object_details_XSLT_config_submit($form, &$form_state variable_set('islandora_object_details_display_table', 'xslt'); variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); + variable_set('islandora_object_details_xslt_default_dc', $form_state['values']['default_dc']); drupal_set_message('Object Details view has been set to XSLT and your configuration has been saved'); } From bc708b1574dc7e9bced958e5f8d569b76c683ce7 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 16:05:56 -0300 Subject: [PATCH 04/13] Add support to default to DC for Object Details on table view if datastream is missing --- ObjectDetails.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 1dacf49f..16276cef 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -137,7 +137,10 @@ function fedora_repository_object_details_table($item) { $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; } $xmlstr = $item->get_datastream_dissemination($dsid); - + + if (empty($xmlstr) && variable_get('islandora_object_details_table_default_dc', FALSE) && $dsid != 'DC' && $dsid != 'QDC') { + $xmlstr = $item->get_datastream_dissemination('DC'); + } if (empty($xmlstr)) { return t('Error - could not find datastream @dsid on object @pid
Please contact the site administrator.', array('@dsid' => $dsid, '@pid' => $item->pid)); @@ -270,6 +273,11 @@ function fedora_repository_object_details_table_config() { '#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'), '#required' => TRUE, ); + $form['config']['default_dc'] = array( + '#type' => 'checkbox', + '#title' => t("If the datastream to transform is unavailable, attempt to transform using the DC datastream"), + '#default_value' => variable_get('islandora_object_details_table_default_dc', FALSE), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), @@ -289,5 +297,6 @@ function fedora_repository_object_details_table_config() { function fedora_repository_object_details_table_config_submit($form, &$form_state) { variable_set('islandora_object_details_display_table', 'table'); variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); + variable_set('islandora_object_details_table_default_dc', $form_state['values']['default_dc']); drupal_set_message('Object Details view has been set to Table and your configuration has been saved'); } From 61859a078b6ead731144955c0c0803873214b1f7 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 17:26:13 -0300 Subject: [PATCH 05/13] Display dsid in table header for table Object Details view --- ObjectDetails.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 16276cef..4bd46790 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -150,7 +150,7 @@ function fedora_repository_object_details_table($item) { $headers = array( array( - 'data' => t('Metadata'), + 'data' => t('@dsid Metadata', array('@dsid' => $dsid)), 'colspan' => 2, ), ); From ff0893a30b5fd1ee2396e9cdbc7a25ceb09c0a57 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 17 Oct 2012 18:18:05 -0300 Subject: [PATCH 06/13] ISLANDORA-764: Rewrite core permissions handling Needed to be able to give permissions from other places, like XACML... In order to do so, we have to break out of the context of Drupal permissions, and the use of user_access(). Instead, we have introduced the function fedora_repository_check_perm() (in addition to deprecating the old fedora_repository_access(), to avoid possible confusion with the hook_access() used by Drupal nodes). This new function calls a hook of the same name (hook_fedora_repository_check_perm()), to allow other modules to influence the outcome. The default/core implementation should function as permissions previously worked. --- CollectionClass.inc | 6 +- ObjectHelper.inc | 48 +-- SearchClass.inc | 4 +- api/fedora_collection.inc | 3 +- fedora_repository.api.php | 28 ++ fedora_repository.module | 386 +++++++----------------- formClass.inc | 31 +- plugins/FedoraObjectDetailedContent.inc | 6 +- plugins/ShowStreamsInFieldSets.inc | 2 +- plugins/herbarium.inc | 2 +- plugins/tagging_form.inc | 6 +- 11 files changed, 184 insertions(+), 338 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 87f1f4b6..fe5528eb 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -102,7 +102,7 @@ class CollectionClass { function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); return ' '; } @@ -321,7 +321,7 @@ class CollectionClass { * @return type */ function getAndDoRules($file, $mimetype, $pid, $dsid) { - if (!user_access('ingest new fedora objects')) { + if (!fedora_repository_check_perm('ingest new fedora objects', $pid)) { drupal_set_message(t('You do not have permission to ingest objects.')); return FALSE; } @@ -586,7 +586,7 @@ class CollectionClass { function getIngestInterface() { module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); $collectionPolicyExists = $this->collectionObject->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); - if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { + if (fedora_repository_check_perm(ObjectHelper :: $INGEST_FEDORA_OBJECTS, $this->pid) && $collectionPolicyExists) { if (!empty($collectionPolicyExists)) { $allow = TRUE; if (module_exists('fedora_fesl')) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 698e5d42..1fe1ae7b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -93,7 +93,7 @@ class ObjectHelper { return ' '; } - if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { drupal_set_message(t("You do not have access Fedora objects within the attempted namespace."), 'error'); drupal_access_denied(); return ' '; @@ -298,7 +298,7 @@ class ObjectHelper { drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error'); return ''; } - if (!fedora_repository_access(ObjectHelper :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(ObjectHelper :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { drupal_set_message(t('You do not have the appropriate permissions'), 'error'); return; } @@ -333,7 +333,7 @@ class ObjectHelper { drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error'); return ''; } - if (!fedora_repository_access(ObjectHelper :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(ObjectHelper :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { drupal_set_message(t('You do not have the appropriate permissions'), 'error'); return; } @@ -368,7 +368,7 @@ class ObjectHelper { $item = new Fedora_Item($pid); $purge_image = ' '; - if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { + if (fedora_repository_check_perm(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $pid)) { $allow = TRUE; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); @@ -388,7 +388,7 @@ class ObjectHelper { // Add an icon to replace a datastream // @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled. $replace_image = ' '; - if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { + if (fedora_repository_check_perm(ObjectHelper :: $ADD_FEDORA_STREAMS, $pid)) { $allow = TRUE; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); @@ -533,7 +533,7 @@ class ObjectHelper { $dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC'; $path = drupal_get_path('module', 'fedora_repository'); - if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { + if (fedora_repository_check_perm(ObjectHelper :: $EDIT_FEDORA_METADATA, $pid)) { $allow = TRUE; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); @@ -573,7 +573,7 @@ class ObjectHelper { $dataStreamBody = ''; $fedoraItem = new Fedora_Item($object_pid); - if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) { + if (fedora_repository_check_perm(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST, $object_pid)) { $availableDataStreamsText = 'Detailed List of Content'; $mainStreamLabel = NULL; @@ -606,7 +606,7 @@ class ObjectHelper { $dataStreamBody = theme('table', $headers, $DSs); //if they have access let them add a datastream - if (user_access(ObjectHelper::$ADD_FEDORA_STREAMS) && //If allowed throw Drupal + if (fedora_repository_check_perm(ObjectHelper::$ADD_FEDORA_STREAMS, $object_pid) && //If allowed throw Drupal ((module_exists('fedora_fesl') && fedora_fesl_check_roles($object_pid, 'write')) || //And allowed throw FESL !module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form. $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid); @@ -673,36 +673,6 @@ class ObjectHelper { return $cmodels; } - /** - * determines whether we can see the object or not - * checks PID namespace permissions, and user permissions - * @global type $user - * @param type $op - * @param type $pid - * @return type - */ - function fedora_repository_access($op, $pid = NULL, $as_user = NULL) { - $returnValue = FALSE; - - if ($pid == NULL) { - $pid = variable_get('fedora_repository_pid', 'islandora:root'); - } - - $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); - $namespace_access = NULL; - if (!$isRestricted) { - $namespace_access = TRUE; - } - else { - $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon) - $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); - - $namespace_access = in_array($pid_namespace, $allowed_namespaces); - } - - return ($namespace_access && user_access($op, $as_user)); - } - /** * Get the query to find parent objects. * @@ -795,7 +765,7 @@ class ObjectHelper { * @return boolean */ function get_and_do_datastream_rules($pid, $dsid, $file = '') { - if (!user_access('ingest new fedora objects')) { + if (!fedora_repository_check_perm('ingest new fedora objects', $pid)) { drupal_set_message(t('You do not have permission to add datastreams.')); return FALSE; } diff --git a/SearchClass.inc b/SearchClass.inc index 473076a1..4230257b 100644 --- a/SearchClass.inc +++ b/SearchClass.inc @@ -187,7 +187,7 @@ class SearchClass { function quickSearch($type, $query, $showForm = 1, $orderBy = 0, & $userArray) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - if (user_access('view fedora collection')) { + if (fedora_repository_check_perm('view fedora collection')) { $numberOfHistPerPage = '5000'; //hack for IR they do not want next button $luceneQuery = NULL; // Demo search string ?operation=gfindObjects&indexName=DemoOnLucene&query=fgs.DS.first.text%3Achristmas&hitPageStart=11&hitPageSize=10 @@ -272,7 +272,7 @@ class SearchClass { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - if (user_access('view fedora collection')) { + if (fedora_repository_check_perm('view fedora collection')) { //$numberOfHistPerPage = '50';//hack for IR they do not want next button $luceneQuery = NULL; $indexName = variable_get('fedora_index_name', 'DemoOnLucene'); diff --git a/api/fedora_collection.inc b/api/fedora_collection.inc index 200fb324..52b830df 100644 --- a/api/fedora_collection.inc +++ b/api/fedora_collection.inc @@ -70,8 +70,7 @@ function export_collection($collection_pid, $relationship = 'isMemberOfCollectio function get_related_items_as_xml($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - global $user; - if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); return array(); } diff --git a/fedora_repository.api.php b/fedora_repository.api.php index 724078b2..190c9ec1 100644 --- a/fedora_repository.api.php +++ b/fedora_repository.api.php @@ -95,6 +95,8 @@ function hook_required_fedora_objects() { * Override ingest permissions. * (from islandora_workflow) * + * @deprecated + * Deprecated in favour of hook_fedora_repository_check_perm(). * @param string $collection_pid * The PID of the collection * @@ -107,3 +109,29 @@ function hook_fedora_repository_can_ingest($collection_pid) { return (islandora_workflow_user_collection_permission_check($collection_pid) !== FALSE); } + +/** + * Implements hook_fedora_repository_check_perm(). + * + * Hook to allow other modules to allow or deny operations on conditions other + * than the explicit Drupal permissions. + * + * @param string $op + * A string representing the operation to be performed. + * @param string|null $pid + * A string containing the Fedora PID on which the operation is to be + * performed. The (default) value of NULL will use the PID indicated by the + * fedora_repository_pid Drupal variable. + * @param object|null $as_user + * An object representing the user for whom to check the permissions (as + * given by user_load or the $user global). The (default) value of NULL will + * cause permissions to be evaluated for the current user (from the $user + * global). + * + * @return boolean|null + * Either a boolean permitting (TRUE) or forbidding (FALSE) an operation, or + * NULL to make no assertion. + */ +function hook_fedora_repository_check_perm($op, $pid = NULL, $as_user = NULL) { + return NULL; +} diff --git a/fedora_repository.module b/fedora_repository.module index 1beb9b06..a120029c 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -54,15 +54,11 @@ function fedora_repository_help($path, $arg) { * * @return type */ -function fedora_repository_purge_object($pid = NULL, $name = NULL) { - if (!user_access('purge objects and datastreams')) { +function fedora_repository_purge_object($pid, $name = NULL) { + if (!fedora_repository_check_perm('purge objects and datastreams', $pid)) { drupal_set_message(t('You do not have access to add a datastream to this object.'), 'error'); return ''; } - if ($pid == NULL) { - drupal_set_message(t('You must specify an object pid to purge an object.'), 'error'); - return ''; - } $output = t('Are you sure you wish to purge object %name %pid!
This cannot be undone
', array( '%name' => $name, '%pid' => $pid) @@ -75,16 +71,18 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) { /** * fedora repository ingest object * + * XXX: Is this even used? + * * @param type $collection_pid * @param type $collection_label * @param type $content_model * * @return type */ -function fedora_repository_ingest_object($collection_pid=NULL, $collection_label = NULL, $content_model = NULL) { +function fedora_repository_ingest_object($collection_pid, $collection_label = NULL, $content_model = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - if (!user_access('ingest new fedora objects')) { + if (!fedora_repository_check_perm('ingest new fedora objects', $collection_pid)) { drupal_set_message(t('You do not have permission to ingest.'), 'error'); return ''; } @@ -296,10 +294,7 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio */ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) { global $base_url; - if (!user_access('purge objects and datastreams')) { - return NULL; - } - if ($pid == NULL) { + if (!fedora_repository_check_perm('purge objects and datastreams', $pid)) { return NULL; } $form['pid'] = array( @@ -339,25 +334,21 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL /** * add stream * - * @param type $collection_pid + * @param type $pid * @param type $collectionName * * @return type */ -function add_stream($collection_pid=NULL, $collectionName=NULL) { +function add_stream($pid, $collectionName=NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); if (!valid_pid($collection_pid)) { drupal_set_message(t("This PID is not valid!"), 'error'); return ' '; } - if (!user_access('ingest new fedora objects')) { + if (!fedora_repository_check_perm('add fedora datastreams', $pid)) { drupal_set_message(t('You do not have permission to ingest.'), 'error'); return ''; } - if ($collection_pid == NULL) { - drupal_set_message(t('You must specify an collection object pid to ingest an object.'), 'error'); - return ''; - } $output .= drupal_get_form('fedora_repository_add_stream_form', $pid); return $output; @@ -506,7 +497,7 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL) drupal_set_message(t('You must specify an object pid and DataStream ID to purge a datastream'), 'error'); return ' '; } - if (!fedora_repository_access(OBJECTHELPER :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $pid, $user)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or you do not have permission to purge objects."), 'error'); return ' '; } @@ -658,7 +649,7 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $ ), ); - if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { + if (fedora_repository_check_perm(ObjectHelper::$EDIT_FEDORA_METADATA, $pid)) { $item = new Fedora_Item($pid); $versions = $item->get_datastream_history($dsid); $version_array = array(); @@ -809,7 +800,7 @@ function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { drupal_set_message(t('You must specify an object pid and a Dublin Core DataStream ID to edit metadata'), 'error'); return ' '; } - if (!fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $pid, $user)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or you do not have permission to edit meta data for this object."), 'error'); return ' '; } @@ -833,7 +824,7 @@ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) { drupal_set_message(t('You must specify an object pid!'), 'error'); } global $user; - if (!fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $pid, $user)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or you do not have permission to edit meta data for this object."), 'error'); return ' '; } @@ -936,21 +927,6 @@ function fedora_repository_perm() { ); } -/** - * drupal hook - * determines if a user has access to what they are asking for - * - * @param type $op - * @param type $node - * @param type $account - * @return type - */ -function fedora_repository_access($op, $node = NULL, $account = NULL) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $objectHelper = new ObjectHelper(); - return $objectHelper->fedora_repository_access($op, $node, $account); -} - /** * Grabs a stream from fedora sets the mimetype and returns it. $dsID is the * datastream id. @@ -975,7 +951,7 @@ function makeObject($pid, $dsID) { return ' '; } global $user, $conf; - if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { drupal_access_denied(); return; drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace."), 'error'); @@ -1118,7 +1094,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU drupal_set_message(t("Invalid dsID!"), 'error'); return ' '; } - if (!fedora_repository_access(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { if (user_access('access administration pages')) { drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed !here", array('!here' => l('here', 'admin/settings/fedora_repository'))), 'warning'); } @@ -1185,7 +1161,7 @@ function fedora_repository_urlencode_string($str) { * Uses makeobject to get a stream. Sets the Content Disposition in the header so it suggests a filename * and sends it as an attachment. This should prompt for a download of the object. * - * @global type $user + * @global type $conf * @param type $pid * @param type $dsId * @param type $label @@ -1209,6 +1185,7 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { /** * repository page + * * @param type $pid * @param type $dsId * @param type $collection @@ -1223,6 +1200,9 @@ function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNum /** * repository service + * + * XXX: Is this even used? + * * @global type $user * @param type $pid * @param type $servicePid @@ -1234,7 +1214,7 @@ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NU module_load_include('inc', 'fedora_repository', 'ObjectHelper'); global $user; - if (!fedora_repository_access(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + if (!fedora_repository_check_perm(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { //drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied"), 'error'); drupal_access_denied(); if (user_access('access administration pages')) { @@ -1603,238 +1583,6 @@ function fedora_repository_mnpl_advanced_search_form_submit($form, &$form_state) drupal_goto("fedora/repository/mnpl_advanced_search/$searchString"); } -/** - * fedora repository install demo page - * @return type - */ -function fedora_repository_install_demos_page() { - $output = drupal_get_form('fedora_repository_demo_objects_form'); - return $output; -} - -/** - * fedora repository demo objects form - * @return string - */ -function fedora_repository_demo_objects_form() { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $form = array(); - $existing_demos = array(); - - $form['install_demos'] = array( - '#title' => t('Islandora Demo Collections'), - '#type' => 'fieldset', - '#description' => t('Install demo image and document collections and content models.'), - ); - $demo_objects = array(); -// Check if the top-level islandora collection exists. If not, display a button to ingest. - - $form['install_demos']['demo_collections'] = array( - '#type' => 'checkboxes', - '#title' => t('Collections to ingest'), - '#options' => array(), - '#description' => t('Choose which demo collections you would like ingested into the repository.'), - ); - - foreach (array( -'islandora:collectionCModel' => 'Islandora default content models', - 'islandora:root' => 'Islandora top-level collection', - 'islandora:demos' => 'Islandora demos collection', - 'islandora:largeimages' => 'Sample large image content model (requires Djatoka and Kakadu.)', - ) - as $available_demo => $available_demo_desc) { - try { - $demo_objects[$available_demo] = new Fedora_Item($available_demo); - } catch (exception $e) { - - } - - if (empty($demo_objects[$available_demo]->objectProfile)) { -//The demo objects collection does not exist in the repository, display a button to ingest them. - $form['install_demos']['demo_collections']['#options'][$available_demo] = $available_demo_desc; - } - else { - array_push($existing_demos, $demo_objects[$available_demo]); - } - } - -// Check if the SmileyStuff collectoin exists, and if it has a COLLECTION_VIEW datastream. If it doesn't then we can add it. - - $smiley_stuff = new Fedora_Item('demo:SmileyStuff'); - if (!empty($smiley_stuff->objectProfile)) { - $datastreams_list = $smiley_stuff->get_datastreams_list_as_array(); - if (empty($datastreams_list['COLLECTION_VIEW'])) { - $form['install_demos']['demo_collections']['#options']['demo:SmileyStuff'] = 'Add Islandora Collection View to Fedora Smiley Stuff Collection'; - } - else { - $demo_objects['demo:SmileyStuff'] = $smiley_stuff; - } - } - else { - $form['install_demos']['smileynote'] = array( - '#value' => '

If you install the ' . l('fedora demo objects', 'https://wiki.duraspace.org/display/FCR30/Demonstration+Objects') . ' Islandora can display them as a collection.

' - ); - } - - $form['install_demos']['ingest'] = array( - '#type' => 'submit', - '#name' => 'install_demos', - '#value' => 'Install Selected Demos', - '#disabled' => (empty($form['install_demos']['demo_collections']['#options'])) ? TRUE : FALSE, - ); - - $form['existing_demos'] = array( - '#prefix' => '

Demo collections already installed in this repository:

    ', - '#suffix' => '
', - ); - - if (!empty($existing_demos)) { - foreach ($existing_demos as $pid => $demo_object) { - - $form['existing_demos'][$demo_object->pid] = array( - '#prefix' => '
  • ', - '#value' => l($demo_object->pid, $demo_object->url()), - '#suffix' => '
  • ', - ); - } - } - - return $form; -} - -/** - * fedora repository demo objects form submit - * @global type $base_url - * @param type $form - * @param type $form_state - */ -function fedora_repository_demo_objects_form_submit($form, &$form_state) { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - module_load_include('inc', 'fedora_repository', 'api/dublin_core'); - module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - global $base_url; - if ($form_state['clicked_button']['#name'] == 'install_demos') { - if (!empty($form_state['values']['demo_collections']['islandora:collectionCModel'])) { - try { - $collectioncm = Fedora_Item::ingest_new_item('islandora:collectionCModel', 'A', 'Islandora Collection Content Model'); - $collectioncm->add_relationship('hasModel', 'fedora-system:ContentModel-3.0', FEDORA_MODEL_URI); - $collectioncm->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/COLLECTIONCM.xml', 'ISLANDORACM', 'Islandora Content Model.xml', 'application/xml', 'X'); - } catch (exception $e) { - - } - try { - $strictpdfcm = Fedora_Item::ingest_new_item('islandora:strict_pdf', 'A', 'Strict PDF Content Model'); - $strictpdfcm->add_relationship('hasModel', 'fedora-system:ContentModel-3.0', FEDORA_MODEL_URI); - $strictpdfcm->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/STRICT_PDFCM.xml', 'ISLANDORACM', 'Islandora Content Model.xml', 'application/xml', 'X'); - } catch (exception $e) { - - } - -// Install a collection object that points to all content model objects - try { - $cmodel_collection_xml = Fedora_Item::create_object_FOXML('islandora:ContentModelCollection'); - $cmodel_collection = Fedora_Item::ingest_from_FOXML($cmodel_collection_xml); - -//$dc = new Dublin_Core(new Fedora_Item('islandora:ContentModelCollection')); - $dc = new Dublin_Core($cmodel_collection); - $dc->set_element('dc:title', array('Installed Content Model')); - $dc->save(); - $cmodel_collection->add_datastream_from_string('select $object $title from <#ri> - where ($object $title - and ($object - or $object ) - and $object ) - order by $title', 'QUERY', 'Content Model Collection Query', 'text/plain'); - $cmodel_collection->add_relationship('isMemberOfCollection', 'islandora:root'); - $cmodel_collection->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); - $cmodel_collection->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_views/simple_list_view.xml', 'COLLECTION_VIEW', 'Collection View', 'text/xml', 'X'); - $cmodel_collection->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/contentModel.jpg', 'TN', 'Thumbnail', 'image/jpg', 'M'); - drupal_set_message(t("Successfully installed islandora:ContentModelCollection.", array('@base_url' => check_plain($base_url))), 'message'); - } catch (exception $e) { - - } - } - - if (!empty($form_state['values']['demo_collections']['islandora:root'])) { - $new_item = Fedora_Item::ingest_new_item('islandora:root', 'A', 'Islandora Top-level Collection'); - $new_item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); - $cp = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_policies/COLLECTION-COLLECTION POLICY.xml', 'COLLECTION_POLICY', 'Collection Policy', 'text/xml', 'X'); - try { - $tn = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/Gnome-emblem-photos.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); - drupal_set_message(t("Successfully installed islandora:root.", array('@base_url' => check_plain($base_url))), 'message'); - } catch (exception $e) { - - } - } - - if (!empty($form_state['values']['demo_collections']['islandora:demos'])) { - $new_item = fedora_item::ingest_new_item('islandora:demos', 'A', 'Islandora Demo Collection'); - $new_item->add_relationship('isMemberOfCollection', 'islandora:root'); - $new_item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); - $cp = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_policies/COLLECTION-COLLECTION POLICY.xml', 'COLLECTION_POLICY', 'Collection Policy', 'text/xml', 'X'); - -// $cv = $new_item->add_datastream_from_file( drupal_get_path('module', 'fedora_repository') . '/collection_views/COLLECTION_VIEW.xml', 'COLLECTION_VIEW', 'Collection View.xml', 'text/xml', 'X'); - $tn = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/Gnome-emblem-photos.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); - try { - $new_item = Fedora_Item::ingest_new_item('islandora:pdf_collection', 'A', 'PDF Collection'); - $new_item->add_relationship('isMemberOfCollection', 'islandora:demos'); - $new_item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); - $cp = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml', 'COLLECTION_POLICY', 'Collection Policy', 'text/xml', 'X'); - $tn = $new_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_mimetype_pdf.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); - drupal_set_message(t("Successfully installed islandora:demos.", array('@base_url' => check_plain($base_url))), 'message'); - } catch (exception $e) { - - } - } - - if (!empty($form_state['values']['demo_collections']['demo:SmileyStuff'])) { - $smiley_stuff = new Fedora_Item('demo:SmileyStuff'); - $new_item = $smiley_stuff->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_views/SmileyStuff-COLLECTION_VIEW.xml', 'COLLECTION_VIEW', 'Collection View', 'text/xml', 'X'); - $smiley_stuff->add_relationship('isMemberOfCollection', 'info:fedora/islandora:demos'); - $tn = $smiley_stuff->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/smileytn.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); - $cp = $smiley_stuff->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_policies/JPG-COLLECTION POLICY.xml', 'COLLECTION_POLICY', 'Collection Policy.xml', 'application/xml', 'X'); - - $cm = new Fedora_Item('demo:DualResImage'); - try { - $cmstream = $cm->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/STANDARD JPG.xml', 'ISLANDORACM', 'Content Model.xml', 'application/xml', 'X'); - } catch (exception $e) { - - } - $dual_res_image_collection_cmodel = new Fedora_Item('demo:DualResImageCollection'); - try { - $cmstream = $dual_res_image_collection_cmodel->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/COLLECTIONCM.xml', 'ISLANDORACM', 'Islandora Content Model.xml', 'application/xml', 'X'); - drupal_set_message(t("Successfully installed demo:SmileyStuff collection view.", array('@base_url' => check_plain($base_url))), 'message'); - } catch (exception $e) { - - } - } - - if (!empty($form_state['values']['demo_collections']['islandora:largeimages'])) { - $error = ''; - foreach (array('islandora_jp2Sdep-slideCModel.xml', 'islandora_mods2htmlSdef.xml', 'islandora_mods2htmlSdep.xml', - 'islandora_slideCModel.xml', 'islandora_viewerSdep-slideCModel.xml', 'ilives_jp2Sdef.xml', 'ilives_viewerSdef.xml') as $foxml_file) { - try { - $item = Fedora_Item::ingest_from_FOXML_file(drupal_get_path('module', 'fedora_repository') . '/content_models/' . $foxml_file); - } catch (exception $e) { - $error .= " - Problem ingesting $foxml_file"; - } - } - try { - $item = Fedora_Item::ingest_from_FOXML_file(drupal_get_path('module', 'fedora_repository') . '/content_models/islandora_largeimages.xml'); - $tn = $item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/Gnome-emblem-photos.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); - drupal_set_message(t("Successfully installed islandora:largeimages.", array('@base_url' => check_plain($base_url))), 'message'); - } catch (exception $e) { - $error .= " - Problem ingesting islandora:largeimages collection"; - } - } - - if (!empty($error)) { - drupal_set_message(t('Some problems occurred: @error', array('@error' => $error))); - } - } -} - /** * fedora repository required fedora objects * @@ -2305,8 +2053,6 @@ function fedora_repository_display_schema($file) { * and finished callback */ function fedora_repository_batch_reingest_object($object, $module_name, &$context) { - - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -2539,3 +2285,91 @@ function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedor function fedora_repository_string_to_domnode($string) { return DOMDocument::loadXML($string); } + +/** + * Permission check function at old name. + * + * Defers the call to fedora_repository_check_perm() and displays a message + * to encourage any people using the old function to change their code. + * + * @deprecated + */ +function fedora_repository_access() { + drupal_set_message(t('Contact your code maintainer to change all occurences of fedora_repository_access() to fedora_repository_check_perm().')); + return call_user_func_array('fedora_repository_check_perm', func_get_args()); +} + +/** + * Hookable access check for module-specific permissions. + * + * @global $user + * @see hook_fedora_repository_check_perm() + * @param string $op + * The operation to be performed. + * @param string|null $pid + * A PID to check, or NULL to use the root collection PID. + * @param object|null $as_user + * An account to check the permission on, or NULL to use the current user. + * @param boolean $reset_cache + * A boolean to reset the static cache, if required in long-running processes. + * + * @return boolean + * A boolean indicating if the operation should be permitted (TRUE) or denied + * (FALSE). + */ +function fedora_repository_check_perm($op, $pid = NULL, $as_user = NULL, $reset_cache = FALSE) { + static $cache = array(); + + if ($reset_cache) { + $cache = array(); + } + + if ($pid === NULL) { + $pid = variable_get('fedora_repository_pid', 'islandora:root'); + } + if ($as_user === NULL) { + global $user; + $as_user = $user; + } + + // Populate the cache on a miss. + if (!isset($cache[$op][$pid][$as_user->uid])) { + $results = module_invoke_all('fedora_repository_check_perm', $op, $pid, $as_user); + + // Nothing returned FALSE, and something returned TRUE. + $cache[$op][$pid][$as_user->uid] = (!in_array(FALSE, $results, TRUE) && in_array(TRUE, $results, TRUE)); + } + + return $cache[$op][$pid][$as_user->uid]; +} + +/** + * Implements hook_fedora_repository_check_perm(). + * + * Checks the PID namespace if restrictions are enabled, in addition to + * permitting according to Drupal permissions. + */ +function fedora_repository_fedora_repository_check_perm($op, $pid, $user) { + $to_return = TRUE; + if (variable_get('fedora_namespace_restriction_enforced', TRUE)) { + //Get the namespace (with colon) + $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); + $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); + + $to_return = in_array($pid_namespace, $allowed_namespaces); + } + + if ($to_return && user_access($op, $user)) { + // Straight Drupal permissions, let's allow it. + return TRUE; + } + elseif ($to_return === FALSE) { + // PID namespace is outside of those allowed. Forbid! + return FALSE; + } + else { + // Neither allowing of forbidding, to allow other modules to override. + return NULL; + } +} + diff --git a/formClass.inc b/formClass.inc index 30f7d220..6da8529b 100644 --- a/formClass.inc +++ b/formClass.inc @@ -41,6 +41,7 @@ class formClass { 'title' => t('Solution Packs'), 'description' => t('Install content models and collections required by installed solution packs.'), 'page callback' => 'fedora_repository_solution_packs_page', + 'access callback' => 'fedora_repository_check_perm', 'access arguments' => array('add fedora datastreams'), 'file' => 'fedora_repository.solutionpacks.inc', 'type' => MENU_LOCAL_TASK, @@ -50,6 +51,7 @@ class formClass { 'page callback' => 'fedora_repository_display_schema', 'page arguments' => array('islandoracm.xsd'), 'type' => MENU_CALLBACK, + 'access callback' => 'fedora_repository_check_perm', 'access arguments' => array('view fedora collection'), ); @@ -58,24 +60,28 @@ class formClass { 'page callback' => 'fedora_repository_display_schema', 'page arguments' => array('collection_policy.xsd'), 'type' => MENU_CALLBACK, + 'access callback' => 'fedora_repository_check_perm', 'access arguments' => array('view fedora collection'), ); $items['fedora'] = array( 'page callback' => 'repository_page', 'type' => MENU_CALLBACK, - 'access arguments' => array('view fedora collection'), + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('view fedora collection', 1), ); $items['fedora/repository'] = array( 'title' => 'Digital Repository', 'page callback' => 'repository_page', 'type' => MENU_NORMAL_ITEM, - 'access arguments' => array('view fedora collection'), + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('view fedora collection', 2), ); $items['fedora/repository/service'] = array( 'page callback' => 'repository_service', 'type' => MENU_CALLBACK, + 'access callback' => 'fedora_repository_check_perm', 'access arguments' => array('view fedora collection'), ); @@ -83,6 +89,7 @@ class formClass { 'title' => t('Download object'), 'page callback' => 'fedora_object_as_attachment', 'type' => MENU_CALLBACK, + 'access callback' => 'fedora_repository_check_perm', 'access arguments' => array('view fedora collection') ); @@ -90,35 +97,40 @@ class formClass { 'title' => t('Edit metadata'), 'page callback' => 'fedora_repository_edit_qdc_page', 'type' => MENU_CALLBACK, - 'access arguments' => array('edit fedora meta data') + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('edit fedora meta data', 3) ); $items['fedora/repository/purgeStream'] = array( 'title' => t('Purge data stream'), 'page callback' => 'fedora_repository_purge_stream', 'type' => MENU_CALLBACK, - 'access arguments' => array('purge objects and datastreams') + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('purge objects and datastreams', 3) ); $items['fedora/repository/replaceStream'] = array( 'title' => t('Replace Stream'), 'page callback' => 'fedora_repository_replace_stream', 'type' => MENU_CALLBACK, - 'access arguments' => array('add fedora datastreams'), + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('add fedora datastreams', 3), ); $items['fedora/repository/purgeObject'] = array( 'title' => t('Purge object'), 'page callback' => 'fedora_repository_purge_object', 'type' => MENU_CALLBACK, - 'access arguments' => array('purge objects and datastreams') + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('purge objects and datastreams', 3) ); $items['fedora/repository/addStream'] = array( 'title' => t('Add stream'), 'page callback' => 'add_stream', 'type' => MENU_CALLBACK, - 'access arguments' => array('add fedora datastreams') + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('add fedora datastreams', 3) ); //new for mnpl****************************************** @@ -133,7 +145,8 @@ class formClass { 'title' => t('Ingest object'), 'page callback' => 'fedora_repository_ingest_object', 'type' => MENU_CALLBACK, - 'access arguments' => array('add fedora datastreams') + 'access callback' => 'fedora_repository_check_perm', + 'access arguments' => array('add fedora datastreams', 2) ); $items['fedora/repository/list_terms'] = array( @@ -500,7 +513,7 @@ class formClass { * @return type */ function canShowIngestForm($collection_pid) { - if (!user_access('ingest new fedora objects')) { + if (!fedora_repository_check_perm('ingest new fedora objects', $collection_pid)) { $ingest_override_array = module_invoke_all('fedora_repository_can_ingest', $collection_pid); $overrides = array_filter($ingest_override_array); if (empty($overrides)) { diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 593a42a2..709b9203 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -93,7 +93,7 @@ class FedoraObjectDetailedContent { $tabset['fedora_object_details']['tabset']['view']['dc'] = $dc_array; } - if (fedora_repository_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { + if (fedora_repository_check_perm(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { $tabset['fedora_object_details']['tabset']['view'] += array( 'list' => array( '#type' => 'fieldset', @@ -118,7 +118,7 @@ class FedoraObjectDetailedContent { ); } - if (fedora_repository_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $this->pid, $user)) { + if (fedora_repository_check_perm(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $this->pid, $user)) { $tabset['fedora_object_details']['tabset']['view'] += array( 'purge' => array( '#type' => 'markup', @@ -128,7 +128,7 @@ class FedoraObjectDetailedContent { ); } - if (fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { + if (fedora_repository_check_perm(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC'); $tabset['fedora_object_details']['tabset']['edit'] = array( '#type' => 'tabpage', diff --git a/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index e75ddec1..ed9ba511 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -121,7 +121,7 @@ EOJS '#content' => $dl_link . $dc_html, ); - if (fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { + if (fedora_repository_check_perm(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC'); $tabset['first_tab']['tabs']['edit'] = array( '#type' => 'tabpage', diff --git a/plugins/herbarium.inc b/plugins/herbarium.inc index 0ad13fd6..e8ef429f 100644 --- a/plugins/herbarium.inc +++ b/plugins/herbarium.inc @@ -186,7 +186,7 @@ class Herbarium { ); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $obj = new ObjectHelper(); - if (fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { + if (fedora_repository_check_perm(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) { $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DARWIN_CORE'); $tabset['third_tab']['tabset']['edit'] = array( '#type' => 'tabpage', diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index 9b7c4658..0cfbff50 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -76,7 +76,8 @@ function fedora_repository_image_tagging_form($form_state, $pid) { 'title' => $tag_title_text ))), ); - if (user_access('modify fedora datastreams') || user_access('add fedora tags')) { + if (fedora_repository_check_perm('modify fedora datastreams', $pid) || + fedora_repository_check_perm('edit tags datastream', $pid)) { // Delete button for each existing tag. $form_tag['delete'] = array( '#type' => 'imagebutton', @@ -86,7 +87,8 @@ function fedora_repository_image_tagging_form($form_state, $pid) { ); } } - if (user_access('modify fedora datastreams') || user_access('add fedora tags')) { + if (fedora_repository_check_perm('modify fedora datastreams', $pid) || + fedora_repository_check_perm('edit tags datastream', $pid)) { $form['tags-wrapper']['addtag'] = array( '#type' => 'textfield', '#title' => t('New Tag'), From 3fcda63151d70e2a4d5e1f1575adb3faf505cf14 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 17 Oct 2012 18:37:06 -0300 Subject: [PATCH 07/13] Code cleanup - squash code pertaining to "baskets" in core This should have been largely replaced by the MyPID module. --- ObjectHelper.inc | 1 + fedora_repository.module | 321 --------------------------------------- formClass.inc | 27 ---- 3 files changed, 1 insertion(+), 348 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 698e5d42..d96f694a 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -810,6 +810,7 @@ class ObjectHelper { * Get a tree of related pids - for the basket functionality * * FIXME: This doesn't actually get a tree... + * XXX: Is this still required, without basket being in? * * @param type $pid * @return type diff --git a/fedora_repository.module b/fedora_repository.module index 1beb9b06..7fb11f2d 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1953,327 +1953,6 @@ function theme_fedora_repository_time($element) { return theme('form_element', $element, $output); } -/* Export (basket) functionality */ - -/** - * fedora repository remove item from basket - * @param type $pid - */ -function fedora_repository_remove_item_from_basket($pid) { - - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $pids = empty($_SESSION['basket']['processed']) ? array() : $_SESSION['basket']['processed']; - - $objectHelper = new ObjectHelper(); -// getting child PIDs if any - $cpids = $objectHelper->get_child_pids(array($pid)); - - if (array_key_exists($pid, $pids)) { -// remove item from basket - unset($_SESSION['basket']['processed'][$pid]); - } - if (!empty($cpids)) { // there are children - foreach ($cpids as $child_pid => $value) { -// remove child item from basket recursively - fedora_repository_remove_item_from_basket($child_pid); - } - } -} - -/** - * fedora repository basket - * @return type - */ -function fedora_repository_basket() { - $pids = _fedora_repository_get_basket_pids(); - $output = drupal_get_form('fedora_repository_basket_form', $pids); - - return $output; -} - -function fedora_repository_basket_form($form_state, $pids) { - $form = array(); - - if (!empty($pids)) { - $form['pid'] = array(); - $form['title'] = array(); - $form['desc'] = array(); - } - else { - return; - } - - ksort($pids); - foreach ($pids as $pid => $arr) { - $cbs[$pid] = ''; - - $form['pid'][$pid] = array('#value' => l($pid, "fedora/repository/$pid")); - $form['title'][$pid] = array('#value' => $arr['title']); - $form['desc'][$pid] = array('#value' => $arr['desc']); - } - - $form['remove'] = array( - '#type' => 'checkboxes', - '#options' => $cbs, - ); - - $form['remove_submit'] = array( - '#type' => 'submit', - '#value' => t('Remove selected'), - ); - - $form['remove_all'] = array( - '#type' => 'submit', - '#value' => t('Empty basket'), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Export selected'), - ); - - $form['submit_all'] = array( - '#type' => 'submit', - '#value' => t('Export all'), - ); - - return $form; -} - -/** - * theme fedora repository basket form - * @param type $form - * @return string - */ -function theme_fedora_repository_basket_form($form) { - $header = array( - theme('table_select_header_cell'), - t('PID'), - t('Title'), - t('Description'), - ); - - if (isset($form['pid']) && is_array($form['pid'])) { - foreach (element_children($form['pid']) as $key) { - $rows[] = array( - drupal_render($form['remove'][$key]), - drupal_render($form['pid'][$key]), - drupal_render($form['title'][$key]), - drupal_render($form['desc'][$key]), - ); - } - } - else { - $rows[] = array(array('data' => t('Your basket is empty.'), 'colspan' => '4')); - } - - $output = theme('table', $header, $rows); - - $frm = drupal_render($form); - $output = $frm . $output . $frm; - - return $output; -} - -/** - * fedora repository basket form validate - * @param type $form - * @param type $form_state - */ -function fedora_repository_basket_form_validate($form, &$form_state) { - -} - -/** - * fedora repository basket form submit - * @global type $user - * @param type $form - * @param type $form_state - * @return type - */ -function fedora_repository_basket_form_submit($form, &$form_state) { - if ($form_state['values']['op'] == $form_state['values']['remove_submit']) { - $pids = $form_state['clicked_button']['#post']['remove']; - - if (isset($pids)) { - foreach ($pids as $pid) { - fedora_repository_remove_from_basket($pid); - } - drupal_set_message(t("Selected objects removed")); - return; - } - } - - if ($form_state['values']['op'] == $form_state['values']['remove_all']) { - _fedora_repository_empty_basket(); - drupal_set_message(t("Basket emptied")); - return; - } - - if ($form_state['values']['op'] == $form_state['values']['submit_all']) { - $msg = t("All objects exported to staging area"); - $pids = _fedora_repository_get_basket_pids(); - } - elseif ($form_state['values']['op'] == $form_state['values']['submit']) { - $msg = t("Selected objects exported to staging area"); - $pids = array_filter($form_state['values']['remove']); - } - - if (!empty($pids)) { - global $user; - $log = array(); - $success = TRUE; - $export_dir = variable_get('export_area', file_directory_path() . '/fedora_export_area') . '/' . $user->name . '/' . date("Ymd-His"); - $foxml_dir = $export_dir . '/foxml'; - - if (!file_exists($foxml_dir) && !@mkdir($foxml_dir, 0775, TRUE)) { - drupal_set_message(t("Failed to create foxml dir @dir. Check that export dir exsits and has correct permissions", array('@dir' => $foxml_dir)), 'error'); - return FALSE; - } - - module_load_include('inc', 'fedora_repository', 'api/fedora_export'); - foreach ($pids as $pid => $arr) { - - $objects_dir = $export_dir . '/objects/' . $pid; - if (!file_exists($objects_dir) && !@mkdir($objects_dir, 0775, TRUE)) { - drupal_set_message(t("Failed to create objects dir @dir. Check that export dir exsits and has correct permissions", array('@dir' => $objects_dir)), 'error'); - return FALSE; - } - - if (!export_to_export_area($pid, $foxml_dir, $objects_dir, $log)) { - $success = FALSE; - } - } - $msg = $success ? $msg : t("Failed to export objects to staging area"); - $msg .= ":
    " . implode("
    ", $log); - - drupal_set_message($msg, $success ? 'info' : 'error'); -//_fedora_repository_empty_basket(); - } - else { - drupal_set_message(t("No objects selected or basket empty"), 'error'); - } - - return; -} - -/** - * Get all pids saved to the basket. - * - * @return type - */ -function _fedora_repository_get_basket_pids() { - -// Set empty defaults if basket elements are missing - $_SESSION['basket'] = isset($_SESSION['basket']) ? $_SESSION['basket'] : array('processed' => array(), 'unprocessed' => array()); - $_SESSION['basket']['processed'] = isset($_SESSION['basket']['processed']) ? $_SESSION['basket']['processed'] : array(); - $_SESSION['basket']['unprocessed'] = isset($_SESSION['basket']['unprocessed']) ? $_SESSION['basket']['unprocessed'] : array(); - - $pids = empty($_SESSION['basket']['processed']) ? array() : $_SESSION['basket']['processed']; - - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $ob = new ObjectHelper(); - foreach ($_SESSION['basket']['unprocessed'] as $pid) { -// Check if the pid already exists in the tree - if (array_key_exists($pid, $pids)) { - continue; - } - - $pids += $ob->get_all_related_pids($pid); -// $pids += array($pid); - } - - $_SESSION['basket']['processed'] = $pids; - $_SESSION['basket']['unprocessed'] = array(); - - return $pids; -} - -/** - * fedora repository empty basket - */ -function _fedora_repository_empty_basket() { - unset($_SESSION['basket']); -} - -/** - * fedora repository add to basket - * @param type $pid - * @param type $warn - * @param type $searchResultsFlag - */ -function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag = FALSE) { - if ($warn && _is_added_to_basket($pid)) { - drupal_set_message(t("Object already in basket")); - } - - if (!isset($_SESSION['basket'])) { - $_SESSION['basket'] = array(); - $_SESSION['basket']['unprocessed'] = array($pid => $pid); - } - else { - $_SESSION['basket']['unprocessed'][$pid] = $pid; - } - - if (!$searchResultsFlag) { - drupal_goto('fedora/basket'); - } -} - -/** - * fedora repository remove from basket - * @param type $pid - * @return type - */ -function fedora_repository_remove_from_basket($pid) { - if (isset($_SESSION['basket']['unprocessed'][$pid])) { - unset($_SESSION['basket']['unprocessed'][$pid]); - } - - if (isset($_SESSION['basket']['processed'][$pid])) { - unset($_SESSION['basket']['processed'][$pid]); - } - return; -} - -/** - * theme add to basket link - * @param type $pid - * @param type $type - * @return type - */ -function theme_add_to_basket_link($pid, $type = 'object') { - $object = t($type); - $path = drupal_urlencode($pid); - - $save = "export_big.png"; - $saved = "exported_big.png"; -// $path = drupal_get_path('module', 'fedora_repository').'/images/'.$save ; - /* - var_dump($path); - var_dump(theme('image',drupal_get_path('module', 'fedora_repository').'/images/'.$save)); - die(); - */ - if (!_is_added_to_basket($pid)) { - return l( - theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE) - ); - } - - return theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object))); -} - -/** - * is added to basket - * @param type $pid - * @param type $account - * @return type - */ -function _is_added_to_basket($pid, $account = NULL) { - return isset($_SESSION['basket']['unprocessed'][$pid]) || isset($_SESSION['basket']['processed'][$pid]); -// return db_result(db_query("SELECT uid FROM {repository_basket} WHERE uid = %d AND pid = '%s'", $account->uid, $pid)); -} - /** * fedora repository display schema * diff --git a/formClass.inc b/formClass.inc index 30f7d220..acd8d3e1 100644 --- a/formClass.inc +++ b/formClass.inc @@ -143,33 +143,6 @@ class formClass { 'access arguments' => array('view fedora collection') ); - /* Export functionality */ - $items['fedora/basket'] = array( - 'title' => t('Fedora Basket'), - 'description' => t('View and download objects added to your basket'), - 'page callback' => 'fedora_repository_basket', - 'access arguments' => array('view fedora collection'), - 'type' => MENU_CALLBACK, - ); - - $items['fedora/repository/addToBasket'] = array( - 'page callback' => 'fedora_repository_add_to_basket', - 'type' => MENU_CALLBACK, - 'access arguments' => array('view fedora collection'), - ); - - $items['fedora/repository/removeFromBasket'] = array( - 'page callback' => 'fedora_repository_remove_from_basket', - 'type' => MENU_CALLBACK, - 'access arguments' => array('view fedora collection'), - ); - - $items['fedora/repository/add_search_results_to_basket'] = array( - 'page callback' => 'fedora_repository_add_search_results_to_basket', - 'type' => MENU_CALLBACK, - 'access arguments' => array('view fedora collection'), - ); - $items['admin/settings/fedora_repository/object_details_xslt'] = array( 'title' => "", 'type' => MENU_CALLBACK, From 1c9da08e501434e15a98c54aa3ad7535aea8be15 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 18:58:47 -0300 Subject: [PATCH 08/13] Modify title coming from DC XSLT: add 'DC' part and lower-case the D in metadata --- object_details_xslts/convertQDC.xsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/object_details_xslts/convertQDC.xsl b/object_details_xslts/convertQDC.xsl index 5d881e35..275d4c3f 100644 --- a/object_details_xslts/convertQDC.xsl +++ b/object_details_xslts/convertQDC.xsl @@ -9,7 +9,7 @@
    - + @@ -30,4 +30,4 @@ - \ No newline at end of file + From 5ce9f4fa6d293a3478be159c7c3204bce693abe3 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 19:05:24 -0300 Subject: [PATCH 09/13] Add title to the table coming from MODS XSLT for Object Details --- object_details_xslts/mods2html.xsl | 1 + 1 file changed, 1 insertion(+) diff --git a/object_details_xslts/mods2html.xsl b/object_details_xslts/mods2html.xsl index 3f794523..91ac74e5 100644 --- a/object_details_xslts/mods2html.xsl +++ b/object_details_xslts/mods2html.xsl @@ -51,6 +51,7 @@

    MetaData

    DC Metadata

    +
    From a9472691d46b80b3a30fe0c44edbc4e74dfcfd60 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 19:07:13 -0300 Subject: [PATCH 10/13] Add class to

    for styling --- object_details_xslts/convertQDC.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object_details_xslts/convertQDC.xsl b/object_details_xslts/convertQDC.xsl index 275d4c3f..9d0cf02b 100644 --- a/object_details_xslts/convertQDC.xsl +++ b/object_details_xslts/convertQDC.xsl @@ -9,7 +9,7 @@
    - + From 9a23050b94c27d2e31c17b105052e2785b5a41fa Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 19:12:34 -0300 Subject: [PATCH 11/13] Add a span and class to the dsid portion of title for styling, not sure if it's exactly valid HTML but enables hiding via CSS --- object_details_xslts/convertQDC.xsl | 2 +- object_details_xslts/mods2html.xsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/object_details_xslts/convertQDC.xsl b/object_details_xslts/convertQDC.xsl index 9d0cf02b..036eb20a 100644 --- a/object_details_xslts/convertQDC.xsl +++ b/object_details_xslts/convertQDC.xsl @@ -9,7 +9,7 @@

    DC Metadata

    - + diff --git a/object_details_xslts/mods2html.xsl b/object_details_xslts/mods2html.xsl index 91ac74e5..59e13a50 100644 --- a/object_details_xslts/mods2html.xsl +++ b/object_details_xslts/mods2html.xsl @@ -51,7 +51,7 @@
    - +
    From 0e0aaec229d3f82b54a3f133f3b1b8086d7c36b0 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Wed, 17 Oct 2012 19:18:14 -0300 Subject: [PATCH 12/13] Make titles consistent between table and XSLT views --- ObjectDetails.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 4bd46790..30121080 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -139,7 +139,8 @@ function fedora_repository_object_details_table($item) { $xmlstr = $item->get_datastream_dissemination($dsid); if (empty($xmlstr) && variable_get('islandora_object_details_table_default_dc', FALSE) && $dsid != 'DC' && $dsid != 'QDC') { - $xmlstr = $item->get_datastream_dissemination('DC'); + $dsid = 'DC'; + $xmlstr = $item->get_datastream_dissemination($dsid); } if (empty($xmlstr)) { return t('Error - could not find datastream @dsid on object @pid
    Please contact the site administrator.', @@ -150,7 +151,7 @@ function fedora_repository_object_details_table($item) { $headers = array( array( - 'data' => t('@dsid Metadata', array('@dsid' => $dsid)), + 'data' => t('Metadata (@dsid)', array('@dsid' => $dsid)), 'colspan' => 2, ), ); From 0947f3b790423b88cceb02c0465a3f0dc0c5cf50 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 18 Oct 2012 12:34:34 -0300 Subject: [PATCH 13/13] ISLANDORA-766: Allow arrays relationship objects --- api/fedora_item.inc | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 16cc762a..eb4c3e66 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -281,8 +281,8 @@ class Fedora_Item { * * @param string $relationship * The predicate/relationship tag to add - * @param string $object - * The object to be related to. + * @param string|array $object + * The object(s) to be related to. * @param string $namespaceURI * The predicate namespace. * @param int $literal_value @@ -318,10 +318,6 @@ RDF; $relsext = $this->get_datastream_dissemination('RELS-EXT'); - if ($literal_value == RELS_TYPE_URI && strpos($object, $f_prefix) !== 0) { - $object = $f_prefix . $object; - } - $relsextxml->loadXML($relsext); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); if ($description->length == 0) { @@ -333,18 +329,26 @@ RDF; } $description = $description->item(0); - // Create the new relationship node. - $newrel = $relsextxml->createElementNS($namespaceURI, $relationship); + // Casting a string to an array gives an array containing the string, and + // casting an array to an array does nothing. + foreach ((array)$object as $obj) { + if ($literal_value == RELS_TYPE_URI && strpos($obj, $f_prefix) !== 0) { + $obj = $f_prefix . $obj; + } + + // Create the new relationship node. + $newrel = $relsextxml->createElementNS($namespaceURI, $relationship); - $this->buildRelsStatement($newrel, $object, $literal_value); + $this->buildRelsStatement($newrel, $obj, $literal_value); - $description->appendChild($newrel); + $description->appendChild($newrel); + } return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); } /** - * Extension of add_relationship, which acts on RELS-INT. + * Extension of add_relationship(), which acts on RELS-INT. * * @param $dsid * A string containing either the base dsid (EXAMPLE) @@ -367,9 +371,6 @@ RDF; $rels_text = $this->get_datastream_dissemination('RELS-INT'); - if ($literal_value == RELS_TYPE_URI && strpos($object, $f_prefix) !== 0) { - $object = $f_prefix . $object; - } if (strpos($dsid, $f_prefix) !== 0) { $dsid = $f_prefix . $this->pid . '/' . $dsid; } @@ -391,12 +392,18 @@ RDF; $relsxml->documentElement->appendChild($description); } - // Create the new relationship node. - $newrel = $relsxml->createElementNS($namespaceURI, $relationship); + foreach ((array)$object as $obj) { + if ($literal_value == RELS_TYPE_URI && strpos($obj, $f_prefix) !== 0) { + $obj = $f_prefix . $object; + } - $this->buildRelsStatement($newrel, $object, $literal_value); + // Create the new relationship node. + $newrel = $relsxml->createElementNS($namespaceURI, $relationship); - $description->appendChild($newrel); + $this->buildRelsStatement($newrel, $obj, $literal_value); + + $description->appendChild($newrel); + } return $this->modify_datastream($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'application/rdf+xml'); }