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
3d226bec86
  1. 1
      .gitignore
  2. 161
      CollectionClass.inc
  3. 4
      MimeClass.inc
  4. 276
      ObjectDetails.inc
  5. 508
      ObjectHelper.inc
  6. 1
      api/fedora_export.inc
  7. 128
      api/fedora_item.inc
  8. 23
      api/fedora_utils.inc
  9. 115
      api/tuque.inc
  10. 500
      fedora_repository.module
  11. 207
      formClass.inc
  12. 0
      object_details_xslts/convertQDC.xsl
  13. 232
      object_details_xslts/mods2html.xsl
  14. 25
      plugins/FedoraObjectDetailedContent.inc
  15. 3
      plugins/tagging_form.inc
  16. 34
      xsl/convertQDC.xsl.deprecated
  17. 31
      xsl/sparql_to_html.xsl

1
.gitignore vendored

@ -0,0 +1 @@
nbproject

161
CollectionClass.inc

@ -28,11 +28,9 @@ class CollectionClass {
* @return CollectionClass
*/
function __construct($pid = NULL) {
if (!empty($pid)) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$this->collectionObject = new ObjectHelper($pid);
$this->pid = $pid;
}
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$this->collectionObject = new ObjectHelper();
$this->pid = $pid;
}
public static function getCollectionQuery($pid) {
@ -535,16 +533,12 @@ class CollectionClass {
function showFieldSets($page_number) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
//module_load_include('inc', 'fedora_repository', 'BatchIngest'); //Legacy code?
global $base_url;
global $user;
$tabset = array();
$query = NULL;
$query = self::getCollectionQuery($this->pid);
$item = new Fedora_Item($this->pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$query = $item->get_datastream_dissemination('QUERY');
}
$results = $this->getRelatedItems($this->pid, $query);
$collection_items = $this->renderCollection($results, $this->pid, NULL, NULL, $page_number);
@ -672,6 +666,86 @@ class CollectionClass {
return $page;
}
/**
* Assemble results in a somewhat more logical manner...
*
* ... Compared to generating a table in XSLT to contain a list (as
* renderCollection() used to do/does by default).
*
* @param $sparql_results array
* The array of results as yielded by ObjectHelper::parseSparqlResults()
* (and those associated functions which make use of it).
* Each result must contain:
* - 'object': The PID/URI of the child object.
* - 'title': A title for the child object.
* and may contain:
* - 'thumbnail': URI to a datastream. (will default to the 'TN' stream on the child)
* @return
* 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) {
$title = $result['title'];
$truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5);
$obj_path = "fedora/repository/{$result['object']}";
//Get a thumbnail
$tn_path = ($result['thumbnail'] ?
"fedora/repository/{$result['thumbnail']}":
"$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,
));
return array(
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name),
),
array(
'#type' => 'markup',
'#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)
),
);
}
}
/**
* render collection
* @global type $base_url
@ -685,17 +759,8 @@ class CollectionClass {
function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository');
global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe
$parsedContent = NULL;
if(!isset($this->collectionObject)){
$this->collectionObject = new ObjectHelper($pid);
}
$contentModels = $this->collectionObject->get_content_models_list($pid);
$isCollection = FALSE;
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.
$fedoraItem = NULL;
if (empty($collectionName)) {
$collectionName = menu_get_active_title();
@ -706,48 +771,13 @@ class CollectionClass {
$objectList = '';
if (isset($content) && $content != FALSE) {
if (!$xslContent) { //Didn't find an XSLT.
$intermediate_results = ObjectHelper::parse_sparql_results($content);
unset($content);
$per_page = 20; //XXX: Make this configurable.
$pager_name = 0;
$total = count($intermediate_results);
$pager_page = self::hackPager($pager_name, $per_page, $total);
$results = array();
foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) {
$title = $result['title'];
$obj_path = "fedora/repository/{$result['object']}";
$thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE);
$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
'attributes' => array(
'class' => 'results-image',
),
)) . l($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,
));
//$objectList = '<h3>' . $results_range_text . '</h3>';
$objectList .= theme('pager', array(), $per_page, $pager_name);
$objectList .= theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
));
$objectList .= theme('pager', array(), $per_page, $pager_name);
}
return drupal_render(
self::assembleCollectionView(
$this->collectionObject->parseSparqlResults(
$content
)
)
);
}
else {
if (!$pageNumber) {
@ -762,7 +792,7 @@ class CollectionClass {
try {
$proc = new XsltProcessor();
$options = array( //Could make this the return of a hook?
'collectionPid' => $collection_pid,
'collectionPid' => $pid,
'collectionTitle' => $collectionName,
'baseUrl' => $base_url,
'path' => "$base_url/$path",
@ -774,10 +804,7 @@ class CollectionClass {
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$xsl->loadXML($xslContent);
// php xsl does not seem to work with namespaces so removing it below
// I may have just been being stupid here
// $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content);
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);

4
MimeClass.inc

@ -231,9 +231,7 @@ class MimeClass {
* @return type
*/
public function get_mimetype($filename, $debug = FALSE) {
$file_name_and_extension = explode('.', $filename);
$ext = strtolower(array_pop($file_name_and_extension));
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
if (!empty($this->private_mime_types[$ext])) {
if (TRUE === $debug)

276
ObjectDetails.inc

@ -0,0 +1,276 @@
<?php
/**
* @file ObjectDetails.inc
* The functions required to define and respond to all the default object
* details display modes.
*/
/**
* Islandora core object details display modes. These are the default display
* modes that are always available.
* @return A list of display modes that can be used to render the object details
* page.
*/
function fedora_repository_islandora_object_details_display() {
$profiles = array(
'hidden' => array(
"name" => "Hidden",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_hidden",
"description" => t("No object details page"),
),
'xslt' => array(
"name" => "XSLT",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_xslt",
"description" => t("Show a datastream with an XSLT"),
"config" => "admin/settings/fedora_repository/object_details_xslt",
),
'table' => array(
"name" => "Table",
"module" => "fedora_repository",
"file" => "ObjectDetails.inc",
"function" => "fedora_repository_object_details_table",
"description" => t("Show a datastream with a table"),
"config" => "admin/settings/fedora_repository/object_details_table",
)
);
return $profiles;
}
/**
* The renderer for the "hidden" display mode. In this mode, no data is
* displayed. This is supplied so you can disable the object details metadata
* display without disabling the tab entirely.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_hidden($item) {
// do nothing
return "";
}
/**
* The renderer for the "xslt" display mode. In this mode, an xslt is applied
* to the selected datastream to produce a user defined look and feel to the
* output data.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_XSLT($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$dsid = variable_get('islandora_object_details_xslt_datastream', 'DC');
// special case for DC+QDC for backward compatibility
if ($dsid == 'DC' || $dsid == 'QDC') {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : '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));
}
try {
$proc = new XsltProcessor();
} catch (Exception $e) {
watchdog('fedora_repository', "Error while creating XSLT processor: @e", array('@e' => $e->getMessage()), WATCHDOG_ERROR);
return;
}
$proc->setParameter('', 'baseUrl', $base_url);
$proc->setParameter('', 'path', $path);
$input = NULL;
$xsl_file = variable_get('islandora_object_details_xslt_sheet', '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)) {
$xsl = new DomDocument();
$input = new DomDocument();
try {
$xsl->load($xsl_file);
$input->loadXML(trim($xmlstr));
} catch (Exception $e) {
watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR);
}
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
$output = $newdom->saveHTML();
}
return $output;
}
/**
* The renderer for the "table" display mode. In this mode, the requested
* datastream is rendered using a simple table with keys(tags) on the left and
* values on the right.
* @param item The item with the metadata to display.
* @return The fully composed object details metadata display.
*/
function fedora_repository_object_details_table($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$dsid = variable_get('islandora_object_details_table_datastream', 'DC');
// special case for DC+QDC for backward compatibility
if ($dsid == 'DC' || $dsid == 'QDC') {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : '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));
}
$simplexml = new SimpleXMLElement($xmlstr);
$headers = array(
array(
'data' => t('Metadata'),
'colspan' => 2,
),
);
$rows = array();
foreach ($simplexml->getNamespaces(TRUE) as $ns) {
foreach ($simplexml->children($ns) as $child) {
$rows[] = array(
array(
'data' => $child->getName(),
'class' => 'dc-tag-name',
),
array(
'data' => (string)$child,
'class' => 'dc-content',
),
);
}
}
return theme('table', $headers, $rows, array('class' => 'dc-table'));
}
/**
* Configuration page for the xslt display mode.
*
* This mode requires two parameters: the datastream to render, and the xslt to
* apply to it.
*
* @return
* The configuration page.
*/
function fedora_repository_object_details_XSLT_config() {
$form = array();
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t("XSLT display options"),
);
$options = module_invoke_all("object_details_get_available_xslts");
$form['config']['xslt'] = array(
'#type' => 'select',
'#title' => t("XSL transform to use"),
'#default_value' => variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'),
'#options' => $options,
'#key_type' => 'associative',
'#required' => TRUE,
);
$form['config']['dsid'] = array(
'#type' => 'textfield',
'#title' => t("Datastream to transform"),
'#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Submit"),
'#weight' => 1,
);
return $form;
}
/**
* Custom submit handler for the xslt configuration page.
*
* @param $form
* @param &$form_state
* The user supplied values for the form.
*/
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']);
drupal_set_message('Object Details view has been set to XSLT and your configuration has been saved');
}
/**
* Base function to supply the available xslt files.
*
* Modules implementing this hook need to return an array describing where the
* XSLT is. The array key is the path to the XSLT (paths start with sites/) and
* the value in the array is the display name. In the simplest form you can use
* file_scan_directory like we do here - this puts the filename as the display
* name and will automatically detect new files as they are added.
*/
function fedora_repository_object_details_get_available_xslts() {
$folder = drupal_get_path("module", "fedora_repository") ."/object_details_xslts/";
// retrieve the filenames from the system
$xslts = file_scan_directory($folder, ".xsl");
$options = array();
foreach ($xslts as $xsl) {
$options[$xsl->filename] = $xsl->basename;
}
return $options;
}
/**
* Configuration page for the table display mode. This mode requires only one
* parameter: the datastream to render.
*
* @return
* The configuration page.
*/
function fedora_repository_object_details_table_config() {
$form = array();
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t("Table display options"),
);
$form['config']['dsid'] = array(
'#type' => 'textfield',
'#title' => t("Datastream to transform"),
'#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Submit"),
'#weight' => 1,
);
return $form;
}
/**
* Custom submit handler for the table configuration page.
*
* @param $form
* @param &$form_state
* The user supplied values for the form.
*/
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']);
drupal_set_message('Object Details view has been set to Table and your configuration has been saved');
}

