Browse Source

Resolving merge conflicts

pull/192/head
Daniel Lamb 12 years ago
parent
commit
a44e2ff789
  1. 69
      CollectionClass.inc
  2. 31
      ObjectDetails.inc
  3. 49
      ObjectHelper.inc
  4. 62
      PagerSetup.inc
  5. 612
      SearchClass.inc
  6. 3
      api/fedora_collection.inc
  7. 77
      api/fedora_item.inc
  8. 28
      fedora_repository.api.php
  9. 1161
      fedora_repository.module
  10. 73
      formClass.inc
  11. 2
      object_details_xslts/convertQDC.xsl
  12. 1
      object_details_xslts/mods2html.xsl
  13. 6
      plugins/FedoraObjectDetailedContent.inc
  14. 2
      plugins/ShowStreamsInFieldSets.inc
  15. 2
      plugins/herbarium.inc
  16. 6
      plugins/tagging_form.inc

69
CollectionClass.inc

@ -102,7 +102,7 @@ class CollectionClass {
function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { 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', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); 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'); drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
return ' '; return ' ';
} }
@ -321,7 +321,7 @@ class CollectionClass {
* @return type * @return type
*/ */
function getAndDoRules($file, $mimetype, $pid, $dsid) { 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.')); drupal_set_message(t('You do not have permission to ingest objects.'));
return FALSE; return FALSE;
} }
@ -586,7 +586,7 @@ class CollectionClass {
function getIngestInterface() { function getIngestInterface() {
module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$collectionPolicyExists = $this->collectionObject->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); $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)) { if (!empty($collectionPolicyExists)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
@ -604,66 +604,6 @@ class CollectionClass {
return $ingestObject; 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... * Assemble results in a somewhat more logical manner...
* *
@ -683,10 +623,11 @@ class CollectionClass {
* list of items, and another pager. * list of items, and another pager.
*/ */
public static function assembleCollectionView($sparql_results) { public static function assembleCollectionView($sparql_results) {
module_load_include('inc', 'fedora_repository', 'PagerSetup');
$per_page = 20; //XXX: Make this configurable. $per_page = 20; //XXX: Make this configurable.
$pager_name = 0; $pager_name = 0;
$total = count($sparql_results); $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; $max_title_length = 60;
$results = array(); $results = array();

31
ObjectDetails.inc

@ -72,6 +72,11 @@ function fedora_repository_object_details_XSLT($item) {
} }
$xmlstr = $item->get_datastream_dissemination($dsid); $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)) { if (empty($xmlstr)) {
return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.', return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.',
array('@dsid' => $dsid, '@pid' => $item->pid)); array('@dsid' => $dsid, '@pid' => $item->pid));
@ -88,7 +93,13 @@ function fedora_repository_object_details_XSLT($item) {
$proc->setParameter('', 'path', $path); $proc->setParameter('', 'path', $path);
$input = NULL; $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 // set an error message in case xslt parsing fails
$output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file)); $output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file));
if (is_readable($xsl_file)) { if (is_readable($xsl_file)) {
@ -127,6 +138,10 @@ function fedora_repository_object_details_table($item) {
} }
$xmlstr = $item->get_datastream_dissemination($dsid); $xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr) && variable_get('islandora_object_details_table_default_dc', FALSE) && $dsid != 'DC' && $dsid != 'QDC') {
$dsid = 'DC';
$xmlstr = $item->get_datastream_dissemination($dsid);
}
if (empty($xmlstr)) { if (empty($xmlstr)) {
return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.', return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.',
array('@dsid' => $dsid, '@pid' => $item->pid)); array('@dsid' => $dsid, '@pid' => $item->pid));
@ -136,7 +151,7 @@ function fedora_repository_object_details_table($item) {
$headers = array( $headers = array(
array( array(
'data' => t('Metadata'), 'data' => t('Metadata (@dsid)', array('@dsid' => $dsid)),
'colspan' => 2, 'colspan' => 2,
), ),
); );
@ -191,6 +206,11 @@ function fedora_repository_object_details_XSLT_config() {
'#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'), '#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'),
'#required' => TRUE, '#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( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t("Submit"), '#value' => t("Submit"),
@ -210,6 +230,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_display_table', 'xslt');
variable_set('islandora_object_details_xslt_sheet', $form_state['values']['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_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'); drupal_set_message('Object Details view has been set to XSLT and your configuration has been saved');
} }
@ -253,6 +274,11 @@ function fedora_repository_object_details_table_config() {
'#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'), '#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'),
'#required' => TRUE, '#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( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t("Submit"), '#value' => t("Submit"),
@ -272,5 +298,6 @@ function fedora_repository_object_details_table_config() {
function fedora_repository_object_details_table_config_submit($form, &$form_state) { function fedora_repository_object_details_table_config_submit($form, &$form_state) {
variable_set('islandora_object_details_display_table', 'table'); 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_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'); drupal_set_message('Object Details view has been set to Table and your configuration has been saved');
} }

49
ObjectHelper.inc

@ -93,7 +93,7 @@ class ObjectHelper {
return ' '; 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_set_message(t("You do not have access Fedora objects within the attempted namespace."), 'error');
drupal_access_denied(); drupal_access_denied();
return ' '; return ' ';
@ -298,7 +298,7 @@ class ObjectHelper {
drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error'); drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error');
return ''; 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'); drupal_set_message(t('You do not have the appropriate permissions'), 'error');
return; return;
} }
@ -333,7 +333,7 @@ class ObjectHelper {
drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error'); drupal_set_message(t('You must specify an object pid and datastream ID.'), 'error');
return ''; 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'); drupal_set_message(t('You do not have the appropriate permissions'), 'error');
return; return;
} }
@ -368,7 +368,7 @@ class ObjectHelper {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$purge_image = '&nbsp;'; $purge_image = '&nbsp;';
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { if (fedora_repository_check_perm(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $pid)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
@ -388,7 +388,7 @@ class ObjectHelper {
// Add an icon to replace a datastream // 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. // @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled.
$replace_image = '&nbsp;'; $replace_image = '&nbsp;';
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { if (fedora_repository_check_perm(ObjectHelper :: $ADD_FEDORA_STREAMS, $pid)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
@ -533,7 +533,7 @@ class ObjectHelper {
$dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC'; $dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC';
$path = drupal_get_path('module', 'fedora_repository'); $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; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
@ -573,7 +573,7 @@ class ObjectHelper {
$dataStreamBody = ''; $dataStreamBody = '';
$fedoraItem = new Fedora_Item($object_pid); $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'; $availableDataStreamsText = 'Detailed List of Content';
$mainStreamLabel = NULL; $mainStreamLabel = NULL;
@ -606,7 +606,7 @@ class ObjectHelper {
$dataStreamBody = theme('table', $headers, $DSs); $dataStreamBody = theme('table', $headers, $DSs);
//if they have access let them add a datastream //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') && fedora_fesl_check_roles($object_pid, 'write')) || //And allowed throw FESL
!module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form. !module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form.
$dataStreamBody .= drupal_get_form('add_stream_form', $object_pid); $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
@ -673,36 +673,6 @@ class ObjectHelper {
return $cmodels; 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. * Get the query to find parent objects.
* *
@ -795,7 +765,7 @@ class ObjectHelper {
* @return boolean * @return boolean
*/ */
function get_and_do_datastream_rules($pid, $dsid, $file = '') { 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.')); drupal_set_message(t('You do not have permission to add datastreams.'));
return FALSE; return FALSE;
} }
@ -810,6 +780,7 @@ class ObjectHelper {
* Get a tree of related pids - for the basket functionality * Get a tree of related pids - for the basket functionality
* *
* FIXME: This doesn't actually get a tree... * FIXME: This doesn't actually get a tree...
* XXX: Is this still required, without basket being in?
* *
* @param type $pid * @param type $pid
* @return type * @return type

62
PagerSetup.inc

@ -0,0 +1,62 @@
<?php
/**
* Setups the globals for the Drupal pager.
*
* 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.
*/
function fedora_repository_setup_pager($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;
}

612
SearchClass.inc

@ -1,612 +0,0 @@
<?php
/**
* @file
* SearchClass Class
*/
/**
* SearchClass ??
*/
class SearchClass {
public static $SEARCH_CLASS_ADVANCED_SEARCH_NUMBER_FIELDS = 5;
/**
* solr_search ??
* @param type $query
* @param type $startPage
* @param type $fq
* @param type $dismax
* @return type
*/
function solr_search($query, $startPage=1, $fq = NULL, $dismax = NULL) {
$solrFile = trim(variable_get('islandora_solr_search_block_handler_file', 'plugins/SolrResults.inc'));
// Don't let us bust out of fedora_repository modules directory when looking for a handler
if (strpos($solrField, '../')) {
drupal_set_message(t('You have illegal characters in your solr handler function in the Islandora solr block config.'), 'error');
}
$solrClass = trim(variable_get('islandora_solr_search_block_handler_class', 'SolrResults'));
$solrFunction = trim(variable_get('islandora_solr_search_block_handler_function', 'SearchAndDisplay'));
require_once(drupal_get_path('module', 'fedora_repository') . '/' . $solrFile);
try {
$implementation = new $solrClass();
} catch (Exception $e) {
watchdog(t("fedora_repository"), "Error getting solr search results class: !message", array('!message' => $e->getMessage()), NULL, WATCHDOG_ERROR);
return 'Error getting solr search results class. Check watchdog for more info.';
}
return $implementation->$solrFunction($query, $startPage, $fq, $dismax);
}
/**
* build solr search form ??
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return type
*/
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {
$types = $this->get_search_terms_array(NULL, 'solrSearchTerms.xml');
$queryArray = NULL;
if (isset($query)) {
$queryArray = explode('AND', $query);
}
$andOrArray = array(
'AND' => 'and',
//'OR' => 'or' //removed or for now as it would be a pain to parse
);
$form = array();
if (!isset($repeat)) {
$repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
}
$var0 = explode(':', $queryArray[0]);
$var1 = explode(':', $queryArray[1]);
$form['search_type']['type1'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($var0[0])
);
$form['fedora_terms1'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#required' => TRUE,
'#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''),
);
$form['andor1'] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']['type2'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''),
);
$form['fedora_terms2'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''),
);
if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
$field_and_term = explode(':', $queryArray[$t]);
$form["andor$t"] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']["type$i"] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($field_and_term[0])
);
$form["fedora_terms$i"] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''),
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
);
return $form;
}
/**
* build simple solr form ??
* @return string
*/
function build_simple_solr_form() {
//$form = array();
$form["search_query"] = array(
'#size' => '30',
'#type' => 'textfield',
'#title' => t(''),
// '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
);
return $form;
}
/**
* theme solr search form ??
* @param type $form
* @return type
*/
function theme_solr_search_form($form) {
if (!isset($repeat)) {
$repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
}
$output = drupal_render($form['search_type']['type1']);
$output .= drupal_render($form['fedora_terms1']);
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']);
$output .= drupal_render($form['fedora_terms2']);
if ($repeat > 2 && $repeat < 9) {
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]);
$output .= drupal_render($form["fedora_terms$i"]);
}
}
$output .= drupal_render($form['submit']);
$output .= drupal_render($form);
return $output;
}
/**
* quick search ??
* @param type $type
* @param type $query
* @param type $showForm
* @param type $orderBy
* @param type $userArray
* @return type
*/
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')) {
$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
$keywords = explode(' ', $query);
foreach ($keywords as $keyword) {
$luceneQuery .= $type . ':' . $keyword . '+AND+';
}
$luceneQuery = substr($luceneQuery, 0, strlen($luceneQuery) - 5);
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$keys = htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $luceneQuery;
$searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=1';
//$searchString = htmlentities($searchString);
$searchUrl .= $searchString;
// $objectHelper = new ObjectHelper();
$resultData = do_curl($searchUrl, 1);
if (isset($userArray)) {
$doc = new DOMDocument();
$doc->loadXML($resultData);
$xPath = new DOMXPath($doc);
// Add users to department list. This is a hack as not all users will be in dupal
$nodeList = $xPath->query('//field[@name="refworks.u1"]');
foreach ($nodeList as $node) {
if (!in_array($node->nodeValue, $userArray)) {
$userArray[] = $node->nodeValue;
}
}
}
if ($showForm) {
$output = '<Strong>Quick Search</strong><br /><table class="table-form"><tr>' . drupal_get_form('fedora_repository_quick_search_form') . '</tr></table>';
}
$output .= $this->applyXSLT($resultData, $orderBy);
return $output;
}
}
/**
* gets term from a lucene index and displays them in a list
* @param type $fieldName
* @param type $startTerm
* @param type $displayName
* @return type
*/
function getTerms($fieldName, $startTerm, $displayName = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
if ($startTerm == NULL) {
$startTerm = "";
}
$startTerm = drupal_urlencode($startTerm);
$query = 'operation=browseIndex&startTerm=' . $startTerm . '&fieldName=' . $fieldName . '&termPageSize=20&indexName=' . $indexName . '&restXslt=copyXml&resultPageXslt=copyXml';
// $query=drupal_urlencode($query);
$query = '?' . $query;
$searchString = $searchUrl . $query;
$objectHelper = new ObjectHelper();
$resultData = do_curl($searchString, 1);
$path = drupal_get_path('module', 'fedora_repository');
$output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName);
//$output .= '<br />'.$alpha_out;
return $output;
}
/**
* custom search ??
* @param type $query
* @param type $startPage
* @param type $xslt
* @param type $numberOfHistPerPage
* @return type
*/
function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
if (user_access('view fedora collection')) {
//$numberOfHistPerPage = '50';//hack for IR they do not want next button
$luceneQuery = NULL;
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$copyXMLFile = 'copyXml';
// if($indexName=='ilives' || $indexName=='BasicIndex'){
// $copyXMLFile = 'copyXmliLives';
// }
$query = trim($query);
$query = htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query;
$searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage;
//$searchString = htmlentities($searchString);
$searchUrl .= $searchString;
//$objectHelper = new ObjectHelper();
$resultData = do_curl($searchUrl, 1);
//var_dump($resultData);exit(0);
// $doc = new DOMDocument();
// $doc->loadXML($resultData);
$output .= $this->applyLuceneXSLT($resultData, $startPage, $xslt, $query);
return $output;
}
}
/**
* apply specified xslt ??
* @global type $user
* @param type $resultData
* @param type $pathToXSLT
* @param type $displayName
* @return type
*/
function applySpecifiedXSLT($resultData, $pathToXSLT, $displayName = NULL) {
$proc = NULL;
global $user;
if (!$resultData) {
drupal_set_message(t('No data found!'));
return ' '; //no results
}
try {
$proc = new XsltProcessor();
} catch (Exception $e) {
drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!') . $e->getMessage());
return ' ';
}
//$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'userID', $user->uid);
if (isset($displayName)) {
$proc->setParameter('', 'displayName', $displayName);
}
else {
$proc->setParameter('', 'displayName', "test");
}
$xsl = new DomDocument();
$test = $xsl->load($pathToXSLT);
if (!isset($test)) {
drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!'));
return t('Error loading !pathToXSLT xslt.', array('!pathToXSLT' => $pathToXSLT));
}
$input = new DomDocument();
$didLoadOk = $input->loadXML($resultData);
if (!isset($didLoadOk)) {
drupal_set_message(t('Error loading XML data!'));
return t('Error loading XML data.');
}
else {
$proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
return $newdom->saveXML();
}
}
//default function for lucene results
/**
* apply an xslt to lucene gsearch search results
*
* @param <type> $resultData
* @param <type> $startPage
* @param <type> $xslt_file
* @param <type> $query the query that was executed. May want to pass this on.
*/
function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) {
$path = drupal_get_path('module', 'fedora_repository');
$test = $xslt_file;
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if (!isRestricted && $xslt_file == NULL) {
$xslt_file = '/xsl/unfilteredresults.xsl';
}
$proc = NULL;
if (!$resultData) {
//drupal_set_message(t('No Results!'));
return ' '; //no results
}
try {
$proc = new XsltProcessor();
} catch (Exception $e) {
drupal_set_message(t('Error loading results xslt!') . $e->getMessage());
return ' ';
}
if (isset($query)) {
$proc->setParameter('', 'fullQuery', $query);
}
//inject into xsl stylesheet
global $user;
$proc->setParameter('', 'userID', $user->uid);
$proc->setParameter('', 'searchToken', drupal_get_token('fedora_repository_advanced_search')); //token generated by Drupal, keeps tack of what tab etc we are on
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$proc->setParameter('', 'hitPageStart', $startPage);
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$test = $xsl->load($path . $xslt_file);
if (!isset($test)) {
drupal_set_message(t('Error loading search results xslt!'));
return t('Error loading search results XSLT.');
}
$input = new DomDocument();
$didLoadOk = $input->loadXML($resultData);
if (!isset($didLoadOk)) {
drupal_set_message(t('Error loading search results!'));
return t('Error loading search results.');
}
else {
$proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
return $newdom->saveXML();
}
}
/**
* xslt for islandscholar these xslt functions can probably be pulled into one
* @param type $resultData
* @param type $orderBy
* @return type
*/
function applyXSLT($resultData, $orderBy = 0) {
$path = drupal_get_path('module', 'fedora_repository');
$proc = NULL;
if (!$resultData) {
//drupal_set_message(t('No Results!'));
return ' '; //no results
}
try {
$proc = new XsltProcessor();
} catch (Exception $e) {
drupal_set_message(t('Error loading results xslt!') . " " . $e->getMessage());
return ' ';
}
//inject into xsl stylesheet
//$proc->setParameter('', 'searchToken', drupal_get_token('search_form')); //token generated by Drupal, keeps tack of what tab etc we are on
$proc->setParameter('', 'userID', $user->uid);
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$proc->setParameter('', 'orderBy', $orderBy);
$xsl = new DomDocument();
$test = $xsl->load($path . '/ir/xsl/results.xsl');
if (!isset($test)) {
drupal_set_message(t('Error loading search results xslt!'));
return t('Error loading search results XSLT.');
}
$input = new DomDocument();
$didLoadOk = $input->loadXML($resultData);
if (!isset($didLoadOk)) {
drupal_set_message(t('Error loading search results!'));
return t('Error loading search results.');
}
else {
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
return $newdom->saveXML();
}
}
/**
* theme advanced search form ??
* @param type $form
* @param type $repeat
* @return type
*/
function theme_advanced_search_form($form, $repeat=NULL) {
if (!isset($repeat)) {
$repeat = variable_get('fedora_repository_advanced_block_repeat', t('3'));
}
$output = drupal_render($form['search_type']['type1']);
$output .= drupal_render($form['fedora_terms1']);
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']);
$output .= drupal_render($form['fedora_terms2']);
if ($repeat > 2 && $repeat < 9) {
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]);
$output .= drupal_render($form["fedora_terms$i"]);
}
}
$output .= drupal_render($form['submit']);
$output .= drupal_render($form);
return $output;
}
/**
* build search form, custom blocks should set the number of repeats or it will use the default
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return string
*/
function build_advanced_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {
$types = $this->get_search_terms_array($pathToSearchTerms);
$queryArray = NULL;
if (isset($query)) {
$queryArray = explode('AND', $query);
}
$andOrArray = array(
'AND' => 'and',
//'OR' => 'or' //removed or for now as it would be a pain to parse
);
$form = array();
if (!isset($repeat)) {
$repeat = variable_get('fedora_repository_advanced_block_repeat', t('3'));
}
$var0 = explode(':', $queryArray[0]);
$var1 = explode(':', $queryArray[1]);
$form['search_type']['type1'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($var0[0])
);
$form['fedora_terms1'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#required' => TRUE,
'#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''),
);
$form['andor1'] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']['type2'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''),
);
$form['fedora_terms2'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''),
);
if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
$field_and_term = explode(':', $queryArray[$t]);
$form["andor$t"] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']["type$i"] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($field_and_term[0])
);
$form["fedora_terms$i"] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''),
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
);
return $form;
}
/**
* get search terms array
* @param type $path
* @param string $file
* @return type
*/
function get_search_terms_array($path = NULL, $file = NULL) {
if (!isset($path)) {
$path = drupal_get_path('module', 'fedora_repository');
}
$xmlDoc = new DomDocument();
if (!isset($file)) {
$file = 'searchTerms.xml';
}
$xmlDoc->load($path . '/' . $file);
$nodeList = $xmlDoc->getElementsByTagName('term');
$types = array();
for ($i = 0; $i < $nodeList->length; $i++) {
$field = $nodeList->item($i)->getElementsByTagName('field');
$value = $nodeList->item($i)->getElementsByTagName('value');
$fieldValue = $field->item(0)->nodeValue;
$valueValue = $value->item(0)->nodeValue;
$types["$fieldValue"] = "$valueValue";
}
return $types;
}
}

