Browse Source

Updated version number for 6.x-12.3.0-RC1

pull/213/head 6.x-12.3.0-RC1
jonathangreen 12 years ago
parent
commit
b69d6bd139
  1. 83
      CollectionClass.inc
  2. 13
      ContentModel.inc
  3. 83
      MimeClass.inc
  4. 29
      ObjectDetails.inc
  5. 55
      ObjectHelper.inc
  6. 62
      PagerSetup.inc
  7. 7
      README
  8. 612
      SearchClass.inc
  9. 3
      api/fedora_collection.inc
  10. 550
      api/fedora_item.inc
  11. 95
      api/fedora_utils.inc
  12. 4
      api/tuque.inc
  13. 137
      fedora_repository.api.php
  14. 2
      fedora_repository.info
  15. 28
      fedora_repository.install
  16. 1557
      fedora_repository.module
  17. 87
      fedora_repository.solutionpacks.inc
  18. 161
      fedora_repository.test.inc
  19. 99
      formClass.inc
  20. 2
      object_details_xslts/convertQDC.xsl
  21. 1
      object_details_xslts/mods2html.xsl
  22. 41
      plugins/FedoraObjectDetailedContent.inc
  23. 2
      plugins/ShowStreamsInFieldSets.inc
  24. 2
      plugins/fedora_imageapi.info
  25. 96
      plugins/fits.inc
  26. 2
      plugins/herbarium.inc
  27. 4
      plugins/qt_viewer.inc
  28. 6
      plugins/tagging_form.inc
  29. 14
      xsl/sparql_to_html.xsl

83
CollectionClass.inc

@ -34,12 +34,12 @@ class CollectionClass {
}
public static function getCollectionQuery($pid) {
if ($query = self::getCollectionQueryFromStream($pid)) {
return $query;
}
else {
return self::getDefaultCollectionQuery($pid);
$query = self::getCollectionQueryFromStream($pid);
if (!$query) {
$query = self::getDefaultCollectionQuery($pid);
}
drupal_alter("islandora_collection_query", $query, $pid);
return $query;
}
protected static function getCollectionQueryFromStream($pid) {
@ -54,13 +54,11 @@ class CollectionClass {
}
protected static function getDefaultCollectionQuery($pid) {
return 'select $object $title $content from <#ri>
return 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and $object <fedora-model:hasModel> $content
and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '>
or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title';
}
@ -104,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 ' ';
}
@ -323,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;
}
@ -588,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')) {
@ -606,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...
*
@ -685,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();

13
ContentModel.inc

@ -1475,7 +1475,17 @@ class ContentModel extends XMLDatastream {
self::$errors[] = 'Execute Form Handler: file \'' . $path . '\' does not exist.';
}
else {
require_once($path);
$file_extension = pathinfo($method->getAttribute('file'), PATHINFO_EXTENSION);
$file_path_without_extension = $method->getAttribute('file');
/* Only in PHP. This is meant to avoid file path
* concatenation issues.*/
$file_path_without_extension = substr($file_path_without_extension, 0, strlen($file_path_without_extension) - (strlen($file_extension) + 1));
/* Only try to execute if the module is present, this is
* necessarybecause we go outside of the expected
* 'Drupal Way' and have dynamic dependencies.*/
if (module_exists(!empty($module) ? $module : 'fedora_repository')) {
module_load_include($file_extension, !empty($module) ? $module : 'fedora_repository', $file_path_without_extension);
$className = $method->getAttribute('class');
$methodName = ($method->getAttribute('method'));
if (!class_exists($className)) {
@ -1496,6 +1506,7 @@ class ContentModel extends XMLDatastream {
}
}
}
}
return $output;
}

83
MimeClass.inc

