Browse Source

Merge 3f7f320794 into bd76dbf214

pull/98/merge
GitHub Merge Button 14 years ago
parent
commit
8d4a4298ee
  1. 9
      CollectionClass.inc
  2. 192
      ObjectHelper.inc
  3. 10
      api/fedora_item.inc
  4. 6
      api/fedora_utils.inc
  5. 43
      fedora_repository.install
  6. 3
      fedora_repository.module
  7. 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-------------------------------------------

192
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[] = '...'; //Add an non-link, as we don't know how to get back to the root.
$this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass).
}
}
}
@ -1012,5 +1016,119 @@ class ObjectHelper {
drupal_set_message(t($configMess . "<br />" . $messMap[$app] . "<hr width='40%' align = 'left'/>", array('%app' => $app)), 'warning', FALSE);
}
/**
* Performs the given Resource Index query and return the results.
*
* @param $query string
* A string containing the RI query to perform.
* @param $type string
* The type of query to perform, as used by the risearch interface.
* @param $limit int
* An integer, used to limit the number of results to return.
* @param $offset int
* An integer, used to offset the results (results should be ordered, to
* maintain consistency.
* @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', //Sparql XML is processed into the array below.
'lang' => $type,
'query' => $query
);
//Add limit if provided.
if ($limit > 0) {
$options['limit'] = $limit;
}
//Add offset if provided.
if ($offset > 0) {
$options['offset'] = $offset;
}
//Construct the query URL.
$queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options));
//Perform the query.
$curl_result = do_curl_ext($queryUrl);
//If the query failed, write message to the logs and return.
if (!$curl_result[0]) {
watchdog('fedora_repository', 'Failed to perform %type resource index query: %query', array('%type' => $type, '%query' => $query), WATCHDOG_ERROR);
return FALSE;
}
//Load the results into a SimpleXMLElement
$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) {
//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().
*
* @see 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().
*
* @see 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 = strpos($uri, $chunk);
if ($pos === 0) { //Remove info:fedora/ chunk
return substr($uri, strlen($chunk));
}
else { //Doesn't start with info:fedora/ chunk...
return $uri;
}
}
}

10
api/fedora_item.inc

@ -276,7 +276,7 @@ RDF;
$description->appendChild($newrel);
$this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml');
return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml');
//print ($description->dump_node());
/*
$params = array( 'pid' => $this->pid,
@ -969,6 +969,8 @@ RDF;
* Error suppression? Refer to soap_call for usage (just passed along here).
*/
function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) {
$toReturn = NULL;
//Determine if it's inline xml; if it is, modify by value
if ($this->get_datastream($dsid)->controlGroup === 'X') {
$content = '<null/>';
@ -979,7 +981,7 @@ RDF;
$content = $filename_or_content;
}
$this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage);
$toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage);
}
//Otherwise, write to web-accessible temp file and modify by reference.
else {
@ -1000,12 +1002,14 @@ RDF;
$file_url = file_create_url($file);
$this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage);
$toReturn = $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage);
if ($created_temp && is_file($file) && is_writable($file)) {
file_delete($file);
}
}
return $toReturn;
}
/**

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

43
fedora_repository.install

@ -34,71 +34,70 @@ function fedora_collections_enable() {
* @see _update_cron_notify()
*/
function fedora_repository_requirements($phase) {
global $base_url;
$requirements = array();
$t = get_t(); //May not have access to the regular t() function; and so Drupal provides...
if ($phase == 'install') {
// Test for SOAP
$requirements['fedora-soap']['title'] = t("PHP SOAP extension library");
$requirements['fedora-soap']['title'] = $t("PHP SOAP extension library");
if (!class_exists('SoapClient')) {
$requirements['fedora-soap']['value'] = t("Not installed");
$requirements['fedora-soap']['value'] = $t("Not installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-soap']['description'] = t('Ensure that the PHP SOAP extension is installed.');
$requirements['fedora-soap']['description'] = $t('Ensure that the PHP SOAP extension is installed.');
}
else {
$requirements['fedora-soap']['value'] = t("Installed");
$requirements['fedora-soap']['value'] = $t("Installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK;
}
// Test for Curl
$requirements['curl']['title'] = "PHP Curl extension library";
$requirements['curl']['title'] = $t('PHP Curl extension library');
if (!function_exists('curl_init')) {
$requirements['curl']['value'] = t("Not installed");
$requirements['curl']['value'] = $t("Not installed");
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
$requirements['curl']['description'] = t("Ensure that the PHP Curl extension is installed.");
$requirements['curl']['description'] = $t("Ensure that the PHP Curl extension is installed.");
}
else {
$requirements['curl']['value'] = t("Installed");
$requirements['curl']['value'] = $t("Installed");
$requirements['curl']['severity'] = REQUIREMENT_OK;
}
// Test for DOM
$requirements['dom']['title'] = "PHP DOM XML extension library";
$requirements['dom']['title'] = $t("PHP DOM XML extension library";
if (!method_exists('DOMDocument', 'loadHTML')) {
$requirements['dom']['value'] = t("Not installed");
$requirements['dom']['value'] = $t("Not installed");
$requirements['dom']['severity'] = REQUIREMENT_ERROR;
$requirements['dom']['description'] = t("Ensure that the PHP DOM XML extension is installed.");
$requirements['dom']['description'] = $t("Ensure that the PHP DOM XML extension is installed.");
}
else {
$requirements['dom']['value'] = t("Installed");
$requirements['dom']['value'] = $t("Installed");
$requirements['dom']['severity'] = REQUIREMENT_OK;
}
// Test for XSLT
$requirements['xsl']['title'] = "PHP XSL extension library";
$requirements['xsl']['title'] = $t("PHP XSL extension library");
if (!class_exists('XSLTProcessor')) {
$requirements['xslt']['value'] = t("Not installed");
$requirements['xslt']['value'] = $t("Not installed");
$requirements['xslt']['severity'] = REQUIREMENT_ERROR;
$requirements['xslt']['description'] = t("Ensure that the PHP XSL extension is installed.");
$requirements['xslt']['description'] = $t("Ensure that the PHP XSL extension is installed.");
}
else {
$requirements['xslt']['value'] = t("Installed");
$requirements['xslt']['value'] = $t("Installed");
$requirements['xslt']['severity'] = REQUIREMENT_OK;
}
}
elseif ($phase == 'runtime') {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$requirements['fedora-repository']['title'] = t("Fedora server");
$requirements['fedora-repository']['title'] = $t("Fedora server");
if (!fedora_available()) {
$requirements['fedora-repository']['value'] = t("Not available");
$requirements['fedora-repository']['value'] = $t("Not available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => $base_url . '/admin/settings/fedora_repository'));
$requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => url('admin/settings/fedora_repository')));
}
else {
$requirements['fedora-repository']['value'] = t("Available");
$requirements['fedora-repository']['value'] = $t("Available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK;
}
}

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_name', '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