Browse Source

Overhaul breadcrumbs and nuke fedora_repository_{name,title}

Addresses the title/name issues of ISLANDORA-562 (by getting rid of them).
Menu/root title is provided through the menu system.
pull/99/head
Adam Vessey 13 years ago
parent
commit
e4cad8c448
  1. 9
      CollectionClass.inc
  2. 176
      ObjectHelper.inc
  3. 6
      api/fedora_utils.inc
  4. 3
      fedora_repository.module
  5. 23
      formClass.inc

9
CollectionClass.inc

@ -607,7 +607,7 @@ class CollectionClass {
* @param int $pageNumber
* @return type
*/
function renderCollection($content, $pid, $dsId, $collection, $pageNumber = NULL) {
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
@ -620,17 +620,14 @@ class CollectionClass {
$fedoraItem = NULL;
$collectionName = $collection;
if (!$pageNumber) {
$pageNumber = 1;
}
if (empty($collectionName)) {
$collectionName = variable_get('fedora_repository_name', 'Collection');
$collectionName = menu_get_active_title();
}
$xslContent = $this->getXslContent($pid, $path);
//get collection list and display using xslt-------------------------------------------

176
ObjectHelper.inc

@ -938,58 +938,62 @@ class ObjectHelper {
/**
* Builds an array of drupal links for use in breadcrumbs.
*
* @todo Make fully recursive...
*
* @global type $base_url
* @param type $pid
* @param type $breadcrumbs
* @param type $level
*/
function getBreadcrumbs($pid, &$breadcrumbs, $level=10) {
function getBreadcrumbs($pid, &$breadcrumbs) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
// Before executing the query, we hve a base case of accessing the top-level collection
global $base_url;
if ($pid == variable_get('fedora_repository_pid', 'islandora:root')) {
//$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(variable_get('fedora_repository_title', 'Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(t('Home'), $base_url);
static $max_level = 10;
static $level = -1;
if (count($breadcrumbs) === 0) {
$level = $max_level;
}
$root = variable_get('fedora_repository_pid', 'islandora:root');
if ($pid == $root) {
$breadcrumbs[] = l(menu_get_active_title(), 'fedora/repository');
$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';
$query_string = htmlentities(urlencode($query_string));
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string;
$result = preg_split('/[\r\n]+/', do_curl($url));
array_shift($result); // throw away first line
$matches = str_getcsv(join("\n", $result));
if (count($matches) >= 2) {
$parent = preg_replace('/^info:fedora\//', '', $matches[0]);
if (0 == strlen($matches[1])) {
$matches[1] = "Unlabeled Object";
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::_perform_itql_query($query_string)) > 0 && $level > 0) {
$parent = $results[0]['parentObject'];
$this_title = $results[0]['title'];
if (empty($this_title)) {
$this_title = t('Unlabeled Object');
}
$breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid);
if ($parent == variable_get('fedora_repository_pid', 'islandora:root')) {
//$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(variable_get('fedora_repository_name', 'Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(t('Home'), $base_url);
}
elseif ($level > 0) {
$this->getBreadcrumbs($parent, $breadcrumbs, $level - 1);
}
}
$breadcrumbs[] = l($this_title, "fedora/repository/$pid");
$level--;
$this->getBreadcrumbs($parent, $breadcrumbs);
}
else {
$breadcrumbs[] = l(t("Path Calculation Error"), 'fedora/repository/' . $pid);
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);
$breadcrumbs[] = '...';
$this->getBreadcrumbs($root, $breadcrumbs);
}
}
}
@ -1012,5 +1016,103 @@ class ObjectHelper {
drupal_set_message(t($configMess . "<br />" . $messMap[$app] . "<hr width='40%' align = 'left'/>", array('%app' => $app)), 'warning', FALSE);
}
/**
* Performs the given RI query.
*
* FIXME: Could probably made more fail-safe (avoid loading directly with SimpleXML.)
*
* @param string $query
* @param int $limit
* @param int $offset
* @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.
*/
protected static function _perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) {
//Setup the query options...
$options = array(
'type' => 'tuples',
'flush' => TRUE,
'format' => 'Sparql',
'lang' => $type,
'query' => $query
);
if ($limit > 0) {
$options['limit'] = $limit;
}
if ($offset > 0) {
$options['offset'] = $offset;
}
//Actually construct the query URL.
$queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options));
$curl_result = do_curl_ext($queryUrl);
if (!$curl_result[0]) {
watchdog('fedora_repository', 'Failed to perform %type resource index query: %query', array('%type' => $type, '%query' => $query), WATCHDOG_ERROR);
return FALSE;
}
$doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result');
$results = array(); //Storage.
//Build the results.
foreach ($doc->results->children() as $result) {
$r = array();
foreach ($result->children() as $element) {
$val = NULL;
$attrs = $element->attributes();
if (!empty($attrs['uri'])) {
$val = $attrs['uri'];
}
else {
$val = $element;
}
$r[$element->getName()] = self::_pid_uri_to_bare_pid((string)$val);
}
$results[] = $r;
}
return $results;
}
/**
* Thin wrapper for self::_perform_ri_query().
*/
public static function _perform_itql_query($query, $limit = -1, $offset = 0) {
return self::_perform_ri_query($query, 'itql', $limit, $offset);
}
/**
* Thin wrapper for self::_perform_ri_query().
*/
public static function _perform_sparql_query($query, $limit = -1, $offset = 0) {
return self::_perform_ri_query($query, 'sparql', $limit, $offset);
}
/**
* Utility function used in self::_perform_ri_query().
*
* Strips off the 'info:fedora/' prefix from the passed in string.
*
* @param $uri string
* A string containing a URI.
* @return string
* The input string less the 'info:fedora/' prefix (if it has it).
* The original string otherwise.
*/
protected static function _pid_uri_to_bare_pid($uri) {
$chunk = 'info:fedora/';
$pos = strrpos($uri, $chunk);
if ($pos !== FALSE) { //Remove info:fedora/ chunk
return substr($uri, strlen($chunk));
}
else { //Doesn't start with info:fedora/ chunk...
return $uri;
}
}
}

