Browse Source

Merge branch '6.x' of github.com:Islandora/islandora into 6.x

Conflicts:
	api/fedora_utils.inc
pull/23/head
Ben Woodhead 13 years ago
parent
commit
744b72b993
  1. 196
      CollectionClass.inc
  2. 76
      api/fedora_utils.inc
  3. 7
      fedora_repository.install
  4. 12
      xsl/results.xsl
  5. 21
      xsl/sparql_to_html.xsl

196
CollectionClass.inc

@ -1,6 +1,5 @@
<?php <?php
/** /**
* @file * @file
* *
@ -40,6 +39,7 @@ class CollectionClass {
* gets objects related to this object. must include offset and limit * gets objects related to this object. must include offset and limit
* calls getRelatedItems but enforces limit and offset * calls getRelatedItems but enforces limit and offset
*/ */
function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
@ -99,7 +99,7 @@ class CollectionClass {
} }
/** /**
* getCollectionPolicyStream ?? *
* @param type $collection_pid * @param type $collection_pid
* @return type * @return type
*/ */
@ -112,7 +112,7 @@ class CollectionClass {
} }
/** /**
* getRelationshipElement *
* @param type $collection_pid * @param type $collection_pid
* @return type * @return type
*/ */
@ -129,7 +129,7 @@ class CollectionClass {
} }
/** /**
* getCollectionViewStream ?? *
* @param type $collection_pid * @param type $collection_pid
* @return type * @return type
*/ */
@ -139,7 +139,7 @@ class CollectionClass {
} }
/** /**
* getStream ?? *
* @param type $pid * @param type $pid
* @param type $dsid * @param type $dsid
* @param type $showError * @param type $showError
@ -152,7 +152,7 @@ class CollectionClass {
} }
/** /**
* getPidNameSpace ?? *
* @param type $pid * @param type $pid
* @param type $dsid * @param type $dsid
* @return type * @return type
@ -249,7 +249,7 @@ class CollectionClass {
} }
/** /**
* getAllowedMimeType ?? *
* @param type $contentModelPid * @param type $contentModelPid
* @param type $contentModel_dsid * @param type $contentModel_dsid
* @return type * @return type
@ -320,7 +320,7 @@ class CollectionClass {
$thisClass = new $phpClass (); $thisClass = new $phpClass ();
$returnValue = $thisClass->$phpMethod($parametersArray, $dsid, $file, $file_ext); $returnValue = $thisClass->$phpMethod($parametersArray, $dsid, $file, $file_ext);
if (!$returnValue) { if (!$returnValue) {
drupal_set_message(t('Error! Failed running content model method !m !rv'), array('!m' => $phpMethod, '!rv' => $returnValue)); drupal_set_message('Error! Failed running content model method !m !rv', array('!m' => $phpMethod, '!rv' => $returnValue));
return FALSE; return FALSE;
} }
} }
@ -394,9 +394,8 @@ class CollectionClass {
} }
/** /**
* This will also create a personal collection for an existing user if they don't have one * this will also create a personal collection for an existing user if they don't have one
* not using this function currently. * not using this function currently
*
* @param type $user * @param type $user
* @return type * @return type
*/ */
@ -419,8 +418,8 @@ class CollectionClass {
'pidNamespace' => $pidNameSpace 'pidNamespace' => $pidNameSpace
); );
$object = $soapClient->__soapCall('getNextPID', array( $object = $soapClient->__soapCall('getNextPID', array(
$params $params
)); ));
} catch (exception $e) { } catch (exception $e) {
drupal_set_message(t('Error getting Next PID: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Error getting Next PID: !e', array('!e' => $e->getMessage())), 'error');
return FALSE; return FALSE;
@ -434,7 +433,7 @@ class CollectionClass {
module_load_include('inc', 'fedora_repository', 'plugins/PersonalCollectionClass'); module_load_include('inc', 'fedora_repository', 'plugins/PersonalCollectionClass');
$personalCollectionClass = new PersonalCollectionClass(); $personalCollectionClass = new PersonalCollectionClass();
if (!$personalCollectionClass->createCollection($user, $pid, $soapClient)) { if (!$personalCollectionClass->createCollection($user, $pid, $soapClient)) {
drupal_set_message(t("Did not create a personal collection object for !u"), array('!u' => $user->name)); drupal_set_message("Did not create a personal collection object for !u", array('!u' => $user->name));
return FALSE; //creation failed don't save the collection pid in drupal db return FALSE; //creation failed don't save the collection pid in drupal db
} }
user_save($user, $personal_collection_pid); user_save($user, $personal_collection_pid);
@ -456,7 +455,7 @@ class CollectionClass {
} }
/** /**
* showFieldSets ?? *
* @global type $base_url * @global type $base_url
* @global type $user * @global type $user
* @param type $page_number * @param type $page_number
@ -465,9 +464,7 @@ class CollectionClass {
function showFieldSets($page_number) { function showFieldSets($page_number) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_url; global $base_url;
$tabset = array(); $tabset = array();
global $user; global $user;
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
$item = new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
@ -482,10 +479,16 @@ class CollectionClass {
// Check the form post to see if we are in the middle of an ingest operation. // Check the form post to see if we are in the middle of an ingest operation.
$show_ingest_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_ingest_form'); $show_ingest_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_ingest_form');
$add_to_collection = $this->getIngestInterface(); $add_to_collection = $this->getIngestInterface();
if (!$show_ingest_tab) {
$view_selected = true;
}
drupal_set_message();
$tabset['view_tab'] = array( $tabset['view_tab'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => 'View', '#title' => 'View',
'#selected' => $view_selected,
'#content' => $collection_items '#content' => $collection_items
); );
$tabset['add_tab'] = array( $tabset['add_tab'] = array(
@ -496,11 +499,19 @@ class CollectionClass {
// This will be the content of the tab. // This will be the content of the tab.
'#content' => $add_to_collection, '#content' => $add_to_collection,
); );
$tabset['add_collection_tab'] = array(
// #type and #title are the minimum requirements.
'#type' => 'tabpage',
'#title' => t('Add Child Collection'),
// This will be the content of the tab.
'#content' => drupal_get_form('collection_creation_form', $this->pid),
);
return $tabset; return $tabset;
} }
/** /**
* getIngestInterface ?? *
* @global type $base_url * @global type $base_url
* @return string * @return string
*/ */
@ -527,16 +538,6 @@ class CollectionClass {
return $ingestObject; return $ingestObject;
} }
/**
* renderCOllection ??
* @global type $base_url
* @param type $content
* @param type $pid
* @param type $dsId
* @param type $collection
* @param int $pageNumber
* @return type
*/
function renderCollection($content, $pid, $dsId, $collection, $pageNumber = NULL) { function renderCollection($content, $pid, $dsId, $collection, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
global $base_url; global $base_url;
@ -605,3 +606,142 @@ class CollectionClass {
} }
/**
*
* @param type $form_state
* @param type $parent_collection_pid
* @return type
*/
function collection_creation_form(&$form_state, $parent_collection_pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = FALSE;
if (variable_get('fedora_namespace_restriction_enforced', true)) {
$restricted = true;
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[trim($namespace)] = trim($namespace);
}
}
}
$content_models = get_content_models_as_option_array();
$form['titlebox'] = array(
'#type' => 'item',
'#value' => t("Create New Child Collection within $collection_pid"),
);
$form['collection_name'] = array(
'#title' => "Collection Name",
'#type' => 'textfield',
'#description' => t("Human readable name for this collection"),
);
$form['collection_pid'] = array(
'#title' => "Collection PID",
'#type' => 'textfield',
'#size' => 15,
'#description' => t("Unique PID for this collection. <br />Pids take the general form of namespace:collection eg islandora:pamphlets"),
);
if (!$restricted) {
$form['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => 'default',
'#description' => t("Namespace for objects in this collection."),
);
}
else {
$form['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#type' => 'select',
'#options' => $allowed,
'#default_value' => 'default',
'#description' => t("Namespace for objects in this collection."),
);
}
$form['parent_collection'] = array(
'#type' => 'hidden',
'#value' => $parent_collection_pid,
);
$form['all_content_models'] = array(
'#type' => 'hidden',
'#value' => implode('~~~',$content_models),
);
$form['content_models'] = array(
'#title' => "Choose allowable content models for this collection",
'#type' => 'checkboxes',
'#options' => $content_models,
'#description' => t("Content models describe the behaviours of objects with which they are associated."),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return($form);
}
/**
*
* @param type $form
* @param type $form_state
* @return type
*/
function collection_creation_form_validate($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$pid = $form_state['values']['collection_pid'];
$item = new fedora_item($pid);
if ($item->exists()) {
drupal_set_message("$pid already exists within your repository. the PID must be unique", 'warning');
return;
}
}
/**
*
* @global type $user
* @param type $form
* @param type $form_state
*/
function collection_creation_form_submit($form, &$form_state) {
global $user;
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$module_path = drupal_get_path('module', 'fedora_repository');
$thumbnail = drupal_get_path('module', 'Fedora_Repository') . '/images/Crystal_Clear_filesystem_folder_grey.png';
$collection_pid = $form_state['values']['collection_pid'];
$collection_name = $form_state['values']['collection_name'];
$parent_collection = $form_state['values']['parent_collection'];
$all_cModels = explode('~~~', $form_state['values']['all_content_models']);
$collection_policy = '<?xml version="1.0" encoding="UTF-8"?>
<collection_policy xmlns="http://www.islandora.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="" xsi:schemaLocation="http://www.islandora.ca http://syn.lib.umanitoba.ca/collection_policy.xsd">
<content_models>
</content_models>
<search_terms>
</search_terms>
<staging_area></staging_area>
<relationship>isMemberOfCollection</relationship>
</collection_policy>';
$content_models = $form_state['values']['content_models'];
$collection_policy_xml = simplexml_load_string($collection_policy);
foreach ($content_models as $content_model) {
if ($content_model) {
$node = $collection_policy_xml->content_models->addChild('content_model');
$node->addAttribute('dsid', 'ISLANDORACM');
$node->addAttribute('name', $all_cModels[$content_model]);
$node->addAttribute('namespace', $pid_namespace . '1');
$node->addAttribute('pid', $content_model);
}
}
$item = fedora_item::ingest_new_item($collection_pid, 'A', $new_collections_label, $user->name);
$item->add_relationship('isMemberOfCollection', $parent_collection, RELS_EXT_URI);
$item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI);
$item->add_datastream_from_string($collection_policy_xml->saveXML(), 'COLLECTION_POLICY');
$item->add_datastream_from_file($thumbnail, 'TN');
drupal_goto("/fedora/repository/$collection_pid");
}