@ -21,10 +21,11 @@
* http://api.drupal.org/api/function/file_default_mimetype_mapping/7
*
*/
class MimeClass {
private $private_mime_types = array(
/**
/*
* This is a shortlist of mimetypes which should catch most
* mimetype<-->extension lookups in the context of Islandora collections.
*
@ -37,16 +38,16 @@ class MimeClass {
* project, as lookups against this list will be quicker and less
* resource intensive than other methods.
*
* Lookups are first checked against this short list. If no results are found,
* then the lookup function may move on to check other sources, namely the
* system's mime.types file.
* Lookups are first checked against this short list.
* If no results are found, then the lookup function may move
* on to check other sources, namely the system's mime.types file.
*
* In most cases though, this short list should suffice.
*
* If modifying this list, please note that for promiscuous mimetypes
* (those which map to multiple extensions, such as text/plain)
* The function get_extension will always return the *LAST* extension in this list,
* so you should put your preferred extension *LAST*.
* The function get_extension will always return the *LAST* extension
* in this list, so you should put your preferred extension *LAST*.
*
* e.g...
* "jpeg" => "image/jpeg",
@ -89,7 +90,7 @@ class MimeClass {
'ksp' => 'application/x-kspread',
'kwt' => 'application/x-kword',
'kwd' => 'application/x-kword',
// ms office 97:
// MS office 97:
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
@ -113,9 +114,9 @@ class MimeClass {
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// wordperfect (who cares?):
// Wordperfect (who cares?):
'wpd' => 'application/wordperfect',
// common and generic containers:
// Common and generic containers:
'pdf' => 'application/pdf',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
@ -133,6 +134,7 @@ class MimeClass {
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xml',
'xslt' => 'text/xml',
'xml' => 'text/xml',
'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values',
@ -174,6 +176,8 @@ class MimeClass {
"movie" => "video/x-sgi-movie",
"flv" => "video/x-flv",
"swf" => "application/x-shockwave-flash",
'mkv' => "video/x-matroska",
'wmv' => 'video/x-ms-wmv',
// audio:
"mp3" => "audio/mpeg",
"mp4a" => "audio/mp4",
@ -182,7 +186,8 @@ class MimeClass {
"ogg" => "audio/ogg",
"flac" => "audio/x-flac",
"wav" => "audio/vnd.wave",
// compressed formats: (note: http://svn.cleancode.org/svn/email/trunk/mime.types)
/* Compressed formats:
(note: http://svn.cleancode.org/svn/email/trunk/mime.types).*/
"tgz" => "application/x-gzip",
"gz" => "application/x-gzip",
"tar" => "application/x-tar",
@ -190,7 +195,9 @@ class MimeClass {
"zip" => "application/x-zip",
// others:
'bin' => 'application/octet-stream',
'json' => 'application/json',
);
private $private_file_extensions;
private $system_types;
private $system_exts;
@ -201,10 +208,10 @@ class MimeClass {
*/
public function __construct() {
// populate the reverse shortlist:
// Populate the reverse shortlist:
$this->private_file_extensions = array_flip($this->private_mime_types);
// pick up a local mime.types file if it is available
// Pick up a local mime.types file if it is available.
if (is_readable('mime.types')) {
$this->etc_mime_types = 'mime.types';
}
@ -224,40 +231,47 @@ class MimeClass {
/**
* function: get_mimetype
* description: returns a mimetype associated with the file extension of $filename
* description: returns a mimetype associated with the
* file extension of $filename
*
* @param type $filename
* @param type $debug
* @return type
* @return string
* mimetype associated with the file extension of $filename
*/
public function get_mimetype($filename, $debug = FALSE) {
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
if (!empty($this->private_mime_types[$ext])) {
if (TRUE === $debug)
if (TRUE === $debug) {
return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array');
}
return $this->private_mime_types[$ext];
}
if (function_exists('file_get_mimetype')) {
$drupal_mimetype = file_get_mimetype($filename);
if ('application/octet-stream' != $drupal_mimetype) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype');
}
return $drupal_mimetype;
}
}
if (!isset($this->system_types))
if (!isset($this->system_types)) {
$this->system_types = $this->system_extension_mime_types();
}
if (isset($this->system_types[$ext])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types');
}
return $this->system_types[$ext];
}
if (TRUE === $debug)
if (TRUE === $debug) {
return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort');
}
return 'application/octet-stream';
}
@ -272,21 +286,25 @@ class MimeClass {
public function get_extension($mime_type, $debug = FALSE) {
if (!empty($this->private_file_extensions[$mime_type])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array');
}
return $this->private_file_extensions[$mime_type];
}
if (!isset($this->system_exts))
if (!isset($this->system_exts)) {
$this->system_exts = $this->system_mime_type_extensions();
}
if (isset($this->system_exts[$mime_type])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types');
}
return $this->system_exts[$mime_type];
}
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => 'bin', 'method' => 'last_resort');
}
return 'bin';
}
@ -303,15 +321,18 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line));
if (!$line)
if (!$line) {
continue;
}
$parts = preg_split('/\s+/', $line);
if (count($parts) == 1)
if (count($parts) == 1) {
continue;
}
// A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts);
if (!isset($out[$type]))
if (!isset($out[$type])) {
$out[$type] = array_shift($parts);
}
// We take the first ext from the line if many are present.
}
fclose($file);
@ -332,20 +353,22 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line));
if (!$line)
if (!$line) {
continue;
}
$parts = preg_split('/\s+/', $line);
if (count($parts) == 1)
if (count($parts) == 1) {
continue;
}
// A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts);
foreach ($parts as $part)
foreach ($parts as $part) {
$out[$part] = $type;
}
}
fclose($file);
}
return $out;
}
}

29
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<br/>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;
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)) {
@ -127,6 +138,10 @@ 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') {
$dsid = 'DC';
$xmlstr = $item->get_datastream_dissemination($dsid);
}
if (empty($xmlstr)) {
return t('Error - could not find datastream @dsid on object @pid<br/>Please contact the site administrator.',
array('@dsid' => $dsid, '@pid' => $item->pid));
@ -136,7 +151,7 @@ function fedora_repository_object_details_table($item) {
$headers = array(
array(
'data' => t('Metadata'),
'data' => t('Metadata (@dsid)', array('@dsid' => $dsid)),
'colspan' => 2,
),
);
@ -191,6 +206,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 +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_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');
}
@ -253,6 +274,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"),
@ -272,5 +298,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');
}

