Browse Source

Documenting incs found in the root directory

pull/5/head
Ben Woodhead 14 years ago
parent
commit
d4a3ff7ec1
  1. 86
      CollectionClass.inc
  2. 166
      CollectionPolicy.inc
  3. 49
      ConnectionHelper.inc
  4. 540
      ContentModel.inc
  5. 64
      MimeClass.inc
  6. 143
      ObjectHelper.inc
  7. 188
      SearchClass.inc
  8. 60
      SecurityClass.inc
  9. 19
      XMLDatastream.inc
  10. 4
      formClass.inc
  11. 9
      plugins/Flv.inc

86
CollectionClass.inc

@ -2,15 +2,18 @@
// $Id$ // $Id$
/* /**
* Created on 18-Feb-08 * @file
* *
* To change the template for this generated file go to * Collection Class Class
* Window - Preferences - PHPeclipse - PHP - Code Templates */
/**
* This CLASS caches the streams so once you call a getstream once it will always return
* the same stream as long as you are using the instance of this class. Cached to
* prevent mutiple hits to fedora. maybe a bit confusing though if this class is used in
* a different context.
*/ */
// module_load_include('nc', 'CollectionClass', '');
// This CLASS caches the streams so once you call a getstream once it will always return the same stream as long as you are using the
// instance of this class. Cached to prevent mutiple hits to fedora. maybe a bit confusing though if this class is used in a different context.
class CollectionClass { class CollectionClass {
public static $COLLECTION_CLASS_COLLECTION_POLICY_STREAM = 'COLLECTION_POLICY'; public static $COLLECTION_CLASS_COLLECTION_POLICY_STREAM = 'COLLECTION_POLICY';
@ -34,10 +37,10 @@ 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();
@ -96,6 +99,11 @@ class CollectionClass {
return $content; return $content;
} }
/**
* getCollectionPolicyStream ??
* @param type $collection_pid
* @return type
*/
function getCollectionPolicyStream($collection_pid) { function getCollectionPolicyStream($collection_pid) {
if ($this->collectionPolicyStream != NULL) { if ($this->collectionPolicyStream != NULL) {
return $this->collectionPolicyStream; return $this->collectionPolicyStream;
@ -104,6 +112,11 @@ class CollectionClass {
return $this->collectionPolicyStream; return $this->collectionPolicyStream;
} }
/**
* getRelationshipElement
* @param type $collection_pid
* @return type
*/
function getRelationshipElement($collection_pid) { function getRelationshipElement($collection_pid) {
$stream = $this->getCollectionPolicyStream($collection_pid); $stream = $this->getCollectionPolicyStream($collection_pid);
try { try {
@ -116,17 +129,35 @@ class CollectionClass {
return $relationship; return $relationship;
} }
/**
* getCollectionViewStream ??
* @param type $collection_pid
* @return type
*/
function getCollectionViewStream($collection_pid) { function getCollectionViewStream($collection_pid) {
$this->collectionViewStream = $this->getStream($collection_pid, CollectionClass :: $COLLECTION_CLASS_COLLECTION_VIEW_STREAM, 0); $this->collectionViewStream = $this->getStream($collection_pid, CollectionClass :: $COLLECTION_CLASS_COLLECTION_VIEW_STREAM, 0);
return $this->collectionViewStream; return $this->collectionViewStream;
} }
/**
* getStream ??
* @param type $pid
* @param type $dsid
* @param type $showError
* @return type
*/
function getStream($pid, $dsid, $showError = 1) { function getStream($pid, $dsid, $showError = 1) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new fedora_item($pid); $item = new fedora_item($pid);
return isset($item->datastreams[$dsid]) ? $item->get_datastream_dissemination($dsid) : NULL; return isset($item->datastreams[$dsid]) ? $item->get_datastream_dissemination($dsid) : NULL;
} }
/**
* getPidNameSpace ??
* @param type $pid
* @param type $dsid
* @return type
*/
function getPidNameSpace($pid, $dsid) { function getPidNameSpace($pid, $dsid) {
$stream = $this->getCollectionPolicyStream($pid); $stream = $this->getCollectionPolicyStream($pid);
try { try {
@ -218,6 +249,12 @@ class CollectionClass {
return NULL; return NULL;
} }
/**
* getAllowedMimeType ??
* @param type $contentModelPid
* @param type $contentModel_dsid
* @return type
*/
function getAllowedMimeTypes($contentModelPid, $contentModel_dsid) { function getAllowedMimeTypes($contentModelPid, $contentModel_dsid) {
$stream = $this->getContentModelStream($contentModelPid, $contentModel_dsid); $stream = $this->getContentModelStream($contentModelPid, $contentModel_dsid);
try { try {
@ -357,8 +394,13 @@ class CollectionClass {
return $thisClass->$phpMethod($form, $ingest_form, $form_state['values'], $form_state); return $thisClass->$phpMethod($form, $ingest_form, $form_state['values'], $form_state);
} }
//this will also create a personal collection for an existing user if they don't have one /**
//not using this function currently * This will also create a personal collection for an existing user if they don't have one
* not using this function currently.
*
* @param type $user
* @return type
*/
function createUserCollection(& $user) { function createUserCollection(& $user) {
if (isset($user->fedora_personal_pid)) { if (isset($user->fedora_personal_pid)) {
return; return;
@ -414,6 +456,13 @@ class CollectionClass {
return $xslContent; return $xslContent;
} }
/**
* showFieldSets ??
* @global type $base_url
* @global type $user
* @param type $page_number
* @return string
*/
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;
@ -451,6 +500,11 @@ class CollectionClass {
return $tabset; return $tabset;
} }
/**
* getIngestInterface ??
* @global type $base_url
* @return string
*/
function getIngestInterface() { function getIngestInterface() {
global $base_url; global $base_url;
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
@ -474,6 +528,16 @@ 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;

166
CollectionPolicy.inc

@ -2,14 +2,20 @@
// $Id$ // $Id$
/**
* @file
* Collection Policy Class
*/
module_load_include('inc', 'fedora_repository', 'XMLDatastream'); module_load_include('inc', 'fedora_repository', 'XMLDatastream');
/**
* Collection Policy class ??
*/
class CollectionPolicy extends XMLDatastream { class CollectionPolicy extends XMLDatastream {
static $SCHEMA_URI = 'http://syn.lib.umanitoba.ca/collection_policy.xsd'; static $SCHEMA_URI = 'http://syn.lib.umanitoba.ca/collection_policy.xsd';
static $DEFAULT_DSID = 'COLLECTION_POLICY'; static $DEFAULT_DSID = 'COLLECTION_POLICY';
private $staging_area = NULL;
private $staging_area=NULL;
/** /**
* Gets the default DSID to use for ContentModel datastreams. * Gets the default DSID to use for ContentModel datastreams.
@ -36,22 +42,21 @@ class CollectionPolicy extends XMLDatastream {
try { try {
if (self::validPid($pid)) { if (self::validPid($pid)) {
$dsid=CollectionPolicy::getDefaultDSID(); $dsid = CollectionPolicy::getDefaultDSID();
if ($preFetch) { if ($preFetch) {
$fedoraItem = new Fedora_Item($pid); $fedoraItem = new Fedora_Item($pid);
$ds = $fedoraItem->get_datastream_dissemination($dsid); $ds = $fedoraItem->get_datastream_dissemination($dsid);
} else {
$ds=null;
} }
else {
$ds = null;
}
} }
if (!empty($ds) || !$preFetch) { if (!empty($ds) || !$preFetch) {
$ret=new CollectionPolicy($ds, $pid, $dsid); $ret = new CollectionPolicy($ds, $pid, $dsid);
} }
} } catch (SOAPException $e) {
catch (SOAPException $e) {
$ret = FALSE; $ret = FALSE;
} }
@ -133,7 +138,7 @@ class CollectionPolicy extends XMLDatastream {
*/ */
public static function ingestBlankPolicy($pid, $name, $policyDsid, $model_pid, $model_namespace, $relationship, $searchField, $searchValue) { public static function ingestBlankPolicy($pid, $name, $policyDsid, $model_pid, $model_namespace, $relationship, $searchField, $searchValue) {
$ret = FALSE; $ret = FALSE;
if (($cp = self::loadFromCollection($pid )) === FALSE) { //removed second, non-existant variable if (($cp = self::loadFromCollection($pid)) === FALSE) { //removed second, non-existant variable
module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'ContentModel');
if (($cm = ContentModel::loadFromModel($model_pid)) !== FALSE && $cm->validate()) { if (($cm = ContentModel::loadFromModel($model_pid)) !== FALSE && $cm->validate()) {
$newDom = new DOMDocument('1.0', 'utf-8'); $newDom = new DOMDocument('1.0', 'utf-8');
@ -142,7 +147,7 @@ class CollectionPolicy extends XMLDatastream {
$rootEl->setAttribute('name', $name); $rootEl->setAttribute('name', $name);
$rootEl->setAttribute('xmlns', self::$XMLNS); $rootEl->setAttribute('xmlns', self::$XMLNS);
$rootEl->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootEl->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootEl->setAttribute('xsi:schemaLocation', self::$XMLNS .' '. self::$SCHEMA_URI); $rootEl->setAttribute('xsi:schemaLocation', self::$XMLNS . ' ' . self::$SCHEMA_URI);
$modelsEl = $newDom->createElement('content_models'); $modelsEl = $newDom->createElement('content_models');
@ -175,13 +180,11 @@ class CollectionPolicy extends XMLDatastream {
$fedoraItem->add_datastream_from_string($cp->dumpXml(), $policyDsid, $name, 'text/xml', 'X'); $fedoraItem->add_datastream_from_string($cp->dumpXml(), $policyDsid, $name, 'text/xml', 'X');
$ret = $cp; $ret = $cp;
} }
} }
return $ret; return $ret;
} }
/** /**
* Constructor * Constructor
* NOTE: Use the static constructor methods whenever possible. * NOTE: Use the static constructor methods whenever possible.
@ -192,8 +195,8 @@ class CollectionPolicy extends XMLDatastream {
* @return XMLDatastream $cm * @return XMLDatastream $cm
*/ */
public function __construct($xmlStr, $pid = NULL, $dsid = NULL) { public function __construct($xmlStr, $pid = NULL, $dsid = NULL) {
parent::__construct($xmlStr,$pid,$dsid); parent::__construct($xmlStr, $pid, $dsid);
$this->name= 'Collection Policy'; $this->name = 'Collection Policy';
} }
/** /**
@ -215,7 +218,7 @@ class CollectionPolicy extends XMLDatastream {
$rootEl->setAttribute('name', $sXml['name']); $rootEl->setAttribute('name', $sXml['name']);
$rootEl->setAttribute('xmlns', self::$XMLNS); $rootEl->setAttribute('xmlns', self::$XMLNS);
$rootEl->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootEl->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootEl->setAttribute('xsi:schemaLocation', self::$XMLNS .' '. self::$SCHEMA_URI); $rootEl->setAttribute('xsi:schemaLocation', self::$XMLNS . ' ' . self::$SCHEMA_URI);
$content_modelsEl = $newDom->createElement('content_models'); $content_modelsEl = $newDom->createElement('content_models');
foreach ($sXml->contentmodels->contentmodel as $contentmodel) { foreach ($sXml->contentmodels->contentmodel as $contentmodel) {
@ -247,7 +250,6 @@ class CollectionPolicy extends XMLDatastream {
$this->xml = DOMDocument::loadXML($newDom->saveXml()); $this->xml = DOMDocument::loadXML($newDom->saveXml());
} }
/** /**
* Gets the name of the relationship to use * Gets the name of the relationship to use
* for members of this collection. * for members of this collection.
@ -256,9 +258,9 @@ class CollectionPolicy extends XMLDatastream {
* @return string $relationship * @return string $relationship
*/ */
public function getRelationship() { public function getRelationship() {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$ret=trim($this->xml->getElementsByTagName('relationship')->item(0)->nodeValue); $ret = trim($this->xml->getElementsByTagName('relationship')->item(0)->nodeValue);
} }
return $ret; return $ret;
} }
@ -272,10 +274,10 @@ class CollectionPolicy extends XMLDatastream {
* @return boolean $ret * @return boolean $ret
*/ */
public function setRelationship($relationship) { public function setRelationship($relationship) {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$relationshipEl=$this->xml->getElementsByTagName('relationship')->item(0); $relationshipEl = $this->xml->getElementsByTagName('relationship')->item(0);
$relationshipEl->nodeValue=trim($relationship); $relationshipEl->nodeValue = trim($relationship);
$ret = TRUE; $ret = TRUE;
} }
return $ret; return $ret;
@ -290,17 +292,18 @@ class CollectionPolicy extends XMLDatastream {
* @return string $path * @return string $path
*/ */
public function getStagingArea($recurse=TRUE) { public function getStagingArea($recurse=TRUE) {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
if ($this->staging_area === NULL) { if ($this->staging_area === NULL) {
$stagingEl=$this->xml->getElementsByTagName('staging_area'); $stagingEl = $this->xml->getElementsByTagName('staging_area');
if ($stagingEl->length > 0) { if ($stagingEl->length > 0) {
$this->staging_area = trim($stagingEl->item(0)->nodeValue); $this->staging_area = trim($stagingEl->item(0)->nodeValue);
} elseif ($recurse) { }
elseif ($recurse) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item=new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
$rels=$item->get_relationships(); $rels = $item->get_relationships();
if (count($rels) > 0) { if (count($rels) > 0) {
foreach ($rels as $rel) { foreach ($rels as $rel) {
$cp = CollectionPolicy::loadFromCollection($rel['object']); $cp = CollectionPolicy::loadFromCollection($rel['object']);
@ -314,7 +317,6 @@ class CollectionPolicy extends XMLDatastream {
} }
$ret = $this->staging_area; $ret = $this->staging_area;
} }
return $ret; return $ret;
} }
@ -329,21 +331,21 @@ class CollectionPolicy extends XMLDatastream {
* @return string $relationship * @return string $relationship
*/ */
public function setStagingArea($path) { public function setStagingArea($path) {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$rootEl=$this->xml->getElementsByTagName('collection_policy')->item(0); $rootEl = $this->xml->getElementsByTagName('collection_policy')->item(0);
$stagingEl=$this->xml->getElementsByTagName('staging_area'); $stagingEl = $this->xml->getElementsByTagName('staging_area');
if ($stagingEl->length > 0) { if ($stagingEl->length > 0) {
$stagingEl=$stagingEl->item(0); $stagingEl = $stagingEl->item(0);
if (trim($path) == '') { if (trim($path) == '') {
$rootEl->removeChild($stagingEl); $rootEl->removeChild($stagingEl);
} }
else { else {
$stagingEl->nodeValue=trim($path); $stagingEl->nodeValue = trim($path);
} }
} }
elseif (trim($path) != '') { elseif (trim($path) != '') {
$stagingEl=$this->xml->createElement('staging_area', trim($path)); $stagingEl = $this->xml->createElement('staging_area', trim($path));
$rootEl->appendChild($stagingEl); $rootEl->appendChild($stagingEl);
} }
@ -352,7 +354,6 @@ class CollectionPolicy extends XMLDatastream {
return $ret; return $ret;
} }
/** /**
* Gets the next available PID for the * Gets the next available PID for the
* content model specified by the DSID * content model specified by the DSID
@ -366,7 +367,7 @@ class CollectionPolicy extends XMLDatastream {
if (self::validDsid($dsid) && $this->validate()) { if (self::validDsid($dsid) && $this->validate()) {
$content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model');
$namespace = FALSE; $namespace = FALSE;
for ($i=0; $namespace === FALSE && $i<$content_models->length;$i++) { for ($i = 0; $namespace === FALSE && $i < $content_models->length; $i++) {
if (strtolower($content_models->item($i)->getAttribute('dsid')) == strtolower($dsid)) { if (strtolower($content_models->item($i)->getAttribute('dsid')) == strtolower($dsid)) {
$namespace = $content_models->item($i)->getAttribute('namespace'); $namespace = $content_models->item($i)->getAttribute('namespace');
} }
@ -386,27 +387,21 @@ class CollectionPolicy extends XMLDatastream {
* @return ContentModel[] $models * @return ContentModel[] $models
*/ */
function getContentModels() { function getContentModels() {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
module_load_include('inc', 'Fedora_Repository', 'ContentModel'); module_load_include('inc', 'Fedora_Repository', 'ContentModel');
$ret=array(); $ret = array();
$content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model');
for ($i=0;$i<$content_models->length;$i++) { for ($i = 0; $i < $content_models->length; $i++) {
$cm=ContentModel::loadFromModel($content_models->item($i)->getAttribute('pid'), $cm = ContentModel::loadFromModel($content_models->item($i)->getAttribute('pid'), $content_models->item($i)->getAttribute('dsid'), $content_models->item($i)->getAttribute('namespace'), $content_models->item($i)->getAttribute('name'));
$content_models->item($i)->getAttribute('dsid'),
$content_models->item($i)->getAttribute('namespace'),
$content_models->item($i)->getAttribute('name'));
if ($cm !== FALSE) { if ($cm !== FALSE) {
$ret[]=$cm; $ret[] = $cm;
} }
} }
} }
return $ret; return $ret;
} }
/** /**
* Gets a list of search terms from the Collection Policy. If asArray is set * Gets a list of search terms from the Collection Policy. If asArray is set
* it will return an associative array with the value, field name, and the default value. * it will return an associative array with the value, field name, and the default value.
@ -422,9 +417,10 @@ class CollectionPolicy extends XMLDatastream {
function getSearchTerms($asArray = FALSE, $recurse = FALSE, $cache = FALSE) { function getSearchTerms($asArray = FALSE, $recurse = FALSE, $cache = FALSE) {
$ret = FALSE; $ret = FALSE;
if ($cache == TRUE && ($cache = cache_get('collection_policy_search_terms-'.$this->pid)) !== 0 ) { if ($cache == TRUE && ($cache = cache_get('collection_policy_search_terms-' . $this->pid)) !== 0) {
$ret=$cache->data; $ret = $cache->data;
} else { }
else {
if ($this->xml == NULL) { if ($this->xml == NULL) {
$fedoraItem = new Fedora_Item($this->pid); $fedoraItem = new Fedora_Item($this->pid);
@ -434,21 +430,21 @@ class CollectionPolicy extends XMLDatastream {
if ($this->validate()) { if ($this->validate()) {
$ret=array(); $ret = array();
$terms= $this->xml->getElementsByTagName('search_terms')->item(0)->getElementsByTagName('term'); $terms = $this->xml->getElementsByTagName('search_terms')->item(0)->getElementsByTagName('term');
for ($i=0;$i<$terms->length;$i++) { for ($i = 0; $i < $terms->length; $i++) {
$default = $terms->item($i)->attributes->getNamedItem('default'); $default = $terms->item($i)->attributes->getNamedItem('default');
$default = ($default !== NULL) ? (strtolower($default->nodeValue) == 'true') : FALSE; $default = ($default !== NULL) ? (strtolower($default->nodeValue) == 'true') : FALSE;
$ret[] = ($asArray)?array( 'value' => $terms->item($i)->nodeValue, $ret[] = ($asArray) ? array('value' => $terms->item($i)->nodeValue,
'field' => $terms->item($i)->getAttribute('field'), 'field' => $terms->item($i)->getAttribute('field'),
'default' => $default): $terms->item($i)->nodeValue; 'default' => $default) : $terms->item($i)->nodeValue;
} }
if ($recurse && count($ret) == 0) { if ($recurse && count($ret) == 0) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item=new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
$rels=$item->get_relationships(); $rels = $item->get_relationships();
if (count($rels) > 0) { if (count($rels) > 0) {
foreach ($rels as $rel) { foreach ($rels as $rel) {
$cp = CollectionPolicy::loadFromCollection($rel['object']); $cp = CollectionPolicy::loadFromCollection($rel['object']);
@ -459,14 +455,12 @@ class CollectionPolicy extends XMLDatastream {
} }
} }
} }
cache_set('collection_policy_search_terms-'.$this->pid, $ret, 'cache', time()+3600); cache_set('collection_policy_search_terms-' . $this->pid, $ret, 'cache', time() + 3600);
} }
} }
return $ret; return $ret;
} }
/** /**
* Adds a search term to the collection policy. * Adds a search term to the collection policy.
* Returns fase on failure. * Returns fase on failure.
@ -476,12 +470,12 @@ class CollectionPolicy extends XMLDatastream {
* @return boolean $success * @return boolean $success
*/ */
function addTerm($field, $value) { function addTerm($field, $value) {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0);
$terms= $search_termsEl->getElementsByTagName('term'); $terms = $search_termsEl->getElementsByTagName('term');
$found=FALSE; $found = FALSE;
for ($i=0;!$found && $i<$terms->length;$i++) { for ($i = 0; !$found && $i < $terms->length; $i++) {
if ($terms->item($i)->getAttribute('field') == $field) { if ($terms->item($i)->getAttribute('field') == $field) {
$found = TRUE; $found = TRUE;
} }
@ -504,12 +498,12 @@ class CollectionPolicy extends XMLDatastream {
* @return boolean $success * @return boolean $success
*/ */
function removeTerm($field) { function removeTerm($field) {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0);
$terms = $search_termsEl->getElementsByTagName('term'); $terms = $search_termsEl->getElementsByTagName('term');
$found = FALSE; $found = FALSE;
for ($i=0; !$found && $i < $terms->length; $i++) { for ($i = 0; !$found && $i < $terms->length; $i++) {
if ($terms->item($i)->getAttribute('field') == $field) { if ($terms->item($i)->getAttribute('field') == $field) {
$found = $terms->item($i); $found = $terms->item($i);
} }
@ -523,21 +517,25 @@ class CollectionPolicy extends XMLDatastream {
return $ret; return $ret;
} }
/**
* setDefaultTerm ??
* @param type $field
* @return boolean
*/
function setDefaultTerm($field) { function setDefaultTerm($field) {
$ret = FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0);
$terms= $search_termsEl->getElementsByTagName('term'); $terms = $search_termsEl->getElementsByTagName('term');
$found=FALSE; $found = FALSE;
for ($i=0;!$found && $i<$terms->length;$i++) { for ($i = 0; !$found && $i < $terms->length; $i++) {
if ($terms->item($i)->getAttribute('field') == $field) { if ($terms->item($i)->getAttribute('field') == $field) {
$found = $terms->item($i); $found = $terms->item($i);
} }
} }
if ($found !== FALSE) { if ($found !== FALSE) {
for ($i=0;$i<$terms->length;$i++) for ($i = 0; $i < $terms->length; $i++)
if ($terms->item($i)->attributes->getNamedItem('default') !== NULL) { if ($terms->item($i)->attributes->getNamedItem('default') !== NULL) {
$terms->item($i)->removeAttribute('default'); $terms->item($i)->removeAttribute('default');
} }
@ -548,7 +546,6 @@ class CollectionPolicy extends XMLDatastream {
return $ret; return $ret;
} }
/** /**
* Removes the specified content model from the collection policy. This will only * Removes the specified content model from the collection policy. This will only
* prevent future ingests of the removed model to the collection. $cm should be * prevent future ingests of the removed model to the collection. $cm should be
@ -559,14 +556,14 @@ class CollectionPolicy extends XMLDatastream {
* @return boolean $valid * @return boolean $valid
*/ */
function removeModel($cm) { function removeModel($cm) {
$ret=FALSE; $ret = FALSE;
if ($this->validate() && $cm->validate()) { if ($this->validate() && $cm->validate()) {
$contentmodelsEl = $this->xml->getElementsByTagName('content_models'); $contentmodelsEl = $this->xml->getElementsByTagName('content_models');
$models = $contentmodelsEl->item(0)->getElementsByTagName('content_model'); $models = $contentmodelsEl->item(0)->getElementsByTagName('content_model');
$found = FALSE; $found = FALSE;
for ($i=0; $found === FALSE && $i < $models->length; $i++) { for ($i = 0; $found === FALSE && $i < $models->length; $i++) {
if ($models->item($i)->getAttribute('pid') == $cm->pid) { if ($models->item($i)->getAttribute('pid') == $cm->pid) {
$found=$models->item($i); $found = $models->item($i);
} }
} }
@ -578,16 +575,19 @@ class CollectionPolicy extends XMLDatastream {
return $ret; return $ret;
} }
/**
* addModel ??
* @param type $cm
* @param type $namespace
* @return type
*/
function addModel($cm, $namespace) { function addModel($cm, $namespace) {
$ret = FALSE; $ret = FALSE;
if (self::validPid($namespace) && $this->validate() && $cm->validate()) { if (self::validPid($namespace) && $this->validate() && $cm->validate()) {
$contentmodelsEl = $this->xml->getElementsByTagName('content_models'); $contentmodelsEl = $this->xml->getElementsByTagName('content_models');
$models = $contentmodelsEl->item(0)->getElementsByTagName('content_model'); $models = $contentmodelsEl->item(0)->getElementsByTagName('content_model');
$found = FALSE; $found = FALSE;
for ($i=0;!$found && $i<$models->length;$i++) { for ($i = 0; !$found && $i < $models->length; $i++) {
if ($models->item($i)->getAttribute('pid') == $cm->pid) if ($models->item($i)->getAttribute('pid') == $cm->pid)
$found = TRUE; $found = TRUE;
} }
@ -606,10 +606,14 @@ class CollectionPolicy extends XMLDatastream {
return $ret; return $ret;
} }
/**
* getName ??
* @return type
*/
function getName() { function getName() {
$ret=FALSE; $ret = FALSE;
if ($this->validate()) { if ($this->validate()) {
$ret=$this->xml->getElementsByTagName('collection_policy')->item(0)->getAttribute('name'); $ret = $this->xml->getElementsByTagName('collection_policy')->item(0)->getAttribute('name');
} }
return $ret; return $ret;
} }

49
ConnectionHelper.inc

@ -1,31 +1,44 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on Jan 24, 2008 * @file
* * Connection Helper Class
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ */
module_load_include('inc', 'ConnectionHelper', ''); module_load_include('inc', 'ConnectionHelper', '');
/**
* Connection Helper Class ??
*/
class ConnectionHelper { class ConnectionHelper {
/**
* Constructor
*/
function ConnectionHelper() { function ConnectionHelper() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* fixURL ??
* @param type $url
* @param type $_name
* @param type $_pass
* @return string
*/
function _fixURL($url, $_name, $_pass) { function _fixURL($url, $_name, $_pass) {
if (empty($url)) { if (empty($url)) {
$url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); $url = variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
} }
$creds = urlencode($_name) . ':'. urlencode($_pass); $creds = urlencode($_name) . ':' . urlencode($_pass);
if (strpos($url, 'http://') === 0) { if (strpos($url, 'http://') === 0) {
$new_url = 'http://'. $creds . '@'. substr($url, 7); $new_url = 'http://' . $creds . '@' . substr($url, 7);
} }
elseif (strpos($url, 'https://') === 0) { elseif (strpos($url, 'https://') === 0) {
$new_url = 'https://'. $creds . '@'. substr($url, 8); $new_url = 'https://' . $creds . '@' . substr($url, 8);
} }
else { else {
drupal_set_message(t('Invalid URL: !url', array('!url' => $url))); drupal_set_message(t('Invalid URL: !url', array('!url' => $url)));
@ -35,9 +48,16 @@ class ConnectionHelper {
return $new_url; return $new_url;
} }
/**
* getSoapClient
* @global type $user
* @param type $url
* @param type $exceptions
* @return SoapClient
*/
function getSoapClient($url = NULL, $exceptions = TRUE) { function getSoapClient($url = NULL, $exceptions = TRUE) {
if (empty($url)) { if (empty($url)) {
$url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); $url = variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
} }
global $user; global $user;
@ -50,8 +70,7 @@ class ConnectionHelper {
'password' => 'anonymous', 'password' => 'anonymous',
'exceptions' => $exceptions, 'exceptions' => $exceptions,
)); ));
} } catch (SoapFault $e) {
catch (SoapFault $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage()))); drupal_set_message(t("!e", array('!e' => $e->getMessage())));
return NULL; return NULL;
} }
@ -63,13 +82,13 @@ class ConnectionHelper {
'password' => $user->pass, 'password' => $user->pass,
'exceptions' => TRUE, 'exceptions' => TRUE,
)); ));
} } catch (SoapFault $e) {
catch (SoapFault $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage()))); drupal_set_message(t("!e", array('!e' => $e->getMessage())));
return NULL; return NULL;
} }
} }
return $client; return $client;
} }
} }

540
ContentModel.inc

File diff suppressed because it is too large Load Diff

64
MimeClass.inc

@ -1,4 +1,5 @@
<?php <?php
// $Id$ // $Id$
/** /**
@ -20,8 +21,8 @@
* http://api.drupal.org/api/function/file_default_mimetype_mapping/7 * http://api.drupal.org/api/function/file_default_mimetype_mapping/7
* *
*/ */
class MimeClass { class MimeClass {
private $private_mime_types = array( private $private_mime_types = array(
/** /**
* This is a shortlist of mimetypes which should catch most * This is a shortlist of mimetypes which should catch most
@ -190,50 +191,58 @@ class MimeClass {
// others: // others:
'bin' => 'application/octet-stream', 'bin' => 'application/octet-stream',
); );
private $private_file_extensions; private $private_file_extensions;
private $system_types; private $system_types;
private $system_exts; private $system_exts;
private $etc_mime_types = '/etc/mime.types'; private $etc_mime_types = '/etc/mime.types';
/**
* Construtor
*/
public function __construct() { public function __construct() {
// populate the reverse shortlist: // populate the reverse shortlist:
$this->private_file_extensions = array_flip( $this->private_mime_types ); $this->private_file_extensions = array_flip($this->private_mime_types);
// pick up a local mime.types file if it is available // pick up a local mime.types file if it is available
if (is_readable('mime.types') ) { if (is_readable('mime.types')) {
$this->etc_mime_types = 'mime.types'; $this->etc_mime_types = 'mime.types';
} }
} }
/** /**
* function: getType * function: getType
* description: An alias to get_mimetype, * description: An alias to get_mimetype,
* for backwards-compatibility with our old mimetype class. * for backwards-compatibility with our old mimetype class.
*
* @param type $filename
* @return type
*/ */
public function getType( $filename ) { public function getType($filename) {
return $this->get_mimetype( $filename ); return $this->get_mimetype($filename);
} }
/** /**
* function: get_mimetype * function: get_mimetype
* description: returns a mimetype associated with the file extension of $filename * description: returns a mimetype associated with the file extension of $filename
*
* @param type $filename
* @param type $debug
* @return type
*/ */
public function get_mimetype( $filename, $debug = FALSE ) { public function get_mimetype($filename, $debug = FALSE) {
$file_name_and_extension = explode( '.', $filename ); $file_name_and_extension = explode('.', $filename);
$ext = strtolower( array_pop( $file_name_and_extension ) ); $ext = strtolower(array_pop($file_name_and_extension));
if ( ! empty( $this->private_mime_types[$ext] ) ) { if (!empty($this->private_mime_types[$ext])) {
if ( TRUE === $debug ) if (TRUE === $debug)
return array( 'mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array' ); return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array');
return $this->private_mime_types[$ext]; return $this->private_mime_types[$ext];
} }
if (function_exists('file_get_mimetype')) { if (function_exists('file_get_mimetype')) {
$drupal_mimetype = file_get_mimetype( $filename ); $drupal_mimetype = file_get_mimetype($filename);
if ('application/octet-stream' != $drupal_mimetype) { if ('application/octet-stream' != $drupal_mimetype) {
if (TRUE == $debug) if (TRUE == $debug)
return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype'); return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype');
@ -241,42 +250,45 @@ class MimeClass {
} }
} }
if (!isset( $this->system_types)) if (!isset($this->system_types))
$this->system_types = $this->system_extension_mime_types(); $this->system_types = $this->system_extension_mime_types();
if (isset( $this->system_types[$ext])) { if (isset($this->system_types[$ext])) {
if (TRUE == $debug) if (TRUE == $debug)
return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types'); return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types');
return $this->system_types[$ext]; return $this->system_types[$ext];
} }
if ( TRUE === $debug ) if (TRUE === $debug)
return array( 'mime_type' => 'application/octet-stream', 'method' => 'last_resort' ); return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort');
return 'application/octet-stream'; return 'application/octet-stream';
} }
/** /**
* function: get_extension * function: get_extension
* description: returns *one* valid file extension for a given $mime_type * description: returns *one* valid file extension for a given $mime_type
*
* @param type $mime_type
* @param type $debug
* @return type
*/ */
public function get_extension( $mime_type, $debug = FALSE ) { public function get_extension($mime_type, $debug = FALSE) {
if (!empty( $this->private_file_extensions[$mime_type])) { if (!empty($this->private_file_extensions[$mime_type])) {
if (TRUE == $debug) if (TRUE == $debug)
return array( 'extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array' ); return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array');
return $this->private_file_extensions[$mime_type]; return $this->private_file_extensions[$mime_type];
} }
if (!isset ( $this->system_exts)) if (!isset($this->system_exts))
$this->system_exts = $this->system_mime_type_extensions(); $this->system_exts = $this->system_mime_type_extensions();
if (isset( $this->system_exts[$mime_type])) { if (isset($this->system_exts[$mime_type])) {
if (TRUE == $debug) if (TRUE == $debug)
return array( 'extension' => $this->system_exts[$mime_type], 'method' => 'mime.types' ); return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types');
return $this->system_exts[$mime_type]; return $this->system_exts[$mime_type];
} }
if (TRUE == $debug) if (TRUE == $debug)
return array( 'extension' => 'bin', 'method' => 'last_resort' ); return array('extension' => 'bin', 'method' => 'last_resort');
return 'bin'; return 'bin';
} }

143
ObjectHelper.inc

@ -1,12 +1,13 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* Object Helper Class
*/
/* /**
* Created on Feb 1, 2008 * ObjectHelper Class ??
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ */
class ObjectHelper { class ObjectHelper {
@ -24,6 +25,9 @@ class ObjectHelper {
// TODO: Make this into a static member constant // TODO: Make this into a static member constant
public $availableDataStreamsText = 'Detailed list of content'; public $availableDataStreamsText = 'Detailed list of content';
/**
* Constructor
*/
function ObjectHelper() { function ObjectHelper() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
@ -36,8 +40,16 @@ class ObjectHelper {
* Grabs a stream from fedora sets the mimetype and returns it. $dsID is the * Grabs a stream from fedora sets the mimetype and returns it. $dsID is the
* datastream id. If $forceSoap is set, the function will always buffer the datastream from fedora. Otherwise, it will * datastream id. If $forceSoap is set, the function will always buffer the datastream from fedora. Otherwise, it will
* try and use a redirect if possible. * try and use a redirect if possible.
* @param $pid String *
* @param $dsID String * @global type $user
* @param type $pid
* @param type $dsID
* @param type $asAttachment
* @param type $label
* @param type $filePath
* @param type $version
* @param type $forceSoap
* @return type
*/ */
function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = TRUE) { function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = TRUE) {
global $user; global $user;
@ -85,7 +97,8 @@ class ObjectHelper {
if ($label == NULL) { if ($label == NULL) {
$label = $item->datastreams[$dsID]['label']; $label = $item->datastreams[$dsID]['label'];
} }
} else { }
else {
drupal_not_found(); drupal_not_found();
exit(); exit();
} }
@ -95,7 +108,8 @@ class ObjectHelper {
$fedoraUser = 'anonymous'; $fedoraUser = 'anonymous';
$fedoraPass = 'anonymous'; $fedoraPass = 'anonymous';
$contentSize = 0; $contentSize = 0;
} else { }
else {
$fedoraUser = $user->name; $fedoraUser = $user->name;
$fedoraPass = $user->pass; $fedoraPass = $user->pass;
$dataStreamInfo = $item->get_datastream_info($dsID); $dataStreamInfo = $item->get_datastream_info($dsID);
@ -135,7 +149,8 @@ class ObjectHelper {
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch); curl_exec($ch);
fclose($fp); fclose($fp);
} else { }
else {
header("Content-type: $mimeType"); header("Content-type: $mimeType");
if ($contentSize > 0) { if ($contentSize > 0) {
@ -145,7 +160,8 @@ class ObjectHelper {
if ($asAttachment) { if ($asAttachment) {
$suggestedFileName = "$label"; $suggestedFileName = "$label";
$pos = strpos($suggestedFileName, '.'); $pos = strpos($suggestedFileName, '.');
/**
/*
* Here we used to take an object of, say, type application/pdf with label, say, "My Document" * Here we used to take an object of, say, type application/pdf with label, say, "My Document"
* and we assemble the output filename extension based on the post-slash portion of the mimetype. * and we assemble the output filename extension based on the post-slash portion of the mimetype.
* (If the label has a period anywhere in it, we leave it alone.) * (If the label has a period anywhere in it, we leave it alone.)
@ -168,17 +184,25 @@ class ObjectHelper {
if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch); curl_exec($ch);
} else { }
else {
header('Location: ' . $url); header('Location: ' . $url);
} }
} }
curl_close($ch); curl_close($ch);
} else { }
else {
drupal_set_message(t('No curl support.'), 'error'); drupal_set_message(t('No curl support.'), 'error');
} }
} }
//Gets collection objects t /**
* Gets collection objects t
*
* @param type $pid
* @param type $query
* @return type
*/
function getCollectionInfo($pid, $query = NULL) { function getCollectionInfo($pid, $query = NULL) {
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collectionClass = new CollectionClass(); $collectionClass = new CollectionClass();
@ -188,6 +212,11 @@ class ObjectHelper {
/** /**
* returns the mime type * returns the mime type
*
* @global type $user
* @param type $pid
* @param type $dsID
* @return type
*/ */
function getMimeType($pid, $dsID) { function getMimeType($pid, $dsID) {
global $user; global $user;
@ -217,6 +246,13 @@ class ObjectHelper {
return ''; return '';
} }
/**
* getDatastreamInfo ??
* @global type $user
* @param type $pid
* @param type $dsID
* @return type
*/
function getDatastreamInfo($pid, $dsID) { function getDatastreamInfo($pid, $dsID) {
global $user; global $user;
if (empty($pid) || empty($dsID)) { if (empty($pid) || empty($dsID)) {
@ -267,7 +303,8 @@ class ObjectHelper {
$pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path .
'/images/purge.gif" alt="purge datastream" /></a>'; '/images/purge.gif" alt="purge datastream" /></a>';
} }
} else { }
else {
$purgeImage = '&nbsp;'; $purgeImage = '&nbsp;';
} }
$fullPath = base_path() . $path; $fullPath = base_path() . $path;
@ -311,6 +348,12 @@ class ObjectHelper {
return $content; return $content;
} }
/**
* getFormattedDC ??
* @global type $base_url
* @param type $item
* @return type
*/
function getFormattedDC($item) { function getFormattedDC($item) {
global $base_url; global $base_url;
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
@ -322,7 +365,6 @@ class ObjectHelper {
if (empty($xmlstr)) { if (empty($xmlstr)) {
return ''; return '';
} }
try { try {
@ -375,13 +417,11 @@ class ObjectHelper {
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' . $output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
$dsid . '"><img src="' . $base_url . '/' . $path . '/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; return $output;
} }
/** /**
* Gets a list of datastreams from an object using its pid * Gets a list of datastreams from an object using its pid
* *
@ -466,8 +506,6 @@ class ObjectHelper {
return ''; return '';
} }
/** /**
* returns a stream from a fedora object given a pid and dsid * returns a stream from a fedora object given a pid and dsid
* *
@ -499,11 +537,13 @@ class ObjectHelper {
return $content; return $content;
} }
/* /**
* gets the name of the content models for the specified object * gets the name of the content models for the specified object
* this now returns an array of pids as in Fedora 3 we can have more then one Cmodel for an object * this now returns an array of pids as in Fedora 3 we can have more then one Cmodel for an object
* @param type $pid
* @param type $include_fedora_system_content_models
* @return array
*/ */
function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) { function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) {
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collectionHelper = new CollectionClass(); $collectionHelper = new CollectionClass();
@ -542,11 +582,14 @@ class ObjectHelper {
return $cmodels; return $cmodels;
} }
/* /**
* determines whether we can see the object or not * determines whether we can see the object or not
* checks PID namespace permissions, and user permissions * checks PID namespace permissions, and user permissions
* @global type $user
* @param type $op
* @param type $pid
* @return type
*/ */
function fedora_repository_access($op, $pid) { function fedora_repository_access($op, $pid) {
global $user; global $user;
@ -572,7 +615,8 @@ class ObjectHelper {
return FALSE; return FALSE;
} }
return $user_access; return $user_access;
} else { }
else {
return FALSE; return FALSE;
} }
} }
@ -633,10 +677,10 @@ class ObjectHelper {
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection'); '/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection');
} }
} }
} else { }
else {
$ingestObject = '&nbsp;'; $ingestObject = '&nbsp;';
} }
} }
$datastreams .= $ingestObject; $datastreams .= $ingestObject;
@ -691,6 +735,12 @@ class ObjectHelper {
return $objects; return $objects;
} }
/**
* get_parent_objects_asHTML ??
* @global type $base_url
* @param type $pid
* @return string
*/
function get_parent_objects_asHTML($pid) { function get_parent_objects_asHTML($pid) {
global $base_url; global $base_url;
$parent_collections = $this->get_parent_objects($pid); $parent_collections = $this->get_parent_objects($pid);
@ -722,6 +772,11 @@ class ObjectHelper {
/** /**
* gets a list of datastreams and related function that we should use to show datastreams in their own fieldsets * gets a list of datastreams and related function that we should use to show datastreams in their own fieldsets
* from the content model associated with the object * from the content model associated with the object
*
* @param type $pid
* @param type $contentModel
* @param type $page_number
* @return type
*/ */
function createExtraFieldsets($pid, $contentModel, $page_number) { function createExtraFieldsets($pid, $contentModel, $page_number) {
//$models = $collectionHelper->getContentModels($collectionPid, FALSE); //$models = $collectionHelper->getContentModels($collectionPid, FALSE);
@ -760,6 +815,9 @@ class ObjectHelper {
/** /**
* Get a tree of related pids - for the basket functionality * Get a tree of related pids - for the basket functionality
*
* @param type $pid
* @return type
*/ */
function get_all_related_pids($pid) { function get_all_related_pids($pid) {
if (!$pid) { if (!$pid) {
@ -789,6 +847,9 @@ class ObjectHelper {
/** /**
* Get children of PID - but only 2 levels deep * Get children of PID - but only 2 levels deep
*
* @param type $pids
* @return type
*/ */
function get_child_pids($pids) { function get_child_pids($pids) {
// Get pid, title and description for children of object $pid // Get pid, title and description for children of object $pid
@ -834,6 +895,11 @@ class ObjectHelper {
/** /**
* Returns XML description of the object (export). * Returns XML description of the object (export).
*
* @param type $pid
* @param type $context
* @param type $format
* @return type
*/ */
function getObject($pid, $context = 'archive', $format = FOXML_11) { function getObject($pid, $context = 'archive', $format = FOXML_11) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -845,15 +911,21 @@ class ObjectHelper {
/** /**
* Builds an array of drupal links for use in breadcrumbs. * Builds an array of drupal links for use in breadcrumbs.
*
* @global type $base_url
* @param type $pid
* @param type $breadcrumbs
* @param type $level
*/ */
function getBreadcrumbs($pid, &$breadcrumbs, $level=10) { function getBreadcrumbs($pid, &$breadcrumbs, $level=10) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
// Before executing the query, we hve a base case of accessing the top-level collection // Before executing the query, we hve a base case of accessing the top-level collection
global $base_url; global $base_url;
if ($pid == variable_get('fedora_repository_pid', 'islandora:top')){ if ($pid == variable_get('fedora_repository_pid', 'islandora:top')) {
$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(t('Home'), $base_url); $breadcrumbs[] = l(t('Home'), $base_url);
} else { }
else {
$query_string = 'select $parentObject $title $content from <#ri> $query_string = 'select $parentObject $title $content from <#ri>
where (<info:fedora/' . $pid . '> <dc:title> $title where (<info:fedora/' . $pid . '> <dc:title> $title
and $parentObject <fedora-model:hasModel> $content and $parentObject <fedora-model:hasModel> $content
@ -868,23 +940,28 @@ class ObjectHelper {
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string; $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)); $result = preg_split('/[\r\n]+/', do_curl($url));
array_shift($result); // throw away first line array_shift($result); // throw away first line
$matches =str_getcsv(join("\n",$result)); $matches = str_getcsv(join("\n", $result));
if ($matches !== FALSE) { if ($matches !== FALSE) {
$parent = preg_replace('/^info:fedora\//','',$matches[0]); $parent = preg_replace('/^info:fedora\//', '', $matches[0]);
$breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid);
if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) { if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) {
$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository');
$breadcrumbs[] = l(t('Home'), $base_url); $breadcrumbs[] = l(t('Home'), $base_url);
} elseif ($level > 0) { }
elseif ($level > 0) {
$this->getBreadcrumbs($parent, $breadcrumbs, $level - 1); $this->getBreadcrumbs($parent, $breadcrumbs, $level - 1);
} }
} }
} }
} }
/**
* warnIfMisconfigured ??
* @param type $app
*/
public static function warnIfMisconfigured($app) { public static function warnIfMisconfigured($app) {
$messMap = array( $messMap = array(
'Kakadu' => 'Full installation instructions for Kakadu can be found 'Kakadu' => 'Full installation instructions for Kakadu can be found

188
SearchClass.inc

@ -1,8 +1,27 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* SearchClass Class
*/
/**
* SearchClass ??
*/
class SearchClass { class SearchClass {
public static $SEARCH_CLASS_ADVANCED_SEARCH_NUMBER_FIELDS = 5; public static $SEARCH_CLASS_ADVANCED_SEARCH_NUMBER_FIELDS = 5;
/**
* solr_search ??
* @param type $query
* @param type $startPage
* @param type $fq
* @param type $dismax
* @return type
*/
function solr_search($query, $startPage=1, $fq = NULL, $dismax = NULL) { function solr_search($query, $startPage=1, $fq = NULL, $dismax = NULL) {
$solrFile = trim(variable_get('islandora_solr_search_block_handler_file', 'plugins/SolrResults.inc')); $solrFile = trim(variable_get('islandora_solr_search_block_handler_file', 'plugins/SolrResults.inc'));
if (strpos($solrField, '../')) { // Don't let us bust out of fedora_repository modules directory when looking for a handler if (strpos($solrField, '../')) { // Don't let us bust out of fedora_repository modules directory when looking for a handler
@ -10,7 +29,7 @@ class SearchClass {
} }
$solrClass = trim(variable_get('islandora_solr_search_block_handler_class', 'SolrResults')); $solrClass = trim(variable_get('islandora_solr_search_block_handler_class', 'SolrResults'));
$solrFunction = trim(variable_get('islandora_solr_search_block_handler_function', 'SearchAndDisplay')); $solrFunction = trim(variable_get('islandora_solr_search_block_handler_function', 'SearchAndDisplay'));
require_once(drupal_get_path('module', 'fedora_repository') . '/'. $solrFile); require_once(drupal_get_path('module', 'fedora_repository') . '/' . $solrFile);
try { try {
$implementation = new $solrClass(); $implementation = new $solrClass();
} catch (Exception $e) { } catch (Exception $e) {
@ -19,9 +38,17 @@ class SearchClass {
} }
return $implementation->$solrFunction($query, $startPage, $fq, $dismax); return $implementation->$solrFunction($query, $startPage, $fq, $dismax);
} }
/**
* build solr search form ??
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return type
*/
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) { function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {
$types = $this->get_search_terms_array(NULL, 'solrSearchTerms.xml'); $types = $this->get_search_terms_array(NULL, 'solrSearchTerms.xml');
$queryArray=NULL; $queryArray = NULL;
if (isset($query)) { if (isset($query)) {
$queryArray = explode('AND', $query); $queryArray = explode('AND', $query);
} }
@ -68,7 +95,7 @@ class SearchClass {
'#title' => t(''), '#title' => t(''),
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''), '#default_value' => (count($var1) >= 2 ? $var1[1] : ''),
); );
if ($repeat>2 && $repeat < 9) { //don't want less then 2 or more then 9 if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9
for ($i = 3; $i < $repeat + 1; $i++) { for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1; $t = $i - 1;
$field_and_term = explode(':', $queryArray[$t]); $field_and_term = explode(':', $queryArray[$t]);
@ -100,6 +127,10 @@ class SearchClass {
return $form; return $form;
} }
/**
* build simple solr form ??
* @return string
*/
function build_simple_solr_form() { function build_simple_solr_form() {
//$form = array(); //$form = array();
$form["search_query"] = array( $form["search_query"] = array(
@ -114,28 +145,42 @@ class SearchClass {
); );
return $form; return $form;
} }
/**
* theme solr search form ??
* @param type $form
* @return type
*/
function theme_solr_search_form($form) { function theme_solr_search_form($form) {
if (!isset($repeat)) { if (!isset($repeat)) {
$repeat = variable_get('islandora_solr_search_block_repeat', t('3')); $repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
} }
$output = drupal_render($form['search_type']['type1']) ; $output = drupal_render($form['search_type']['type1']);
$output .= drupal_render($form['fedora_terms1']) ; $output .= drupal_render($form['fedora_terms1']);
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']) ; $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']);
$output .= drupal_render($form['fedora_terms2']); $output .= drupal_render($form['fedora_terms2']);
if ($repeat>2 && $repeat < 9) { if ($repeat > 2 && $repeat < 9) {
for ($i=3;$i<$repeat+1;$i++) { for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1; $t = $i - 1;
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]) ; $output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]);
$output .= drupal_render($form["fedora_terms$i"]) ; $output .= drupal_render($form["fedora_terms$i"]);
} }
} }
$output .= drupal_render($form['submit']) ; $output .= drupal_render($form['submit']);
$output .= drupal_render($form); $output .= drupal_render($form);
return $output; return $output;
} }
/**
* quick search ??
* @param type $type
* @param type $query
* @param type $showForm
* @param type $orderBy
* @param type $userArray
* @return type
*/
function quickSearch($type, $query, $showForm = 1, $orderBy = 0, & $userArray) { function quickSearch($type, $query, $showForm = 1, $orderBy = 0, & $userArray) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -146,15 +191,15 @@ class SearchClass {
$keywords = explode(' ', $query); $keywords = explode(' ', $query);
foreach ($keywords as $keyword) { foreach ($keywords as $keyword) {
$luceneQuery .= $type . ':'. $keyword . '+AND+'; $luceneQuery .= $type . ':' . $keyword . '+AND+';
} }
$luceneQuery = substr($luceneQuery, 0, strlen($luceneQuery) - 5); $luceneQuery = substr($luceneQuery, 0, strlen($luceneQuery) - 5);
$indexName = variable_get('fedora_index_name', 'DemoOnLucene'); $indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$keys = htmlentities(urlencode($query)); $keys = htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName='. $indexName . '&restXslt=copyXml&query='. $luceneQuery; $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $luceneQuery;
$searchString .= '&hitPageSize='. $numberOfHistPerPage . '&hitPageStart=1'; $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=1';
//$searchString = htmlentities($searchString); //$searchString = htmlentities($searchString);
$searchUrl .= $searchString; $searchUrl .= $searchString;
@ -169,20 +214,25 @@ class SearchClass {
$nodeList = $xPath->query('//field[@name="refworks.u1"]'); $nodeList = $xPath->query('//field[@name="refworks.u1"]');
foreach ($nodeList as $node) { foreach ($nodeList as $node) {
if (!in_array($node->nodeValue, $userArray)) { if (!in_array($node->nodeValue, $userArray)) {
$userArray[]=$node->nodeValue; $userArray[] = $node->nodeValue;
} }
} }
} }
if ($showForm) { if ($showForm) {
$output = '<Strong>Quick Search</strong><br /><table class="table-form"><tr>'. drupal_get_form('fedora_repository_quick_search_form') . '</tr></table>'; $output = '<Strong>Quick Search</strong><br /><table class="table-form"><tr>' . drupal_get_form('fedora_repository_quick_search_form') . '</tr></table>';
} }
$output .= $this->applyXSLT($resultData, $orderBy); $output .= $this->applyXSLT($resultData, $orderBy);
return $output; return $output;
} }
} }
/**
// gets term from a lucene index and displays them in a list * gets term from a lucene index and displays them in a list
* @param type $fieldName
* @param type $startTerm
* @param type $displayName
* @return type
*/
function getTerms($fieldName, $startTerm, $displayName = NULL) { function getTerms($fieldName, $startTerm, $displayName = NULL) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -192,10 +242,10 @@ class SearchClass {
$startTerm = ""; $startTerm = "";
} }
$startTerm = drupal_urlencode($startTerm); $startTerm = drupal_urlencode($startTerm);
$query = 'operation=browseIndex&startTerm='. $startTerm . '&fieldName='. $fieldName . '&termPageSize=20&indexName='. $indexName . '&restXslt=copyXml&resultPageXslt=copyXml'; $query = 'operation=browseIndex&startTerm=' . $startTerm . '&fieldName=' . $fieldName . '&termPageSize=20&indexName=' . $indexName . '&restXslt=copyXml&resultPageXslt=copyXml';
// $query=drupal_urlencode($query); // $query=drupal_urlencode($query);
$query = '?'. $query; $query = '?' . $query;
$searchString=$searchUrl . $query; $searchString = $searchUrl . $query;
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
@ -205,11 +255,16 @@ class SearchClass {
$output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName); $output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName);
//$output .= '<br />'.$alpha_out; //$output .= '<br />'.$alpha_out;
return $output; return $output;
} }
/**
* custom search ??
* @param type $query
* @param type $startPage
* @param type $xslt
* @param type $numberOfHistPerPage
* @return type
*/
function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) { function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -225,8 +280,8 @@ class SearchClass {
$query = trim($query); $query = trim($query);
$query = htmlentities(urlencode($query)); $query = htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt='. $copyXMLFile . '&query=' . $query; $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query;
$searchString .= '&hitPageSize='. $numberOfHistPerPage . '&hitPageStart='. $startPage; $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage;
//$searchString = htmlentities($searchString); //$searchString = htmlentities($searchString);
$searchUrl .= $searchString; $searchUrl .= $searchString;
@ -242,7 +297,14 @@ class SearchClass {
} }
} }
/**
* apply specified xslt ??
* @global type $user
* @param type $resultData
* @param type $pathToXSLT
* @param type $displayName
* @return type
*/
function applySpecifiedXSLT($resultData, $pathToXSLT, $displayName = NULL) { function applySpecifiedXSLT($resultData, $pathToXSLT, $displayName = NULL) {
$proc = NULL; $proc = NULL;
global $user; global $user;
@ -252,9 +314,8 @@ class SearchClass {
} }
try { try {
$proc = new XsltProcessor(); $proc = new XsltProcessor();
} } catch (Exception $e) {
catch (Exception $e) { drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!') . $e->getMessage());
drupal_set_message(t('Error loading '. $pathToXSLT . ' xslt!') . $e->getMessage());
return ' '; return ' ';
} }
@ -270,10 +331,10 @@ class SearchClass {
$xsl = new DomDocument(); $xsl = new DomDocument();
$test= $xsl->load($pathToXSLT); $test = $xsl->load($pathToXSLT);
if (!isset($test)) { if (!isset($test)) {
drupal_set_message(t('Error loading '. $pathToXSLT . ' xslt!')); drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!'));
return t('Error loading !pathToXSLT xslt.', array('!pathToXSLT' => $pathToXSLT)); return t('Error loading !pathToXSLT xslt.', array('!pathToXSLT' => $pathToXSLT));
} }
@ -291,8 +352,8 @@ class SearchClass {
return $newdom->saveXML(); return $newdom->saveXML();
} }
} }
//default function for lucene results
//default function for lucene results
/** /**
* apply an xslt to lucene gsearch search results * apply an xslt to lucene gsearch search results
@ -305,8 +366,8 @@ class SearchClass {
function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) { function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) {
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$test = $xslt_file; $test = $xslt_file;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE); $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if(!isRestricted && $xslt_file == null){ if (!isRestricted && $xslt_file == null) {
$xslt_file = '/xsl/unfilteredresults.xsl'; $xslt_file = '/xsl/unfilteredresults.xsl';
} }
$proc = NULL; $proc = NULL;
@ -354,7 +415,12 @@ class SearchClass {
} }
} }
//xslt for islandscholar these xslt functions can probably be pulled into one /**
* xslt for islandscholar these xslt functions can probably be pulled into one
* @param type $resultData
* @param type $orderBy
* @return type
*/
function applyXSLT($resultData, $orderBy = 0) { function applyXSLT($resultData, $orderBy = 0) {
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$proc = NULL; $proc = NULL;
@ -378,7 +444,7 @@ class SearchClass {
$proc->setParameter('', 'orderBy', $orderBy); $proc->setParameter('', 'orderBy', $orderBy);
$xsl = new DomDocument(); $xsl = new DomDocument();
$test=$xsl->load($path . '/ir/xsl/results.xsl'); $test = $xsl->load($path . '/ir/xsl/results.xsl');
if (!isset($test)) { if (!isset($test)) {
drupal_set_message(t('Error loading search results xslt!')); drupal_set_message(t('Error loading search results xslt!'));
return t('Error loading search results XSLT.'); return t('Error loading search results XSLT.');
@ -398,31 +464,43 @@ class SearchClass {
} }
} }
/**
* theme advanced search form ??
* @param type $form
* @param type $repeat
* @return type
*/
function theme_advanced_search_form($form, $repeat=NULL) { function theme_advanced_search_form($form, $repeat=NULL) {
if (!isset($repeat)) { if (!isset($repeat)) {
$repeat = variable_get('fedora_repository_advanced_block_repeat', t('3')); $repeat = variable_get('fedora_repository_advanced_block_repeat', t('3'));
} }
$output = drupal_render($form['search_type']['type1']) ; $output = drupal_render($form['search_type']['type1']);
$output .= drupal_render($form['fedora_terms1']) ; $output .= drupal_render($form['fedora_terms1']);
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']) ; $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']);
$output .= drupal_render($form['fedora_terms2']); $output .= drupal_render($form['fedora_terms2']);
if ($repeat>2 && $repeat < 9) { if ($repeat > 2 && $repeat < 9) {
for ($i=3;$i<$repeat+1;$i++) { for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1; $t = $i - 1;
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]) ; $output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]);
$output .= drupal_render($form["fedora_terms$i"]) ; $output .= drupal_render($form["fedora_terms$i"]);
} }
} }
$output .= drupal_render($form['submit']) ; $output .= drupal_render($form['submit']);
$output .= drupal_render($form); $output .= drupal_render($form);
return $output; return $output;
} }
//build search form, custom blocks should set the number of repeats or it will use the default /**
* build search form, custom blocks should set the number of repeats or it will use the default
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return string
*/
function build_advanced_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) { function build_advanced_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {
$types = $this->get_search_terms_array($pathToSearchTerms); $types = $this->get_search_terms_array($pathToSearchTerms);
$queryArray=NULL; $queryArray = NULL;
if (isset($query)) { if (isset($query)) {
$queryArray = explode('AND', $query); $queryArray = explode('AND', $query);
} }
@ -469,7 +547,7 @@ class SearchClass {
'#title' => t(''), '#title' => t(''),
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''), '#default_value' => (count($var1) >= 2 ? $var1[1] : ''),
); );
if ($repeat>2 && $repeat < 9) { //don't want less then 2 or more then 9 if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9
for ($i = 3; $i < $repeat + 1; $i++) { for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1; $t = $i - 1;
$field_and_term = explode(':', $queryArray[$t]); $field_and_term = explode(':', $queryArray[$t]);
@ -501,7 +579,12 @@ class SearchClass {
return $form; return $form;
} }
/**
* get search terms array
* @param type $path
* @param string $file
* @return type
*/
function get_search_terms_array($path = NULL, $file = NULL) { function get_search_terms_array($path = NULL, $file = NULL) {
if (!isset($path)) { if (!isset($path)) {
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
@ -510,7 +593,7 @@ class SearchClass {
if (!isset($file)) { if (!isset($file)) {
$file = 'searchTerms.xml'; $file = 'searchTerms.xml';
} }
$xmlDoc->load($path . '/'. $file); $xmlDoc->load($path . '/' . $file);
$nodeList = $xmlDoc->getElementsByTagName('term'); $nodeList = $xmlDoc->getElementsByTagName('term');
$types = array(); $types = array();
for ($i = 0; $i < $nodeList->length; $i++) { for ($i = 0; $i < $nodeList->length; $i++) {
@ -522,4 +605,5 @@ class SearchClass {
} }
return $types; return $types;
} }
} }

60
SecurityClass.inc

@ -1,20 +1,33 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on 22-Oct-08 * @file
* * SecurityClass Class
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ */
/**
* SecurityClass ??
*/
class SecurityClass { class SecurityClass {
public static $SECURITY_CLASS_SECURITY_STREAM = 'POLICY'; public static $SECURITY_CLASS_SECURITY_STREAM = 'POLICY';
/**
* Constructor
*/
function SecurityClass() { function SecurityClass() {
module_load_include('inc', 'SecurityClass', ''); module_load_include('inc', 'SecurityClass', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* canIngestHere ??
* @global type $user
* @param type $collection_pid
* @return type
*/
function canIngestHere($collection_pid) { function canIngestHere($collection_pid) {
global $user; global $user;
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
@ -47,15 +60,18 @@ class SecurityClass {
return FALSE; return FALSE;
} }
//parses our simple xacml policies checking for users or roles that are allowed to ingest /**
* parses our simple xacml policies checking for users or roles that are allowed to ingest
* @param type $policyStream
* @return type
*/
function getAllowedUsersAndRoles($policyStream) { function getAllowedUsersAndRoles($policyStream) {
$allowedRoles = array(); $allowedRoles = array();
$allowedUsers = array(); $allowedUsers = array();
$usersAndRoles = array(); $usersAndRoles = array();
try { try {
$xml = new SimpleXMLElement($policyStream); $xml = new SimpleXMLElement($policyStream);
} } catch (Exception $e) {
catch (Exception $e) {
watchdog(t("Fedora_Repository"), t("No roles found in security policy, could not parse policy stream."), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("No roles found in security policy, could not parse policy stream."), NULL, WATCHDOG_ERROR);
//we may not want to send this to the screen. //we may not want to send this to the screen.
drupal_set_message(t('No roles found in security policy, could not parse policy stream: !message', array('!message' => $e->getMessage())), 'error'); drupal_set_message(t('No roles found in security policy, could not parse policy stream: !message', array('!message' => $e->getMessage())), 'error');
@ -68,7 +84,7 @@ class SecurityClass {
foreach ($conditions as $condition) { foreach ($conditions as $condition) {
$designator = $condition->Apply->SubjectAttributeDesignator; $designator = $condition->Apply->SubjectAttributeDesignator;
if (empty($designator)) {//$disignator may be wrapped by an or if (empty($designator)) {//$disignator may be wrapped by an or
$designator=$condition->Apply->Apply->SubjectAttributeDesignator; $designator = $condition->Apply->Apply->SubjectAttributeDesignator;
} }
$attributeId = strip_tags($designator['AttributeId']); $attributeId = strip_tags($designator['AttributeId']);
@ -92,17 +108,20 @@ class SecurityClass {
$usersAndRoles['users'] = $allowedUsers; $usersAndRoles['users'] = $allowedUsers;
$usersAndRoles['roles'] = $allowedRoles; $usersAndRoles['roles'] = $allowedRoles;
return $usersAndRoles; return $usersAndRoles;
} }
// When a user's profile is saved in drupal we will attempt to create a collection for them in Fedora
// this will be their personal space. In the IR it is editable by users with the same role in the VRE /**
// it probably would not be. * When a user's profile is saved in drupal we will attempt to create a collection for them in Fedora
* this will be their personal space. In the IR it is editable by users with the same role in the VRE
* it probably would not be.
* @param type $user
* @return DOMDocument
*/
function createPersonalPolicy($user) { function createPersonalPolicy($user) {
$doc = new DOMDocument(); $doc = new DOMDocument();
try { try {
$doc->load(drupal_get_path('module', 'Fedora_Repository') . '/policies/noObjectEditPolicy.xml'); $doc->load(drupal_get_path('module', 'Fedora_Repository') . '/policies/noObjectEditPolicy.xml');
} } catch (exception $e) {
catch (exception $e) {
watchdog(t("Fedora_Repository"), t("Problem loading policy file."), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("Problem loading policy file."), NULL, WATCHDOG_ERROR);
} }
$conditions = $doc->getElementsByTagName('Condition'); $conditions = $doc->getElementsByTagName('Condition');
@ -117,7 +136,7 @@ class SecurityClass {
if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') {
foreach ($user->roles as $role) { foreach ($user->roles as $role) {
if (!($role == 'authenticated user' || $role == 'administrator')) { //don't want authenticated user included administrator already is included' if (!($role == 'authenticated user' || $role == 'administrator')) { //don't want authenticated user included administrator already is included'
$newAttributeValue=$doc->createElement('AttributeValue', '<![CDATA['. $role . ']]>'); $newAttributeValue = $doc->createElement('AttributeValue', '<![CDATA[' . $role . ']]>');
$newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string');
// $newAttributeValue->setAttribute('MustBePresent', 'FALSE'); // $newAttributeValue->setAttribute('MustBePresent', 'FALSE');
$apply->appendChild($newAttributeValue); $apply->appendChild($newAttributeValue);
@ -132,7 +151,7 @@ class SecurityClass {
foreach ($applies as $apply) { foreach ($applies as $apply) {
$functionId = $apply->getAttribute('FunctionId'); $functionId = $apply->getAttribute('FunctionId');
if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') {
$newAttributeValue=$doc->createElement('AttributeValue', $user->name); $newAttributeValue = $doc->createElement('AttributeValue', $user->name);
$newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string');
//$newAttributeValue->setAttribute('MustBePresent', 'FALSE'); //$newAttributeValue->setAttribute('MustBePresent', 'FALSE');
$apply->appendChild($newAttributeValue); $apply->appendChild($newAttributeValue);
@ -170,7 +189,7 @@ class SecurityClass {
if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') {
foreach ($allowed_roles as $role) { foreach ($allowed_roles as $role) {
if (!($role == 'authenticated user' || $role == 'administrator')) { //don't want authenticated user included administrator already is included' if (!($role == 'authenticated user' || $role == 'administrator')) { //don't want authenticated user included administrator already is included'
$newAttributeValue=$dom->createElement('AttributeValue', $role); $newAttributeValue = $dom->createElement('AttributeValue', $role);
$newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string');
//$newAttributeValue->setAttribute('MustBePresent', 'FALSE'); //$newAttributeValue->setAttribute('MustBePresent', 'FALSE');
$apply->appendChild($newAttributeValue); $apply->appendChild($newAttributeValue);
@ -186,8 +205,8 @@ class SecurityClass {
foreach ($applies as $apply) { foreach ($applies as $apply) {
$functionId = $apply->getAttribute('FunctionId'); $functionId = $apply->getAttribute('FunctionId');
if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') {
foreach ( $allowed_users as $username ) { foreach ($allowed_users as $username) {
$newAttributeValue=$dom->createElement('AttributeValue', $username ); $newAttributeValue = $dom->createElement('AttributeValue', $username);
$newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string');
//$newAttributeValue->setAttribute('MustBePresent', 'FALSE'); //$newAttributeValue->setAttribute('MustBePresent', 'FALSE');
$apply->appendChild($newAttributeValue); $apply->appendChild($newAttributeValue);
@ -200,4 +219,5 @@ class SecurityClass {
// $this->collection_policy_stream = $dom->saveXML(); // $this->collection_policy_stream = $dom->saveXML();
return $dom->saveXML(); return $dom->saveXML();
} }
} }

19
XMLDatastream.inc

@ -2,6 +2,14 @@
// $Id$ // $Id$
/**
* @file
* XMLDatastream Abstract Class
*/
/**
* XMLDatastream class ??
*/
abstract class XMLDatastream { abstract class XMLDatastream {
static $XMLNS = 'http://www.islandora.ca'; static $XMLNS = 'http://www.islandora.ca';
@ -96,7 +104,7 @@ abstract class XMLDatastream {
$this->pid = $pid; $this->pid = $pid;
$this->dsid = $dsid; $this->dsid = $dsid;
if ($xmlStr !== NULL) { if ($xmlStr !== NULL) {
if(is_object($xmlStr) && get_class($xmlStr) == DOMDocument) { if (is_object($xmlStr) && get_class($xmlStr) == DOMDocument) {
$this->xml = $xmlStr; $this->xml = $xmlStr;
} }
else { else {
@ -180,7 +188,8 @@ abstract class XMLDatastream {
// a subclass. // a subclass.
$vars = get_class_vars(get_class($this)); $vars = get_class_vars(get_class($this));
$schemaLocation = $vars['SCHEMA_URI']; $schemaLocation = $vars['SCHEMA_URI'];
} elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) { }
elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) {
//figure out where the schema is located and validate. //figure out where the schema is located and validate.
list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue); list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue);
} }
@ -193,10 +202,12 @@ abstract class XMLDatastream {
foreach ($errors as $err) { foreach ($errors as $err) {
self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message; self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message;
} }
} else { }
else {
$this->name = $rootEl->attributes->getNamedItem('name')->nodeValue; $this->name = $rootEl->attributes->getNamedItem('name')->nodeValue;
} }
} else { }
else {
$ret = FALSE; $ret = FALSE;
self::$errors[] = 'Unable to load schema.'; self::$errors[] = 'Unable to load schema.';
} }

4
formClass.inc

@ -2,10 +2,6 @@
// $Id$ // $Id$
/*
* Created on Jan 22, 2008
*/
class formClass { class formClass {
function formClass() { function formClass() {

9
plugins/Flv.inc

@ -38,6 +38,7 @@ class FormBuilder {
$datastream->appendChild($version); $datastream->appendChild($version);
$content = $dom->createElement("foxml:xmlContent"); $content = $dom->createElement("foxml:xmlContent");
$version->appendChild($content); $version->appendChild($content);
///begin writing qdc ///begin writing qdc
$oai = $dom->createElement("oai_dc:dc"); $oai = $dom->createElement("oai_dc:dc");
$oai->setAttribute('xmlns:oai_dc', "http://www.openarchives.org/OAI/2.0/oai_dc/"); $oai->setAttribute('xmlns:oai_dc', "http://www.openarchives.org/OAI/2.0/oai_dc/");
@ -45,10 +46,12 @@ class FormBuilder {
$oai->setAttribute('xmlns:dcterms', "http://purl.org/dc/terms/"); $oai->setAttribute('xmlns:dcterms', "http://purl.org/dc/terms/");
$oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$content->appendChild($oai); $content->appendChild($oai);
//dc elements //dc elements
$previousElement = NULL; //used in case we have to nest elements for qualified dublin core $previousElement = NULL; //used in case we have to nest elements for qualified dublin core
foreach ($form_values as $key => $value) { foreach ($form_values as $key => $value) {
$index = strrpos($key, '-'); $index = strrpos($key, '-');
if ($index > 01) { if ($index > 01) {
$key = substr($key, 0, $index); $key = substr($key, 0, $index);
} }
@ -89,10 +92,13 @@ class FormBuilder {
$rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-0.xsd"); $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-0.xsd");
$dom->appendChild($rootElement); $dom->appendChild($rootElement);
//create standard fedora stuff //create standard fedora stuff
$this->createStandardFedoraStuff($form_values, $dom, $rootElement); $this->createStandardFedoraStuff($form_values, $dom, $rootElement);
//create relationships //create relationships
$this->createRelationShips($form_values, $dom, $rootElement); $this->createRelationShips($form_values, $dom, $rootElement);
//create dublin core //create dublin core
$this->createQDCStream($form_values, $dom, $rootElement); $this->createQDCStream($form_values, $dom, $rootElement);
$this->createFedoraDataStreams($form_values, $dom, $rootElement); $this->createFedoraDataStreams($form_values, $dom, $rootElement);
@ -261,11 +267,13 @@ class FormBuilder {
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Ingest Digital Object Step #2') '#title' => t('Ingest Digital Object Step #2')
); );
foreach ($ingest_form_definition->form_elements->element as $element) { foreach ($ingest_form_definition->form_elements->element as $element) {
$name = strip_tags($element->name->asXML()); $name = strip_tags($element->name->asXML());
$title = strip_tags($element->label->asXML()); $title = strip_tags($element->label->asXML());
$required = strip_tags($element->required->asXML()); $required = strip_tags($element->required->asXML());
$required = strtolower($required); $required = strtolower($required);
if ($required != 'TRUE') { if ($required != 'TRUE') {
$required = '0'; $required = '0';
} }
@ -273,6 +281,7 @@ class FormBuilder {
$description = strip_tags($element->description->asXML()); $description = strip_tags($element->description->asXML());
$type = strip_tags($element->type->asXML()); $type = strip_tags($element->type->asXML());
$options = array(); $options = array();
if ($element->type == 'select') { if ($element->type == 'select') {
foreach ($element->authoritative_list->item as $item) { foreach ($element->authoritative_list->item as $item) {
$field = strip_tags($item->field->asXML()); $field = strip_tags($item->field->asXML());

Loading…
Cancel
Save