76
api/fedora_utils.inc

@ -154,3 +154,79 @@ function fix_dsid($dsid) {
return $new_dsid; return $new_dsid;
} }
/**
* Function: get_collections_as_option_array
*
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array
*/
function get_collections_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$query = 'select $object $title from <#ri>
where ($object <dc:title> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=true&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
$options = array();
foreach ($list as $item) { //removes blanks
if ($item) {
$parts = explode(',', $item);
$options[$parts[0]] = $parts[1];
}
}
unset($options['islandora:ContentModelCollection']);
return $options;
}
/**
* Function: get_content_models_as_option_array
*
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array
*/
function get_content_models_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = variable_get('fedora_namespace_restriction_enforced', true);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[] = trim($namespace);
}
}
$query = 'select $object $title from <#ri>
where ($object <dc:title> $title
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=true&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks
if ($item) {
$parts = explode(',', $item);
$item = new fedora_item($parts[0]);
$nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed))
if ($item->get_datastream_dissemination('ISLANDORACM')) {
$options[$parts[0]] = $parts[1];
}
}
}
return $options;
}

7
fedora_repository.install

@ -89,9 +89,9 @@ function fedora_repository_requirements($phase) {
} }
// Test for Imagick // Test for Imagick
system("hash convert 2>&-", $return_value);
$requirements['imagick']['title'] = t("Image Magick library"); $requirements['imagick']['title'] = t("Image Magick library");
//if ( ! class_exists('Imagick') ) { if ($return_value) {
if (!file_exists('convert')) {
$requirements['imagick']['value'] = t("Not installed"); $requirements['imagick']['value'] = t("Not installed");
$requirements['imagick']['severity'] = REQUIREMENT_ERROR; $requirements['imagick']['severity'] = REQUIREMENT_ERROR;
$requirements['imagick']['description'] = t('Ensure that the Image Magick library is installed.'); $requirements['imagick']['description'] = t('Ensure that the Image Magick library is installed.');
@ -102,8 +102,9 @@ function fedora_repository_requirements($phase) {
} }
// Test for Kakadu // Test for Kakadu
system("hash kdu_compress 2>&-", $return_value);
$requirements['kakadu']['title'] = t("Kakadu library"); $requirements['kakadu']['title'] = t("Kakadu library");
if (!file_exists('kdu_compress')) { if ($return_value) {
$requirements['kakadu']['value'] = t("Not installed"); $requirements['kakadu']['value'] = t("Not installed");
$requirements['kakadu']['severity'] = REQUIREMENT_ERROR; $requirements['kakadu']['severity'] = REQUIREMENT_ERROR;
$requirements['kakadu']['description'] = t('Ensure that the Kakadu library is installed.'); $requirements['kakadu']['description'] = t('Ensure that the Kakadu library is installed.');

12
xsl/results.xsl

@ -199,9 +199,7 @@
<td valign="top"> <td valign="top">
<a> <a>
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/ <xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/<xsl:copy-of select="$PIDVALUE"/>/-/<xsl:value-of select="$CLEANTITLE"/>
<xsl:copy-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute> </xsl:attribute>
<!--<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"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>
@ -234,9 +232,7 @@
<!--<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"><![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"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>-->
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/ <xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/<xsl:value-of select="$PIDVALUE"/>/-/<xsl:value-of select="$CLEANTITLE"/>
<xsl:value-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute> </xsl:attribute>
@ -253,9 +249,7 @@
<!--<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"/><![CDATA[&pid=]]><xsl:value-of select="$PIDVALUE"/><![CDATA[&collection=object]]>-->
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/ <xsl:copy-of select="$OBJECTSPAGE"/>fedora/repository/<xsl:value-of select="$PIDVALUE"/>/-/<xsl:value-of select="$CLEANTITLE"/>
<xsl:value-of select="$PIDVALUE"/>/-/
<xsl:value-of select="$CLEANTITLE"/>
</xsl:attribute> </xsl:attribute>
<xsl:value-of select="field[@name='dc.title']/node()" disable-output-escaping="yes"/> <xsl:value-of select="field[@name='dc.title']/node()" disable-output-escaping="yes"/>

21
xsl/sparql_to_html.xsl

@ -42,10 +42,7 @@
<li class="pager-previous"> <li class="pager-previous">
<a> <a>
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="$BASEURL"/>/fedora/repository/ <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/<xsl:value-of select="$thisTitle"/>/<xsl:value-of select="$page - 1"/>
<xsl:value-of select="$thisPid"/>/-/
<xsl:value-of select="$thisTitle"/>/
<xsl:value-of select="$page - 1"/>
</xsl:attribute> </xsl:attribute>
&lt;Prev &lt;Prev
</a> </a>
@ -60,10 +57,7 @@
<li class="pager-next"> <li class="pager-next">
<a> <a>
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="$BASEURL"/>/fedora/repository/ <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$thisPid"/>/-/<xsl:value-of select="$thisTitle"/>/<xsl:value-of select="$page + 1"/>
<xsl:value-of select="$thisPid"/>/-/
<xsl:value-of select="$thisTitle"/>/
<xsl:value-of select="$page + 1"/>
</xsl:attribute> </xsl:attribute>
Next> Next>
</a> </a>
@ -235,16 +229,12 @@
<xsl:variable name="linkUrl"> <xsl:variable name="linkUrl">
<xsl:choose> <xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')"> <xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="$BASEURL"/>/fedora/repository/ <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="$cleanTitle"/>
<xsl:copy-of select="$PID"/>/-/
<xsl:value-of select="$cleanTitle"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<!--the below is an example of going straight to a datastream instead of the details page. <!--the below is an example of going straight to a datastream instead of the details page.
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/OBJ/<xsl:value-of select="s:title"/>--> <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/OBJ/<xsl:value-of select="s:title"/>-->
<xsl:value-of select="$BASEURL"/>/fedora/repository/ <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="$cleanTitle"/>
<xsl:copy-of select="$PID"/>/-/
<xsl:value-of select="$cleanTitle"/>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:value-of select="s:content"/> <xsl:value-of select="s:content"/>
@ -256,8 +246,7 @@
</xsl:attribute> </xsl:attribute>
<img> <img>
<xsl:attribute name="src"> <xsl:attribute name="src">
<xsl:value-of select="$BASEURL"/>/fedora/repository/ <xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:value-of select="$PID"/>/TN
<xsl:value-of select="$PID"/>/TN
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="alt"> <xsl:attribute name="alt">
<xsl:value-of select="$newTitle" disable-output-escaping="yes"/> <xsl:value-of select="$newTitle" disable-output-escaping="yes"/>

Loading…
Cancel
Save