Browse Source

Merge branch '6.x' of https://github.com/Islandora/islandora into 6.x

pull/147/head
Alan Stanley 13 years ago
parent
commit
06f4a0d335
  1. 82
      CollectionClass.inc
  2. 143
      ContentModel.inc
  3. 1
      MimeClass.inc
  4. 3
      ObjectHelper.inc
  5. 74
      api/fedora_item.inc
  6. 45
      plugins/FedoraObjectDetailedContent.inc

82
CollectionClass.inc

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

143
ContentModel.inc

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

1
MimeClass.inc

@ -133,6 +133,7 @@ class MimeClass {
'xht' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xml', 'xsl' => 'text/xml',
'xslt' => 'text/xml',
'xml' => 'text/xml', 'xml' => 'text/xml',
'csv' => 'text/csv', 'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values', 'tsv' => 'text/tab-separated-values',

3
ObjectHelper.inc

@ -137,9 +137,6 @@ class ObjectHelper {
$fedoraPass = $user->pass; $fedoraPass = $user->pass;
} }
$dataStreamInfo = $item->get_datastream_info($dsID);
$contentSize = $dataStreamInfo->datastream->size;
if (function_exists("curl_init")) { if (function_exists("curl_init")) {
$url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content'; $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content';
$query_options = array(); $query_options = array();

74
api/fedora_item.inc

@ -347,7 +347,10 @@ RDF;
$modified = FALSE; $modified = FALSE;
$rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship); $rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship);
if (!empty($rels)) { if (!empty($rels)) {
foreach ($rels as $rel) { // iterate backwards so if we delete something our pointer doesn't get out of sync
for ($i = $rels->length; $i>0; $i--) {
$rel = $rels->item($i-1);
// foreach ($rels as $rel) { // moving forward like this caused iteration errors when something was deleted
if ( //If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed. if ( //If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed.
empty($object) || empty($object) ||
(($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || (($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) ||
@ -986,6 +989,54 @@ RDF;
return self::soap_call('modifyObject', $params, $quiet); return self::soap_call('modifyObject', $params, $quiet);
} }
/**
* Work around function, due to file_create_url not URL encoding stuff.
*
* Parses and reassembles the URL, exploding, rawurlencoding and imploding
* the path components along the way.
*
* @param $url
* A string containing an HTTP(S) URL to attempt.
* @return string
* The results of the HTTP request if successful; boolean FALSE otherwise.
*/
protected static function try_http_get_content($url) {
//Can throw a warning prior to 5.3.3
$parsed_url = @parse_url($url);
$supported_schemes = array(
'http',
'https'
);
$content = FALSE;
if ($parsed_url && array_key_exists('scheme', $parsed_url) && in_array($parsed_url['scheme'], $supported_schemes)) {
$components = explode('/', $parsed_url['path']);
$components = array_map('rawurlencode', $components);
$result = drupal_http_request(
url(
t('!scheme://!user:!pass@!host:!port/!path', array(
'!scheme' => $parsed_url['scheme'],
'!user' => rawurlencode($parsed_url['user']),
'!pass' => rawurlencode($parsed_url['pass']),
'!host' => $parsed_url['host'],
'!path' => implode('/', $components),
)),
array(
'query' => $parsed_url['query'],
'fragment' => $parsed_url['fragment'],
)
)
);
if ((int)($result->code / 100) === 2) {
$content = $result->data;
}
}
return $content;
}
/** /**
* Wrap modify by value and reference * Wrap modify by value and reference
* *
@ -1011,7 +1062,7 @@ RDF;
*/ */
function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) { function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) {
$toReturn = NULL; $toReturn = NULL;
//Determine if it's inline xml; if it is, modify by value //Determine if it's inline xml; if it is, modify by value
if ($this->get_datastream($dsid)->controlGroup === 'X') { if ($this->get_datastream($dsid)->controlGroup === 'X') {
$content = '<null/>'; $content = '<null/>';
@ -1019,7 +1070,15 @@ RDF;
$content = file_get_contents($filename_or_content); $content = file_get_contents($filename_or_content);
} }
else { else {
$content = $filename_or_content; //XXX: Get the contents to deal with fopen not being allowed for remote access
// in some OSs
$temp_content = self::try_http_get_content($filename_or_content);
if ($temp_content !== FALSE) {
$content = $temp_content;
}
else {
$content = $filename_or_content;
}
} }
$toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); $toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage);
@ -1036,8 +1095,15 @@ RDF;
$created_temp = ($original_path != $file); $created_temp = ($original_path != $file);
} }
else { else {
//XXX: Get the contents to deal with fopen not being allowed for remote access
// in some OSs
$temp_content = self::try_http_get_content($filename_or_content);
if ($temp_content !== FALSE) {
$filename_or_content = $temp_content;
}
//Push contents to a web-accessible file //Push contents to a web-accessible file
$file = file_save_data($filename_or_content, file_directory_path()); $file = file_save_data($filename_or_content, file_create_filename($label, file_directory_path()));
$created_temp = TRUE; $created_temp = TRUE;
} }

45
plugins/FedoraObjectDetailedContent.inc

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

Loading…
Cancel
Save