508
ObjectHelper.inc

@ -2,7 +2,7 @@
/**
* @file
* @file
* Object Helper Class
*/
@ -19,9 +19,7 @@ class ObjectHelper {
public static $INGEST_FEDORA_OBJECTS = 'ingest new fedora objects';
public static $EDIT_TAGS_DATASTREAM = 'edit tags datastream';
public static $VIEW_DETAILED_CONTENT_LIST = 'view detailed list of content';
public static $DISPLAY_ALWAYS = 0;
public static $DISPLAY_NEVER = 1;
public static $DISPLAY_NO_MODEL_OUTPUT = 2;
// TODO: Make this into a static member constant
public $availableDataStreamsText = 'Detailed list of content';
@ -32,8 +30,37 @@ class ObjectHelper {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$connectionHelper = new ConnectionHelper();
//$this->fedoraUser = $connectionHelper->getUser();
//$this->fedoraPass = $connectionHelper->getPassword();
}
/**
* Get the size of the indicated datastream.
*
* Note that this only works for Inline XML and Managed datastream, as Fedora
* does not know anything about external or redirect streams, other than a URI.
* If run on an external or redirect stream, Fedora (and therefore this
* function) will return the integer value '0'.
* This function requires the use of the API-M method getDatastream, and defaults
* to returning '0' if it is not accessible.
*
* @param $pid string
* A string containing the PID of a Fedora object.
* @param $dsid string
* A string containing the datastream ID of datastream on the Fedora object
* indicated by the PID.
* @param $quiet boolean
* A boolean indicating whether SOAP errors should be displayed.
* @return integer
* An integer representing the size of the datastream, or zero if it could not be determined.
*/
static function getDatastreamSize($pid, $dsid, $quiet = FALSE) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($ds_info = $item->get_datastream($dsid, '', $quiet)) {
return $ds_info->size;
}
else {
return 0;
}
}
/**
@ -72,7 +99,6 @@ class ObjectHelper {
return ' ';
}
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) {
if (($cm = ContentModel::loadFromObject($pid)) == FALSE) {
drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error');
@ -91,7 +117,6 @@ class ObjectHelper {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if (isset($item->datastreams[$dsID])) {
$mimeType = $item->datastreams[$dsID]['MIMEType'];
if ($label == NULL) {
@ -107,40 +132,41 @@ class ObjectHelper {
if ((!isset($user)) || $user->uid == 0) {
$fedoraUser = 'anonymous';
$fedoraPass = 'anonymous';
$contentSize = 0;
}
else {
} else {
$fedoraUser = $user->name;
$fedoraPass = $user->pass;
$dataStreamInfo = $item->get_datastream_info($dsID);
$contentSize = $dataStreamInfo->datastream->size;
}
$dataStreamInfo = $item->get_datastream_info($dsID);
$contentSize = $dataStreamInfo->datastream->size;
if (function_exists("curl_init")) {
if (!isset($mimeType)) {
$pid = variable_get('fedora_default_display_pid', 'demo:10');
$dsID = variable_get('fedora_default_display_dsid', 'TN');
$mimeType = 'image/jpeg';
}
$url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content';
$query_options = array();
if ($version) {
$url .= '/' . $version; //drupal_urlencode($version);
$query_options['asOfDateTime'] = $version; //drupal_urlencode($version);
}
if ($query_options) {
$url = url($url, array(
'query' => $query_options,
));
}
$ch = curl_init();
$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, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedoraUser:$fedoraPass");
// There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error.
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable
curl_setopt($ch, CURLOPT_URL, $url);
$ch = curl_init($url);
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
$curl_opts = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_FAILONERROR => TRUE, // Fail on errors
CURLOPT_FOLLOWLOCATION => TRUE, // allow redirects
//CURLOPT_TIMEOUT => 15, // times out after 15s
CURLOPT_USERAGENT => $user_agent,
CURLOPT_USERPWD => "$fedoraUser:$fedoraPass",
// There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error.
//CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_RETURNTRANSFER => TRUE, // return into a variable; need to at first, so additional headers can be set later.
);
curl_setopt_array($ch, $curl_opts);
if ($filePath !== FALSE) {
$fp = fopen($filePath, 'w');
@ -150,42 +176,47 @@ class ObjectHelper {
fclose($fp);
}
else {
header("Content-type: $mimeType");
if ($contentSize > 0) {
header("Content-length: $contentSize");
}
if ($asAttachment) {
$suggestedFileName = "$label";
$pos = strpos($suggestedFileName, '.');
/*
* Here we used to take an object of, say, type application/pdf with label, say, "My Document"
* and we assemble the output filename extension based on the post-slash portion of the mimetype.
* (If the label has a period anywhere in it, we leave it alone.)
*
* This is great for simple mimetypes like application/pdf, text/html, image/jpeg, etc.
* but it's terrible for, say, application/vnd.oasis.opendocument.text (.odt).
*
* Instead we'll use the get_extension function in MimeClass.inc to discover a valid extension
* for the mimetype in question.
*/
if ($pos === FALSE) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimeclass = new MimeClass();
$ext = $mimeclass->get_extension($mimeType);
$suggestedFileName = "$label.$ext";
}
header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
}
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$curl_out = curl_exec($ch);
if ($curl_out !== FALSE) {
$info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
//dd($info, 'effective URL');
if ($url !== $info) { //Handle redirect streams (the final URL is not the same as the Fedora URL)
$curl_stat = curl_exec($ch);
if ($curl_stat !== FALSE) {
$info = curl_getinfo($ch);
//Set what headers we can...
if ($mimeType = $info['content_type']) {
drupal_set_header("Content-Type: $mimeType");
if ($asAttachment) {
$suggestedFileName = "$label";
$pos = strpos($suggestedFileName, '.');
/*
* Here we used to take an object of, say, type application/pdf with
* label, say, "My Document" and we assemble the output filename
* extension based on the post-slash portion of the mimetype. (If the
* label has a period anywhere in it, we leave it alone.)
*
* This is great for simple mimetypes like application/pdf, text/html,
* image/jpeg, etc., but it's terrible for, say
* application/vnd.oasis.opendocument.text (.odt).
*
* Instead we'll use the get_extension function in MimeClass.inc to
* discover a valid extension for the mimetype in question.
*/
if ($pos === FALSE) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimeclass = new MimeClass();
$ext = $mimeclass->get_extension($mimeType);
$suggestedFileName = "$label.$ext";
}
drupal_set_header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
}
}
$effective_url = $info['url'];
//dd($info, 'header/nobody info');
if ($url !== $effective_url) { //Handle redirect streams (the final URL is not the same as the Fedora URL)
//Add the parameters passed to Drupal, leaving out the 'q'
$query = array();
@ -194,23 +225,42 @@ class ObjectHelper {
unset($query['q']);
}
header('HTTP/1.1 307 Moved Temporarily');
header('Location: ' . $info . '?' . http_build_query($query)); //Fedora seems to discard the query portion.
drupal_set_header('HTTP/1.1 307 Moved Temporarily');
drupal_set_header('Location: ' . url($effective_url, array('query' => $query)));
}
elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS
//Have the webserver mediate the transfer (download and restream)
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); //CURLOPT_NOBODY sets it to 'HEAD'
$toReturn = curl_exec($ch);
echo $toReturn;
if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) {
drupal_set_header("Content-Length: $contentSize");
}
$opts = array(
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPGET => TRUE, //CURLOPT_NOBODY sets it to 'HEAD'
CURLOPT_RETURNTRANSFER => FALSE, //Want to output as efficiently as possible now...
);
curl_setopt_array($ch, $opts);
$curl_stat = curl_exec($ch);
if (!$curl_stat) {
watchdog('fedora_repository', 'Error in ObjectHelper->makeObject() for @pid/@dsid. See link for attempted URL.', array(
'@pid' => $pid,
'@dsid' => $dsID,
), WATCHDOG_WARNING, $url);
}
}
else {
header('Location: ' . $url);
else { //Try to redirect directly to Fedora.
drupal_set_header('HTTP/1.1 307 Moved Temporarily');
drupal_set_header('Location: ' . $url);
}
}
else {
//Curl error...
watchdog('fedora_repository', 'Curl error while trying to get datastream %dsid from Fedora object %pid. Curl info: !info', array(
'%pid' => $pid,
'%dsid' => $dsID,
'!info' => print_r(curl_getinfo($ch), TRUE),
), WATCHDOG_WARNING);
}
}
curl_close($ch);
@ -355,7 +405,7 @@ class ObjectHelper {
$content = '';
$id = $dataStreamValue->ID;
$label = $dataStreamValue->label;
$label = str_replace("_", " ", $label);
//$label = str_replace("_", " ", $label);
$label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh.
$mimeType = $dataStreamValue->MIMEType;
@ -364,20 +414,8 @@ class ObjectHelper {
'target' => '_blank',
),
));
$action = url("fedora/repository/object_download/$pid/$id/$label_deslashed");
$downloadVersion = '<form method="GET" action="' . $action . '"><input type="submit" value="' . t('Download') . '"></form>';
if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$versions = $item->get_datastream_history($id);
if (is_array($versions)) {
$downloadVersion = '<form method="GET" action="' . $action . '" onsubmit="this.action=\'' . $action . '\' + \'/\'+this.version.value;">';
$downloadVersion .= '<input type="submit" value="' . t('Download') . '">';
$downloadVersion .= '<select name="version">';
foreach ($versions as $version) {
$downloadVersion .= '<option>' . $version->createDate . '</option>';
}
$downloadVersion .= '</select></form>';
}
}
$downloadVersion = drupal_get_form('fedora_repository_download_datastream_form', $pid, $id, $label_deslashed);
return array(
array(
@ -407,7 +445,6 @@ class ObjectHelper {
function getFormattedDC($item) {
global $base_url;
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
$xmlstr = $item->get_datastream_dissemination($dsid);
@ -416,31 +453,68 @@ class ObjectHelper {
return '';
}
$simplexml = new SimpleXMLElement($xmlstr);
if (($xsl_path = "$path/xsl/convertQDC.xsl") &&
(is_readable($xsl_path)) &&
($xsl = DOMDocument::load($xsl_path)) && //Fails loading XSLT -> FALSE
($ds = DOMDocument::loadXML($xmlstr))) {
$xslt_opts = array(
'BASEURL' => $base_url,
'PATH' => url($path, array('absolute' => TRUE)),
'baseUrl' => $base_url, //XXX: Deprecated; just here for legacy cases.
'path' => url($path, array('absolute' => TRUE)), //XXX: Deprecated; just here for legacy cases.
);
$transform = new XSLTProcessor();
$transform->importStylesheet($xsl);
$transform->setParameter('', $xslt_opts);
$transformed = $transform->transformToDoc($ds);
return $transformed->saveHTML();
}
else {
$simplexml = new SimpleXMLElement($xmlstr);
$headers = array(
array(
'data' => t('Metadata'),
'colspan' => 2,
),
);
$rows = array();
foreach ($simplexml->getNamespaces(TRUE) as $ns) {
foreach ($simplexml->children($ns) as $child) {
$rows[] = array(
array(
'data' => $child->getName(),
'class' => 'dc-tag-name',
),
array(
'data' => (string)$child,
'class' => 'dc-content',
),
);
$headers = array(
array(
'data' => t('Metadata'),
'colspan' => 2,
),
);
$rows = array();
foreach ($simplexml->getNamespaces(TRUE) as $ns) {
foreach ($simplexml->children($ns) as $child) {
$data = array();
$rendered_data = '';
if ($grand_children = $child->children()) {
foreach($grand_children as $grand_child) {
$data[] = $grand_child->getName() . ' = ' . (string)$grand_child;
}
}
else {
$rendered_data = (string)$child;
}
if ($data) {
$rendered_data = theme('item_list', $data);
}
if ($rendered_data) {
$rows[] = array(
array(
'data' => $child->getName(),
'class' => 'dc-tag-name',
),
array(
'data' => $rendered_data,
'class' => 'dc-content',
),
);
}
}
}
}
return theme('table', $headers, $rows, array('class' => 'dc-table'));
return theme('table', $headers, $rows, array('class' => 'dc-table'));
}
}
/**
@ -548,30 +622,9 @@ class ObjectHelper {
*
*/
function getStream($pid, $dsid, $showError = FALSE) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$soapHelper = new ConnectionHelper();
try {
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
$params = array(
'pid' => "$pid",
'dsID' => "$dsid",
'asOfDateTime' => ""
);
if (!isset($client)) {
drupal_set_message(t('Error connection to Fedora using soap client.'));
return NULL;
}
$object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) {
if ($showError) {
drupal_set_message(t('Error getting Datastream for %pid and %datastream<br />', array('%pid' => $pid, '%datastream' => $dsid)), 'error');
}
return NULL;
}
$content = $object->dissemination->stream;
$content = trim($content);
return $content;
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new fedora_item($pid);
return $item->get_datastream_dissemination($dsid);
}
/**
@ -650,107 +703,6 @@ class ObjectHelper {
return ($namespace_access && user_access($op, $as_user));
}
/**
* internal function
* uses an xsl to parse the sparql xml returned from the ITQL query
* @deprecated
* This is only used in the fedora/repository/collection path,
* which should probably be nuked.
* @param $content String
*/
function parseContent($content, $pid, $dsId, $collection, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository');
global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe
$objectHelper = $this;
$parsedContent = NULL;
$contentModels = $this->get_content_models_list($pid);
$isCollection = FALSE;
$fedoraItem = NULL;
$datastreams = $this->get_formatted_datastream_list($pid, $contentModels, $fedoraItem);
if (!empty($contentModels)) {
foreach ($contentModels as $contentModel) {
if ($contentModel == variable_get('fedora_collection_model_pid', 'islandora:collectionCModel')) {
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.
$_SESSION['fedora_collection'] = $pid;
$isCollection = TRUE;
}
}
}
if ($fedoraItem !== NULL) {
$dslist = $fedoraItem->get_datastreams_list_as_array();
if (isset($dslist['COLLECTION_POLICY'])) {
$isCollection = TRUE;
}
}
//--------------------------------------------------------------------------------
//show the collections datastreams
if ($results->length > 0 || $isCollection == TRUE) {
// if(strlen($objectList)>22||$contentModel=='Collection'||$contentModel=='Community')//length of empty dom still equals 22 because of <table/> etc
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$collectionPolicyExists = $this->getMimeType($pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) {
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
// $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
$ingest_text = t('Ingest a new object into @collection_name PID @collection_pid', array('@collection_name' => $collectionName, '@collection_pid' => $collection_pid));
$ingestObject = l(theme('image', "$path/images/ingest.png", $ingest_text), "fedora/ingestObject/$collection_pid/$collectionName", array('attributes' => array(
'class' => 'icon',
'title' => $ingest_text,
))) . t('Add to this Collection');
}
}
}
else {
$ingestObject = '&nbsp;';
}
}
$datastreams .= $ingestObject;
$output .= $datastreams;
$showDesc = FALSE;
switch (variable_get('fedora_object_display_description', ObjectHelper :: $DISPLAY_NO_MODEL_OUTPUT)) {
case ObjectHelper :: $DISPLAY_NEVER: break;
case ObjectHelper :: $DISPLAY_NO_MODEL_OUTPUT:
if (trim($datastreams) == '') {
$showDesc = TRUE;
}
break;
case ObjectHelper :: $DISPLAY_ALWAYS:
default:
$showDesc = TRUE;
break;
}
if ($showDesc) {
//just show default dc or qdc as we could not find a content model
$metaDataText = t('Description');
$body = $this->getQDC($pid);
$fieldset = array(
'#title' => t("!metaDataText", array('!metaDataText' => $metaDataText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $body
);
$output .= theme('fieldset', $fieldset);
}
return $output;
}
/**
* Get the query to find parent objects.
*
@ -965,37 +917,54 @@ class ObjectHelper {
$breadcrumbs[] = l(t('Home'), '<front>');
}
else {
$query_string = 'select $parentObject $title $content from <#ri>
where (
<info:fedora/' . $pid . '> <fedora-model:label> $title
and $parentObject <fedora-model:hasModel> $content
and (
<info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOf> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isPartOf> $parentObject
)
and $parentObject <fedora-model:state> <info:fedora/fedora-system:def/model#Active>
)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title desc';
if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) {
$parent = $results[0]['parentObject'];
$this_title = $results[0]['title'];
$sparql_query_string = <<<EOQ
PREFIX fedora-model: <info:fedora/fedora-system:def/model#>
PREFIX rels-ext: <info:fedora/fedora-system:def/relations-external#>
SELECT ?parentObject ?title ?content
FROM <#ri>
WHERE {
<info:fedora/$pid> ?relationship ?parentObject .
?parentObject fedora-model:label ?title ;
fedora-model:state fedora-model:Active ;
fedora-model:hasModel ?content .
FILTER(
(
sameTerm(?relationship, rels-ext:isMemberOfCollection) ||
sameTerm(?relationship, rels-ext:isMemberOf) ||
sameTerm(?relationship, rels-ext:isPartOf)
) &&
!sameTerm(?content, <info:fedora/fedora-system:FedoraObject-3.0>)
) .
}
ORDER BY DESC(?title)
EOQ;
$results = self::performSparqlQuery($sparql_query_string);
$next_pid = NULL;
if (count($results) > 0 && $level > 0) {
$parent_pid = $results[0]['parentObject'];
$parent_title = $results[0]['title'];
if (empty($this_title)) {
$this_title = t('Unlabeled Object');
}
$breadcrumbs[] = l($this_title, "fedora/repository/$pid");
if ($parent_pid != $root) {
$breadcrumbs[] = l($parent_title, "fedora/repository/$parent_pid");
}
$level--;
$this->getBreadcrumbs($parent, $breadcrumbs);
$next_pid = $parent_pid;
}
else {
watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING);
watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_level), WATCHDOG_WARNING);
$breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root.
$this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass).
$next_pid = $root; //And cue the last two links to render and break recursion (on the next pass).
}
if ($next_pid !== NULL) {
$level--;
$this->getBreadcrumbs($next_pid, $breadcrumbs);
}
}
}
@ -1046,6 +1015,18 @@ class ObjectHelper {
if (!empty($attrs['uri'])) {
$val = self::pidUriToBarePid((string)$attrs['uri']);
}
elseif(!empty($attrs['datatype'])) {
$dt = (string)$attrs['datatype'];
$val = (string)$element; //Default to a string...
if ($dt == 'http://www.w3.org/2001/XMLSchema#int') {
$val = intval($val);
}
else {
watchdog('fedora_repository', 'Datatype @dt_uri handled as string.', array(
'@dt_uri' => $dt,
), WATCHDOG_DEBUG);
}
}
else {
$val = (string)$element;
}
@ -1101,6 +1082,7 @@ class ObjectHelper {
$queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options));
//Perform the query.
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$curl_result = do_curl_ext($queryUrl);
//If the query failed, write message to the logs and return.

1
api/fedora_export.inc

@ -57,7 +57,6 @@ function export_objects_for_pid($pid, $dir, &$log) {
$file = $dir . '/' . $ds->label . '.' . get_file_extension($ds->MIMEType);
$paths[$ds->ID] = $file;
//$content = $ob_helper->getDatastreamDissemination($pid, $ds->ID);
if ($content = $ob_helper->getStream($pid, $ds->ID, FALSE)) {
if (!$fp = @fopen($file, 'w')) {
$log[] = log_line(t("Failed to open file %file to write datastream %dsid for pid %pid", array('%file' => $file, '%dsid' => $ds->ID, '%pid' => $pid)), 'error');

128
api/fedora_item.inc

@ -10,6 +10,12 @@ define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#');
define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#');
define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#");
define("RELS_TYPE_URI", 0);
define("RELS_TYPE_PLAIN_LITERAL", 1);
define("RELS_TYPE_STRING", 2);
define("RELS_TYPE_INT", 3);
define("RELS_TYPE_DATETIME", 4);
/**
* Fedora Item Class
*/
@ -124,6 +130,7 @@ class Fedora_Item {
$datastream_url = drupal_urlencode($datastream_file);
$url = file_create_url($datastream_url);
// add_datastream_from_url forces a re-sync of the datastream list
$return_value = $this->add_datastream_from_url($url, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage);
if ($original_path != $datastream_file) {
@ -159,7 +166,7 @@ class Fedora_Item {
'pid' => $this->pid,
'dsID' => $datastream_id,
'altIDs' => NULL,
'dsLabel' => $datastream_label,
'dsLabel' => truncate_utf8($datastream_label, 255, TRUE, TRUE),
'versionable' => TRUE,
'MIMEType' => $datastream_mimetype,
'formatURI' => NULL,
@ -171,8 +178,10 @@ class Fedora_Item {
'logMessage' => ($logMessage != NULL) ? $logMessage : 'Ingested object ' . $datastream_id
);
return $this->soap_call('addDataStream', $params);
$soap_result = $this->soap_call('addDataStream', $params);
// make sure to refresh the datastream list after adding so this item stays in sync with the repository
$this->datastreams = $this->get_datastreams_list_as_array();
return $soap_result;
}
/**
@ -191,6 +200,7 @@ class Fedora_Item {
$tmpfile = fopen($tmpfilename, 'w');
fwrite($tmpfile, $str, strlen($str));
fclose($tmpfile);
// add_datastream_from_file forces a re-sync of the datastream list
$returnvalue = $this->add_datastream_from_file($tmpfilename, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage);
unlink($tmpfilename);
return $returnvalue;
@ -230,11 +240,22 @@ class Fedora_Item {
* The object to be related to.
* @param string $namespaceURI
* The predicate namespace.
* @param boolean $literal_value
* Whether or not the object should be added as a URI (FALSE) or a literal (TRUE).
* @param int $literal_value
* Used to type the value.
* - 0: URI
* - 1: plain literal
* - 2: string (explicitly typed)
* - 3: integer
* - 4: dateTime
* @return ???
* Value returned from SOAP call for modify_datastream.
*/
function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) {
//dd($this, 'The Fedora_Item');
function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) {
static $relsextxml = NULL;
if ($relsextxml === NULL) {
$relsextxml = new DOMDocument(); //Avoid new instantiations in long-running processes
}
$ds_list = $this->get_datastreams_list_as_array();
$f_prefix = 'info:fedora/';
if (!array_key_exists('RELS-EXT', $ds_list)) {
@ -249,12 +270,10 @@ RDF;
$relsext = $this->get_datastream_dissemination('RELS-EXT');
if (!$literal_value && strpos($object, $f_prefix) !== 0) {
if ($literal_value == REL_TYPE_URI && strpos($object, $f_prefix) !== 0) {
$object = $f_prefix . $object;
}
$relsextxml = new DOMDocument();
$relsextxml->loadXML($relsext);
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
if ($description->length == 0) {
@ -269,8 +288,20 @@ RDF;
// Create the new relationship node.
$newrel = $relsextxml->createElementNS($namespaceURI, $relationship);
if ($literal_value) {
if ($literal_value > 0) {
$newrel->appendChild($relsextxml->createTextNode($object));
if ($literal_value == RELS_TYPE_STRING) {
$newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#string');
}
elseif ($literal_value == RELS_TYPE_INT) {
$newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#int');
}
elseif ($literal_value == RELS_TYPE_DATETIME) {
$newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#dateTime');
}
else {
//plain literal.
}
}
else {
$newrel->setAttribute('rdf:resource', $object);
@ -303,8 +334,8 @@ RDF;
* The object to be related to. (NULL/value for which empty() evaluates to true will remove all relations of the given type, ignoring $literal_value)
* @param string $namespaceURI
* The predicate namespace.
* @param boolean $literal_value
* Whether or not the object should be looked for as a URI (FALSE) or a literal (TRUE).
* @param int $literal_value
* Same as add_relationship. NOTE: dateTime implemented.
* @return boolean
* Whether or not this operation has produced any changes in the RELS-EXT
*/
@ -319,8 +350,10 @@ RDF;
foreach ($rels as $rel) {
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) ||
(!$literal_value && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) ||
($literal_value && $rel->textContent == $object)) {
(($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) ||
(($literal_value == RELS_TYPE_PLAIN_LITERAL) && $rel->textContent == $object) ||
(($literal_value == RELS_TYPE_STRING) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#string' && $rel->textContent == $object) ||
(($literal_value == RELS_TYPE_INT) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#int' && intval($rel->textContent) == $object)) {
$rel->parentNode->removeChild($rel);
$modified = TRUE;
}
@ -484,6 +517,10 @@ RDF;
* @return null
*/
function get_datastream_dissemination($dsid, $as_of_date_time = "", $quiet=TRUE) {
if (!array_key_exists($dsid, $this->datastreams)) {
return NULL;
}
$params = array(
'pid' => $this->pid,
'dsID' => $dsid,
@ -508,13 +545,16 @@ RDF;
* @param type $as_of_date_time
* @return type
*/
function get_datastream($dsid, $as_of_date_time = '') {
function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) {
if (!array_key_exists($dsid, $this->datastreams)) {
return NULL;
}
$params = array(
'pid' => $this->pid,
'dsID' => $dsid,
'asOfDateTime' => $as_of_date_time,
);
$object = self::soap_call('getDatastream', $params);
$object = self::soap_call('getDatastream', $params, $quiet);
return $object->datastream;
}
@ -637,18 +677,15 @@ RDF;
// datastream, instead of returning it as an array, only
// the single item will be returned directly. We have to
// check for this.
if (count($this->datastreams_list->datastreamDef) > 1) {
foreach ($this->datastreams_list->datastreamDef as $ds) {
if (!is_object($ds)) {
print_r($ds);
}
$ds_list[$ds->ID]['label'] = $ds->label;
$ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType;
$ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label);
}
$xml_list = $this->datastreams_list->datastreamDef;
if (!is_array($this->datastreams_list->datastreamDef)) {
$xml_list = array($xml_list);
}
else {
$ds = $this->datastreams_list->datastreamDef;
foreach ($xml_list as $ds) {
if (!is_object($ds)) {
print_r($ds);
}
$ds_list[$ds->ID]['label'] = $ds->label;
$ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType;
$ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label);
@ -774,9 +811,9 @@ RDF;
/**
* Set the object to a deleted state
*/
function move_to_trash($log_message = 'Flagged deleted using Islandora API.') {
function move_to_trash($log_message = 'Flagged deleted using Islandora API.', $quiet = TRUE) {
// Loop through the datastreams and mark them deleted
foreach ($this->get_datastreams_list_as_array() as $dsid) {
foreach ($this->get_datastreams_list_as_array() as $dsid => $info) {
$this->set_datastream_state($dsid, 'D');
}
@ -784,7 +821,7 @@ RDF;
$params = array(
'pid' => $this->pid,
'state' => 'D',
'logMessage' => $logMessage,
'logMessage' => $log_message,
'label' => $this->objectProfile->objLabel,
'ownerId' => null,
);
@ -833,7 +870,10 @@ RDF;
'logMessage' => $log_message,
'force' => $force,
);
return $this->soap_call('purgeDatastream', $params);
$soap_result = $this->soap_call('purgeDatastream', $params);
// make sure to refresh the datastream list after adding so this item stays in sync with the repository
$this->datastreams = $this->get_datastreams_list_as_array();
return $soap_result;
}
/**
@ -849,11 +889,10 @@ RDF;
/**
* Get Next PID in Namespace
* @param type $pid_namespace
* @return type
* @param $pid_namespace string
* @return string
*/
static function get_next_PID_in_namespace($pid_namespace = '') {
static function get_next_PID_in_namespace($pid_namespace = '', $number_of_pids = 1) {
if (empty($pid_namespace)) {
// Just get the first one in the config settings.
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
@ -867,11 +906,12 @@ RDF;
}
$params = array(
'numPIDs' => '',
'numPIDs' => $number_of_pids,
'pidNamespace' => $pid_namespace,
);
$result = self::soap_call('getNextPID', $params);
return $result->pid;
}
@ -887,7 +927,6 @@ RDF;
'logMessage' => 'Fedora Object Ingested'
);
$object = self::soap_call('ingest', $params);
//dd($object, 'Soap return');
return new Fedora_Item($object->objectPID);
}
@ -927,11 +966,11 @@ RDF;
/**
* Modify Object
* @param type $label
* @param type $state
* @param type $ownerId
* @param type $logMessage
* @param type $quiet
* @param $label string
* @param $state string
* @param $ownerId string
* @param $logMessage string
* @param $quiet boolean
* @return type
*/
function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) {
@ -1148,6 +1187,7 @@ RDF;
$pid = self::get_next_PID_in_namespace();
}
if (empty($owner)) {
global $user;
if (!empty($user->uid)) { // Default to current Drupal user.
$owner = $user->uid;
}
@ -1170,7 +1210,7 @@ RDF;
$label_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property");
$label_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#label");
$label_property->setAttribute("VALUE", $label);
$label_property->setAttribute("VALUE", truncate_utf8($label, 255, TRUE, TRUE));
$owner_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property");
$owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId");

23
api/fedora_utils.inc

@ -239,13 +239,24 @@ function get_collections_as_option_array() {
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
where ($object <fedora-model:label> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
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)));
$options = array(
'type' => 'tuples',
'flush' => 'TRUE',
'format' => 'csv',
'limit' => '1000',
'lang' => 'itql',
'stream' => 'on',
'query' => $query,
);
//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);

115
api/tuque.inc

@ -0,0 +1,115 @@
<?php
$islandora_module_path = drupal_get_path('module', 'fedora_repository');
//do this until we expost 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';
@include_once 'sites/all/libraries/tuque/Object.php';
@include_once 'sites/all/libraries/tuque/RepositoryConnection.php';
@include_once 'sites/all/libraries/tuque/Cache.php';
@include_once 'sites/all/libraries/tuque/RepositoryException.php';
@include_once 'sites/all/libraries/tuque/Repository.php';
@include_once 'sites/all/libraries/tuque/FedoraRelationships.php';
@include_once "$islandora_module_path/libraries/tuque/Datastream.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraApi.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraApiSerializer.php";
@include_once "$islandora_module_path/libraries/tuque/Object.php";
@include_once "$islandora_module_path/libraries/tuque/RepositoryConnection.php";
@include_once "$islandora_module_path/libraries/tuque/Cache.php";
@include_once "$islandora_module_path/libraries/tuque/RepositoryException.php";
@include_once "$islandora_module_path/libraries/tuque/Repository.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraRelationships.php";
class IslandoraTuque {
/**
* Connection to the repository
*
* @var RepositoryConnection
*/
public $connection = NULL;
/**
* The Fedora API we are using
*
* @var FedoraAPI
*/
public $api = NULL;
/**
* The cache we use to connect.
*
* @var SimpleCache
*/
public $cache = NULL;
/**
* The repository object.
*
* @var FedoraRepository
*/
public $repository = NULL;
function __construct($user = NULL, $url = NULL) {
if(!isset($user)) {
global $user;
}
if(!isset($user) || $user->uid == 0){
$user_string = 'anonymous';
$pass_string = 'anonymous';
} else {
$user_string = $user->name;
$pass_string = $user->pass;
}
if (!isset($url)) {
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
}
if(self::exists()) {
$this->connection = new RepositoryConnection($url, $user_string, $pass_string);
$this->connection->reuseConnection = TRUE;
$this->api = new FedoraApi($this->connection);
$this->cache = new SimpleCache();
$this->repository = new FedoraRepository($this->api, $this->cache);
}
}
static function exists() {
return class_exists('RepositoryConnection');
}
static function getError() {
$islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora');
$tuque_link = l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque');
$message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link));
drupal_set_message($message, 'error', FALSE);
}
}
function islandora_object_load($object_id) {
static $islandora_tuque = NULL;
if(!$islandora_tuque) {
$islandora_tuque = new IslandoraTuque();
}
if(IslandoraTuque::exists()) {
try {
$fedora_object = $islandora_tuque->repository->getObject($object_id);
} catch (Exception $e) {
return NULL;
}
return $fedora_object;
}
else {
IslandoraTuque::getError();
return NULL;
}
}

500
fedora_repository.module

@ -62,37 +62,6 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) {
return $output;
}
/**
* fedora repository collection view
* @global type $user
* @param type $pid
* @param type $collection
* @param type $pageNumber
* @return type
*/
function fedora_repository_collection_view($pid = NULL, $collection = NULL, $pageNumber = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
global $user;
if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
return ' ';
}
$objectHelper = new ObjectHelper();
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:root');
}
$content = '';
module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collectionClass = new CollectionClass();
$results = $collectionClass->getRelatedItems($pid, NULL);
$content .= $objectHelper->parseContent($results, $pid, $dsId, $collection, $pageNumber);
return $content;
}
/**
* fedora repository ingest object
* @param type $collection_pid
@ -220,18 +189,26 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
// Get the uploaded file.
$validators = array();
if (!empty($_FILES['files']['name']['ingest-file-location'])) {
$fileObject = file_save_upload('ingest-file-location', $validators);
$ifl = 'ingest-file-location';
$fileObject = NULL;
//Check if it's already there; this is what upload_element provides.
if (is_a($form_state['values'][$ifl], 'stdClass') && property_exists($form_state['values'][$ifl], '')) {
$fileObject = $form_state['values'][$ifl];
}
elseif (!empty($_FILES['files']['name'][$ifl])) {
$fileObject = file_save_upload($ifl, $validators);
}
if ($fileObject !== NULL && property_exists($fileObject, 'filepath')) {
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['ingest-file-location'] = $fileObject->filepath;
$form_state['values'][$ifl] = $fileObject->filepath;
}
if (isset($form_state['values']['ingest-file-location']) && file_exists($form_state['values']['ingest-file-location'])) {
if (isset($form_state['values'][$ifl]) && file_exists($form_state['values'][$ifl])) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'MimeClass');
$file = $form_state['values']['ingest-file-location'];
$file = $form_state['values'][$ifl];
$contentModelPid = ContentModel::getPidFromIdentifier($form_state['values']['models']);
$contentModelDsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']);
@ -244,11 +221,11 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
if (!empty($file)) {
if (!in_array($dformat, $allowedMimeTypes)) {
form_set_error('ingest-file-location',
t('The uploaded file\'s mimetype') .
' (' . $dformat . ') ' .
t('is not associated with this Content Model. The allowed types are') .
' ' . implode(' ', $allowedMimeTypes));
form_set_error($ifl,
t('The uploaded file\'s mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed', array(
'@mime' => $dformat,
'@allowed' => implode(', ', $allowedMimeTypes),
)));
file_delete($file);
return;
}
@ -377,41 +354,30 @@ function add_stream_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
return;
}
module_load_include('inc', 'fedora_repository', 'MimeClass');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$pathToModule = drupal_get_path('module', 'fedora_repository');
$file = $form_state['values']['add-stream-file-location'];
$pid = $form_state['values']['pid'];
$dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.;
$file_basename = basename($file);
$file_directory = dirname($file);
$streamUrl = $base_url . '/' . $file_directory . '/' . drupal_urlencode($file_basename);
$dsLabel = $form_state['values']['stream_label'] . substr($form_state['storage']['stream_url'], strrpos($form_state['storage']['stream_url'], '.')); // Add the file extention to the end of the label.;
/* -----------------------------------------------------------------
* need a better way to get mimetypes
*/
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file);
$controlGroup = "M";
if ($dformat == 'text/xml') {
$controlGroup = 'X';
}
try {
$item = new Fedora_Item($pid);
$item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup);
$item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['storage']['control_group']);
$object_helper = new ObjectHelper();
$object_helper->get_and_do_datastream_rules($pid, $dsid, $file);
if ($file = $form_state['values']['add-stream-file-location']) {
$object_helper = new ObjectHelper();
$object_helper->get_and_do_datastream_rules($pid, $dsid, $file);
file_delete($file);
file_delete($file);
}
} catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return;
}
unset($form_state['storage']); //Using storage; need to unset it for forms to work properly...
$form_state['rebuild'] = TRUE;
}
@ -434,6 +400,7 @@ function add_stream_form(&$form_state, $pid) {
* @return type
*/
function add_stream_form_validate($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
if ($form_state['clicked_button']['#value'] == 'OK') {
$form_state['rebuild'] = TRUE;
return;
@ -444,15 +411,15 @@ function add_stream_form_validate($form, &$form_state) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE;
}
if (!(preg_match("/^[a-zA-Z]/", $dsid))) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
elseif (!(preg_match("/^[a-zA-Z]/", $dsid))) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => $dsid)));
return FALSE;
}
if (strlen($dsLabel) > 64) {
elseif (strlen($dsLabel) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
}
if (strpos($dsLabel, '/')) {
elseif (strpos($dsLabel, '/') !== FALSE) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
}
@ -461,13 +428,36 @@ function add_stream_form_validate($form, &$form_state) {
// 'file_validate_image_resolution' => array('85x85'),
// 'file_validate_size' => array(30 * 1024),
);
$fileObject = file_save_upload('add-stream-file-location', $validators);
// Move the uploaded file to Drupal's files directory.
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['add-stream-file-location'] = $fileObject->filepath;
// TODO: Add error checking here.
$controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group'];
if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)))) {
// Move the uploaded file to Drupal's files directory.
$file_path = $fileObject->filepath;
file_move($file_path, 0, FILE_EXISTS_RENAME);
$form_state['values']['add-stream-file-location'] = $file_path;
$form_state['storage']['stream_url'] = file_create_url($file_path);
}
elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) {
$form_state['storage']['stream_url'] = $form_state['values']['ds_reference'];
}
else {
form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".'));
}
$mimeClass = new MimeClass();
$mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']);
if (!$controlGroup) {
if ($mimetype == 'text/xml') {
$form_state['storage']['control_group'] = 'X';
}
else {
$form_state['storage']['control_group'] = 'M';
}
}
// TODO: Add error checking here.
$form_state['rebuild'] = FALSE;
}
@ -604,7 +594,44 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) {
} catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
}
$form_state['redirect'] = $base_url . "/fedora/repository/$pid";
$form_state['redirect'] = "fedora/repository/$pid";
}
function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$form = array(
'#action' => url("fedora/repository/object_download/$pid/$dsid/$label"),
'submit' => array(
'#type' => 'submit',
'#value' => t('Download'),
),
);
if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$item = new Fedora_Item($pid);
$versions = $item->get_datastream_history($dsid);
$version_array = array();
if (is_array($versions)) {
foreach ($versions as $version) {
$version_array[] = $version->createDate;
}
}
else {
$version_array[] = $versions->createDate;
}
if (count($version_array) > 1) {
$form['#attributes'] = array(
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;'
);
$form['version'] = array(
'#type' => 'select',
'#options' => array_combine($version_array, $version_array),
);
}
}
return $form;
}
/**
@ -646,29 +673,37 @@ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLab
* @return type
*/
function fedora_repository_replace_stream_form_validate($form, &$form_state) {
// If a file was uploaded, process it.
// If a file was uploaded, process it.
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) {
// attempt to save the uploaded file
// attempt to save the uploaded file
$file = file_save_upload('file', array(), file_directory_path());
// set error is file was not uploaded
// set error is file was not uploaded
if (!$file) {
form_set_error('file', 'Error uploading file.');
return;
}
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
$doc = new DOMDocument();
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mime = new MimeClass();
if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) {
form_set_error('file', 'Invalid XML format.');
$mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath);
if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) {
form_set_error('file', 'Invalid XML format. (XML could not be parsed)');
return;
}
// set files to form_state, to process when form is submitted
// set files to form_state, to process when form is submitted
$form_state['values']['file'] = $file;
}
elseif (!$form_state['values']['ds_reference']) {
form_set_error('', 'Need either a file or a reference!');
}
}
/**
@ -678,46 +713,30 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
* @param array $form_state
*/
function fedora_repository_replace_stream_form_submit($form, &$form_state) {
global $base_url;
$file = $form_state['values']['file'];
$pid = $form_state['values']['pid'];
$dsid = $form_state['values']['dsId'];
$dsLabel = $form_state['values']['dsLabel'];
// Remove the original file extension from the label and add the new one
$indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot
if ($indexOfDot !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot);
$dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.;
$streamUrl = ($file !== NULL) ?
file_create_url($file->filepath):
url($form_state['values']['reference'], array('absolute' => TRUE));
// Remove the original file extension from the label and add the new one
// use strrpos to get the last dot
if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot) .
substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label.
}
module_load_include('inc', 'fedora_repository', 'MimeClass');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$file_basename = basename($file->filepath);
$file_directory = dirname($file->filepath);
$streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename);
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
$dformat = $form_state['storage']['mime_type'];
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$info = $item->get_datastream_info($dsid);
if($info->datastream->controlGroup == 'M') {
$item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat);
} elseif ($info->datastream->controlGroup == 'X') {
if($dformat == 'text/xml') {
$item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat);
}
else {
drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error');
}
} else {
drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error');
}
$item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
unset($form_state['storage']);
$form_state['redirect'] = 'fedora/repository/' . $pid;
}
@ -898,7 +917,7 @@ function makeObject($pid, $dsID) {
drupal_set_message(t("No pid or dsid given to create an object with."));
return ' ';
}
global $user;
global $user, $conf;
if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
drupal_access_denied();
return;
@ -906,23 +925,106 @@ function makeObject($pid, $dsID) {
return ' ';
}
//Disable the page cache, so entire datastreams do not get thrown into the page cache.
$conf['cache'] = CACHE_DISABLED;
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper();
$objectHelper->makeObject($pid, $dsID);
}
/**
* Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara)
* Reads the pid and datastream id as url parameters. Queries the collection object for the query
* if there is no query datastream falls back to the query shipped with the module.
* Implementation of hook_islandora_tabs().
*
* @param $content_models array
* An array of ContentModel objects to which the current Fedora Object
* subscribes.
* @param $pid string
* A string containing the Fedora PID of the current Fedora Object.
* @param $page_number integer
* An integer for which page we should start on in the loaded object.
* @return array
* An array containing a tabset (an array of tabpages), renderable with
* drupal_render().
*/
function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
$cmodels_tabs = array();
foreach ($content_models as $content_model) {
$content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number);
// Each content model may return either a tabpage array or plain HTML. If
// it is HTML, stick it in a tabpage.
if (is_array($content_model_fieldset)) {
$cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset);
}
else {
$cmodels_tabs[$content_model->pid] = array(
'#type' => 'tabpage',
'#title' => $content_model->name,
'#content' => $content_model_fieldset,
);
}
}
//can disable showing the object details tab in admin UI
if (variable_get('fedora_repository_show_object_details_tab', TRUE)) {
// Add a 'manage object' tab for all objects, where detailed list of content is shown.
// XXX: Perhaps this should be extracted into its own object?
module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent');
$obj = new FedoraObjectDetailedContent($pid);
$object_details = $obj->showFieldSets();
$cmodels_tabs = array_merge($cmodels_tabs, $object_details);
}
return $cmodels_tabs;
}
/**
* Implementation of hook_islandora_tabs_alter().
*
* @param &$tabs array
* The array of tabs/tabset to alter.
* @param $params array
* An associative array containing the parameters with which the original
* hook was called.
* @see fedora_repository_get_items()
*/
function fedora_repository_islandora_tabs_alter(&$tabs, $params) {
//Deselect all other tabs if the fedora_object_details tab is supposed
// to be selected.
$object_details_key = 'fedora_object_details';
if ($tabs[$object_details_key]['#selected']) {
foreach (element_children($tabs) as $key) {
if ($key != $object_details_key) {
$tabs[$key]['#selected'] = FALSE;
}
}
}
}
/**
* Menu callback for "fedora/repository".
*
* If user is allow, and we are given a PID and a sensical DSID, return the
* datastream via the makeObject() function; otherwise, call out to the PIDs'
* ContentModels and all Drupal modules for Islandora tabs.
*
* @global type $user
* @param type $pid
* @param type $dsId
* @param type $collection
* @param type $page_number
* @param type $limit
* @return type
* @global $user stdObject
* @param $pid string
* An optional string containing the PID of an object. (defaults to islandora:root)
* @param $dsId string
* An optional string containing the dsid of an object. ("-" will be ignored
* to allow later parameters without including one).
* @param $collection string
* The collection name... Deprecated.
* @param $page_number string/integer(?)
* A page number to start on... Seems to be going towards deprecation?
* @param $limit string/integer(?)
* Used to limit the number of results returned? Deprecated?
* @return string
* A string containing markup for the rendered tabs.
*/
function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NULL, $page_number = NULL, $limit = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
@ -944,7 +1046,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
$pid = variable_get('fedora_repository_pid', 'islandora:root');
}
$item = new fedora_item($pid);
$item = new Fedora_Item($pid);
if (!$item->exists()) {
drupal_not_found();
exit();
@ -961,7 +1063,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
}
if (!fedora_repository_access(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
if (user_access('access administration pages')) {
drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed @here", array('@here' => l('here', 'admin/settings/fedora_repository'))), 'warning');
drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed !here", array('!here' => l('here', 'admin/settings/fedora_repository'))), 'warning');
}
drupal_access_denied();
exit;
@ -983,57 +1085,32 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
return makeObject($pid, $dsId);
}
$content = '<div id="content-fedora">';
module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collectionClass = new CollectionClass();
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent');
$breadcrumbs = array();
$objectHelper->getBreadcrumbs($pid, $breadcrumbs);
drupal_set_breadcrumb(array_reverse($breadcrumbs));
drupal_set_title(truncate_utf8($item->objectProfile->objLabel, 56, TRUE, TRUE));
$offset = $limit * $page_number;
$content_models = $objectHelper->get_content_models_list($pid);
// Each content model may return either a tabset array or plain HTML. If it's HTML, stick it in a tab.
//Get the tabs from all modules...
$hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number);
$cmodels_tabs = array(
'#type' => 'tabset',
);
foreach ($content_models as $content_model) {
$content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number);
if (is_array($content_model_fieldset)) {
$cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset);
}
else {
$cmodels_tabs[$content_model->pid] = array(
'#type' => 'tabpage',
'#title' => $content_model->name,
'#content' => $content_model_fieldset,
);
}
}
$cmodels_tabs += $hook_tabs;
// Add a 'manage object' tab for all objects, where detailed list of content is shown.
$obj = new FedoraObjectDetailedContent($pid);
//Assemble parameters, to pass during alter
$params = array(
'content_models' => $content_models,
'pid' => $pid,
'page' => $page_number,
);
//Allow returned tabs to be altered, before return.
drupal_alter('islandora_tabs', $cmodels_tabs, $params);
//can disable showing the object details tab in admin UI
if (variable_get('fedora_repository_show_object_details_tab', TRUE)) {
$object_details = $obj->showFieldSets();
if ($object_details['fedora_object_details']['#selected'] == TRUE) {
foreach ($cmodels_tabs as &$cmodel_tab) {
if (is_array($cmodel_tab)) {
$cmodel_tab['#selected'] = FALSE;
}
}
}
}
else {
$object_details = array();
}
$hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid);
$cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs);
return tabs_render($cmodels_tabs);
}
@ -1059,7 +1136,6 @@ function fedora_repository_urlencode_string($str) {
* @return type
*/
function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) {
global $user;
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
if ($pid == NULL || $dsId == NULL) {
@ -1067,8 +1143,11 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) {
return ' ';
}
//Disable the page cache, so entire datastreams do not get thrown into the page cache.
$GLOBALS['conf']['cache'] = CACHE_DISABLED;
$objectHelper = new ObjectHelper();
$objectHelper->makeObject($pid, $dsId, 1, $label, FALSE, $version);
$objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version);
}
/**
@ -2273,9 +2352,6 @@ function theme_fedora_repository_solution_packs_list($solution_packs) {
$header = array();
$rows = array();
drupal_add_css(drupal_get_path('module', 'update') . '/update.css');
return $output;
}
@ -2294,3 +2370,87 @@ function fedora_repository_forms($form_id) {
}
return $forms;
}
/**
* Implementation of hook_imagecache_default_presets().
*/
function fedora_repository_imagecache_default_presets() {
return array(
'fedora_repository_collection_thumbnail' => array(
'presetname' => 'fedora_repository_collection_thumbnail',
'actions' => array(
0 => array(
'weight' => 0,
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' => array(
'width' => 200,
'height' => 200,
'upscale' => TRUE,
),
),
),
),
);
}
/**
* Actually render an image, given an arbitrary path and preset.
*
* Note: If imagecache_external is not available, the full-sized image will be
* produced... Might want to look into restricting the display size by adding
* the width and height attributes to the theme('image') call, based on the
* selected preset? (get the presets and figure out the size from its actions?)
*
* @param $tn_path string
* @param $imagecache_preset string
* @return
* Markup for the image, making use of imagecache_external if it is available.
*/
function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_repository_collection_thumbnail') {
$thumbnail = NULL;
if ($thumbnail === NULL &&
module_exists('imagecache_external') &&
is_callable('theme_imagecache_external_image') &&
variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE) &&
imagecache_external_can_fetch($tn_path, TRUE)) {
$thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title);
}
if ($thumbnail === NULL) {
$thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE);
}
return $thumbnail;
}
/**
* Render an image, given a PID, DSID and preset.
*
* Produces a Drupal path for the image, passes to
* _fedora_repository_render_image(), and returns the result.
*
* @see _fedora_repository_render_image()
* @param $pid string
* A string containing a Fedora PID.
* @param $dsid
* A string indicating a DSID on the object indicated by $pid.
* @param $imagecache_preset
* An imagecache preset with which to render the image; defaults to
* fedora_repository_collection_thumbnail, which is added in this module's
* implementation of hook_imagecache_default_presets().
*/
function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedora_repository_collection_thumbnail') {
$tn_path = "fedora/repository/$pid/$dsid";
return _fedora_repository_render_image($tn_path, $imagecache_preset);
}
/**
* Convenience function used in XSLT callback...
*
* @param $string string
* A string containing some markup to convert to a domnode.
*/
function fedora_repository_string_to_domnode($string) {
return DOMDocument::loadXML($string);
}