3
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') { 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'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
global $user; if (!fedora_repository_check_perm(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) {
if (!fedora_repository_access(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_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
return array(); return array();
} }

77
api/fedora_item.inc

@ -79,7 +79,7 @@ class Fedora_Item {
if (!empty($raw_objprofile)) { if (!empty($raw_objprofile)) {
$this->objectProfile = $raw_objprofile->objectProfile; $this->objectProfile = $raw_objprofile->objectProfile;
$this->datastreams = $this->get_datastreams_list_as_array(); $this->datastreams = $this->get_datastreams_list_as_array();
$this->ownerId = & Fedora_Item::getOwnerId($pid); $this->ownerId = Fedora_Item::getOwnerId($pid);
} }
else { else {
$this->objectProfile = ''; $this->objectProfile = '';
@ -281,8 +281,8 @@ class Fedora_Item {
* *
* @param string $relationship * @param string $relationship
* The predicate/relationship tag to add * The predicate/relationship tag to add
* @param string $object * @param string|array $object
* The object to be related to. * The object(s) to be related to.
* @param string $namespaceURI * @param string $namespaceURI
* The predicate namespace. * The predicate namespace.
* @param int $literal_value * @param int $literal_value
@ -318,10 +318,6 @@ RDF;
$relsext = $this->get_datastream_dissemination('RELS-EXT'); $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); $relsextxml->loadXML($relsext);
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
if ($description->length == 0) { if ($description->length == 0) {
@ -333,18 +329,26 @@ RDF;
} }
$description = $description->item(0); $description = $description->item(0);
// Create the new relationship node. // Casting a string to an array gives an array containing the string, and
$newrel = $relsextxml->createElementNS($namespaceURI, $relationship); // 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;
}
$this->buildRelsStatement($newrel, $object, $literal_value); // Create the new relationship node.
$newrel = $relsextxml->createElementNS($namespaceURI, $relationship);
$description->appendChild($newrel); $this->buildRelsStatement($newrel, $obj, $literal_value);
$description->appendChild($newrel);
}
return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); 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 * @param $dsid
* A string containing either the base dsid (EXAMPLE) * A string containing either the base dsid (EXAMPLE)
@ -367,9 +371,6 @@ RDF;
$rels_text = $this->get_datastream_dissemination('RELS-INT'); $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) { if (strpos($dsid, $f_prefix) !== 0) {
$dsid = $f_prefix . $this->pid . '/' . $dsid; $dsid = $f_prefix . $this->pid . '/' . $dsid;
} }
@ -391,12 +392,18 @@ RDF;
$relsxml->documentElement->appendChild($description); $relsxml->documentElement->appendChild($description);
} }
// Create the new relationship node. foreach ((array)$object as $obj) {
$newrel = $relsxml->createElementNS($namespaceURI, $relationship); if ($literal_value == RELS_TYPE_URI && strpos($obj, $f_prefix) !== 0) {
$obj = $f_prefix . $object;
}
// Create the new relationship node.
$newrel = $relsxml->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($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'application/rdf+xml'); return $this->modify_datastream($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'application/rdf+xml');
} }
@ -860,7 +867,7 @@ RDF;
$this->get_datastreams_list_as_SimpleXML(); $this->get_datastreams_list_as_SimpleXML();
$mimetype = ''; $mimetype = '';
foreach ($datastream_list as $datastream) { foreach ($this->datastreams_list as $datastream) {
foreach ($datastream as $datastreamValue) { foreach ($datastream as $datastreamValue) {
if ($datastreamValue->ID == $dsid) { if ($datastreamValue->ID == $dsid) {
return $datastreamValue->MIMEType; return $datastreamValue->MIMEType;
@ -1165,7 +1172,6 @@ RDF;
* @return type * @return type
*/ */
function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
// Default to the current owner if none is provided.. // Default to the current owner if none is provided..
@ -1466,7 +1472,9 @@ RDF;
* @param string $pid if none given, getnextpid will be called. * @param string $pid if none given, getnextpid will be called.
* @param string $state The initial state, A - Active, I - Inactive, D - Deleted * @param string $state The initial state, A - Active, I - Inactive, D - Deleted
* @param type $label * @param type $label
* @param type $owner * @param string $owner
* Used to set an object's ownerId attribute. Defaults to current user's
* name. If we are not a Drupal user(ie. Drush) defaults to ''.
* *
* @return DOMDocument * @return DOMDocument
*/ */
@ -1480,12 +1488,12 @@ RDF;
if (empty($owner)) { if (empty($owner)) {
global $user; global $user;
// Default to current Drupal user. // Default to current Drupal user.
if (!empty($user->uid)) { if (!empty($user->name)) {
$owner = $user->uid; $owner = $user->name;
} }
// We are not inside Drupal. // We are annonamous user.
else { elseif ($user->uid == 0) {
$owner = 'fedoraAdmin'; $owner = 'anonymous';
} }
} }
@ -1551,9 +1559,17 @@ RDF;
* The Fedora PID to retrieve the * The Fedora PID to retrieve the
*/ */
static function getOwnerId($PID) { static function getOwnerId($PID) {
$params = array( $params = array(
'query' => array(array('property' => 'pid', 'operator' => 'eq', 'value' => $PID)), 'query' => array(
'conditions' => array(
array(
'property' => 'pid',
'operator' => 'eq',
'value' => $PID,
),
),
'terms' => '',
),
'resultFields' => array('pid', 'ownerId'), 'resultFields' => array('pid', 'ownerId'),
'maxResults' => 1, 'maxResults' => 1,
); );
@ -1562,7 +1578,8 @@ RDF;
if (!$response) { if (!$response) {
return FALSE; return FALSE;
} }
return $response->result->resultList->objectFields->ownerId; $ownerId = $response->result->resultList->objectFields->ownerId;
return $ownerId;
} }
} }

28
fedora_repository.api.php

@ -95,6 +95,8 @@ function hook_required_fedora_objects() {
* Override ingest permissions. * Override ingest permissions.
* (from islandora_workflow) * (from islandora_workflow)
* *
* @deprecated
* Deprecated in favour of hook_fedora_repository_check_perm().
* @param string $collection_pid * @param string $collection_pid
* The PID of the collection * 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); 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;
}

1161
fedora_repository.module

File diff suppressed because it is too large Load Diff

73
formClass.inc

@ -41,6 +41,7 @@ class formClass {
'title' => t('Solution Packs'), 'title' => t('Solution Packs'),
'description' => t('Install content models and collections required by installed solution packs.'), 'description' => t('Install content models and collections required by installed solution packs.'),
'page callback' => 'fedora_repository_solution_packs_page', 'page callback' => 'fedora_repository_solution_packs_page',
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('add fedora datastreams'), 'access arguments' => array('add fedora datastreams'),
'file' => 'fedora_repository.solutionpacks.inc', 'file' => 'fedora_repository.solutionpacks.inc',
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
@ -50,6 +51,7 @@ class formClass {
'page callback' => 'fedora_repository_display_schema', 'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('islandoracm.xsd'), 'page arguments' => array('islandoracm.xsd'),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('view fedora collection'), 'access arguments' => array('view fedora collection'),
); );
@ -58,24 +60,28 @@ class formClass {
'page callback' => 'fedora_repository_display_schema', 'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('collection_policy.xsd'), 'page arguments' => array('collection_policy.xsd'),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('view fedora collection'), 'access arguments' => array('view fedora collection'),
); );
$items['fedora'] = array( $items['fedora'] = array(
'page callback' => 'repository_page', 'page callback' => 'repository_page',
'type' => MENU_CALLBACK, '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( $items['fedora/repository'] = array(
'title' => 'Digital Repository', 'title' => 'Digital Repository',
'page callback' => 'repository_page', 'page callback' => 'repository_page',
'type' => MENU_NORMAL_ITEM, '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( $items['fedora/repository/service'] = array(
'page callback' => 'repository_service', 'page callback' => 'repository_service',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('view fedora collection'), 'access arguments' => array('view fedora collection'),
); );
@ -83,6 +89,7 @@ class formClass {
'title' => t('Download object'), 'title' => t('Download object'),
'page callback' => 'fedora_object_as_attachment', 'page callback' => 'fedora_object_as_attachment',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('view fedora collection') 'access arguments' => array('view fedora collection')
); );
@ -90,84 +97,48 @@ class formClass {
'title' => t('Edit metadata'), 'title' => t('Edit metadata'),
'page callback' => 'fedora_repository_edit_qdc_page', 'page callback' => 'fedora_repository_edit_qdc_page',
'type' => MENU_CALLBACK, '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( $items['fedora/repository/purgeStream'] = array(
'title' => t('Purge data stream'), 'title' => t('Purge data stream'),
'page callback' => 'fedora_repository_purge_stream', 'page callback' => 'fedora_repository_purge_stream',
'type' => MENU_CALLBACK, '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( $items['fedora/repository/replaceStream'] = array(
'title' => t('Replace Stream'), 'title' => t('Replace Stream'),
'page callback' => 'fedora_repository_replace_stream', 'page callback' => 'fedora_repository_replace_stream',
'type' => MENU_CALLBACK, '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( $items['fedora/repository/purgeObject'] = array(
'title' => t('Purge object'), 'title' => t('Purge object'),
'page callback' => 'fedora_repository_purge_object', 'page callback' => 'fedora_repository_purge_object',
'type' => MENU_CALLBACK, '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( $items['fedora/repository/addStream'] = array(
'title' => t('Add stream'), 'title' => t('Add stream'),
'page callback' => 'add_stream', 'page callback' => 'add_stream',
'type' => MENU_CALLBACK, '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******************************************
$items['fedora/repository/mnpl_advanced_search'] = array(
'title' => t('Repository advanced search'),
'page callback' => 'fedora_repository_mnpl_advanced_search',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection')
); );
$items['fedora/ingestObject'] = array( $items['fedora/ingestObject'] = array(
'title' => t('Ingest object'), 'title' => t('Ingest object'),
'page callback' => 'fedora_repository_ingest_object', 'page callback' => 'fedora_repository_ingest_object',
'type' => MENU_CALLBACK, '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(
'title' => t('List terms'),
'page callback' => 'fedora_repository_list_terms',
'type' => MENU_CALLBACK,
'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( $items['admin/settings/fedora_repository/object_details_xslt'] = array(
@ -500,7 +471,7 @@ class formClass {
* @return type * @return type
*/ */
function canShowIngestForm($collection_pid) { 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); $ingest_override_array = module_invoke_all('fedora_repository_can_ingest', $collection_pid);
$overrides = array_filter($ingest_override_array); $overrides = array_filter($ingest_override_array);
if (empty($overrides)) { if (empty($overrides)) {

2
object_details_xslts/convertQDC.xsl

@ -9,7 +9,7 @@
<xsl:template match="/"> <xsl:template match="/">
<div><table cellspacing="3" cellpadding="3"><tbody> <div><table cellspacing="3" cellpadding="3"><tbody>
<tr><th colspan="3"><h3>MetaData</h3></th></tr> <tr><th colspan="3"><h3 class="islandora-obj-details-metadata-title">Metadata <span class="islandora-obj-details-dsid">(DC)</span></h3></th></tr>
<xsl:for-each select="/*/*"> <xsl:for-each select="/*/*">
<xsl:variable name="FULLFIELD" select="name()"/> <xsl:variable name="FULLFIELD" select="name()"/>
<xsl:variable name="FIELD" select="local-name()"/> <xsl:variable name="FIELD" select="local-name()"/>

1
object_details_xslts/mods2html.xsl

@ -51,6 +51,7 @@
<xsl:template match="mods:mods"> <xsl:template match="mods:mods">
<table class="modsContainer"> <table class="modsContainer">
<tr><th colspan="2"><h3 class="islandora-obj-details-metadata-title">Metadata <span class="islandora-obj-details-dsid">(MODS)</span></h3></th></tr>
<xsl:apply-templates/> <xsl:apply-templates/>
</table> </table>
<!--hr/--> <!--hr/-->

6
plugins/FedoraObjectDetailedContent.inc

@ -93,7 +93,7 @@ class FedoraObjectDetailedContent {
$tabset['fedora_object_details']['tabset']['view']['dc'] = $dc_array; $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( $tabset['fedora_object_details']['tabset']['view'] += array(
'list' => array( 'list' => array(
'#type' => 'fieldset', '#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( $tabset['fedora_object_details']['tabset']['view'] += array(
'purge' => array( 'purge' => array(
'#type' => 'markup', '#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'); $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC');
$tabset['fedora_object_details']['tabset']['edit'] = array( $tabset['fedora_object_details']['tabset']['edit'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',

2
plugins/ShowStreamsInFieldSets.inc

@ -121,7 +121,7 @@ EOJS
'#content' => $dl_link . $dc_html, '#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'); $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC');
$tabset['first_tab']['tabs']['edit'] = array( $tabset['first_tab']['tabs']['edit'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',

2
plugins/herbarium.inc

@ -186,7 +186,7 @@ class Herbarium {
); );
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$obj = new 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'); $editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DARWIN_CORE');
$tabset['third_tab']['tabset']['edit'] = array( $tabset['third_tab']['tabset']['edit'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',

6
plugins/tagging_form.inc

@ -76,7 +76,8 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
'title' => $tag_title_text '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. // Delete button for each existing tag.
$form_tag['delete'] = array( $form_tag['delete'] = array(
'#type' => 'imagebutton', '#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( $form['tags-wrapper']['addtag'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('New Tag'), '#title' => t('New Tag'),

Loading…
Cancel
Save