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. 155
      CollectionClass.inc
  2. 143
      ContentModel.inc
  3. 119
      MimeClass.inc
  4. 33
      ObjectDetails.inc
  5. 57
      ObjectHelper.inc
  6. 62
      PagerSetup.inc
  7. 7
      README
  8. 612
      SearchClass.inc
  9. 3
      api/fedora_collection.inc
  10. 634
      api/fedora_item.inc
  11. 189
      api/fedora_utils.inc
  12. 4
      api/tuque.inc
  13. 2
      collection_policy.xsd
  14. 137
      fedora_repository.api.php
  15. 2
      fedora_repository.info
  16. 236
      fedora_repository.install
  17. 1631
      fedora_repository.module
  18. 93
      fedora_repository.solutionpacks.inc
  19. 161
      fedora_repository.test.inc
  20. 189
      formClass.inc
  21. 4
      object_details_xslts/convertQDC.xsl
  22. 1
      object_details_xslts/mods2html.xsl
  23. 47
      plugins/FedoraObjectDetailedContent.inc
  24. 2
      plugins/ShowStreamsInFieldSets.inc
  25. 2
      plugins/fedora_imageapi.info
  26. 96
      plugins/fits.inc
  27. 2
      plugins/herbarium.inc
  28. 4
      plugins/qt_viewer.inc
  29. 6
      plugins/tagging_form.inc
  30. 14
      xsl/sparql_to_html.xsl

155
CollectionClass.inc

@ -2,10 +2,10 @@
/**
* @file
*
*
* Collection Class Class
*/
/**
* This CLASS caches the streams so once you call a getstream once it will always return
* the same stream as long as you are using the instance of this class. Cached to
@ -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...
*
@ -684,17 +622,18 @@ class CollectionClass {
* An array to be passed to drupal_render, containing a pager, an unordered
* list of items, and another pager.
*/
public static function assembleCollectionView($sparql_results) {
$per_page = 20; //XXX: Make this configurable.
$pager_name = 0;
$total = count($sparql_results);
$pager_page = self::hackPager($pager_name, $per_page, $total);
$max_title_length = 60;
$results = array();
foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) {
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 = fedora_repository_setup_pager($pager_name, $per_page, $total);
$max_title_length = 60;
$results = array();
foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) {
$title = $result['title'];
$truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5);
$truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5);
$obj_path = "fedora/repository/{$result['object']}";
//Get a thumbnail
@ -703,28 +642,28 @@ class CollectionClass {
"$obj_path/TN");
$thumbnail = _fedora_repository_render_image($tn_path);
$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
'attributes' => array(
'class' => 'results-image',
),
)) . l($truncated_title, $obj_path, array('attributes' => array('class' => 'results-text'))),
);
}
if (!$results) {
drupal_set_message(t("No objects in this collection (or bad query)."));
}
else {
$first = $per_page * $pager_page;
$last = (($total - $first) > $per_page)?
($first + $per_page):
$total;
$results_range_text = t('Results @first to @last of @total', array(
'@first' => $first + 1,
'@last' => $last,
'@total' => $total,
$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
'attributes' => array(
'class' => 'results-image',
),
)) . l($truncated_title, $obj_path, array('attributes' => array('class' => 'results-text'))),
);
}
if (!$results) {
drupal_set_message(t("No objects in this collection (or bad query)."));
}
else {
$first = $per_page * $pager_page;
$last = (($total - $first) > $per_page)?
($first + $per_page):
$total;
$results_range_text = t('Results @first to @last of @total', array(
'@first' => $first + 1,
'@last' => $last,
'@total' => $total,
));
return array(
@ -734,15 +673,15 @@ class CollectionClass {
),
array(
'#type' => 'markup',
'#value' => theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
'#value' => theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
))
),
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name)
),
);
);
}
}

143
ContentModel.inc

