Browse Source

Merge pull request #99 from adam-vessey/6.x

6.x
pull/100/merge
Jonathan Green 13 years ago
parent
commit
dd475a8c80
  1. 339
      CollectionClass.inc
  2. 444
      ObjectHelper.inc
  3. 4
      fedora_repository.install
  4. 2
      fedora_repository.module
  5. 8
      formClass.inc
  6. 24
      plugins/FedoraObjectDetailedContent.inc
  7. 5
      plugins/ShowDemoStreamsInFieldSets.inc
  8. 42
      plugins/ShowStreamsInFieldSets.inc
  9. 4
      plugins/herbarium.inc
  10. 99
      plugins/qt_viewer.inc
  11. 6
      plugins/slide_viewer.inc
  12. 30
      plugins/tagging_form.inc
  13. 6
      xsl/convertQDC.xsl
  14. 398
      xsl/sparql_to_html.xsl

339
CollectionClass.inc

@ -6,11 +6,6 @@
* Collection Class Class * Collection Class Class
*/ */
if (!defined('PHP_VERSION_ID')) { //XXX: This should go elsewhere
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
/** /**
* This CLASS caches the streams so once you call a getstream once it will always return * This CLASS caches the streams so once you call a getstream once it will always return
* the same stream as long as you are using the instance of this class. Cached to * the same stream as long as you are using the instance of this class. Cached to
@ -39,79 +34,110 @@ class CollectionClass {
$this->pid = $pid; $this->pid = $pid;
} }
} }
public static function getCollectionQuery($pid) {
if ($query = self::getCollectionQueryFromStream($pid)) {
return $query;
}
else {
return self::getDefaultCollectionQuery($pid);
}
}
protected static function getCollectionQueryFromStream($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
return $item->get_datastream_dissemination('QUERY');
}
else {
return FALSE;
}
}
protected static function getDefaultCollectionQuery($pid) {
return 'select $object $title $content from <#ri>
where ($object <fedora-model:label> $title
and $object <fedora-model:hasModel> $content
and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '>
or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title';
}
/** /**
* gets objects related to this object. must include offset and limit * Gets objects related to this object. Must include offset and limit!
* calls getRelatedItems but enforces limit and offset *
* @param type $pid * Calls self::getRelatedItems() but requires limit and offset.
* @param type $limit *
* @param $pid string
* A string containing a Fedora PID.
* @param $limit
* An integer
* @param type $offset * @param type $offset
* @param type $itqlquery * @param type $itqlquery
* @return type * @return type
*/ */
function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) {
if (!isset($itqlquery)) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$itqlquery = $item->get_datastream_dissemination('QUERY');
}
}
return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); return $this->getRelatedItems($pid, $itqlquery, $limit, $offset);
} }
/** /**
* Gets objects related to this item. It will query the object for a Query stream and use that as a itql query * Gets objects related to this item.
* or if there is no query stream it will use the default. If you pass a query to this method it will use the passed in query no matter what *
* @global type $user * Query the resource index using the provided iTQL query. If no query is
* @param type $pid * provided, one should be obtained via self::getCollectionQuery() which
* @param type $itqlquery * grabs the child objects.
* @param int $limit *
* @param $pid string
* A string containing a PID which may be substituted into the query,
* in place of the %parent_collection% placeholder.
* @param $query_string string
* An optional iTQL query.
* @param $limit int
* An optional integer to limit the number of results returned.
* @param int $offset * @param int $offset
* @return type * An optional integer used to offset the results returned. (Query should
* involve a sort to maintain consistency.
* @return string
* Sparql XML results from the resource index.
*/ */
function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
if (!isset($offset)) {
$offset = 0; if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) {
}
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'); drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
return ' '; return ' ';
} }
$objectHelper = new ObjectHelper();
$query_string = $itqlquery; if ($query_string === NULL) {
if (!isset($query_string)) { $query_string = self::getCollectionQuery($pid);
$query_string = NULL;
$item = new Fedora_Item($pid);
if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
$query_string = $item->get_datastream_dissemination('QUERY');
}
if ($query_string == NULL) {
$query_string = 'select $object $title $content from <#ri>
where ($object <fedora-model:label> $title
and $object <fedora-model:hasModel> $content
and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '>
or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title';
}
}
else {
// Replace %parent_collection% with the actual collection PID
$query_string = preg_replace("/\%parent_collection\%/", "<info:fedora/$pid>", $query_string);
} }
$query_string = htmlentities(urlencode($query_string)); // Replace %parent_collection% with the actual collection PID
$query_string = preg_replace("/\%parent_collection\%/", "<info:fedora/$pid>", $query_string);
$content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query_string;
$content .= do_curl($url); $settings = array(
'type' => 'tuples',
'flush' => TRUE,
'format' => 'Sparql',
'lang' => 'itql',
'stream' => 'on',
'query' => $query_string
);
if ($limit > 0) {
$settings['limit'] = $limit;
}
if ($offset > 0) {
$settings['offset'] = $offset;
}
$url .= '?' . http_build_query($settings, NULL, '&');
$content = do_curl($url);
return $content; return $content;
} }
@ -490,9 +516,12 @@ class CollectionClass {
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collectionClass = new CollectionClass(); $collectionClass = new CollectionClass();
$xslContent = $collectionClass->getCollectionViewStream($pid); $xslContent = $collectionClass->getCollectionViewStream($pid);
if (!$xslContent && $canUseDefault) { //no xslt so we will use the default sent with the module
//If there's no XSLT from the object, then check if the one which used to exist, does...
if (!$xslContent && $canUseDefault && file_exists($path . '/xsl/sparql_to_html.xsl')) {
$xslContent = file_get_contents($path . '/xsl/sparql_to_html.xsl'); $xslContent = file_get_contents($path . '/xsl/sparql_to_html.xsl');
} }
return $xslContent; return $xslContent;
} }
@ -519,7 +548,6 @@ class CollectionClass {
$results = $this->getRelatedItems($this->pid, $query); $results = $this->getRelatedItems($this->pid, $query);
$collection_items = $this->renderCollection($results, $this->pid, NULL, NULL, $page_number); $collection_items = $this->renderCollection($results, $this->pid, NULL, NULL, $page_number);
//$collection_item = new Fedora_Item($this->pid); //XXX: This didn't seem to be used...
$show_batch_tab = FALSE; $show_batch_tab = FALSE;
$policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE);
@ -554,17 +582,6 @@ class CollectionClass {
'#tab_name' => 'add-tab', '#tab_name' => 'add-tab',
); );
} }
if ($show_batch_tab && user_access('create batch process')) { //XXX: Is this not put in by the batch module?
$tabset['batch_ingest_tab'] = array(
// #type and #title are the minimum requirements.
'#type' => 'tabpage',
'#title' => t('Batch Ingest'),
// This will be the content of the tab.
'#content' => drupal_get_form('batch_creation_form', $this->pid, $content_models),
'#tab_name' => 'batch-ingest-tab',
);
}
return $tabset; return $tabset;
} }
@ -575,10 +592,8 @@ class CollectionClass {
* @return string * @return string
*/ */
function getIngestInterface() { function getIngestInterface() {
global $base_url;
$objectHelper = new ObjectHelper();
module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy'); module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy');
$collectionPolicyExists = $objectHelper->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); $collectionPolicyExists = $this->collectionObject->getMimeType($this->pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) { if (!empty($collectionPolicyExists)) {
$allow = TRUE; $allow = TRUE;
@ -597,6 +612,66 @@ class CollectionClass {
return $ingestObject; return $ingestObject;
} }
/**
* Unfortunate function, I know...
*
* Does just what it says: Hacks the default Drupal pager such that it might
* be rendered, likely with: theme('pager', array(), $per_page, $pager_name)
* (I reccomend seeing the real documentation for more detail, but the first
* array can be a list of the tags to use for first, previous, next and last
* (text in the pager), I don't believe per_page is actually used in the theme
* function, and $pager_name is an integer used to identify the pager (such
* that there can be more than one--that is, tracking different lists of
* content on a single page. You can render the exact same pager multiple
* times, say if you want one at the top and bottom of a list, using the same
* ID/pager_name.
*
* @global $pager_total array
* Numerically indexed array, where keys are the $pager_names and values
* are the number of pages in the given set, based on: ceil($total_items/$per_page);
* @global $pager_page_array array
* Numerically indexed array, where keys are the $pager_names and values
* are the page selected in the relevant set.
* @param $pager_name int
* An integer to identify the pager to affect. Do note that paging in using
* this function will add the 'page' HTTP GET parameter to the URL, with
* the value containing a comma-separated list with max($pager_name + 1)
* values--that is, if you create a single pager named '10', the 'next'
* link will look something like: 0,0,0,0,0,0,0,0,0,0,1
* @param $per_page int
* An integer representing the number of items per page.
* @param $total_items int
* An integer representing the total number of items in the set.
* @return int
* An integer representing what the current page should be.
*/
protected static function hackPager($pager_name, $per_page = NULL, $total_items = NULL) {
global $pager_total, $pager_page_array;
if ($per_page !== NULL && $total_items !== NULL) {
$pager_total[$pager_name] = ceil($total_items / $per_page);
}
//XXX: Don't know that this is neccessary, to try to load all the time, or
// whether Drupal will load it automatically somewhere... Docs seems a
// a little sparse.
$page_info = explode(',', isset($_GET['page']) ? $_GET['page'] : '');
$page = $page_info[$pager_name];
if ($page < 0) {
$page = 0;
}
if (!isset($pager_page_array)) {
$pager_page_array = pager_load_array($page, $pager_name, $page_info);
}
else {
$pager_page_array = pager_load_array($page, $pager_name, $pager_page_array);
}
$page = $pager_page_array[$pager_name];
return $page;
}
/** /**
* render collection * render collection
* @global type $base_url * @global type $base_url
@ -611,69 +686,107 @@ class CollectionClass {
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
global $base_url; global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe $collection_pid = $pid; //we will be changing the pid later maybe
$objectHelper = new ObjectHelper();
$parsedContent = NULL; $parsedContent = NULL;
$contentModels = $objectHelper->get_content_models_list($pid); $contentModels = $this->collectionObject->get_content_models_list($pid);
$isCollection = FALSE; $isCollection = FALSE;
//if this is a collection object store the $pid in the session as it will come in handy //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. //after a purge or ingest to return to the correct collection.
$fedoraItem = NULL; $fedoraItem = NULL;
if (!$pageNumber) {
$pageNumber = 1;
}
if (empty($collectionName)) { if (empty($collectionName)) {
$collectionName = menu_get_active_title(); $collectionName = menu_get_active_title();
} }
$xslContent = $this->getXslContent($pid, $path); $xslContent = $this->getXslContent($pid, $path);
//get collection list and display using xslt-------------------------------------------
$objectList = ''; $objectList = '';
if (isset($content) && $content != FALSE) { if (isset($content) && $content != FALSE) {
$input = new DomDocument(); if (!$xslContent) { //Didn't find an XSLT.
$input->loadXML(trim($content)); $intermediate_results = ObjectHelper::parse_sparql_results($content);
$results = $input->getElementsByTagName('result'); unset($content);
if ($results->length > 0) {
try { $per_page = 20; //XXX: Make this configurable.
$proc = new XsltProcessor(); $pager_name = 0;
$options = array( //Could make this the return of a hook? $total = count($intermediate_results);
'collectionPid' => $collection_pid, $pager_page = self::hackPager($pager_name, $per_page, $total);
'collectionTitle' => $collectionName,
'baseUrl' => $base_url, $results = array();
'path' => "$base_url/$path", foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) {
'hitPage' => $pageNumber, $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 (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50100) { 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);
}
}
else {
if (!$pageNumber) {
$pageNumber = 1;
}
//get collection list and display using xslt-------------------------------------------
$input = new DomDocument();
$input->loadXML(trim($content));
$results = $input->getElementsByTagName('result');
if ($results->length > 0) {
try {
$proc = new XsltProcessor();
$options = array( //Could make this the return of a hook?
'collectionPid' => $collection_pid,
'collectionTitle' => $collectionName,
'baseUrl' => $base_url,
'path' => "$base_url/$path",
'hitPage' => $pageNumber,
);
$proc->setParameter('', $options); $proc->setParameter('', $options);
}
else {
foreach ($options as $name => $value) {
$proc->setParameter('', $name, $value);
}
}
$proc->registerPHPFunctions(); $proc->registerPHPFunctions();
$xsl = new DomDocument(); $xsl = new DomDocument();
$xsl->loadXML($xslContent); $xsl->loadXML($xslContent);
// php xsl does not seem to work with namespaces so removing it below // php xsl does not seem to work with namespaces so removing it below
// I may have just been being stupid here // I may have just been being stupid here
// $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content); // $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content);
$xsl = $proc->importStylesheet($xsl); $xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input); $newdom = $proc->transformToDoc($input);
$objectList = $newdom->saveXML(); //is the xml transformed to html as defined in the xslt associated with the collection object $objectList = $newdom->saveHTML(); //is the xml transformed to html as defined in the xslt associated with the collection object
if (!$objectList) { if (!$objectList) {
throw new Exception("Invalid XML."); throw new Exception("Invalid XML.");
}
} catch (Exception $e) {
drupal_set_message(check_plain($e->getMessage()), 'error');
return '';
} }
} catch (Exception $e) {
drupal_set_message(check_plain($e->getMessage()), 'error');
return '';
} }
} }
} }

444
ObjectHelper.inc

@ -313,36 +313,42 @@ class ObjectHelper {
function create_link_for_ds($pid, $dataStreamValue) { function create_link_for_ds($pid, $dataStreamValue) {
global $base_url; global $base_url;
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
require_once($path . '/api/fedora_item.inc');
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$purge_image = '&nbsp;';
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { if ($allow) {
$purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' . $purge_text = t('Purge datastream "@label"', array('@label' => $dataStreamValue->label));
$pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . $purge_path = "fedora/repository/purgeStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}";
'/images/purge.gif" alt="purge datastream" /></a>'; $purge_image = l(theme('image', "$path/images/purge.gif", $purge_text, $purge_text, NULL, FALSE), $purge_path, array(
'html' => TRUE,
));
} }
} }
else { else {
$purgeImage = '&nbsp;'; $purge_image = '&nbsp;';
} }
$fullPath = base_path() . $path;
// Add an icon to replace a datastream // Add an icon to replace a datastream
// @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled. // @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled.
$replaceImage = '&nbsp;'; $replace_image = '&nbsp;';
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { if ($allow) {
$replaceImage = '<a title="' . t("Replace datastream") . " " . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/replaceStream/' . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . '/images/replace.png" alt="replace datastream" /></a>'; $replace_text = t('Replace datastream "@label"', array('@label' => $dataStreamValue->label));
$replace_path = "fedora/repository/replaceStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}";
$replace_image = l(theme('image', "$path/images/replace.png", $replace_text, $replace_text, NULL, FALSE), $replace_path, array(
'html' => TRUE,
));
} }
} }
@ -350,13 +356,17 @@ class ObjectHelper {
$id = $dataStreamValue->ID; $id = $dataStreamValue->ID;
$label = $dataStreamValue->label; $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; $mimeType = $dataStreamValue->MIMEType;
$view = '<a href="' . $base_url . '/fedora/repository/' . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode($label) . $view = l(t('View'), "'fedora/repository/$pid/$id/$label_deslashed", array(
'" target="_blank" >' . t('View') . '</a>'; 'attributes' => array(
$action = "$base_url/fedora/repository/object_download/" . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode(preg_replace('/\//i', '${1}_', $label)); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. '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>'; $downloadVersion = '<form method="GET" action="' . $action . '"><input type="submit" value="' . t('Download') . '"></form>';
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$versions = $item->get_datastream_history($id); $versions = $item->get_datastream_history($id);
if (is_array($versions)) { if (is_array($versions)) {
$downloadVersion = '<form method="GET" action="' . $action . '" onsubmit="this.action=\'' . $action . '\' + \'/\'+this.version.value;">'; $downloadVersion = '<form method="GET" action="' . $action . '" onsubmit="this.action=\'' . $action . '\' + \'/\'+this.version.value;">';
@ -369,8 +379,23 @@ class ObjectHelper {
} }
} }
$content .= "<tr><td>$label</td><td>&nbsp;$view</td><td>&nbsp;$downloadVersion</td><td>&nbsp;$mimeType</td><td>&nbsp;$replaceImage&nbsp;$purgeImage</td></tr>\n"; return array(
return $content; array(
'data' => $label,
),
array(
'data' => $view,
),
array(
'data' => $downloadVersion,
),
array(
'data' => $mimeType
),
array(
'data' => $replace_image . $purge_image,
),
);
} }
/** /**
@ -386,34 +411,36 @@ class ObjectHelper {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
$xmlstr = $item->get_datastream_dissemination($dsid); $xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr)) { if (empty($xmlstr)) {
return ''; return '';
} }
$simplexml = new SimpleXMLElement($xmlstr);
try { $headers = array(
$proc = new XsltProcessor(); array(
} catch (Exception $e) { 'data' => t('Metadata'),
drupal_set_message($e->getMessage(), 'error'); 'colspan' => 2,
return; ),
);
$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',
),
);
}
} }
$proc->setParameter('', 'baseUrl', $base_url); return theme('table', $headers, $rows, array('class' => 'dc-table'));
$proc->setParameter('', 'path', $base_url . '/' . $path);
$input = NULL;
$xsl = new DomDocument();
try {
$xsl->load($path . '/xsl/convertQDC.xsl');
$input = new DomDocument();
$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;
} }
/** /**
@ -432,16 +459,17 @@ class ObjectHelper {
$dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC'; $dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC';
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
//$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1));
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { if ($allow) {
$link_image = theme('image', "$path/images/edit.gif", t('Edit Metadata'));
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' . $link = l($link_image, "fedora/repository/editmetadata/$pid", array(
$dsid . '"><img src="' . $base_url . '/' . $path . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>'; 'html' => TRUE,
));
$output .= '<br />' . $link;
} }
} }
return $output; return $output;
@ -461,7 +489,7 @@ class ObjectHelper {
* *
*/ */
function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) { function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) {
global $fedoraUser, $fedoraPass, $base_url, $user; global $base_url, $user;
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -473,58 +501,42 @@ class ObjectHelper {
if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) { if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) {
$availableDataStreamsText = 'Detailed List of Content'; $availableDataStreamsText = 'Detailed List of Content';
//$metaDataText='Description';
$mainStreamLabel = NULL; $mainStreamLabel = NULL;
$object = $fedoraItem->get_datastreams_list_as_SimpleXML(); $object = $fedoraItem->get_datastreams_list_as_SimpleXML();
if (!isset($object)) { if (!isset($object)) {
drupal_set_message(t("No datastreams available")); drupal_set_message(t("No datastreams available"));
return ' '; return ' ';
} }
$hasOBJStream = NULL;
$hasTNStream = FALSE;
$dataStreamBody = "<br /><table>\n";
$cmDatastreams = array(); $cmDatastreams = array();
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE && ($cm = ContentModel::loadFromObject($object_pid)) !== FALSE) { if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE && ($cm = ContentModel::loadFromObject($object_pid)) !== FALSE) {
$cmDatastreams = $cm->listDatastreams(); $cmDatastreams = $cm->listDatastreams();
} }
$dataStreamBody .= $this->get_parent_objects_asHTML($object_pid); $headers = array(
$dataStreamBody .= '<tr><th colspan="4"><h3>' . t("!text", array('!text' => $availableDataStreamsText)) . '</h3></th></tr>'; array(
'data' => $availableDataStreamsText,
'colspan' => 4,
),
);
$DSs = array();
foreach ($object as $datastream) { foreach ($object as $datastream) {
foreach ($datastream as $datastreamValue) { foreach ($datastream as $datastreamValue) {
if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) { if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) {
if ($datastreamValue->ID == 'OBJ') {
$hasOBJStream = '1';
$mainStreamLabel = $datastreamValue->label;
$mainStreamLabel = str_replace("_", " ", $mainStreamLabel);
}
if ($datastreamValue->ID == 'TN') {
$hasTNStream = TRUE;
}
//create the links to each datastream //create the links to each datastream
$dataStreamBody .= $this->create_link_for_ds($object_pid, $datastreamValue); //"<tr><td><b>$key :</b></td><td>$value</td></tr>\n"; $DSs []= $this->create_link_for_ds($object_pid, $datastreamValue);
} }
} }
} }
$dataStreamBody .= "</table>\n";
$dataStreamBody = theme('table', $headers, $DSs);
//if they have access let them add a datastream //if they have access let them add a datastream
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { if (user_access(ObjectHelper::$ADD_FEDORA_STREAMS) && //If allowed throw Drupal
$allow = TRUE; ((module_exists('fedora_fesl') && fedora_fesl_check_roles($object_pid, 'write')) || //And allowed throw FESL
if (module_exists('fedora_fesl')) { !module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form.
$allow = fedora_fesl_check_roles($object_pid, 'write'); $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
}
if ($allow) {
$dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
}
} }
$fieldset = array(
'#title' => t("!text", array('!text' => $availableDataStreamsText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $dataStreamBody
);
$dataStreamBody = '<div class = "fedora_detailed_list">' . theme('fieldset', $fieldset) . '</div>';
return $dataStreamBody; return $dataStreamBody;
} }
@ -616,55 +628,44 @@ class ObjectHelper {
* @param type $pid * @param type $pid
* @return type * @return type
*/ */
function fedora_repository_access($op, $pid) { function fedora_repository_access($op, $pid = NULL, $as_user = NULL) {
global $user;
$returnValue = FALSE; $returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if (!$isRestricted) {
$namespaceAccess = TRUE;
}
if ($pid == NULL) { if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:root'); $pid = variable_get('fedora_repository_pid', 'islandora:root');
} }
$nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$pos = NULL; $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
foreach ($nameSpaceAllowed as $nameSpace) { $namespace_access = NULL;
$pos = stripos($pid, $nameSpace); if (!$isRestricted) {
if ($pos === 0) { $namespace_access = TRUE;
$namespaceAccess = TRUE;
}
}
if ($namespaceAccess) {
$user_access = user_access($op);
if ($user_access == NULL) {
return FALSE;
}
return $user_access;
} }
else { else {
return FALSE; $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon)
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$namespace_access = in_array($pid_namespace, $allowed_namespaces);
} }
return ($namespace_access && user_access($op, $as_user));
} }
/** /**
* internal function * internal function
* uses an xsl to parse the sparql xml returned from the ITQL query * 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 * @param $content String
*/ */
function parseContent($content, $pid, $dsId, $collection, $pageNumber = NULL) { function parseContent($content, $pid, $dsId, $collection, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
global $base_url; global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe $collection_pid = $pid; //we will be changing the pid later maybe
//module_load_include('php', ''Fedora_Repository'', 'ObjectHelper');
$objectHelper = $this; $objectHelper = $this;
$parsedContent = NULL; $parsedContent = NULL;
$contentModels = $objectHelper->get_content_models_list($pid); $contentModels = $this->get_content_models_list($pid);
$isCollection = FALSE; $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; $fedoraItem = NULL;
$datastreams = $this->get_formatted_datastream_list($pid, $contentModels, $fedoraItem); $datastreams = $this->get_formatted_datastream_list($pid, $contentModels, $fedoraItem);
@ -672,6 +673,9 @@ class ObjectHelper {
if (!empty($contentModels)) { if (!empty($contentModels)) {
foreach ($contentModels as $contentModel) { foreach ($contentModels as $contentModel) {
if ($contentModel == variable_get('fedora_collection_model_pid', 'islandora:collectionCModel')) { 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; $_SESSION['fedora_collection'] = $pid;
$isCollection = TRUE; $isCollection = TRUE;
} }
@ -689,8 +693,8 @@ class ObjectHelper {
if ($results->length > 0 || $isCollection == TRUE) { 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 // 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'); module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy');
$collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID()); $collectionPolicyExists = $this->getMimeType($pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) { if (!empty($collectionPolicyExists)) {
$allow = TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
@ -698,9 +702,11 @@ class ObjectHelper {
} }
if ($allow) { if ($allow) {
// $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() . // $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
$ingestObject = '<a title="' . t('Ingest a New object into !collection_name PID !collection_pid', array('!collection_name' => $collectionName, '!collection_pid' => $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));
'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '"><img src="' . $base_url . '/' . $path . $ingestObject = l(theme('image', "$path/images/ingest.png", $ingest_text), "fedora/ingestObject/$collection_pid/$collectionName", array('attributes' => array(
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a> ' . t('Add to this Collection'); 'class' => 'icon',
'title' => $ingest_text,
))) . t('Add to this Collection');
} }
} }
} }
@ -745,19 +751,35 @@ class ObjectHelper {
return $output; return $output;
} }
/**
* Get the query to find parent objects.
*
* @param $pid string
* A string containing a Fedora PID to find the parents for.
* @return string
* A string containing an iTQL query, selecting something into $object and $title
*/
static function parentQuery($pid) {
return 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $object
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
}
/** /**
* Gets the parent objects that this object is related to * Gets the parent objects that this object is related to
* *
* @param unknown_type $pid * @param $pid string
* @return unknown * A string containing a Fedora PID to find the parents for.
* @return string
* A string containing Sparql XML (the results of the self::parentQuery())
*/ */
function get_parent_objects($pid) { function get_parent_objects($pid) {
$query_string = 'select $object $title from <#ri> $query_string = self::parentQuery();
where ($object <fedora-model:label> $title module_load_include('inc', 'fedora_repository', 'CollectionClass');
and <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $object $collection_class = new CollectionClass($pid);
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>) $objects = CollectionClass::getRelatedItems($pid, $query_string);
order by $title';
$objects = $this->getCollectionInfo($pid, $query_string);
return $objects; return $objects;
} }
@ -768,31 +790,24 @@ class ObjectHelper {
* @return string * @return string
*/ */
function get_parent_objects_asHTML($pid) { function get_parent_objects_asHTML($pid) {
global $base_url; module_load_include('inc', 'fedora_repository', 'CollectionClass');
$parent_collections = $this->get_parent_objects($pid); $results = self::performItqlQuery(self::parentQuery($pid));
try {
$parent_collections = new SimpleXMLElement($parent_collections); $parent_collections = array();
} catch (exception $e) { foreach ($results as $result) {
drupal_set_message(t('Error getting parent objects @e', array('@e' => check_plain($e->getMessage())))); $collection_title = $result['title'];
return; $collection_pid = $result['object'];
} $path = "fedora/repository/$collection_pid/-/$collection_title";
$parent = array(
$parent_collections_HTML = ''; 'data' => l($collection_title, $path),
foreach ($parent_collections->results->result as $result) { );
$collection_label = $result->title;
foreach ($result->object->attributes() as $a => $b) { $parent_collections[] = $parent;
if ($a == 'uri') {
$uri = (string) $b;
$uri = $base_url . '/fedora/repository' . substr($uri, strpos($uri, '/')) . '/-/' . $collection_label;
}
}
$parent_collections_HTML .= '<a href="' . $uri . '">' . $collection_label . '</a><br />';
} }
if (!empty($parent_collections_HTML)) {
$parent_collections_HTML = '<tr><td><h3>' . t("Belongs to these collections:") . ' </h3></td><td colspan="4">' . $parent_collections_HTML . '</td></tr>'; if (!empty($parent_collections)) {
return theme('item_list', $parent_collections, t('Belongs to these collections'), 'ul');
} }
return $parent_collections_HTML;
} }
/** /**
@ -842,6 +857,8 @@ class ObjectHelper {
/** /**
* Get a tree of related pids - for the basket functionality * Get a tree of related pids - for the basket functionality
* *
* FIXME: This doesn't actually get a tree...
*
* @param type $pid * @param type $pid
* @return type * @return type
*/ */
@ -852,19 +869,18 @@ class ObjectHelper {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
// Get title and descriptions for $pid // Get title and descriptions for $pid
$query_string = 'select $title $desc from <#ri> $query_string = 'select $title $description from <#ri>
where $o <fedora-model:label> $title where $o <fedora-model:label> $title
and $o <dc:description> $desc and $o <dc:description> $desc
and $o <mulgara:is> <info:fedora/' . $pid . '>'; and $o <mulgara:is> <info:fedora/' . $pid . '>';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $results = self::performItqlQuery($query_string);
$url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query_string))); $pids = array();
//There should only be one... Anyway.
$rows = explode("\n", $content); foreach($results as $result) {
$fields = explode(',', $rows[1]); $pids[$pid] = $result;
}
$pids[$pid] = array('title' => $fields[0], 'description' => $fields[1]);
// $pids += $this->get_child_pids(array($pid)); // $pids += $this->get_child_pids(array($pid));
@ -878,38 +894,24 @@ class ObjectHelper {
* @return type * @return type
*/ */
function get_child_pids($pids) { function get_child_pids($pids) {
//Build the parts which are used to filter to the list of input.
$query_chunks = array();
foreach ($pids as $pid) {
$query_chunks[] = '$s <mulgara:is> <info:fedora/' . $pid . '>';
}
// Get pid, title and description for children of object $pid // Get pid, title and description for children of object $pid
$query_string = 'select $o $title from <#ri> ' . $query_string = 'select $o $title from <#ri> ' .
// $query_string = 'select $o $title $desc from <#ri> '.
'where $s <info:fedora/fedora-system:def/relations-external#hasMember> $o ' . 'where $s <info:fedora/fedora-system:def/relations-external#hasMember> $o ' .
'and $o <fedora-model:label> $title ' . 'and $o <fedora-model:label> $title ' .
// 'and $o <dc:description> $desc '. 'and ( ' . implode(' or ', $query_chunks) . ' )';
'and ( ';
$results = self::performItqlQuery($query_string);
foreach ($pids as $pid) {
$query_string .= '$s <mulgara:is> <info:fedora/' . $pid . '> or ';
}
$query_string = substr($query_string, 0, -3) . ' )';
$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=";
$url .= htmlentities(urlencode($query_string));
$content = $this->doCurl($url);
$rows = explode("\n", $content);
// Knock of the first heading row
array_shift($rows);
$child_pids = array(); $child_pids = array();
if (count($rows)) { if ($results) {
// iterate through each row // iterate through each row
foreach ($rows as $row) { foreach ($results as $result) {
if ($row == "") { $child_pids[$result['o']] = array('title' => $result['title']);
continue;
}
$fields = explode(',', $row);
$child_pid = substr($fields[0], 12);
$child_pids[$child_pid] = array('title' => $fields[1], 'description' => $fields[2]);
} }
if (!empty($child_pids)) { if (!empty($child_pids)) {
$child_pids += $this->get_child_pids(array_keys($child_pids)); $child_pids += $this->get_child_pids(array_keys($child_pids));
@ -977,7 +979,7 @@ class ObjectHelper {
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title desc'; order by $title desc';
if (count($results = self::perform_itql_query($query_string)) > 0 && $level > 0) { if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) {
$parent = $results[0]['parentObject']; $parent = $results[0]['parentObject'];
$this_title = $results[0]['title']; $this_title = $results[0]['title'];
@ -1016,6 +1018,48 @@ class ObjectHelper {
drupal_set_message(t($configMess . "<br />" . $messMap[$app] . "<hr width='40%' align = 'left'/>", array('%app' => $app)), 'warning', FALSE); drupal_set_message(t($configMess . "<br />" . $messMap[$app] . "<hr width='40%' align = 'left'/>", array('%app' => $app)), 'warning', FALSE);
} }
/**
* Parse the passed in Sparql XML string into a more easily usable format.
*
* @param $sparql string
* A string containing Sparql result XML.
* @return array
* Indexed (numerical) array, containing a number of associative arrays,
* with keys being the same as the variable names in the query.
* URIs beginning with 'info:fedora/' will have this beginning stripped
* off, to facilitate their use as PIDs.
*/
public static function parseSparqlResults($sparql) {
//Load the results into a SimpleXMLElement
$doc = new SimpleXMLElement($sparql, 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result');
$results = array(); //Storage.
//Build the results.
foreach ($doc->results->children() as $result) {
//Built a single result.
$r = array();
foreach ($result->children() as $element) {
$val = NULL;
$attrs = $element->attributes();
if (!empty($attrs['uri'])) {
$val = self::pidUriToBarePid((string)$attrs['uri']);
}
else {
$val = (string)$element;
}
//Map the name to the value in the array.
$r[$element->getName()] = $val;
}
//Add the single result to the set to return.
$results[] = $r;
}
return $results;
}
/** /**
* Performs the given Resource Index query and return the results. * Performs the given Resource Index query and return the results.
* *
@ -1035,7 +1079,7 @@ class ObjectHelper {
* URIs beginning with 'info:fedora/' will have this beginning stripped * URIs beginning with 'info:fedora/' will have this beginning stripped
* off, to facilitate their use as PIDs. * off, to facilitate their use as PIDs.
*/ */
protected static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { static function performRiQuery($query, $type = 'itql', $limit = -1, $offset = 0) {
//Setup the query options... //Setup the query options...
$options = array( $options = array(
'type' => 'tuples', 'type' => 'tuples',
@ -1065,53 +1109,27 @@ class ObjectHelper {
return FALSE; return FALSE;
} }
//Load the results into a SimpleXMLElement //Pass the query's results off to a decent parser.
$doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); return self::parseSparqlResults($curl_result[0]);
$results = array(); //Storage.
//Build the results.
foreach ($doc->results->children() as $result) {
//Built a single result.
$r = array();
foreach ($result->children() as $element) {
$val = NULL;
$attrs = $element->attributes();
if (!empty($attrs['uri'])) {
$val = self::pid_uri_to_bare_pid((string)$attrs['uri']);
}
else {
$val = (string)$element;
}
//Map the name to the value in the array.
$r[$element->getName()] = $val;
}
//Add the single result to the set to return.
$results[] = $r;
}
return $results;
} }
/** /**
* Thin wrapper for self::_perform_ri_query(). * Thin wrapper for self::_performRiQuery().
* *
* @see self::_perform_ri_query() * @see self::performRiQuery()
*/ */
public static function perform_itql_query($query, $limit = -1, $offset = 0) { public static function performItqlQuery($query, $limit = -1, $offset = 0) {
return self::perform_ri_query($query, 'itql', $limit, $offset); return self::performRiQuery($query, 'itql', $limit, $offset);
} }
/** /**
* Thin wrapper for self::_perform_ri_query(). * Thin wrapper for self::performRiQuery().
* *
* @see self::_perform_ri_query() * @see self::_performRiQuery()
*/ */
public static function perform_sparql_query($query, $limit = -1, $offset = 0) { public static function performSparqlQuery($query, $limit = -1, $offset = 0) {
return self::perform_ri_query($query, 'sparql', $limit, $offset); return self::performRiQuery($query, 'sparql', $limit, $offset);
} }
/** /**
* Utility function used in self::_perform_ri_query(). * Utility function used in self::performRiQuery().
* *
* Strips off the 'info:fedora/' prefix from the passed in string. * Strips off the 'info:fedora/' prefix from the passed in string.
* *
@ -1122,7 +1140,7 @@ class ObjectHelper {
* The input string less the 'info:fedora/' prefix (if it has it). * The input string less the 'info:fedora/' prefix (if it has it).
* The original string otherwise. * The original string otherwise.
*/ */
protected static function pid_uri_to_bare_pid($uri) { protected static function pidUriToBarePid($uri) {
$chunk = 'info:fedora/'; $chunk = 'info:fedora/';
$pos = strpos($uri, $chunk); $pos = strpos($uri, $chunk);
if ($pos === 0) { //Remove info:fedora/ chunk if ($pos === 0) { //Remove info:fedora/ chunk

4
fedora_repository.install

@ -63,8 +63,8 @@ function fedora_repository_requirements($phase) {
$requirements['curl']['severity'] = REQUIREMENT_OK; $requirements['curl']['severity'] = REQUIREMENT_OK;
} }
// Test for DOM // Test for DOM
$requirements['dom']['title'] = $t("PHP DOM XML extension library"; $requirements['dom']['title'] = $t("PHP DOM XML extension library");
if (!method_exists('DOMDocument', 'loadHTML')) { if (!method_exists('DOMDocument', 'loadHTML')) {
$requirements['dom']['value'] = $t("Not installed"); $requirements['dom']['value'] = $t("Not installed");
$requirements['dom']['severity'] = REQUIREMENT_ERROR; $requirements['dom']['severity'] = REQUIREMENT_ERROR;

2
fedora_repository.module

@ -869,7 +869,7 @@ function fedora_repository_perm() {
* @param type $account * @param type $account
* @return type * @return type
*/ */
function fedora_repository_access($op, $node, $account) { function fedora_repository_access($op, $node = NULL, $account = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
return $objectHelper->fedora_repository_access($op, $node, $account); return $objectHelper->fedora_repository_access($op, $node, $account);

8
formClass.inc

@ -13,7 +13,6 @@
class formClass { class formClass {
function formClass() { function formClass() {
module_load_include('inc', 'formClass', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
@ -128,7 +127,7 @@ class formClass {
'title' => t('Collection view'), 'title' => t('Collection view'),
'page callback' => 'fedora_collection_view', 'page callback' => 'fedora_collection_view',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access argruments' => array('view fedora collection') 'access argruments' => array('view fedora collection'),
); );
//new for mnpl****************************************** //new for mnpl******************************************
@ -229,7 +228,10 @@ class formClass {
'#description' => t('The URL to use for SOAP connections'), '#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE, '#required' => TRUE,
'#weight' => -12, '#weight' => -12,
'#suffix' => '<p>' . (fedora_available() ? '<img src="' . url('misc/watchdog-ok.png') . '"/>' . t('Successfully connected to Fedora server at !fedora_soap_url', array('!fedora_soap_url' => variable_get('fedora_soap_url', ''))) : '<img src="' . url('misc/watchdog-error.png') . '"/> ' . t('Unable to connect to Fedora server at !fedora_soap_url</p>', array('!fedora_soap_url' => variable_get('fedora_soap_url', '')))), '#suffix' => '<p>' . (
fedora_available() ?
theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) :
theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '</p>',
); );
$form['fedora_soap_manage_url'] = array( $form['fedora_soap_manage_url'] = array(

24
plugins/FedoraObjectDetailedContent.inc

@ -48,10 +48,9 @@ class FedoraObjectDetailedContent {
$tabset['fedora_object_details']['tabset'] = array( $tabset['fedora_object_details']['tabset'] = array(
'#type' => 'tabset', '#type' => 'tabset',
); );
$dc_html = $objectHelper->getFormattedDC($this->item); $dc_html = $objectHelper->getFormattedDC($this->item);
$ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item);
$i = 0; $i = 0;
if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {
$tabset['fedora_object_details']['tabset']['view'] = array( $tabset['fedora_object_details']['tabset']['view'] = array(
@ -63,9 +62,24 @@ class FedoraObjectDetailedContent {
'#weight' => $i++ '#weight' => $i++
), ),
'list' => array( 'list' => array(
'#type' => 'markup', '#type' => 'fieldset',
'#value' => $ds_list, //XXX: The function called here could be cleaned up a fair bit as well... '#title' => t('Detailed List of Content'),
'#weight' => $i++ '#attributes' => array(
'class' => 'fedora_detailed_list',
),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => $i++,
'parents' => array(
'#type' => 'markup',
'#value' => $objectHelper->get_parent_objects_asHTML($this->pid),
'#weight' => $i++,
),
'datastreams' => array(
'#type' => 'markup',
'#value' => $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item), //XXX: The function called here could be cleaned up a fair bit as well...
'#weight' => $i++,
),
), ),
'purge' => array( 'purge' => array(
'#type' => 'markup', '#type' => 'markup',

5
plugins/ShowDemoStreamsInFieldSets.inc

@ -29,11 +29,10 @@ class ShowDemoStreamsInFieldSets {
* @return type * @return type
*/ */
function showMediumSize() { function showMediumSize() {
global $base_url; $path = "fedora/repository/{$this->pid}/MEDIUM_SIZE";
$collection_fieldset = array( $collection_fieldset = array(
'#collapsible' => FALSE, '#collapsible' => FALSE,
'#value' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/MEDIUM_SIZE/"><img src="' . '#value' => l(theme('image', $path), $path, array('html' => TRUE)),
$base_url . '/fedora/repository/' . $this->pid . '/MEDIUM_SIZE/MEDIUM_SIZE' . '" /></a>',
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }

42
plugins/ShowStreamsInFieldSets.inc

@ -29,15 +29,21 @@ class ShowStreamsInFieldSets {
function showFlv() { function showFlv() {
//FLV is the datastream id //FLV is the datastream id
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$fullPath = base_path() . $path; $fullPath = url($path);
$content = ""; $content = "";
$pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js'; $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js';
drupal_add_js("$pathTojs"); drupal_add_js("$pathTojs");
$content .= '<div id="player' . $this->pid . 'FLV"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>'; $div_id = "player' . $this->pid . 'FLV";
drupal_add_js('var s1 = new SWFObject("' . $fullPath . '/flash/flvplayer.swf","single","320","240","7"); $content .= <<<EOH
s1.addParam("allowfullscreen","TRUE"); <div id="$div_id"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
s1.addVariable("file","' . base_path() . 'fedora/repository/' . $this->pid . '/FLV/FLV.flv"); EOH;
s1.write("player' . $this->pid . 'FLV");', 'inline', 'footer'); drupal_add_js(<<<EOJS
var s1 = new SWFObject("$fullPath/flash/flvplayer.swf","single","320","240","7");
s1.addParam("allowfullscreen","TRUE");
s1.addVariable("file", "$fullPath/fedora/repository/{$this->pid}/FLV/FLV.flv");
s1.write("$div_id");
EOJS
, 'inline', 'footer');
$collection_fieldset = array( $collection_fieldset = array(
'#title' => t('Flash Video'), '#title' => t('Flash Video'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
@ -48,30 +54,26 @@ class ShowStreamsInFieldSets {
/** /**
* Show the TN ?? * Show the TN ??
* @global type $base_url
* @return type * @return type
*/ */
function showTN() { function showTN() {
global $base_url;
$collection_fieldset = array( $collection_fieldset = array(
'#title' => '', '#title' => '',
'#attributes' => array(), '#attributes' => array(),
'#collapsible' => FALSE, '#collapsible' => FALSE,
'#value' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/OBJ/"><img src="' . $base_url . '/fedora/repository/' . $this->pid . '/TN/TN' . '" /></a>', '#value' => l(theme('image', "fedora/repository/{$this->pid}/TN/TN", '', '', NULL, FALSE), "fedora/repository/{$this->pid}/OBJ", array('html' => TRUE)),
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/** /**
* Same as showTN but artinventory stores the image in a dsid of IMAGE instead of OBJ * Same as showTN but artinventory stores the image in a dsid of IMAGE instead of OBJ
* @global type $base_url
* @return type * @return type
*/ */
function showArtInventoryTN() { function showArtInventoryTN() {
global $base_url;
$collection_fieldset = array( $collection_fieldset = array(
'#collapsible' => FALSE, '#collapsible' => FALSE,
'#value' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/IMAGE/image.jpg"><img src="' . $base_url . '/fedora/repository/' . $this->pid . '/TN/TN' . '" /></a>', '#value' => l(theme('image', "fedora/repository/{$this->pid}/TN/TN", '', '', NULL, FALSE), "fedora/repository/{$this->pid}/IMAGE/image.jpg", array('html' => TRUE)),
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
@ -102,14 +104,16 @@ class ShowStreamsInFieldSets {
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
$item = new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
if (key_exists('TN', $item->datastreams)) { if (key_exists('TN', $item->datastreams)) {
$tn_url = $base_url . '/fedora/repository/' . $item->pid . '/TN'; $tn_url = "fedora/repository/{$item->pid}/TN";
} }
else { else {
$tn_url = $base_path . drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_app_download_manager.png'; $tn_url = drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_app_download_manager.png';
} }
$tn_url = url($tn_url);
$dc_html = $objectHelper->getFormattedDC($item); $dc_html = $objectHelper->getFormattedDC($item);
$dl_link = l('<div style="float:left; padding: 10px"><img src="' . $tn_url . '"><br />' . t('View Document') .'</div>', 'fedora/repository/' . $this->pid . '/OBJ', array('html' => TRUE)); $dl_link = l('<div style="float:left; padding: 10px">' . theme('image', $tn_url, '', '', NULL, FALSE) . '<br />' . t('View Document') .'</div>', "fedora/repository/{$this->pid}/OBJ", array('html' => TRUE));
$tabset['first_tab']['tabs']['view'] = array( $tabset['first_tab']['tabs']['view'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
@ -126,11 +130,13 @@ class ShowStreamsInFieldSets {
); );
} }
$viewer_url = 'http://docs.google.com/viewer?url=' . url("fedora/repository/{$this->pid}/OBJ/preview.pdf", array('absolute' => TRUE)) . '&embedded=TRUE';
$tabset['second_tab'] = array( $tabset['second_tab'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('Read Online'), '#title' => t('Read Online'),
'#content' => "<iframe src=\"http://docs.google.com/viewer?url=" . $base_url . '/fedora/repository/' . '#content' => <<<EOM
$this->pid . '/OBJ/preview.pdf' . "&embedded=TRUE\" style=\"width:600px; height:500px;\" frameborder=\"0\"></iframe>" <iframe src="$viewer_url" style="width:600px; height:500px;" frameborder="0"></iframe>"
EOM
); );
// Render the tabset. // Render the tabset.
@ -164,7 +170,7 @@ class ShowStreamsInFieldSets {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
$streams = $item->get_datastreams_list_as_array(); $streams = $item->get_datastreams_list_as_array();
return "<a href='" . $base_url . "/fedora/repository/" . $this->pid . "/OBJ/" . $streams['OBJ']['label'] . "'>" . $streams['OBJ']['label'] . "</a>"; return l($streams['OBJ']['label'], "fedora/repository/{$this->pid}/OBJ");
} }
/** /**

4
plugins/herbarium.inc

@ -161,13 +161,13 @@ class Herbarium {
'#title' => t('Full-size'), '#title' => t('Full-size'),
'#content' => $html '#content' => $html
); );
$image = theme('image', "fedora/imageapi/{$this->pid}/JPG/JPG.jpg", '', '', NULL, FALSE);
$tabset['first_tab'] = array( $tabset['first_tab'] = array(
// #type and #title are the minimum requirements. // #type and #title are the minimum requirements.
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('View'), '#title' => t('View'),
// This will be the content of the tab. // This will be the content of the tab.
'#content' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/FULL_JPG/"><img src="' . $base_url . '/fedora/imageapi/' . '#content' => l($image, "fedora/repository/{$this->pid}/FULL_JPG", array('html' => TRUE)), '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
$this->pid . '/JPG/JPG.jpg' . '" /></a>' . '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
); );
$dwc = new DarwinCore($this->item); $dwc = new DarwinCore($this->item);

99
plugins/qt_viewer.inc

@ -125,59 +125,76 @@ class ShowQtStreamsInFieldSets {
if ($media === FALSE) { if ($media === FALSE) {
return ''; return '';
} }
global $base_url;
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$fullPath = base_path() . $path;
$content = ''; drupal_add_js("$path/js/AC_Quicktime.js");
$pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/AC_Quicktime.js';
drupal_add_js($pathTojs);
$divid = 'player' . md5($this->pid) . 'MOV'; $divid = 'player' . md5($this->pid) . 'MOV';
$content .= '<div class="player" id="' . $divid . '">';
$collection_fieldset = array(
'#title' => t('Quicktime'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'player' => array(
'#type' => 'markup',
'#prefix' => '<div class="player" id="' . $divid . '">',
'#suffix' => '</div>',
),
);
if ($pframe !== FALSE) { if ($pframe !== FALSE) {
$content .= '<div class="poster" style="cursor: pointer; position: relative; width: ' . $width . 'px; min-height: ' . ($height) . 'px;">'; $collection_fieldset['player']['poster_container'] = array(
$content .= '<img src="' . base_path() . 'fedora/repository/' . $this->pid . '/' . $pframe->ID . '/poster.jpg' . '" />'; '#type' => 'markup',
$content .= '<div class="play" style="font-size: 128px; color: white; position: absolute; top: 50%; left: 50%; margin-top: -0.085em; margin-left: -0.33em; opacity: 0.9; "></div>'; '#prefix' => '<div class="poster" style="cursor: pointer; position: relative; width: ' . $width . 'px; min-height: ' . ($height) . 'px;">',
$content .= '</div>'; '#suffix' => '</div>',
'poster' => array(
'#type' => 'markup',
'#value' => theme('image', "fedora/repository/{$this->pid}/{$pframe->ID}/poster.jpg", '', '', NULL, FALSE)
)
'play' => array(
'#type' => 'markup',
'#prefix' => '<div class="play" style="font-size: 128px; color: white; position: absolute; top: 50%; left: 50%; margin-top: -0.085em; margin-left: -0.33em; opacity: 0.9;">',
'#suffix' => '</div>',
'#value' => '&nbsp;',
),
);
} }
$content .= '</div>';
if ($this->enableDownload()) { if ($this->enableDownload()) {
$url = base_path() . 'fedora/repository/' . $this->pid . '/OBJ/MOV.mov'; //$url = url();
$content .= '<a class="download" href="' . $url . '">Download Media File</a>'; $collection_fieldset['download_link'] = array(
'#type' => 'markup',
'#value' => l(t('Download Media File'), "fedora/repository/{$this->pid}/OBJ/MOV.mov", array('attributes' => array('class' => 'download'))),
);
} }
$src = base_path() . 'fedora/repository/' . $this->pid . '/' . $media->ID . '/MOV.mov'; $src = url("fedora/repository/{$this->pid}/{$media->ID}/MOV.mov";
$qtparams = '';
$qtparams .= "'autostart', '" . ($pframe !== FALSE ? 'TRUE' : 'FALSE') . "', "; $qtparams = "'autostart', '" . ($pframe !== FALSE ? 'TRUE' : 'FALSE') . "', ";
$init = <<<EOD $init = <<<EOD
$(function() { $(function() {
src = "$src"; src = "$src";
if(src.substring(0,4) != 'http') { if(src.substring(0,4) != 'http') {
src = 'http://' + location.host + src; src = 'http://' + location.host + src;
} }
str = QT_GenerateOBJECTText_XHTML(src, "$width", ($height+15), '', str = QT_GenerateOBJECTText_XHTML(src, "$width", ($height+15), '',
$qtparams $qtparams
'postdomevents', 'TRUE', 'postdomevents', 'TRUE',
'EnableJavaScript', 'TRUE', 'EnableJavaScript', 'TRUE',
'bgcolor', 'black', 'bgcolor', 'black',
'controller', 'TRUE', 'controller', 'TRUE',
'SCALE', 'aspect', 'SCALE', 'aspect',
'LOOP', 'FALSE' 'LOOP', 'FALSE'
); );
if($('.poster', '#$divid').length ==0) { if($('.poster', '#$divid').length == 0) {
$('#$divid').append(str); $('#$divid').append(str);
} else { } else {
$('#$divid .poster').one('click', function() { $(this).hide(); $('#$divid').append(str); }); $('#$divid .poster').one('click', function() { $(this).hide(); $('#$divid').append(str); });
} }
}); });
EOD; EOD;
drupal_add_js($init, 'inline', 'footer'); drupal_add_js($init, 'inline', 'footer');
$collection_fieldset = array(
'#title' => t('Quicktime'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $content);
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }

6
plugins/slide_viewer.inc

@ -30,14 +30,13 @@ class ShowSlideStreamsInFieldSets {
function showJPG() { function showJPG() {
module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets'); module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets');
global $base_url;
global $user; global $user;
$tabset = array(); $tabset = array();
$qs = ''; $qs = '';
if ($user->uid != 0) { if ($user->uid != 0) {
$qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); //XXX: Base64 encoding is not encryption; SSL would be nice...
} }
$viewer_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs; $viewer_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs;
@ -55,8 +54,7 @@ class ShowSlideStreamsInFieldSets {
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('View'), '#title' => t('View'),
// This will be the content of the tab. // This will be the content of the tab.
'#content' => '<img src="' . $base_url . '#content' => theme('image', "fedora/imageapi/{$this->pid}/JPG/JPG.jpg", '', '', NULL, FALSE) . '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
'/fedora/imageapi/' . $this->pid . '/JPG/JPG.jpg' . '" />' . '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
); );
return $tabset; return $tabset;

30
plugins/tagging_form.inc

@ -19,13 +19,15 @@ function _show_subject_tags($pid) {
$obj = new Fedora_Item($pid); $obj = new Fedora_Item($pid);
$tags = new TagSet($obj); $tags = new TagSet($obj);
if (!empty($tags->tags)) { if (!empty($tags->tags)) {
$output = "<ul>"; $items = array();
foreach ($tags->tags as $tag) { foreach ($tags->tags as $tag) {
$output .= "<li title=" . $tag['creator'] . '>' . $tag['name'] . '</li> '; $items[] = array(
'data' => $tag['name'],
'title' => $tag['creator'],
);
} }
$output .= "</ul>"; return theme('item_list', $items);
} }
return $output;
} }
/** /**
@ -57,21 +59,27 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
// Add the current tags to the form. // Add the current tags to the form.
$tagset = new TagSet($obj); $tagset = new TagSet($obj);
$tags = array();
foreach ($tagset->tags as $tag) { foreach ($tagset->tags as $tag) {
$form['tags-wrapper']['tags'][$tag['name']] = array( $form_tag =& $form['tags-wrapper']['tags'][$tag['name']] = array(
'#prefix' => '<li>', '#prefix' => '<li>',
'#suffix' => '</li>', '#suffix' => '</li>',
); );
$form['tags-wrapper']['tags'][$tag['name']]['tag'] = array(
'#prefix' => '<a title="Added by ' . $tag['creator'] . '" href="' . $base_url . '/fedora/repository/mnpl_advanced_search/tag:' . $tag['name'] . '">', $tag_title_text = t('Added by @creator.', array(
'#value' => $tag['name'], '@creator' => $tag['creator'],
'#suffix' => '</a>', ));
$tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}"
$form_tag['tag'] = array(
'#value' => l($tag['name'], $tag_mnpl_search_path, array('attributes' => array(
'title' => $tag_title_text
))),
); );
if (user_access('modify fedora datastreams') || user_access('add fedora tags')) { if (user_access('modify fedora datastreams') || user_access('add fedora tags')) {
// Delete button for each existing tag. // Delete button for each existing tag.
$form['tags-wrapper']['tags'][$tag['name']]['delete'] = array( $form_tag['delete'] = array(
'#type' => 'imagebutton', '#type' => 'imagebutton',
'#image' => $base_url . '/' . drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png', '#image' => drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png',
'#default_value' => $tag['name'], '#default_value' => $tag['name'],
'#title' => t('Delete this tag'), '#title' => t('Delete this tag'),
); );

6
xsl/convertQDC.xsl

@ -12,13 +12,13 @@
<tr><th colspan="3"><h3>MetaData</h3></th></tr> <tr><th colspan="3"><h3>MetaData</h3></th></tr>
<xsl:for-each select="/*/*"> <xsl:for-each select="/*/*">
<xsl:variable name="FULLFIELD" select="name()"/> <xsl:variable name="FULLFIELD" select="name()"/>
<xsl:variable name="FIELD" select="substring-after(name(),':')"/> <xsl:variable name="FIELD" select="local-name()"/>
<xsl:variable name="DATA" select="text()"/> <xsl:variable name="DATA" select="text()"/>
<xsl:if test="$DATA != ' '"> <xsl:if test="$DATA != ' '">
<tr><td><strong><xsl:value-of select="substring-after(name(),':')"/></strong></td><td><xsl:value-of select="text()"/> <tr><td><strong><xsl:value-of select="local-name()"/></strong></td><td><xsl:value-of select="text()"/>
<xsl:for-each select="*"> <xsl:for-each select="*">
<div> <div>
<xsl:value-of select="substring-after(name(),':')"/> = <xsl:value-of select="text()"/> <xsl:value-of select="local-name()"/> = <xsl:value-of select="text()"/>
</div> </div>
</xsl:for-each> </xsl:for-each>
</td></tr> </td></tr>

398
xsl/sparql_to_html.xsl

@ -1,248 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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 --> <!-- Red and White XSLT -->
<xsl:variable name="BASEURL"> <xsl:variable name="BASEURL" select="$baseUrl"/>
<xsl:value-of select="$baseUrl"/> <xsl:variable name="PATH" select="$path"/>
</xsl:variable> <xsl:variable name="thisPid" select="$collectionPid"/>
<xsl:variable name="PATH"> <xsl:variable name="size" select="20"/>
<xsl:value-of select="$path"/> <xsl:variable name="page" select="$hitPage"/>
</xsl:variable> <xsl:variable name="start" select="((number($page) - 1) * number($size)) + 1"/>
<xsl:variable name="thisPid" select="$collectionPid"/> <xsl:variable name="end" select="($start - 1) + number($size)"/>
<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"/> <xsl:variable name="cellsPerRow" select="4"/>
<xsl:variable name="count" select="count(s:sparql/s:results/s:result)"/> <xsl:variable name="count" select="count(s:sparql/s:results/s:result)"/>
<xsl:template match="/">
<xsl:if test="$count>0">
<table cellpadding="3" cellspacing="3" width="90%">
<tr><td colspan="{$cellsPerRow}">
<!-- <div STYLE="text-align: center;">-->
<!-- start previous next -->
<div class="item-list">
<ul class="pager">
<xsl:choose>
<xsl:when test="$end >= $count and $start = 1">
<xsl:value-of select="$start"/>-<xsl:value-of select="$count"/>
of <xsl:value-of select="$count"/>&#160;<br />
</xsl:when>
<xsl:when test="$end >= $count">
<xsl:value-of select="$start"/>-<xsl:value-of select="$count"/> <xsl:template match="/">
of <xsl:value-of select="$count"/>&#160;<br /> <xsl:if test="$count>0">
<li class="pager-previous"> <xsl:call-template name="render_pager"/>
<a> <table cellpadding="3" cellspacing="3" width="90%">
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page - 1"/> <xsl:apply-templates select="s:sparql/s:results"/>
</xsl:attribute> </table><br clear="all" />
&lt;Prev <xsl:call-template name="render_pager"/>
</a></li> </xsl:if>
</xsl:when> </xsl:template>
<xsl:when test="$start = 1">
<xsl:value-of select="$start"/>-<xsl:value-of select="$end"/>
of <xsl:value-of select="$count"/>&#160;<br />
<li class="pager-next">
<a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page + 1"/>
</xsl:attribute>
Next>
</a></li>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$start"/>-<xsl:value-of select="$end"/>
of <xsl:value-of select="$count"/>&#160;<br />
<li class="pager-previous">
<a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page - 1"/>
</xsl:attribute>
&lt;Prev
</a>&#160;</li>
<li class="pager-next">
<a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page + 1"/>
</xsl:attribute>
Next>
</a></li>
</xsl:otherwise>
</xsl:choose>
</ul>
</div>
<!-- end previous next-->
<br clear="all" />
</td></tr>
<!--<xsl:for-each select="/sparql/results/result[position()>=$start and position() &lt;=$end]"> <xsl:template match="s:sparql/s:results">
<xsl:variable name='OBJECTURI' select="object/@uri"/> <xsl:for-each select="s:result[position() mod $cellsPerRow = 1 and position()>=$start and position() &lt;=$end]">
<xsl:variable name='PID' select="substring-after($OBJECTURI,'/')"/> <tr>
<tr> <xsl:apply-templates select=". | following-sibling::s:result[position() &lt; $cellsPerRow]"/>
<td> </tr>
<img> </xsl:for-each>
<xsl:attribute name="src"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$PID"/>/TN </xsl:template>
</xsl:attribute>
</img> <xsl:template name="render_pager">
<a> <!-- start previous next -->
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="title"/> <div class="item-list">
</xsl:attribute> <ul class="pager">
<xsl:value-of select="title"/> <xsl:choose>
</a> <xsl:when test="$end >= $count and $start = 1">
</td> <xsl:value-of select="concat($start, '-', $count, ' of ', $count, '&#160;')"/><br />
</tr> </xsl:when>
</xsl:for-each>- <xsl:when test="$end >= $count">
--> <xsl:value-of select="concat($start, '-', $count, ' of ', $count, '&#160;')"/><br />
<xsl:apply-templates select="s:sparql/s:results"/> <li class="pager-previous">
</table><br clear="all" /> <a>
<!-- start previous next --> <xsl:attribute name="href">
<div class="item-list"> <xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page - 1)"/>
<ul class="pager"> </xsl:attribute>
<xsl:choose> &lt;Prev
<xsl:when test="$end >= $count and $start = 1"> </a>
<xsl:value-of select="$start"/>-<xsl:value-of select="$count"/> </li>
of <xsl:value-of select="$count"/>&#160;<br /> </xsl:when>
</xsl:when> <xsl:when test="$start = 1">
<xsl:when test="$end >= $count"> <xsl:value-of select="concat($start, '-', $end, ' of ', $count, '&#160;')"/><br />
<li class="pager-next">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page + 1)"/>
</xsl:attribute>
Next>
</a>
</li>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($start, '-', $end, ' of ', $count, '&#160;')"/><br />
<li class="pager-previous">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page - 1)"/>
</xsl:attribute>
&lt;Prev
</a>&#160;
</li>
<li class="pager-next">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $page + 1)"/>
</xsl:attribute>
Next>
</a>
</li>
</xsl:otherwise>
</xsl:choose>
</ul>
</div>
<!-- end previous next-->
</xsl:template>
<xsl:value-of select="$start"/>-<xsl:value-of select="$count"/> <xsl:template match="s:result">
of <xsl:value-of select="$count"/>&#160;<br /> <xsl:variable name='OBJECTURI' select="s:object/@uri"/>
<li class="pager-previous"> <xsl:variable name='CONTENTURI' select="s:content/@uri"/>
<xsl:variable name='CONTENTMODEL' select="substring-after($CONTENTURI,'/')"/>
<xsl:variable name='PID' select="substring-after($OBJECTURI,'/')"/>
<xsl:variable name="newTitle" >
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="s:title"/>
<xsl:with-param name="from" select="'_'"/>
<xsl:with-param name="to" select="' '"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cleanTitle" select="php:functionString('fedora_repository_urlencode_string', $newTitle)"/>
<xsl:variable name="linkUrl">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="concat($BASEURL, '/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:otherwise>
</xsl:choose>
<xsl:value-of select="s:content"/>
</xsl:variable>
<td valign="top" width="25%">
<a> <a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page - 1"/> <xsl:attribute name="href">
<xsl:value-of select="$linkUrl"/>
</xsl:attribute> </xsl:attribute>
&lt;Prev <img>
</a></li> <xsl:attribute name="src"><xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/TN')"/></xsl:attribute>
</xsl:when> <xsl:attribute name="alt"><xsl:value-of select="$newTitle" disable-output-escaping="yes"/></xsl:attribute>
<xsl:when test="$start = 1"> </img>
<xsl:value-of select="$start"/>-<xsl:value-of select="$end"/> </a><br clear="all" />
of <xsl:value-of select="$count"/>&#160;<br />
<li class="pager-next">
<a> <a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page + 1"/> <xsl:attribute name="href"><xsl:value-of select="$linkUrl"/>
</xsl:attribute> </xsl:attribute>
Next> <xsl:value-of select="$newTitle" disable-output-escaping="yes" />
</a></li> </a>
</xsl:when> <!-- example of a url that would drill down to the details page if the url above went directly to a datastream
<xsl:otherwise> <xsl:if test="($CONTENTMODEL!='islandora:collectionCModel')">
<xsl:value-of select="$start"/>-<xsl:value-of select="$end"/> <br />[[ <a>
of <xsl:value-of select="$count"/>&#160;<br /> <xsl:attribute name="href">
<li class="pager-previous"> <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="$cleanTitle"/>
<a> </xsl:attribute>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page - 1"/> DETAILS
</xsl:attribute> </a> ]]
&lt;Prev </xsl:if>-->
</a>&#160;</li>
<li class="pager-next">
<a>
<xsl:attribute name="href"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/Collection/<xsl:value-of select="$page + 1"/>
</xsl:attribute>
Next>
</a></li>
</xsl:otherwise>
</xsl:choose>
</ul>
</div>
<!-- end previous next-->
</xsl:if>
</xsl:template>
<xsl:template match="s:sparql/s:results">
<xsl:for-each select="s:result[position() mod $cellsPerRow = 1 and position()>=$start and position() &lt;=$end]">
<tr>
<xsl:apply-templates select=". | following-sibling::s:result[position() &lt; $cellsPerRow]"/>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="s:result">
<xsl:variable name='OBJECTURI' select="s:object/@uri"/>
<xsl:variable name='CONTENTURI' select="s:content/@uri"/>
<xsl:variable name='CONTENTMODEL' select="substring-after($CONTENTURI,'/')"/>
<xsl:variable name='PID' select="substring-after($OBJECTURI,'/')"/>
<xsl:variable name="newTitle" >
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="s:title"/>
<xsl:with-param name="from" select="'_'"/>
<xsl:with-param name="to" select="' '"/>
</xsl:call-template>
</xsl:variable> </td>
<xsl:variable name="cleanTitle"> <xsl:if test="(position() = last()) and (position() &lt; $cellsPerRow)">
<xsl:value-of select="php:functionString('fedora_repository_urlencode_string', $newTitle)"/> <xsl:call-template name="FillerCells">
</xsl:variable> <xsl:with-param name="cellCount" select="$cellsPerRow - position()"/>
<xsl:variable name="linkUrl"> </xsl:call-template>
<xsl:choose> </xsl:if>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')"> </xsl:template>
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="'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="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="s:content"/>
</xsl:variable>
<td valign="top" width="25%">
<a>
<xsl:attribute name="href"><xsl:value-of select="$linkUrl"/>
</xsl:attribute>
<img>
<xsl:attribute name="src"><xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$PID"/>/TN
</xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$newTitle" disable-output-escaping="yes"/>
</xsl:attribute>
</img> </a> <br clear="all" />
<a>
<xsl:attribute name="href"><xsl:value-of select="$linkUrl"/>
</xsl:attribute>
<xsl:value-of select="$newTitle" disable-output-escaping="yes" />
</a>
<!-- example of a url that would drill down to the details page if the url above went directly to a datastream
<xsl:if test="($CONTENTMODEL!='islandora:collectionCModel')">
<br />[[ <a>
<xsl:attribute name="href">
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="$cleanTitle"/>
</xsl:attribute>
DETAILS
</a> ]]
</xsl:if>-->
</td> <xsl:template name="FillerCells">
<xsl:if test="(position() = last()) and (position() &lt; $cellsPerRow)"> <xsl:param name="cellCount"/>
<xsl:call-template name="FillerCells"> <td>&#160;</td>
<xsl:with-param name="cellCount" select="$cellsPerRow - position()"/> <xsl:if test="$cellCount > 1">
</xsl:call-template> <xsl:call-template name="FillerCells">
</xsl:if> <xsl:with-param name="cellCount" select="$cellCount - 1"/>
</xsl:template> </xsl:call-template>
<xsl:template name="FillerCells"> </xsl:if>
<xsl:param name="cellCount"/> </xsl:template>
<td>&#160;</td>
<xsl:if test="$cellCount > 1">
<xsl:call-template name="FillerCells">
<xsl:with-param name="cellCount" select="$cellCount - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose> <xsl:template name="replace-string">
<xsl:when test="contains($text, $from)"> <xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:variable name="before" select="substring-before($text, $from)"/> <xsl:choose>
<xsl:variable name="after" select="substring-after($text, $from)"/> <xsl:when test="contains($text, $from)">
<xsl:variable name="prefix" select="concat($before, $to)"/>
<xsl:value-of select="$before"/> <xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:value-of select="$to"/> <xsl:variable name="after" select="substring-after($text, $from)"/>
<xsl:call-template name="replace-string"> <xsl:variable name="prefix" select="concat($before, $to)"/>
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<xsl:value-of select="$before"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Loading…
Cancel
Save