6
api/fedora_utils.inc

@ -85,7 +85,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* an array that consists of three value or NULL if curl is not suported:
* - element 0:
* The value returned from the curl_exec function call.
* This is either a TRUE or FALSE value or the actual data returned from
* This is either a boolean value or the actual data returned from
* accessing the URL.
* - element 1:
* The error code reslting from attempting to access the URL with curl_exec
@ -93,7 +93,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* A string representing a textual representation of the error code that
* resulted from attempting to access the URL with curl_exec
*/
function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0, $post = NULL) {
global $user;
// Check if we are inside Drupal and there is a valid user.
@ -113,7 +113,7 @@ function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $p
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable

3
fedora_repository.module

@ -2,8 +2,7 @@
/**
* Drupal hook for admin form
* fedora_repository_name is the name of the top level collection this module will query
* fedora_repository_pid is the name of the top level pid.
*
* Stores this info in the drupal variables table.
* the name and pid can also be passed as url parameters
*/

23
formClass.inc

@ -70,9 +70,7 @@ class formClass {
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository'] = array(
'title' => '',
'title callback' => 'variable_get',
'title arguments' => array('fedora_repository_name', 'Digital Repository'),
'title' => 'Digital Repository',
'page callback' => 'repository_page',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('view fedora collection'),
@ -187,24 +185,16 @@ class formClass {
/**
* Create admin form
* @return type
* @return array
*/
function createAdminForm() {
if (!user_access('administer site configuration')) {
drupal_set_message(t('You must be a site administrator to edit the Fedora collecitons list.'), 'error');
drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error');
return;
}
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$form = array();
$form['fedora_repository_name'] = array(
'#type' => 'textfield',
'#title' => t('Root Collection Name'),
'#default_value' => variable_get('fedora_repository_name', 'Islandora demos collection'),
'#description' => t('The Name of the Root Collection Object'),
'#required' => TRUE,
'#weight' => -20
);
$form['fedora_repository_pid'] = array(
'#type' => 'textfield',
'#title' => t('Root Collection PID'),
@ -285,12 +275,7 @@ class formClass {
'#weight' => 0
);
}
$form['fedora_repository_title'] = array(
'#type' => 'textfield',
'#title' => t('Digital Repository Title'),
'#default_value' => variable_get('fedora_repository_title', 'Digital Repository'),
'#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'),
);
//have tabs options (like disable)
$form['tabs'] = array(
'#type' => 'fieldset',

Loading…
Cancel
Save