55
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 ' ';
@ -137,9 +137,6 @@ class ObjectHelper {
$fedoraPass = $user->pass;
}
$dataStreamInfo = $item->get_datastream_info($dsID);
$contentSize = $dataStreamInfo->datastream->size;
if (function_exists("curl_init")) {
$url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content';
$query_options = array();
@ -181,6 +178,9 @@ class ObjectHelper {
if ($curl_stat !== FALSE) {
$info = curl_getinfo($ch);
// Fixes an IE issue (ISLANDORA-311)
// http://support.microsoft.com/kb/316431
drupal_set_header("Cache-Control: private", TRUE);
//Set what headers we can...
if ($mimeType = $info['content_type']) {
@ -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 = '&nbsp;';
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 = '&nbsp;';
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;
}
@ -810,6 +780,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

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;
}

7
README

@ -7,3 +7,10 @@ https://wiki.duraspace.org/display/ISLANDORA/Islandora
All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA:
https://jira.duraspace.org/browse/ISLANDORA
Fedora/Drupal Security
======================
The islandora_drupal_filter passes the username of 'anonymous' through to Fedora for unauthenticated
Drupal Users. A user with the name of 'anonymous' may have XACML policies applied to them that are
meant to be applied to Drupal users that are not logged in or vice-versa. This is a potential security
issue that can be plugged by creating a user named 'anonymous' and restricting access to the account.

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') {
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();
}

550
api/fedora_item.inc

File diff suppressed because it is too large Load Diff

95
api/fedora_utils.inc

@ -1,23 +1,23 @@
<?php
/**
* @file
* Base utilities used by the Islandora fedora module.
*/
if (!function_exists('str_getcsv')) {
/**
* Functions that emulate php5.3 functionality for backwards compatiablity
*
* @param type $input
* @param type $delimiter
* @param type $enclosure
* @param type $escape
* @param type $eol
*
* @return type
*/
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=NULL, $eol=NULL) {
function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = NULL, $eol = NULL) {
$temp = fopen("php://memory", "rw");
fwrite($temp, $input);
fseek($temp, 0);
@ -50,7 +50,7 @@ if (!function_exists('str_getcsv')) {
* @param $post
* Whether the curl_exec is done as a "get" or a "post"
*
* @return
* @return mixed
* TRUE, FALSE, NULL, or the data returned from accessing the URL
*/
function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
@ -59,7 +59,6 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
}
/**
*
* Utility method to get data from a url location using curl_exec
*
* This method takes a URL and three associated parameters and initializes the
@ -70,7 +69,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* Various defaults are used for the parameters required by curl_exec including
* the user agent and timeout. These are hard-coded.
*
* @param $url
* @param string $url
* URL to be accessed by the function
* @param $return_to_variable
* Indicates whether the resource accessed by the curl call (HTML page,
@ -81,7 +80,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* @param $post
* Whether the curl_exec is done as a "get" or a "post"
*
* @return
* @return mixed
* an array that consists of three value or NULL if curl is not suported:
* - element 0:
* The value returned from the curl_exec function call.
@ -112,11 +111,15 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s
// Fail on errors.
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
// Allow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// Times out after 90s.
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable
// Return into a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
@ -141,7 +144,8 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
/**
* Fedora available
* @return type
*
* @return mixed
*/
function fedora_available() {
@ -151,7 +155,8 @@ function fedora_available() {
/**
* Resource index search available
* @return type
*
* @return mixed
*/
function risearch_available() {
@ -161,7 +166,9 @@ function risearch_available() {
/**
* Returns a UTF-8-encoded transcripiton of the string given in $in_str.
*
* @param string $in_str
*
* @return string A UTF-8 encoded string.
*/
function fix_encoding($in_str) {
@ -176,7 +183,9 @@ function fix_encoding($in_str) {
/**
* valid pid ??
*
* @param type $pid
*
* @return boolean
*/
function valid_pid($pid) {
@ -190,7 +199,9 @@ function valid_pid($pid) {
/**
* Valid Dsid ??
*
* @param type $dsid
*
* @return boolean
*/
function valid_dsid($dsid) {
@ -204,7 +215,9 @@ function valid_dsid($dsid) {
/**
* fixDsid ??
*
* @param type $dsid
*
* @return string
*/
function fix_dsid($dsid) {
@ -214,14 +227,17 @@ function fix_dsid($dsid) {
$replace = '';
$new_dsid = preg_replace($find, $replace, $new_dsid);
if (strlen($new_dsid) > 63)
if (strlen($new_dsid) > 63) {
$new_dsid = substr($new_dsid, -63);
}
if (preg_match('/^[^a-zA-Z]/', $dsid))
if (preg_match('/^[^a-zA-Z]/', $dsid)) {
$new_dsid = 'x' . $new_dsid;
}
if (strlen($new_dsid) == 0)
if (strlen($new_dsid) == 0) {
$new_dsid = 'item' . rand(1, 100);
}
return $new_dsid;
}
@ -229,9 +245,8 @@ function fix_dsid($dsid) {
/**
* Function: get_collections_as_option_array
*
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array
* Returns an associative array of all collection objects in Fedora instance
*/
function get_collections_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -254,7 +269,7 @@ function get_collections_as_option_array() {
'stream' => 'on',
'query' => $query,
);
//The url function will take care of URL encoding...
// The url function will take care of URL encoding.
$content = do_curl(url($url, array('query' => $options)));
$list = explode("\n", $content);
@ -264,7 +279,8 @@ function get_collections_as_option_array() {
$trimmed_names[] = trim($namespace);
}
$options = array();
foreach ($list as $item) { //removes blanks
// Removes blanks.
foreach ($list as $item) {
if ($item) {
$parts = explode(',', $item);
$namespace = explode(':', $parts[0]);
@ -283,9 +299,8 @@ function get_collections_as_option_array() {
/**
* Function: get_content_models_as_option_array
*
* Description: Returns an associative array of all available content models in Fedora instance
*
* @return array
* associative array of all available content models in Fedora instance
*/
function get_content_models_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -311,12 +326,12 @@ function get_content_models_as_option_array() {
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks
// Removes blanks.
foreach ($list as $item) {
if ($item) {
$parts = explode(',', $item);
$nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed)) {
if (!preg_match('/fedora-system/', $nameparts[0])) {
$options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0];
}
@ -326,3 +341,33 @@ function get_content_models_as_option_array() {
return $options;
}
/**
* This function will retrieve the collections that the given PID belongs to.
*
* @param string $PID
* The PID to find the parents of.
*
* @return array
* $object_PIDs the list of PIDs of the collections that the
* indicated object is a member of.
*/
function get_parent_collections_from_pid($PID) {
$query_string = 'select $parent from <#ri>
where ($object <fedora-rels-ext:isMemberOf> $parent
or $object <fedora-rels-ext:isMemberOfCollection> $parent)
and $object <dc:identifier> \'' . $PID . '\'
order by $object';
$query_string = htmlentities(urlencode($query_string));
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= '?type=tuples&flush=true&format=csv&limit=13000&lang=itql&stream=on&query=' . $query_string;
$content = do_curl($url, TRUE);
$results = explode("\n", $content);
$object_PIDs = preg_replace('/^info:fedora\/|"parent"| /', '', $results);
$object_PIDs = array_values(array_filter($object_PIDs));
return $object_PIDs;
}

4
api/tuque.inc

@ -2,7 +2,7 @@
$islandora_module_path = drupal_get_path('module', 'fedora_repository');
//do this until we expost these in a module or library
//do this until we export these in a module or library
@include_once 'sites/all/libraries/tuque/Datastream.php';
@include_once 'sites/all/libraries/tuque/FedoraApi.php';
@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php';
@ -67,7 +67,7 @@ class IslandoraTuque {
}
if (!isset($url)) {
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
$url = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
}
if(self::exists()) {

137
fedora_repository.api.php

@ -0,0 +1,137 @@
<?php
/**
* @file
* This file defines the hooks that fedora_repository (islandora)
* makes available.
*/
/**
* Implements hook_islandora_tabs().
* This hook lets one add tabs to the object page in Islandora.
*
* @param array $content_models
* An Array of content model objects. A content model is only included
* if the object actualy exists with a ISLANDORACM datastream.
* @param string $pid
* The Fedora PID of the object who's page is firing the hook.
* @param int $page_number
* Page number for collection views.
*
* @return array
* $tabset a tab definition.
*/
function hook_islandora_tabs($content_models, $pid, $page_number) {
$tabset['A TAB'] = array(
'#type' => 'tabpage',
'#title' => t('A TITLE'),
'#content' => 'content')
);
return $tabset;
}
/**
* Implements hook_postprocess_solution_pack().
* This hook fires after the batch job to ingest a solution pack finishes.
*
* @param string $module
* Name of the module that spcified the solution pack.
*/
function hook_fedora_repository_postprocess_solution_pack($module) {
// Do something that requires the objects to be ingested ie. add XACML.
return;
}
/**
* Implements hook_required_fedora_objects().
* This hook lets one add objects to the repository through the
* solution pack interface.
*
* @return array
* array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file',
* int dsversion, boolean required)
*/
function hook_required_fedora_objects() {
return array(
'fedora_repository' => array(
'module' => 'fedora_repository',
'title' => 'Islandora Core',
'objects' => array(
array(
'pid' => 'islandora:collectionCModel',
'label' => 'Islandora Collection Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "./$module_path/content_models/COLLECTIONCM.xml",
'dsversion' => 2,
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:root',
'label' => 'Islandora Top-level Collection',
'cmodel' => 'islandora:collectionCModel',
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "./$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
),
array(
'dsid' => 'TN',
'datastream_file' => "./$module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
),
),
),
),
);
}
/**
* Implements hook_fedora_repository_can_ingest().
* 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
*
* @return boolean
* TRUE if the user can ingest into the specified collection, FALSE otherwise.
*/
function hook_fedora_repository_can_ingest($collection_pid) {
module_load_include('inc', 'islandora_workflow', 'islandora_workflow.permissions');
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;
}

2
fedora_repository.info

@ -4,5 +4,5 @@ dependencies[] = tabs
dependencies[] = islandora_content_model_forms
description = Shows a list of items in a fedora collection.
package = Islandora
version = 6.x-12.2.0
version = 6.x-12.3.0-RC1
core = 6.x

28
fedora_repository.install

@ -104,3 +104,31 @@ function fedora_repository_requirements($phase) {
return $requirements;
}
/**
* Implements hook_update_N().
*
* This function will try and update the SOAP WSDLs
* as they were set wrong in previous releases.
*/
function fedora_repository_update_6001() {
// Get variables to check for update.
$API_A_WSDL = variable_get('fedora_soap_url', $default = NULL);
$API_M_WSDL = variable_get('fedora_soap_manage_url', $default = NULL);
// Update API A if necessary.
$A_WSDL = parse_url($API_A_WSDL, PHP_URL_PATH) . '?' . parse_url($API_A_WSDL, PHP_URL_QUERY);
if ($A_WSDL == '/fedora/services/access?wsdl') {
variable_set('fedora_soap_url', str_replace('/fedora/services/access?wsdl', '/fedora/wsdl?api=API-A', $API_A_WSDL));
}
// Update API M if necessary.
$M_WSDL = parse_url($API_M_WSDL, PHP_URL_PATH) . '?' . parse_url($API_M_WSDL, PHP_URL_QUERY);
if ($M_WSDL == '/fedora/services/management?wsdl') {
variable_set('fedora_soap_manage_url', str_replace('/fedora/services/management?wsdl', '/fedora/wsdl?api=API-M', $API_M_WSDL));
}
return array(
array('success' => TRUE, 'query' => 'Please check your WSDL paths in Islandora\'s config, this update requires them to be set correctly: access; /fedora/wsdl?api=API-A, management; /fedora/wsdl?api=API-M'),
);
}

1557
fedora_repository.module

File diff suppressed because it is too large Load Diff

87
fedora_repository.solutionpacks.inc

@ -2,26 +2,38 @@
/**
* @file
* Invokes a hook to any dependent modules asking them if their installations require
* any fedora objects to be present. Modules implementing this hook should return an array
* Invokes a hook to any dependent modules asking them if their
* installations require any fedora objects to be present.
* Modules implementing this hook should return an array
* of arrays of the form:
*
* array( 'pid', 'path-to-foxml-file', 'dsid', 'path-to-datastream-file', int dsversion)
* array( 'pid', 'path-to-foxml-file',
* 'dsid',
* 'path-to-datastream-file',
* int dsversion)
*
* where the last three options are optional. A module can either point to a simple
* foxml file to install, or can specify a datastreamstream to check for, with a
* path to load the datastream from if it isn't there. Optionally a version number
* can be included, to enable updating of content model or collection policy streams
* that may have been updated. THis is a simple whole number that should be incremented
* when changed. This value appears in as an attribute of the topmost element of the stream,
* where the last three options are optional.
* A module can either point to a simple foxml file to install,
* or can specify a datastreamstream to check for, with a
* path to load the datastream from if it isn't there.
* Optionally a version number can be included,
* to enable updating of content model or collection policy streams
* that may have been updated.
* This is a simple whole number that should be incremented when changed.
* This value appears in as an attribute of the topmost element of the stream,
* e.g.,:
*
* <?xml version="1.0" encoding="utf-8"?> <content_model name="Collection" version="2" ...
* <?xml version="1.0" encoding="utf-8"?>
* <content_model name="Collection" version="2" ...
*
* Datastreams which don't have this element are assumed to be at version 0.
*/
/**
* Builds the tab for the solution packs.
*/
function fedora_repository_solution_packs_page() {
$enabled_solution_packs = module_invoke_all('required_fedora_objects');
$enabled_solution_packs = module_invoke_all('fedora_repository_required_fedora_objects');
$output = '';
foreach ($enabled_solution_packs as $solution_pack_module => $solution_pack_info) {
$objects = array();
@ -42,8 +54,17 @@ function fedora_repository_solution_packs_page() {
}
/**
* Check for installed objects and add a 'Update' or 'Install' button if some objects are missing.
* @param array $solution_pack
* Check for installed objects and add a 'Update' or 'Install' button if
* some objects are missing.
*
* @param array &$form_state
* The current state of the form.
* @param unknown $solution_pack_module
* Module name of that solution pack.
* @param string $solution_pack_name
* Human readable name for the solution pack.
* @param array $objects
* Defaults to an empty array.
*/
function fedora_repository_solution_pack_form(&$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) {
@ -161,13 +182,19 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul
return $form;
}
/**
* Submit handler for solution pack form.
*
* @param array $form
* The form submitted.
* @param array_reference $form_state
* The state of the form submited.
*/
function fedora_repository_solution_pack_form_submit($form, &$form_state) {
$what = $form_state;
$module_name = $form_state['values']['solution_pack_module'];
// This should be replaced with module_invoke
//$solution_pack_info = call_user_func($module_name . '_required_fedora_objects');
$solution_pack_info = module_invoke($module_name, 'required_fedora_objects');
$solution_pack_info = module_invoke($module_name, 'fedora_repository_required_fedora_objects');
$batch = array(
'title' => t('Installing / updating solution pack objects'),
@ -178,11 +205,25 @@ function fedora_repository_solution_pack_form_submit($form, &$form_state) {
foreach ($solution_pack_info[$module_name]['objects'] as $object) {
// Add this object to the batch job queue.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object));
// Module name is needed in the finished callback.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object, $module_name));
}
// Tell the batch to call the function to send out a postprocess hook.
$batch['finished'] = 'fedora_repository_solutionpack_send_postprocess';
batch_set($batch);
}
/**
* Writes a form entry into the database.
*
* @param string $form_name
* The name of the form.
* @param unknown_type $form_xml
* The form definition.
*/
function solution_pack_add_form($form_name, $form_xml) {
$result = db_result(db_query('Select name from {xml_forms} where name = "%s"', $form_name));
if (!$result) {
@ -194,6 +235,14 @@ function solution_pack_add_form($form_name, $form_xml) {
}
}
/**
* Writes a form association to the database
*
* @param string $content_model
* content model PID
* @param string $form_name
* Name of the form
*/
function solution_pack_add_form_association($content_model, $form_name) {
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"',
$content_model, $form_name));
@ -205,6 +254,6 @@ function solution_pack_add_form_association($content_model, $form_name) {
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name"=>$form_name)));
drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name" => $form_name)));
}
}

161
fedora_repository.test.inc

@ -0,0 +1,161 @@
<?php
/**
* @file
* Generic test case to be extended to implement Islandora testing.
*
* In order to use this properly, you must place a test user in
* your Fedora installation. Please add the follwing snippet to your
* $FEDORA_HOME/server/config/fedora-users.xml:
*
* <user name="simpletestuser" password="41fe63c9636c6649f0a4747400f0f95e">
* <attribute name="fedoraRole">
* <value>administrator</value>
* </attribute>
* </user>
*/
abstract class IslandoraTestCase extends DrupalWebTestCase {
/**
* User with the rights required to perform the test
*/
protected $privileged_user;
/**
* Override this method to provide the name of the module,
* e.g. the name of the .module file
*
* @return string - The name of the module
*/
abstract protected function getModuleName();
/**
* Returns basic permissions needed for running Islandora tests.
* Override this method to provide additional permissions, but
* be sure to append your new permissions to the return value
* of parent::getUserPermissions and return that.
*
* @return array - An array of strings describing permissions
*/
protected function getUserPermissions() {
return array(
'access content',
'add fedora datastreams',
'edit fedora meta data',
'edit tags datastream',
'ingest new fedora objects',
'purge objects and datastreams',
'view fedora collection',
'view detailed list of content',
);
}
/**
* Creates a user with permissions required for the test, and logs in.
*/
protected function createPrivilegedUser() {
// Create a role with the permissions from getUserPermissions()
$role = $this->drupalCreateRole($this->getUserPermissions());
// Create a user model
$user = array(
'name' => 'simpletestuser',
'mail' => 'simpletestuser@example.com',
'roles' => array( $role => $role ),
'pass' => 'simpletestpass',
'status' => 1,
);
// Create a user from the model
$this->privileged_user = user_save('', $user);
// Add the raw password so we can log in
$this->privileged_user->pass_raw = $user['pass'];
// Log in
!$this->drupalLogin($this->privileged_user);
}
/**
* Automatically generates all module dependencies and enables them in order.
* Also logs in a privileged user with the appropriate permissions for the
* test.
*
* If you need to override this method to provide extra functionality,
* please be sure to call parent::setUp so dependency resolution and
* authentication still happen.
*/
public function setUp() {
// Grab all the available modules
$modules = module_rebuild_cache();
// Grab the module to test's dependencies
$dependencies = $modules[$this->getModuleName()]->info['dependencies'];
// Sort them so they're in the correct order to enable
$dependencies = array_reverse($dependencies);
// Add our module to the end
$dependencies[] = $this->getModuleName();
// Enable the module's dependencies in order
call_user_func_array('parent::setUp', $dependencies);
// Authenticate the privileged user
$this->createPrivilegedUser();
}
public function invoke($hook_name) {
$args = func_get_args();
array_unshift($args, $this->getModuleName());
return call_user_func_array('module_invoke', $args);
}
}
/**
* Class containing tests that are common to all solution packs.
*/
abstract class SolutionPackTestCase extends IslandoraTestCase {
/**
* Tests the fedora_repository_required_fedora_objects hook.
*
* Validates the schema of the array returned by the hook. The array should
* be roughly of the form:
* [
* module_name =>
* [
* 'module' => module_name,
* 'title' => module_title,
* 'objects' =>
* [
* ...
* ]
* ]
* ]
*
* Where each entry of the 'objects' sub-array should be arrays themselves,
* each containing the information needed for drupal_get_form().
*
* Note that the root key of the array is the actual module name (e.g.
* islandora_audio_sp, islandora_image_sp, etc...), not 'module_name'
*/
public function testFedoraRepositoryRequiredFedoraObjects() {
// Invoke the hook
$results = $this->invoke('fedora_repository_required_fedora_objects');
// Validate the schema of the returned data structure
$this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.');
$this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.');
$this->assertTrue(array_key_exists($this->getModuleName(), $results), "Returned array has top level key that is equal to the module's short form name");
$this->assertTrue(is_array($results[$this->getModuleName()]), "Value associated with top level key that is equal to the module's short form name is an array");
$this->assertTrue(array_key_exists('module', $results[$this->getModuleName()]), "Top level array has 'module' key");
$this->assertEqual($results[$this->getModuleName()]['module'], $this->getModuleName(), "Value associated with 'module' key is equal to the module's short form name");
$this->assertTrue(array_key_exists('title', $results[$this->getModuleName()]), "Top level array has 'title' key");
$this->assertTrue($results[$this->getModuleName()]['title'], "Title string is not empty");
$this->assertTrue(array_key_exists('objects', $results[$this->getModuleName()]), "Returned array has second level key equal to 'object'");
$this->assertTrue(is_array($results[$this->getModuleName()]['objects']), "Value associated with second level 'object' key is an array");
}
}

99
formClass.inc

@ -1,7 +1,5 @@
<?php
/**
* @file
* formClass class
@ -43,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,
@ -52,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'),
);
@ -60,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'),
);
@ -85,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')
);
@ -92,84 +97,48 @@ 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')
);
//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')
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('add fedora datastreams', 3)
);
$items['fedora/ingestObject'] = array(
'title' => t('Ingest object'),
'page callback' => 'fedora_repository_ingest_object',
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams')
);
$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'),
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('add fedora datastreams', 2)
);
$items['admin/settings/fedora_repository/object_details_xslt'] = array(
@ -234,7 +203,7 @@ class formClass {
$form['fedora_soap_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP Url'),
'#default_value' => variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'),
'#default_value' => variable_get('fedora_soap_url', 'http://localhost:8080/fedora/wsdl?api=API-A'),
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => -12,
@ -370,12 +339,28 @@ class formClass {
'#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE),
);
//FITS functionality
$form['advanced']['enable_fits'] = array(
'#type' => 'checkbox',
'#title' => t('Enable FITS support?'),
'#description' => t('Whether or not we should create a FITS datastream upon object ingest.'),
'#default_value' => variable_get('enable_fits', FALSE),
);
//FITS Path
$form['advanced']['fits_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to FITS executable'),
'#description' => t("Path to FITS program on your server. It must be accessible by Drupal (i.e. apache user)."),
'#default_value' => variable_get('fits_path','/usr/local/bin/fits.sh'),
);
//Export functionality
$form['advanced']['module']['export_area'] = array(
'#type' => 'textfield',
'#title' => t('Export area'),
'#default_value' => variable_get('export_area', file_directory_path() . '/fedora_export_area'),
'#description' => t("Path to the export area. It must be accessible by druapl (i.e. apache user)."),
'#description' => t("Path to the export area. It must be accessible by drupal (i.e. apache user)."),
'#required' => TRUE,
);
@ -486,10 +471,14 @@ 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)) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return FALSE;
}
}
module_load_include('inc', 'fedora_repository', 'SecurityClass');
$security_class = new SecurityClass();
if (!$security_class->canIngestHere($collection_pid)) {

2
object_details_xslts/convertQDC.xsl

@ -9,7 +9,7 @@
<xsl:template match="/">
<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:variable name="FULLFIELD" select="name()"/>
<xsl:variable name="FIELD" select="local-name()"/>

1
object_details_xslts/mods2html.xsl

@ -51,6 +51,7 @@
<xsl:template match="mods:mods">
<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/>
</table>
<!--hr/-->

41
plugins/FedoraObjectDetailedContent.inc

@ -55,14 +55,14 @@ class FedoraObjectDetailedContent {
if (!isset($profile)) {
// default behaviour
watchdog('fedora_repository', "Error while reading the default object details display profile: @e", array("@e" => $e->getMessage()), WATCHDOG_WARNING);
$dc_html = $objectHelper->getFormattedDC($this->item);
$dc_returned = $objectHelper->getFormattedDC($this->item);
}
else {
// invoke the requested display profile
require_once(drupal_get_path('module', $profile['module']) ."/". $profile['file']);
$details_function = $profile['function'];
if (function_exists($details_function)) {
$dc_html = $details_function($this->item);
$dc_returned = $details_function($this->item);
}
else {
// problem - display profile not found
@ -70,16 +70,31 @@ class FedoraObjectDetailedContent {
}
}
$dc_array = array();
$i = 0;
if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {
if (is_array($dc_returned)) {
$dc_array = $dc_returned;
$dc_array['#weight'] = $i++;
}
elseif (!empty($dc_returned)) {
$dc_array = array(
'#type' => 'markup',
'#value' => $dc_returned, //XXX: This could easily be done in Drupal, instead of using an XSL
'#weight' => $i++
);
}
$tabset['fedora_object_details']['tabset']['view'] = array(
'#type' => 'tabpage',
'#title' => t('View'),
'dc' => array(
'#type' => 'markup',
'#value' => $dc_html, //XXX: This could easily be done in Drupal, instead of using an XSL
'#weight' => $i++
),
);
if (!empty($dc_array)) {
$tabset['fedora_object_details']['tabset']['view']['dc'] = $dc_array;
}
if (fedora_repository_check_perm(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {
$tabset['fedora_object_details']['tabset']['view'] += array(
'list' => array(
'#type' => 'fieldset',
'#title' => t('Detailed List of Content'),
@ -100,6 +115,11 @@ class FedoraObjectDetailedContent {
'#weight' => $i++,
),
),
);
}
if (fedora_repository_check_perm(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS, $this->pid, $user)) {
$tabset['fedora_object_details']['tabset']['view'] += array(
'purge' => array(
'#type' => 'markup',
'#value' => $purge_form,
@ -108,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',
@ -119,7 +139,8 @@ class FedoraObjectDetailedContent {
}
$ts = $tabset['fedora_object_details']['tabset'];
if (array_key_exists('view', $ts) || array_key_exists('edit', $ts)) {
if ((array_key_exists('view', $ts) && (count(element_children($ts['view'])) > 0)) ||
(array_key_exists('edit', $ts) && (count(element_children($ts['edit'])) > 0 || array_key_exists('#content', $ts['edit'])))) {
return $tabset;
}
else {

2
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',

2
plugins/fedora_imageapi.info

@ -3,5 +3,5 @@ description = Adds image manipulation support through a REST interface
package = Islandora Dependencies
dependencies[] = fedora_repository
dependencies[] = imageapi
version = 6.x-12.2.0
version = 6.x-12.3.0-RC1
core = 6.x

96
plugins/fits.inc

@ -0,0 +1,96 @@
<?php
/**
* @file
* Fits
* fits.sh must be in the apache user's path
*
* Download FITS from http://code.google.com/p/fits/
* Installing: http://code.google.com/p/fits/wiki/installing
* Edit line 5 in fits.sh (FITS_HOME='') and give it a home.
* Make sure that home is in the apache user's path.
*
*/
/**
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/
class fits {
private $pid = NULL;
private $item = NULL;
/**
* Constructor
* @param type $pid
*/
function __construct($pid = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!empty($pid)) {
$this->pid = $pid;
$this->item = new Fedora_Item($this->pid);
}
}
/**
* extract metadata
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function extractFits($parameterArray, $dsid, $file, $file_ext) {
if (variable_get('enable_fits', FALSE) == 1) {
$file_name = '_' . $dsid . '.xml';
$output = array();
exec(variable_get('fits_path', '/usr/local/bin/fits.sh') .' -i ' . escapeshellarg($file) . '', $output);
if ( !file_put_contents($file . $file_name, implode("\n", $output)) ) {
//drupal_set_message(t("error writing fits file %s", array('%s' => "$file.$file_name")));
return FALSE;
}
$_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_name;
return TRUE;
}
return TRUE; //this prevents getting the error following content model rules message when fits generation is turned off
}
/**
* display metadata
* @return type
*/
function displayFits() {
$output = '';
$fits = $this->item->get_datastream_dissemination('TECHMD_FITS');
if (trim($fits) != '') {
$fitsDom = DOMDocument::loadXML($this->item->get_datastream_dissemination('FITS'));
if ($fitsDom != NULL) {
$description = $fitsDom->getElementsByTagName('fits');
if ($description->length > 0) {
$description = $description->item(0);
$output .= '<div class="fedora_technical_metadata"><ul>';
for ($i = 0; $i < $description->childNodes->length; $i++) {
$name = $description->childNodes->item($i)->nodeName;
$value = $description->childNodes->item($i)->nodeValue;
if ($name != '#text' && !preg_match('/^System\:.*$/', $name) && trim($value) != '') {
list($type, $name) = preg_split('/\:/', $name);
$name = trim(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])/', " $1", $name));
$output .= '<li><b>' . $name . '</b>: ' . $value . ' </li>';
}
}
$output .= '</ul></div>';
$fieldset = array(
'#title' => t("!text", array('!text' => 'FITS Technical Metadata')),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output
);
$output = theme('fieldset', $fieldset);
}
}
}
return $output;
}
}

2
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',

4
plugins/qt_viewer.inc

@ -151,7 +151,7 @@ class ShowQtStreamsInFieldSets {
'poster' => array(
'#type' => 'markup',
'#value' => theme('image', "fedora/repository/{$this->pid}/{$pframe->ID}/poster.jpg", '', '', NULL, FALSE)
)
),
'play' => array(
'#type' => 'markup',
'#prefix' => '<div class="play" style="font-size: 128px; color: white; position: absolute; top: 50%; left: 50%; margin-top: -0.085em; margin-left: -0.33em; opacity: 0.9;">',
@ -167,7 +167,7 @@ class ShowQtStreamsInFieldSets {
'#value' => l(t('Download Media File'), "fedora/repository/{$this->pid}/OBJ/MOV.mov", array('attributes' => array('class' => 'download'))),
);
}
$src = url("fedora/repository/{$this->pid}/{$media->ID}/MOV.mov";
$src = url("fedora/repository/{$this->pid}/{$media->ID}/MOV.mov");
$qtparams = "'autostart', '" . ($pframe !== FALSE ? 'TRUE' : 'FALSE') . "', ";
$init = <<<EOD

6
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'),

14
xsl/sparql_to_html.xsl

@ -90,8 +90,6 @@
<xsl:template match="s:result">
<xsl:variable name='OBJECTURI' select="s:object/@uri"/>
<xsl:variable name='CONTENTURI' select="s:content/@uri"/>
<xsl:variable name='CONTENTMODEL' select="substring-after($CONTENTURI,'/')"/>
<xsl:variable name='PID' select="substring-after($OBJECTURI,'/')"/>
<xsl:variable name="newTitle" >
<xsl:call-template name="replace-string">
@ -103,17 +101,9 @@
<xsl:variable name="cleanTitle" select="php:functionString('fedora_repository_urlencode_string', $newTitle)"/>
<xsl:variable name="linkUrl">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $PID, '/-/collection'))"/>
</xsl:when>
<xsl:otherwise>
<!--the below is an example of going straight to a datastream instead of the details page.
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/OBJ/<xsl:value-of select="s:title"/>-->
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $PID))"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="s:content"/>
</xsl:variable>
<td valign="top" width="25%">
<a>

Loading…
Cancel
Save