207
formClass.inc

@ -122,13 +122,6 @@ class formClass {
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams')
);
$items['fedora/repository/collection'] = array(
'title' => t('Collection view'),
'page callback' => 'fedora_collection_view',
'type' => MENU_CALLBACK,
'access argruments' => array('view fedora collection'),
);
//new for mnpl******************************************
$items['fedora/repository/mnpl_advanced_search'] = array(
@ -179,6 +172,23 @@ class formClass {
'access arguments' => array('view fedora collection'),
);
$items['admin/settings/fedora_repository/object_details_xslt'] = array(
'title' => "",
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('fedora_repository_object_details_XSLT_config'),
'file' => 'ObjectDetails.inc',
'access arguments' => array('administer site configuration'),
);
$items['admin/settings/fedora_repository/object_details_table'] = array(
'title' => "",
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('fedora_repository_object_details_table_config'),
'file' => 'ObjectDetails.inc',
'access arguments' => array('administer site configuration'),
);
return $items;
}
@ -233,7 +243,7 @@ class formClass {
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>',
);
$form['fedora_soap_manage_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP management URL'),
@ -241,7 +251,7 @@ class formClass {
'#required' => TRUE,
'#weight' => -10
);
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) {
$form['fedora_namespace'] = array(
@ -282,10 +292,11 @@ class formClass {
$form['tabs'] = array(
'#type' => 'fieldset',
'#title' => t('Tabs Configuration'),
'#description' => t('Configure the tabs avaialble when viewing Fedora objects.'),
'#description' => t('Configure the tabs available when viewing Fedora objects.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
//when checked show object details tab
$form['tabs']['fedora_repository_show_object_details_tab'] = array(
'#type' => 'checkbox',
@ -293,7 +304,35 @@ class formClass {
'#default_value' => variable_get('fedora_repository_show_object_details_tab', TRUE),
'#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"),
);
module_load_include('inc', 'fedora_repository', 'ObjectDetails');
$primary_display_mode = variable_get('islandora_object_details_display_table', 'xslt');
$profiles = module_invoke_all("islandora_object_details_display");
$display_options = array();
// suppress php warnings from empty lists
if ($profiles) {
foreach ($profiles as $machine_name => $profile) {
// make sure the name exists (the bare minimum)
if (array_key_exists('name', $profile)) {
$display_options[$machine_name] = $profile['name'];
if (array_key_exists('config', $profile)) {
$config_path = $profile['config'];
if (isset($config_path) && $config_path != "") {
$display_options[$machine_name] .= " (". l("config", $config_path, array()) .")";
}
}
}
}
}
$form['tabs']['islandora_object_details_display_table'] = array(
'#type' => 'radios',
'#title' => t('Show object details as'),
'#options' => $display_options,
'#default_value' => $primary_display_mode,
'#description' => t("Tells Islandora how to display the object details page for each object"),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced configuration options'),
@ -301,21 +340,6 @@ class formClass {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['fedora_object_display_title'] = array(
'#type' => 'select',
'#title' => t('Display Object Title Behaviour'),
'#default_value' => variable_get('fedora_object_display_title', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the object (or collection) title when viewing an object/collection page.'),
);
$form['advanced']['fedora_object_display_description'] = array(
'#type' => 'select',
'#title' => t('Display Object Description Behaviour'),
'#default_value' => variable_get('fedora_object_display_description', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the default object (or collection) description fieldset when viewing an object/collection page.'),
);
$form['advanced']['fedora_object_restrict_datastreams'] = array(
'#type' => 'checkbox',
@ -323,13 +347,27 @@ 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_collection_display_list'] = array(
'#type' => 'select',
'#title' => t('Display Collection List Behaviour'),
'#default_value' => variable_get('fedora_collection_display_list', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the list of objects when viewing a collection page.'),
$form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array(
'#type' => 'checkbox',
'#title' => t('Allow imagecache_external use for thumbnails in collection view'),
'#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE),
'#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.',
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'),
'#description' => t('Whether or not we should allow the user to select which control group to ingest a stream as, or to follow the old paradigm--to add stream IDed as XML as inline, and everything else as managed.'),
'#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE),
);
//Export functionality
@ -656,17 +694,21 @@ class formClass {
}
}
$form['add_datastream_label'] = array(
'#value' => t('<br /><h3>Add Datastream:</h3>'),
'#weight' => -10,
$form['fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Add datastream'),
);
//$form['add_datastream_label'] = array(
// '#value' => t('<br /><h3>Add Datastream:</h3>'),
// '#weight' => -10,
//);
$form['pid'] = array(
$form['fieldset']['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
$form['stream_label'] = array(
$form['fieldset']['stream_label'] = array(
'#title' => 'Datastream Label',
'#required' => 'TRUE',
'#description' => t('A Human readable label'),
@ -674,35 +716,41 @@ class formClass {
);
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['add-stream-file-location'] = array(
$form['fieldset']['add-stream-file-location'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#size' => 48,
// '#required'=>'TRUE',
'#description' => t('The file to upload.')
'#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',
'#title' => t('Datastream reference'),
'#size' => 48,
'#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['submit'] = array(
$form['fieldset']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Datastream')
);
if (!empty($unused_dsids)) {
$dsidsForForm = array();
foreach ($unused_dsids as $dsid) {
$dsidsForForm[$dsid] = $dsid;
}
$form['stream_id'] = array(
$form['fieldset']['stream_id'] = array(
'#type' => 'select',
'#title' => t('Datastream ID'),
'#default_value' => variable_get('feed_item_length', 'teaser'),
'#weight' => '-1',
'#weight' => -1,
'#description' => t('Datastream IDs defined by the content model.'),
'#options' => array_combine($unused_dsids, $unused_dsids),
);
$form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids);
}
else {
$form['stream_id'] = array(
$form['fieldset']['stream_id'] = array(
'#title' => 'Datastream ID',
'#required' => 'TRUE',
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'),
@ -710,6 +758,21 @@ class formClass {
'#weight' => -1,
);
}
if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
$form['fieldset']['control_group'] = array(
'#type' => 'select',
'#title' => t('Control group'),
'#options' => array(
'X' => t('Inline XML'),
'M' => t('Managed datastream'),
'E' => t('Externally Referenced/managed datastream'),
'R' => t('Redirect datastream'),
),
'#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'),
'#weight' => 0,
);
}
return $form;
}
@ -724,15 +787,12 @@ class formClass {
* @return string
*/
function createQDCEditForm($pid, $dsid, $client, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$dsid = empty($dsid) ? 'QDC' : $dsid;
try {
$params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => "");
$object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) {
return array();
}
$content = $object->dissemination->stream;
$content = trim($content);
$item = new fedora_item($pid);
$content = trim($item->get_datastream_dissemination($dsid));
$doc = new DOMDocument();
if (!$doc->loadXML($content)) {
echo "error loading xml";
@ -836,12 +896,33 @@ class formClass {
$form = array();
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#description' => t('The file to upload.')
);
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$info = $item->get_datastream_info($dsId);
$control_group = $info->datastream->controlGroup;
if (in_array($control_group, array('M', 'X'))) {
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#description' => t('A file with which to replace the contents of this datastream.'),
);
}
if ($control_group != 'X') {
$form['reference'] = array(
'#type' => 'textfield',
'#title' => t('Reference to object'),
'#description' => t('A URL the datastream will be updated to reference.'),
);
}
if ($control_group == 'M') {
$form['note'] = array(
'#type' => 'item',
'#title' => t('NOTE'),
'#value' => t('If both a file and a reference are given, the file will be given preference.'),
);
}
$form['pid'] = array(
'#type' => 'value',
'#value' => $pid,

0
xsl/convertQDC.xsl → object_details_xslts/convertQDC.xsl

232
object_details_xslts/mods2html.xsl

@ -0,0 +1,232 @@
<xsl:stylesheet xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="mods" version="1.0">
<xsl:output indent="yes" method="html"/>
<xsl:variable name="dictionary" select="document('http://www.loc.gov/standards/mods/modsDictionary.xml')/dictionary"/>
<xsl:template match="/">
<html>
<head>
<style type="text/css">
.modsLabelTop {
}
.modsLabelLevel2 {
padding-left: 10px;
}
.modsLabelLevel3 {
padding-left: 20px;
}
.modsLabelLevel4 {
padding-left: 30px;
}
.modsValueTop {
}
.modsValueLevel2 {
}
.modsValueLevel3 {
}
</style>
</head>
<body>
<xsl:choose>
<xsl:when test="mods:modsCollection">
<xsl:apply-templates select="mods:modsCollection"/>
</xsl:when>
<xsl:when test="mods:mods">
<xsl:apply-templates select="mods:mods"/>
</xsl:when>
</xsl:choose>
</body>
</html>
</xsl:template>
<xsl:template match="mods:modsCollection">
<xsl:apply-templates select="mods:mods"/>
</xsl:template>
<xsl:template match="mods:mods">
<table class="modsContainer">
<xsl:apply-templates/>
</table>
<!--hr/-->
</xsl:template>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelTop">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>:
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level2"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelTop">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueTop">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="formatValue">
<xsl:choose>
<xsl:when test="@type='uri'">
<a href="{text()}" class="modsLink">
<xsl:value-of select="text()"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level2">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelLevel2">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level3"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelLevel2">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel2">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level3">
<xsl:choose>
<xsl:when test="child::*">
<tr><td colspan="2">
<span class="modsLabelLevel3">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td></tr>
<xsl:apply-templates mode="level4"/>
</xsl:when>
<xsl:otherwise>
<tr><td>
<span class="modsLabelLevel3">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel3">
<xsl:call-template name="formatValue"/>
</span>
</td></tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="level4">
<tr><td>
<span class="modsLabelLevel4">
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="local-name()"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="attr"/>
</span>
</td><td>
<span class="modsValueLevel4">
<xsl:value-of select="text()"/>
</span>
</td></tr>
</xsl:template>
<xsl:template name="longName">
<xsl:param name="name"/>
<xsl:choose>
<xsl:when test="$dictionary/entry[@key=$name]">
<xsl:value-of select="$dictionary/entry[@key=$name]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="attr">
<xsl:for-each select="@type|@point">:
<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="."/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="@authority or @edition">
<xsl:for-each select="@authority">(<xsl:call-template name="longName">
<xsl:with-param name="name">
<xsl:value-of select="."/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="@edition">
Edition <xsl:value-of select="@edition"/>
</xsl:if>)
</xsl:if>
<xsl:variable name="attrStr">
<xsl:for-each select="@*[local-name()!='edition' and local-name()!='type' and local-name()!='authority' and local-name()!='point']">
<xsl:value-of select="local-name()"/>="<xsl:value-of select="."/>",
</xsl:for-each>
</xsl:variable>
<xsl:variable name="nattrStr" select="normalize-space($attrStr)"/>
<xsl:if test="string-length($nattrStr)">
(<xsl:value-of select="substring($nattrStr,1,string-length($nattrStr)-1)"/>)
</xsl:if>
</xsl:template>
</xsl:stylesheet>

25
plugins/FedoraObjectDetailedContent.inc

@ -32,7 +32,6 @@ class FedoraObjectDetailedContent {
*/
public function showFieldSets() {
global $user;
drupal_set_title($this->item->objectProfile->objLabel);
$objectHelper = new ObjectHelper();
$tabset = array();
$show_purge_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_purge_object_form');
@ -48,8 +47,28 @@ class FedoraObjectDetailedContent {
$tabset['fedora_object_details']['tabset'] = array(
'#type' => 'tabset',
);
$dc_html = $objectHelper->getFormattedDC($this->item);
module_load_include('inc', 'fedora_repository', 'ObjectDetails');
$object_details_profile = variable_get('islandora_object_details_display_table', 'xslt');
$profiles = module_invoke_all("islandora_object_details_display");
$profile = $profiles[$object_details_profile];
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);
}
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);
}
else {
// problem - display profile not found
watchdog('fedora_repository', "Error - could not find object details display function @function", array('@function' => $details_function), WATCHDOG_WARNING);
}
}
$i = 0;
if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {

3
plugins/tagging_form.inc

@ -61,10 +61,11 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
$tagset = new TagSet($obj);
$tags = array();
foreach ($tagset->tags as $tag) {
$form_tag = $form['tags-wrapper']['tags'][$tag['name']] = array(
$form['tags-wrapper']['tags'][$tag['name']] = array(
'#prefix' => '<li>',
'#suffix' => '</li>',
);
$form_tag =& $form['tags-wrapper']['tags'][$tag['name']];
$tag_title_text = t('Added by @creator.', array(
'@creator' => $tag['creator'],

34
xsl/convertQDC.xsl.deprecated

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This was how the metadata in the 'Fedora Object Details' tab was rendered. Can be renamed back to 'convertQDC.xsl' (without '.deprecated') to make it be used again. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Old parameter names "$baseUrl" and "$path" are deprecated. Currently just used as defaults. -->
<xsl:param name="BASEURL" select="$baseUrl"/>
<xsl:param name="PATH" select="$path"/>
<xsl:template match="/">
<div>
<table cellspacing="3" cellpadding="3">
<tbody>
<tr>
<th colspan="3"><h3>MetaData</h3></th>
</tr>
<xsl:for-each select="/*/*">
<xsl:variable name="FULLFIELD" select="name()"/>
<xsl:variable name="FIELD" select="local-name()"/>
<xsl:variable name="DATA" select="normalize-space(text())"/>
<xsl:if test="$DATA">
<tr>
<td><strong><xsl:value-of select="local-name()"/></strong></td>
<td><xsl:value-of select="$DATA"/>
<xsl:for-each select="*">
<div><xsl:value-of select="concat(local-name(), ' = ', text())"/></div>
</xsl:for-each>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</tbody>
</table>
</div>
</xsl:template>
</xsl:stylesheet>

31
xsl/sparql_to_html.xsl

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://www.w3.org/2001/sw/DataAccess/rf1/result" version="1.0" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<!-- Red and White XSLT -->
<xsl:variable name="BASEURL" select="$baseUrl"/>
<xsl:variable name="PATH" select="$path"/>
<xsl:variable name="thisPid" select="$collectionPid"/>
<xsl:output method="xml" encoding="UTF-8"/>
<!-- Red and White XSLT -->
<xsl:param name="BASEURL" select="$baseUrl"/>
<xsl:param name="PATH" select="$path"/>
<xsl:param name="thisPid" select="$collectionPid"/>
<xsl:param name="page" select="$hitPage"/>
<xsl:param name="COLLECTION_TITLE" select="$collectionTitle"/>
<xsl:param name="imagecache_preset">fedora_repository_collection_thumbnail</xsl:param>
<xsl:variable name="size" select="20"/>
<xsl:variable name="page" select="$hitPage"/>
<xsl:variable name="start" select="((number($page) - 1) * number($size)) + 1"/>
<xsl:variable name="end" select="($start - 1) + number($size)"/>
<xsl:variable name="cellsPerRow" select="4"/>
@ -42,7 +46,7 @@
<li class="pager-previous">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page - 1)"/>
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $thisPid, '/-/Collection/', $page - 1))"/>
</xsl:attribute>
&lt;Prev
</a>
@ -53,7 +57,7 @@
<li class="pager-next">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page + 1)"/>
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $thisPid, '/-/Collection/', $page + 1))"/>
</xsl:attribute>
Next>
</a>
@ -64,7 +68,7 @@
<li class="pager-previous">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page - 1)"/>
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $thisPid, '/-/Collection/', $page - 1))"/>
</xsl:attribute>
&lt;Prev
</a>&#160;
@ -72,7 +76,7 @@
<li class="pager-next">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page + 1)"/>
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $thisPid, '/-/Collection/', $page + 1))"/>
</xsl:attribute>
Next>
</a>
@ -101,12 +105,12 @@
<xsl:variable name="linkUrl">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/-/collection')"/>
<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="concat($BASEURL, '/fedora/repository/', $PID)"/>
<xsl:value-of select="php:functionString('url', concat('fedora/repository/', $PID))"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="s:content"/>
@ -116,10 +120,11 @@
<xsl:attribute name="href">
<xsl:value-of select="$linkUrl"/>
</xsl:attribute>
<img>
<xsl:copy-of select="php:function('fedora_repository_string_to_domnode', php:functionString('fedora_repository_render_image', $PID, 'TN', $imagecache_preset))"/>
<!-- <img>
<xsl:attribute name="src"><xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/TN')"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$newTitle" disable-output-escaping="yes"/></xsl:attribute>
</img>
</img> -->
</a><br clear="all" />
<a>
<xsl:attribute name="href"><xsl:value-of select="$linkUrl"/>

Loading…
Cancel
Save