@ -1,11 +1,11 @@
<?php
/**
* @file
*
* @file
*
*/
/**
* @file
* @file
* Content Model Class
*/
module_load_include('inc', 'fedora_repository', 'XMLDatastream');
@ -56,7 +56,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Ingests a Content Model from a file to the specified pid/dsid .
* Ingests a Content Model from a file to the specified pid/dsid .
* Returns FALSE on failure.
*
* @param string $pid
@ -83,7 +83,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Ingests a Content Model from an existing model to the specified pid/dsid .
* Ingests a Content Model from an existing model to the specified pid/dsid .
* Returns FALSE on failure.
*
* @param string $pid
@ -112,7 +112,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Ingests a minimum Content Model to the specified pid/dsid.
* Ingests a minimum Content Model to the specified pid/dsid.
* Returns FALSE on failure.
*
* @param string $pid
@ -515,7 +515,7 @@ class ContentModel extends XMLDatastream {
* in the form builder if more complex forms or behaviour is required.
* Each element has the following keys: 'label', 'type', 'required', 'description', and if defined, 'authoritative_list' and/or 'parameters'
*
* @return string[] $elements
* @return string[] $elements
*/
public function getIngestFormElements() {
$ret = FALSE;
@ -575,14 +575,14 @@ class ContentModel extends XMLDatastream {
}
/**
* Decrements an ingest form element in the list of elements.
* Decrements an ingest form element in the list of elements.
* Updates the "order". This method is simply an overload to the incIngestFormElement
* which has a direction parameter.
*
* TODO: Might be useful to move multiple places at once, or define
* a method to move to an absolute position.
* TODO: Might be useful to move multiple places at once, or define
* a method to move to an absolute position.
*
* @param String $name
* @param String $name
* @return boolean $success
*/
public function decIngestFormElement($name) {
@ -590,14 +590,14 @@ class ContentModel extends XMLDatastream {
}
/**
* Increments (or decrements) ingest form element in the list of elements.
* Increments (or decrements) ingest form element in the list of elements.
* Updates the "order". The $reorder parameter accepts 'inc' or 'dec' to
* specify the direction to move (defaults to increment.)
*
* TODO: Might be useful to move multiple places at once, or define
* a method to move to an absolute position.
* TODO: Might be useful to move multiple places at once, or define
* a method to move to an absolute position.
*
* @param String $name
* @param String $name
* @param String $reorder
* @return boolean $success
*/
@ -658,7 +658,7 @@ class ContentModel extends XMLDatastream {
/**
* Sets a parameter of an ingest form element. If the value of the element is FALSE the parameter
* will be removed entirely (if you want to store FALSE as a value, then send the String "FALSE").
*
*
* @param String $elementName
* @param String $paramName
* @param String $paramValue
@ -729,7 +729,7 @@ class ContentModel extends XMLDatastream {
/**
* Gets a list of all parameters that belong to the specified ingest form element.
*
*
* @param String $elementName
* @return boolean success
*/
@ -762,7 +762,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Edits the ingest form element specified.
* Edits the ingest form element specified.
* NOTE: The element name can not be changed. To update an elements name
* it must be deleted and added with the new name.
*
@ -854,12 +854,12 @@ class ContentModel extends XMLDatastream {
}
/**
* Decrements an authority list item from a form element in the list of elements.
* Decrements an authority list item from a form element in the list of elements.
* Updates the "order". This method is simply an overload to the incAuthListItem
* which has a direction parameter.
*
* @param String $elementName
* @param String $elementName
* @param String $value
* @return boolean $success
*/
@ -868,10 +868,10 @@ class ContentModel extends XMLDatastream {
}
/**
* Increments (or decrements) an authority list item from a form element in the list of elements.
* Updates the "order".
* Increments (or decrements) an authority list item from a form element in the list of elements.
* Updates the "order".
*
* @param String $elementName
* @param String $elementName
* @param String $value
* @param String $direction
* @return boolean $success
@ -921,7 +921,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Removes an authority list item from a form element.
* Removes an authority list item from a form element.
* @param String $elementName
* @param String $value
* @return boolean $success
@ -966,7 +966,7 @@ class ContentModel extends XMLDatastream {
}
/**
* Adds an authority list item to a form element.
* Adds an authority list item to a form element.
* @param String $elementName
* @param String $value
* @param String $label (optional)
@ -1310,9 +1310,9 @@ class ContentModel extends XMLDatastream {
/**
* Executes the ingest rules that apply to the specified file/mimetype.
* Returns FALSE on failure.
*
* If $preview is TRUE, then only execute rules with
* Returns FALSE on failure.
*
* If $preview is TRUE, then only execute rules with
* a parameter 'preview'. Used to generate previews for the file chooser.
*
* @param string $file
@ -1475,19 +1475,30 @@ class ContentModel extends XMLDatastream {
self::$errors[] = 'Execute Form Handler: file \'' . $path . '\' does not exist.';
}
else {
require_once($path);
$className = $method->getAttribute('class');
$methodName = ($method->getAttribute('method'));
if (!class_exists($className)) {
self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.';
}
else {
$class = new $className($pid);
if (!method_exists($class, $methodName)) {
self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.';
$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)) {
self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.';
}
else {
$output = $class->$methodName($page_number);
$class = new $className($pid);
if (!method_exists($class, $methodName)) {
self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.';
}
else {
$output = $class->$methodName($page_number);
}
}
}
}
@ -1527,8 +1538,8 @@ class ContentModel extends XMLDatastream {
}
/**
* Adds an allowed mimetype to the model.
*
* Adds an allowed mimetype to the model.
*
* @param String $type
* @return boolean $success
*/
@ -1581,7 +1592,7 @@ class ContentModel extends XMLDatastream {
/**
* getDisplayMethods ??
* @param type $ds
* @return type
* @return type
*/
public function getDisplayMethods($ds) {
$ret = FALSE;
@ -1603,7 +1614,7 @@ class ContentModel extends XMLDatastream {
* addDs ??
* @param type $dsid
* @param type $display_in_fieldset
* @return boolean
* @return boolean
*/
public function addDs($dsid, $display_in_fieldset = FALSE) {
$ret = FALSE;
@ -1632,7 +1643,7 @@ class ContentModel extends XMLDatastream {
/**
* removeDs ??
* @param type $dsid
* @return boolean
* @return boolean
*/
public function removeDs($dsid) {
$ret = FALSE;
@ -1648,7 +1659,7 @@ class ContentModel extends XMLDatastream {
/**
* displayInFieldset ??
* @param type $dsid
* @return type
* @return type
*/
public function displayInFieldset($dsid) {
$ret = FALSE;
@ -1662,7 +1673,7 @@ class ContentModel extends XMLDatastream {
* setDisplayInFieldset ??
* @param type $dsid
* @param type $value
* @return boolean
* @return boolean
*/
public function setDisplayInFieldset($dsid, $value = TRUE) {
$ret = FALSE;
@ -1686,7 +1697,7 @@ class ContentModel extends XMLDatastream {
* @param type $file
* @param type $class
* @param type $method
* @return boolean
* @return boolean
*/
public function setDefaultDispMeth($dsid, $module, $file, $class, $method) {
$ret = FALSE;
@ -1725,7 +1736,7 @@ class ContentModel extends XMLDatastream {
* @param type $file
* @param type $class
* @param type $method
* @return boolean
* @return boolean
*/
public function removeDispMeth($dsid, $module, $file, $class, $method) {
$ret = FALSE;
@ -1757,7 +1768,7 @@ class ContentModel extends XMLDatastream {
* @param type $class
* @param type $method
* @param type $default
* @return boolean
* @return boolean
*/
public function addDispMeth($dsid, $module, $file, $class, $method, $default = FALSE) {
$ret = FALSE;
@ -1779,7 +1790,7 @@ class ContentModel extends XMLDatastream {
/**
* getAddDsMethod ??
* @param type $ds
* @return type
* @return type
*/
public function getAddDsMethod($ds) {
$ret = FALSE;
@ -1801,7 +1812,7 @@ class ContentModel extends XMLDatastream {
/**
* getIngestRule ??
* @param type $rule_id
* @return type
* @return type
*/
public function getIngestRule($rule_id) {
$ret = FALSE;
@ -1817,7 +1828,7 @@ class ContentModel extends XMLDatastream {
* removeAppliesTo ??
* @param type $rule_id
* @param type $type
* @return boolean
* @return boolean
*/
public function removeAppliesTo($rule_id, $type) {
$ret = FALSE;
@ -1842,7 +1853,7 @@ class ContentModel extends XMLDatastream {
* addAppliesTo ??
* @param type $rule_id
* @param type $type
* @return boolean
* @return boolean
*/
public function addAppliesTo($rule_id, $type) {
$ret = FALSE;
@ -1871,7 +1882,7 @@ class ContentModel extends XMLDatastream {
* @param type $method
* @param type $dsid
* @param type $modified_files_ext
* @return boolean
* @return boolean
*/
public function addIngestMethod($rule_id, $module, $file, $class, $method, $dsid, $modified_files_ext) {
$ret = FALSE;
@ -1898,7 +1909,7 @@ class ContentModel extends XMLDatastream {
* @param type $file
* @param type $class
* @param type $method
* @return boolean
* @return boolean
*/
public function removeIngestMethod($rule_id, $module, $file, $class, $method) {
$ret = FALSE;
@ -1929,7 +1940,7 @@ class ContentModel extends XMLDatastream {
* @param type $method
* @param type $name
* @param type $value
* @return boolean
* @return boolean
*/
public function addIngestMethodParam($rule_id, $module, $file, $class, $method, $name, $value) {
$ret = FALSE;
@ -1981,7 +1992,7 @@ class ContentModel extends XMLDatastream {
* @param type $class
* @param type $method
* @param type $name
* @return boolean
* @return boolean
*/
public function removeIngestMethodParam($rule_id, $module, $file, $class, $method, $name) {
$ret = FALSE;
@ -2024,7 +2035,7 @@ class ContentModel extends XMLDatastream {
/**
* removeIngestRule ??
* @param type $rule_id
* @return type
* @return type
*/
public function removeIngestRule($rule_id) {
$ret = FALSE;
@ -2043,7 +2054,7 @@ class ContentModel extends XMLDatastream {
* @param type $method
* @param type $dsid
* @param type $modified_files_ext
* @return type
* @return type
*/
public function addIngestRule($applies_to, $module, $file, $class, $method, $dsid, $modified_files_ext) {
$ret = FALSE;
@ -2061,7 +2072,7 @@ class ContentModel extends XMLDatastream {
/**
* getIngestRules ??
* @return type
* @return type
*/
public function getIngestRules() {
$ret = FALSE;
@ -2105,7 +2116,7 @@ class ContentModel extends XMLDatastream {
/**
* getIngestFormAttributes ??
* @return type
* @return type
*/
public function getIngestFormAttributes() {
$ret = FALSE;
@ -2125,7 +2136,7 @@ class ContentModel extends XMLDatastream {
* @param type $page
* @param type $hide_file_chooser
* @param type $redirect
* @return boolean
* @return boolean
*/
public function editIngestFormAttributes($dsid, $page, $hide_file_chooser = FALSE, $redirect = TRUE) {
$ret = FALSE;
@ -2152,7 +2163,7 @@ class ContentModel extends XMLDatastream {
/**
* getIngestFormBuilderMethod
* @return type
* @return type
*/
public function getIngestFormBuilderMethod() {
$ret = FALSE;
@ -2174,7 +2185,7 @@ class ContentModel extends XMLDatastream {
* @param type $class
* @param type $method
* @param type $handler
* @return boolean
* @return boolean
*/
public function editIngestFormBuilderMethod($module, $file, $class, $method, $handler) {
$ret = FALSE;
@ -2192,7 +2203,7 @@ class ContentModel extends XMLDatastream {
/**
* Find the form element with name $name.
*
*
* @param string $name
* The name of the form element to find.
* @return DOMElement
@ -2263,7 +2274,7 @@ class ContentModel extends XMLDatastream {
*
* @param string $name
* Name of the form to remove.
*
*
* @return boolean
* TRUE on success, FALSE otherwise.
*/

119
MimeClass.inc

@ -6,26 +6,27 @@
* @file
* This class inspired by Chris Jean's work, here:
* http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/
*
* It does some MIME trickery, inspired by the need to to deal with Openoffice
* and MS Office 2007 file formats -- which are often mis-interpreted by
*
* It does some MIME trickery, inspired by the need to to deal with Openoffice
* and MS Office 2007 file formats -- which are often mis-interpreted by
* mime-magic, fileinfo, and the *nix `file` command.
*
* In Drupal 6, we also make use of file_get_mimetype. See:
* In Drupal 6, we also make use of file_get_mimetype. See:
* http://api.drupal.org/api/function/file_get_mimetype/6
* ... however this only provides a uni-directional lookup (ext->mime).
* While I don't have a specific use case for a mime->extension lookup, I think
* it's good to have in here.
*
*
* Drupal 7 will have better mime handlers. See:
* 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
/*
* This is a shortlist of mimetypes which should catch most
* mimetype<-->extension lookups in the context of Islandora collections.
*
* It has been cut from a much longer list.
@ -33,26 +34,26 @@ class MimeClass {
* Two types of mimetypes should be put in this list:
* 1) Special emerging formats which may not yet be expressed in the system
* mime.types file.
* 2) Heavily used mimetypes of particular importance to the Islandora
* project, as lookups against this list will be quicker and less
* 2) Heavily used mimetypes of particular importance to the Islandora
* 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...
* e.g...
* "jpeg" => "image/jpeg",
* "jpe" => "image/jpeg",
* "jpg" => "image/jpeg",
*
*
* $this->get_extension('image/jpeg') will always return 'jpg'.
*
*/
@ -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,15 +186,18 @@ 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",
"gtar" => "application/x-gtar",
"zip" => "application/x-zip",
// others:
// 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';
}
@ -216,7 +223,7 @@ class MimeClass {
* for backwards-compatibility with our old mimetype class.
*
* @param type $filename
* @return type
* @return type
*/
public function getType($filename) {
return $this->get_mimetype($filename);
@ -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';
}
@ -267,34 +281,38 @@ class MimeClass {
*
* @param type $mime_type
* @param type $debug
* @return type
* @return type
*/
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';
}
/**
* function: system_mime_type_extensions
* description: populates an internal array of mimetype/extension associations
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* return: array of mimetype => extension
*/
private function system_mime_type_extensions() {
@ -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);
@ -322,8 +343,8 @@ class MimeClass {
/**
* function: system_mime_type_extensions
* description: populates an internal array of mimetype/extension associations
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* return: array of extension => mimetype
*/
private function system_extension_mime_types() {
@ -332,15 +353,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);
foreach ($parts as $part)
foreach ($parts as $part) {
$out[$part] = $type;
}
}
fclose($file);
}
@ -348,4 +372,3 @@ class MimeClass {
}
}

33
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;
$xsl_file = variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl');
if (!$default_to_dc) {
$xsl_file = variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl');
}
else {
$xsl_file = 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl';
}
// set an error message in case xslt parsing fails
$output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file));
if (is_readable($xsl_file)) {
@ -126,7 +137,11 @@ function fedora_repository_object_details_table($item) {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
}
$xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr) && variable_get('islandora_object_details_table_default_dc', FALSE) && $dsid != 'DC' && $dsid != 'QDC') {
$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');
}

57
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,7 +178,10 @@ 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']) {
drupal_set_header("Content-Type: $mimeType");
@ -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();
}

634
api/fedora_item.inc

File diff suppressed because it is too large Load Diff

189
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
*
* @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);
@ -29,16 +29,16 @@ if (!function_exists('str_getcsv')) {
}
/**
*
*
* Utility method to get data from a url location using curl_exec and return
*
*
* This method takes identical parameters to do_curl_ext and passes them
* directly to do_curl_ext. The output from do_curl_ext is processed into
* either a TRUE, FALSE, or NULL value.
*
*
* This method exists for historical reasons as existing code makes use of
* do_curl directly and expects a simple return value and not an array.
*
*
* @param $url
* URL to be accessed by the function
* @param $return_to_variable
@ -49,8 +49,8 @@ if (!function_exists('str_getcsv')) {
* Number of variable sot be posted
* @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,18 +59,17 @@ 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
* structure required to make a call to curl_exec. As a part of the
* initialization the permissions associated with the (global) user are added
* to the call. This ensures access to any potentially user restricted URLs.
*
*
* 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,
@ -80,8 +79,8 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* Number of variable sot be posted
* @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,8 +183,10 @@ function fix_encoding($in_str) {
/**
* valid pid ??
*
* @param type $pid
* @return boolean
*
* @return boolean
*/
function valid_pid($pid) {
$valid = FALSE;
@ -190,8 +199,10 @@ function valid_pid($pid) {
/**
* Valid Dsid ??
*
* @param type $dsid
* @return boolean
*
* @return boolean
*/
function valid_dsid($dsid) {
$valid = FALSE;
@ -204,8 +215,10 @@ function valid_dsid($dsid) {
/**
* fixDsid ??
*
* @param type $dsid
* @return string
*
* @return string
*/
function fix_dsid($dsid) {
$new_dsid = trim($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');
@ -244,7 +259,7 @@ function get_collections_as_option_array() {
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$options = array(
'type' => 'tuples',
'flush' => 'TRUE',
@ -254,9 +269,9 @@ 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);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
@ -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,46 +299,75 @@ 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');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[] = trim($namespace);
}
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[] = trim($namespace);
}
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks
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];
}
}
}
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
// 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];
}
}
}
}
return $options;
}
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()) {

2
collection_policy.xsd

@ -45,4 +45,4 @@
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
</xsd:schema>

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

236
fedora_repository.install

@ -1,106 +1,134 @@
<?php
/**
* @file fedora_repository.install
*/
/**
* Implementation of hook_enable().
*/
function fedora_collections_enable() {
//nothing to do as we do not currently touch the drupal database.
//other than the variables table
}
/**
* Implementation of hook_requirements().
*
* @return
* An array describing the status of the site regarding available updates.
* If there is no update data, only one record will be returned, indicating
* that the status of core can't be determined. If data is available, there
* will be two records: one for core, and another for all of contrib
* (assuming there are any contributed modules or themes enabled on the
* site). In addition to the fields expected by hook_requirements ('value',
* 'severity', and optionally 'description'), this array will contain a
* 'reason' attribute, which is an integer constant to indicate why the
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
* notification messages during update_cron(), and might be useful for other
* modules that invoke update_requirements() to find out if the site is up
* to date or not.
*
* @see _update_message_text()
* @see _update_cron_notify()
*/
function fedora_repository_requirements($phase) {
$requirements = array();
$t = get_t(); //May not have access to the regular t() function; and so Drupal provides...
if ($phase == 'install') {
// Test for SOAP
$requirements['fedora-soap']['title'] = $t("PHP SOAP extension library");
if (!class_exists('SoapClient')) {
$requirements['fedora-soap']['value'] = $t("Not installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-soap']['description'] = $t('Ensure that the PHP SOAP extension is installed.');
}
else {
$requirements['fedora-soap']['value'] = $t("Installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK;
}
// Test for Curl
$requirements['curl']['title'] = $t('PHP Curl extension library');
if (!function_exists('curl_init')) {
$requirements['curl']['value'] = $t("Not installed");
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
$requirements['curl']['description'] = $t("Ensure that the PHP Curl extension is installed.");
}
else {
$requirements['curl']['value'] = $t("Installed");
$requirements['curl']['severity'] = REQUIREMENT_OK;
}
<?php
/**
* @file fedora_repository.install
*/
/**
* Implementation of hook_enable().
*/
function fedora_collections_enable() {
//nothing to do as we do not currently touch the drupal database.
//other than the variables table
}
/**
* Implementation of hook_requirements().
*
* @return
* An array describing the status of the site regarding available updates.
* If there is no update data, only one record will be returned, indicating
* that the status of core can't be determined. If data is available, there
* will be two records: one for core, and another for all of contrib
* (assuming there are any contributed modules or themes enabled on the
* site). In addition to the fields expected by hook_requirements ('value',
* 'severity', and optionally 'description'), this array will contain a
* 'reason' attribute, which is an integer constant to indicate why the
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
* notification messages during update_cron(), and might be useful for other
* modules that invoke update_requirements() to find out if the site is up
* to date or not.
*
* @see _update_message_text()
* @see _update_cron_notify()
*/
function fedora_repository_requirements($phase) {
$requirements = array();
$t = get_t(); //May not have access to the regular t() function; and so Drupal provides...
if ($phase == 'install') {
// Test for SOAP
$requirements['fedora-soap']['title'] = $t("PHP SOAP extension library");
if (!class_exists('SoapClient')) {
$requirements['fedora-soap']['value'] = $t("Not installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-soap']['description'] = $t('Ensure that the PHP SOAP extension is installed.');
}
else {
$requirements['fedora-soap']['value'] = $t("Installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK;
}
// Test for Curl
$requirements['curl']['title'] = $t('PHP Curl extension library');
if (!function_exists('curl_init')) {
$requirements['curl']['value'] = $t("Not installed");
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
$requirements['curl']['description'] = $t("Ensure that the PHP Curl extension is installed.");
}
else {
$requirements['curl']['value'] = $t("Installed");
$requirements['curl']['severity'] = REQUIREMENT_OK;
}
// Test for DOM
$requirements['dom']['title'] = $t("PHP DOM XML extension library");
if (!method_exists('DOMDocument', 'loadHTML')) {
$requirements['dom']['value'] = $t("Not installed");
$requirements['dom']['severity'] = REQUIREMENT_ERROR;
$requirements['dom']['description'] = $t("Ensure that the PHP DOM XML extension is installed.");
}
else {
$requirements['dom']['value'] = $t("Installed");
$requirements['dom']['severity'] = REQUIREMENT_OK;
}
// Test for XSLT
$requirements['xsl']['title'] = $t("PHP XSL extension library");
if (!class_exists('XSLTProcessor')) {
$requirements['xslt']['value'] = $t("Not installed");
$requirements['xslt']['severity'] = REQUIREMENT_ERROR;
$requirements['xslt']['description'] = $t("Ensure that the PHP XSL extension is installed.");
}
else {
$requirements['xslt']['value'] = $t("Installed");
$requirements['xslt']['severity'] = REQUIREMENT_OK;
}
}
elseif ($phase == 'runtime') {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$requirements['fedora-repository']['title'] = $t("Fedora server");
if (!fedora_available()) {
$requirements['fedora-repository']['value'] = $t("Not available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => url('admin/settings/fedora_repository')));
}
else {
$requirements['fedora-repository']['value'] = $t("Available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK;
}
}
return $requirements;
}
if (!method_exists('DOMDocument', 'loadHTML')) {
$requirements['dom']['value'] = $t("Not installed");
$requirements['dom']['severity'] = REQUIREMENT_ERROR;
$requirements['dom']['description'] = $t("Ensure that the PHP DOM XML extension is installed.");
}
else {
$requirements['dom']['value'] = $t("Installed");
$requirements['dom']['severity'] = REQUIREMENT_OK;
}
// Test for XSLT
$requirements['xsl']['title'] = $t("PHP XSL extension library");
if (!class_exists('XSLTProcessor')) {
$requirements['xslt']['value'] = $t("Not installed");
$requirements['xslt']['severity'] = REQUIREMENT_ERROR;
$requirements['xslt']['description'] = $t("Ensure that the PHP XSL extension is installed.");
}
else {
$requirements['xslt']['value'] = $t("Installed");
$requirements['xslt']['severity'] = REQUIREMENT_OK;
}
}
elseif ($phase == 'runtime') {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$requirements['fedora-repository']['title'] = $t("Fedora server");
if (!fedora_available()) {
$requirements['fedora-repository']['value'] = $t("Not available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => url('admin/settings/fedora_repository')));
}
else {
$requirements['fedora-repository']['value'] = $t("Available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK;
}
}
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'),
);
}

1631
fedora_repository.module

File diff suppressed because it is too large Load Diff

93
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,18 +54,27 @@ 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()) {
// Check each object to see if it is in the repository.
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_path;
$needs_update = FALSE;
$needs_install = FALSE;
$form = array();
$form['solution_pack_module'] = array(
'#type' => 'hidden',
'#value' => $solution_pack_module,
@ -161,14 +182,20 @@ 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'),
'file' => drupal_get_path('module', 'fedora_repository') . '/fedora_repository.module',
@ -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");
}
}

189
formClass.inc

@ -1,7 +1,5 @@
<?php
/**
* @file
* formClass class
@ -18,7 +16,7 @@ class formClass {
/**
* Create the paths for urls and map them to php functions
* @return array
* @return array
*/
function createMenu() {
$items = array();
@ -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,91 +89,56 @@ 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')
);
$items['fedora/repository/editmetadata'] = array(
'title' => t('Edit metadata'),
'page callback' => 'fedora_repository_edit_qdc_page',
'type' => MENU_CALLBACK,
'access arguments' => array('edit fedora meta data')
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('edit fedora meta data', 3)
);
$items['fedora/repository/purgeStream'] = array(
'title' => t('Purge data stream'),
'page callback' => 'fedora_repository_purge_stream',
'type' => MENU_CALLBACK,
'access arguments' => array('purge objects and datastreams')
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('purge objects and datastreams', 3)
);
$items['fedora/repository/replaceStream'] = array(
'title' => t('Replace Stream'),
'page callback' => 'fedora_repository_replace_stream',
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams'),
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('add fedora datastreams', 3),
);
$items['fedora/repository/purgeObject'] = array(
'title' => t('Purge object'),
'page callback' => 'fedora_repository_purge_object',
'type' => MENU_CALLBACK,
'access arguments' => array('purge objects and datastreams')
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('purge objects and datastreams', 3)
);
$items['fedora/repository/addStream'] = array(
'title' => t('Add stream'),
'page callback' => 'add_stream',
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams')
'access callback' => 'fedora_repository_check_perm',
'access arguments' => array('add fedora datastreams', 3)
);
//new for mnpl******************************************
$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(
'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(
@ -194,7 +163,7 @@ class formClass {
/**
* Create admin form
* @return array
* @return array
*/
function createAdminForm() {
if (!user_access('administer site configuration')) {
@ -221,7 +190,7 @@ class formClass {
'#required' => TRUE,
'#weight' => -16,
);
$form['fedora_repository_url'] = array(
'#type' => 'textfield',
@ -230,16 +199,16 @@ class formClass {
'#description' => t('The url of the Fedora server'), '#required' => TRUE,
'#weight' => -14
);
$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,
'#suffix' => '<p>' . (
fedora_available() ?
fedora_available() ?
theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) :
theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '</p>',
);
@ -347,7 +316,7 @@ class formClass {
'#default_value' => variable_get('fedora_object_restrict_datastreams', FALSE),
'#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'),
);
$form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array(
'#type' => 'checkbox',
'#title' => t('Allow imagecache_external use for thumbnails in collection view'),
@ -355,14 +324,14 @@ class formClass {
'#description' => t('If enabled, the default collection list view (or ' .
'anywhere the function "@function" is used) will try to use ' .
'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' .
'be updated to use this function.',
'be updated to use this function.',
array(
'@function' => '_fedora_repository_render_image()',
'@preset' => 'fedora_repository_collection_thumbnail',
'@xsl' => 'sparql_to_html.xsl',
)),
);
$form['advanced']['fedora_control_group_control_during_ingest'] = array(
'#type' => 'checkbox',
'#title' => t('Allow control groups select in datastream ingest'),
@ -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,
);
@ -390,7 +375,7 @@ class formClass {
* @param type $form_id
* @param type $form_values
* @param type $client
* @return type
* @return type
*/
function updateMetaData($form_id, $form_values, $client) {
// ======================================
@ -409,13 +394,13 @@ class formClass {
// DC elements
$previousElement = NULL; // Used in case we have to nest elements for qualified dublin core.
$label = null;
foreach ($form_values as $key => $value) {
//echo ($key);
if ($key == 'dc:title-0') {
$label = $value;
}
}
$index = strrpos($key, '-');
$key = substr($key, 0, $index);
$test = substr($key, 0, 2);
@ -441,8 +426,8 @@ class formClass {
{
$object = new Fedora_Item($form_values['pid']);
$object->modify_object($label);
}
}
$dom->appendChild($oai);
if (!$client) {
@ -472,7 +457,7 @@ class formClass {
* to determine if this user is allowed to ingest in this collection
* we assume if they are able to modify objects in the collection they can ingest as well.
* @param type $collection_pid
* @return type
* @return type
*/
function can_ingest_here($collection_pid) {
module_load_include('inc', 'fedora_repository', 'SecurityClass');
@ -483,12 +468,16 @@ class formClass {
/**
* Drupal's permissions at this point no xacml yet. xacml decisions are made by fedora
* @param type $collection_pid
* @return type
* @return type
*/
function canShowIngestForm($collection_pid) {
if (!user_access('ingest new fedora objects')) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return FALSE;
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();
@ -508,11 +497,11 @@ class formClass {
/**
* Creates the first page of the ingest form for editing QDC.
*
*
* @param string $collection_pid
* @param string $collection_label
* @param array $form_state
*
*
* @return array
*/
function createQDCIngestFormPageOne($collection_pid, $collection_label, array &$form_state) {
@ -558,11 +547,11 @@ class formClass {
/**
* Create the second page of the ingest form for editing QDC
*
*
* @param string $collection_pid
* @param string $collection_label
* @param array $form_state
*
*
* @return array
*/
function createQDCIngestFormPageTwo($collection_pid, $collection_label, array &$form_state) {
@ -593,11 +582,11 @@ class formClass {
/**
* Create the QDC Ingest Form.
*
*
* @param type $collection_pid
* @param type $collection_label
* @param array $form_state
*
* @param array $form_state
*
* @return array
*/
function createQDCIngestForm($collection_pid, $collection_label, array &$form_state) {
@ -613,18 +602,18 @@ class formClass {
/**
* Create a multi step form (wizard) for ingesting objects into Fedora
*
*
* @param string $collection_pid
* @param string $collection_label
* @param array $form_state
*
* @return array
*
* @return array
*/
function createIngestForm($collection_pid, $collection_label, array &$form_state) {
if (!$this->canShowIngestForm($collection_pid)) {
return FALSE;
}
drupal_set_title($collection_label);
if (module_exists('islandora_content_model_forms')) {
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
@ -643,7 +632,7 @@ class formClass {
* this function may not be being used
* @param type $pid
* @param type $form_state
* @return string
* @return string
*/
function createAddDataStreamForm($pid, &$form_state) {
//dump_vars($form_state);
@ -723,7 +712,7 @@ class formClass {
// '#required'=>'TRUE',
'#description' => t('The file to upload. (Only for Managed and Inline)')
);
if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
$form['fieldset']['ds_reference'] = array(
'#type' => 'textfield',
@ -732,7 +721,7 @@ class formClass {
'#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'),
);
}
$form['#redirect'] = "fedora/repository/$pid/";
$form['fieldset']['submit'] = array(
'#type' => 'submit',
@ -758,7 +747,7 @@ class formClass {
'#weight' => -1,
);
}
if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
$form['fieldset']['control_group'] = array(
'#type' => 'select',
@ -778,13 +767,13 @@ class formClass {
/**
* Create QDC Edit form.
*
*
* @param string $pid
* @param string $dsid
* @param object $client
* @param array $form_state
*
* @return string
*
* @return string
*/
function createQDCEditForm($pid, $dsid, $client, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -869,7 +858,7 @@ class formClass {
* @param type $dsid
* @param type $client
* @param boolean $form_state
* @return type
* @return type
*/
function createMetaDataForm($pid, $dsid, $client, &$form_state) {
if (module_exists('islandora_content_model_forms')) {
@ -890,13 +879,13 @@ class formClass {
* @param type $dsId
* @param type $dsLabel
* @param type $form_state
* @return type
* @return type
*/
function createReplaceDataStreamForm($pid, $dsId, $dsLabel, &$form_state) {
$form = array();
$form['#attributes']['enctype'] = 'multipart/form-data';
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$info = $item->get_datastream_info($dsId);
@ -922,7 +911,7 @@ class formClass {
'#value' => t('If both a file and a reference are given, the file will be given preference.'),
);
}
$form['pid'] = array(
'#type' => 'value',
'#value' => $pid,

4
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()"/>
@ -30,4 +30,4 @@
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

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/-->

47
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)) {
$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 (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'),
);
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