diff --git a/CollectionClass.inc b/CollectionClass.inc index a7c369a3..c2929708 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -2,15 +2,18 @@ // $Id$ -/* - * Created on 18-Feb-08 - * - * To change the template for this generated file go to - * Window - Preferences - PHPeclipse - PHP - Code Templates +/** + * @file + * + * Collection Class Class + */ + +/** + * 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 { 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 */ - function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $objectHelper = new ObjectHelper(); @@ -96,6 +99,11 @@ class CollectionClass { return $content; } + /** + * getCollectionPolicyStream ?? + * @param type $collection_pid + * @return type + */ function getCollectionPolicyStream($collection_pid) { if ($this->collectionPolicyStream != NULL) { return $this->collectionPolicyStream; @@ -104,6 +112,11 @@ class CollectionClass { return $this->collectionPolicyStream; } + /** + * getRelationshipElement + * @param type $collection_pid + * @return type + */ function getRelationshipElement($collection_pid) { $stream = $this->getCollectionPolicyStream($collection_pid); try { @@ -116,17 +129,35 @@ class CollectionClass { return $relationship; } + /** + * getCollectionViewStream ?? + * @param type $collection_pid + * @return type + */ function getCollectionViewStream($collection_pid) { $this->collectionViewStream = $this->getStream($collection_pid, CollectionClass :: $COLLECTION_CLASS_COLLECTION_VIEW_STREAM, 0); return $this->collectionViewStream; } + /** + * getStream ?? + * @param type $pid + * @param type $dsid + * @param type $showError + * @return type + */ function getStream($pid, $dsid, $showError = 1) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new fedora_item($pid); return isset($item->datastreams[$dsid]) ? $item->get_datastream_dissemination($dsid) : NULL; } + /** + * getPidNameSpace ?? + * @param type $pid + * @param type $dsid + * @return type + */ function getPidNameSpace($pid, $dsid) { $stream = $this->getCollectionPolicyStream($pid); try { @@ -218,6 +249,12 @@ class CollectionClass { return NULL; } + /** + * getAllowedMimeType ?? + * @param type $contentModelPid + * @param type $contentModel_dsid + * @return type + */ function getAllowedMimeTypes($contentModelPid, $contentModel_dsid) { $stream = $this->getContentModelStream($contentModelPid, $contentModel_dsid); try { @@ -357,8 +394,13 @@ class CollectionClass { 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) { if (isset($user->fedora_personal_pid)) { return; @@ -414,6 +456,13 @@ class CollectionClass { return $xslContent; } + /** + * showFieldSets ?? + * @global type $base_url + * @global type $user + * @param type $page_number + * @return string + */ function showFieldSets($page_number) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); global $base_url; @@ -451,6 +500,11 @@ class CollectionClass { return $tabset; } + /** + * getIngestInterface ?? + * @global type $base_url + * @return string + */ function getIngestInterface() { global $base_url; $objectHelper = new ObjectHelper(); @@ -474,6 +528,16 @@ class CollectionClass { 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) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; diff --git a/CollectionPolicy.inc b/CollectionPolicy.inc index 8997b42e..af28633e 100644 --- a/CollectionPolicy.inc +++ b/CollectionPolicy.inc @@ -2,15 +2,21 @@ // $Id$ +/** + * @file + * Collection Policy Class + */ module_load_include('inc', 'fedora_repository', 'XMLDatastream'); +/** + * Collection Policy class ?? + */ 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'; + private $staging_area = NULL; - private $staging_area=NULL; - /** * Gets the default DSID to use for ContentModel datastreams. * @@ -33,31 +39,30 @@ class CollectionPolicy extends XMLDatastream { static function loadFromCollection($pid, $preFetch=TRUE) { $ret = FALSE; module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - + try { if (self::validPid($pid)) { - $dsid=CollectionPolicy::getDefaultDSID(); + $dsid = CollectionPolicy::getDefaultDSID(); if ($preFetch) { $fedoraItem = new Fedora_Item($pid); $ds = $fedoraItem->get_datastream_dissemination($dsid); - } else { - $ds=null; } - + else { + $ds = null; + } } - + if (!empty($ds) || !$preFetch) { - $ret=new CollectionPolicy($ds, $pid, $dsid); + $ret = new CollectionPolicy($ds, $pid, $dsid); } - } - catch (SOAPException $e) { - + } catch (SOAPException $e) { + $ret = FALSE; } return $ret; } - + /** * Ingests a new Collection Policy datastream to the specified * PID with the DSID specified. The file should be a valid collection @@ -68,24 +73,24 @@ class CollectionPolicy extends XMLDatastream { * @param string $cpDsid * @param string $file * @return CollectionPolicy $ret - */ + */ public static function ingestFromFile($pid, $name, $cpDsid, $file) { $ret = FALSE; - + if (($cp = self::loadFromCollection($pid, $cpDsid)) === FALSE && file_exists($file)) { $cp = new ContentModel(file_get_contents($file), $pid, $cpDsid); $rootEl = $cp->xml->getElementsByTagName('collection_policy')->item(0); $rootEl->setAttribute('name', $name); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $fedoraItem = new Fedora_Item($pid); $fedoraItem->add_datastream_from_string($cp->dumpXml(), $cpDsid, $name, 'text/xml', 'X'); $ret = $cp; } - + return $ret; } - + /** * Ingests a new Collection Policy datastream to the specified * PID with the DSID specified. Clones the collection policy from the @@ -96,26 +101,26 @@ class CollectionPolicy extends XMLDatastream { * @param string $cpDsid * @param string $copy_collection_pid * @return CollectionPolicy $ret - */ + */ public static function ingestFromCollection($pid, $name, $cpDsid, $copy_collection_pid) { $ret = FALSE; - + if (($cp = self::loadFromCollection($pid, $cpDsid)) === FALSE && ($copy_cp = self::loadFromCollection($copy_collection_pid)) !== FALSE && $copy_cp->validate()) { $newDom = $copy_cp->xml; $rootEl = $newDom->getElementsByTagName('collection_policy')->item(0); $rootEl->setAttribute('name', $name); - + $cp = new CollectionPolicy($newDom, $pid, $cpDsid); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $fedoraItem = new Fedora_Item($pid); $fedoraItem->add_datastream_from_string($cp->dumpXml(), $cpDsid, $name, 'text/xml', 'X'); $ret = $cp; } - + return $ret; - } - + } + /** * Ingests a new minimum Collection Policy datastream to the specified * PID with the DSID specified. Initializes the policy with the specified values. @@ -130,10 +135,10 @@ class CollectionPolicy extends XMLDatastream { * @param string $searchField * @param string $searchValue * @return CollectionPolicy $ret - */ + */ public static function ingestBlankPolicy($pid, $name, $policyDsid, $model_pid, $model_namespace, $relationship, $searchField, $searchValue) { - $ret = FALSE; - if (($cp = self::loadFromCollection($pid )) === FALSE) { //removed second, non-existant variable + $ret = FALSE; + if (($cp = self::loadFromCollection($pid)) === FALSE) { //removed second, non-existant variable module_load_include('inc', 'fedora_repository', 'ContentModel'); if (($cm = ContentModel::loadFromModel($model_pid)) !== FALSE && $cm->validate()) { $newDom = new DOMDocument('1.0', 'utf-8'); @@ -142,45 +147,43 @@ class CollectionPolicy extends XMLDatastream { $rootEl->setAttribute('name', $name); $rootEl->setAttribute('xmlns', self::$XMLNS); $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'); - + $cmEl = $newDom->createElement('content_model'); $cmEl->setAttribute('name', $cm->getName()); $cmEl->setAttribute('dsid', $cm->dsid); $cmEl->setAttribute('namespace', $model_namespace); $cmEl->setAttribute('pid', $cm->pid); - - $modelsEl->appendChild($cmEl); + + $modelsEl->appendChild($cmEl); $rootEl->appendChild($modelsEl); - + $relEl = $newDom->createElement('relationship', $relationship); $rootEl->appendChild($relEl); - + $searchTermsEl = $newDom->createElement('search_terms'); $newTermEl = $newDom->createElement('term', $searchValue); $newTermEl->setAttribute('field', $searchField); $searchTermsEl->appendChild($newTermEl); $rootEl->appendChild($searchTermsEl); - + $newDom->appendChild($rootEl); - + $cp = new CollectionPolicy($newDom, $pid, $policyDsid); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - - + + $fedoraItem = new Fedora_Item($pid); $fedoraItem->add_datastream_from_string($cp->dumpXml(), $policyDsid, $name, 'text/xml', 'X'); $ret = $cp; } - } - + return $ret; - } - + } /** * Constructor @@ -192,10 +195,10 @@ class CollectionPolicy extends XMLDatastream { * @return XMLDatastream $cm */ public function __construct($xmlStr, $pid = NULL, $dsid = NULL) { - parent::__construct($xmlStr,$pid,$dsid); - $this->name= 'Collection Policy'; + parent::__construct($xmlStr, $pid, $dsid); + $this->name = 'Collection Policy'; } - + /** * Attempts to convert from the old XML schema to the new by * traversing the XML DOM and building a new DOM. When done @@ -205,17 +208,17 @@ class CollectionPolicy extends XMLDatastream { */ protected function convertFromOldSchema() { if ($this->xml == NULL) { - $this->fetchXml(); + $this->fetchXml(); } $sXml = simplexml_load_string($this->xml->saveXML()); $newDom = new DOMDocument('1.0', 'utf-8'); $newDom->formatOutput = TRUE; - + $rootEl = $newDom->createElement('collection_policy'); $rootEl->setAttribute('name', $sXml['name']); $rootEl->setAttribute('xmlns', self::$XMLNS); $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'); foreach ($sXml->contentmodels->contentmodel as $contentmodel) { @@ -227,13 +230,13 @@ class CollectionPolicy extends XMLDatastream { $content_modelsEl->appendChild($content_modelEl); } $rootEl->appendChild($content_modelsEl); - + $search_termsEl = $newDom->createElement('search_terms'); foreach ($sXml->search_terms->term as $term) { $termEl = $newDom->createElement('term', $term->value); $termEl->setAttribute('field', $term->field); if (strval($sXml->search_terms->default) == $term->field) { - $termEl->setAttribute('default', 'true'); + $termEl->setAttribute('default', 'true'); } $search_termsEl->appendChild($termEl); } @@ -241,13 +244,12 @@ class CollectionPolicy extends XMLDatastream { $relationshipEl = $newDom->createElement('relationship', $sXml->relationship); $rootEl->appendChild($relationshipEl); - + $newDom->appendChild($rootEl); $this->xml = DOMDocument::loadXML($newDom->saveXml()); } - /** * Gets the name of the relationship to use * for members of this collection. @@ -256,14 +258,14 @@ class CollectionPolicy extends XMLDatastream { * @return string $relationship */ public function getRelationship() { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { - $ret=trim($this->xml->getElementsByTagName('relationship')->item(0)->nodeValue); + $ret = trim($this->xml->getElementsByTagName('relationship')->item(0)->nodeValue); } return $ret; } - - /** + + /** * Sets the name of the relationship to use * for members of this collection. * Returns FALSE on failure. @@ -272,16 +274,16 @@ class CollectionPolicy extends XMLDatastream { * @return boolean $ret */ public function setRelationship($relationship) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { - $relationshipEl=$this->xml->getElementsByTagName('relationship')->item(0); - $relationshipEl->nodeValue=trim($relationship); + $relationshipEl = $this->xml->getElementsByTagName('relationship')->item(0); + $relationshipEl->nodeValue = trim($relationship); $ret = TRUE; } - return $ret; + return $ret; } - - /** + + /** * Gets the path to the staging area to use for this * collection. By default recurses to the parent collection * if the staging area is undefined @@ -290,17 +292,18 @@ class CollectionPolicy extends XMLDatastream { * @return string $path */ public function getStagingArea($recurse=TRUE) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { if ($this->staging_area === NULL) { - $stagingEl=$this->xml->getElementsByTagName('staging_area'); - + $stagingEl = $this->xml->getElementsByTagName('staging_area'); + if ($stagingEl->length > 0) { $this->staging_area = trim($stagingEl->item(0)->nodeValue); - } elseif ($recurse) { + } + elseif ($recurse) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $item=new Fedora_Item($this->pid); - $rels=$item->get_relationships(); + $item = new Fedora_Item($this->pid); + $rels = $item->get_relationships(); if (count($rels) > 0) { foreach ($rels as $rel) { $cp = CollectionPolicy::loadFromCollection($rel['object']); @@ -310,16 +313,15 @@ class CollectionPolicy extends XMLDatastream { } } } - } + } } - + $ret = $this->staging_area; - } return $ret; } - - /** + + /** * Sets the path to the staging area to use for this * collection. If specified path is blank (or false) it will * remove the staging are path element from the collection policy. @@ -329,84 +331,77 @@ class CollectionPolicy extends XMLDatastream { * @return string $relationship */ public function setStagingArea($path) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { - $rootEl=$this->xml->getElementsByTagName('collection_policy')->item(0); - $stagingEl=$this->xml->getElementsByTagName('staging_area'); + $rootEl = $this->xml->getElementsByTagName('collection_policy')->item(0); + $stagingEl = $this->xml->getElementsByTagName('staging_area'); if ($stagingEl->length > 0) { - $stagingEl=$stagingEl->item(0); - if (trim($path) == '') { - $rootEl->removeChild($stagingEl); - } + $stagingEl = $stagingEl->item(0); + if (trim($path) == '') { + $rootEl->removeChild($stagingEl); + } else { - $stagingEl->nodeValue=trim($path); - } - } + $stagingEl->nodeValue = trim($path); + } + } elseif (trim($path) != '') { - $stagingEl=$this->xml->createElement('staging_area', trim($path)); - $rootEl->appendChild($stagingEl); + $stagingEl = $this->xml->createElement('staging_area', trim($path)); + $rootEl->appendChild($stagingEl); } $ret = TRUE; } - return $ret; - } - - + return $ret; + } + /** - * Gets the next available PID for the - * content model specified by the DSID - * parameter. - * - * @param string $dsid - * @return string $nextPid - */ + * Gets the next available PID for the + * content model specified by the DSID + * parameter. + * + * @param string $dsid + * @return string $nextPid + */ public function getNextPid($dsid) { $ret = FALSE; if (self::validDsid($dsid) && $this->validate()) { $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); $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)) { $namespace = $content_models->item($i)->getAttribute('namespace'); } } $pname = substr($namespace, 0, strpos($namespace, ":")); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $ret = Fedora_Item::get_next_pid_in_namespace($pname); } return $ret; } - + /** - * Gets a list of ContentModel objects supported by this collection. - * - * @return ContentModel[] $models - */ + * Gets a list of ContentModel objects supported by this collection. + * + * @return ContentModel[] $models + */ function getContentModels() { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { module_load_include('inc', 'Fedora_Repository', 'ContentModel'); - $ret=array(); + $ret = array(); $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); - for ($i=0;$i<$content_models->length;$i++) { - $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')); - if ($cm !== FALSE) { - $ret[]=$cm; - } - + for ($i = 0; $i < $content_models->length; $i++) { + $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')); + if ($cm !== FALSE) { + $ret[] = $cm; + } } } return $ret; } - - /** * 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. @@ -421,52 +416,51 @@ class CollectionPolicy extends XMLDatastream { */ function getSearchTerms($asArray = FALSE, $recurse = FALSE, $cache = FALSE) { $ret = FALSE; - - if ($cache == TRUE && ($cache = cache_get('collection_policy_search_terms-'.$this->pid)) !== 0 ) { - $ret=$cache->data; - } else { - + + if ($cache == TRUE && ($cache = cache_get('collection_policy_search_terms-' . $this->pid)) !== 0) { + $ret = $cache->data; + } + else { + if ($this->xml == NULL) { - $fedoraItem = new Fedora_Item($this->pid); - $ds = $fedoraItem->get_datastream_dissemination($this->dsid); - $this->xml = DOMDocument::loadXML($ds); + $fedoraItem = new Fedora_Item($this->pid); + $ds = $fedoraItem->get_datastream_dissemination($this->dsid); + $this->xml = DOMDocument::loadXML($ds); } - + if ($this->validate()) { - $ret=array(); - $terms= $this->xml->getElementsByTagName('search_terms')->item(0)->getElementsByTagName('term'); - for ($i=0;$i<$terms->length;$i++) { - $default = $terms->item($i)->attributes->getNamedItem('default'); - $default = ($default !== NULL) ? (strtolower($default->nodeValue) == 'true') : FALSE; - $ret[] = ($asArray)?array( 'value' => $terms->item($i)->nodeValue, - 'field' => $terms->item($i)->getAttribute('field'), - 'default' => $default): $terms->item($i)->nodeValue; - } - - - if ($recurse && count($ret) == 0) { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $item=new Fedora_Item($this->pid); - $rels=$item->get_relationships(); - if (count($rels) > 0) { - foreach ($rels as $rel) { - $cp = CollectionPolicy::loadFromCollection($rel['object']); - if ($cp !== FALSE) { - $ret = $cp->getSearchTerms($asArray, $recurse); - break; - } - } - } - } - cache_set('collection_policy_search_terms-'.$this->pid, $ret, 'cache', time()+3600); - + $ret = array(); + $terms = $this->xml->getElementsByTagName('search_terms')->item(0)->getElementsByTagName('term'); + for ($i = 0; $i < $terms->length; $i++) { + $default = $terms->item($i)->attributes->getNamedItem('default'); + $default = ($default !== NULL) ? (strtolower($default->nodeValue) == 'true') : FALSE; + $ret[] = ($asArray) ? array('value' => $terms->item($i)->nodeValue, + 'field' => $terms->item($i)->getAttribute('field'), + 'default' => $default) : $terms->item($i)->nodeValue; + } + + + if ($recurse && count($ret) == 0) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($this->pid); + $rels = $item->get_relationships(); + if (count($rels) > 0) { + foreach ($rels as $rel) { + $cp = CollectionPolicy::loadFromCollection($rel['object']); + if ($cp !== FALSE) { + $ret = $cp->getSearchTerms($asArray, $recurse); + break; + } + } + } + } + cache_set('collection_policy_search_terms-' . $this->pid, $ret, 'cache', time() + 3600); } } return $ret; } - /** * Adds a search term to the collection policy. * Returns fase on failure. @@ -476,17 +470,17 @@ class CollectionPolicy extends XMLDatastream { * @return boolean $success */ function addTerm($field, $value) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); - $terms= $search_termsEl->getElementsByTagName('term'); - $found=FALSE; - for ($i=0;!$found && $i<$terms->length;$i++) { + $terms = $search_termsEl->getElementsByTagName('term'); + $found = FALSE; + for ($i = 0; !$found && $i < $terms->length; $i++) { if ($terms->item($i)->getAttribute('field') == $field) { - $found = TRUE; + $found = TRUE; } } - + if (!$found) { $newTermEl = $this->xml->createElement('term', $value); $newTermEl->setAttribute('field', $field); @@ -502,19 +496,19 @@ class CollectionPolicy extends XMLDatastream { * * @param string $field * @return boolean $success - */ + */ function removeTerm($field) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); $terms = $search_termsEl->getElementsByTagName('term'); $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) { - $found = $terms->item($i); + $found = $terms->item($i); } } - + if ($found !== FALSE) { $search_termsEl->removeChild($found); $ret = TRUE; @@ -523,21 +517,25 @@ class CollectionPolicy extends XMLDatastream { return $ret; } - - function setDefaultTerm($field) { + /** + * setDefaultTerm ?? + * @param type $field + * @return boolean + */ + function setDefaultTerm($field) { $ret = FALSE; if ($this->validate()) { $search_termsEl = $this->xml->getElementsByTagName('search_terms')->item(0); - $terms= $search_termsEl->getElementsByTagName('term'); - $found=FALSE; - for ($i=0;!$found && $i<$terms->length;$i++) { + $terms = $search_termsEl->getElementsByTagName('term'); + $found = FALSE; + for ($i = 0; !$found && $i < $terms->length; $i++) { if ($terms->item($i)->getAttribute('field') == $field) { - $found = $terms->item($i); + $found = $terms->item($i); } } - + 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) { $terms->item($i)->removeAttribute('default'); } @@ -547,8 +545,7 @@ class CollectionPolicy extends XMLDatastream { } return $ret; } - - + /** * 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 @@ -559,17 +556,17 @@ class CollectionPolicy extends XMLDatastream { * @return boolean $valid */ function removeModel($cm) { - $ret=FALSE; + $ret = FALSE; if ($this->validate() && $cm->validate()) { $contentmodelsEl = $this->xml->getElementsByTagName('content_models'); $models = $contentmodelsEl->item(0)->getElementsByTagName('content_model'); $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) { - $found=$models->item($i); + $found = $models->item($i); } - } - + } + if ($found !== FALSE && $models->length > 1) { $contentmodelsEl->item(0)->removeChild($found); $ret = TRUE; @@ -577,21 +574,24 @@ class CollectionPolicy extends XMLDatastream { } return $ret; } - - - + /** + * addModel ?? + * @param type $cm + * @param type $namespace + * @return type + */ function addModel($cm, $namespace) { $ret = FALSE; if (self::validPid($namespace) && $this->validate() && $cm->validate()) { $contentmodelsEl = $this->xml->getElementsByTagName('content_models'); $models = $contentmodelsEl->item(0)->getElementsByTagName('content_model'); $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) $found = TRUE; } - + if (!$found) { $cmEl = $this->xml->createElement('content_model'); $cmEl->setAttribute('name', $cm->getName()); @@ -600,16 +600,20 @@ class CollectionPolicy extends XMLDatastream { $cmEl->setAttribute('pid', $cm->pid); $contentmodelsEl->item(0)->appendChild($cmEl); } - + $ret = !$found; } return $ret; } - + + /** + * getName ?? + * @return type + */ function getName() { - $ret=FALSE; + $ret = FALSE; 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; } diff --git a/ConnectionHelper.inc b/ConnectionHelper.inc index 68ed4124..344fb6a9 100644 --- a/ConnectionHelper.inc +++ b/ConnectionHelper.inc @@ -1,57 +1,76 @@ $url))); return NULL; } - + return $new_url; } + /** + * getSoapClient + * @global type $user + * @param type $url + * @param type $exceptions + * @return SoapClient + */ function getSoapClient($url = NULL, $exceptions = TRUE) { 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; if ($user->uid == 0) { //anonymous user. We will need an entry in the fedora users.xml file //with the appropriate entry for a username of anonymous password of anonymous try { $client = new SoapClient($this->_fixURL($url, 'anonymous', 'anonymous'), array( - 'login' => 'anonymous', - 'password' => 'anonymous', - 'exceptions' => $exceptions, - )); - } - catch (SoapFault $e) { + 'login' => 'anonymous', + 'password' => 'anonymous', + 'exceptions' => $exceptions, + )); + } catch (SoapFault $e) { drupal_set_message(t("!e", array('!e' => $e->getMessage()))); return NULL; } @@ -59,17 +78,17 @@ class ConnectionHelper { else { try { $client = new SoapClient($this->_fixURL($url, $user->name, $user->pass), array( - 'login' => $user->name, - 'password' => $user->pass, - 'exceptions' => TRUE, - )); - } - catch (SoapFault $e) { + 'login' => $user->name, + 'password' => $user->pass, + 'exceptions' => TRUE, + )); + } catch (SoapFault $e) { drupal_set_message(t("!e", array('!e' => $e->getMessage()))); return NULL; } } return $client; } + } diff --git a/ContentModel.inc b/ContentModel.inc index 4ed21c3d..d0c07bbb 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -2,12 +2,19 @@ // $Id$ +/** + * @file + * Content Model Class + */ module_load_include('inc', 'fedora_repository', 'XMLDatastream'); +/** + * Conent Model ?? + */ class ContentModel extends XMLDatastream { + static $SCHEMA_URI = 'http://localhost/islandoracm.xsd'; static $DEFAULT_DSID = 'ISLANDORACM'; - private $mimes = NULL; public $pid_namespace; public $name; @@ -33,7 +40,7 @@ class ContentModel extends XMLDatastream { $ret = FALSE; if (self::validPid($pid)) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $objectHelper=new ObjectHelper(); + $objectHelper = new ObjectHelper(); $content_models = $objectHelper->get_content_models_list($pid); foreach ($content_models as $content_model) { @@ -58,21 +65,20 @@ class ContentModel extends XMLDatastream { */ public static function ingestFromFile($pid, $name, $modelDsid, $file) { $ret = FALSE; - + if (($cm = self::loadFromModel($pid, $modelDsid)) === FALSE && file_exists($file)) { $cm = new ContentModel(file_get_contents($file), $pid, $modelDsid); $rootEl = $cm->xml->getElementsByTagName('content_model')->item(0); $rootEl->setAttribute('name', $name); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $fedoraItem = new Fedora_Item($pid); $fedoraItem->add_datastream_from_string($cm->dumpXml(), $modelDsid, $name, 'text/xml', 'X'); - $ret= $cm; - } + $ret = $cm; + } return $ret; } - /** * Ingests a Content Model from an existing model to the specified pid/dsid . @@ -86,24 +92,23 @@ class ContentModel extends XMLDatastream { */ public static function ingestFromModel($pid, $name, $modelDsid, $copy_model_pid) { $ret = FALSE; - + if (($cm = self::loadFromModel($pid, $modelDsid)) === FALSE && ($copy_cm = self::loadFromModel($copy_model_pid)) !== FALSE && $copy_cm->validate()) { $newDom = $copy_cm->xml; $rootEl = $newDom->getElementsByTagName('content_model')->item(0); $rootEl->setAttribute('name', $name); - + $cm = new ContentModel($newDom, $pid, $modelDsid); - + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $fedoraItem = new Fedora_Item($pid); $fedoraItem->add_datastream_from_string($cm->dumpXml(), $modelDsid, $name, 'text/xml', 'X'); $ret = $cm; -} + } - return $ret; + return $ret; } - - + /** * Ingests a minimum Content Model to the specified pid/dsid. * Returns false on failure. @@ -123,9 +128,9 @@ class ContentModel extends XMLDatastream { * @param string $ingestFormHandler * * @return ContentModel $cm - */ + */ public static function ingestBlankModel($pid, $name, $modelDsid, $defaultMimetype, $ingestFormDsid, $ingestFormPage, $ingestFormHideChooser, $ingestFormModule, $ingestFormModule, $ingestFormFile, $ingestFormClass, $ingestFormMethod, $ingestFormHandler) { - $ret = FALSE; + $ret = FALSE; if (($cm = self::loadFromModel($pid, $modelDsid)) === FALSE) { $newDom = new DOMDocument('1.0', 'utf-8'); $newDom->formatOutput = TRUE; @@ -133,48 +138,47 @@ class ContentModel extends XMLDatastream { $rootEl->setAttribute('name', $name); $rootEl->setAttribute('xmlns', self::$XMLNS); $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); + $mimeEl = $newDom->createElement('mimetypes'); - $typeEl=$newDom->createElement('type', $defaultMimetype); - $mimeEl->appendChild($typeEl); + $typeEl = $newDom->createElement('type', $defaultMimetype); + $mimeEl->appendChild($typeEl); $rootEl->appendChild($mimeEl); - + $ingestRulesEl = $newDom->createElement('ingest_rules'); $rootEl->appendChild($ingestRulesEl); - + $ingestFormEl = $newDom->createElement('ingest_form'); $ingestFormEl->setAttribute('dsid', $ingestFormDsid); $ingestFormEl->setAttribute('page', $ingestFormPage); if ($ingestFormHideChooser == 'true') { $ingestFormEl->setAttribute('hide_file_chooser', 'true'); } - - $builderEl= $newDom->createElement('form_builder_method'); + + $builderEl = $newDom->createElement('form_builder_method'); $builderEl->setAttribute('module', $ingestFormModule); $builderEl->setAttribute('file', $ingestFormFile); $builderEl->setAttribute('class', $ingestFormClass); $builderEl->setAttribute('method', $ingestFormMethod); $builderEl->setAttribute('handler', $ingestFormHandler); - $ingestFormEl->appendChild($builderEl); - + $ingestFormEl->appendChild($builderEl); + $elementsEl = $newDom->createElement('form_elements'); $ingestFormEl->appendChild($elementsEl); $rootEl->appendChild($ingestFormEl); $newDom->appendChild($rootEl); - + $cm = new ContentModel($newDom, $pid, $modelDsid); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $fedoraItem = new Fedora_Item($pid); - $fedoraItem->add_datastream_from_string($cm->dumpXml(), $modelDsid, $name, 'text/xml', 'X'); - $ret = $cm; + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $fedoraItem = new Fedora_Item($pid); + $fedoraItem->add_datastream_from_string($cm->dumpXml(), $modelDsid, $name, 'text/xml', 'X'); + $ret = $cm; } - + return $ret; } - - + /** * Constructs a ContentModel object from the PID of the model in Fedora. * If DSID is specified it will use that datastream as the model, otherwise it will @@ -200,11 +204,10 @@ class ContentModel extends XMLDatastream { $dsid = ($dsid != NULL && self::validDsid($dsid)) ? $dsid : ContentModel::getDefaultDSID(); $ds = $fedoraItem->get_datastream_dissemination($dsid); if (!empty($ds)) { - $ret=new ContentModel($ds, $pid, $dsid, $pid_namespace, $name); + $ret = new ContentModel($ds, $pid, $dsid, $pid_namespace, $name); } } - } - catch (SOAPException $e) { + } catch (SOAPException $e) { $ret = FALSE; } return $ret; @@ -224,7 +227,7 @@ class ContentModel extends XMLDatastream { public function __construct($xmlStr, $pid = NULL, $dsid = NULL, $pid_namespace = NULL, $name = NULL) { parent::__construct($xmlStr, $pid, $dsid); $this->pid_namespace = $pid_namespace; - $this->name = ($name == NULL)?'Islandora Content Model':$name; + $this->name = ($name == NULL) ? 'Islandora Content Model' : $name; $this->xpath = new DOMXPath($this->xml); $this->xpath->registerNamespace('cm', 'http://www.islandora.ca'); } @@ -244,7 +247,7 @@ class ContentModel extends XMLDatastream { $rootEl->setAttribute('name', $sXml['name']); $rootEl->setAttribute('xmlns', self::$XMLNS); $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); $mimeEl = $newDom->createElement('mimetypes'); foreach ($sXml->mimetypes->type as $mime) { @@ -270,7 +273,7 @@ class ContentModel extends XMLDatastream { $methodEl->setAttribute('method', $method->method_name); $methodEl->setAttribute('dsid', $method->datastream_id); $methodEl->setAttribute('modified_files_ext', $method->modified_files_ext); - + if (isset($method->parameters)) { $paramsEl = $newDom->createElement('parameters'); foreach ($method->parameters->parameter as $param) { @@ -280,14 +283,13 @@ class ContentModel extends XMLDatastream { } $methodEl->appendChild($paramsEl); } - - + + $methodsEl->appendChild($methodEl); } $ruleEl->appendChild($methodsEl); $ingestRulesEl->appendChild($ruleEl); } - } $rootEl->appendChild($ingestRulesEl); @@ -306,7 +308,7 @@ class ContentModel extends XMLDatastream { $add_ds_methodEl->setAttribute('method', $ds->add_datastream_method->method_name); $add_ds_methodEl->setAttribute('dsid', $ds->add_datastream_method->datastream_id); $add_ds_methodEl->setAttribute('modified_files_ext', $ds->add_datastream_method->modified_files_ext); - + if (isset($ds->add_datastream_method->parameters)) { $paramsEl = $newDom->createElement('parameters'); foreach ($ds->add_datastream_method->parameters->parameter as $param) { @@ -316,7 +318,7 @@ class ContentModel extends XMLDatastream { } $add_ds_methodEl->appendChild($paramsEl); } - + $dsEl->appendChild($add_ds_methodEl); } @@ -354,12 +356,12 @@ class ContentModel extends XMLDatastream { //I found an XML where the label was HTML.. this code will attempt to //walk the object setting the label to be the first string it finds. if (count(get_object_vars($element->label)) > 0) { - $obj=$element->label; + $obj = $element->label; while ($obj != NULL && !is_string($obj)) { $keys = get_object_vars($obj); $obj = array_shift($keys); } - $element->label=($obj == NULL) ? '' : $obj; + $element->label = ($obj == NULL) ? '' : $obj; } $elEl = $newDom->createElement('element'); @@ -390,15 +392,15 @@ class ContentModel extends XMLDatastream { $ingest_formEl->appendChild($form_elementsEl); $rootEl->appendChild($ingest_formEl); - if (isset($sXml->edit_metadata) && - trim($sXml->edit_metadata->build_form_method->module) != '' && - trim($sXml->edit_metadata->build_form_method->file) != '' && - trim($sXml->edit_metadata->build_form_method->class_name) != '' && - trim($sXml->edit_metadata->build_form_method->method_name) != '' && - trim($sXml->edit_metadata->submit_form_method->method_name) != '' && - trim($sXml->edit_metadata->build_form_method['dsid']) != '' - ) { - $edit_metadata_methodEl= $newDom->createElement('edit_metadata_method'); + if (isset($sXml->edit_metadata) && + trim($sXml->edit_metadata->build_form_method->module) != '' && + trim($sXml->edit_metadata->build_form_method->file) != '' && + trim($sXml->edit_metadata->build_form_method->class_name) != '' && + trim($sXml->edit_metadata->build_form_method->method_name) != '' && + trim($sXml->edit_metadata->submit_form_method->method_name) != '' && + trim($sXml->edit_metadata->build_form_method['dsid']) != '' + ) { + $edit_metadata_methodEl = $newDom->createElement('edit_metadata_method'); $edit_metadata_methodEl->setAttribute('module', $sXml->edit_metadata->build_form_method->module); $edit_metadata_methodEl->setAttribute('file', $sXml->edit_metadata->build_form_method->file); $edit_metadata_methodEl->setAttribute('class', $sXml->edit_metadata->build_form_method->class_name); @@ -411,39 +413,38 @@ class ContentModel extends XMLDatastream { $newDom->appendChild($rootEl); $this->xml = DOMDocument::loadXML($newDom->saveXml()); - } /** - * Gets a list of service deployments that this model has. - * - * NOTE: Not currently being used. - * - * @return String[] $serviceDepPids - */ + * Gets a list of service deployments that this model has. + * + * NOTE: Not currently being used. + * + * @return String[] $serviceDepPids + */ public function getServices() { - $query = 'select $object $title from <#ri> + $query = 'select $object $title from <#ri> where ($object $title and $object $deploymentOf and $object - and $object pid .'> + and $object pid . '> and $object ) order by $title'; - - module_load_include('inc', 'fedora_repository', 'CollectionClass'); - - $collectionHelper = new CollectionClass(); - $xml = simplexml_load_string($collectionHelper->getRelatedItems($this->pid, $query)); - - $results = array(); - foreach ($xml->results->result as $result) { - $pid = strval(($result->object['uri'])); - $pid = substr($pid, strpos($pid, "/") + 1, strlen($pid)); - $results[] = $pid; - } - - return $results; - } + + module_load_include('inc', 'fedora_repository', 'CollectionClass'); + + $collectionHelper = new CollectionClass(); + $xml = simplexml_load_string($collectionHelper->getRelatedItems($this->pid, $query)); + + $results = array(); + foreach ($xml->results->result as $result) { + $pid = strval(($result->object['uri'])); + $pid = substr($pid, strpos($pid, "/") + 1, strlen($pid)); + $results[] = $pid; + } + + return $results; + } /** * Gets the name of the ContentModel @@ -455,7 +456,7 @@ class ContentModel extends XMLDatastream { $ret = FALSE; if ($this->name != NULL) { $ret = $this->name; - } + } elseif ($this->validate()) { $rootEl = $this->xml->getElementsByTagName('content_model')->item(0); $this->name = $rootEl->getAttribute('name'); @@ -464,7 +465,6 @@ class ContentModel extends XMLDatastream { return $ret; } - /** * Gets the element corresponding to the datastream specified * in the element of the schema. @@ -476,12 +476,12 @@ class ContentModel extends XMLDatastream { private function getDSModel($dsid) { $ret = FALSE; if (self::validDsid($dsid) && $this->validate()) { - $result=$this->xml->getElementsByTagName('datastreams'); - if ($result->length > 0) { - $result=$result->item(0)->getElementsByTagName('datastream'); + $result = $this->xml->getElementsByTagName('datastreams'); + if ($result->length > 0) { + $result = $result->item(0)->getElementsByTagName('datastream'); for ($i = 0; $ret == FALSE && $i < $result->length; $i++) { if ($result->item($i)->getAttribute('dsid') == $dsid) - $ret=$result->item($i); + $ret = $result->item($i); } } } @@ -501,59 +501,59 @@ class ContentModel extends XMLDatastream { if ($this->validate()) { $elements_array = array(); $form_elements_wrapper = $this->xml->getElementsbyTagName('ingest_form')->item(0)->getElementsByTagName('form_elements'); - + if ($form_elements_wrapper->length == 0) { return $ret; } $elements = $this->xml->getElementsbyTagName('ingest_form')->item(0)->getElementsByTagName('form_elements')->item(0)->getElementsByTagName('element'); - for ($i=0;$i<$elements->length;$i++) { + for ($i = 0; $i < $elements->length; $i++) { $desc = $elements->item($i)->getElementsByTagName('description'); - $desc = ($desc->length > 0)?$desc->item(0)->nodeValue:''; - + $desc = ($desc->length > 0) ? $desc->item(0)->nodeValue : ''; + $label = $elements->item($i)->getAttribute('label'); if ($label == NULL) { - $label=$elements->item($i)->getAttribute('name'); + $label = $elements->item($i)->getAttribute('name'); } - - $element=array('name' => $elements->item($i)->getAttribute('name'), - 'label' => $label, - 'type' => $elements->item($i)->getAttribute('type'), - 'required' => ($elements->item($i)->getAttribute('required') == 'true') ? TRUE : FALSE, - 'description' => $desc + + $element = array('name' => $elements->item($i)->getAttribute('name'), + 'label' => $label, + 'type' => $elements->item($i)->getAttribute('type'), + 'required' => ($elements->item($i)->getAttribute('required') == 'true') ? TRUE : FALSE, + 'description' => $desc ); - + $auth_list = $elements->item($i)->getElementsByTagName('authoritative_list'); if ($auth_list->length > 0) { $list = array(); $items = $auth_list->item(0)->getElementsByTagName('item'); for ($j = 0; $j < $items->length; $j++) { $field = $items->item($j)->attributes->getNamedItem('field'); - $list[ $items->item($j)->nodeValue ] = ($field !== NULL) ? $field->nodeValue : $items->item($j)->nodeValue; + $list[$items->item($j)->nodeValue] = ($field !== NULL) ? $field->nodeValue : $items->item($j)->nodeValue; } - $element['authoritative_list']=$list; + $element['authoritative_list'] = $list; } - + $params = $elements->item($i)->getElementsByTagName('parameters'); $list = array(); if ($params->length > 0) { $items = $params->item(0)->getElementsByTagName('parameter'); for ($j = 0; $j < $items->length; $j++) { - $value = $items-> item($j)->nodeValue; + $value = $items->item($j)->nodeValue; $list[$items->item($j)->getAttribute('name')] = (strtolower($value) == 'true' ? TRUE : (strtolower($value) == 'false' ? FALSE : $value)); } } $element['parameters'] = $list; - + $elements_array[] = $element; - } + } $ret = $elements_array; } - return $ret; + return $ret; } - /** + /** * Decrements an ingest form element in the list of elements. * Updates the "order". This method is simply an overload to the incIngestFormElement * which has a direction parameter. @@ -563,12 +563,12 @@ class ContentModel extends XMLDatastream { * * @param String $name * @return boolean $success - */ + */ public function decIngestFormElement($name) { return $this->incIngestFormElement($name, 'dec'); } - - /** + + /** * Increments (or decrements) ingest form element in the list of elements. * Updates the "order". The $reorder parameter accepts 'inc' or 'dec' to * specify the direction to move (defaults to increment.) @@ -579,7 +579,7 @@ class ContentModel extends XMLDatastream { * @param String $name * @param String $reorder * @return boolean $success - */ + */ public function incIngestFormElement($name, $reorder = 'inc') { $ret = FALSE; if ($this->validate()) { @@ -590,26 +590,26 @@ class ContentModel extends XMLDatastream { for ($i = 0; $found === FALSE && $i < $elements->length; $i++) { if ($elements->item($i)->getAttribute('name') == trim($name)) { if ($reorder == 'inc') { - $found=$elements->item($i); - $refEl = ($i > 0)?$elements->item($i-1):false; - } + $found = $elements->item($i); + $refEl = ($i > 0) ? $elements->item($i - 1) : false; + } else { $found = ($i + 1 < $elements->length) ? $elements->item($i + 1) : FALSE; $refEl = $elements->item($i); } } } - + if ($found !== FALSE) { $elementsEl->removeChild($found); $elementsEl->insertBefore($found, $refEl); $ret = TRUE; } - } + } return $ret; - } - - /** + } + + /** * Removes an ingest form element from the list of ingest form elements. * @param String $name * @return boolean $success @@ -622,18 +622,18 @@ class ContentModel extends XMLDatastream { $found = FALSE; for ($i = 0; $found === FALSE && $i < $elements->length; $i++) { if ($elements->item($i)->getAttribute('name') == trim($name)) { - $found=$elements->item($i); + $found = $elements->item($i); } } - + if ($found !== FALSE) { $elementsEl->removeChild($found); $ret = TRUE; } - } + } return $ret; } - + /** * Sets a parameter of an ingest form element. If the value of the element is FALSE the parameter * will be removed entirely (if you want to store false as a value, then send the String "false"). @@ -646,7 +646,7 @@ class ContentModel extends XMLDatastream { public function setIngestFormElementParam($name, $paramName, $paramValue) { $ret = FALSE; - if ($this->validate()) { + if ($this->validate()) { $elements = $this->xml->getElementsbyTagName('ingest_form')->item(0)->getElementsByTagName('form_elements')->item(0)->getElementsByTagName('element'); $element = FALSE; for ($i = 0; $element === FALSE && $i < $elements->length; $i++) { @@ -661,24 +661,24 @@ class ContentModel extends XMLDatastream { if ($paramValue !== FALSE) { $paramsEl = $this->xml->createElement('parameters'); $element->appendChild($paramsEl); - } + } else { $ret = TRUE; } - } + } else { - $paramsEl=$paramsEl->item(0); + $paramsEl = $paramsEl->item(0); } - + if (!$ret) { $params = $paramsEl->getElementsByTagName('parameter'); $found = FALSE; for ($i = 0; $found === FALSE && $i < $params->length; $i++) { if ($params->item($i)->getAttribute('name') == $paramName) { - $found=$params->item($i); + $found = $params->item($i); } } - + if ($paramValue === FALSE) { if ($found !== FALSE) { $paramsEl->removeChild($found); @@ -687,27 +687,26 @@ class ContentModel extends XMLDatastream { } } $ret = TRUE; - } + } else { if ($found !== FALSE) { $found->nodeValue = $paramValue; - } + } else { - $paramEl=$this->xml->createElement('parameter', $paramValue); + $paramEl = $this->xml->createElement('parameter', $paramValue); $paramEl->setAttribute('name', $paramName); $paramsEl->appendChild($paramEl); } $ret = TRUE; } } - } + } } return $ret; } - - -/** + + /** * Gets a list of all parameters that belong to the specified ingest form element. * * @param String $elementName @@ -719,7 +718,7 @@ class ContentModel extends XMLDatastream { if ($this->validate()) { $elements = $this->xml->getElementsbyTagName('ingest_form')->item(0)->getElementsByTagName('form_elements')->item(0)->getElementsByTagName('element'); $element = FALSE; - for ($i=0; $element === FALSE && $i < $elements->length; $i++) { + for ($i = 0; $element === FALSE && $i < $elements->length; $i++) { if ($elements->item($i)->getAttribute('name') == $name) { $element = $elements->item($i); } @@ -727,20 +726,20 @@ class ContentModel extends XMLDatastream { if ($element !== FALSE) { $ret = array(); - $paramsEl = $element->getElementsByTagName('parameters'); - + $paramsEl = $element->getElementsByTagName('parameters'); + if ($paramsEl->length > 0) { - $params = $paramsEl->item(0)->getElementsByTagName('parameter'); - for ($i = 0; $i < $params->length; $i++) { - $ret[$params->item($i)->getAttribute('name')]=$params->item($i)->nodeValue; - } - } - } + $params = $paramsEl->item(0)->getElementsByTagName('parameter'); + for ($i = 0; $i < $params->length; $i++) { + $ret[$params->item($i)->getAttribute('name')] = $params->item($i)->nodeValue; + } + } + } } return $ret; - } - + } + /** * Edits the ingest form element specified. * NOTE: The element name can not be changed. To update an elements name @@ -763,45 +762,44 @@ class ContentModel extends XMLDatastream { $found = $elements->item($i); } } - + $found->setAttribute('name', $name); $found->setAttribute('type', $type); $found->setAttribute('required', $required ? 'true' : 'false'); if (trim($label) != '' && trim($label) != trim($name)) { $found->setAttribute('label', $label); - } + } elseif ($found->getAttribute('label') != '') { $found->removeAttribute('label'); } - - $descEl=$found->getElementsByTagName('description'); + + $descEl = $found->getElementsByTagName('description'); if (trim($description) != '') { - if ($descEl->length > 0) { - $descEl=$descEl->item(0); - $descEl->nodeValue = $description; - } + if ($descEl->length > 0) { + $descEl = $descEl->item(0); + $descEl->nodeValue = $description; + } else { - $descEl = $this->xml->createElement('description', $description); - $found->appendChild($descEl); - } - } + $descEl = $this->xml->createElement('description', $description); + $found->appendChild($descEl); + } + } elseif ($descEl->length > 0) { - $found->removeChild($descEl->item(0)); + $found->removeChild($descEl->item(0)); } - - if ($found->getAttribute('type') != 'select' && $found->getAttribute('type') != 'radio') { + + if ($found->getAttribute('type') != 'select' && $found->getAttribute('type') != 'radio') { $authList = $found->getElementsByTagName('authoritative_list'); if ($authList->length > 0) { $found->removeChild($authList->item(0)); } } - + $ret = TRUE; } return $ret; } - - + /** * Add an ingest form element to the model. * @@ -822,19 +820,19 @@ class ContentModel extends XMLDatastream { $elementEl->setAttribute('required', $requiredi ? 'true' : 'false'); if (trim($label) != '' && trim($label) != trim($name)) { $elementEl->setAttribute('label', $label); - } + } if (trim($description) != '') { - $descEl=$this->xml->createElement('description', $description); - $elementEl->appendChild($descEl); + $descEl = $this->xml->createElement('description', $description); + $elementEl->appendChild($descEl); } $elements->appendChild($elementEl); - + $ret = TRUE; } return $ret; } - - /** + + /** * Decrements an authority list item from a form element in the list of elements. * Updates the "order". This method is simply an overload to the incAuthListItem * which has a direction parameter. @@ -843,12 +841,12 @@ class ContentModel extends XMLDatastream { * @param String $elementName * @param String $value * @return boolean $success - */ + */ public function decAuthListItem($elementName, $value) { return $this->incAuthListItem($elementName, $value, 'dec'); - } + } - /** + /** * Increments (or decrements) an authority list item from a form element in the list of elements. * Updates the "order". * @@ -856,7 +854,7 @@ class ContentModel extends XMLDatastream { * @param String $value * @param String $direction * @return boolean $success - */ + */ public function incAuthListItem($elementName, $value, $reorder = 'inc') { $ret = FALSE; if ($this->validate()) { @@ -869,43 +867,43 @@ class ContentModel extends XMLDatastream { } if ($found !== FALSE) { - - $authListEl = $found->getElementsByTagName('authoritative_list'); - if ($authListEl->length > 0) { - $authListEl = $authListEl->item(0); - - $items = $authListEl->getElementsByTagName('item'); - $found = FALSE; - $refEl = FALSE; - for ($i = 0; $found === FALSE && $i < $items->length; $i++) { - if ($items->item($i)->nodeValue == $value) { - if ($reorder == 'inc') { - $refEl = ($i > 0) ? $items->item($i - 1) : FALSE; - $found = $items->item($i); - } - else { - $refEl = $items->item($i); - $found = ($i + 1 < $items->length) ? $items->item($i + 1) : FALSE; - } - } - } - - if ($found !== FALSE && $refEl !== FALSE) { - $authListEl->removeChild($found); - $authListEl->insertBefore($found, $refEl); - $ret = TRUE; - } - } + + $authListEl = $found->getElementsByTagName('authoritative_list'); + if ($authListEl->length > 0) { + $authListEl = $authListEl->item(0); + + $items = $authListEl->getElementsByTagName('item'); + $found = FALSE; + $refEl = FALSE; + for ($i = 0; $found === FALSE && $i < $items->length; $i++) { + if ($items->item($i)->nodeValue == $value) { + if ($reorder == 'inc') { + $refEl = ($i > 0) ? $items->item($i - 1) : FALSE; + $found = $items->item($i); + } + else { + $refEl = $items->item($i); + $found = ($i + 1 < $items->length) ? $items->item($i + 1) : FALSE; + } + } + } + + if ($found !== FALSE && $refEl !== FALSE) { + $authListEl->removeChild($found); + $authListEl->insertBefore($found, $refEl); + $ret = TRUE; + } + } } } return $ret; - } + } /** * Removes an authority list item from a form element. - @param String $elementName - @param String $value - @return boolean $success + * @param String $elementName + * @param String $value + * @return boolean $success */ public function removeAuthListItem($elementName, $value) { $ret = FALSE; @@ -913,46 +911,46 @@ class ContentModel extends XMLDatastream { $elements = $this->xml->getElementsbyTagName('ingest_form')->item(0)->getElementsByTagName('form_elements')->item(0)->getElementsByTagName('element'); $found = FALSE; for ($i = 0; $found === FALSE && $i < $elements->length; $i++) { - if ($elements->item($i)->getAttribute('name') == $elementName) { - $found = $elements->item($i); - } + if ($elements->item($i)->getAttribute('name') == $elementName) { + $found = $elements->item($i); + } } if ($found !== FALSE) { - $authListEl = $found->getElementsByTagName('authoritative_list'); - if ($authListEl->length > 0) { - $authListEl = $authListEl->item(0); - $items = $authListEl->getElementsByTagName('item'); - $found = FALSE; - for ($i = 0; $found === FALSE && $i < $items->length; $i++) { - if ($items->item($i)->nodeValue == $value) { - $found=$items->item($i); - } - } - - if ($found !== FALSE) { - if ($items->length == 1) { - $found->removeChild($authListEl); - } - else { - $authListEl->removeChild($found); - } - - $ret = TRUE; - } - } + $authListEl = $found->getElementsByTagName('authoritative_list'); + if ($authListEl->length > 0) { + $authListEl = $authListEl->item(0); + $items = $authListEl->getElementsByTagName('item'); + $found = FALSE; + for ($i = 0; $found === FALSE && $i < $items->length; $i++) { + if ($items->item($i)->nodeValue == $value) { + $found = $items->item($i); + } + } + + if ($found !== FALSE) { + if ($items->length == 1) { + $found->removeChild($authListEl); + } + else { + $authListEl->removeChild($found); + } + + $ret = TRUE; + } + } } } return $ret; - } + } /** * Adds an authority list item to a form element. - @param String $elementName - @param String $value - @param String $label (optional) - @return boolean $success - */ + * @param String $elementName + * @param String $value + * @param String $label (optional) + * @return boolean $success + */ public function addAuthListItem($elementName, $value, $label = '') { $ret = FALSE; if ($this->validate()) { @@ -965,37 +963,36 @@ class ContentModel extends XMLDatastream { } if ($found !== FALSE) { - $authListEl = $found->getElementsByTagName('authoritative_list'); - if ($authListEl->length == 0) { - $authListEl = $this->xml->createElement('authoritative_list'); - $found->appendChild($authListEl); - } - else { - $authListEl = $authListEl->item(0); - } - - $items = $authListEl->getElementsByTagName('item'); - $found = FALSE; - for ($i = 0; $found == FALSE && $i < $items->length; $i++) { - if ($items->item($i)->nodeValue == $value) { - $found = TRUE; - } - } - - if (!$found) { - $itemEl = $this->xml->createElement('item', trim($value)); - if (trim($label) != '' && trim($label) != trim($value)) { - $itemEl->setAttribute('field', trim($label)); - } - $authListEl->appendChild($itemEl); - $ret = TRUE; - } - } - + $authListEl = $found->getElementsByTagName('authoritative_list'); + if ($authListEl->length == 0) { + $authListEl = $this->xml->createElement('authoritative_list'); + $found->appendChild($authListEl); + } + else { + $authListEl = $authListEl->item(0); + } + + $items = $authListEl->getElementsByTagName('item'); + $found = FALSE; + for ($i = 0; $found == FALSE && $i < $items->length; $i++) { + if ($items->item($i)->nodeValue == $value) { + $found = TRUE; + } + } + + if (!$found) { + $itemEl = $this->xml->createElement('item', trim($value)); + if (trim($label) != '' && trim($label) != trim($value)) { + $itemEl->setAttribute('field', trim($label)); + } + $authListEl->appendChild($itemEl); + $ret = TRUE; + } + } } return $ret; } - + /** * Builds an ingest form using the method specified in element of * Returns FALSE on failure. @@ -1009,9 +1006,9 @@ class ContentModel extends XMLDatastream { if ($this->validate()) { $docRoot = $_SERVER['DOCUMENT_ROOT']; $file = (isset($form_state['values']['ingest-file-location']) ? $form_state['values']['ingest-file-location'] : ''); - + $fullpath = $file; - + $form['step'] = array( '#type' => 'hidden', '#value' => (isset($form_state['values']['step']) ? $form_state['values']['step'] : 0) + 1, @@ -1024,7 +1021,7 @@ class ContentModel extends XMLDatastream { '#type' => 'hidden', '#value' => 'ISLANDORACM', ); - $form['models'] = array( //content models available + $form['models'] = array(//content models available '#type' => 'hidden', '#value' => $form_state['values']['models'], ); @@ -1050,27 +1047,27 @@ class ContentModel extends XMLDatastream { } $dsid = $ingest_form->getAttribute('dsid'); - $method=$ingest_form->getElementsByTagName('form_builder_method')->item(0); + $method = $ingest_form->getElementsByTagName('form_builder_method')->item(0); $module = $method->getAttribute('module'); - $path=drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path)) { - self::$errors[]='Build Ingest Form: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Build Ingest Form: file \'' . $path . '\' does not exist.'; + } else { @require_once($path); - $className=$method->getAttribute('class'); - $methodName=($method->getAttribute('method')); + $className = $method->getAttribute('class'); + $methodName = ($method->getAttribute('method')); if (!class_exists($className)) { - self::$errors[] = 'Build Ingest Form: class \''. $className .' does not exist.'; - } + self::$errors[] = 'Build Ingest Form: class \'' . $className . ' does not exist.'; + } else { $class = new $className; - $elements_array=$this->getIngestFormElements(); + $elements_array = $this->getIngestFormElements(); if (method_exists($class, $methodName)) { - $ret = $class->$methodName ($form, $elements_array, $form_state); - } + $ret = $class->$methodName($form, $elements_array, $form_state); + } else { - self::$errors[] = 'Build Ingest Form: method \''. $className .'->'. $methodName .'\' does not exist.'; + self::$errors[] = 'Build Ingest Form: method \'' . $className . '->' . $methodName . '\' does not exist.'; } } } @@ -1080,7 +1077,7 @@ class ContentModel extends XMLDatastream { /** * Builds an edit metadata form using the method specified in the element -= * The DSID specified must match the DSID attribute of . Returns FALSE on failure. + * The DSID specified must match the DSID attribute of . Returns FALSE on failure. * * @param string $dsid * @return $form @@ -1092,22 +1089,22 @@ class ContentModel extends XMLDatastream { if ($method->length > 0 && $method->item(0)->getAttribute('dsid') == $dsid) { $method = $method->item(0); $module = $method->getAttribute('module'); - $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file') ; + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path)) { - self::$errors[] = 'Build Edit Metadata Form: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Build Edit Metadata Form: file \'' . $path . '\' does not exist.'; + } else { @require_once($path ); - $className=$method->getAttribute('class'); - $methodName=($method->getAttribute('method')); + $className = $method->getAttribute('class'); + $methodName = ($method->getAttribute('method')); if (!class_exists($className)) { - self::$errors[] = 'Build Edit Metadata Form: class \''. $className .'\' does not exist.'; - } + self::$errors[] = 'Build Edit Metadata Form: class \'' . $className . '\' does not exist.'; + } else { $class = new $className($pid); if (!method_exists($class, $methodName)) { - self::$errors[] = 'Build Edit Metadata Form: method \''. $className .'->'. $methodName .'\' does not exist.'; - } + self::$errors[] = 'Build Edit Metadata Form: method \'' . $className . '->' . $methodName . '\' does not exist.'; + } else { $ret = $class->$methodName(); } @@ -1133,24 +1130,24 @@ class ContentModel extends XMLDatastream { if ($this->validate()) { $method = $this->xml->getElementsByTagName('edit_metadata_method'); if ($method->length > 0) { - $method=$method->item(0); + $method = $method->item(0); $module = $method->getAttribute('module'); - $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path)) { - self::$errors[] = 'Handle Edit Metadata Form: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Handle Edit Metadata Form: file \'' . $path . '\' does not exist.'; + } else { @require_once($path); $className = $method->getAttribute('class'); $methodName = ($method->getAttribute('handler')); if (!class_exists($className)) { - self::$errors[] = 'Handle Edit Metadata Form: class \''. $className .'\' does not exist.'; - } + self::$errors[] = 'Handle Edit Metadata Form: class \'' . $className . '\' does not exist.'; + } else { $class = new $className($form_state['values']['pid']); if (!method_exists($class, $methodName)) { - self::$errors[] = 'Handle Edit Metadata Form: metho \''. $className .'->'. $methodName .'\' does not exist.'; - } + self::$errors[] = 'Handle Edit Metadata Form: metho \'' . $className . '->' . $methodName . '\' does not exist.'; + } else { $ret = $class->$methodName($form_id, $form_state['values'], $soap_client); } @@ -1164,13 +1161,11 @@ class ContentModel extends XMLDatastream { $ret = $metaDataForm->updateMetaData($form_state['values']['form_id'], $form_state['values'], $soap_client); $form_state['storage'] = NULL; $form_state['redirect'] = $base_url . '/fedora/repository/' . $form_state['values']['pid']; - } } return $ret; } - /** * Gets an associative array describing the edit metadata method. * Array has the following keys: 'file', 'class', 'method', 'handler', 'dsid' @@ -1179,21 +1174,21 @@ class ContentModel extends XMLDatastream { public function getEditMetadataMethod() { $ret = FALSE; if ($this->validate()) { - $method=$this->xml->getElementsByTagName('content_model')->item(0)->getElementsByTagName('edit_metadata_method'); + $method = $this->xml->getElementsByTagName('content_model')->item(0)->getElementsByTagName('edit_metadata_method'); if ($method->length > 0) { $method = $method->item(0); $ret = array('module' => $method->getAttribute('module') == '' ? 'fedora_repository' : $method->getAttribute('module'), - 'file' => $method->getAttribute('file'), - 'class' => $method->getAttribute('class'), - 'method' => $method->getAttribute('method'), - 'handler' => $method->getAttribute('handler'), - 'dsid' => $method->getAttribute('dsid') + 'file' => $method->getAttribute('file'), + 'class' => $method->getAttribute('class'), + 'method' => $method->getAttribute('method'), + 'handler' => $method->getAttribute('handler'), + 'dsid' => $method->getAttribute('dsid') ); } } return $ret; - } - + } + /** * Removes the edit data method from the Content Model. * @return boolean $success @@ -1201,7 +1196,7 @@ class ContentModel extends XMLDatastream { public function removeEditMetadataMethod() { $ret = FALSE; if ($this->validate()) { - $rootEl=$this->xml->getElementsByTagName('content_model')->item(0); + $rootEl = $this->xml->getElementsByTagName('content_model')->item(0); $method = $rootEl->getElementsByTagName('edit_metadata_method'); if ($method->length > 0) { $rootEl->removeChild($method->item(0)); @@ -1210,8 +1205,8 @@ class ContentModel extends XMLDatastream { } return $ret; } - - /** + + /** * Update the Edit Metadata Method defined in the Content Model * @param String $module * @param String $file @@ -1226,8 +1221,8 @@ class ContentModel extends XMLDatastream { if (self::validDsid($dsid) && $this->validate()) { $methodEl = $this->xml->getElementsByTagName('content_model')->item(0)->getElementsByTagName('edit_metadata_method'); if ($methodEl->length > 0) { - $methodEl=$methodEl->item(0); - } + $methodEl = $methodEl->item(0); + } else { $methodEl = $this->xml->createElement('edit_metadata_method'); $this->xml->getElementsByTagName('content_model')->item(0)->appendChild($methodEl); @@ -1242,7 +1237,7 @@ class ContentModel extends XMLDatastream { } return $ret; } - + /** * Executes the add datastream method for the specified datastream on the specified file. * Returns FALSE on failure. @@ -1256,32 +1251,32 @@ class ContentModel extends XMLDatastream { if (self::validDsid($dsid) && $this->validate() && ($ds = $this->getDSModel($dsid)) !== FALSE) { $addMethod = $ds->getElementsByTagName('add_datastream_method'); if ($addMethod->length > 0) { - $addMethod=$addMethod->item(0); + $addMethod = $addMethod->item(0); $paramArray = array(); - $params= $addMethod->getElementsByTagName('parameters'); + $params = $addMethod->getElementsByTagName('parameters'); if ($params->length > 0) { - $params=$params->item(0)->getElementsByTagName('parameter'); + $params = $params->item(0)->getElementsByTagName('parameter'); for ($i = 0; $i < $params->length; $i++) { $paramsArray[$params->item($i)->getAttribute('name')] = $params->item($i)->nodeValue; } } $module = $addMethod->getAttribute('module'); - $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $addMethod->getAttribute('file') ; + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $addMethod->getAttribute('file'); if (!file_exists($path)) { - self::$errors[] = 'Execute Add Datastream Methods: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Execute Add Datastream Methods: file \'' . $path . '\' does not exist.'; + } else { @require_once($path); $className = $addMethod->getAttribute('class'); $methodName = $addMethod->getAttribute('method'); if (!class_exists($className)) { - self::$errors[] = 'Execute Add Datastream Methods: class \''. $className .'\' does not exist.'; - } + self::$errors[] = 'Execute Add Datastream Methods: class \'' . $className . '\' does not exist.'; + } else { $class = new $className; if (!method_exists($class, $methodName)) { - self::$errors[] = 'Execute Add Datastream Methods: method \''. $className .'->'. $methodName .'\' does not exist.'; - } + self::$errors[] = 'Execute Add Datastream Methods: method \'' . $className . '->' . $methodName . '\' does not exist.'; + } else { $ret = $class->$methodName($paramsArray, $addMethod->getAttribute('dsid'), $file, $addMethod->getAttribute('modified_files_ext')); } @@ -1310,11 +1305,11 @@ class ContentModel extends XMLDatastream { $ret = TRUE; $rules = $this->xml->getElementsByTagName('ingest_rules')->item(0)->getElementsByTagName('rule'); for ($i = 0; $i < $rules->length; $i++) { - $rule=$rules->item($i); + $rule = $rules->item($i); $types = $rule->getElementsbyTagName('applies_to'); $valid_types = array(); for ($j = 0; $j < $types->length; $j++) { - $valid_types[]=trim($types->item($j)->nodeValue); + $valid_types[] = trim($types->item($j)->nodeValue); } if (in_array($mimetype, $valid_types)) { @@ -1322,38 +1317,39 @@ class ContentModel extends XMLDatastream { if ($methods->length > 0) { $methods = $methods->item(0)->getElementsbyTagName('ingest_method'); for ($j = 0; $j < $methods->length; $j++) { - $method=$methods->item($j); - $param_array=array(); - $params=$method->getElementsByTagName('parameters'); + $method = $methods->item($j); + $param_array = array(); + $params = $method->getElementsByTagName('parameters'); $param_array['model_pid'] = $this->pid; - if ($params->length > 0) { + if ($params->length > 0) { $params = $params->item(0)->getElementsByTagName('parameter'); for ($k = 0; $k < $params->length; $k++) - $param_array[$params->item($k)->getAttribute('name')]=$params->item($k)->nodeValue; + $param_array[$params->item($k)->getAttribute('name')] = $params->item($k)->nodeValue; } - - + + if (!$preview || isset($param_array['preview'])) { $module = $method->getAttribute('module'); - $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file') ; + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path) || substr_compare($path, 'fedora_repository/', -strlen('fedora_repository/'), strlen('fedora_repository/')) === 0) { - self::$errors[] = 'Execute Ingest Rules: file \''. $path .'\' does not exist.'; + self::$errors[] = 'Execute Ingest Rules: file \'' . $path . '\' does not exist.'; $ret = FALSE; - } + } else { require_once($path); - $className=$method->getAttribute('class'); - $methodName=($method->getAttribute('method')); + $className = $method->getAttribute('class'); + $methodName = ($method->getAttribute('method')); if (!class_exists($className)) { - self::$errors[] = 'Execute Ingest Rules: class \''. $className .'\' does not exist.'; + self::$errors[] = 'Execute Ingest Rules: class \'' . $className . '\' does not exist.'; $ret = FALSE; - } - else $class = new $className; + } + else + $class = new $className; if (!method_exists($class, $methodName)) { - self::$errors[] = 'Execute Ingest Rules: method \''. $className .'->' . $methodName .'\' does not exist.'; + self::$errors[] = 'Execute Ingest Rules: method \'' . $className . '->' . $methodName . '\' does not exist.'; $ret = FALSE; - } + } else { $status = $class->$methodName($param_array, $method->getAttribute('dsid'), $file, $method->getAttribute('modified_files_ext')); if ($status !== TRUE) { @@ -1366,7 +1362,6 @@ class ContentModel extends XMLDatastream { } } } - } return $ret; } @@ -1378,29 +1373,29 @@ class ContentModel extends XMLDatastream { * @param &$form_state * @return boolean $success */ - public function execFormHandler(&$data,&$form_state) { + public function execFormHandler(&$data, &$form_state) { $ret = FALSE; if ($this->validate()) { - $method =$this->xml->getElementsByTagName('ingest_form')->item(0)->getElementsByTagName('form_builder_method')->item(0); + $method = $this->xml->getElementsByTagName('ingest_form')->item(0)->getElementsByTagName('form_builder_method')->item(0); $module = $method->getAttribute('module'); - $path=drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file') ; + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path)) { - self::$errors[] = 'Execute Form Handler: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: file \'' . $path . '\' does not exist.'; + } else { require_once($path); - $className=$method->getAttribute('class'); - $methodName=($method->getAttribute('handler')); + $className = $method->getAttribute('class'); + $methodName = ($method->getAttribute('handler')); if (!class_exists($className)) { - self::$errors[] = 'Execute Form Handler: class \''. $className .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.'; + } else { $class = new $className; if (!method_exists($class, $methodName)) { - self::$errors[] = 'Execute Form Handler: method \''. $className .'->'. $methodName .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.'; + } else { - $class->$methodName($data,$form_state); + $class->$methodName($data, $form_state); $ret = TRUE; } } @@ -1420,13 +1415,13 @@ class ContentModel extends XMLDatastream { //only proceed if the xml is valid. if ($this->validate()) { if ($this->mimes === NULL) { - $result=$this->xml->getElementsByTagName('mimetypes'); - $result=$result->item(0)->getElementsByTagName('type'); + $result = $this->xml->getElementsByTagName('mimetypes'); + $result = $result->item(0)->getElementsByTagName('type'); $mimes = array(); for ($i = 0; $i < $result->length; $i++) { $mimes[] = trim($result->item($i)->nodeValue); } - $this->mimes=$mimes; + $this->mimes = $mimes; } return $this->mimes; } @@ -1446,29 +1441,29 @@ class ContentModel extends XMLDatastream { $datastreams = $this->xml->getElementsByTagName('datastreams'); if ($datastreams->length > 0) { $datastreams = $datastreams->item(0)->getElementsByTagName('datastream'); - for ($i=0; $i < $datastreams->length; $i++) { + for ($i = 0; $i < $datastreams->length; $i++) { $ds = $datastreams->item($i); - if ($ds->attributes->getNamedItem('display_in_fieldset') == NULL || strtolower($ds->getAttribute('display_in_fieldset')) != 'false' ) { + if ($ds->attributes->getNamedItem('display_in_fieldset') == NULL || strtolower($ds->getAttribute('display_in_fieldset')) != 'false') { $dispMethods = $ds->getElementsByTagName('display_method'); for ($j = 0; $j < $dispMethods->length; $j++) { $method = $dispMethods->item($j); $module = $method->getAttribute('module'); - $path=drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file') ; + $path = drupal_get_path('module', !empty($module) ? $module : 'fedora_repository') . '/' . $method->getAttribute('file'); if (!file_exists($path)) { - self::$errors[] = 'Execute Form Handler: file \''. $path .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: file \'' . $path . '\' does not exist.'; + } else { require_once($path); $className = $method->getAttribute('class'); $methodName = ($method->getAttribute('method')); if (!class_exists($className)) { - self::$errors[] = 'Execute Form Handler: class \''. $className .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.'; + } else { $class = new $className($pid); if (!method_exists($class, $methodName)) { - self::$errors[] = 'Execute Form Handler: method \''. $className .'->'. $methodName .'\' does not exist.'; - } + self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.'; + } else { $output = $class->$methodName($page_number); } @@ -1491,17 +1486,17 @@ class ContentModel extends XMLDatastream { * @return string[] $datastreams */ public function listDatastreams() { - $ds_array=array(); + $ds_array = array(); if ($this->validate()) { $datastreams = $this->xml->getElementsByTagName('datastreams'); if ($datastreams->length > 0) { - $datastreams=$datastreams->item(0)->getElementsByTagName('datastream'); - for ($i=0;$i<$datastreams->length;$i++) { - $dsName=$datastreams->item($i)->getAttribute('dsid'); - // if ($dsName != 'QDC') - // { - $ds_array[]=$dsName; - // } + $datastreams = $datastreams->item(0)->getElementsByTagName('datastream'); + for ($i = 0; $i < $datastreams->length; $i++) { + $dsName = $datastreams->item($i)->getAttribute('dsid'); + // if ($dsName != 'QDC') + // { + $ds_array[] = $dsName; + // } } } } @@ -1509,30 +1504,29 @@ class ContentModel extends XMLDatastream { return $ds_array; } - /** + /** * Adds an allowed mimetype to the model. * * @param String $type * @return boolean $success */ public function addMimetype($type) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { $mimetypesEl = $this->xml->getElementsByTagName('mimetypes')->item(0); - $types= $mimetypesEl->getElementsByTagName('type'); + $types = $mimetypesEl->getElementsByTagName('type'); $found = FALSE; - for ($i=0;!$found && $i<$types->length;$i++) { + for ($i = 0; !$found && $i < $types->length; $i++) { if ($types->item($i)->nodeValue == $type) - $found = TRUE; + $found = TRUE; } if (!$found) { $newTypeEl = $this->xml->createElement('type', $type); $mimetypesEl->appendChild($newTypeEl); - $ret=TRUE; + $ret = TRUE; } - } return $ret; } @@ -1544,54 +1538,64 @@ class ContentModel extends XMLDatastream { * @return boolean $success */ public function removeMimetype($type) { - $ret=FALSE; + $ret = FALSE; if ($this->validate()) { $mimetypesEl = $this->xml->getElementsByTagName('mimetypes')->item(0); - $types= $mimetypesEl->getElementsByTagName('type'); - $found=FALSE; - for ($i=0;!$found && $i<$types->length;$i++) { + $types = $mimetypesEl->getElementsByTagName('type'); + $found = FALSE; + for ($i = 0; !$found && $i < $types->length; $i++) { if ($types->item($i)->nodeValue == $type) - $found=$types->item($i); + $found = $types->item($i); } if ($found !== FALSE && $types->length > 1) { $mimetypesEl->removeChild($found); $ret = TRUE; } - } return $ret; } + /** + * getDisplayMethods ?? + * @param type $ds + * @return type + */ public function getDisplayMethods($ds) { - $ret=FALSE; - if (($ds = $this->getDSModel($ds))!==FALSE) { - $ret=array(); - $dispMethods= $ds->getElementsByTagName('display_method'); - for ($i=0;$i<$dispMethods->length;$i++) { - $ret[] = array( 'module' => $dispMethods->item($i)->getAttribute('module')==''?'fedora_repository':$dispMethods->item($i)->getAttribute('module'), - 'file' => $dispMethods->item($i)->getAttribute('file'), - 'class' => $dispMethods->item($i)->getAttribute('class'), - 'method' => $dispMethods->item($i)->getAttribute('method'), - 'default' => ($dispMethods->item($i)->attributes->getNamedItem('default') !== NULL ? strtolower($dispMethods->item($i)->getAttribute('default')) == 'true' : FALSE)); + $ret = FALSE; + if (($ds = $this->getDSModel($ds)) !== FALSE) { + $ret = array(); + $dispMethods = $ds->getElementsByTagName('display_method'); + for ($i = 0; $i < $dispMethods->length; $i++) { + $ret[] = array('module' => $dispMethods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $dispMethods->item($i)->getAttribute('module'), + 'file' => $dispMethods->item($i)->getAttribute('file'), + 'class' => $dispMethods->item($i)->getAttribute('class'), + 'method' => $dispMethods->item($i)->getAttribute('method'), + 'default' => ($dispMethods->item($i)->attributes->getNamedItem('default') !== NULL ? strtolower($dispMethods->item($i)->getAttribute('default')) == 'true' : FALSE)); } } return $ret; } + /** + * addDs ?? + * @param type $dsid + * @param type $display_in_fieldset + * @return boolean + */ public function addDs($dsid, $display_in_fieldset = FALSE) { - $ret=FALSE; - + $ret = FALSE; + if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) === FALSE) { $datastreamsEl = $this->xml->getElementsByTagName('datastreams'); if ($datastreamsEl->length > 0) { - $datastreamsEl=$datastreamsEl->item(0); - } + $datastreamsEl = $datastreamsEl->item(0); + } else { $datastreamsEl = $this->xml->createElement('datastreams'); $this->xml->getElementsByTagName('content_model')->item(0)->appendChild($datastreamsEl); } - + $dsEl = $this->xml->createElement('datastream'); $dsEl->setAttribute('dsid', $dsid); if ($display_in_fieldset == TRUE) { @@ -1603,6 +1607,11 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * removeDs ?? + * @param type $dsid + * @return boolean + */ public function removeDs($dsid) { $ret = FALSE; @@ -1614,6 +1623,11 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * displayInFieldset ?? + * @param type $dsid + * @return type + */ public function displayInFieldset($dsid) { $ret = FALSE; if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) !== FALSE) { @@ -1622,13 +1636,19 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * setDisplayInFieldset ?? + * @param type $dsid + * @param type $value + * @return boolean + */ public function setDisplayInFieldset($dsid, $value = TRUE) { $ret = FALSE; if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) !== FALSE) { if ($value == FALSE && $ds->attributes->getNamedItem('display_in_fieldset') !== NULL) { $ds->removeAttribute('display_in_fieldset'); $ret = TRUE; - } + } elseif ($value == TRUE) { $ds->setAttribute('display_in_fieldset', 'true'); $ret = TRUE; @@ -1637,18 +1657,27 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * setDefaultDispMeth ?? + * @param type $dsid + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @return boolean + */ public function setDefaultDispMeth($dsid, $module, $file, $class, $method) { $ret = FALSE; - + if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) !== FALSE) { $found = FALSE; $dispMethods = $ds->getElementsByTagName('display_method'); for ($i = 0; !$found && $i < $dispMethods->length; $i++) { if ($module == ($dispMethods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $dispMethods->item($i)->getAttribute('module')) && - $file == $dispMethods->item($i)->getAttribute('file') && - $class == $dispMethods->item($i)->getAttribute('class') && - $method == $dispMethods->item($i)->getAttribute('method')) { - $found=$dispMethods->item($i); + $file == $dispMethods->item($i)->getAttribute('file') && + $class == $dispMethods->item($i)->getAttribute('class') && + $method == $dispMethods->item($i)->getAttribute('method')) { + $found = $dispMethods->item($i); } } @@ -1663,22 +1692,30 @@ class ContentModel extends XMLDatastream { $found->setAttribute('default', 'true'); $ret = TRUE; } - } return $ret; } + /** + * removeDispMeth ?? + * @param type $dsid + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @return boolean + */ public function removeDispMeth($dsid, $module, $file, $class, $method) { $ret = FALSE; if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) !== FALSE) { $found = FALSE; - $dispMethods= $ds->getElementsByTagName('display_method'); - for ($i=0;!$found && $i<$dispMethods->length;$i++) { + $dispMethods = $ds->getElementsByTagName('display_method'); + for ($i = 0; !$found && $i < $dispMethods->length; $i++) { if ($module == ($dispMethods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $dispMethods->item($i)->getAttribute('module') == '') && - $file == $dispMethods->item($i)->getAttribute('file') && - $class == $dispMethods->item($i)->getAttribute('class') && - $method == $dispMethods->item($i)->getAttribute('method')) { - $found=$dispMethods->item($i); + $file == $dispMethods->item($i)->getAttribute('file') && + $class == $dispMethods->item($i)->getAttribute('class') && + $method == $dispMethods->item($i)->getAttribute('method')) { + $found = $dispMethods->item($i); } } @@ -1686,20 +1723,29 @@ class ContentModel extends XMLDatastream { $ds->removeChild($found); $ret = TRUE; } - } return $ret; } + /** + * addDispMeth ?? + * @param type $dsid + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $default + * @return boolean + */ public function addDispMeth($dsid, $module, $file, $class, $method, $default = FALSE) { - $ret=FALSE; - if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid))!==FALSE) { + $ret = FALSE; + if (self::validDsid($dsid) && ($ds = $this->getDSModel($dsid)) !== FALSE) { $dispMethEl = $this->xml->createElement('display_method'); $dispMethEl->setAttribute('module', $module); $dispMethEl->setAttribute('file', $file); $dispMethEl->setAttribute('class', $class); $dispMethEl->setAttribute('method', $method); - if ($default==TRUE) { + if ($default == TRUE) { $dispMethEl->setAttribute('default', TRUE); } $ds->appendChild($dispMethEl); @@ -1708,39 +1754,55 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * getAddDsMethod ?? + * @param type $ds + * @return type + */ public function getAddDsMethod($ds) { - $ret=FALSE; - if (($ds = $this->getDSModel($ds))!==FALSE) { - $addDsMethod= $ds->getElementsByTagName('add_datastream_method'); + $ret = FALSE; + if (($ds = $this->getDSModel($ds)) !== FALSE) { + $addDsMethod = $ds->getElementsByTagName('add_datastream_method'); if ($addDsMethod !== FALSE && $addDsMethod->length > 0) { $ret = array('module' => $addDsMethod->item(0)->getAttribute('module') == '' ? 'fedora_repository' : $addDsMethod->item(0)->getAttribute('module'), - 'file' => $addDsMethod->item(0)->getAttribute('file'), - 'class' => $addDsMethod->item(0)->getAttribute('class'), - 'method' => $addDsMethod->item(0)->getAttribute('method'), - 'modified_files_ext' => $addDsMethod->item(0)->getAttribute('modified_files_ext'), - 'dsid' => $addDsMethod->item(0)->getAttribute('dsid') + 'file' => $addDsMethod->item(0)->getAttribute('file'), + 'class' => $addDsMethod->item(0)->getAttribute('class'), + 'method' => $addDsMethod->item(0)->getAttribute('method'), + 'modified_files_ext' => $addDsMethod->item(0)->getAttribute('modified_files_ext'), + 'dsid' => $addDsMethod->item(0)->getAttribute('dsid') ); } } return $ret; } + /** + * getIngestRule ?? + * @param type $rule_id + * @return type + */ public function getIngestRule($rule_id) { $ret = FALSE; if ($this->validate()) { $rules = $this->xml->getElementsByTagName('ingest_rules')->item(0)->getElementsByTagName('rule'); if ($rule_id < $rules->length) - $ret = $rules->item($rule_id); + $ret = $rules->item($rule_id); } return $ret; } + /** + * removeAppliesTo ?? + * @param type $rule_id + * @param type $type + * @return boolean + */ public function removeAppliesTo($rule_id, $type) { $ret = FALSE; if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { $applies = $rule->getElementsByTagName('applies_to'); $found = FALSE; - for ($i=0; $found === FALSE && $i < $applies->length; $i++) { + for ($i = 0; $found === FALSE && $i < $applies->length; $i++) { if ($type == $applies->item($i)->nodeValue) { $found = $applies->item($i); } @@ -1754,12 +1816,18 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * addAppliesTo ?? + * @param type $rule_id + * @param type $type + * @return boolean + */ public function addAppliesTo($rule_id, $type) { - $ret=FALSE; - if (($rule = $this->getIngestRule($rule_id))!==FALSE) { + $ret = FALSE; + if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { $applies = $rule->getElementsByTagName('applies_to'); $found = FALSE; - for ($i=0;!$found && $i<$applies->length;$i++) { + for ($i = 0; !$found && $i < $applies->length; $i++) { $found = ($type == $applies->item($i)->nodeValue); } @@ -1772,9 +1840,20 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * addIngestMethods ?? + * @param type $rule_id + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $dsid + * @param type $modified_files_ext + * @return boolean + */ public function addIngestMethod($rule_id, $module, $file, $class, $method, $dsid, $modified_files_ext) { - $ret=FALSE; - if (self::validDsid($dsid) && ($rule=$this->getIngestRule($rule_id))!==FALSE) { + $ret = FALSE; + if (self::validDsid($dsid) && ($rule = $this->getIngestRule($rule_id)) !== FALSE) { $methodsEl = $rule->getElementsByTagName('ingest_methods')->item(0); $meth = $this->xml->createElement('ingest_method'); $meth->setAttribute('module', $module); @@ -1790,13 +1869,22 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * removeIngestMethod ?? + * @param type $rule_id + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @return boolean + */ public function removeIngestMethod($rule_id, $module, $file, $class, $method) { - $ret=FALSE; - if (($rule=$this->getIngestRule($rule_id))!==FALSE) { - $found=FALSE; + $ret = FALSE; + if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { + $found = FALSE; $methodsEl = $rule->getElementsByTagName('ingest_methods')->item(0); $methods = $methodsEl->getElementsByTagName('ingest_method'); - for ($i=0;!$found && $i<$methods->length;$i++) { + for ($i = 0; !$found && $i < $methods->length; $i++) { if ($methods->item($i)->getAttribute('module') == $module && $methods->item($i)->getAttribute('file') == $file && $methods->item($i)->getAttribute('class') == $class && $methods->item($i)->getAttribute('method') == $method) { $found = $methods->item($i); } @@ -1809,33 +1897,44 @@ class ContentModel extends XMLDatastream { } return $ret; } - + + /** + * addIngestMethodParam ?? + * @param type $rule_id + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $name + * @param type $value + * @return boolean + */ public function addIngestMethodParam($rule_id, $module, $file, $class, $method, $name, $value) { $ret = FALSE; - if (($rule=$this->getIngestRule($rule_id)) !== FALSE) { + if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { $methods = $rule->getElementsByTagName('ingest_methods')->item(0)->getElementsByTagName('ingest_method'); $found = FALSE; for ($i = 0; $found === FALSE && $i < $methods->length; $i++) { if (($methods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $methods->item($i)->getAttribute('module')) == $module && - $methods->item($i)->getAttribute('file') == $file && - $methods->item($i)->getAttribute('class') == $class && - $methods->item($i)->getAttribute('method') == $method) { - $found=$methods->item($i); + $methods->item($i)->getAttribute('file') == $file && + $methods->item($i)->getAttribute('class') == $class && + $methods->item($i)->getAttribute('method') == $method) { + $found = $methods->item($i); } } if ($found !== FALSE) { $paramsEl = $found->getElementsByTagName('parameters'); if ($paramsEl->length == 0) { - $paramsEl=$found->appendChild($this->xml->createElement('parameters')); - } + $paramsEl = $found->appendChild($this->xml->createElement('parameters')); + } else { - $paramsEl=$paramsEl->item(0); + $paramsEl = $paramsEl->item(0); } $params = $paramsEl->getElementsByTagName('parameter'); $found = FALSE; - for ($i=0; $found === FALSE && $i < $params->length; $i++) { + for ($i = 0; $found === FALSE && $i < $params->length; $i++) { if ($params->item($i)->getAttribute('name') == $name) { $found = $params->item($i); } @@ -1852,14 +1951,24 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * removeIngestMethodParam ?? + * @param type $rule_id + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $name + * @return boolean + */ public function removeIngestMethodParam($rule_id, $module, $file, $class, $method, $name) { $ret = FALSE; - if (($rule=$this->getIngestRule($rule_id)) !== FALSE) { + if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { $found = FALSE; $methodsEl = $rule->getElementsByTagName('ingest_methods')->item(0); $methods = $methodsEl->getElementsByTagName('ingest_method'); - for ($i=0; !$found && $i < $methods->length; $i++) { - if (( trim($methods->item($i)->getAttribute('module')) == $module || (trim($methods->item($i)->getAttribute('module')) == '' && $module == 'fedora_repository')) && trim($methods->item($i)->getAttribute('file')) == $file && trim($methods->item($i)->getAttribute('class')) == $class && trim($methods->item($i)->getAttribute('method')) == $method) { + for ($i = 0; !$found && $i < $methods->length; $i++) { + if (( trim($methods->item($i)->getAttribute('module')) == $module || (trim($methods->item($i)->getAttribute('module')) == '' && $module == 'fedora_repository')) && trim($methods->item($i)->getAttribute('file')) == $file && trim($methods->item($i)->getAttribute('class')) == $class && trim($methods->item($i)->getAttribute('method')) == $method) { $found = $methods->item($i); } } @@ -1867,38 +1976,53 @@ class ContentModel extends XMLDatastream { $methodEl = $found; $paramsEl = $found->getElementsByTagName('parameters'); if ($paramsEl->length > 0) { - $paramsEl=$paramsEl->item(0); + $paramsEl = $paramsEl->item(0); $params = $paramsEl->getElementsByTagName('parameter'); $found = FALSE; - for ($i=0; $found === FALSE && $i < $params->length; $i++) { + for ($i = 0; $found === FALSE && $i < $params->length; $i++) { if ($params->item($i)->getAttribute('name') == $name) { - $found=$params->item($i); + $found = $params->item($i); } } - + if ($found !== FALSE) { $paramsEl->removeChild($found); if ($params->length == 0) { $methodEl->removeChild($paramsEl); } - + $ret = TRUE; } } - } } return $ret; } + /** + * removeIngestRule ?? + * @param type $rule_id + * @return type + */ public function removeIngestRule($rule_id) { $ret = FALSE; - if (($rule = $this->getIngestRule($rule_id))!==FALSE) { + if (($rule = $this->getIngestRule($rule_id)) !== FALSE) { $ret = $this->xml->getElementsByTagName('ingest_rules')->item(0)->removeChild($rule); } return $ret; } + /** + * addIngestRule ?? + * @param type $applies_to + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $dsid + * @param type $modified_files_ext + * @return type + */ public function addIngestRule($applies_to, $module, $file, $class, $method, $dsid, $modified_files_ext) { $ret = FALSE; if (self::validDsid($dsid) && $this->validate()) { @@ -1913,39 +2037,42 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * getIngestRules ?? + * @return type + */ public function getIngestRules() { $ret = FALSE; if ($this->validate()) { $ret = array(); $rules = $this->xml->getElementsByTagName('ingest_rules')->item(0)->getElementsByTagName('rule'); - for ($i=0; $i < $rules->length; $i++) { + for ($i = 0; $i < $rules->length; $i++) { $rule = array('applies_to' => array(), 'ingest_methods' => array()); $applies_to = $rules->item($i)->getElementsByTagName('applies_to'); - for ($j=0; $j < $applies_to->length; $j++) { + for ($j = 0; $j < $applies_to->length; $j++) { $rule['applies_to'][] = trim($applies_to->item($j)->nodeValue); } $methods = $rules->item($i)->getElementsByTagName('ingest_methods')->item(0)->getElementsByTagName('ingest_method'); - for ($j=0; $j < $methods->length; $j++) { + for ($j = 0; $j < $methods->length; $j++) { $method = array('module' => $methods->item($j)->getAttribute('module') == '' ? 'fedora_repository' : $methods->item($j)->getAttribute('module'), - 'file' => $methods->item($j)->getAttribute('file'), - 'class' => $methods->item($j)->getAttribute('class'), - 'method' => $methods->item($j)->getAttribute('method'), - 'dsid' => $methods->item($j)->getAttribute('dsid'), - 'modified_files_ext' => $methods->item($j)->getAttribute('modified_files_ext'), - 'parameters' => array()); - + 'file' => $methods->item($j)->getAttribute('file'), + 'class' => $methods->item($j)->getAttribute('class'), + 'method' => $methods->item($j)->getAttribute('method'), + 'dsid' => $methods->item($j)->getAttribute('dsid'), + 'modified_files_ext' => $methods->item($j)->getAttribute('modified_files_ext'), + 'parameters' => array()); + $params = $methods->item($j)->getElementsByTagName('parameters'); if ($params->length > 0) { - $params=$params->item(0)->getElementsByTagName('parameter'); - for ($k=0; $k < $params->length; $k++) { + $params = $params->item(0)->getElementsByTagName('parameter'); + for ($k = 0; $k < $params->length; $k++) { $method['parameters'][$params->item($k)->getAttribute('name')] = $params->item($k)->nodeValue; } } - + $rule['ingest_methods'][] = $method; - } $ret[] = $rule; @@ -1954,55 +2081,79 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * getIngestFormAttributes ?? + * @return type + */ public function getIngestFormAttributes() { $ret = FALSE; if ($this->validate()) { $ingest_formEl = $this->xml->getElementsByTagName('ingest_form')->item(0); - $ret=array('dsid' => $ingest_formEl->getAttribute('dsid'), - 'page' => $ingest_formEl->getAttribute('page'), - 'hide_file_chooser' => strtolower($ingest_formEl->getAttribute('hide_file_chooser')) == 'true', - 'redirect' => strtolower($ingest_formEl->getAttribute('redirect')) == 'false' ? FALSE : TRUE); - + $ret = array('dsid' => $ingest_formEl->getAttribute('dsid'), + 'page' => $ingest_formEl->getAttribute('page'), + 'hide_file_chooser' => strtolower($ingest_formEl->getAttribute('hide_file_chooser')) == 'true', + 'redirect' => strtolower($ingest_formEl->getAttribute('redirect')) == 'false' ? FALSE : TRUE); } return $ret; } - + + /** + * editIngestFormAttributes ?? + * @param type $dsid + * @param type $page + * @param type $hide_file_chooser + * @param type $redirect + * @return boolean + */ public function editIngestFormAttributes($dsid, $page, $hide_file_chooser = FALSE, $redirect = TRUE) { $ret = FALSE; if (self::validDsid($dsid) && $this->validate()) { - $ingest_formEl = $this->xml->getElementsByTagName('ingest_form')->item(0); - $ingest_formEl->setAttribute('dsid', $dsid); - $ingest_formEl->setAttribute('page', $page); - if (!$redirect) { - $ingest_formEl->setAttribute('redirect', 'false'); - } - else { - $ingest_formEl->removeAttribute('redirect'); - } - if ($hide_file_chooser) { + $ingest_formEl = $this->xml->getElementsByTagName('ingest_form')->item(0); + $ingest_formEl->setAttribute('dsid', $dsid); + $ingest_formEl->setAttribute('page', $page); + if (!$redirect) { + $ingest_formEl->setAttribute('redirect', 'false'); + } + else { + $ingest_formEl->removeAttribute('redirect'); + } + if ($hide_file_chooser) { $ingest_formEl->setAttribute('hide_file_chooser', 'true'); - } - else { + } + else { $ingest_formEl->removeAttribute('hide_file_chooser'); - } - $ret = TRUE; + } + $ret = TRUE; } return $ret; } + /** + * getIngestFormBuilderMethod + * @return type + */ public function getIngestFormBuilderMethod() { $ret = FALSE; if ($this->validate()) { $method = $this->xml->getElementsByTagName('ingest_form')->item(0)->getElementsByTagName('form_builder_method')->item(0); - $ret = array( 'module' => ($method->getAttribute('module')==''?'fedora_repository':$method->getAttribute('module')), - 'file' => $method->getAttribute('file'), - 'class' => $method->getAttribute('class'), - 'method' => $method->getAttribute('method'), - 'handler' => $method->getAttribute('handler')); + $ret = array('module' => ($method->getAttribute('module') == '' ? 'fedora_repository' : $method->getAttribute('module')), + 'file' => $method->getAttribute('file'), + 'class' => $method->getAttribute('class'), + 'method' => $method->getAttribute('method'), + 'handler' => $method->getAttribute('handler')); } return $ret; } - + + /** + * editIngestFormBuilderMethod ?? + * @param type $module + * @param type $file + * @param type $class + * @param type $method + * @param type $handler + * @return boolean + */ public function editIngestFormBuilderMethod($module, $file, $class, $method, $handler) { $ret = FALSE; if ($this->validate()) { @@ -2014,7 +2165,7 @@ class ContentModel extends XMLDatastream { $methodEl->setAttribute('handler', $handler); $ret = TRUE; } - return $ret; + return $ret; } /** @@ -2041,7 +2192,7 @@ class ContentModel extends XMLDatastream { } $names = FALSE; $result = $this->xpath->query('//cm:forms/cm:form/@name'); // Select the name attribute of all forms. - for($i = 0; $i < $result->length; $i++) { + for ($i = 0; $i < $result->length; $i++) { $attribute = $result->item($i); $name = $attribute->value; $names[$name] = $name; @@ -2059,7 +2210,7 @@ class ContentModel extends XMLDatastream { return FALSE; } $result = $this->xpath->query('//cm:forms/cm:form[@ingest_class and @ingest_file and @ingest_module]/@name'); // Select the name attribute of all forms. - for($i = 0; $i < $result->length; $i++) { + for ($i = 0; $i < $result->length; $i++) { $attribute = $result->item($i); $name = $attribute->value; $names[$name] = $name; @@ -2077,7 +2228,7 @@ class ContentModel extends XMLDatastream { return FALSE; } $result = $this->xpath->query('//cm:forms/cm:form[@edit_class and @edit_file and @edit_module]/@name'); // Select the name attribute of all forms. - for($i = 0; $i < $result->length; $i++) { + for ($i = 0; $i < $result->length; $i++) { $attribute = $result->item($i); $name = $attribute->value; $names[$name] = $name; @@ -2131,7 +2282,6 @@ class ContentModel extends XMLDatastream { return FALSE; } - /** * Edits a form element with attribute name='$name' from the 'forms' element. * @@ -2142,11 +2292,11 @@ class ContentModel extends XMLDatastream { return FALSE; } $result = $this->xpath->query("//cm:form[@name='$name']"); - if($result->length == 1) { + if ($result->length == 1) { $form = $result->item(0); $result = $this->xpath->query("child::node()", $form); $element = $this->xml->importNode($element); - for($i = 0; $i < $result->length; $i++) { + for ($i = 0; $i < $result->length; $i++) { $child = $result->item($i); $element->appendChild($child); } @@ -2177,10 +2327,10 @@ class ContentModel extends XMLDatastream { $new_element = $this->xml->importNode($new_element, TRUE); $name = $new_element->tagName; $result = $new_element->getElementsByTagName('content'); - if($result->length == 1) { + if ($result->length == 1) { $new_content = $result->item(0); $result = $this->xpath->query("child::cm:content/child::node()", $edit_element); - for($i = 0; $i < $result->length; $i++) { + for ($i = 0; $i < $result->length; $i++) { $child = $result->item($i); $new_content->appendChild($child); } diff --git a/MimeClass.inc b/MimeClass.inc index f1c5cb16..82ba3b7f 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -1,4 +1,5 @@ extension lookups in the context of Islandora collections. - * - * It has been cut from a much longer list. - * - * Two types of mimetypes should be put in this list: - * 1) Special emerging formats which may not yet be expressed in the system - * mime.types file. - * 2) Heavily used mimetypes of particular importance to the Islandora - * project, as lookups against this list will be quicker and less - * resource intensive than other methods. - * - * Lookups are first checked against this short list. If no results are found, - * then the lookup function may move on to check other sources, namely the - * system's mime.types file. - * - * In most cases though, this short list should suffice. - * - * If modifying this list, please note that for promiscuous mimetypes - * (those which map to multiple extensions, such as text/plain) - * The function get_extension will always return the *LAST* extension in this list, - * so you should put your preferred extension *LAST*. - * - * e.g... - * "jpeg" => "image/jpeg", - * "jpe" => "image/jpeg", - * "jpg" => "image/jpeg", - * - * $this->get_extension('image/jpeg') will always return 'jpg'. - * - */ + /** + * This is a shortlist of mimetypes which should catch most + * mimetype<-->extension lookups in the context of Islandora collections. + * + * It has been cut from a much longer list. + * + * Two types of mimetypes should be put in this list: + * 1) Special emerging formats which may not yet be expressed in the system + * mime.types file. + * 2) Heavily used mimetypes of particular importance to the Islandora + * project, as lookups against this list will be quicker and less + * resource intensive than other methods. + * + * Lookups are first checked against this short list. If no results are found, + * then the lookup function may move on to check other sources, namely the + * system's mime.types file. + * + * In most cases though, this short list should suffice. + * + * If modifying this list, please note that for promiscuous mimetypes + * (those which map to multiple extensions, such as text/plain) + * The function get_extension will always return the *LAST* extension in this list, + * so you should put your preferred extension *LAST*. + * + * e.g... + * "jpeg" => "image/jpeg", + * "jpe" => "image/jpeg", + * "jpg" => "image/jpeg", + * + * $this->get_extension('image/jpeg') will always return 'jpg'. + * + */ // openoffice: - 'odb' => 'application/vnd.oasis.opendocument.database', - 'odc' => 'application/vnd.oasis.opendocument.chart', - 'odf' => 'application/vnd.oasis.opendocument.formula', - 'odg' => 'application/vnd.oasis.opendocument.graphics', - 'odi' => 'application/vnd.oasis.opendocument.image', - 'odm' => 'application/vnd.oasis.opendocument.text-master', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'odt' => 'application/vnd.oasis.opendocument.text', - 'otg' => 'application/vnd.oasis.opendocument.graphics-template', - 'oth' => 'application/vnd.oasis.opendocument.text-web', - 'otp' => 'application/vnd.oasis.opendocument.presentation-template', - 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', - 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'odb' => 'application/vnd.oasis.opendocument.database', + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'ott' => 'application/vnd.oasis.opendocument.text-template', // staroffice: - 'stc' => 'application/vnd.sun.xml.calc.template', - 'std' => 'application/vnd.sun.xml.draw.template', - 'sti' => 'application/vnd.sun.xml.impress.template', - 'stw' => 'application/vnd.sun.xml.writer.template', - 'sxc' => 'application/vnd.sun.xml.calc', - 'sxd' => 'application/vnd.sun.xml.draw', - 'sxg' => 'application/vnd.sun.xml.writer.global', - 'sxi' => 'application/vnd.sun.xml.impress', - 'sxm' => 'application/vnd.sun.xml.math', - 'sxw' => 'application/vnd.sun.xml.writer', + 'stc' => 'application/vnd.sun.xml.calc.template', + 'std' => 'application/vnd.sun.xml.draw.template', + 'sti' => 'application/vnd.sun.xml.impress.template', + 'stw' => 'application/vnd.sun.xml.writer.template', + 'sxc' => 'application/vnd.sun.xml.calc', + 'sxd' => 'application/vnd.sun.xml.draw', + 'sxg' => 'application/vnd.sun.xml.writer.global', + 'sxi' => 'application/vnd.sun.xml.impress', + 'sxm' => 'application/vnd.sun.xml.math', + 'sxw' => 'application/vnd.sun.xml.writer', // k-office: - 'kil' => 'application/x-killustrator', - 'kpt' => 'application/x-kpresenter', - 'kpr' => 'application/x-kpresenter', - 'ksp' => 'application/x-kspread', - 'kwt' => 'application/x-kword', - 'kwd' => 'application/x-kword', + 'kil' => 'application/x-killustrator', + 'kpt' => 'application/x-kpresenter', + 'kpr' => 'application/x-kpresenter', + 'ksp' => 'application/x-kspread', + 'kwt' => 'application/x-kword', + 'kwd' => 'application/x-kword', // ms office 97: - 'doc' => 'application/msword', - 'xls' => 'application/vnd.ms-excel', - 'ppt' => 'application/vnd.ms-powerpoint', + 'doc' => 'application/msword', + 'xls' => 'application/vnd.ms-excel', + 'ppt' => 'application/vnd.ms-powerpoint', // office2007: - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', - 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', - 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', - 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', - 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', - 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', - 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', - 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', - 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', - 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', - 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', - 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', - 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', + 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', + 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', + 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', + 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', + 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', + 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', + 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', + 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', + 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', + 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', + 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', + 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', + 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', // wordperfect (who cares?): - 'wpd' => 'application/wordperfect', + 'wpd' => 'application/wordperfect', // common and generic containers: - 'pdf' => 'application/pdf', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - 'rtf' => 'text/rtf', - 'rtx' => 'text/richtext', - 'latex' => 'application/x-latex', - 'tex' => 'application/x-tex', - 'texi' => 'application/x-texinfo', + 'pdf' => 'application/pdf', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'rtf' => 'text/rtf', + 'rtx' => 'text/richtext', + 'latex' => 'application/x-latex', + 'tex' => 'application/x-tex', + 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', // *ml: - 'css' => 'text/css', - 'htm' => 'text/html', - 'html' => 'text/html', - 'wbxml' => 'application/vnd.wap.wbxml', - 'xht' => 'application/xhtml+xml', - 'xhtml' => 'application/xhtml+xml', - 'xsl' => 'text/xml', - 'xml' => 'text/xml', - 'csv' => 'text/csv', - 'tsv' => 'text/tab-separated-values', - 'txt' => 'text/plain', + 'css' => 'text/css', + 'htm' => 'text/html', + 'html' => 'text/html', + 'wbxml' => 'application/vnd.wap.wbxml', + 'xht' => 'application/xhtml+xml', + 'xhtml' => 'application/xhtml+xml', + 'xsl' => 'text/xml', + 'xml' => 'text/xml', + 'csv' => 'text/csv', + 'tsv' => 'text/tab-separated-values', + 'txt' => 'text/plain', // images: - "bmp" => "image/bmp", - "gif" => "image/gif", - "ief" => "image/ief", - "jpeg" => "image/jpeg", - "jpe" => "image/jpeg", - "jpg" => "image/jpeg", - "jp2" => "image/jp2", - "png" => "image/png", - "tiff" => "image/tiff", - "tif" => "image/tif", - "djvu" => "image/vnd.djvu", - "djv" => "image/vnd.djvu", - "wbmp" => "image/vnd.wap.wbmp", - "ras" => "image/x-cmu-raster", - "pnm" => "image/x-portable-anymap", - "pbm" => "image/x-portable-bitmap", - "pgm" => "image/x-portable-graymap", - "ppm" => "image/x-portable-pixmap", - "rgb" => "image/x-rgb", - "xbm" => "image/x-xbitmap", - "xpm" => "image/x-xpixmap", - "xwd" => "image/x-windowdump", + "bmp" => "image/bmp", + "gif" => "image/gif", + "ief" => "image/ief", + "jpeg" => "image/jpeg", + "jpe" => "image/jpeg", + "jpg" => "image/jpeg", + "jp2" => "image/jp2", + "png" => "image/png", + "tiff" => "image/tiff", + "tif" => "image/tif", + "djvu" => "image/vnd.djvu", + "djv" => "image/vnd.djvu", + "wbmp" => "image/vnd.wap.wbmp", + "ras" => "image/x-cmu-raster", + "pnm" => "image/x-portable-anymap", + "pbm" => "image/x-portable-bitmap", + "pgm" => "image/x-portable-graymap", + "ppm" => "image/x-portable-pixmap", + "rgb" => "image/x-rgb", + "xbm" => "image/x-xbitmap", + "xpm" => "image/x-xpixmap", + "xwd" => "image/x-windowdump", // videos: - "mpeg" => "video/mpeg", - "mpe" => "video/mpeg", - "mpg" => "video/mpeg", - "m4v" => "video/mp4", - "mp4" => "video/mp4", - "ogv" => "video/ogg", - "qt" => "video/quicktime", - "mov" => "video/quicktime", - "mxu" => "video/vnd.mpegurl", - "avi" => "video/x-msvideo", - "movie" => "video/x-sgi-movie", - "flv" => "video/x-flv", - "swf" => "application/x-shockwave-flash", + "mpeg" => "video/mpeg", + "mpe" => "video/mpeg", + "mpg" => "video/mpeg", + "m4v" => "video/mp4", + "mp4" => "video/mp4", + "ogv" => "video/ogg", + "qt" => "video/quicktime", + "mov" => "video/quicktime", + "mxu" => "video/vnd.mpegurl", + "avi" => "video/x-msvideo", + "movie" => "video/x-sgi-movie", + "flv" => "video/x-flv", + "swf" => "application/x-shockwave-flash", // audio: - "mp3" => "audio/mpeg", - "mp4a" => "audio/mp4", - "m4a" => "audio/mp4", - "oga" => "audio/ogg", - "ogg" => "audio/ogg", - "flac" => "audio/x-flac", - "wav" => "audio/vnd.wave", + "mp3" => "audio/mpeg", + "mp4a" => "audio/mp4", + "m4a" => "audio/mp4", + "oga" => "audio/ogg", + "ogg" => "audio/ogg", + "flac" => "audio/x-flac", + "wav" => "audio/vnd.wave", // compressed formats: (note: http://svn.cleancode.org/svn/email/trunk/mime.types) - "tgz" => "application/x-gzip", - "gz" => "application/x-gzip", - "tar" => "application/x-tar", - "gtar" => "application/x-gtar", - "zip" => "application/x-zip", + "tgz" => "application/x-gzip", + "gz" => "application/x-gzip", + "tar" => "application/x-tar", + "gtar" => "application/x-gtar", + "zip" => "application/x-zip", // others: - 'bin' => 'application/octet-stream', + 'bin' => 'application/octet-stream', ); - private $private_file_extensions; private $system_types; private $system_exts; private $etc_mime_types = '/etc/mime.types'; + /** + * Construtor + */ public function __construct() { // 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 - if (is_readable('mime.types') ) { + if (is_readable('mime.types')) { $this->etc_mime_types = 'mime.types'; } - } - + /** * function: getType * description: An alias to get_mimetype, * for backwards-compatibility with our old mimetype class. + * + * @param type $filename + * @return type */ - public function getType( $filename ) { - return $this->get_mimetype( $filename ); + public function getType($filename) { + return $this->get_mimetype($filename); } /** * function: get_mimetype * 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 ); - $ext = strtolower( array_pop( $file_name_and_extension ) ); - - if ( ! empty( $this->private_mime_types[$ext] ) ) { - if ( TRUE === $debug ) - return array( 'mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array' ); + $file_name_and_extension = explode('.', $filename); + $ext = strtolower(array_pop($file_name_and_extension)); + + if (!empty($this->private_mime_types[$ext])) { + if (TRUE === $debug) + return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array'); return $this->private_mime_types[$ext]; } - + 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 (TRUE == $debug) return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype'); return $drupal_mimetype; } } - - if (!isset( $this->system_types)) + + if (!isset($this->system_types)) $this->system_types = $this->system_extension_mime_types(); - if (isset( $this->system_types[$ext])) { + if (isset($this->system_types[$ext])) { if (TRUE == $debug) return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types'); return $this->system_types[$ext]; } - - if ( TRUE === $debug ) - return array( 'mime_type' => 'application/octet-stream', 'method' => 'last_resort' ); - return 'application/octet-stream'; + if (TRUE === $debug) + return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort'); + return 'application/octet-stream'; } /** * function: get_extension * 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) - 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]; } - if (!isset ( $this->system_exts)) + if (!isset($this->system_exts)) $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) - 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]; } if (TRUE == $debug) - return array( 'extension' => 'bin', 'method' => 'last_resort' ); + return array('extension' => 'bin', 'method' => 'last_resort'); return 'bin'; } @@ -297,11 +309,11 @@ class MimeClass { $parts = preg_split('/\s+/', $line); if (count($parts) == 1) continue; - // A single part means a mimetype without extensions, which we ignore. + // A single part means a mimetype without extensions, which we ignore. $type = array_shift($parts); if (!isset($out[$type])) $out[$type] = array_shift($parts); - // We take the first ext from the line if many are present. + // We take the first ext from the line if many are present. } fclose($file); return $out; @@ -324,7 +336,7 @@ class MimeClass { $parts = preg_split('/\s+/', $line); if (count($parts) == 1) continue; - // A single part means a mimetype without extensions, which we ignore. + // A single part means a mimetype without extensions, which we ignore. $type = array_shift($parts); foreach ($parts as $part) $out[$part] = $type; diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 0f8be1bb..734edab4 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1,12 +1,13 @@ datastreams[$dsID]['label']; } - } else { + } + else { drupal_not_found(); exit(); } @@ -95,7 +108,8 @@ class ObjectHelper { $fedoraUser = 'anonymous'; $fedoraPass = 'anonymous'; $contentSize = 0; - } else { + } + else { $fedoraUser = $user->name; $fedoraPass = $user->pass; $dataStreamInfo = $item->get_datastream_info($dsID); @@ -135,7 +149,8 @@ class ObjectHelper { curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); fclose($fp); - } else { + } + else { header("Content-type: $mimeType"); if ($contentSize > 0) { @@ -145,7 +160,8 @@ class ObjectHelper { if ($asAttachment) { $suggestedFileName = "$label"; $pos = strpos($suggestedFileName, '.'); - /** + + /* * 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. * (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'])) { curl_exec($ch); - } else { + } + else { header('Location: ' . $url); } } curl_close($ch); - } else { + } + else { 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) { module_load_include('inc', 'fedora_repository', 'CollectionClass'); $collectionClass = new CollectionClass(); @@ -188,6 +212,11 @@ class ObjectHelper { /** * returns the mime type + * + * @global type $user + * @param type $pid + * @param type $dsID + * @return type */ function getMimeType($pid, $dsID) { global $user; @@ -217,6 +246,13 @@ class ObjectHelper { return ''; } + /** + * getDatastreamInfo ?? + * @global type $user + * @param type $pid + * @param type $dsID + * @return type + */ function getDatastreamInfo($pid, $dsID) { global $user; if (empty($pid) || empty($dsID)) { @@ -267,7 +303,8 @@ class ObjectHelper { $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '">purge datastream'; } - } else { + } + else { $purgeImage = ' '; } $fullPath = base_path() . $path; @@ -311,6 +348,12 @@ class ObjectHelper { return $content; } + /** + * getFormattedDC ?? + * @global type $base_url + * @param type $item + * @return type + */ function getFormattedDC($item) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); @@ -322,9 +365,8 @@ class ObjectHelper { if (empty($xmlstr)) { return ''; - } - + try { $proc = new XsltProcessor(); } catch (Exception $e) { @@ -348,7 +390,7 @@ class ObjectHelper { $output = $newdom->saveHTML(); return $output; } - + /** * Queries fedora for what we call the qualified dublin core. Currently only dc.coverage has * any qualified fields @@ -364,7 +406,7 @@ class ObjectHelper { $output = $this->getFormattedDC($item); $dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC'; $path = drupal_get_path('module', 'fedora_repository'); - + //$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1)); if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { $allow = TRUE; @@ -375,13 +417,11 @@ class ObjectHelper { $output .= '
' . t('Edit Meta Data') . ''; - } } return $output; } - /** * Gets a list of datastreams from an object using its pid * @@ -465,8 +505,6 @@ class ObjectHelper { } return ''; } - - /** * returns a stream from a fedora object given a pid and dsid @@ -499,11 +537,13 @@ class ObjectHelper { return $content; } - /* + /** * 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 + * @param type $pid + * @param type $include_fedora_system_content_models + * @return array */ - function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) { module_load_include('inc', 'fedora_repository', 'CollectionClass'); $collectionHelper = new CollectionClass(); @@ -542,11 +582,14 @@ class ObjectHelper { return $cmodels; } - /* + /** * determines whether we can see the object or not * checks PID namespace permissions, and user permissions + * @global type $user + * @param type $op + * @param type $pid + * @return type */ - function fedora_repository_access($op, $pid) { global $user; @@ -572,7 +615,8 @@ class ObjectHelper { return FALSE; } return $user_access; - } else { + } + else { return FALSE; } } @@ -633,13 +677,13 @@ class ObjectHelper { '/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon">' . t(' Add to this Collection'); } } - } else { + } + else { $ingestObject = ' '; } - } - $datastreams .= $ingestObject; + $datastreams .= $ingestObject; $output .= $datastreams; @@ -671,7 +715,7 @@ class ObjectHelper { $output .= theme('fieldset', $fieldset); } - + return $output; } @@ -691,6 +735,12 @@ class ObjectHelper { return $objects; } + /** + * get_parent_objects_asHTML ?? + * @global type $base_url + * @param type $pid + * @return string + */ function get_parent_objects_asHTML($pid) { global $base_url; $parent_collections = $this->get_parent_objects($pid); @@ -718,10 +768,15 @@ class ObjectHelper { return $parent_collections_HTML; } - + /** * 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 + * + * @param type $pid + * @param type $contentModel + * @param type $page_number + * @return type */ function createExtraFieldsets($pid, $contentModel, $page_number) { //$models = $collectionHelper->getContentModels($collectionPid, FALSE); @@ -760,6 +815,9 @@ class ObjectHelper { /** * Get a tree of related pids - for the basket functionality + * + * @param type $pid + * @return type */ function get_all_related_pids($pid) { if (!$pid) { @@ -789,6 +847,9 @@ class ObjectHelper { /** * Get children of PID - but only 2 levels deep + * + * @param type $pids + * @return type */ function get_child_pids($pids) { // Get pid, title and description for children of object $pid @@ -834,6 +895,11 @@ class ObjectHelper { /** * 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) { 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. + * + * @global type $base_url + * @param type $pid + * @param type $breadcrumbs + * @param type $level */ function getBreadcrumbs($pid, &$breadcrumbs, $level=10) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); // Before executing the query, we hve a base case of accessing the top-level collection global $base_url; - if ($pid == variable_get('fedora_repository_pid', 'islandora:top')){ - $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(t('Home'), $base_url); - } else { + if ($pid == variable_get('fedora_repository_pid', 'islandora:top')) { + $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + $breadcrumbs[] = l(t('Home'), $base_url); + } + else { $query_string = 'select $parentObject $title $content from <#ri> where ( $title and $parentObject $content @@ -868,23 +940,28 @@ class ObjectHelper { $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string; - $result = preg_split('/[\r\n]+/',do_curl($url)); + $result = preg_split('/[\r\n]+/', do_curl($url)); array_shift($result); // throw away first line - $matches =str_getcsv(join("\n",$result)); + $matches = str_getcsv(join("\n", $result)); if ($matches !== FALSE) { - $parent = preg_replace('/^info:fedora\//','',$matches[0]); + $parent = preg_replace('/^info:fedora\//', '', $matches[0]); $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) { $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Home'), $base_url); - } elseif ($level > 0) { + } + elseif ($level > 0) { $this->getBreadcrumbs($parent, $breadcrumbs, $level - 1); } } } } + /** + * warnIfMisconfigured ?? + * @param type $app + */ public static function warnIfMisconfigured($app) { $messMap = array( 'Kakadu' => 'Full installation instructions for Kakadu can be found diff --git a/SearchClass.inc b/SearchClass.inc index 85a91968..70e18b71 100644 --- a/SearchClass.inc +++ b/SearchClass.inc @@ -1,141 +1,186 @@ $e->getMessage())), NULL, WATCHDOG_ERROR); return 'Error getting solr search results class. Check watchdog for more info.'; - } + } 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) { $types = $this->get_search_terms_array(NULL, 'solrSearchTerms.xml'); - $queryArray=NULL; + $queryArray = NULL; if (isset($query)) { $queryArray = explode('AND', $query); } $andOrArray = array( - 'AND' => 'and', - //'OR' => 'or' //removed or for now as it would be a pain to parse + 'AND' => 'and', + //'OR' => 'or' //removed or for now as it would be a pain to parse ); $form = array(); if (!isset($repeat)) { - $repeat = variable_get('islandora_solr_search_block_repeat', t('3')); + $repeat = variable_get('islandora_solr_search_block_repeat', t('3')); } $var0 = explode(':', $queryArray[0]); $var1 = explode(':', $queryArray[1]); $form['search_type']['type1'] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => trim($var0[0]) + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => trim($var0[0]) ); $form['fedora_terms1'] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#required' => TRUE, - '#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#required' => TRUE, + '#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), ); $form['andor1'] = array( - '#title' => t(''), - '#type' => 'select', - '#default_value' => 'AND', - '#options' => $andOrArray + '#title' => t(''), + '#type' => 'select', + '#default_value' => 'AND', + '#options' => $andOrArray ); $form['search_type']['type2'] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), ); $form['fedora_terms2'] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#default_value' => (count($var1) >= 2 ? $var1[1] : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#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++) { $t = $i - 1; $field_and_term = explode(':', $queryArray[$t]); $form["andor$t"] = array( - '#title' => t(''), - '#type' => 'select', - '#default_value' => 'AND', - '#options' => $andOrArray + '#title' => t(''), + '#type' => 'select', + '#default_value' => 'AND', + '#options' => $andOrArray ); $form['search_type']["type$i"] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => trim($field_and_term[0]) + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => trim($field_and_term[0]) ); $form["fedora_terms$i"] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), ); } } $form['submit'] = array( - '#type' => 'submit', - '#value' => t('search') + '#type' => 'submit', + '#value' => t('search') ); return $form; } + /** + * build simple solr form ?? + * @return string + */ function build_simple_solr_form() { //$form = array(); $form["search_query"] = array( - '#size' => '30', - '#type' => 'textfield', - '#title' => t(''), - // '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), - ); + '#size' => '30', + '#type' => 'textfield', + '#title' => t(''), + // '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), + ); $form['submit'] = array( - '#type' => 'submit', - '#value' => t('search') + '#type' => 'submit', + '#value' => t('search') ); return $form; } + + /** + * theme solr search form ?? + * @param type $form + * @return type + */ function theme_solr_search_form($form) { 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['fedora_terms1']) ; - $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']) ; + $output = drupal_render($form['search_type']['type1']); + $output .= drupal_render($form['fedora_terms1']); + $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']); $output .= drupal_render($form['fedora_terms2']); - if ($repeat>2 && $repeat < 9) { - for ($i=3;$i<$repeat+1;$i++) { + if ($repeat > 2 && $repeat < 9) { + for ($i = 3; $i < $repeat + 1; $i++) { $t = $i - 1; - $output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]) ; - $output .= drupal_render($form["fedora_terms$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['submit']) ; + $output .= drupal_render($form['submit']); $output .= drupal_render($form); 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) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -146,15 +191,15 @@ class SearchClass { $keywords = explode(' ', $query); foreach ($keywords as $keyword) { - $luceneQuery .= $type . ':'. $keyword . '+AND+'; + $luceneQuery .= $type . ':' . $keyword . '+AND+'; } $luceneQuery = substr($luceneQuery, 0, strlen($luceneQuery) - 5); $indexName = variable_get('fedora_index_name', 'DemoOnLucene'); $keys = htmlentities(urlencode($query)); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); - $searchString = '?operation=gfindObjects&indexName='. $indexName . '&restXslt=copyXml&query='. $luceneQuery; - $searchString .= '&hitPageSize='. $numberOfHistPerPage . '&hitPageStart=1'; + $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $luceneQuery; + $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=1'; //$searchString = htmlentities($searchString); $searchUrl .= $searchString; @@ -169,20 +214,25 @@ class SearchClass { $nodeList = $xPath->query('//field[@name="refworks.u1"]'); foreach ($nodeList as $node) { if (!in_array($node->nodeValue, $userArray)) { - $userArray[]=$node->nodeValue; + $userArray[] = $node->nodeValue; } } } if ($showForm) { - $output = 'Quick Search
'. drupal_get_form('fedora_repository_quick_search_form') . '
'; + $output = 'Quick Search
' . drupal_get_form('fedora_repository_quick_search_form') . '
'; } $output .= $this->applyXSLT($resultData, $orderBy); 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) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -192,10 +242,10 @@ class SearchClass { $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 = '?'. $query; - $searchString=$searchUrl . $query; + $query = '?' . $query; + $searchString = $searchUrl . $query; $objectHelper = new ObjectHelper(); @@ -205,11 +255,16 @@ class SearchClass { $output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName); //$output .= '
'.$alpha_out; 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) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); @@ -225,8 +280,8 @@ class SearchClass { $query = trim($query); $query = htmlentities(urlencode($query)); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); - $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt='. $copyXMLFile . '&query=' . $query; - $searchString .= '&hitPageSize='. $numberOfHistPerPage . '&hitPageStart='. $startPage; + $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query; + $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage; //$searchString = htmlentities($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) { $proc = NULL; global $user; @@ -252,9 +314,8 @@ class SearchClass { } try { $proc = new XsltProcessor(); - } - catch (Exception $e) { - drupal_set_message(t('Error loading '. $pathToXSLT . ' xslt!') . $e->getMessage()); + } catch (Exception $e) { + drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!') . $e->getMessage()); return ' '; } @@ -270,10 +331,10 @@ class SearchClass { $xsl = new DomDocument(); - $test= $xsl->load($pathToXSLT); + $test = $xsl->load($pathToXSLT); 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)); } @@ -291,8 +352,8 @@ class SearchClass { return $newdom->saveXML(); } } - //default function for lucene results + //default function for lucene 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) { $path = drupal_get_path('module', 'Fedora_Repository'); $test = $xslt_file; - $isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE); - if(!isRestricted && $xslt_file == null){ + $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); + if (!isRestricted && $xslt_file == null) { $xslt_file = '/xsl/unfilteredresults.xsl'; } $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) { $path = drupal_get_path('module', 'Fedora_Repository'); $proc = NULL; @@ -378,7 +444,7 @@ class SearchClass { $proc->setParameter('', 'orderBy', $orderBy); $xsl = new DomDocument(); - $test=$xsl->load($path . '/ir/xsl/results.xsl'); + $test = $xsl->load($path . '/ir/xsl/results.xsl'); if (!isset($test)) { drupal_set_message(t('Error loading search results xslt!')); return t('Error loading search results XSLT.'); @@ -398,110 +464,127 @@ class SearchClass { } } + /** + * theme advanced search form ?? + * @param type $form + * @param type $repeat + * @return type + */ function theme_advanced_search_form($form, $repeat=NULL) { 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['fedora_terms1']) ; - $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']) ; + $output = drupal_render($form['search_type']['type1']); + $output .= drupal_render($form['fedora_terms1']); + $output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']); $output .= drupal_render($form['fedora_terms2']); - if ($repeat>2 && $repeat < 9) { - for ($i=3;$i<$repeat+1;$i++) { + if ($repeat > 2 && $repeat < 9) { + for ($i = 3; $i < $repeat + 1; $i++) { $t = $i - 1; - $output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]) ; - $output .= drupal_render($form["fedora_terms$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['submit']) ; + $output .= drupal_render($form['submit']); $output .= drupal_render($form); 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) { $types = $this->get_search_terms_array($pathToSearchTerms); - $queryArray=NULL; + $queryArray = NULL; if (isset($query)) { $queryArray = explode('AND', $query); } $andOrArray = array( - 'AND' => 'and', - //'OR' => 'or' //removed or for now as it would be a pain to parse + 'AND' => 'and', + //'OR' => 'or' //removed or for now as it would be a pain to parse ); $form = array(); if (!isset($repeat)) { - $repeat = variable_get('fedora_repository_advanced_block_repeat', t('3')); + $repeat = variable_get('fedora_repository_advanced_block_repeat', t('3')); } $var0 = explode(':', $queryArray[0]); $var1 = explode(':', $queryArray[1]); $form['search_type']['type1'] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => trim($var0[0]) + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => trim($var0[0]) ); $form['fedora_terms1'] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#required' => TRUE, - '#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#required' => TRUE, + '#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), ); $form['andor1'] = array( - '#title' => t(''), - '#type' => 'select', - '#default_value' => 'AND', - '#options' => $andOrArray + '#title' => t(''), + '#type' => 'select', + '#default_value' => 'AND', + '#options' => $andOrArray ); $form['search_type']['type2'] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), ); $form['fedora_terms2'] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#default_value' => (count($var1) >= 2 ? $var1[1] : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#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++) { $t = $i - 1; $field_and_term = explode(':', $queryArray[$t]); $form["andor$t"] = array( - '#title' => t(''), - '#type' => 'select', - '#default_value' => 'AND', - '#options' => $andOrArray + '#title' => t(''), + '#type' => 'select', + '#default_value' => 'AND', + '#options' => $andOrArray ); $form['search_type']["type$i"] = array( - '#title' => t(''), - '#type' => 'select', - '#options' => $types, - '#default_value' => trim($field_and_term[0]) + '#title' => t(''), + '#type' => 'select', + '#options' => $types, + '#default_value' => trim($field_and_term[0]) ); $form["fedora_terms$i"] = array( - '#size' => '24', - '#type' => 'textfield', - '#title' => t(''), - '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), + '#size' => '24', + '#type' => 'textfield', + '#title' => t(''), + '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), ); } } $form['submit'] = array( - '#type' => 'submit', - '#value' => t('search') + '#type' => 'submit', + '#value' => t('search') ); return $form; } - + /** + * get search terms array + * @param type $path + * @param string $file + * @return type + */ function get_search_terms_array($path = NULL, $file = NULL) { if (!isset($path)) { $path = drupal_get_path('module', 'Fedora_Repository'); @@ -510,7 +593,7 @@ class SearchClass { if (!isset($file)) { $file = 'searchTerms.xml'; } - $xmlDoc->load($path . '/'. $file); + $xmlDoc->load($path . '/' . $file); $nodeList = $xmlDoc->getElementsByTagName('term'); $types = array(); for ($i = 0; $i < $nodeList->length; $i++) { @@ -522,4 +605,5 @@ class SearchClass { } return $types; } + } diff --git a/SecurityClass.inc b/SecurityClass.inc index c314cbd1..588239e5 100644 --- a/SecurityClass.inc +++ b/SecurityClass.inc @@ -1,20 +1,33 @@ $e->getMessage())), 'error'); @@ -68,7 +84,7 @@ class SecurityClass { foreach ($conditions as $condition) { $designator = $condition->Apply->SubjectAttributeDesignator; 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']); @@ -92,17 +108,20 @@ class SecurityClass { $usersAndRoles['users'] = $allowedUsers; $usersAndRoles['roles'] = $allowedRoles; 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) { $doc = new DOMDocument(); try { $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); } $conditions = $doc->getElementsByTagName('Condition'); @@ -117,7 +136,7 @@ class SecurityClass { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { foreach ($user->roles as $role) { if (!($role == 'authenticated user' || $role == 'administrator')) { //don't want authenticated user included administrator already is included' - $newAttributeValue=$doc->createElement('AttributeValue', ''); + $newAttributeValue = $doc->createElement('AttributeValue', ''); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); // $newAttributeValue->setAttribute('MustBePresent', 'FALSE'); $apply->appendChild($newAttributeValue); @@ -132,7 +151,7 @@ class SecurityClass { foreach ($applies as $apply) { $functionId = $apply->getAttribute('FunctionId'); 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('MustBePresent', 'FALSE'); $apply->appendChild($newAttributeValue); @@ -145,7 +164,7 @@ class SecurityClass { return $doc; //NULL; //$xml; } - /** + /** * Add a list of allowed users and roles to the given policy stream and return it. * * @param string $policy_stream @@ -170,7 +189,7 @@ class SecurityClass { if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { foreach ($allowed_roles as $role) { 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('MustBePresent', 'FALSE'); $apply->appendChild($newAttributeValue); @@ -186,8 +205,8 @@ class SecurityClass { foreach ($applies as $apply) { $functionId = $apply->getAttribute('FunctionId'); if ($functionId == 'urn:oasis:names:tc:xacml:1.0:function:string-bag') { - foreach ( $allowed_users as $username ) { - $newAttributeValue=$dom->createElement('AttributeValue', $username ); + foreach ($allowed_users as $username) { + $newAttributeValue = $dom->createElement('AttributeValue', $username); $newAttributeValue->setAttribute('DataType', 'http://www.w3.org/2001/XMLSchema#string'); //$newAttributeValue->setAttribute('MustBePresent', 'FALSE'); $apply->appendChild($newAttributeValue); @@ -200,4 +219,5 @@ class SecurityClass { // $this->collection_policy_stream = $dom->saveXML(); return $dom->saveXML(); } + } diff --git a/XMLDatastream.inc b/XMLDatastream.inc index f5efa4d2..611a54cb 100644 --- a/XMLDatastream.inc +++ b/XMLDatastream.inc @@ -2,6 +2,14 @@ // $Id$ +/** + * @file + * XMLDatastream Abstract Class + */ + +/** + * XMLDatastream class ?? + */ abstract class XMLDatastream { static $XMLNS = 'http://www.islandora.ca'; @@ -95,14 +103,14 @@ abstract class XMLDatastream { $this->pid = $pid; $this->dsid = $dsid; - if ($xmlStr !== NULL) { - if(is_object($xmlStr) && get_class($xmlStr) == DOMDocument) { + if ($xmlStr !== NULL) { + if (is_object($xmlStr) && get_class($xmlStr) == DOMDocument) { $this->xml = $xmlStr; } else { $this->xml = new DOMDocument(); $this->xml->loadXML($xmlStr); - } + } } } @@ -180,7 +188,8 @@ abstract class XMLDatastream { // a subclass. $vars = get_class_vars(get_class($this)); $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. list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue); } @@ -193,10 +202,12 @@ abstract class XMLDatastream { foreach ($errors as $err) { self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message; } - } else { + } + else { $this->name = $rootEl->attributes->getNamedItem('name')->nodeValue; } - } else { + } + else { $ret = FALSE; self::$errors[] = 'Unable to load schema.'; } diff --git a/formClass.inc b/formClass.inc index 8621eae5..f22be8dc 100644 --- a/formClass.inc +++ b/formClass.inc @@ -2,10 +2,6 @@ // $Id$ -/* - * Created on Jan 22, 2008 - */ - class formClass { function formClass() { diff --git a/plugins/Flv.inc b/plugins/Flv.inc index 4345428f..7b076d00 100644 --- a/plugins/Flv.inc +++ b/plugins/Flv.inc @@ -38,6 +38,7 @@ class FormBuilder { $datastream->appendChild($version); $content = $dom->createElement("foxml:xmlContent"); $version->appendChild($content); + ///begin writing qdc $oai = $dom->createElement("oai_dc: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:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $content->appendChild($oai); + //dc elements $previousElement = NULL; //used in case we have to nest elements for qualified dublin core foreach ($form_values as $key => $value) { $index = strrpos($key, '-'); + if ($index > 01) { $key = substr($key, 0, $index); } @@ -89,10 +92,13 @@ class FormBuilder { $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"); $dom->appendChild($rootElement); + //create standard fedora stuff $this->createStandardFedoraStuff($form_values, $dom, $rootElement); + //create relationships $this->createRelationShips($form_values, $dom, $rootElement); + //create dublin core $this->createQDCStream($form_values, $dom, $rootElement); $this->createFedoraDataStreams($form_values, $dom, $rootElement); @@ -261,11 +267,13 @@ class FormBuilder { '#type' => 'fieldset', '#title' => t('Ingest Digital Object Step #2') ); + foreach ($ingest_form_definition->form_elements->element as $element) { $name = strip_tags($element->name->asXML()); $title = strip_tags($element->label->asXML()); $required = strip_tags($element->required->asXML()); $required = strtolower($required); + if ($required != 'TRUE') { $required = '0'; } @@ -273,6 +281,7 @@ class FormBuilder { $description = strip_tags($element->description->asXML()); $type = strip_tags($element->type->asXML()); $options = array(); + if ($element->type == 'select') { foreach ($element->authoritative_list->item as $item) { $field = strip_tags($item->field->asXML());