Browse Source

Initial merge attempt.

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
5ccb6b9e03
  1. 167
      ObjectHelper.inc
  2. 90
      SearchClass.inc
  3. 119
      api/fedora_item.inc
  4. 2
      api/fedora_utils.inc
  5. 8
      fedora_repository.install
  6. 98
      fedora_repository.module
  7. 145
      formClass.inc
  8. 1
      ilives/fedora_ilives.module
  9. 2
      plugins/fedoraObject.inc
  10. 6
      plugins/fedora_attach/fedora_attach.admin.inc
  11. 205
      tests/fedora_repository.test
  12. 269
      xsl/unfilteredresults.xsl

167
ObjectHelper.inc

@ -41,7 +41,7 @@ class ObjectHelper {
*/
function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = TRUE) {
global $user;
module_load_include('inc','fedora_repository','ContentModel');
module_load_include('inc', 'fedora_repository', 'ContentModel');
if ($pid == NULL || $dsID == NULL) {
drupal_set_message(t("no pid or dsid given to create an object with"), 'error');
return ' ';
@ -61,7 +61,7 @@ class ObjectHelper {
}
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE ) {
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) {
if (($cm = ContentModel::loadFromObject($pid)) == FALSE) {
drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error');
drupal_access_denied();
@ -69,7 +69,7 @@ class ObjectHelper {
}
$cmDatastreams = $cm->listDatastreams();
if ( !((isset($user) && in_array('administrator',$user->roles)) || in_array($dsID,$cmDatastreams))) {
if (!((isset($user) && in_array('administrator', $user->roles)) || in_array($dsID, $cmDatastreams))) {
drupal_set_message(t("You do not have access to the specified datastream."), 'error');
drupal_access_denied();
return ' ';
@ -81,7 +81,7 @@ class ObjectHelper {
if (isset($item->datastreams[$dsID])) {
$mimeType=$item->datastreams[$dsID]['MIMEType'];
$mimeType = $item->datastreams[$dsID]['MIMEType'];
if ($label == NULL) {
$label = $item->datastreams[$dsID]['label'];
}
@ -94,7 +94,7 @@ class ObjectHelper {
if ((!isset($user)) || $user->uid == 0) {
$fedoraUser = 'anonymous';
$fedoraPass = 'anonymous';
$contentSize= 0;
$contentSize = 0;
} else {
$fedoraUser = $user->name;
$fedoraPass = $user->pass;
@ -166,10 +166,10 @@ class ObjectHelper {
header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
}
if ( (isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch);
} else {
header('Location: '.$url);
header('Location: ' . $url);
}
}
curl_close($ch);
@ -258,9 +258,9 @@ class ObjectHelper {
$item = new Fedora_Item($pid);
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
$purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' .
@ -274,11 +274,11 @@ class ObjectHelper {
// 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.
$replaceImage= '&nbsp;';
$replaceImage = '&nbsp;';
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
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>';
@ -319,8 +319,10 @@ class ObjectHelper {
$dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
$xmlstr = $item->get_datastream_dissemination($dsid);
if (empty($xmlstr)) {
return '';
}
try {
@ -365,19 +367,45 @@ class ObjectHelper {
//$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1));
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
$dsid . '"><img src="' . $base_url . '/' . drupal_get_path('module', 'fedora_repository') . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>';
$dsId . '"><img src="' . $base_url . '/' . $path . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>';
}
}
return $output;
}
function getFormattedDatastreamList($object_pid, $contentModels, &$fedoraItem) {
/**
* Gets a list of datastreams from an object using its pid
*
* We make some assumptions here. We have implemented a policy that
* we ingest in our repository will have TN (thumbnail) datastream. Even audio
* will have a picture of a speaker or something. This is not critical
* but makes searches etc. look better if there is a TN stream.
* This diplays all the streams in a collapsed fieldset at the bottom of the object page.
* you can implement a content model if you would like certain streams displayed in certain ways.
* @param $object_pid String
* @return String
*
*/
function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) {
global $fedoraUser, $fedoraPass, $base_url, $user;
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'ContentModel');
$path = drupal_get_path('module', 'fedora_repository');
$dataStreamBody = '';
$fedoraItem = new Fedora_Item($object_pid);
if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) {
$availableDataStreamsText = 'Detailed List of Content';
//$metaDataText='Description';
@ -400,8 +428,7 @@ class ObjectHelper {
$dataStreamBody .= '<tr><th colspan="4"><h3>' . t("!text", array('!text' => $availableDataStreamsText)) . '</h3></th></tr>';
foreach ($object as $datastream) {
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;
@ -418,91 +445,27 @@ class ObjectHelper {
$dataStreamBody .= "</table>\n";
//if they have access let them add a datastream
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write');
$allow = fedora_fesl_check_roles($object_pid, 'write');
}
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>';
$dataStreamBody = '<div class = "fedora_detailed_list">' . $dataStreamBody . '</div>';
return $dataStreamBody;
}
return '';
}
/**
* Gets a list of datastreams from an object using its pid
*
* We make some assumptions here. We have implemented a policy that
* we ingest in our repository will have TN (thumbnail) datastream. Even audio
* will have a picture of a speaker or something. This is not critical
* but makes searches etc. look better if there is a TN stream.
* This diplays all the streams in a collapsed fieldset at the bottom of the object page.
* you can implement a content model if you would like certain streams displayed in certain ways.
* @param $object_pid String
* @return String
*
*/
function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) {
global $fedoraUser, $fedoraPass, $base_url, $user;
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'ContentModel');
$path = drupal_get_path('module', 'fedora_repository');
$dataStreamBody = '';
$fedoraItem = new Fedora_Item($object_pid);
$dataStreamBody = $this->getFormattedDatastreamList($object_pid, $contentModels, $fedoraItem);
$content = '';
if (empty($contentModels)) {
//only show this stuff if there are no contentmodels
if (isset($hasOBJStream)) {
$content .= '<a href="' . base_path() . 'fedora/repository/' . $object_pid . '/OBJ/' . $mainStreamLabel . '" target="_blank" >';
$content .= '<img src="' . base_path() . 'fedora/repository/' . $object_pid . '/TN" alt="Thumbnail"/>';
$content .= '</a>';
} else {
//don't use thumbnail as link, we don't know which datastream to link to
$content .= '<img src="' . base_path() . 'fedora/repository/' . $object_pid . '/TN" alt="' . $object_pid . '"/>';
}
}
foreach ($contentModels as $contentModel) {
$content .= $this->createExtraFieldsets($object_pid, $contentModel);
}
$content .= $dataStreamBody;
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write');
}
if ($allow) {
//$purgeObject = '<a title="' . t('Purge Object ') . $object_pid . '" href="' . base_path() . 'fedora/repository/purgeObject/' .
//$object_pid . '"><img src="' . $base_url . '/' . $path . '/images/purge_big.png" alt="' . t('Purge Object') . '" class="icon">' . t('Purge Object') . '</a>';
$purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(substr(request_uri(), strlen(base_path()))));
}
} else {
$purgeObject = '&nbsp;';
}
$content .= $purgeObject;
$addObject = "&nbsp;";
if (user_access(ObjectHelper :: $OBJECT_HELPER_VIEW_FEDORA)) {
$addObject = theme('add_to_basket_link', $object_pid);
}
$content .= $addObject;
return '<div class="fedora-datastream-content">' . $content . '</div>';
}
/**
@ -581,23 +544,29 @@ class ObjectHelper {
/*
* determines whether we can see the object or not
* checks PID namespace permissions, and user permissions
*/
function fedora_repository_access($op, $pid) {
global $user;
$returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if (!$isRestricted) {
$namespaceAccess = TRUE;
}
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:top');
}
$nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$pos = NULL;
foreach ($nameSpaceAllowed as $nameSpace) {
$pos = stripos($pid, $nameSpace);
if ($pos === 0) {
$returnValue = TRUE;
$namespaceAccess = TRUE;
}
}
if ($returnValue) {
if ($namespaceAccess) {
$user_access = user_access($op);
if ($user_access == NULL) {
return FALSE;
@ -653,9 +622,9 @@ class ObjectHelper {
$collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
// $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
@ -664,10 +633,10 @@ class ObjectHelper {
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection');
}
}
}
else {
} else {
$ingestObject = '&nbsp;';
}
}
$datastreams .= $ingestObject;
@ -894,11 +863,13 @@ class ObjectHelper {
$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 ($matches !== FALSE) {
$parent = preg_replace('/^info:fedora\//','',$matches[0]);
$breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid);
if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) {
$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository');

90
SearchClass.inc

@ -208,42 +208,7 @@ class SearchClass {
}
/*
function custom_search($query,$pathToXslt=NULL){
module_load_include('php', 'Fedora_Repository', 'ObjectHelper');
module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils');
if (user_access('view fedora collection')) {
$numberOfHistPerPage = '1000';//hack for IR they do not want next button
$luceneQuery = NULL;
//demo search string ?operation=gfindObjects&indexName=DemoOnLucene&query=fgs.DS.first.text%3Achristmas&hitPageStart=11&hitPageSize=10
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$query=htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $query;
$searchString .= '&hitPageSize='.$numberOfHistPerPage.'&hitPageStart=1';
//$searchString = htmlentities($searchString);
$searchUrl .= $searchString;
$objectHelper = new ObjectHelper();
$resultData = do_curl($searchUrl,1);
//var_dump($resultData);exit(0);
// $doc = new DOMDocument();
// $doc->loadXML($resultData);
if($pathToXslt==NULL) {
$output.=$this->applyLuceneXSLT($resultData,$query);
}else{
$output.=$this->applySpecifiedXSLT($resultData,$pathToXslt);
}
return $output;
}
}
*/
function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
@ -327,53 +292,7 @@ class SearchClass {
}
}
//default function for lucene results
/*
function applyLuceneXSLT($resultData, $query = NULL){
$path = drupal_get_path('module', 'Fedora_Repository');
$proc = NULL;
if (!$resultData) {
drupal_set_message(t('No Results!'));
return ' '; //no results
}
try {
$proc = new XsltProcessor();
}
catch (Exception $e) {
drupal_set_message(t('Error loading results xslt! ') . $e->getMessage()) ;
return ' ';
}
//inject into xsl stylesheet
if(isset($query)){
$proc->setParameter('', 'fullQuery', $query);
}
$proc->setParameter('', 'searchToken', drupal_get_token('fedora_repository_advanced_search')); //token generated by Drupal, keeps tack of what tab etc we are on
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'demo: changeme:'));
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$test= $xsl->load($path . '/xsl/results.xsl');
if (!isset($test)) {
drupal_set_message(t('Error loading search results XSLT!'));
return t('Error loading search results XSLT.');
}
$input = new DomDocument();
$didLoadOk = $input->loadXML($resultData);
if (!isset($didLoadOk)) {
drupal_set_message(t('Error loading search results!'));
return t('Error loading search results.');
}
else {
$proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
return $newdom->saveXML();
}
}
*/
/**
* apply an xslt to lucene gsearch search results
@ -385,6 +304,11 @@ class SearchClass {
*/
function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) {
$path = drupal_get_path('module', 'Fedora_Repository');
$test = $xslt_file;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if(!isRestricted && $xslt_file == null){
$xslt_file = '/xsl/unfilteredresults.xsl';
}
$proc = NULL;
if (!$resultData) {
//drupal_set_message(t('No Results!'));
@ -405,7 +329,7 @@ class SearchClass {
$proc->setParameter('', 'searchToken', drupal_get_token('fedora_repository_advanced_search')); //token generated by Drupal, keeps tack of what tab etc we are on
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$proc->setParameter('', 'hitPageStart', $startPage);
$proc->registerPHPFunctions();
$xsl = new DomDocument();
@ -450,7 +374,7 @@ class SearchClass {
$proc->setParameter('', 'userID', $user->uid);
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$proc->setParameter('', 'orderBy', $orderBy);
$xsl = new DomDocument();

119
api/fedora_item.inc

@ -2,19 +2,18 @@
// $Id$
define ('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#');
define ("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#');
define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#');
define("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#');
class Fedora_Item {
public $pid = NULL; // The $pid of the fedora object represented by an instance of this class.
public $objectProfile = NULL;
private $datastreams_list = NULL; // A SimpleXML object to store a list of this item's datastreams
public $datastreams = NULL;
private static $connection_helper = NULL;
private static $instantiated_pids = array();
/**
* Create an object to represent an item in the Fedora repository.
* Throws a SOAPException if the PID is not in the repository.
@ -29,10 +28,11 @@ class Fedora_Item {
$this->pid = $pid;
if (isset(Fedora_Item::$instantiated_pids[$pid])) {
$this->objectProfile =& Fedora_Item::$instantiated_pids[$pid]->objectProfile;
$this->datastreams =& Fedora_Item::$instantiated_pids[$pid]->datastreams;
$this->datastreams_list =& Fedora_Item::$instantiated_pids[$pid]->datastreams_list;
} else {
$this->objectProfile = & Fedora_Item::$instantiated_pids[$pid]->objectProfile;
$this->datastreams = & Fedora_Item::$instantiated_pids[$pid]->datastreams;
$this->datastreams_list = & Fedora_Item::$instantiated_pids[$pid]->datastreams_list;
}
else {
if (empty(self::$connection_helper)) {
self::$connection_helper = new ConnectionHelper();
}
@ -42,11 +42,12 @@ class Fedora_Item {
if (!empty($raw_objprofile)) {
$this->objectProfile = $raw_objprofile->objectProfile;
$this->datastreams = $this->get_datastreams_list_as_array();
} else {
}
else {
$this->objectProfile = '';
$this->datastreams = array();
}
Fedora_Item::$instantiated_pids[$pid]=&$this;
Fedora_Item::$instantiated_pids[$pid] = &$this;
}
}
@ -54,7 +55,7 @@ class Fedora_Item {
return (!empty($this->objectProfile));
}
function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M',$logMessage = null) {
function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
if (empty($datastream_mimetype)) {
// Get mime type from the file extension.
@ -67,7 +68,7 @@ class Fedora_Item {
$datastream_url = drupal_urlencode($datastream_file);
$url = file_create_url($datastream_url);
$return_value = $this->add_datastream_from_url($url, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup,$logMessage);
$return_value = $this->add_datastream_from_url($url, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage);
if ($original_path != $datastream_file) {
file_delete($datastream_file);
@ -75,8 +76,8 @@ class Fedora_Item {
return $return_value;
}
function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M',$logMessage = null) {
if (empty( $datastream_label)) {
function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) {
if (empty($datastream_label)) {
$datastream_label = $datastream_id;
}
@ -93,19 +94,21 @@ class Fedora_Item {
'dsState' => 'A',
'checksumType' => 'DISABLED',
'checksum' => 'none',
'logMessage' => ($logMessage != null)?$logMessage: 'Ingested object '. $datastream_id
'logMessage' => ($logMessage != null) ? $logMessage : 'Ingested object ' . $datastream_id
);
return $this->soap_call( 'addDataStream', $params );
}
function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M',$logMessage = null) {
function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = null) {
$dir = sys_get_temp_dir();
$tmpfilename = tempnam($dir, 'fedoratmp');
$tmpfile = fopen($tmpfilename, 'w');
fwrite($tmpfile, $str, strlen($str));
fclose($tmpfile);
$returnvalue = $this->add_datastream_from_file($tmpfilename, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup,$logMessage);
$returnvalue = $this->add_datastream_from_file($tmpfilename, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage);
unlink($tmpfilename);
return $returnvalue;
}
@ -121,7 +124,7 @@ class Fedora_Item {
if (empty($ds_list['RELS-EXT'])) {
$this->add_datastream_from_string(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="info:fedora/'. $this->pid . '">
<rdf:Description rdf:about="info:fedora/' . $this->pid . '">
</rdf:Description>
</rdf:RDF>', 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'text/xml', 'X');
}
@ -139,7 +142,7 @@ class Fedora_Item {
if ($description->length == 0) {
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'description');
}
$description=$description->item(0);
$description = $description->item(0);
// Create the new relationship node.
$newrel = $relsextxml->createElementNS($namespaceURI, $relationship);
@ -147,7 +150,7 @@ class Fedora_Item {
$newrel->setAttribute('rdf:resource', $object);
$description->appendChild($newrel);
$this->modify_datastream_by_value( $relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
$this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
//print ($description->dump_node());
/*
$params = array( 'pid' => $this->pid,
@ -205,7 +208,7 @@ class Fedora_Item {
}
}
if ($modified) {
$this->modify_datastream_by_value( $relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
$this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
}
return $modified;
//print ($description->dump_node());
@ -249,7 +252,7 @@ class Fedora_Item {
}
if (count($resultFields) > 0) {
$url .= '&'.join('=true&',$resultFields).'=true';
$url .= '&' . join('=true&', $resultFields) . '=true';
}
$resultxml = do_curl($url);
@ -267,14 +270,14 @@ class Fedora_Item {
}
foreach ($resultelements->resultList->objectFields as $obj) {
$ret = (string)$obj->title;
$ret = (string) $obj->title;
if (count($resultFields) > 0) {
$ret = array('title' => $ret);
foreach ($resultFields as $field) {
$ret[$field]=(string)$obj->$field;
$ret[$field] = (string) $obj->$field;
}
}
$results[(string)$obj->pid] = $ret;
$results[(string) $obj->pid] = $ret;
$cursor++;
if ($cursor >= $max_results) {
$done = TRUE;
@ -365,6 +368,7 @@ class Fedora_Item {
//}
return $this->datastreams_list;
}
/**
* * DatastreamControlGroup controlGroup - String restricted to the values of "X", "M", "R", or "E" (InlineXML,Managed Content,Redirect, or External Referenced).
* String ID - The datastream ID (64 characters max).
@ -386,7 +390,7 @@ class Fedora_Item {
* @return datastream object
* get the mimetype size etc. in one shot. instead of iterating throught the datastream list for what we need
*/
function get_datastream_info($dsid,$as_of_date_time = ""){
function get_datastream_info($dsid, $as_of_date_time = "") {
$params = array(
'pid' => $this->pid,
'dsID' => $dsid,
@ -394,7 +398,6 @@ class Fedora_Item {
);
return $this->soap_call('getDatastream', $params);
}
/**
@ -427,14 +430,14 @@ class Fedora_Item {
}
$ds_list[$ds->ID]['label'] = $ds->label;
$ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType;
$ds_list[$ds->ID]['URL'] = $this->url() . '/'. $ds->ID . '/'. drupal_urlencode($ds->label);
$ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label);
}
}
else {
$ds = $this->datastreams_list->datastreamDef;
$ds_list[$ds->ID]['label'] = $ds->label;
$ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType;
$ds_list[$ds->ID]['URL'] = $this->url().'/'.$ds->ID.'/'.drupal_urlencode($ds->label);
$ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label);
}
}
@ -472,8 +475,7 @@ class Fedora_Item {
$relationships = array();
try {
$relsext = $this->get_datastream_dissemination('RELS-EXT');
}
catch (exception $e) {
} catch (exception $e) {
drupal_set_message("Error retrieving RELS-EXT of object $pid", 'error');
return $relationships;
}
@ -510,12 +512,12 @@ class Fedora_Item {
// Verify the array format and that it isn't empty.
if (!empty($relationships)) {
$relsextxml = '<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fedora="info:fedora/fedora-system:def/relations-external#" xmlns:fedora-model="info:fedora/fedora-system:def/model#" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">'
. '<rdf:description rdf:about="'. $this->pid . '">';
. '<rdf:description rdf:about="' . $this->pid . '">';
foreach ($relationships as $rel) {
if (empty($rel['subject']) || empty($rel['predicate']) || empty($rel['object']) || $rel['subject'] != 'info:fedora/'. $this->pid) {
if (empty($rel['subject']) || empty($rel['predicate']) || empty($rel['object']) || $rel['subject'] != 'info:fedora/' . $this->pid) {
// drupal_set_message should use parameterized variables, not interpolated.
drupal_set_message("Error with relationship format: ". $rel['subject'] . " - ". $rel['predicate'] . ' - '. $rel['object'], "error");
drupal_set_message("Error with relationship format: " . $rel['subject'] . " - " . $rel['predicate'] . ' - ' . $rel['object'], "error");
return FALSE;
}
}
@ -539,7 +541,7 @@ class Fedora_Item {
return $this->soap_call('purgeObject', $params);
}
function purge_datastream( $dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) {
function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) {
$params = array(
'pid' => $this->pid,
'dsID' => $dsID,
@ -553,13 +555,14 @@ class Fedora_Item {
function url() {
global $base_url;
return $base_url . '/fedora/repository/'. $this->pid . (!empty($this->objectProfile) ? '/-/'. drupal_urlencode($this->objectProfile->objLabel) : '');
return $base_url . '/fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : '');
}
static function get_next_PID_in_namespace( $pid_namespace = '') {
static function get_next_PID_in_namespace($pid_namespace = '') {
if (empty($pid_namespace)) {
// Just get the first one in the config settings.
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$pid_namespace = $allowed_namespaces[0];
if (!empty($pid_namespace)) {
$pid_namespace = substr($pid_namespace, 0, strpos($pid_namespace, ":"));
@ -586,7 +589,7 @@ class Fedora_Item {
static function ingest_from_FOXML_file($foxml_file) {
$foxml = new DOMDocument();
$foxml->load( $foxml_file );
$foxml->load($foxml_file);
return self::ingest_from_FOXML($foxml);
}
@ -600,9 +603,9 @@ class Fedora_Item {
}
try {
self::ingest_from_FOXML_file( $path . '/'. $file );
}
catch (exception $e) {
self::ingest_from_FOXML_file($path . '/' . $file);
} catch (exception $e) {
}
}
// Close
@ -622,7 +625,7 @@ class Fedora_Item {
return self::soap_call('modifyObject', $params, $quiet);
}
function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API',$quiet=FALSE) {
function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array(
'pid' => $this->pid,
'dsID' => $dsid,
@ -639,7 +642,7 @@ class Fedora_Item {
return self::soap_call('modifyDatastreamByReference', $params, $quiet);
}
function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API',$quiet=FALSE) {
function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array(
'pid' => $this->pid,
'dsID' => $dsid,
@ -653,10 +656,10 @@ class Fedora_Item {
'logMessage' => $logMessage,
'force' => $force
);
return self::soap_call('modifyDatastreamByValue', $params,$quiet);
return self::soap_call('modifyDatastreamByValue', $params, $quiet);
}
static function soap_call( $function_name, $params_array, $quiet = FALSE ) {
static function soap_call($function_name, $params_array, $quiet = FALSE) {
if (!self::$connection_helper) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
self::$connection_helper = new ConnectionHelper();
@ -684,13 +687,13 @@ class Fedora_Item {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection."));
return NULL;
}
}
catch (exception $e) {
} catch (exception $e) {
if (!$quiet) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/',$e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name) ), 'error');
} else {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name)), 'error');
}
else {
drupal_set_message(t("Error trying to call SOAP function $function_name. Check watchdog logs for more information."), 'error');
}
@ -702,7 +705,7 @@ class Fedora_Item {
default:
try {
$soap_client = self::$connection_helper->getSoapClient( variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
$soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
if (!empty($soap_client)) {
$result = $soap_client->__soapCall($function_name, array('parameters' => $params_array));
}
@ -710,8 +713,7 @@ class Fedora_Item {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection."));
return NULL;
}
}
catch (exception $e) {
} catch (exception $e) {
if (!$quiet) {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to call SOAP function !fn: !e", array('!fn' => $function_name, '!e' => $e)), NULL, WATCHDOG_ERROR);
@ -722,7 +724,6 @@ class Fedora_Item {
return $result;
}
/**
* Creates the minimal FOXML for a new Fedora object, which is then passed to
* ingest_from_FOXML to be added to the repository.
@ -766,7 +767,7 @@ class Fedora_Item {
$owner_property = $foxml->createElement("foxml:property");
$owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId");
$owner_property->setAttribute("VALUE", $owner );
$owner_property->setAttribute("VALUE", $owner);
$object_properties->appendChild($state_property);
$object_properties->appendChild($label_property);
@ -778,7 +779,7 @@ class Fedora_Item {
}
static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') {
return self::ingest_from_FOXML(self::create_object_FOXML( $pid, $state, $label, $owner));
return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner));
}
static function fedora_item_exists($pid) {
@ -786,9 +787,9 @@ class Fedora_Item {
return $item->exists();
}
/********************************************************
/* * ******************************************************
* Relationship Functions
********************************************************/
* ****************************************************** */
/**
* Returns an associative array of relationships that this item has

2
api/fedora_utils.inc

@ -66,8 +66,10 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
}
function fedora_available() {
$response = do_curl(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe');
return strstr($response, 'Repository Information HTML Presentation') !== FALSE;
}

8
fedora_repository.install

@ -68,8 +68,8 @@ function fedora_repository_requirements($phase) {
// Check for ImageMagick
$requirements['fedora-imagemagick']['title'] = t("ImageMagick convert in \$PATH");
system('which convert', $res);
if ($res != 0) {
$result = exec('convert');
if (!$result) {
$requirements['fedora-imagemagick']['value'] = t('Not in $PATH');
$requirements['fedora-imagemagick']['description'] = t('Islandora will not be able to create thumbnails. Ensure that <a href="www.imagemagick.org/">ImageMagick</a> is installed and the convert command is executable by the web server user.');
$requirements['fedora-imagemagick']['severity'] = REQUIREMENT_WARNING;
@ -80,8 +80,8 @@ function fedora_repository_requirements($phase) {
}
$requirements['fedora-kakadu']['title'] = 'Kakadu kdu_compress in $PATH';
system('which kdu_compress', $kdu_res);
if ($kdu_res != 0) {
$kdu_res = exec('kdu_compress -v');
if (!$kdu_res) {
$requirements['fedora-kakadu']['value'] = ('Not in $PATH');
$requirements['fedora-kakadu']['description'] = t('Islandora cannot convert TIFF image files to JPEG2000 format. Ensure <a href="http://www.kakadusoftware.com/">Kakadu</a> is installed and the kdu_compress command is executable by the web server user.');
$requirements['fedora-kakadu']['severity'] = REQUIREMENT_WARNING;

98
fedora_repository.module

@ -101,11 +101,11 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label
if (!validPid($collection_pid)) {
if (validPid(urldecode($collection_pid))) {
$collection_pid = urldecode($collection_pid);
} else {
}
else {
drupal_set_message(t("This collection PID $collection_pid is not valid"), 'error');
return ' ';
}
}
if ($collection_pid == NULL) {
@ -145,7 +145,7 @@ function fedora_repository_ingest_form_submit($form, &$form_state) {
$form_state['values']['content_model_pid'] = $contentModelPid;
$form_state['values']['relationship'] = $relationship;
$err = (!$cm->execFormHandler($form_state['values'],$form_state));
$err = (!$cm->execFormHandler($form_state['values'], $form_state));
$_SESSION['fedora_ingest_files'] = ''; //empty this variable
@ -206,7 +206,8 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
implode(' ', $allowedMimeTypes)));
file_delete($file);
return;
} elseif (!$cm->execIngestRules($file, $dformat)) {
}
elseif (!$cm->execIngestRules($file, $dformat)) {
drupal_set_message(t('Error following Content Model Rules'), 'error');
foreach (ContentModel::$errors as $err) {
drupal_set_message($err, 'error');
@ -245,19 +246,19 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
'#type' => 'hidden',
'#value' => "$pid"
);
if (!strstr( drupal_get_destination(), urlencode('fedora/repository'))) {
if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) {
$form['referrer'] = array(
'#type' => 'hidden',
'#value' => $referrer,
);
}
if(!isset($form_state['storage']['confirm'])) {
if (!isset($form_state['storage']['confirm'])) {
// do your normal $form definition here
$form['submit'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'fedora_repository').'/images/purge_big.png',
'#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png',
'#value' => t('Purge'),
'#suffix' => 'Purge this object',
);
@ -425,7 +426,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
} catch (exception $e) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error');
} else {
}
else {
drupal_set_message(t($e->getMessage()), 'error');
}
return;
@ -544,11 +546,13 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
*/
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
$item = new Fedora_Item($pid);
$item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat);
$form_state['redirect'] = 'fedora/repository/' . $pid;
}
function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) {
@ -719,22 +723,30 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
global $user;
if (!fedora_available()) {
drupal_set_message('The Fedora repository server is currently unavailable. Please contact the site administrator.', 'warning', FALSE);
return '';
}
if ($pid &!validPid($pid)) {
drupal_set_message(t("Invalid PID!"), 'error');
return ' ';
}
if ($dsId &!validDsid($dsId)) {
if ($dsId & !validDsid($dsId)) {
drupal_set_message(t("Invalid dsID!"), 'error');
return ' ';
}
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');
if (user_access('access administration pages')) {
drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed !here", array('!here' => l('here', 'admin/settings/fedora_repository'))), 'warning');
}
drupal_access_denied();
exit;
return ' ';
}
@ -835,11 +847,16 @@ function repository_page($pid = NULL, $dsId = NULL, $collection = NULL, $pageNum
}
function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NULL) {
module_load_include('inc','fedora_repository', 'api/fedora_item');
module_load_include('inc','fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
global $user;
if (!fedora_repository_access(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied!"), 'error');
//drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied"), 'error');
drupal_access_denied();
if (user_access('access administration pages')) {
drupal_set_message(t("PIDs may be added to allowed namespaces, or all namespace restrictions removed !here", array('!here' => l('here', 'admin/settings/fedora_repository'))), 'error');
}
return ' ';
}
if ($pid == NULL) {
@ -854,13 +871,11 @@ function repository_service($pid = NULL, $servicePid = NULL, $serviceMethod = NU
$item = new Fedora_Item($pid);
if ($item !== false)
{
echo $item->get_dissemination($servicePid,$serviceMethod);
if ($item !== false) {
echo $item->get_dissemination($servicePid, $serviceMethod);
}
exit();
}
//Search Stuff ********************************************************************
@ -925,7 +940,8 @@ function fedora_repository_search($op = 'search', $keys = NULL) {
$searchQuery = NULL;
if (isset($type) && strcmp($type, ':')) {
$searchQuery = $type . ':' . $keys;
} else {
}
else {
$searchQuery = $keys;
}
//$searchQuery.=" AND (PID:vre OR PID:vre:ref OR PID:demo OR PID:changeme)";
@ -955,6 +971,7 @@ function fedora_repository_search($op = 'search', $keys = NULL) {
*/
function fedora_repository_search_page($resultData) {
$path = drupal_get_path('module', 'fedora_repository');
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$proc = NULL;
if (!$resultData[0][0]['data']) {
return ''; //no results
@ -980,8 +997,13 @@ function fedora_repository_search_page($resultData) {
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$proc->registerPHPFunctions();
$xsl = new DomDocument();
if ($isRestricted) {
$xsl->load($path . '/xsl/results.xsl');
$quimby = $xsl;
}
else {
$xsl->load($path . '/xsl/unfilteredresults.xsl');
}
$input = new DomDocument();
$didLoadOk = $input->loadXML(utf8_encode($resultData[0][0]['data']));
@ -992,7 +1014,8 @@ function fedora_repository_search_page($resultData) {
'colspan' => 2
)
);
} else {
}
else {
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
@ -1159,12 +1182,13 @@ function fedora_repository_theme() {
'arguments' => array(
'element' => NULL
),
),
'fedora_repository_solution_packs_list' => array(
'arguments' => array(
'solution_packs' => NULL,
),
),
),
);
}
@ -1192,6 +1216,7 @@ function theme_fedora_repository_mnpl_advanced_search_form($form) {
function fedora_repository_mnpl_advanced_search($query, $startPage = 1) {
module_load_include('inc', 'fedora_repository', 'SearchClass');
$searchClass = new SearchClass();
$retVal = $searchClass->custom_search($query, $startPage);
return $searchClass->custom_search($query, $startPage);
}
@ -1255,7 +1280,8 @@ function fedora_repository_demo_objects_form() {
if (empty($demo_objects[$available_demo]->objectProfile)) {
//The demo objects collection does not exist in the repository, display a button to ingest them.
$form['install_demos']['demo_collections']['#options'][$available_demo] = $available_demo_desc;
} else {
}
else {
array_push($existing_demos, $demo_objects[$available_demo]);
}
}
@ -1267,12 +1293,14 @@ function fedora_repository_demo_objects_form() {
$datastreams_list = $smiley_stuff->get_datastreams_list_as_array();
if (empty($datastreams_list['COLLECTION_VIEW'])) {
$form['install_demos']['demo_collections']['#options']['demo:SmileyStuff'] = 'Add Islandora Collection View to Fedora Smiley Stuff Collection';
} else {
}
else {
$demo_objects['demo:SmileyStuff'] = $smiley_stuff;
}
} else {
}
else {
$form['install_demos']['smileynote'] = array(
'#value' => '<p>If you install the '.l('fedora demo objects', 'https://wiki.duraspace.org/display/FCR30/Demonstration+Objects').' Islandora can display them as a collection.</p>'
'#value' => '<p>If you install the ' . l('fedora demo objects', 'https://wiki.duraspace.org/display/FCR30/Demonstration+Objects') . ' Islandora can display them as a collection.</p>'
);
}
@ -1291,7 +1319,7 @@ function fedora_repository_demo_objects_form() {
if (!empty($existing_demos)) {
foreach ($existing_demos as $pid => $demo_object) {
$form['existing_demos'][$demo_object->pid] = array (
$form['existing_demos'][$demo_object->pid] = array(
'#prefix' => '<li>',
'#value' => l($demo_object->pid, $demo_object->url()),
'#suffix' => '</li>',
@ -1693,7 +1721,8 @@ function fedora_repository_basket_form($form_state, $pids) {
$form['pid'] = array();
$form['title'] = array();
$form['desc'] = array();
} else {
}
else {
return;
}
@ -1751,7 +1780,8 @@ function theme_fedora_repository_basket_form($form) {
drupal_render($form['desc'][$key]),
);
}
} else {
}
else {
$rows[] = array(array('data' => t('Your basket is empty.'), 'colspan' => '4'));
}
@ -1789,7 +1819,8 @@ function fedora_repository_basket_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == $form_state['values']['submit_all']) {
$msg = t("All objects exported to staging area");
$pids = _fedora_repository_get_basket_pids();
} elseif ($form_state['values']['op'] == $form_state['values']['submit']) {
}
elseif ($form_state['values']['op'] == $form_state['values']['submit']) {
$msg = t("Selected objects exported to staging area");
$pids = array_filter($form_state['values']['remove']);
}
@ -1824,7 +1855,8 @@ function fedora_repository_basket_form_submit($form, &$form_state) {
drupal_set_message($msg, $success ? 'info' : 'error');
//_fedora_repository_empty_basket();
} else {
}
else {
drupal_set_message(t("No objects selected or basket empty"), 'error');
}
@ -1874,7 +1906,8 @@ function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = array();
$_SESSION['basket']['unprocessed'] = array($pid => $pid);
} else {
}
else {
$_SESSION['basket']['unprocessed'][$pid] = $pid;
}
@ -1926,7 +1959,8 @@ function fedora_repository_display_schema($file) {
$path = drupal_get_path('module', 'fedora_repository');
if (strtolower(substr($file, -3)) == 'xsd' && file_exists($path . '/' . $file)) {
drupal_goto($path . '/' . $file);
} else {
}
else {
drupal_goto();
}
return;

145
formClass.inc

@ -4,9 +4,6 @@
/*
* Created on Jan 22, 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class formClass {
@ -28,10 +25,8 @@ class formClass {
'description' => t('Enter the Fedora Collection information here'),
'page callback' => 'drupal_get_form',
'page arguments' => array('fedora_repository_admin'),
//'access' => user_access('access administration pages'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
// 'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/fedora_repository/collection'] = array(
'title' => t('Collection list'),
@ -55,9 +50,7 @@ class formClass {
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('islandoracm.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['collection_policy.xsd'] = array(
@ -65,30 +58,25 @@ class formClass {
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('collection_policy.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['fedora'] = array(
// 'title' => t('Digital repository'),
'page callback' => 'repository_page',
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$repository_title = variable_get('fedora_repository_title','Digital repository');
if (trim($repository_title)!= '') {
$respository_title=t($repository_title);
} else {
$repository_title= NULL;
$repository_title = variable_get('fedora_repository_title', 'Digital repository');
if (trim($repository_title) != '') {
$respository_title = t($repository_title);
}
else {
$repository_title = NULL;
}
$items['fedora/repository'] = array(
'title' => $repository_title,
'page callback' => 'repository_page',
'type' => MENU_NORMAL_ITEM,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
@ -203,23 +191,6 @@ class formClass {
'access arguments' => array('view fedora collection'),
);
/*
$items['fedora/item'] = array (
'title' => t('Repository Item'),
'access arguments' => array('view fedora collection'),
'page callback' => 'fedora_repository_item',
'type' => MENU_NORMAL_ITEM,
);
$item['feodra/item/view'] = array (
'title' => t('View Repository Item'),
'access arguments' => array('view fedora collection'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
*/
// $items = array_merge($items,$irItems);
return $items;
}
@ -298,7 +269,6 @@ class formClass {
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => 0,
// '#suffix' => '<p>'. (fedora_available() ? '<img src="'. url('misc/watchdog-ok.png') . '"/>'. t('Successfully connected to Fedora server at ') : '<img src="'. url('misc/watchdog-error.png') . '"/> '. t('Unable to connect to Fedora server at ')) . variable_get('fedora_soap_url', '') . '</p>',
'#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', '')))),
);
$form['fedora_base_url'] = array(
@ -326,90 +296,79 @@ class formClass {
'#weight' => 0
);
/*
$form['fedora_default_display_pid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Object Pid' ),
'#default_value' => variable_get('fedora_default_display_pid', 'demo:10'),
'#description' => t('Object Pid of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) {
$form['fedora_namespace'] = array(
'#type' => 'fieldset',
);
$form['fedora_default_display_dsid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Datastream ID' ),
'#default_value' => variable_get('fedora_default_display_dsid', 'TN'),
'#description' => t('Object Datastream id of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
$form['fedora_namespace']['fedora_namespace_restriction_enforced'] = array(
'#weight' => -1,
'#type' => 'radios',
'#title' => t('Enforce namespace restrictions'),
'#options' => array(
TRUE => t('Enabled'),
FALSE => t('Disabled')
),
'#description' => t('Allow administrator to restrict user\'s access to the PID namepaces listed below'),
'#default_value' => variable_get('fedora_namespace_restriction_enforced', TRUE)
);
*/
$form['fedora_pids_allowed'] = array(
$form['fedora_namespace']['fedora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '),
'#description' => t('The PID namespaces that you are allowed to see from this Drupal install. In reality this can be more than a namespace as it could include demo:mydemos etc. Can be a space seperated list to include more than one PID namespace.'),
'#required' => TRUE,
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '),
'#description' => t('A space separated list PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
/*
$form['fedora_admin_user'] = array(
}
else {
$form['fedora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('A user with the Drupal role administrator'),
'#default_value' => variable_get('fedora_admin_user', 'admin'),
'#description' => t('A user with the administrator role. This is the user the Islandora module will use when admin access is needed for a task, such as creating a collection object for a new user.'),
'#required' => TRUE, '#weight' => 0
);
$form['fedora_searchterms_location'] = array(
'#type' => 'file',
'#title' => 'SearchTerms.xml file location',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '),
'#description' => t('A space separated list PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
*/
}
$form['fedora_repository_title'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Repository Title'),
'#default_value'=> variable_get('fedora_repository_title', 'Digital Repository'),
'#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.'),
);
$form['fedora_object_display_title'] = array(
'#type' => 'select',
'#title' => t('Display Object Title Behaviour'),
'#default_value'=> variable_get('fedora_object_display_title', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#default_value' => variable_get('fedora_object_display_title', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the object (or collection) title when viewing an object/collection page.'),
);
$form['fedora_object_display_description'] = array(
'#type' => 'select',
'#title' => t('Display Object Description Behaviour'),
'#default_value'=> variable_get('fedora_object_display_description', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#default_value' => variable_get('fedora_object_display_description', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the default object (or collection) description fieldset when viewing an object/collection page.'),
);
$form['fedora_object_restrict_datastreams'] = array(
'#type' => 'checkbox',
'#title' => t('Restrict Access to Fedora Object Datastreams'),
'#default_value'=> variable_get('fedora_object_restrict_datastreams', FALSE),
'#default_value' => variable_get('fedora_object_restrict_datastreams', FALSE),
'#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'),
);
$form['fedora_collection_display_list'] = array(
'#type' => 'select',
'#title' => t('Display Collection List Behaviour'),
'#default_value'=> variable_get('fedora_collection_display_list', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#default_value' => variable_get('fedora_collection_display_list', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the list of objects when viewing a collection page.'),
);
//Export functionality
$form['module']['export_area'] = array(
'#type' => 'textfield',
@ -555,7 +514,6 @@ class formClass {
'#options' => $modelsForForm,
//'#description' => t('Content models available in this collection. A content model defines what is allowed in a collection and what to do with a file when it is uploaded (An example may creating a thumbnail from an image.).')
'#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> ')
);
break;
@ -660,15 +618,6 @@ class formClass {
'#type' => 'hidden',
'#value' => "$pid"
);
/*
$form['stream_location'] = array (
'#title' => 'File Location',
'#required' => 'TRUE',
'#description' => 'The path to the file for the new datastream',
//'#prefix' => '<a onclick="window.open(\'?q=imce/browse\', \'_imce_fedora_\', \'width=640, height=600, resizable=1\')" href="#">Upload File</a>',
'#type' => 'hidden'
);
*/
$form['stream_label'] = array(
'#title' => 'Datastream Label',
@ -676,13 +625,7 @@ class formClass {
'#description' => t('A Human readable label'),
'#type' => 'textfield'
);
// $form['delete_file'] = array (
// '#title' => 'Remove File After Ingest',
// '#description' => 'Remove the file from the drupal file system after ingest into the Digital Repository.',
// '#type' => 'hidden',
// '#default_value' => 'remove_file',
// '#options' => $options
// );
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['add-stream-file-location'] = array(
'#type' => 'file',
@ -709,9 +652,7 @@ class formClass {
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
);
$form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids);
}
else {
$form['stream_id'] = array(
@ -800,7 +741,7 @@ class formClass {
}
}
}
// $form['#redirect'] = "fedora/repository/$pid/";
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
@ -852,5 +793,5 @@ class formClass {
return $form;
}
}
}

1
ilives/fedora_ilives.module

@ -549,6 +549,7 @@ function install_book_content_model_objects() {
$allowed_pids_str = variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ');
$allowed_pids = explode(' ', $allowed_pids_str);
if (!in_array('ilives:', $allowed_pids)) {
variable_set('fedora_pids_allowed', $allowed_pids_str . ' ilives:');
drupal_set_message('Added ilives: to the set of allowed pidnamespaces.', 'info');

2
plugins/fedoraObject.inc

@ -27,7 +27,7 @@ class FedoraObject {
);
$dc_html = $objectHelper->getFormattedDC($this->item);
$ds_list = $objectHelper->getFormattedDatastreamList($this->pid, NULL, $this->item);
$ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item);
$tabset['fedora_object_details']['tabset']['view'] = array(

6
plugins/fedora_attach/fedora_attach.admin.inc

@ -14,10 +14,12 @@
* @see system_settings_form().
*/
function fedora_attach_admin() {
$options = drupal_map_assoc(explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ')));
$options = drupal_map_assoc(explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: ')));
$default_value = variable_get('fedora_attach_pid_namespace', 'default:');
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if (!in_array($default_value, $options)) {
if (!in_array($default_value, $options) && $isRestricted) {
drupal_set_message( "The value last set here ($default_value) is not in the list of available PID namespaces (perhaps it has changed?). Please choose a valid option from the list.", 'warning' );
}

205
tests/fedora_repository.test

@ -1,38 +1,14 @@
<?php
// $Id$
/*
* Tests the functions of the Fedora Repository module.
*/
* Tests the functions of the Fedora Repository module.
*/
class FedoraRepositoryTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Fedora Repository',
'description' => t('The Fedora repository content models.'),
'group' => t('fedora repository'),
);
}
function setUp() {
parent::setUp('fedora_repository', 'tabs');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// Create and login user.
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams',
'edit fedora meta data',
'edit tags datastream',
'ingest new fedora objects',
'purge objects and datastreams',
'view fedora collection',
'view detailed list of content'));
$this->drupalLogin($repository_user);
}
public function testDatastreams() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -195,4 +171,179 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
$account->pass_raw = $edit['pass'];
return $account;
}
public static function getInfo() {
return array(
'name' => 'Fedora Repository',
'description' => t('The Fedora repository content models.'),
'group' => t('fedora repository'),
);
}
function setUp() {
parent::setUp('fedora_repository');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// Create and login user.
$repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams',
'edit fedora meta data',
'edit tags datastream',
'ingest new fedora objects',
'purge objects and datastreams',
'view fedora collection'));
$this->repository_user = $repository_user;
$this->drupalLogin($repository_user);
}
/**
* Add an item based on a content model. Initially we will assume that the repository
* will be populated with the default content models and collections that are
* created from the admin settings -> Install Demos page.
*
*/
public function testIngest() {
// Check that the 'Strict PDF' content model exists in the repository.
//$pdf_cm = new Fedora_Item('islandora:strict_pdf');
$pid_list = array();
// Create a collection for ingesting PDF content model objects.
//$this->drupalGet('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection');
$ingest_form = array();
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM';
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next');
// Add a sample PDF object via the web ingest form.
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_form_step_2['dc:title'] = $this->randomName(32);
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
$this->assertText('mimetype (application/pdf) is not associated with this Content Model', 'PDF mime type not accepted in collection content model.', 'message');
$this->outputScreenContents('Initial ingest form submit step 2', 'fedora_repository');
// Now try ingesting a proper collection policy.
$ingest_form = array();
$ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM';
$this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next');
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_form_step_2['dc:title'] = $this->randomName(32);
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
//$this->outputScreenContents('Initial ingest form submit step 2 - PDF collection', 'fedora_repository');
$this->assertPattern('/Item .* created successfully./', "Verified item created.");
$pid = $this->getIngestedPid();
$pid_list[] = $pid;
$this->pass('Now attempting to ingest a PDF into the new collection.');
// Now try ingesting a PDF
$ingest_form = array();
$ingest_form['models'] = 'islandora:strict_pdf/ISLANDORACM';
$this->drupalPost("fedora/ingestObject/$pid/", $ingest_form, 'Next');
// Required fields are file location, dc:title and dc:description
$ingest_form_step_2 = array();
$ingest_form_step_2['dc:title'] = "Lorem Ipsum";
$ingest_form_step_2['dc:description'] = $this->randomName(256);
$ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf');
$this->drupalPost(NULL, $ingest_form_step_2, 'Ingest');
$pid = $this->getIngestedPid();
$pid_list[] = $pid;
if (!empty($pid)) {
$this->pass("Successfully ingested PDF object $pid.");
}
$this->cleanUpRepository($pid_list);
}
public function testPidSpaceRestriction() {
// give user full permissions
$admin_tester = $this->drupalCreateUser(array('administer site configuration', 'view fedora collection'));
$this->drupalLogin($admin_tester);
$pageContent = $this->drupalGet('admin/settings/fedora_repository');
$hasOption = preg_match('/Enforce namespace restrictions/', $pageContent);
if (!$hasOption) {
$this->pass('Removal of namespace restrictions is disabled');
}
else {
$this->pass('Removal of namespace restrictions is enabled');
$inVal['fedora_namespace_restriction_enforced'] = TRUE;
$inVal['fedora_pids_allowed'] = 'simpletest:';
$this->drupalPost('admin/settings/fedora_repository', $inVal, 'Save configuration');
$this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.');
$this->drupalGet('fedora/repository/islandora:largeimages/');
$this->assertPattern('/Access denied/', 'No access to Large image Collection Collection');
$inVal['fedora_namespace_restriction_enforced'] = 0;
$this->drupalPost('admin/settings/fedora_repository', $inVal, 'Save configuration');
$this->assertPattern('/The configuration options have been saved./', 'The configuration options have been saved.');
$this->drupalLogin($this->repository_user);
$this->drupalGet('fedora/repository/islandora:largeimages/');
$this->assertPattern('/Large Images Collection/', 'Access to Large Images Collection');
}
}
private function cleanUpRepository($pid_list = array()) {
$this->pass("This is the PID list to purge: " . implode(", ", $pid_list));
foreach ($pid_list as $pid) {
$this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge');
}
}
private function getIngestedPid() {
$subject = $this->drupalGetContent();
$pattern = '/">(.*)<\/a> created successfully./';
$matches = array();
$res = preg_match($pattern, $subject, $matches);
return $matches[1];
}
private function outputScreenContents($description, $basename) {
// This is a hack to get a directory that won't be cleaned up by SimpleTest.
$file_dir = file_directory_path() . '../simpletest_output_pages';
if (!is_dir($file_dir)) {
mkdir($file_dir, 0777, TRUE);
}
$output_path = "$file_dir/$basename." . $this->randomName(10) . '.html';
$rv = file_put_contents($output_path, $this->drupalGetContent());
$this->pass("$description: Contents of result page are " . l('here', $output_path));
}
protected function drupalCreateFedoraUser($permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) {
// Create a role with the given permission set.
if (!($rid = $this->drupalCreateRole($permissions))) {
return FALSE;
}
// Create a user assigned to that role.
$edit = array();
$edit['name'] = 'simpletestuser';
$edit['mail'] = $edit['name'] . '@example.com';
$edit['roles'] = array($rid => $rid);
$edit['pass'] = 'simpletestpass';
$edit['status'] = 1;
$account = user_save('', $edit);
$this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
if (empty($account->uid)) {
return FALSE;
}
// Add the raw password so that we can log in as this user.
$account->pass_raw = $edit['pass'];
return $account;
}
}

269
xsl/unfilteredresults.xsl

@ -0,0 +1,269 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:variable name="OBJECTSPAGE">
<xsl:value-of select="$objectsPage"/>
</xsl:variable>
<xsl:template match="gfindObjects">
<xsl:variable name="INDEXNAME" select="@indexName"/>
<xsl:variable name="PREQUERY" select="substring-before(@query,':')"/>
<xsl:variable name="QUERY" select="substring-after(@query,':')"/>
<xsl:variable name="HITPAGESTART" select="@hitPageStart"/>
<xsl:variable name="HITPAGESIZE" select="@hitPageSize"/>
<xsl:variable name="HITTOTAL" select="@hitTotal"/>
<xsl:variable name="SEARCHURL">
<xsl:value-of select="$searchUrl"/>
</xsl:variable>
<xsl:variable name="TOKEN">
<xsl:value-of select="$searchToken"/>
</xsl:variable>
<xsl:variable name="HITPAGEEND">
<xsl:choose>
<xsl:when test="$HITPAGESTART + $HITPAGESIZE - 1 > $HITTOTAL">
<xsl:value-of select="$HITTOTAL"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$HITPAGESTART + $HITPAGESIZE - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="HITPAGENO" select="ceiling($HITPAGESTART div $HITPAGESIZE)"/>
<xsl:variable name="HITPAGENOLAST" select="ceiling($HITTOTAL div $HITPAGESIZE)"/>
<xsl:variable name="HITPAGESTARTT" select="(($HITPAGENO - 1) * $HITPAGESIZE + 1)"/>
<xsl:choose>
<xsl:when test="$HITTOTAL > 0">
Total Hits =
<strong>
<xsl:value-of select="@hitTotal"/>,
</strong>
Number of Hits/page =
<xsl:value-of select="@hitPageSize"/>
<!-- Current page = <xsl:value-of select="@hitPageStart"/>-->
<br/>
<!--<form action="/drupal-5.1/?q=search/fedora_collections" method="post" id="search-form" class="search-form">-->
<form action="{$SEARCHURL}" method="post" id="search-form" class="search-form">
<input type="hidden" maxlength="255" name="keys" id="edit-keys" size="40" value="{$HITPAGESTARTT+$HITPAGESIZE}:{$QUERY}" class="form-text" />
<!--<xsl:if test="$PREQUERY = fgs.DS.first.text" >-->
<input type="hidden" name="type" id="edit-type" value="{$PREQUERY}" />
<!--</xsl:if>-->
<xsl:if test="$HITPAGENO > 1">
<input type="button" name="back" onClick="javascript:history.go(-1)" id="back-button" value="Previous" class="form-submit" />
</xsl:if>
<xsl:if test="$HITPAGENO &lt; $HITPAGENOLAST">
<input type="submit" name="op" id="edit-submit" value="Next" class="form-submit" />
</xsl:if>
<input type="hidden" name="form_token" id="edit-search-form-form-token" value="{$TOKEN}" />
<input type="hidden" name="form_id" id="edit-search-form" value="search_form" />
</form>
<style type="text/css">
span.highlight
{
background-color:yellow
}
span.searchtitle
{
font-weight: bold
}
</style>
<xsl:apply-templates select="objects"/>
</xsl:when>
<xsl:otherwise>
<div class="box">
<h2>Your search yielded no results</h2>
<div class="content">
<ul>
<li>Check if your spelling is correct.</li>
<li>Remove quotes around phrases to match each word individually:
<em>"blue smurf"</em> will match less than
<em>blue smurf</em>.
</li>
<li>Consider loosening your query with
<em>OR</em>:
<em>blue smurf</em> will match less than
<em>blue OR smurf</em>.
</li>
</ul>
</div>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="objects">
<table>
<div class="search-results">
<xsl:for-each select="object">
<xsl:variable name="PIDVALUE">
<xsl:choose>
<xsl:when test="@PID">
<xsl:value-of select="@PID"/>
</xsl:when>
<xsl:when test="field[@name='PID' and @snippet='yes']">
<xsl:value-of select="field[@name='PID']/span/text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="field[@name='PID']/text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="showResult">
<xsl:with-param name="PIDVALUE" select="$PIDVALUE"/>
</xsl:call-template>
</xsl:for-each>
</div>
</table>
</xsl:template>
<xsl:template name="showResult">
<xsl:param name="PIDVALUE"/>
<xsl:variable name="DCTITLE">
<xsl:value-of select="field[@name='dc.title']/node()"/>
</xsl:variable>
<xsl:variable name="CLEANTITLE">
<xsl:value-of select="php:functionString('fedora_repository_urlencode_string', $DCTITLE)"/>
</xsl:variable>
<tr>
<td valign="top">
<a>
<xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/
<xsl:copy-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute>
<!--<xsl:attribute name="href"><xsl:copy-of select="$OBJECTSPAGE"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>
</xsl:attribute>-->
<img>
<xsl:attribute name="src">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/
<xsl:copy-of select="$PIDVALUE"/>/TN
</xsl:attribute>
</img>
</a>
</td >
<td width="80%" valign="top">
<table valign="top">
<tr valign="top">
<td valign="top" class="search-results" colspan="2">
<xsl:value-of select="@no"/>
<xsl:value-of select="'. '"/>
<a>
<!--<xsl:attribute name="href"><![CDATA[http://localhost/drupal-5.1/?q=node/7&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>-->
<!--<xsl:attribute name="href"><xsl:copy-of select="$OBJECTSPAGE"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>-->
<xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/
<xsl:value-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute>
<xsl:value-of select="$PIDVALUE"/>
<br />
</a>
<span class="searchtitle">
<span >
Score:(
<xsl:value-of select="@score"/>)
</span>
<br />
<a>
<!--<xsl:attribute name="href"><xsl:copy-of select="$OBJECTSPAGE"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>-->
<xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/
<xsl:value-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute>
<xsl:value-of select="field[@name='dc.title']/node()" disable-output-escaping="yes"/>
</a>
</span>
</td>
</tr>
<xsl:for-each select="field[@snippet='yes']">
<xsl:choose>
<xsl:when test="(@name='fgs.DS.first.text')">
<tr>
<td valign="top">
<span class="searchtitle">
Text Stream<!--<xsl:value-of select="@name"/>-->
</span>
</td>
<td>
<span class="text">
<xsl:copy-of select="node()"/>
</span>
</td>
</tr>
</xsl:when>
<xsl:when test="(@name='dc.title')">
</xsl:when>
<xsl:otherwise>
<tr>
<td valign="top">
<span class="searchtitle">
<xsl:value-of select="@name"/>
</span>
</td>
<td>
<span class="text">
<xsl:copy-of select="node()"/>
</span>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save