From d36fdd291ce6d346f75e4414409b73241c286ac8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 12 Jul 2011 14:14:25 -0300 Subject: [PATCH 001/117] Fix Headers for FlowPlayer FlowPlayer requires the "Content-Length" header to be returned in order to work properly, but it wasn't getting returned in the header when a user was not logged in. A slight change to the semantics, and opening up of the getDatastream API-M method via XACML seems to work. --- ObjectHelper.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 0f8be1bb..4a12240b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -94,13 +94,13 @@ class ObjectHelper { if ((!isset($user)) || $user->uid == 0) { $fedoraUser = 'anonymous'; $fedoraPass = 'anonymous'; - $contentSize = 0; } else { $fedoraUser = $user->name; $fedoraPass = $user->pass; - $dataStreamInfo = $item->get_datastream_info($dsID); - $contentSize = $dataStreamInfo->datastream->size; } + + $dataStreamInfo = $item->get_datastream_info($dsID); + $contentSize = $dataStreamInfo->datastream->size; if (function_exists("curl_init")) { if (!isset($mimeType)) { From aa7f8fe24597f366397212f77ad590bdd4ff4caa Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 14:42:02 -0300 Subject: [PATCH 002/117] Fix a tiny error introduced... --- formClass.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formClass.inc b/formClass.inc index c17bb35b..e6a3523b 100644 --- a/formClass.inc +++ b/formClass.inc @@ -288,7 +288,7 @@ class formClass { $form['fedora_repository_title'] = array( '#type' => 'textfield', '#title' => t('Digital Repository Title'), - '#default_value' => variable_get('fedora_repository_name', 'Digital Repository'), + '#default_value' => variable_get('fedora_repository_title', 'Digital Repository'), '#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'), ); $form['advanced'] = array( From 2c47f9bfb2db53a716e67654409bc03a814e4c87 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 13:45:04 -0400 Subject: [PATCH 003/117] Allow returns from modifications... --- api/fedora_item.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index d107a844..66259275 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -268,7 +268,7 @@ RDF; $description->appendChild($newrel); - $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); + return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); //print ($description->dump_node()); /* $params = array( 'pid' => $this->pid, @@ -958,6 +958,8 @@ RDF; * Error suppression? Refer to soap_call for usage (just passed along here). */ function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) { + $toReturn = NULL; + //Determine if it's inline xml; if it is, modify by value if ($this->get_datastream($dsid)->controlGroup === 'X') { $content = ''; @@ -968,7 +970,7 @@ RDF; $content = $filename_or_content; } - $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); } //Otherwise, write to web-accessible temp file and modify by reference. else { @@ -989,12 +991,14 @@ RDF; $file_url = file_create_url($file); - $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); if ($created_temp && is_file($file) && is_writable($file)) { file_delete($file); } } + + return $toReturn; } /** From 0e5bab57062f07cb3f3b320916196f5f2bae1aca Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 19 Apr 2012 16:31:30 -0300 Subject: [PATCH 004/117] Overhaul breadcrumbs and nuke fedora_repository_{name,title} Addresses the title/name issues of ISLANDORA-562 (by getting rid of them). Menu/root title is provided through the menu system. --- CollectionClass.inc | 9 +- ObjectHelper.inc | 194 +++++++++++++++++++++++++++++++-------- README | 4 +- api/fedora_utils.inc | 6 +- fedora_repository.module | 3 +- formClass.inc | 23 +---- 6 files changed, 170 insertions(+), 69 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index a46b1b5f..43d06be0 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -607,7 +607,7 @@ class CollectionClass { * @param int $pageNumber * @return type */ - function renderCollection($content, $pid, $dsId, $collection, $pageNumber = NULL) { + function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; $collection_pid = $pid; //we will be changing the pid later maybe @@ -620,17 +620,14 @@ class CollectionClass { $fedoraItem = NULL; - - - $collectionName = $collection; - if (!$pageNumber) { $pageNumber = 1; } if (empty($collectionName)) { - $collectionName = variable_get('fedora_repository_name', 'Collection'); + $collectionName = menu_get_active_title(); } + $xslContent = $this->getXslContent($pid, $path); //get collection list and display using xslt------------------------------------------- diff --git a/ObjectHelper.inc b/ObjectHelper.inc index aeaf09d0..85c0ab4b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -938,58 +938,62 @@ class ObjectHelper { /** * Builds an array of drupal links for use in breadcrumbs. * + * @todo Make fully recursive... + * * @global type $base_url * @param type $pid * @param type $breadcrumbs * @param type $level */ - function getBreadcrumbs($pid, &$breadcrumbs, $level=10) { + function getBreadcrumbs($pid, &$breadcrumbs) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); // Before executing the query, we hve a base case of accessing the top-level collection global $base_url; - if ($pid == variable_get('fedora_repository_pid', 'islandora:root')) { - //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(variable_get('fedora_repository_title', 'Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(t('Home'), $base_url); + static $max_level = 10; + static $level = -1; + + if (count($breadcrumbs) === 0) { + $level = $max_level; + } + + $root = variable_get('fedora_repository_pid', 'islandora:root'); + + if ($pid == $root) { + $breadcrumbs[] = l(menu_get_active_title(), 'fedora/repository'); + $breadcrumbs[] = l(t('Home'), ''); } else { $query_string = 'select $parentObject $title $content from <#ri> - where ( $title - and $parentObject $content - and ( $parentObject - or $parentObject - or $parentObject) - and $parentObject ) - minus $content - order by $title desc'; - $query_string = htmlentities(urlencode($query_string)); - - $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string; - - $result = preg_split('/[\r\n]+/', do_curl($url)); - array_shift($result); // throw away first line - $matches = str_getcsv(join("\n", $result)); - if (count($matches) >= 2) { - $parent = preg_replace('/^info:fedora\//', '', $matches[0]); - - if (0 == strlen($matches[1])) { - $matches[1] = "Unlabeled Object"; + where ( + $title + and $parentObject $content + and ( + $parentObject + or $parentObject + or $parentObject + ) + and $parentObject + ) + minus $content + order by $title desc'; + + if (count($results = self::perform_itql_query($query_string)) > 0 && $level > 0) { + $parent = $results[0]['parentObject']; + $this_title = $results[0]['title']; + + if (empty($this_title)) { + $this_title = t('Unlabeled Object'); } - $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); - if ($parent == variable_get('fedora_repository_pid', 'islandora:root')) { - //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(variable_get('fedora_repository_name', 'Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(t('Home'), $base_url); - } - elseif ($level > 0) { - $this->getBreadcrumbs($parent, $breadcrumbs, $level - 1); - } + $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); + + $level--; + $this->getBreadcrumbs($parent, $breadcrumbs); } - else { - $breadcrumbs[] = l(t("Path Calculation Error"), 'fedora/repository/' . $pid); + watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); + $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. + $this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass). } } } @@ -1012,5 +1016,121 @@ class ObjectHelper { drupal_set_message(t($configMess . "
" . $messMap[$app] . "
", array('%app' => $app)), 'warning', FALSE); } + /** + * Performs the given Resource Index query and return the results. + * + * @param $query string + * A string containing the RI query to perform. + * @param $type string + * The type of query to perform, as used by the risearch interface. + * @param $limit int + * An integer, used to limit the number of results to return. + * @param $offset int + * An integer, used to offset the results (results should be ordered, to + * maintain consistency. + * + * @return array + * Indexed (numerical) array, containing a number of associative arrays, + * with keys being the same as the variable names in the query. + * URIs beginning with 'info:fedora/' will have this beginning stripped + * off, to facilitate their use as PIDs. + */ + protected static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { + //Setup the query options... + $options = array( + 'type' => 'tuples', + 'flush' => TRUE, + 'format' => 'Sparql', //Sparql XML is processed into the array below. + 'lang' => $type, + 'query' => $query + ); + //Add limit if provided. + if ($limit > 0) { + $options['limit'] = $limit; + } + //Add offset if provided. + if ($offset > 0) { + $options['offset'] = $offset; + } + + //Construct the query URL. + $queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options)); + + //Perform the query. + $curl_result = do_curl_ext($queryUrl); + + //If the query failed, write message to the logs and return. + if (!$curl_result[0]) { + watchdog('fedora_repository', 'Failed to perform %type resource index query: %query', array('%type' => $type, '%query' => $query), WATCHDOG_ERROR); + return FALSE; + } + + //Load the results into a SimpleXMLElement + $doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); + + $results = array(); //Storage. + + //Build the results. + foreach ($doc->results->children() as $result) { + //Built a single result. + $r = array(); + foreach ($result->children() as $element) { + $val = NULL; + + $attrs = $element->attributes(); + if (!empty($attrs['uri'])) { + $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); + } + else { + $val = (string)$element; + } + + //Map the name to the value in the array. + $r[$element->getName()] = $val; + } + + //Add the single result to the set to return. + $results[] = $r; + } + return $results; + } + /** + * Thin wrapper for self::_perform_ri_query(). + * + * @see self::_perform_ri_query() + */ + public static function perform_itql_query($query, $limit = -1, $offset = 0) { + return self::perform_ri_query($query, 'itql', $limit, $offset); + } + /** + * Thin wrapper for self::_perform_ri_query(). + * + * @see self::_perform_ri_query() + */ + public static function perform_sparql_query($query, $limit = -1, $offset = 0) { + return self::perform_ri_query($query, 'sparql', $limit, $offset); + } + /** + * Utility function used in self::_perform_ri_query(). + * + * Strips off the 'info:fedora/' prefix from the passed in string. + * + * @param $uri string + * A string containing a URI. + * + * @return string + * The input string less the 'info:fedora/' prefix (if it has it). + * The original string otherwise. + */ + protected static function pid_uri_to_bare_pid($uri) { + $chunk = 'info:fedora/'; + $pos = strpos($uri, $chunk); + if ($pos === 0) { //Remove info:fedora/ chunk + return substr($uri, strlen($chunk)); + } + else { //Doesn't start with info:fedora/ chunk... + return $uri; + } + } } diff --git a/README b/README index f4980bb4..7a642cc4 100644 --- a/README +++ b/README @@ -4,6 +4,6 @@ For installation and customization instructions please see the documentation and https://wiki.duraspace.org/display/ISLANDORA/Islandora -All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: +All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: -https://jira.duraspace.org/browse/ISLANDORA \ No newline at end of file +https://jira.duraspace.org/browse/ISLANDORA diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index eb56bdcc..459c86ba 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -85,7 +85,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * an array that consists of three value or NULL if curl is not suported: * - element 0: * The value returned from the curl_exec function call. - * This is either a TRUE or FALSE value or the actual data returned from + * This is either a boolean value or the actual data returned from * accessing the URL. * - element 1: * The error code reslting from attempting to access the URL with curl_exec @@ -93,7 +93,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * A string representing a textual representation of the error code that * resulted from attempting to access the URL with curl_exec */ -function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) { +function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0, $post = NULL) { global $user; // Check if we are inside Drupal and there is a valid user. @@ -113,7 +113,7 @@ function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $p curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable diff --git a/fedora_repository.module b/fedora_repository.module index abec4b9e..8a80c8e3 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2,8 +2,7 @@ /** * Drupal hook for admin form - * fedora_repository_name is the name of the top level collection this module will query - * fedora_repository_pid is the name of the top level pid. + * * Stores this info in the drupal variables table. * the name and pid can also be passed as url parameters */ diff --git a/formClass.inc b/formClass.inc index c1122182..1d752f3d 100644 --- a/formClass.inc +++ b/formClass.inc @@ -70,9 +70,7 @@ class formClass { 'access arguments' => array('view fedora collection'), ); $items['fedora/repository'] = array( - 'title' => '', - 'title callback' => 'variable_get', - 'title arguments' => array('fedora_repository_name', 'Digital Repository'), + 'title' => 'Digital Repository', 'page callback' => 'repository_page', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('view fedora collection'), @@ -187,24 +185,16 @@ class formClass { /** * Create admin form - * @return type + * @return array */ function createAdminForm() { if (!user_access('administer site configuration')) { - drupal_set_message(t('You must be a site administrator to edit the Fedora collecitons list.'), 'error'); + drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error'); return; } module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $form = array(); - $form['fedora_repository_name'] = array( - '#type' => 'textfield', - '#title' => t('Root Collection Name'), - '#default_value' => variable_get('fedora_repository_name', 'Islandora demos collection'), - '#description' => t('The Name of the Root Collection Object'), - '#required' => TRUE, - '#weight' => -20 - ); $form['fedora_repository_pid'] = array( '#type' => 'textfield', '#title' => t('Root Collection PID'), @@ -285,12 +275,7 @@ class formClass { '#weight' => 0 ); } - $form['fedora_repository_title'] = array( - '#type' => 'textfield', - '#title' => t('Digital Repository Title'), - '#default_value' => variable_get('fedora_repository_title', 'Digital Repository'), - '#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'), - ); + //have tabs options (like disable) $form['tabs'] = array( '#type' => 'fieldset', From 0f15711e4bcb80c5a1394ad56969d2d5fa631093 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 09:48:52 -0300 Subject: [PATCH 005/117] Use function returned by get_t() Because of Drupal's workflow, we may not have access to the regular t() function. Drupal provides get_t() function to address this issue, it just has to be used (and it's return used). Also, use the bloody url function instead of appending $base_url. --- fedora_repository.install | 43 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/fedora_repository.install b/fedora_repository.install index 164ce02e..169d1178 100644 --- a/fedora_repository.install +++ b/fedora_repository.install @@ -34,71 +34,70 @@ function fedora_collections_enable() { * @see _update_cron_notify() */ function fedora_repository_requirements($phase) { - global $base_url; - $requirements = array(); + $t = get_t(); //May not have access to the regular t() function; and so Drupal provides... if ($phase == 'install') { // Test for SOAP - $requirements['fedora-soap']['title'] = t("PHP SOAP extension library"); + $requirements['fedora-soap']['title'] = $t("PHP SOAP extension library"); if (!class_exists('SoapClient')) { - $requirements['fedora-soap']['value'] = t("Not installed"); + $requirements['fedora-soap']['value'] = $t("Not installed"); $requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR; - $requirements['fedora-soap']['description'] = t('Ensure that the PHP SOAP extension is installed.'); + $requirements['fedora-soap']['description'] = $t('Ensure that the PHP SOAP extension is installed.'); } else { - $requirements['fedora-soap']['value'] = t("Installed"); + $requirements['fedora-soap']['value'] = $t("Installed"); $requirements['fedora-soap']['severity'] = REQUIREMENT_OK; } // Test for Curl - $requirements['curl']['title'] = "PHP Curl extension library"; + $requirements['curl']['title'] = $t('PHP Curl extension library'); if (!function_exists('curl_init')) { - $requirements['curl']['value'] = t("Not installed"); + $requirements['curl']['value'] = $t("Not installed"); $requirements['curl']['severity'] = REQUIREMENT_ERROR; - $requirements['curl']['description'] = t("Ensure that the PHP Curl extension is installed."); + $requirements['curl']['description'] = $t("Ensure that the PHP Curl extension is installed."); } else { - $requirements['curl']['value'] = t("Installed"); + $requirements['curl']['value'] = $t("Installed"); $requirements['curl']['severity'] = REQUIREMENT_OK; } // Test for DOM - $requirements['dom']['title'] = "PHP DOM XML extension library"; + $requirements['dom']['title'] = $t("PHP DOM XML extension library"; if (!method_exists('DOMDocument', 'loadHTML')) { - $requirements['dom']['value'] = t("Not installed"); + $requirements['dom']['value'] = $t("Not installed"); $requirements['dom']['severity'] = REQUIREMENT_ERROR; - $requirements['dom']['description'] = t("Ensure that the PHP DOM XML extension is installed."); + $requirements['dom']['description'] = $t("Ensure that the PHP DOM XML extension is installed."); } else { - $requirements['dom']['value'] = t("Installed"); + $requirements['dom']['value'] = $t("Installed"); $requirements['dom']['severity'] = REQUIREMENT_OK; } // Test for XSLT - $requirements['xsl']['title'] = "PHP XSL extension library"; + $requirements['xsl']['title'] = $t("PHP XSL extension library"); if (!class_exists('XSLTProcessor')) { - $requirements['xslt']['value'] = t("Not installed"); + $requirements['xslt']['value'] = $t("Not installed"); $requirements['xslt']['severity'] = REQUIREMENT_ERROR; - $requirements['xslt']['description'] = t("Ensure that the PHP XSL extension is installed."); + $requirements['xslt']['description'] = $t("Ensure that the PHP XSL extension is installed."); } else { - $requirements['xslt']['value'] = t("Installed"); + $requirements['xslt']['value'] = $t("Installed"); $requirements['xslt']['severity'] = REQUIREMENT_OK; } } elseif ($phase == 'runtime') { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - $requirements['fedora-repository']['title'] = t("Fedora server"); + $requirements['fedora-repository']['title'] = $t("Fedora server"); if (!fedora_available()) { - $requirements['fedora-repository']['value'] = t("Not available"); + $requirements['fedora-repository']['value'] = $t("Not available"); $requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR; - $requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the collection settings are correct.', array('@collection-settings' => $base_url . '/admin/settings/fedora_repository')); + $requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the collection settings are correct.', array('@collection-settings' => url('admin/settings/fedora_repository'))); } else { - $requirements['fedora-repository']['value'] = t("Available"); + $requirements['fedora-repository']['value'] = $t("Available"); $requirements['fedora-repository']['severity'] = REQUIREMENT_OK; } } From 7ad0b140ab2151b0958f85b10fdbf91676d50444 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 14:42:02 -0300 Subject: [PATCH 006/117] Fix a tiny error introduced... --- formClass.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formClass.inc b/formClass.inc index 99decc08..c1122182 100644 --- a/formClass.inc +++ b/formClass.inc @@ -288,7 +288,7 @@ class formClass { $form['fedora_repository_title'] = array( '#type' => 'textfield', '#title' => t('Digital Repository Title'), - '#default_value' => variable_get('fedora_repository_name', 'Digital Repository'), + '#default_value' => variable_get('fedora_repository_title', 'Digital Repository'), '#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'), ); //have tabs options (like disable) From 856489f74fd2ff20e61ab0453494cdc288582403 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 13:45:04 -0400 Subject: [PATCH 007/117] Allow returns from modifications... --- README | 4 ++-- api/fedora_item.inc | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README b/README index f4980bb4..7a642cc4 100644 --- a/README +++ b/README @@ -4,6 +4,6 @@ For installation and customization instructions please see the documentation and https://wiki.duraspace.org/display/ISLANDORA/Islandora -All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: +All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: -https://jira.duraspace.org/browse/ISLANDORA \ No newline at end of file +https://jira.duraspace.org/browse/ISLANDORA diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 279a3e51..fdb4a00d 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -276,7 +276,7 @@ RDF; $description->appendChild($newrel); - $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); + return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); //print ($description->dump_node()); /* $params = array( 'pid' => $this->pid, @@ -969,6 +969,8 @@ RDF; * Error suppression? Refer to soap_call for usage (just passed along here). */ function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) { + $toReturn = NULL; + //Determine if it's inline xml; if it is, modify by value if ($this->get_datastream($dsid)->controlGroup === 'X') { $content = ''; @@ -979,7 +981,7 @@ RDF; $content = $filename_or_content; } - $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); } //Otherwise, write to web-accessible temp file and modify by reference. else { @@ -1000,12 +1002,14 @@ RDF; $file_url = file_create_url($file); - $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); if ($created_temp && is_file($file) && is_writable($file)) { file_delete($file); } } + + return $toReturn; } /** From e4cad8c4488d101b1581ce988ae6aa6959bc6a3f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 19 Apr 2012 16:31:30 -0300 Subject: [PATCH 008/117] Overhaul breadcrumbs and nuke fedora_repository_{name,title} Addresses the title/name issues of ISLANDORA-562 (by getting rid of them). Menu/root title is provided through the menu system. --- CollectionClass.inc | 9 +- ObjectHelper.inc | 176 +++++++++++++++++++++++++++++++-------- api/fedora_utils.inc | 6 +- fedora_repository.module | 3 +- formClass.inc | 23 +---- 5 files changed, 150 insertions(+), 67 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index a46b1b5f..43d06be0 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -607,7 +607,7 @@ class CollectionClass { * @param int $pageNumber * @return type */ - function renderCollection($content, $pid, $dsId, $collection, $pageNumber = NULL) { + function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; $collection_pid = $pid; //we will be changing the pid later maybe @@ -620,17 +620,14 @@ class CollectionClass { $fedoraItem = NULL; - - - $collectionName = $collection; - if (!$pageNumber) { $pageNumber = 1; } if (empty($collectionName)) { - $collectionName = variable_get('fedora_repository_name', 'Collection'); + $collectionName = menu_get_active_title(); } + $xslContent = $this->getXslContent($pid, $path); //get collection list and display using xslt------------------------------------------- diff --git a/ObjectHelper.inc b/ObjectHelper.inc index aeaf09d0..7e4c0161 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -938,58 +938,62 @@ class ObjectHelper { /** * Builds an array of drupal links for use in breadcrumbs. * + * @todo Make fully recursive... + * * @global type $base_url * @param type $pid * @param type $breadcrumbs * @param type $level */ - function getBreadcrumbs($pid, &$breadcrumbs, $level=10) { + function getBreadcrumbs($pid, &$breadcrumbs) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); // Before executing the query, we hve a base case of accessing the top-level collection global $base_url; - if ($pid == variable_get('fedora_repository_pid', 'islandora:root')) { - //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(variable_get('fedora_repository_title', 'Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(t('Home'), $base_url); + static $max_level = 10; + static $level = -1; + + if (count($breadcrumbs) === 0) { + $level = $max_level; + } + + $root = variable_get('fedora_repository_pid', 'islandora:root'); + + if ($pid == $root) { + $breadcrumbs[] = l(menu_get_active_title(), 'fedora/repository'); + $breadcrumbs[] = l(t('Home'), ''); } else { $query_string = 'select $parentObject $title $content from <#ri> - where ( $title - and $parentObject $content - and ( $parentObject - or $parentObject - or $parentObject) - and $parentObject ) - minus $content - order by $title desc'; - $query_string = htmlentities(urlencode($query_string)); - - $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string; - - $result = preg_split('/[\r\n]+/', do_curl($url)); - array_shift($result); // throw away first line - $matches = str_getcsv(join("\n", $result)); - if (count($matches) >= 2) { - $parent = preg_replace('/^info:fedora\//', '', $matches[0]); - - if (0 == strlen($matches[1])) { - $matches[1] = "Unlabeled Object"; + where ( + $title + and $parentObject $content + and ( + $parentObject + or $parentObject + or $parentObject + ) + and $parentObject + ) + minus $content + order by $title desc'; + + if (count($results = self::_perform_itql_query($query_string)) > 0 && $level > 0) { + $parent = $results[0]['parentObject']; + $this_title = $results[0]['title']; + + if (empty($this_title)) { + $this_title = t('Unlabeled Object'); } - $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); - if ($parent == variable_get('fedora_repository_pid', 'islandora:root')) { - //$breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(variable_get('fedora_repository_name', 'Digital repository'), 'fedora/repository'); - $breadcrumbs[] = l(t('Home'), $base_url); - } - elseif ($level > 0) { - $this->getBreadcrumbs($parent, $breadcrumbs, $level - 1); - } + $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); + + $level--; + $this->getBreadcrumbs($parent, $breadcrumbs); } - else { - $breadcrumbs[] = l(t("Path Calculation Error"), 'fedora/repository/' . $pid); + watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); + $breadcrumbs[] = '...'; + $this->getBreadcrumbs($root, $breadcrumbs); } } } @@ -1012,5 +1016,103 @@ class ObjectHelper { drupal_set_message(t($configMess . "
" . $messMap[$app] . "
", array('%app' => $app)), 'warning', FALSE); } + /** + * Performs the given RI query. + * + * FIXME: Could probably made more fail-safe (avoid loading directly with SimpleXML.) + * + * @param string $query + * @param int $limit + * @param int $offset + * @return array + * Indexed (numerical) array, containing a number of associative arrays, + * with keys being the same as the variable names in the query. + * URIs beginning with 'info:fedora/' will have this beginning stripped + * off, to facilitate their use as PIDs. + */ + protected static function _perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { + //Setup the query options... + $options = array( + 'type' => 'tuples', + 'flush' => TRUE, + 'format' => 'Sparql', + 'lang' => $type, + 'query' => $query + ); + if ($limit > 0) { + $options['limit'] = $limit; + } + if ($offset > 0) { + $options['offset'] = $offset; + } + + //Actually construct the query URL. + $queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options)); + + $curl_result = do_curl_ext($queryUrl); + + if (!$curl_result[0]) { + watchdog('fedora_repository', 'Failed to perform %type resource index query: %query', array('%type' => $type, '%query' => $query), WATCHDOG_ERROR); + return FALSE; + } + + $doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); + + $results = array(); //Storage. + + //Build the results. + foreach ($doc->results->children() as $result) { + $r = array(); + foreach ($result->children() as $element) { + $val = NULL; + + $attrs = $element->attributes(); + + if (!empty($attrs['uri'])) { + $val = $attrs['uri']; + } + else { + $val = $element; + } + + $r[$element->getName()] = self::_pid_uri_to_bare_pid((string)$val); + } + $results[] = $r; + } + return $results; + } + /** + * Thin wrapper for self::_perform_ri_query(). + */ + public static function _perform_itql_query($query, $limit = -1, $offset = 0) { + return self::_perform_ri_query($query, 'itql', $limit, $offset); + } + /** + * Thin wrapper for self::_perform_ri_query(). + */ + public static function _perform_sparql_query($query, $limit = -1, $offset = 0) { + return self::_perform_ri_query($query, 'sparql', $limit, $offset); + } + /** + * Utility function used in self::_perform_ri_query(). + * + * Strips off the 'info:fedora/' prefix from the passed in string. + * + * @param $uri string + * A string containing a URI. + * @return string + * The input string less the 'info:fedora/' prefix (if it has it). + * The original string otherwise. + */ + protected static function _pid_uri_to_bare_pid($uri) { + $chunk = 'info:fedora/'; + $pos = strrpos($uri, $chunk); + if ($pos !== FALSE) { //Remove info:fedora/ chunk + return substr($uri, strlen($chunk)); + } + else { //Doesn't start with info:fedora/ chunk... + return $uri; + } + } } diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index eb56bdcc..459c86ba 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -85,7 +85,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * an array that consists of three value or NULL if curl is not suported: * - element 0: * The value returned from the curl_exec function call. - * This is either a TRUE or FALSE value or the actual data returned from + * This is either a boolean value or the actual data returned from * accessing the URL. * - element 1: * The error code reslting from attempting to access the URL with curl_exec @@ -93,7 +93,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post * A string representing a textual representation of the error code that * resulted from attempting to access the URL with curl_exec */ -function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) { +function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0, $post = NULL) { global $user; // Check if we are inside Drupal and there is a valid user. @@ -113,7 +113,7 @@ function do_curl_ext($url, $return_to_variable = 1, $number_of_post_vars = 0, $p curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable diff --git a/fedora_repository.module b/fedora_repository.module index abec4b9e..8a80c8e3 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2,8 +2,7 @@ /** * Drupal hook for admin form - * fedora_repository_name is the name of the top level collection this module will query - * fedora_repository_pid is the name of the top level pid. + * * Stores this info in the drupal variables table. * the name and pid can also be passed as url parameters */ diff --git a/formClass.inc b/formClass.inc index c1122182..1d752f3d 100644 --- a/formClass.inc +++ b/formClass.inc @@ -70,9 +70,7 @@ class formClass { 'access arguments' => array('view fedora collection'), ); $items['fedora/repository'] = array( - 'title' => '', - 'title callback' => 'variable_get', - 'title arguments' => array('fedora_repository_name', 'Digital Repository'), + 'title' => 'Digital Repository', 'page callback' => 'repository_page', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('view fedora collection'), @@ -187,24 +185,16 @@ class formClass { /** * Create admin form - * @return type + * @return array */ function createAdminForm() { if (!user_access('administer site configuration')) { - drupal_set_message(t('You must be a site administrator to edit the Fedora collecitons list.'), 'error'); + drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error'); return; } module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $form = array(); - $form['fedora_repository_name'] = array( - '#type' => 'textfield', - '#title' => t('Root Collection Name'), - '#default_value' => variable_get('fedora_repository_name', 'Islandora demos collection'), - '#description' => t('The Name of the Root Collection Object'), - '#required' => TRUE, - '#weight' => -20 - ); $form['fedora_repository_pid'] = array( '#type' => 'textfield', '#title' => t('Root Collection PID'), @@ -285,12 +275,7 @@ class formClass { '#weight' => 0 ); } - $form['fedora_repository_title'] = array( - '#type' => 'textfield', - '#title' => t('Digital Repository Title'), - '#default_value' => variable_get('fedora_repository_title', 'Digital Repository'), - '#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'), - ); + //have tabs options (like disable) $form['tabs'] = array( '#type' => 'fieldset', From 5560e73202657cb1246a6d0c25b36213ad8ed021 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 09:48:36 -0300 Subject: [PATCH 009/117] Add a couple comments. --- ObjectHelper.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 7e4c0161..7a583c33 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -992,8 +992,8 @@ class ObjectHelper { } else { watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); - $breadcrumbs[] = '...'; - $this->getBreadcrumbs($root, $breadcrumbs); + $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. + $this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass). } } } From e7df7b358bab85d42d75456f5174395ac6ea3062 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 09:48:52 -0300 Subject: [PATCH 010/117] Use function returned by get_t() Because of Drupal's workflow, we may not have access to the regular t() function. Drupal provides get_t() function to address this issue, it just has to be used (and it's return used). Also, use the bloody url function instead of appending $base_url. --- fedora_repository.install | 43 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/fedora_repository.install b/fedora_repository.install index 164ce02e..169d1178 100644 --- a/fedora_repository.install +++ b/fedora_repository.install @@ -34,71 +34,70 @@ function fedora_collections_enable() { * @see _update_cron_notify() */ function fedora_repository_requirements($phase) { - global $base_url; - $requirements = array(); + $t = get_t(); //May not have access to the regular t() function; and so Drupal provides... if ($phase == 'install') { // Test for SOAP - $requirements['fedora-soap']['title'] = t("PHP SOAP extension library"); + $requirements['fedora-soap']['title'] = $t("PHP SOAP extension library"); if (!class_exists('SoapClient')) { - $requirements['fedora-soap']['value'] = t("Not installed"); + $requirements['fedora-soap']['value'] = $t("Not installed"); $requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR; - $requirements['fedora-soap']['description'] = t('Ensure that the PHP SOAP extension is installed.'); + $requirements['fedora-soap']['description'] = $t('Ensure that the PHP SOAP extension is installed.'); } else { - $requirements['fedora-soap']['value'] = t("Installed"); + $requirements['fedora-soap']['value'] = $t("Installed"); $requirements['fedora-soap']['severity'] = REQUIREMENT_OK; } // Test for Curl - $requirements['curl']['title'] = "PHP Curl extension library"; + $requirements['curl']['title'] = $t('PHP Curl extension library'); if (!function_exists('curl_init')) { - $requirements['curl']['value'] = t("Not installed"); + $requirements['curl']['value'] = $t("Not installed"); $requirements['curl']['severity'] = REQUIREMENT_ERROR; - $requirements['curl']['description'] = t("Ensure that the PHP Curl extension is installed."); + $requirements['curl']['description'] = $t("Ensure that the PHP Curl extension is installed."); } else { - $requirements['curl']['value'] = t("Installed"); + $requirements['curl']['value'] = $t("Installed"); $requirements['curl']['severity'] = REQUIREMENT_OK; } // Test for DOM - $requirements['dom']['title'] = "PHP DOM XML extension library"; + $requirements['dom']['title'] = $t("PHP DOM XML extension library"; if (!method_exists('DOMDocument', 'loadHTML')) { - $requirements['dom']['value'] = t("Not installed"); + $requirements['dom']['value'] = $t("Not installed"); $requirements['dom']['severity'] = REQUIREMENT_ERROR; - $requirements['dom']['description'] = t("Ensure that the PHP DOM XML extension is installed."); + $requirements['dom']['description'] = $t("Ensure that the PHP DOM XML extension is installed."); } else { - $requirements['dom']['value'] = t("Installed"); + $requirements['dom']['value'] = $t("Installed"); $requirements['dom']['severity'] = REQUIREMENT_OK; } // Test for XSLT - $requirements['xsl']['title'] = "PHP XSL extension library"; + $requirements['xsl']['title'] = $t("PHP XSL extension library"); if (!class_exists('XSLTProcessor')) { - $requirements['xslt']['value'] = t("Not installed"); + $requirements['xslt']['value'] = $t("Not installed"); $requirements['xslt']['severity'] = REQUIREMENT_ERROR; - $requirements['xslt']['description'] = t("Ensure that the PHP XSL extension is installed."); + $requirements['xslt']['description'] = $t("Ensure that the PHP XSL extension is installed."); } else { - $requirements['xslt']['value'] = t("Installed"); + $requirements['xslt']['value'] = $t("Installed"); $requirements['xslt']['severity'] = REQUIREMENT_OK; } } elseif ($phase == 'runtime') { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - $requirements['fedora-repository']['title'] = t("Fedora server"); + $requirements['fedora-repository']['title'] = $t("Fedora server"); if (!fedora_available()) { - $requirements['fedora-repository']['value'] = t("Not available"); + $requirements['fedora-repository']['value'] = $t("Not available"); $requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR; - $requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the collection settings are correct.', array('@collection-settings' => $base_url . '/admin/settings/fedora_repository')); + $requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the collection settings are correct.', array('@collection-settings' => url('admin/settings/fedora_repository'))); } else { - $requirements['fedora-repository']['value'] = t("Available"); + $requirements['fedora-repository']['value'] = $t("Available"); $requirements['fedora-repository']['severity'] = REQUIREMENT_OK; } } From 8dde6736b70bbeeb3a0c7aafb84642ee37044b08 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 10:13:08 -0300 Subject: [PATCH 011/117] Add comments/inline docs, and change the function names to be more the norm. --- ObjectHelper.inc | 50 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 7a583c33..06481a91 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -977,7 +977,7 @@ class ObjectHelper { minus $content order by $title desc'; - if (count($results = self::_perform_itql_query($query_string)) > 0 && $level > 0) { + if (count($results = self::perform_itql_query($query_string)) > 0 && $level > 0) { $parent = $results[0]['parentObject']; $this_title = $results[0]['title']; @@ -1017,13 +1017,17 @@ class ObjectHelper { } /** - * Performs the given RI query. + * Performs the given Resource Index query and return the results. * - * FIXME: Could probably made more fail-safe (avoid loading directly with SimpleXML.) - * - * @param string $query - * @param int $limit - * @param int $offset + * @param $query string + * A string containing the RI query to perform. + * @param $type string + * The type of query to perform, as used by the risearch interface. + * @param $limit int + * An integer, used to limit the number of results to return. + * @param $offset int + * An integer, used to offset the results (results should be ordered, to + * maintain consistency. * @return array * Indexed (numerical) array, containing a number of associative arrays, * with keys being the same as the variable names in the query. @@ -1035,62 +1039,74 @@ class ObjectHelper { $options = array( 'type' => 'tuples', 'flush' => TRUE, - 'format' => 'Sparql', + 'format' => 'Sparql', //Sparql XML is processed into the array below. 'lang' => $type, 'query' => $query ); + //Add limit if provided. if ($limit > 0) { $options['limit'] = $limit; } + //Add offset if provided. if ($offset > 0) { $options['offset'] = $offset; } - //Actually construct the query URL. + //Construct the query URL. $queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options)); + //Perform the query. $curl_result = do_curl_ext($queryUrl); + //If the query failed, write message to the logs and return. if (!$curl_result[0]) { watchdog('fedora_repository', 'Failed to perform %type resource index query: %query', array('%type' => $type, '%query' => $query), WATCHDOG_ERROR); return FALSE; } + //Load the results into a SimpleXMLElement $doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); $results = array(); //Storage. //Build the results. foreach ($doc->results->children() as $result) { + //Built a single result. $r = array(); foreach ($result->children() as $element) { $val = NULL; $attrs = $element->attributes(); - if (!empty($attrs['uri'])) { - $val = $attrs['uri']; + $val = self::_pid_uri_to_bare_pid((string)$attrs['uri']); } else { - $val = $element; + $val = (string)$element; } - $r[$element->getName()] = self::_pid_uri_to_bare_pid((string)$val); + //Map the name to the value in the array. + $r[$element->getName()] = $val; } + + //Add the single result to the set to return. $results[] = $r; } return $results; } /** * Thin wrapper for self::_perform_ri_query(). + * + * @see self::_perform_ri_query() */ - public static function _perform_itql_query($query, $limit = -1, $offset = 0) { + public static function perform_itql_query($query, $limit = -1, $offset = 0) { return self::_perform_ri_query($query, 'itql', $limit, $offset); } /** * Thin wrapper for self::_perform_ri_query(). + * + * @see self::_perform_ri_query() */ - public static function _perform_sparql_query($query, $limit = -1, $offset = 0) { + public static function perform_sparql_query($query, $limit = -1, $offset = 0) { return self::_perform_ri_query($query, 'sparql', $limit, $offset); } /** @@ -1106,8 +1122,8 @@ class ObjectHelper { */ protected static function _pid_uri_to_bare_pid($uri) { $chunk = 'info:fedora/'; - $pos = strrpos($uri, $chunk); - if ($pos !== FALSE) { //Remove info:fedora/ chunk + $pos = strpos($uri, $chunk); + if ($pos === 0) { //Remove info:fedora/ chunk return substr($uri, strlen($chunk)); } else { //Doesn't start with info:fedora/ chunk... From 5ae0e4605332f9be60b9504d935cf56d41665302 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 19 Apr 2012 16:31:30 -0300 Subject: [PATCH 012/117] Overhaul breadcrumbs and nuke fedora_repository_{name,title} Addresses the title/name issues of ISLANDORA-562 (by getting rid of them). Menu/root title is provided through the menu system. --- ObjectHelper.inc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 06481a91..71d1aa2d 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1028,13 +1028,14 @@ class ObjectHelper { * @param $offset int * An integer, used to offset the results (results should be ordered, to * maintain consistency. + * * @return array * Indexed (numerical) array, containing a number of associative arrays, * with keys being the same as the variable names in the query. * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ - protected static function _perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { +static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { //Setup the query options... $options = array( 'type' => 'tuples', @@ -1078,7 +1079,7 @@ class ObjectHelper { $attrs = $element->attributes(); if (!empty($attrs['uri'])) { - $val = self::_pid_uri_to_bare_pid((string)$attrs['uri']); + $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); } else { $val = (string)$element; @@ -1099,7 +1100,7 @@ class ObjectHelper { * @see self::_perform_ri_query() */ public static function perform_itql_query($query, $limit = -1, $offset = 0) { - return self::_perform_ri_query($query, 'itql', $limit, $offset); + return self::perform_ri_query($query, 'itql', $limit, $offset); } /** * Thin wrapper for self::_perform_ri_query(). @@ -1107,7 +1108,7 @@ class ObjectHelper { * @see self::_perform_ri_query() */ public static function perform_sparql_query($query, $limit = -1, $offset = 0) { - return self::_perform_ri_query($query, 'sparql', $limit, $offset); + return self::perform_ri_query($query, 'sparql', $limit, $offset); } /** * Utility function used in self::_perform_ri_query(). @@ -1116,11 +1117,12 @@ class ObjectHelper { * * @param $uri string * A string containing a URI. + * * @return string * The input string less the 'info:fedora/' prefix (if it has it). * The original string otherwise. */ - protected static function _pid_uri_to_bare_pid($uri) { + protected static function pid_uri_to_bare_pid($uri) { $chunk = 'info:fedora/'; $pos = strpos($uri, $chunk); if ($pos === 0) { //Remove info:fedora/ chunk From f18ce11ba5076c3338af3b235de217c7a6dbe18f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 15:24:24 -0300 Subject: [PATCH 013/117] Overhaul FedoraObjectDetailedContent and Object helper. FODC tab now uses theme functions to generate the DC content, datastream info, and list of parents. Only thing not really being generated is the tiny (but repeated) form for downloading. Also, make the convertQDC XSLT a little simpler, even though it really won't need to be used anymore... Refactored to use the new RI search methods as well. --- CollectionClass.inc | 65 +++-- ObjectHelper.inc | 340 ++++++++++++------------ fedora_repository.module | 2 +- formClass.inc | 5 +- plugins/FedoraObjectDetailedContent.inc | 24 +- xsl/convertQDC.xsl | 6 +- 6 files changed, 234 insertions(+), 208 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 43d06be0..2d0c2b31 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -39,6 +39,36 @@ class CollectionClass { $this->pid = $pid; } } + + static function get_collection_query($pid) { + if ($query = self::_get_collection_query_from_stream($pid)) { + return $query; + } + else { + return self::_get_default_collection_query($pid); + } + } + + static function _get_collection_query_from_stream($pid) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($pid); + if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { + return $item->get_datastream_dissemination('QUERY'); + } + else { + return FALSE; + } + } + static function _get_default_collection_query($pid) { + return 'select $object $title $content from <#ri> + where ($object $title + and $object $content + and ($object + or $object ) + and $object ) + minus $content + order by $title'; + } /** * gets objects related to this object. must include offset and limit @@ -49,15 +79,11 @@ class CollectionClass { * @param type $itqlquery * @return type */ - function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { + static function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { if (!isset($itqlquery)) { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $item = new Fedora_Item($pid); - if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { - $itqlquery = $item->get_datastream_dissemination('QUERY'); - } + $itqlquery = self::get_collection_query($pid); } - return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); + return self::getRelatedItems($pid, $itqlquery, $limit, $offset); } /** @@ -70,7 +96,7 @@ class CollectionClass { * @param int $offset * @return type */ - function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { + static function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); if (!isset($offset)) { @@ -84,26 +110,11 @@ class CollectionClass { $objectHelper = new ObjectHelper(); $query_string = $itqlquery; if (!isset($query_string)) { - $query_string = NULL; - $item = new Fedora_Item($pid); - if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { - $query_string = $item->get_datastream_dissemination('QUERY'); - } - if ($query_string == NULL) { - $query_string = 'select $object $title $content from <#ri> - where ($object $title - and $object $content - and ($object - or $object ) - and $object ) - minus $content - order by $title'; - } - } - else { - // Replace %parent_collection% with the actual collection PID - $query_string = preg_replace("/\%parent_collection\%/", "", $query_string); + $query_string = self::get_collection_query($pid); } + + // Replace %parent_collection% with the actual collection PID + $query_string = preg_replace("/\%parent_collection\%/", "", $query_string); $query_string = htmlentities(urlencode($query_string)); diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 71d1aa2d..35200f87 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -313,36 +313,42 @@ class ObjectHelper { function create_link_for_ds($pid, $dataStreamValue) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - require_once($path . '/api/fedora_item.inc'); $item = new Fedora_Item($pid); + $purge_image = ' '; if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { $allow = TRUE; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); } if ($allow) { - $purgeImage = 'purge datastream'; + $purge_text = t("purge datastream @label", array('@label' => $dataStreamValue->label)); + $purge_path = "fedora/repository/purgeStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}"; + $purge_image = l(theme('image', "$path/images/purge.gif", $purge_text, $purge_text, NULL, FALSE), $purge_path, array( + 'html' => TRUE, + )); } } else { - $purgeImage = ' '; + $purge_image = ' '; } - $fullPath = base_path() . $path; // Add an icon to replace a datastream // @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled. - $replaceImage = ' '; + $replace_image = ' '; if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { $allow = TRUE; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); } if ($allow) { - $replaceImage = 'label . '" href="' . $base_url . '/fedora/repository/replaceStream/' . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '">replace datastream'; + $replace_text = t('Replace datastream "@label"', array('@label' => $dataStreamValue->label)); + $replace_path = "fedora/repository/replaceStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}"; + $replace_image = l(theme('image', "$path/images/replace.png", $replace_text, $replace_text, NULL, FALSE), $replace_path, array( + 'html' => TRUE, + )); } } @@ -350,13 +356,17 @@ class ObjectHelper { $id = $dataStreamValue->ID; $label = $dataStreamValue->label; $label = str_replace("_", " ", $label); + $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $mimeType = $dataStreamValue->MIMEType; - $view = '' . t('View') . ''; - $action = "$base_url/fedora/repository/object_download/" . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode(preg_replace('/\//i', '${1}_', $label)); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. + $view = l(t('View'), "'fedora/repository/$pid/$id/$label_deslashed", array( + 'attributes' => array( + 'target' => '_blank', + ), + )); + $action = url("fedora/repository/object_download/$pid/$id/$label_deslashed"); $downloadVersion = '
'; - if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { + if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { $versions = $item->get_datastream_history($id); if (is_array($versions)) { $downloadVersion = '
'; @@ -369,8 +379,23 @@ class ObjectHelper { } } - $content .= "$label $view $downloadVersion $mimeType $replaceImage $purgeImage\n"; - return $content; + return array( + array( + 'data' => $label, + ), + array( + 'data' => $view, + ), + array( + 'data' => $downloadVersion, + ), + array( + 'data' => $mimeType + ), + array( + 'data' => $replace_image . $purge_image, + ), + ); } /** @@ -386,34 +411,37 @@ class ObjectHelper { $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; $xmlstr = $item->get_datastream_dissemination($dsid); - - + if (empty($xmlstr)) { return ''; } + + $simplexml = new SimpleXMLElement($xmlstr); - try { - $proc = new XsltProcessor(); - } catch (Exception $e) { - drupal_set_message($e->getMessage(), 'error'); - return; + $headers = array( + array( + 'data' => t('Metadata'), + 'colspan' => 2, + ), + ); + $rows = array(); + dsm($xmlstr); + foreach ($simplexml->getNamespaces(TRUE) as $ns) { + foreach ($simplexml->children($ns) as $child) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => (string)$child, + 'class' => 'dc-content', + ), + ); + } } - $proc->setParameter('', 'baseUrl', $base_url); - $proc->setParameter('', 'path', $base_url . '/' . $path); - $input = NULL; - $xsl = new DomDocument(); - try { - $xsl->load($path . '/xsl/convertQDC.xsl'); - $input = new DomDocument(); - $input->loadXML(trim($xmlstr)); - } catch (Exception $e) { - watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); - } - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); - $output = $newdom->saveHTML(); - return $output; + return theme('table', $headers, $rows, array('class' => 'dc-table')); } /** @@ -432,16 +460,17 @@ class ObjectHelper { $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; if (module_exists('fedora_fesl')) { $allow = fedora_fesl_check_roles($pid, 'write'); } if ($allow) { - - $output .= '
' . t('Edit Meta Data') . ''; + $link_image = theme('image', "$path/images/edit.gif", t('Edit Metadata')); + $link = l($link_image, "fedora/repository/editmetadata/$pid", array( + 'html' => TRUE, + )); + $output .= '
' . $link; } } return $output; @@ -461,7 +490,7 @@ class ObjectHelper { * */ function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) { - global $fedoraUser, $fedoraPass, $base_url, $user; + global $base_url, $user; module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -473,58 +502,42 @@ class ObjectHelper { if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) { $availableDataStreamsText = 'Detailed List of Content'; - //$metaDataText='Description'; + $mainStreamLabel = NULL; $object = $fedoraItem->get_datastreams_list_as_SimpleXML(); if (!isset($object)) { drupal_set_message(t("No datastreams available")); return ' '; } - $hasOBJStream = NULL; - $hasTNStream = FALSE; - $dataStreamBody = "
\n"; $cmDatastreams = array(); if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE && ($cm = ContentModel::loadFromObject($object_pid)) !== FALSE) { $cmDatastreams = $cm->listDatastreams(); } - $dataStreamBody .= $this->get_parent_objects_asHTML($object_pid); - $dataStreamBody .= ''; + $headers = array( + array( + 'data' => $availableDataStreamsText, + 'colspan' => 4, + ), + ); + $DSs = array(); foreach ($object as $datastream) { foreach ($datastream as $datastreamValue) { - if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) { - if ($datastreamValue->ID == 'OBJ') { - $hasOBJStream = '1'; - $mainStreamLabel = $datastreamValue->label; - $mainStreamLabel = str_replace("_", " ", $mainStreamLabel); - } - if ($datastreamValue->ID == 'TN') { - $hasTNStream = TRUE; - } + if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) { //create the links to each datastream - $dataStreamBody .= $this->create_link_for_ds($object_pid, $datastreamValue); //"\n"; + $DSs []= $this->create_link_for_ds($object_pid, $datastreamValue); } } } - $dataStreamBody .= "

' . t("!text", array('!text' => $availableDataStreamsText)) . '

$key :$value
\n"; + + $dataStreamBody = theme('table', $headers, $DSs); //if they have access let them add a datastream - if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { - $allow = TRUE; - if (module_exists('fedora_fesl')) { - $allow = fedora_fesl_check_roles($object_pid, 'write'); - } - if ($allow) { - $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid); - } + if (user_access(ObjectHelper::$ADD_FEDORA_STREAMS) && //If allowed throw Drupal + ((module_exists('fedora_fesl') && fedora_fesl_check_roles($object_pid, 'write')) || //And allowed throw FESL + !module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form. + $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid); } - $fieldset = array( - '#title' => t("!text", array('!text' => $availableDataStreamsText)), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#value' => $dataStreamBody - ); - $dataStreamBody = '
' . theme('fieldset', $fieldset) . '
'; return $dataStreamBody; } @@ -616,55 +629,44 @@ class ObjectHelper { * @param type $pid * @return type */ - function fedora_repository_access($op, $pid) { - global $user; - + function fedora_repository_access($op, $pid = NULL, $as_user = NULL) { $returnValue = FALSE; - $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); - if (!$isRestricted) { - $namespaceAccess = TRUE; - } + if ($pid == NULL) { $pid = variable_get('fedora_repository_pid', 'islandora:root'); } - $nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); - $pos = NULL; - foreach ($nameSpaceAllowed as $nameSpace) { - $pos = stripos($pid, $nameSpace); - if ($pos === 0) { - $namespaceAccess = TRUE; - } - } - if ($namespaceAccess) { - $user_access = user_access($op); - if ($user_access == NULL) { - return FALSE; - } - return $user_access; + + $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); + $namespace_access = NULL; + if (!$isRestricted) { + $namespace_access = TRUE; } - else { - return FALSE; + else { + $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon) + $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); + + $namespace_access = in_array($pid_namespace, $allowed_namespaces); } + + return ($namespace_access && user_access($op, $as_user)); } /** * internal function * uses an xsl to parse the sparql xml returned from the ITQL query - * - * + * @deprecated + * This is only used in the fedora/repository/collection path, + * which should probably be nuked. * @param $content String */ function parseContent($content, $pid, $dsId, $collection, $pageNumber = NULL) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; $collection_pid = $pid; //we will be changing the pid later maybe - //module_load_include('php', ''Fedora_Repository'', 'ObjectHelper'); $objectHelper = $this; $parsedContent = NULL; - $contentModels = $objectHelper->get_content_models_list($pid); + $contentModels = $this->get_content_models_list($pid); $isCollection = FALSE; - //if this is a collection object store the $pid in the session as it will come in handy - //after a purge or ingest to return to the correct collection. $fedoraItem = NULL; $datastreams = $this->get_formatted_datastream_list($pid, $contentModels, $fedoraItem); @@ -672,6 +674,9 @@ class ObjectHelper { if (!empty($contentModels)) { foreach ($contentModels as $contentModel) { if ($contentModel == variable_get('fedora_collection_model_pid', 'islandora:collectionCModel')) { + //if this is a collection object store the $pid in the session as it will come in handy + //after a purge or ingest to return to the correct collection. + $_SESSION['fedora_collection'] = $pid; $isCollection = TRUE; } @@ -689,8 +694,8 @@ class ObjectHelper { if ($results->length > 0 || $isCollection == TRUE) { // if(strlen($objectList)>22||$contentModel=='Collection'||$contentModel=='Community')//length of empty dom still equals 22 because of etc module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy'); - $collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID()); - if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { + $collectionPolicyExists = $this->getMimeType($pid, CollectionPolicy::getDefaultDSID()); + if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (!empty($collectionPolicyExists)) { $allow = TRUE; if (module_exists('fedora_fesl')) { @@ -745,19 +750,34 @@ class ObjectHelper { return $output; } + /** + * Get the query to find parent objects. + * + * @param $pid string + * A string containing a Fedora PID to find the parents for. + * @return string + * A string containing an iTQL query, selecting something into $object and $title + */ + static function _parent_query($pid) { + return 'select $object $title from <#ri> + where ($object $title + and $object + and $object ) + order by $title'; + } + /** * Gets the parent objects that this object is related to * - * @param unknown_type $pid - * @return unknown + * @param $pid string + * A string containing a Fedora PID to find the parents for. + * @return string + * A string containing Sparql XML (the results of the self::_parent_query()) */ function get_parent_objects($pid) { - $query_string = 'select $object $title from <#ri> - where ($object $title - and $object - and $object ) - order by $title'; - $objects = $this->getCollectionInfo($pid, $query_string); + $query_string = self::_parent_query(); + module_load_include('inc', 'fedora_repository', 'CollectionClass'); + $objects = CollectionClass::getRelatedItems($pid, $query_string); return $objects; } @@ -768,31 +788,24 @@ class ObjectHelper { * @return string */ function get_parent_objects_asHTML($pid) { - global $base_url; - $parent_collections = $this->get_parent_objects($pid); - try { - $parent_collections = new SimpleXMLElement($parent_collections); - } catch (exception $e) { - drupal_set_message(t('Error getting parent objects @e', array('@e' => check_plain($e->getMessage())))); - return; - } - - $parent_collections_HTML = ''; - foreach ($parent_collections->results->result as $result) { - $collection_label = $result->title; - foreach ($result->object->attributes() as $a => $b) { - if ($a == 'uri') { - $uri = (string) $b; - $uri = $base_url . '/fedora/repository' . substr($uri, strpos($uri, '/')) . '/-/' . $collection_label; - } - } - $parent_collections_HTML .= '' . $collection_label . '
'; + module_load_include('inc', 'fedora_repository', 'CollectionClass'); + $results = self::perform_itql_query(self::_parent_query($pid)); + + $parent_collections = array(); + foreach ($results as $result) { + $collection_title = $result['title']; + $collection_pid = $result['object']; + $path = "fedora/repository/$collection_pid/-/$collection_title"; + $parent = array( + 'data' => l($collection_title, $path), + ); + + $parent_collections[] = $parent; } - if (!empty($parent_collections_HTML)) { - $parent_collections_HTML = '
'; + + if (!empty($parent_collections)) { + return theme('item_list', $parent_collections, t('Belongs to these collections'), 'ul'); } - - return $parent_collections_HTML; } /** @@ -842,6 +855,8 @@ class ObjectHelper { /** * Get a tree of related pids - for the basket functionality * + * FIXME: This doesn't actually get a tree... + * * @param type $pid * @return type */ @@ -852,19 +867,18 @@ class ObjectHelper { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); // Get title and descriptions for $pid - $query_string = 'select $title $desc from <#ri> + $query_string = 'select $title $description from <#ri> where $o $title and $o $desc and $o '; - - $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query="; - $content = do_curl($url . htmlentities(urlencode($query_string))); - - $rows = explode("\n", $content); - $fields = explode(',', $rows[1]); - - $pids[$pid] = array('title' => $fields[0], 'description' => $fields[1]); + + $results = self::perform_itql_query($query_string); + + $pids = array(); + //There should only be one... Anyway. + foreach($results as $result) { + $pids[$pid] = $result; + } // $pids += $this->get_child_pids(array($pid)); @@ -878,38 +892,24 @@ class ObjectHelper { * @return type */ function get_child_pids($pids) { + //Build the parts which are used to filter to the list of input. + $query_chunks = array(); + foreach ($pids as $pid) { + $query_chunks[] = '$s '; + } // Get pid, title and description for children of object $pid $query_string = 'select $o $title from <#ri> ' . -// $query_string = 'select $o $title $desc from <#ri> '. 'where $s $o ' . 'and $o $title ' . -// 'and $o $desc '. - 'and ( '; - - foreach ($pids as $pid) { - $query_string .= '$s or '; - } - $query_string = substr($query_string, 0, -3) . ' )'; - - $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query="; - $url .= htmlentities(urlencode($query_string)); - $content = $this->doCurl($url); - - $rows = explode("\n", $content); - // Knock of the first heading row - array_shift($rows); + 'and ( ' . implode(' or ', $query_chunks) . ' )'; + + $results = self::perform_itql_query($query_string); $child_pids = array(); - if (count($rows)) { + if ($results) { // iterate through each row - foreach ($rows as $row) { - if ($row == "") { - continue; - } - $fields = explode(',', $row); - $child_pid = substr($fields[0], 12); - $child_pids[$child_pid] = array('title' => $fields[1], 'description' => $fields[2]); + foreach ($results as $result) { + $child_pids[$result['o']] = array('title' => $result['title']); } if (!empty($child_pids)) { $child_pids += $this->get_child_pids(array_keys($child_pids)); diff --git a/fedora_repository.module b/fedora_repository.module index 8a80c8e3..e83d91f5 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -869,7 +869,7 @@ function fedora_repository_perm() { * @param type $account * @return type */ -function fedora_repository_access($op, $node, $account) { +function fedora_repository_access($op, $node = NULL, $account = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $objectHelper = new ObjectHelper(); return $objectHelper->fedora_repository_access($op, $node, $account); diff --git a/formClass.inc b/formClass.inc index 1d752f3d..4bd1e132 100644 --- a/formClass.inc +++ b/formClass.inc @@ -13,8 +13,8 @@ class formClass { function formClass() { - module_load_include('inc', 'formClass', ''); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); } /** @@ -128,7 +128,8 @@ class formClass { 'title' => t('Collection view'), 'page callback' => 'fedora_collection_view', 'type' => MENU_CALLBACK, - 'access argruments' => array('view fedora collection') + 'access callback' => 'fedora_repository_access', + 'access argruments' => array(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA), ); //new for mnpl****************************************** diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 9283acb2..30e222a6 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -48,10 +48,9 @@ class FedoraObjectDetailedContent { $tabset['fedora_object_details']['tabset'] = array( '#type' => 'tabset', ); + $dc_html = $objectHelper->getFormattedDC($this->item); - $ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item); - $i = 0; if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { $tabset['fedora_object_details']['tabset']['view'] = array( @@ -63,9 +62,24 @@ class FedoraObjectDetailedContent { '#weight' => $i++ ), 'list' => array( - '#type' => 'markup', - '#value' => $ds_list, //XXX: The function called here could be cleaned up a fair bit as well... - '#weight' => $i++ + '#type' => 'fieldset', + '#title' => t('Detailed List of Content'), + '#attributes' => array( + 'class' => 'fedora_detailed_list', + ), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => $i++, + 'parents' => array( + '#type' => 'markup', + '#value' => $objectHelper->get_parent_objects_asHTML($this->pid), + '#weight' => $i++, + ), + 'datastreams' => array( + '#type' => 'markup', + '#value' => $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item), //XXX: The function called here could be cleaned up a fair bit as well... + '#weight' => $i++, + ), ), 'purge' => array( '#type' => 'markup', diff --git a/xsl/convertQDC.xsl b/xsl/convertQDC.xsl index c2bb50f0..5d881e35 100644 --- a/xsl/convertQDC.xsl +++ b/xsl/convertQDC.xsl @@ -12,13 +12,13 @@ - + - From 7934e43880aa87d8827caf765b6f6d45a6be5ea5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 15:32:07 -0300 Subject: [PATCH 014/117] Fix string which was bugging me. --- ObjectHelper.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 35200f87..5da8fdfd 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -324,7 +324,7 @@ class ObjectHelper { $allow = fedora_fesl_check_roles($pid, 'write'); } if ($allow) { - $purge_text = t("purge datastream @label", array('@label' => $dataStreamValue->label)); + $purge_text = t('Purge datastream "@label"', array('@label' => $dataStreamValue->label)); $purge_path = "fedora/repository/purgeStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}"; $purge_image = l(theme('image', "$path/images/purge.gif", $purge_text, $purge_text, NULL, FALSE), $purge_path, array( 'html' => TRUE, From 548861b7bc444351a99207d621de2fbdcbd1fa55 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 16:17:53 -0300 Subject: [PATCH 015/117] Avoid DSMing the DC... Derp. --- ObjectHelper.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 5da8fdfd..16076a18 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -425,7 +425,6 @@ class ObjectHelper { ), ); $rows = array(); - dsm($xmlstr); foreach ($simplexml->getNamespaces(TRUE) as $ns) { foreach ($simplexml->children($ns) as $child) { $rows[] = array( From a5e6054fbdc9d9a78c5f729f687b4db2a6d11bf5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 18:09:20 -0300 Subject: [PATCH 016/117] Extract the Sparql parser out, so it might be used elsewhere during transition. --- ObjectHelper.inc | 72 +++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 16076a18..7fed4f86 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1015,6 +1015,48 @@ class ObjectHelper { drupal_set_message(t($configMess . "
" . $messMap[$app] . "
", array('%app' => $app)), 'warning', FALSE); } + /** + * Parse the passed in Sparql XML string into a more easily usable format. + * + * @param $sparql string + * A string containing Sparql result XML. + * @return array + * Indexed (numerical) array, containing a number of associative arrays, + * with keys being the same as the variable names in the query. + * URIs beginning with 'info:fedora/' will have this beginning stripped + * off, to facilitate their use as PIDs. + */ + public static function parse_sparql_results($sparql) { + //Load the results into a SimpleXMLElement + $doc = new SimpleXMLElement($sparql, 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); + + $results = array(); //Storage. + + //Build the results. + foreach ($doc->results->children() as $result) { + //Built a single result. + $r = array(); + foreach ($result->children() as $element) { + $val = NULL; + + $attrs = $element->attributes(); + if (!empty($attrs['uri'])) { + $val = self::_pid_uri_to_bare_pid((string)$attrs['uri']); + } + else { + $val = (string)$element; + } + + //Map the name to the value in the array. + $r[$element->getName()] = $val; + } + + //Add the single result to the set to return. + $results[] = $r; + } + return $results; + } + /** * Performs the given Resource Index query and return the results. * @@ -1064,34 +1106,8 @@ static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = return FALSE; } - //Load the results into a SimpleXMLElement - $doc = new SimpleXMLElement($curl_result[0], 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); - - $results = array(); //Storage. - - //Build the results. - foreach ($doc->results->children() as $result) { - //Built a single result. - $r = array(); - foreach ($result->children() as $element) { - $val = NULL; - - $attrs = $element->attributes(); - if (!empty($attrs['uri'])) { - $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); - } - else { - $val = (string)$element; - } - - //Map the name to the value in the array. - $r[$element->getName()] = $val; - } - - //Add the single result to the set to return. - $results[] = $r; - } - return $results; + //Pass the query's results off to a decent parser. + return self::parse_sparql_results($curl_result[0]); } /** * Thin wrapper for self::_perform_ri_query(). From 4182bfac277a280473c06371efc409f347d5d29b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 18:10:35 -0300 Subject: [PATCH 017/117] Add the ability to render a collection view without an XSLT. --- CollectionClass.inc | 245 +++++++++++++++++++++++++++++--------------- 1 file changed, 165 insertions(+), 80 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 2d0c2b31..2bed9a6c 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -71,58 +71,79 @@ class CollectionClass { } /** - * gets objects related to this object. must include offset and limit - * calls getRelatedItems but enforces limit and offset - * @param type $pid - * @param type $limit + * Gets objects related to this object. Must include offset and limit! + * + * Calls self::getRelatedItems() but requires limit and offset. + * + * @param $pid string + * A string containing a Fedora PID. + * @param $limit + * An integer * @param type $offset * @param type $itqlquery * @return type */ static function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { - if (!isset($itqlquery)) { - $itqlquery = self::get_collection_query($pid); - } return self::getRelatedItems($pid, $itqlquery, $limit, $offset); } /** - * Gets objects related to this item. It will query the object for a Query stream and use that as a itql query - * or if there is no query stream it will use the default. If you pass a query to this method it will use the passed in query no matter what - * @global type $user - * @param type $pid - * @param type $itqlquery - * @param int $limit + * Gets objects related to this item. + * + * Query the resource index using the provided iTQL query. If no query is + * provided, one should be obtained via self::get_collection_query() which + * grabs the child objects. + * + * @param $pid string + * A string containing a PID which may be substituted into the query, + * in place of the %parent_collection% placeholder. + * @param $itqlquery string + * An optional iTQL query. + * @param $limit int + * An optional integer to limit the number of results returned. * @param int $offset - * @return type + * An optional integer used to offset the results returned. (Query should + * involve a sort to maintain consistency. + * @return string + * Sparql XML results from the resource index. */ - static function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { + static function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - if (!isset($offset)) { - $offset = 0; - } - global $user; - if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { + + if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); return ' '; } $objectHelper = new ObjectHelper(); - $query_string = $itqlquery; - if (!isset($query_string)) { + + if ($query_string === NULL) { $query_string = self::get_collection_query($pid); } - + // Replace %parent_collection% with the actual collection PID $query_string = preg_replace("/\%parent_collection\%/", "", $query_string); - $query_string = htmlentities(urlencode($query_string)); - - $content = ''; $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query_string; - $content .= do_curl($url); + + $settings = array( + 'type' => 'tuples', + 'flush' => TRUE, + 'format' => 'Sparql', + 'lang' => 'itql', + 'stream' => 'on', + 'query' => $query_string + ); + if ($limit > 0) { + $settings['limit'] = $limit; + } + if ($offset > 0) { + $settings['offset'] = $offset; + } + + $url .= '?' . http_build_query($settings, NULL, '&'); + $content = do_curl($url); return $content; } @@ -501,9 +522,12 @@ class CollectionClass { module_load_include('inc', 'fedora_repository', 'CollectionClass'); $collectionClass = new CollectionClass(); $xslContent = $collectionClass->getCollectionViewStream($pid); - if (!$xslContent && $canUseDefault) { //no xslt so we will use the default sent with the module + + //If there's no XSLT from the object, then check if the one which used to exist, does... + if (!$xslContent && $canUseDefault && file_exists($path . '/xsl/sparql_to_html.xsl')) { $xslContent = file_get_contents($path . '/xsl/sparql_to_html.xsl'); } + return $xslContent; } @@ -530,7 +554,6 @@ class CollectionClass { $results = $this->getRelatedItems($this->pid, $query); $collection_items = $this->renderCollection($results, $this->pid, NULL, NULL, $page_number); - //$collection_item = new Fedora_Item($this->pid); //XXX: This didn't seem to be used... $show_batch_tab = FALSE; $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); @@ -565,17 +588,6 @@ class CollectionClass { '#tab_name' => 'add-tab', ); } - - if ($show_batch_tab && user_access('create batch process')) { //XXX: Is this not put in by the batch module? - $tabset['batch_ingest_tab'] = array( - // #type and #title are the minimum requirements. - '#type' => 'tabpage', - '#title' => t('Batch Ingest'), - // This will be the content of the tab. - '#content' => drupal_get_form('batch_creation_form', $this->pid, $content_models), - '#tab_name' => 'batch-ingest-tab', - ); - } return $tabset; } @@ -608,6 +620,33 @@ class CollectionClass { return $ingestObject; } + /** + * Unfortunate function, I know... + * + * Does just what it says: Hacks the default Drupal pager such that it might + * be rendered. + */ + protected static function _hack_pager($pager_name, $per_page, $total_items) { + global $pager_total, $pager_page_array; + $pager_total[$pager_name] = ceil($total_items / $per_page); + + $page_info = explode(',', isset($_GET['page']) ? $_GET['page'] : ''); + $page = $page_info[$pager_name]; + if ($page < 0) { + $page = 0; + } + + if (!isset($pager_page_array)) { + $pager_page_array = pager_load_array($page, $pager_name, $page_info); + } + else { + $pager_page_array = pager_load_array($page, $pager_name, $pager_page_array); + } + + $page = $pager_page_array[$pager_name]; + return $page; + } + /** * render collection * @global type $base_url @@ -631,60 +670,106 @@ class CollectionClass { $fedoraItem = NULL; - if (!$pageNumber) { - $pageNumber = 1; - } - if (empty($collectionName)) { $collectionName = menu_get_active_title(); } $xslContent = $this->getXslContent($pid, $path); - //get collection list and display using xslt------------------------------------------- $objectList = ''; if (isset($content) && $content != FALSE) { - $input = new DomDocument(); - $input->loadXML(trim($content)); - $results = $input->getElementsByTagName('result'); - if ($results->length > 0) { - try { - $proc = new XsltProcessor(); - $options = array( //Could make this the return of a hook? - 'collectionPid' => $collection_pid, - 'collectionTitle' => $collectionName, - 'baseUrl' => $base_url, - 'path' => "$base_url/$path", - 'hitPage' => $pageNumber, + if (!$xslContent) { //Didn't find an XSLT. + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + $intermediate_results = ObjectHelper::parse_sparql_results($content); + unset($content); + + $per_page = 20; //XXX: Make this configurable. + $pager_name = 0; + $total = count($intermediate_results); + $pager_page = self::_hack_pager($pager_name, $per_page, $total); + + $results = array(); + foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) { + $title = $result['title']; + $obj_path = "fedora/repository/{$result['object']}"; + $thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE); + $results[] = array( + array( + 'data' => l($thumbnail, $obj_path, array( + 'html' => TRUE, + )), + ), + array( + 'data' => l($title, $obj_path), + ), ); - - if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50100) { - $proc->setParameter('', $options); - } - else { - foreach ($options as $name => $value) { - $proc->setParameter('', $name, $value); + } + if (!$results) { + drupal_set_message(t("No objects in this collection (or bad query).")); + } + else { + $first = $per_page * $pager_page; + $last = (($total - $first) > $per_page)? + ($first + $per_page): + $total; + $objectList = '

' . t('Results @first to @last of @total', array( + '@first' => $first + 1, + '@last' => $last, + '@total' => $total, + )) . '

'; + $objectList .= theme('pager', array(), $per_page, $pager_name); + $objectList .= theme('table', NULL, $results); + $objectList .= theme('pager', array(), $per_page, $pager_name); + } + } + else { + if (!$pageNumber) { + $pageNumber = 1; + } + + //get collection list and display using xslt------------------------------------------- + $input = new DomDocument(); + $input->loadXML(trim($content)); + $results = $input->getElementsByTagName('result'); + if ($results->length > 0) { + try { + $proc = new XsltProcessor(); + $options = array( //Could make this the return of a hook? + 'collectionPid' => $collection_pid, + 'collectionTitle' => $collectionName, + 'baseUrl' => $base_url, + 'path' => "$base_url/$path", + 'hitPage' => $pageNumber, + ); + + if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50100) { + $proc->setParameter('', $options); + } + else { + foreach ($options as $name => $value) { + $proc->setParameter('', $name, $value); + } } - } - $proc->registerPHPFunctions(); - $xsl = new DomDocument(); - $xsl->loadXML($xslContent); - // php xsl does not seem to work with namespaces so removing it below - // I may have just been being stupid here - // $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content); + $proc->registerPHPFunctions(); + $xsl = new DomDocument(); + $xsl->loadXML($xslContent); + // php xsl does not seem to work with namespaces so removing it below + // I may have just been being stupid here + // $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content); - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); - $objectList = $newdom->saveXML(); //is the xml transformed to html as defined in the xslt associated with the collection object + $objectList = $newdom->saveHTML(); //is the xml transformed to html as defined in the xslt associated with the collection object - if (!$objectList) { - throw new Exception("Invalid XML."); + if (!$objectList) { + throw new Exception("Invalid XML."); + } + } catch (Exception $e) { + drupal_set_message(check_plain($e->getMessage()), 'error'); + return ''; } - } catch (Exception $e) { - drupal_set_message(check_plain($e->getMessage()), 'error'); - return ''; } } } From eaff54436b3a13663b5987086eda6c11d2594704 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 10:25:45 -0300 Subject: [PATCH 018/117] Get rid of more explicit markup output, in favour of Drupal methods. --- ObjectHelper.inc | 8 ++- formClass.inc | 5 +- plugins/ShowDemoStreamsInFieldSets.inc | 5 +- plugins/ShowStreamsInFieldSets.inc | 42 ++++++----- plugins/herbarium.inc | 4 +- plugins/qt_viewer.inc | 99 +++++++++++++++----------- plugins/slide_viewer.inc | 6 +- plugins/tagging_form.inc | 30 +++++--- 8 files changed, 116 insertions(+), 83 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 7fed4f86..18000b80 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -702,9 +702,11 @@ class ObjectHelper { } if ($allow) { // $ingestObject = ' $collectionName, '!collection_pid' => $collection_pid)) . '" href="' . base_path() . - 'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '">' . t('Add a New Object') . ' ' . t('Add to this Collection'); + $ingest_text = t('Ingest a new object into @collection_name PID @collection_pid', array('@collection_name' => $collectionName, '@collection_pid' => $collection_pid)); + $ingestObject = l(theme('image', "$path/images/ingest.png", $ingest_text), "fedora/ingestObject/$collection_pid/$collectionName", array('attributes' => array( + 'class' => 'icon', + 'title' => $ingest_text, + ))) . t('Add to this Collection'); } } } diff --git a/formClass.inc b/formClass.inc index 4bd1e132..d6cb23df 100644 --- a/formClass.inc +++ b/formClass.inc @@ -230,7 +230,10 @@ class formClass { '#description' => t('The URL to use for SOAP connections'), '#required' => TRUE, '#weight' => -12, - '#suffix' => '

' . (fedora_available() ? '' . t('Successfully connected to Fedora server at !fedora_soap_url', array('!fedora_soap_url' => variable_get('fedora_soap_url', ''))) : ' ' . t('Unable to connect to Fedora server at !fedora_soap_url

', array('!fedora_soap_url' => variable_get('fedora_soap_url', '')))), + '#suffix' => '

' . ( + fedora_available() ? + theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) : + theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '

', ); $form['fedora_soap_manage_url'] = array( diff --git a/plugins/ShowDemoStreamsInFieldSets.inc b/plugins/ShowDemoStreamsInFieldSets.inc index 80f8017c..9d210d2a 100644 --- a/plugins/ShowDemoStreamsInFieldSets.inc +++ b/plugins/ShowDemoStreamsInFieldSets.inc @@ -29,11 +29,10 @@ class ShowDemoStreamsInFieldSets { * @return type */ function showMediumSize() { - global $base_url; + $path = "fedora/repository/{$this->pid}/MEDIUM_SIZE"; $collection_fieldset = array( '#collapsible' => FALSE, - '#value' => '', + '#value' => l(theme('image', $path), $path, array('html' => TRUE)), ); return theme('fieldset', $collection_fieldset); } diff --git a/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index 9e20ca5a..0bbf9403 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -29,15 +29,21 @@ class ShowStreamsInFieldSets { function showFlv() { //FLV is the datastream id $path = drupal_get_path('module', 'Fedora_Repository'); - $fullPath = base_path() . $path; + $fullPath = url($path); $content = ""; $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js'; drupal_add_js("$pathTojs"); - $content .= '
Get the Flash Player to see this player.
'; - drupal_add_js('var s1 = new SWFObject("' . $fullPath . '/flash/flvplayer.swf","single","320","240","7"); - s1.addParam("allowfullscreen","TRUE"); - s1.addVariable("file","' . base_path() . 'fedora/repository/' . $this->pid . '/FLV/FLV.flv"); - s1.write("player' . $this->pid . 'FLV");', 'inline', 'footer'); + $div_id = "player' . $this->pid . 'FLV"; + $content .= <<Get the Flash Player to see this player. +EOH; + drupal_add_js(<<pid}/FLV/FLV.flv"); +s1.write("$div_id"); +EOJS +, 'inline', 'footer'); $collection_fieldset = array( '#title' => t('Flash Video'), '#collapsible' => TRUE, @@ -48,30 +54,26 @@ class ShowStreamsInFieldSets { /** * Show the TN ?? - * @global type $base_url * @return type */ function showTN() { - global $base_url; $collection_fieldset = array( '#title' => '', '#attributes' => array(), '#collapsible' => FALSE, - '#value' => '', + '#value' => l(theme('image', "fedora/repository/{$this->pid}/TN/TN", '', '', NULL, FALSE), "fedora/repository/{$this->pid}/OBJ", array('html' => TRUE)), ); return theme('fieldset', $collection_fieldset); } /** * Same as showTN but artinventory stores the image in a dsid of IMAGE instead of OBJ - * @global type $base_url * @return type */ function showArtInventoryTN() { - global $base_url; $collection_fieldset = array( '#collapsible' => FALSE, - '#value' => '', + '#value' => l(theme('image', "fedora/repository/{$this->pid}/TN/TN", '', '', NULL, FALSE), "fedora/repository/{$this->pid}/IMAGE/image.jpg", array('html' => TRUE)), ); return theme('fieldset', $collection_fieldset); } @@ -102,14 +104,16 @@ class ShowStreamsInFieldSets { $objectHelper = new ObjectHelper(); $item = new Fedora_Item($this->pid); if (key_exists('TN', $item->datastreams)) { - $tn_url = $base_url . '/fedora/repository/' . $item->pid . '/TN'; + $tn_url = "fedora/repository/{$item->pid}/TN"; } else { - $tn_url = $base_path . drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_app_download_manager.png'; + $tn_url = drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_app_download_manager.png'; } + $tn_url = url($tn_url); + $dc_html = $objectHelper->getFormattedDC($item); - $dl_link = l('

' . t('View Document') .'
', 'fedora/repository/' . $this->pid . '/OBJ', array('html' => TRUE)); + $dl_link = l('
' . theme('image', $tn_url, '', '', NULL, FALSE) . '
' . t('View Document') .'
', "fedora/repository/{$this->pid}/OBJ", array('html' => TRUE)); $tabset['first_tab']['tabs']['view'] = array( '#type' => 'tabpage', @@ -126,11 +130,13 @@ class ShowStreamsInFieldSets { ); } + $viewer_url = 'http://docs.google.com/viewer?url=' . url("fedora/repository/{$this->pid}/OBJ/preview.pdf", array('absolute' => TRUE)) . '&embedded=TRUE'; $tabset['second_tab'] = array( '#type' => 'tabpage', '#title' => t('Read Online'), - '#content' => "" + '#content' => <<" +EOM ); // Render the tabset. @@ -164,7 +170,7 @@ class ShowStreamsInFieldSets { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($this->pid); $streams = $item->get_datastreams_list_as_array(); - return "" . $streams['OBJ']['label'] . ""; + return l($streams['OBJ']['label'], "fedora/repository/{$this->pid}/OBJ"); } /** diff --git a/plugins/herbarium.inc b/plugins/herbarium.inc index f7a6d685..0ad13fd6 100644 --- a/plugins/herbarium.inc +++ b/plugins/herbarium.inc @@ -161,13 +161,13 @@ class Herbarium { '#title' => t('Full-size'), '#content' => $html ); + $image = theme('image', "fedora/imageapi/{$this->pid}/JPG/JPG.jpg", '', '', NULL, FALSE); $tabset['first_tab'] = array( // #type and #title are the minimum requirements. '#type' => 'tabpage', '#title' => t('View'), // This will be the content of the tab. - '#content' => '' . '

' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', + '#content' => l($image, "fedora/repository/{$this->pid}/FULL_JPG", array('html' => TRUE)), '

' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', ); $dwc = new DarwinCore($this->item); diff --git a/plugins/qt_viewer.inc b/plugins/qt_viewer.inc index e52e4363..e321f00f 100644 --- a/plugins/qt_viewer.inc +++ b/plugins/qt_viewer.inc @@ -125,59 +125,76 @@ class ShowQtStreamsInFieldSets { if ($media === FALSE) { return ''; } - global $base_url; + $path = drupal_get_path('module', 'Fedora_Repository'); - $fullPath = base_path() . $path; - $content = ''; - $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/AC_Quicktime.js'; - drupal_add_js($pathTojs); + + drupal_add_js("$path/js/AC_Quicktime.js"); $divid = 'player' . md5($this->pid) . 'MOV'; - $content .= '
'; + + $collection_fieldset = array( + '#title' => t('Quicktime'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + 'player' => array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + ), + ); + if ($pframe !== FALSE) { - $content .= '
'; - $content .= ''; - $content .= '
â–¶
'; - $content .= '
'; + $collection_fieldset['player']['poster_container'] = array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + 'poster' => array( + '#type' => 'markup', + '#value' => theme('image', "fedora/repository/{$this->pid}/{$pframe->ID}/poster.jpg", '', '', NULL, FALSE) + ) + 'play' => array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + '#value' => ' ', + ), + ); } - $content .= '
'; if ($this->enableDownload()) { - $url = base_path() . 'fedora/repository/' . $this->pid . '/OBJ/MOV.mov'; - $content .= 'Download Media File'; + //$url = url(); + $collection_fieldset['download_link'] = array( + '#type' => 'markup', + '#value' => l(t('Download Media File'), "fedora/repository/{$this->pid}/OBJ/MOV.mov", array('attributes' => array('class' => 'download'))), + ); } - $src = base_path() . 'fedora/repository/' . $this->pid . '/' . $media->ID . '/MOV.mov'; - $qtparams = ''; - $qtparams .= "'autostart', '" . ($pframe !== FALSE ? 'TRUE' : 'FALSE') . "', "; + $src = url("fedora/repository/{$this->pid}/{$media->ID}/MOV.mov"; + + $qtparams = "'autostart', '" . ($pframe !== FALSE ? 'TRUE' : 'FALSE') . "', "; $init = << t('Quicktime'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - '#value' => $content); return theme('fieldset', $collection_fieldset); } diff --git a/plugins/slide_viewer.inc b/plugins/slide_viewer.inc index f3bdd6b9..729e824e 100644 --- a/plugins/slide_viewer.inc +++ b/plugins/slide_viewer.inc @@ -30,14 +30,13 @@ class ShowSlideStreamsInFieldSets { function showJPG() { module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets'); - global $base_url; global $user; $tabset = array(); $qs = ''; if ($user->uid != 0) { - $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); + $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); //XXX: Base64 encoding is not encryption; SSL would be nice... } $viewer_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs; @@ -55,8 +54,7 @@ class ShowSlideStreamsInFieldSets { '#type' => 'tabpage', '#title' => t('View'), // This will be the content of the tab. - '#content' => '' . '

' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', + '#content' => theme('image', "fedora/imageapi/{$this->pid}/JPG/JPG.jpg", '', '', NULL, FALSE) . '

' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', ); return $tabset; diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index 390bf36c..f00274d4 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -19,13 +19,15 @@ function _show_subject_tags($pid) { $obj = new Fedora_Item($pid); $tags = new TagSet($obj); if (!empty($tags->tags)) { - $output = "
    "; + $items = array(); foreach ($tags->tags as $tag) { - $output .= "
  • "; + return theme('item_list', $items); } - return $output; } /** @@ -57,21 +59,27 @@ function fedora_repository_image_tagging_form($form_state, $pid) { // Add the current tags to the form. $tagset = new TagSet($obj); + $tags = array(); foreach ($tagset->tags as $tag) { - $form['tags-wrapper']['tags'][$tag['name']] = array( + $form_tag =& $form['tags-wrapper']['tags'][$tag['name']] = array( '#prefix' => '
  • ', '#suffix' => '
  • ', ); - $form['tags-wrapper']['tags'][$tag['name']]['tag'] = array( - '#prefix' => '', - '#value' => $tag['name'], - '#suffix' => '', + + $tag_title_text = t('Added by @creator.', array( + '@creator' => $tag['creator'], + )); + $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}" + $form_tag['tag'] = array( + '#value' => l($tag['name'], $tag_mnpl_search_path, array('attributes' => array( + 'title' => $tag_title_text + ))), ); if (user_access('modify fedora datastreams') || user_access('add fedora tags')) { // Delete button for each existing tag. - $form['tags-wrapper']['tags'][$tag['name']]['delete'] = array( + $form_tag['delete'] = array( '#type' => 'imagebutton', - '#image' => $base_url . '/' . drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png', + '#image' => drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png', '#default_value' => $tag['name'], '#title' => t('Delete this tag'), ); From af364d04bee8c776c1a39deafa288645e613fb45 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 14:46:56 -0300 Subject: [PATCH 019/117] Fix syntax error. --- fedora_repository.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora_repository.install b/fedora_repository.install index 169d1178..563fde52 100644 --- a/fedora_repository.install +++ b/fedora_repository.install @@ -64,7 +64,7 @@ function fedora_repository_requirements($phase) { } // Test for DOM - $requirements['dom']['title'] = $t("PHP DOM XML extension library"; + $requirements['dom']['title'] = $t("PHP DOM XML extension library"); if (!method_exists('DOMDocument', 'loadHTML')) { $requirements['dom']['value'] = $t("Not installed"); $requirements['dom']['severity'] = REQUIREMENT_ERROR; From ccfc8454641b482f1e76c6d6b29fe232a4190b1a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 14:48:52 -0300 Subject: [PATCH 020/117] Clean up and formatting --- xsl/sparql_to_html.xsl | 398 +++++++++++++++++------------------------ 1 file changed, 166 insertions(+), 232 deletions(-) diff --git a/xsl/sparql_to_html.xsl b/xsl/sparql_to_html.xsl index 99045659..c5974403 100644 --- a/xsl/sparql_to_html.xsl +++ b/xsl/sparql_to_html.xsl @@ -1,248 +1,182 @@ - - - - - - - - - - - - + + + + + + + + - - - -

' . t("Belongs to these collections:") . '

' . $parent_collections_HTML . '

MetaData

+
- = + =
- + + + +
- - - - -
-
+ +

+ + + - - -
- -
- -
- - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - /fedora/repository//-/ - - - - /fedora/repository/ - - - - - - - - - - /fedora/repository//TN - - - -
- - - - - - + + + + + + +
- - - - - - - - - -   - - - - - - - - - - + + +   + + + + + + - - + + + + - - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + From ccb4ff56712b951f0060f97a6180fdfddebccc18 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 14:54:28 -0300 Subject: [PATCH 021/117] Remove PHP_VERSION shenanigans, as we don't look back before 5.2... Needed at least 5.1 to be able to add XSLT parameters by array. --- CollectionClass.inc | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 2bed9a6c..f03bf4d6 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -6,11 +6,6 @@ * Collection Class Class */ -if (!defined('PHP_VERSION_ID')) { //XXX: This should go elsewhere - $version = explode('.', PHP_VERSION); - define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); -} - /** * 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 @@ -742,14 +737,7 @@ class CollectionClass { 'hitPage' => $pageNumber, ); - if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50100) { - $proc->setParameter('', $options); - } - else { - foreach ($options as $name => $value) { - $proc->setParameter('', $name, $value); - } - } + $proc->setParameter('', $options); $proc->registerPHPFunctions(); $xsl = new DomDocument(); From 3a559b7701637c3508e812fa5f14693ffec0cea3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 14:55:37 -0300 Subject: [PATCH 022/117] Undo bit of code which ended up producing warnings/errors... ... In calling deprecated code, but anyway. --- formClass.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/formClass.inc b/formClass.inc index d6cb23df..7a54133a 100644 --- a/formClass.inc +++ b/formClass.inc @@ -128,8 +128,7 @@ class formClass { 'title' => t('Collection view'), 'page callback' => 'fedora_collection_view', 'type' => MENU_CALLBACK, - 'access callback' => 'fedora_repository_access', - 'access argruments' => array(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA), + 'access argruments' => array('view fedora collection'), ); //new for mnpl****************************************** From b2c1d613f11bc75cc7a4c4544462aad6c644091c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 15:00:18 -0300 Subject: [PATCH 023/117] Remove include added in previous (reverted) commit. --- formClass.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/formClass.inc b/formClass.inc index 7a54133a..713f1fcb 100644 --- a/formClass.inc +++ b/formClass.inc @@ -14,7 +14,6 @@ class formClass { function formClass() { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); } /** From f7bd67d01566f75d243139fc9126de9c02b73679 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 15:16:35 -0300 Subject: [PATCH 024/117] Use an item_list instead of a table, for the XSLT-less display. Should add some default CSS. --- CollectionClass.inc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index f03bf4d6..77318b03 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -689,14 +689,12 @@ class CollectionClass { $obj_path = "fedora/repository/{$result['object']}"; $thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE); $results[] = array( - array( - 'data' => l($thumbnail, $obj_path, array( - 'html' => TRUE, - )), - ), - array( - 'data' => l($title, $obj_path), - ), + 'data' => l($thumbnail, $obj_path, array( + 'html' => TRUE, + 'attributes' => array( + 'class' => 'results-image', + ), + )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), ); } if (!$results) { @@ -707,13 +705,16 @@ class CollectionClass { $last = (($total - $first) > $per_page)? ($first + $per_page): $total; - $objectList = '

' . t('Results @first to @last of @total', array( + $results_range_text = t('Results @first to @last of @total', array( '@first' => $first + 1, '@last' => $last, '@total' => $total, - )) . '

'; + )); + //$objectList = '

' . $results_range_text . '

'; $objectList .= theme('pager', array(), $per_page, $pager_name); - $objectList .= theme('table', NULL, $results); + $objectList .= theme('item_list', $results, $result_range_text, 'ul', array( + 'class' => 'islandora-collection-results-list', + )); $objectList .= theme('pager', array(), $per_page, $pager_name); } } From 8cebf38560689036836c70618080110827ba08d0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 15:41:50 -0300 Subject: [PATCH 025/117] Undo making a couple functions static and fix merge error. --- CollectionClass.inc | 19 +++++++------------ ObjectHelper.inc | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 77318b03..68dbc08a 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -54,6 +54,7 @@ class CollectionClass { return FALSE; } } + static function _get_default_collection_query($pid) { return 'select $object $title $content from <#ri> where ($object $title @@ -78,8 +79,8 @@ class CollectionClass { * @param type $itqlquery * @return type */ - static function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { - return self::getRelatedItems($pid, $itqlquery, $limit, $offset); + function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) { + return $this->getRelatedItems($pid, $itqlquery, $limit, $offset); } /** @@ -92,7 +93,7 @@ class CollectionClass { * @param $pid string * A string containing a PID which may be substituted into the query, * in place of the %parent_collection% placeholder. - * @param $itqlquery string + * @param $query_string string * An optional iTQL query. * @param $limit int * An optional integer to limit the number of results returned. @@ -102,15 +103,13 @@ class CollectionClass { * @return string * Sparql XML results from the resource index. */ - static function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); return ' '; } - $objectHelper = new ObjectHelper(); if ($query_string === NULL) { $query_string = self::get_collection_query($pid); @@ -593,10 +592,8 @@ class CollectionClass { * @return string */ function getIngestInterface() { - global $base_url; - $objectHelper = new ObjectHelper(); module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy'); - $collectionPolicyExists = $objectHelper->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); + $collectionPolicyExists = $this->collectionObject->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (!empty($collectionPolicyExists)) { $allow = TRUE; @@ -656,9 +653,8 @@ class CollectionClass { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; $collection_pid = $pid; //we will be changing the pid later maybe - $objectHelper = new ObjectHelper(); $parsedContent = NULL; - $contentModels = $objectHelper->get_content_models_list($pid); + $contentModels = $this->collectionObject->get_content_models_list($pid); $isCollection = FALSE; //if this is a collection object store the $pid in the session as it will come in handy //after a purge or ingest to return to the correct collection. @@ -674,7 +670,6 @@ class CollectionClass { $objectList = ''; if (isset($content) && $content != FALSE) { if (!$xslContent) { //Didn't find an XSLT. - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $intermediate_results = ObjectHelper::parse_sparql_results($content); unset($content); diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 18000b80..358aaac5 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -778,6 +778,7 @@ class ObjectHelper { function get_parent_objects($pid) { $query_string = self::_parent_query(); module_load_include('inc', 'fedora_repository', 'CollectionClass'); + $collection_class = new CollectionClass($pid); $objects = CollectionClass::getRelatedItems($pid, $query_string); return $objects; } @@ -1043,7 +1044,7 @@ class ObjectHelper { $attrs = $element->attributes(); if (!empty($attrs['uri'])) { - $val = self::_pid_uri_to_bare_pid((string)$attrs['uri']); + $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); } else { $val = (string)$element; From 3b64841ca7c00df18541ef21dbac73f72c95da1e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 23 Apr 2012 19:44:48 -0300 Subject: [PATCH 026/117] Conform a little better with the Drupal code standards. --- CollectionClass.inc | 55 ++++++++++++++++++++++++++++++++++++--------- ObjectHelper.inc | 42 +++++++++++++++++----------------- 2 files changed, 65 insertions(+), 32 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 68dbc08a..5882a460 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -35,16 +35,16 @@ class CollectionClass { } } - static function get_collection_query($pid) { - if ($query = self::_get_collection_query_from_stream($pid)) { + public static function getCollectionQuery($pid) { + if ($query = self::getCollectionQueryFromStream($pid)) { return $query; } else { - return self::_get_default_collection_query($pid); + return self::getDefaultCollectionQuery($pid); } } - static function _get_collection_query_from_stream($pid) { + protected static function getCollectionQueryFromStream($pid) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { @@ -55,7 +55,7 @@ class CollectionClass { } } - static function _get_default_collection_query($pid) { + protected static function getDefaultCollectionQuery($pid) { return 'select $object $title $content from <#ri> where ($object $title and $object $content @@ -87,7 +87,7 @@ class CollectionClass { * Gets objects related to this item. * * Query the resource index using the provided iTQL query. If no query is - * provided, one should be obtained via self::get_collection_query() which + * provided, one should be obtained via self::getCollectionQuery() which * grabs the child objects. * * @param $pid string @@ -112,7 +112,7 @@ class CollectionClass { } if ($query_string === NULL) { - $query_string = self::get_collection_query($pid); + $query_string = self::getCollectionQuery($pid); } // Replace %parent_collection% with the actual collection PID @@ -616,12 +616,45 @@ class CollectionClass { * Unfortunate function, I know... * * Does just what it says: Hacks the default Drupal pager such that it might - * be rendered. + * be rendered, likely with: theme('pager', array(), $per_page, $pager_name) + * (I reccomend seeing the real documentation for more detail, but the first + * array can be a list of the tags to use for first, previous, next and last + * (text in the pager), I don't believe per_page is actually used in the theme + * function, and $pager_name is an integer used to identify the pager (such + * that there can be more than one--that is, tracking different lists of + * content on a single page. You can render the exact same pager multiple + * times, say if you want one at the top and bottom of a list, using the same + * ID/pager_name. + * + * @global $pager_total array + * Numerically indexed array, where keys are the $pager_names and values + * are the number of pages in the given set, based on: ceil($total_items/$per_page); + * @global $pager_page_array array + * Numerically indexed array, where keys are the $pager_names and values + * are the page selected in the relevant set. + * @param $pager_name int + * An integer to identify the pager to affect. Do note that paging in using + * this function will add the 'page' HTTP GET parameter to the URL, with + * the value containing a comma-separated list with max($pager_name + 1) + * values--that is, if you create a single pager named '10', the 'next' + * link will look something like: 0,0,0,0,0,0,0,0,0,0,1 + * @param $per_page int + * An integer representing the number of items per page. + * @param $total_items int + * An integer representing the total number of items in the set. + * @return int + * An integer representing what the current page should be. */ - protected static function _hack_pager($pager_name, $per_page, $total_items) { + protected static function hackPager($pager_name, $per_page = NULL, $total_items = NULL) { global $pager_total, $pager_page_array; - $pager_total[$pager_name] = ceil($total_items / $per_page); + if ($per_page !== NULL && $total_items !== NULL) { + $pager_total[$pager_name] = ceil($total_items / $per_page); + } + + //XXX: Don't know that this is neccessary, to try to load all the time, or + // whether Drupal will load it automatically somewhere... Docs seems a + // a little sparse. $page_info = explode(',', isset($_GET['page']) ? $_GET['page'] : ''); $page = $page_info[$pager_name]; if ($page < 0) { @@ -676,7 +709,7 @@ class CollectionClass { $per_page = 20; //XXX: Make this configurable. $pager_name = 0; $total = count($intermediate_results); - $pager_page = self::_hack_pager($pager_name, $per_page, $total); + $pager_page = self::hackPager($pager_name, $per_page, $total); $results = array(); foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 659847d7..f41217cc 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -759,7 +759,7 @@ class ObjectHelper { * @return string * A string containing an iTQL query, selecting something into $object and $title */ - static function _parent_query($pid) { + static function parentQuery($pid) { return 'select $object $title from <#ri> where ($object $title and $object @@ -773,10 +773,10 @@ class ObjectHelper { * @param $pid string * A string containing a Fedora PID to find the parents for. * @return string - * A string containing Sparql XML (the results of the self::_parent_query()) + * A string containing Sparql XML (the results of the self::parentQuery()) */ function get_parent_objects($pid) { - $query_string = self::_parent_query(); + $query_string = self::parentQuery(); module_load_include('inc', 'fedora_repository', 'CollectionClass'); $collection_class = new CollectionClass($pid); $objects = CollectionClass::getRelatedItems($pid, $query_string); @@ -791,7 +791,7 @@ class ObjectHelper { */ function get_parent_objects_asHTML($pid) { module_load_include('inc', 'fedora_repository', 'CollectionClass'); - $results = self::perform_itql_query(self::_parent_query($pid)); + $results = self::performItqlQuery(self::parentQuery($pid)); $parent_collections = array(); foreach ($results as $result) { @@ -874,7 +874,7 @@ class ObjectHelper { and $o $desc and $o '; - $results = self::perform_itql_query($query_string); + $results = self::performItqlQuery($query_string); $pids = array(); //There should only be one... Anyway. @@ -905,7 +905,7 @@ class ObjectHelper { 'and $o $title ' . 'and ( ' . implode(' or ', $query_chunks) . ' )'; - $results = self::perform_itql_query($query_string); + $results = self::performItqlQuery($query_string); $child_pids = array(); if ($results) { @@ -979,7 +979,7 @@ class ObjectHelper { minus $content order by $title desc'; - if (count($results = self::perform_itql_query($query_string)) > 0 && $level > 0) { + if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) { $parent = $results[0]['parentObject']; $this_title = $results[0]['title']; @@ -1029,7 +1029,7 @@ class ObjectHelper { * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ - public static function parse_sparql_results($sparql) { + public static function parseSparqlResults($sparql) { //Load the results into a SimpleXMLElement $doc = new SimpleXMLElement($sparql, 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); @@ -1044,7 +1044,7 @@ class ObjectHelper { $attrs = $element->attributes(); if (!empty($attrs['uri'])) { - $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); + $val = self::pidUriToBarePid((string)$attrs['uri']); } else { $val = (string)$element; @@ -1079,7 +1079,7 @@ class ObjectHelper { * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ - static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { + static function performRiQuery($query, $type = 'itql', $limit = -1, $offset = 0) { //Setup the query options... $options = array( 'type' => 'tuples', @@ -1110,26 +1110,26 @@ class ObjectHelper { } //Pass the query's results off to a decent parser. - return self::parse_sparql_results($curl_result[0]); + return self::parseSparqlResults($curl_result[0]); } /** - * Thin wrapper for self::_perform_ri_query(). + * Thin wrapper for self::_performRiQuery(). * - * @see self::_perform_ri_query() + * @see self::performRiQuery() */ - public static function perform_itql_query($query, $limit = -1, $offset = 0) { - return self::perform_ri_query($query, 'itql', $limit, $offset); + public static function performItqlQuery($query, $limit = -1, $offset = 0) { + return self::performRiQuery($query, 'itql', $limit, $offset); } /** - * Thin wrapper for self::_perform_ri_query(). + * Thin wrapper for self::performRiQuery(). * - * @see self::_perform_ri_query() + * @see self::_performRiQuery() */ - public static function perform_sparql_query($query, $limit = -1, $offset = 0) { - return self::perform_ri_query($query, 'sparql', $limit, $offset); + public static function performSparqlQuery($query, $limit = -1, $offset = 0) { + return self::performRiQuery($query, 'sparql', $limit, $offset); } /** - * Utility function used in self::_perform_ri_query(). + * Utility function used in self::performRiQuery(). * * Strips off the 'info:fedora/' prefix from the passed in string. * @@ -1140,7 +1140,7 @@ class ObjectHelper { * The input string less the 'info:fedora/' prefix (if it has it). * The original string otherwise. */ - protected static function pid_uri_to_bare_pid($uri) { + protected static function pidUriToBarePid($uri) { $chunk = 'info:fedora/'; $pos = strpos($uri, $chunk); if ($pos === 0) { //Remove info:fedora/ chunk From 364e908ff525977e920cdefc028c9ab0b9ab9057 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 24 Apr 2012 09:58:13 -0300 Subject: [PATCH 027/117] Fix error intro'd during refactor. --- ObjectHelper.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index f41217cc..e866f62f 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -359,7 +359,7 @@ class ObjectHelper { $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $mimeType = $dataStreamValue->MIMEType; - $view = l(t('View'), "'fedora/repository/$pid/$id/$label_deslashed", array( + $view = l(t('View'), "fedora/repository/$pid/$id/$label_deslashed", array( 'attributes' => array( 'target' => '_blank', ), From 5aefe46f85709cd5218a5f139616dc925f57b90c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 24 Apr 2012 14:19:47 -0300 Subject: [PATCH 028/117] Use wrapping modify_datastream wrapper in replace datastream callback. --- fedora_repository.module | 45 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index e83d91f5..208e028e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -646,27 +646,27 @@ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLab * @return type */ function fedora_repository_replace_stream_form_validate($form, &$form_state) { -// If a file was uploaded, process it. + // If a file was uploaded, process it. if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) { -// attempt to save the uploaded file + // attempt to save the uploaded file $file = file_save_upload('file', array(), file_directory_path()); -// set error is file was not uploaded + // set error is file was not uploaded if (!$file) { form_set_error('file', 'Error uploading file.'); return; } - - $doc = new DOMDocument(); - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); + + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); - if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) { + + if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); return; } -// set files to form_state, to process when form is submitted + // set files to form_state, to process when form is submitted $form_state['values']['file'] = $file; } } @@ -683,39 +683,32 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; -// Remove the original file extension from the label and add the new one + + // Remove the original file extension from the label and add the new one $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot if ($indexOfDot !== FALSE) { $dsLabel = substr($dsLabel, 0, $indexOfDot); $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; } - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $file_basename = basename($file->filepath); - $file_directory = dirname($file->filepath); - $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); + $streamUrl = url($file->filepath, array( + 'absolute' => TRUE, + )); /* ----------------------------------------------------------------- * TODO: need a better way to get mimetypes */ + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - $info = $item->get_datastream_info($dsid); - - if($info->datastream->controlGroup == 'M') { - $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); - } elseif ($info->datastream->controlGroup == 'X') { - if($dformat == 'text/xml') { - $item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat); - } - else { - drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error'); - } + + if(in_array($info->datastream->controlGroup, array('M', 'X'))) { + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); } else { - drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error'); + drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); } $form_state['redirect'] = 'fedora/repository/' . $pid; From fa77552e57052ace01abef279e0a8cf3946083e2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 09:22:14 -0300 Subject: [PATCH 029/117] Get the extension without exploding. --- MimeClass.inc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MimeClass.inc b/MimeClass.inc index 42c11e37..b2950f6e 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -231,9 +231,7 @@ class MimeClass { * @return type */ public function get_mimetype($filename, $debug = FALSE) { - - $file_name_and_extension = explode('.', $filename); - $ext = strtolower(array_pop($file_name_and_extension)); + $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if (!empty($this->private_mime_types[$ext])) { if (TRUE === $debug) From 01ac63a3d98c996614f925e6f810098fe7e36117 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 10:05:45 -0300 Subject: [PATCH 030/117] Allow the addition of Redirect and External datastreams. --- fedora_repository.module | 80 ++++++++++++++++++++------------------ formClass.inc | 83 +++++++++++++++++++++++++++++----------- 2 files changed, 104 insertions(+), 59 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 208e028e..940d1585 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -377,37 +377,25 @@ function add_stream_form_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; return; } - module_load_include('inc', 'fedora_repository', 'MimeClass'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $pathToModule = drupal_get_path('module', 'fedora_repository'); - $file = $form_state['values']['add-stream-file-location']; - $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; - $file_basename = basename($file); - $file_directory = dirname($file); - $streamUrl = $base_url . '/' . $file_directory . '/' . drupal_urlencode($file_basename); - /* ----------------------------------------------------------------- - * need a better way to get mimetypes - */ - $mimetype = new MimeClass(); - $dformat = $mimetype->getType($file); - $controlGroup = "M"; - if ($dformat == 'text/xml') { - $controlGroup = 'X'; - } try { $item = new Fedora_Item($pid); - $item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); - $object_helper = new ObjectHelper(); - $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); + if ($file = $form_state['values']['add-stream-file-location']) { + $object_helper = new ObjectHelper(); + $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); - file_delete($file); + file_delete($file); + } } catch (exception $e) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); return; @@ -434,6 +422,7 @@ function add_stream_form(&$form_state, $pid) { * @return type */ function add_stream_form_validate($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'MimeClass'); if ($form_state['clicked_button']['#value'] == 'OK') { $form_state['rebuild'] = TRUE; return; @@ -444,15 +433,15 @@ function add_stream_form_validate($form, &$form_state) { form_set_error('', t('Data stream ID cannot be more than 64 characters.')); return FALSE; } - if (!(preg_match("/^[a-zA-Z]/", $dsid))) { - form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); + elseif (!(preg_match("/^[a-zA-Z]/", $dsid))) { + form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => $dsid))); return FALSE; } - if (strlen($dsLabel) > 64) { + elseif (strlen($dsLabel) > 64) { form_set_error('', t('Data stream Label cannot be more than 64 characters.')); return FALSE; } - if (strpos($dsLabel, '/')) { + elseif (strpos($dsLabel, '/') !== FALSE) { form_set_error('', t('Data stream Label cannot contain a "/".')); return FALSE; } @@ -462,12 +451,30 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_size' => array(30 * 1024), ); - $fileObject = file_save_upload('add-stream-file-location', $validators); - -// Move the uploaded file to Drupal's files directory. - file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); - $form_state['values']['add-stream-file-location'] = $fileObject->filepath; -// TODO: Add error checking here. + $mimetype = new MimeClass(); + $controlGroup = $form_state['values']['control_group']; + if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) { + // Move the uploaded file to Drupal's files directory. + file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); + $form_state['values']['add-stream-file-location'] = $fileObject->filepath; + $form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath); + + $file_basename = basename($fileObject->filepath); + $file_directory = dirname($fileObject->filepath); + + $form_state['storage']['stream_url'] = url($file_directory . '/' . drupal_urlencode($file_basename), array( + 'absolute' => TRUE, + )); + } + elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { + $form_state['storage']['ds_mimetype'] = $mimetype->getType($ref); + $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; + } + else { + form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); + } + + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } @@ -680,6 +687,11 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { function fedora_repository_replace_stream_form_submit($form, &$form_state) { global $base_url; $file = $form_state['values']['file']; + + if ($file !== NULL) { + $file = $form_state['values']['reference']; + } + $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; @@ -702,14 +714,9 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - if(in_array($info->datastream->controlGroup, array('M', 'X'))) { - $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); - } else { - drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); - } + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $form_state['redirect'] = 'fedora/repository/' . $pid; } @@ -1052,7 +1059,6 @@ function fedora_repository_urlencode_string($str) { * @return type */ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { - global $user; module_load_include('inc', 'fedora_repository', 'ObjectHelper'); if ($pid == NULL || $dsId == NULL) { @@ -1061,7 +1067,7 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { } $objectHelper = new ObjectHelper(); - $objectHelper->makeObject($pid, $dsId, 1, $label, FALSE, $version); + $objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version); } /** diff --git a/formClass.inc b/formClass.inc index 713f1fcb..db90798c 100644 --- a/formClass.inc +++ b/formClass.inc @@ -656,17 +656,21 @@ class formClass { } } - $form['add_datastream_label'] = array( - '#value' => t('

Add Datastream:

'), - '#weight' => -10, + $form['fieldset'] = array( + '#type' => 'fieldset', + '#title' => t('Add datastream'), ); + //$form['add_datastream_label'] = array( + // '#value' => t('

Add Datastream:

'), + // '#weight' => -10, + //); - $form['pid'] = array( + $form['fieldset']['pid'] = array( '#type' => 'hidden', '#value' => "$pid" ); - $form['stream_label'] = array( + $form['fieldset']['stream_label'] = array( '#title' => 'Datastream Label', '#required' => 'TRUE', '#description' => t('A Human readable label'), @@ -674,35 +678,37 @@ class formClass { ); $form['#attributes']['enctype'] = 'multipart/form-data'; - $form['add-stream-file-location'] = array( + $form['fieldset']['add-stream-file-location'] = array( '#type' => 'file', '#title' => t('Upload Document'), '#size' => 48, // '#required'=>'TRUE', - '#description' => t('The file to upload.') + '#description' => t('The file to upload. (Only for Managed and Inline)') + ); + $form['fieldset']['ds_reference'] = array( + '#type' => 'textfield', + '#title' => t('Datastream reference'), + '#size' => 48, + '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), ); $form['#redirect'] = "fedora/repository/$pid/"; - $form['submit'] = array( + $form['fieldset']['submit'] = array( '#type' => 'submit', '#value' => t('Add Datastream') ); if (!empty($unused_dsids)) { - $dsidsForForm = array(); - foreach ($unused_dsids as $dsid) { - $dsidsForForm[$dsid] = $dsid; - } - $form['stream_id'] = array( + $form['fieldset']['stream_id'] = array( '#type' => 'select', '#title' => t('Datastream ID'), '#default_value' => variable_get('feed_item_length', 'teaser'), - '#weight' => '-1', + '#weight' => -1, '#description' => t('Datastream IDs defined by the content model.'), + '#options' => array_combine($unused_dsids, $unused_dsids), ); - $form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids); } else { - $form['stream_id'] = array( + $form['fieldset']['stream_id'] = array( '#title' => 'Datastream ID', '#required' => 'TRUE', '#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'), @@ -710,6 +716,18 @@ class formClass { '#weight' => -1, ); } + $form['fieldset']['control_group'] = array( + '#type' => 'select', + '#title' => t('Control group'), + '#options' => array( + 'X' => t('Inline XML'), + 'M' => t('Managed datastream'), + 'E' => t('Externally Referenced/managed datastream'), + 'R' => t('Redirect datastream'), + ), + '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), + '#weight' => 0, + ); return $form; } @@ -836,12 +854,33 @@ class formClass { $form = array(); $form['#attributes']['enctype'] = 'multipart/form-data'; - $form['file'] = array( - '#type' => 'file', - '#title' => t('Upload Document'), - '#description' => t('The file to upload.') - ); - + + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($pid); + $info = $item->get_datastream_info($dsId); + $control_group = $info->datastream->controlGroup; + if (in_array($control_group, array('M', 'X'))) { + $form['file'] = array( + '#type' => 'file', + '#title' => t('Upload Document'), + '#description' => t('A file with which to replace the contents of this datastream.'), + ); + } + if ($control_group != 'X') { + $form['reference'] = array( + '#type' => 'textfield', + '#title' => t('Reference to object'), + '#description' => t('A URL the datastream will be updated to reference.'), + ); + } + if ($control_group == 'M') { + $form['note'] = array( + '#type' => 'item', + '#title' => t('NOTE'), + '#value' => t('If both a file and a reference are given, the file will be given preference.'), + ); + } + $form['pid'] = array( '#type' => 'value', '#value' => $pid, From 8cfdc902ab4aed96ce89377b9947af994c241e9c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 10:32:26 -0300 Subject: [PATCH 031/117] Fix issue with downloading versioned datastreams. Had to do with migration to use of newer REST API; it takes the version parameter differently, as a query parameter instead of a position in the URL. --- ObjectHelper.inc | 14 +++++++++----- fedora_repository.module | 3 --- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e866f62f..c83c5eb8 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -72,7 +72,6 @@ class ObjectHelper { return ' '; } - if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) { if (($cm = ContentModel::loadFromObject($pid)) == FALSE) { drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error'); @@ -91,7 +90,6 @@ class ObjectHelper { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - if (isset($item->datastreams[$dsID])) { $mimeType = $item->datastreams[$dsID]['MIMEType']; if ($label == NULL) { @@ -123,8 +121,14 @@ class ObjectHelper { $mimeType = 'image/jpeg'; } $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content'; + $query_options = array(); if ($version) { - $url .= '/' . $version; //drupal_urlencode($version); + $query_options['asOfDateTime'] = $version; //drupal_urlencode($version); + } + if ($query_options) { + $url = url($url, array( + 'query' => $query_options, + )); } $ch = curl_init(); $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)"; @@ -184,7 +188,6 @@ class ObjectHelper { $curl_out = curl_exec($ch); if ($curl_out !== FALSE) { $info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); - //dd($info, 'effective URL'); if ($url !== $info) { //Handle redirect streams (the final URL is not the same as the Fedora URL) //Add the parameters passed to Drupal, leaving out the 'q' @@ -195,7 +198,7 @@ class ObjectHelper { } header('HTTP/1.1 307 Moved Temporarily'); - header('Location: ' . $info . '?' . http_build_query($query)); //Fedora seems to discard the query portion. + header('Location: ' . url($info, array('query' => $query))); } elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS //Have the webserver mediate the transfer (download and restream) @@ -211,6 +214,7 @@ class ObjectHelper { } else { //Curl error... + watchdog('fedora_repository', 'Curl error. Info: @info', array('@info' => print_r(curl_getinfo($ch), TRUE)), WATCHDOG_WARNING); } } curl_close($ch); diff --git a/fedora_repository.module b/fedora_repository.module index 940d1585..28dc4e8e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2272,9 +2272,6 @@ function theme_fedora_repository_solution_packs_list($solution_packs) { $header = array(); $rows = array(); - - - drupal_add_css(drupal_get_path('module', 'update') . '/update.css'); return $output; } From 7bc755f231380e0b99f472c6877b32a52dd630fa Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 11:04:13 -0300 Subject: [PATCH 032/117] Make control group selection optional. --- fedora_repository.module | 25 +++++++++++++------- formClass.inc | 50 +++++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 28dc4e8e..f14dde6b 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -388,7 +388,7 @@ function add_stream_form_submit($form, &$form_state) { try { $item = new Fedora_Item($pid); - $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); + $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['storage']['control_group']); if ($file = $form_state['values']['add-stream-file-location']) { $object_helper = new ObjectHelper(); @@ -450,14 +450,12 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_image_resolution' => array('85x85'), // 'file_validate_size' => array(30 * 1024), ); - - $mimetype = new MimeClass(); - $controlGroup = $form_state['values']['control_group']; - if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) { + + $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group']; + if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0)) { // Move the uploaded file to Drupal's files directory. file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); $form_state['values']['add-stream-file-location'] = $fileObject->filepath; - $form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath); $file_basename = basename($fileObject->filepath); $file_directory = dirname($fileObject->filepath); @@ -466,14 +464,25 @@ function add_stream_form_validate($form, &$form_state) { 'absolute' => TRUE, )); } - elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { - $form_state['storage']['ds_mimetype'] = $mimetype->getType($ref); + elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; } else { form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); } + $mimeClass = new MimeClass(); + $mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']); + + if (!$controlGroup) { + if ($mimetype == 'text/xml') { + $form_state['storage']['control_group'] = 'X'; + } + else { + $form_state['storage']['control_group'] = 'M'; + } + } + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } diff --git a/formClass.inc b/formClass.inc index db90798c..a5f9bef6 100644 --- a/formClass.inc +++ b/formClass.inc @@ -331,6 +331,13 @@ class formClass { '#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')), '#description' => t('Determines when to display the list of objects when viewing a collection page.'), ); + + $form['advanced']['fedora_control_group_control_during_ingest'] = array( + '#type' => 'checkbox', + '#title' => t('Allow control groups select in datastream ingest'), + '#description' => t('Whether or not we should allow the user to select which control group to ingest a stream as, or to follow the old paradigm--to add stream IDed as XML as inline, and everything else as managed.'), + '#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE), + ); //Export functionality $form['advanced']['module']['export_area'] = array( @@ -685,12 +692,16 @@ class formClass { // '#required'=>'TRUE', '#description' => t('The file to upload. (Only for Managed and Inline)') ); - $form['fieldset']['ds_reference'] = array( - '#type' => 'textfield', - '#title' => t('Datastream reference'), - '#size' => 48, - '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), - ); + + if (variable_get('fedora_control_group_control_during_ingest', FALSE)) { + $form['fieldset']['ds_reference'] = array( + '#type' => 'textfield', + '#title' => t('Datastream reference'), + '#size' => 48, + '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), + ); + } + $form['#redirect'] = "fedora/repository/$pid/"; $form['fieldset']['submit'] = array( '#type' => 'submit', @@ -716,18 +727,21 @@ class formClass { '#weight' => -1, ); } - $form['fieldset']['control_group'] = array( - '#type' => 'select', - '#title' => t('Control group'), - '#options' => array( - 'X' => t('Inline XML'), - 'M' => t('Managed datastream'), - 'E' => t('Externally Referenced/managed datastream'), - 'R' => t('Redirect datastream'), - ), - '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), - '#weight' => 0, - ); + + if (variable_get('fedora_control_group_control_during_ingest', FALSE)) { + $form['fieldset']['control_group'] = array( + '#type' => 'select', + '#title' => t('Control group'), + '#options' => array( + 'X' => t('Inline XML'), + 'M' => t('Managed datastream'), + 'E' => t('Externally Referenced/managed datastream'), + 'R' => t('Redirect datastream'), + ), + '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), + '#weight' => 0, + ); + } return $form; } From 132248951db9ea383ce3d3c2a2d36a408da83e7a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 12:33:04 -0300 Subject: [PATCH 033/117] Fix error when label contains an extension. Error intro'd during datastream replace 'improvements'. --- fedora_repository.module | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index f14dde6b..f5e8602e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -674,10 +674,14 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { return; } + /* ----------------------------------------------------------------- + * TODO: need a better way to get mimetypes + */ module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); + $mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath); - if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { + if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); return; } @@ -694,37 +698,28 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { * @param array $form_state */ function fedora_repository_replace_stream_form_submit($form, &$form_state) { - global $base_url; $file = $form_state['values']['file']; - - if ($file !== NULL) { - $file = $form_state['values']['reference']; - } - + $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; + $streamUrl = ($file !== NULL) ? + url($file->filepath, array('absolute' => TRUE)): + url($form_state['values']['reference'], array('absolute' => TRUE)); + // Remove the original file extension from the label and add the new one - $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot - if ($indexOfDot !== FALSE) { - $dsLabel = substr($dsLabel, 0, $indexOfDot); - $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; + // use strrpos to get the last dot + if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) { + $dsLabel = substr($dsLabel, 0, $indexOfDot) . + substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label. } - $streamUrl = url($file->filepath, array( - 'absolute' => TRUE, - )); + - /* ----------------------------------------------------------------- - * TODO: need a better way to get mimetypes - */ - module_load_include('inc', 'fedora_repository', 'MimeClass'); - $mimetype = new MimeClass(); - $dformat = $mimetype->getType($file->filepath); + $dformat = $form_state['storage']['mime_type']; $item = new Fedora_Item($pid); - $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $form_state['redirect'] = 'fedora/repository/' . $pid; From 5b3fe1ef7627d9b6cf5b326dfdaa70b6b3a0aff5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 09:48:03 -0300 Subject: [PATCH 034/117] Use Sparql query for breadcrumbs. --- ObjectHelper.inc | 52 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index c83c5eb8..1a60784b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -969,21 +969,33 @@ class ObjectHelper { $breadcrumbs[] = l(t('Home'), ''); } else { - $query_string = 'select $parentObject $title $content from <#ri> - where ( - $title - and $parentObject $content - and ( - $parentObject - or $parentObject - or $parentObject - ) - and $parentObject - ) - minus $content - order by $title desc'; - - if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) { + $sparql_query_string = << +PREFIX rels-ext: +SELECT ?parentObject ?title ?content +FROM <#ri> +WHERE { + ?this fedora-model:label ?title ; + ?relationship ?parentObject . + ?parentObject fedora-model:state fedora-model:Active ; + fedora-model:hasModel ?content . + FILTER( + sameTerm(?this, ) && + ( + sameTerm(?relationship, rels-ext:isMemberOfCollection) || + sameTerm(?relationship, rels-ext:isMemberOf) || + sameTerm(?relationship, rels-ext:isPartOf) + ) && + !sameTerm(?content, ) + ) . +} +ORDER BY DESC(?title) +EOQ; + + $results = self::performSparqlQuery($sparql_query_string); + $next_pid = NULL; + + if (count($results) > 0 && $level > 0) { $parent = $results[0]['parentObject']; $this_title = $results[0]['title']; @@ -993,13 +1005,17 @@ class ObjectHelper { $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); - $level--; - $this->getBreadcrumbs($parent, $breadcrumbs); + $next_pid = $parent; } else { watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. - $this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass). + $next_pid = $root; //And cue the last two links to render and break recursion (on the next pass). + } + + if ($next_pid !== NULL) { + $level--; + $this->getBreadcrumbs($next_pid, $breadcrumbs); } } } From 3696cab9eac8832e4a9ba09ffc6bfd4ca9338333 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 10:03:45 -0300 Subject: [PATCH 035/117] Generate the download form. ... As opposed to spitting out markup for it directly. --- ObjectHelper.inc | 18 +++--------------- fedora_repository.module | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 1a60784b..aa093839 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -359,7 +359,7 @@ class ObjectHelper { $content = ''; $id = $dataStreamValue->ID; $label = $dataStreamValue->label; - $label = str_replace("_", " ", $label); + //$label = str_replace("_", " ", $label); $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $mimeType = $dataStreamValue->MIMEType; @@ -368,20 +368,8 @@ class ObjectHelper { 'target' => '_blank', ), )); - $action = url("fedora/repository/object_download/$pid/$id/$label_deslashed"); - $downloadVersion = ''; - if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { - $versions = $item->get_datastream_history($id); - if (is_array($versions)) { - $downloadVersion = '
'; - $downloadVersion .= ''; - $downloadVersion .= '
'; - } - } + + $downloadVersion = drupal_get_form('fedora_repository_download_datastream_form', $pid, $id, $label_deslashed); return array( array( diff --git a/fedora_repository.module b/fedora_repository.module index f5e8602e..5b6052b1 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -623,6 +623,42 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) { $form_state['redirect'] = $base_url . "/fedora/repository/$pid"; } +function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { + $form = array( + '#action' => url("fedora/repository/object_download/$pid/$dsid/$label"), + 'submit' => array( + '#type' => 'submit', + '#value' => t('Download'), + ), + ); + + if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { + $item = new Fedora_Item($pid); + $versions = $item->get_datastream_history($dsid); + $version_array = array(); + if (is_array($versions)) { + foreach ($versions as $version) { + $version_array[] = $version->createDate; + } + } + else { + $version_array[] = $versions->createDate; + } + + if (count($version_array) > 1) { + $form['#attributes'] = array( + 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;' + ); + $form['version'] = array( + '#type' => 'select', + '#options' => array_combine($version_array, $version_array), + ); + } + } + + return $form; +} + /** * fedora repository replace stream * @param type $pid From 6006effbb359b441785d5b621dc200083f0c045c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 16:05:48 -0300 Subject: [PATCH 036/117] Make a little closed to convertQDC.xsl --- ObjectHelper.inc | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 3979aaba..2534540b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -448,16 +448,35 @@ class ObjectHelper { $rows = array(); foreach ($simplexml->getNamespaces(TRUE) as $ns) { foreach ($simplexml->children($ns) as $child) { - $rows[] = array( - array( - 'data' => $child->getName(), - 'class' => 'dc-tag-name', - ), - array( - 'data' => (string)$child, - 'class' => 'dc-content', - ), - ); + $data = array(); + $rendered_data = ''; + if ($grand_children = $child->children()) { + foreach($grand_children as $grand_child) { + $data[] = $grand_child->tagName() . ' = ' . (string)$grand_child; + } + } + else { + $rendered_data = (string)$child; + } + + if ($data) { + $rendered_data = theme('item_list', $data); + } + + if ($rendered_data) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => $rendered_data, + 'class' => 'dc-content', + ), + ); + } + + } } From 278afdf4d80eca6239a73f449bbb8759c7553097 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 16:06:27 -0300 Subject: [PATCH 037/117] Fix syntax error involving reference. --- plugins/tagging_form.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index f00274d4..ae3bba92 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -61,10 +61,11 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tagset = new TagSet($obj); $tags = array(); foreach ($tagset->tags as $tag) { - $form_tag =& $form['tags-wrapper']['tags'][$tag['name']] = array( + $form['tags-wrapper']['tags'][$tag['name']] = array( '#prefix' => '
  • ', '#suffix' => '
  • ', ); + $form_tag =& $form['tags-wrapper']['tags'][$tag['name']]; $tag_title_text = t('Added by @creator.', array( '@creator' => $tag['creator'], From 08545aa19498bd7bd76e0bca7bcd543f7b1aff59 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 16:07:41 -0300 Subject: [PATCH 038/117] Fix error message. Was using wrong variable name. --- ObjectHelper.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index aa093839..f8195a11 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -996,7 +996,7 @@ EOQ; $next_pid = $parent; } else { - watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); + watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_level), WATCHDOG_WARNING); $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. $next_pid = $root; //And cue the last two links to render and break recursion (on the next pass). } From 27d6c763ff52d53ceb104a4e7adaac30adca03d5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:12:02 -0300 Subject: [PATCH 039/117] Fix syntax error. --- plugins/tagging_form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index ae3bba92..9b7c4658 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -70,7 +70,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tag_title_text = t('Added by @creator.', array( '@creator' => $tag['creator'], )); - $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}" + $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}"; $form_tag['tag'] = array( '#value' => l($tag['name'], $tag_mnpl_search_path, array('attributes' => array( 'title' => $tag_title_text From 2ac5ad45c7707d19ead5675053ced284f0c0742c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:12:21 -0300 Subject: [PATCH 040/117] Try to use covertQDC.xsl before using the Drupal's table generating business. --- ObjectHelper.inc | 87 ++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 603c2189..ce8abbcb 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -429,50 +429,59 @@ class ObjectHelper { return ''; } - $simplexml = new SimpleXMLElement($xmlstr); + if (($xsl_path = "$path/xsl/convertQDC.xsl") && + ($xsl = DOMDocument::load($xsl_path)) && + ($ds = DOMDocument::loadXML($xmlstr))) { + $transform = new XSLTProcessor(); + $transform->importStylesheet($domdoc); + return $transform->transformToHTML($ds); + } + else { + $simplexml = new SimpleXMLElement($xmlstr); - $headers = array( - array( - 'data' => t('Metadata'), - 'colspan' => 2, - ), - ); - $rows = array(); - foreach ($simplexml->getNamespaces(TRUE) as $ns) { - foreach ($simplexml->children($ns) as $child) { - $data = array(); - $rendered_data = ''; - if ($grand_children = $child->children()) { - foreach($grand_children as $grand_child) { - $data[] = $grand_child->tagName() . ' = ' . (string)$grand_child; + $headers = array( + array( + 'data' => t('Metadata'), + 'colspan' => 2, + ), + ); + $rows = array(); + foreach ($simplexml->getNamespaces(TRUE) as $ns) { + foreach ($simplexml->children($ns) as $child) { + $data = array(); + $rendered_data = ''; + if ($grand_children = $child->children()) { + foreach($grand_children as $grand_child) { + $data[] = $grand_child->getName() . ' = ' . (string)$grand_child; + } } + else { + $rendered_data = (string)$child; + } + + if ($data) { + $rendered_data = theme('item_list', $data); + } + + if ($rendered_data) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => $rendered_data, + 'class' => 'dc-content', + ), + ); + } + + } - else { - $rendered_data = (string)$child; - } - - if ($data) { - $rendered_data = theme('item_list', $data); - } - - if ($rendered_data) { - $rows[] = array( - array( - 'data' => $child->getName(), - 'class' => 'dc-tag-name', - ), - array( - 'data' => $rendered_data, - 'class' => 'dc-content', - ), - ); - } - - } - } - return theme('table', $headers, $rows, array('class' => 'dc-table')); + return theme('table', $headers, $rows, array('class' => 'dc-table')); + } } /** From 1460b8e5cea623ccbcacd9e32ca0e9ae92e3e3b6 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:16:54 -0300 Subject: [PATCH 041/117] Fix error. --- ObjectHelper.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index ce8abbcb..0aa5f590 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -433,8 +433,8 @@ class ObjectHelper { ($xsl = DOMDocument::load($xsl_path)) && ($ds = DOMDocument::loadXML($xmlstr))) { $transform = new XSLTProcessor(); - $transform->importStylesheet($domdoc); - return $transform->transformToHTML($ds); + $transform->importStylesheet($xsl); + return $transform->transformToXML($ds); } else { $simplexml = new SimpleXMLElement($xmlstr); From 7645a7b438e71d8d500f1d8863ebf7baf391173d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:38:21 -0300 Subject: [PATCH 042/117] Format XSLT and pass parameters. --- ObjectHelper.inc | 10 +++++++- xsl/convertQDC.xsl | 62 +++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 0aa5f590..ac5f9048 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -432,9 +432,17 @@ class ObjectHelper { if (($xsl_path = "$path/xsl/convertQDC.xsl") && ($xsl = DOMDocument::load($xsl_path)) && ($ds = DOMDocument::loadXML($xmlstr))) { + $xslt_opts = array( + 'BASEURL' => $base_url, + 'PATH' => url($path, array('absolute' => TRUE)), + 'baseUrl' => $base_url, //XXX: Deprecated; just here for legacy cases. + 'path' => url($path, array('absolute' => TRUE)), //XXX: Deprecated; just here for legacy cases. + ); $transform = new XSLTProcessor(); $transform->importStylesheet($xsl); - return $transform->transformToXML($ds); + $transform->setParameter('', $xslt_opts); + $transformed = $transform->transformToDoc($ds); + return $transformed->saveHTML(); } else { $simplexml = new SimpleXMLElement($xmlstr); diff --git a/xsl/convertQDC.xsl b/xsl/convertQDC.xsl index 5d881e35..62edd12e 100644 --- a/xsl/convertQDC.xsl +++ b/xsl/convertQDC.xsl @@ -1,33 +1,33 @@ - - - - - - - - -
    - - - - - - - - - - -

    MetaData

    - -
    - = -
    -
    -
    - -
    - - -
    \ No newline at end of file + + + + + +
    + + + + + + + + + + + + + + + + + +

    MetaData

    + +
    +
    +
    +
    +
    + From 47d85f6a6fbf421dde4c43bfff00a6697518d9f2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:45:56 -0300 Subject: [PATCH 043/117] Add comments and rename XSLT so it is not used by default... The XSLT will still be used if it is present, though. --- ObjectHelper.inc | 3 +-- xsl/{convertQDC.xsl => convertQDC.xsl.deprecated} | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) rename xsl/{convertQDC.xsl => convertQDC.xsl.deprecated} (85%) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index ac5f9048..f2d47e0e 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -420,7 +420,6 @@ class ObjectHelper { function getFormattedDC($item) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); - module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; $xmlstr = $item->get_datastream_dissemination($dsid); @@ -430,7 +429,7 @@ class ObjectHelper { } if (($xsl_path = "$path/xsl/convertQDC.xsl") && - ($xsl = DOMDocument::load($xsl_path)) && + ($xsl = DOMDocument::load($xsl_path)) && //Fails loading XSLT -> FALSE ($ds = DOMDocument::loadXML($xmlstr))) { $xslt_opts = array( 'BASEURL' => $base_url, diff --git a/xsl/convertQDC.xsl b/xsl/convertQDC.xsl.deprecated similarity index 85% rename from xsl/convertQDC.xsl rename to xsl/convertQDC.xsl.deprecated index 62edd12e..724f7c70 100644 --- a/xsl/convertQDC.xsl +++ b/xsl/convertQDC.xsl.deprecated @@ -1,4 +1,5 @@ + From 01c5a4736f1d12795512b92956f4d4de77bcf36c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 14:51:12 -0300 Subject: [PATCH 044/117] Fix error in CollectionClass. Was able to instantiate without a PID, which would mean that the 'collectionObject' object helper would not get created... Blargh. --- CollectionClass.inc | 8 +++----- ObjectHelper.inc | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5882a460..2ac6facc 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -28,11 +28,9 @@ class CollectionClass { * @return CollectionClass */ function __construct($pid = NULL) { - if (!empty($pid)) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $this->collectionObject = new ObjectHelper($pid); - $this->pid = $pid; - } + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + $this->collectionObject = new ObjectHelper(); + $this->pid = $pid; } public static function getCollectionQuery($pid) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index f2d47e0e..01a2b0a5 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -32,8 +32,6 @@ class ObjectHelper { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $connectionHelper = new ConnectionHelper(); - //$this->fedoraUser = $connectionHelper->getUser(); - //$this->fedoraPass = $connectionHelper->getPassword(); } private static function getBinaryLength($bin) { From 6d57165be044c0f871cf0b879a3a3a6c224ad1dd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:08:46 -0300 Subject: [PATCH 045/117] Avoid warning/error when file does not exist. --- ObjectHelper.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index f2d47e0e..9e06facf 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -2,7 +2,7 @@ /** - * @file + * @file * Object Helper Class */ @@ -429,6 +429,7 @@ class ObjectHelper { } if (($xsl_path = "$path/xsl/convertQDC.xsl") && + (is_readable($xsl_path)) && ($xsl = DOMDocument::load($xsl_path)) && //Fails loading XSLT -> FALSE ($ds = DOMDocument::loadXML($xmlstr))) { $xslt_opts = array( From 5655a5170beea922607d98258cda2942bc3eedbc Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:19:57 -0300 Subject: [PATCH 046/117] Extract Drupal collection view assembly into separate function. Hurray for enabling code reuse! --- CollectionClass.inc | 118 ++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 42 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5882a460..93733259 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -672,6 +672,75 @@ class CollectionClass { return $page; } + /** + * Assemble results in a somewhat more logical manner... + * + * ... Compared to generating a table in XSLT to contain a list (as + * renderCollection() used to do/does by default). + * + * @param $sparql_results array + * The array of results as yielded by ObjectHelper::parseSparqlResults() + * (and those associated functions which make use of it) + * @return + * An array to be passed to drupal_render, containing a pager, an unordered + * list of items, and another pager. + */ + public static function assembleCollectionView($sparql_results) { + $per_page = 20; //XXX: Make this configurable. + $pager_name = 0; + $total = count($sparql_results); + $pager_page = self::hackPager($pager_name, $per_page, $total); + + $results = array(); + foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) { + $title = $result['title']; + $obj_path = "fedora/repository/{$result['object']}"; + $tn_path = ($result['thumbnail'] ? + "fedora/repository/{$result['thumbnail']}": + "$obj_path/TN"); + $thumbnail = theme('image', $tn_path, $title, $title, array(), FALSE); + $results[] = array( + 'data' => l($thumbnail, $obj_path, array( + 'html' => TRUE, + 'attributes' => array( + 'class' => 'results-image', + ), + )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), + ); + } + if (!$results) { + drupal_set_message(t("No objects in this collection (or bad query).")); + } + else { + $first = $per_page * $pager_page; + $last = (($total - $first) > $per_page)? + ($first + $per_page): + $total; + $results_range_text = t('Results @first to @last of @total', array( + '@first' => $first + 1, + '@last' => $last, + '@total' => $total, + )); + + return array( + array( + '#type' => 'markup', + '#value' => theme('pager', array(), $per_page, $pager_name), + ), + array( + '#type' => 'markup', + '#value' => theme('item_list', $results, $result_range_text, 'ul', array( + 'class' => 'islandora-collection-results-list', + )) + ), + array( + '#type' => 'markup', + '#value' => theme('pager', array(), $per_page, $pager_name) + ), + ); + } + } + /** * render collection * @global type $base_url @@ -703,48 +772,13 @@ class CollectionClass { $objectList = ''; if (isset($content) && $content != FALSE) { if (!$xslContent) { //Didn't find an XSLT. - $intermediate_results = ObjectHelper::parse_sparql_results($content); - unset($content); - - $per_page = 20; //XXX: Make this configurable. - $pager_name = 0; - $total = count($intermediate_results); - $pager_page = self::hackPager($pager_name, $per_page, $total); - - $results = array(); - foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) { - $title = $result['title']; - $obj_path = "fedora/repository/{$result['object']}"; - $thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE); - $results[] = array( - 'data' => l($thumbnail, $obj_path, array( - 'html' => TRUE, - 'attributes' => array( - 'class' => 'results-image', - ), - )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), - ); - } - if (!$results) { - drupal_set_message(t("No objects in this collection (or bad query).")); - } - else { - $first = $per_page * $pager_page; - $last = (($total - $first) > $per_page)? - ($first + $per_page): - $total; - $results_range_text = t('Results @first to @last of @total', array( - '@first' => $first + 1, - '@last' => $last, - '@total' => $total, - )); - //$objectList = '

    ' . $results_range_text . '

    '; - $objectList .= theme('pager', array(), $per_page, $pager_name); - $objectList .= theme('item_list', $results, $result_range_text, 'ul', array( - 'class' => 'islandora-collection-results-list', - )); - $objectList .= theme('pager', array(), $per_page, $pager_name); - } + return drupal_render( + self::assembleCollectionView( + $this->collectionObject->parseSparqlResults( + $content + ) + ) + ); } else { if (!$pageNumber) { From ee2477df91ef79fa1ae6714decda506fe9bea3f0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:20:50 -0300 Subject: [PATCH 047/117] Add the page parameter to the islandora_tabs hook call. ... Facilitates implementation of equivalent functionality, where the object was instantiated with the PID, and then the page was passed to the method declared in your ISLANDORACM stream. --- fedora_repository.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index 5b6052b1..a9209294 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1071,7 +1071,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $object_details = array(); } - $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid); + $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); $cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs); return tabs_render($cmodels_tabs); From d2b0a11a7a065ad641743d0d44bd1e6d4eb6e9b7 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:20:46 -0300 Subject: [PATCH 048/117] Truncate titles for regular display to 60 character +/- a word. Should make the length an actual configurable value... Shouldn't be hard, though. --- CollectionClass.inc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 18d5a107..b027ac4c 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -687,23 +687,27 @@ class CollectionClass { $per_page = 20; //XXX: Make this configurable. $pager_name = 0; $total = count($sparql_results); - $pager_page = self::hackPager($pager_name, $per_page, $total); + $pager_page = self::hackPager($pager_name, $per_page, $total); + $max_title_length = 60; $results = array(); foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) { - $title = $result['title']; + $title = $result['title']; + $truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5); $obj_path = "fedora/repository/{$result['object']}"; $tn_path = ($result['thumbnail'] ? "fedora/repository/{$result['thumbnail']}": - "$obj_path/TN"); - $thumbnail = theme('image', $tn_path, $title, $title, array(), FALSE); + "$obj_path/TN"); + + $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + $results[] = array( 'data' => l($thumbnail, $obj_path, array( 'html' => TRUE, 'attributes' => array( 'class' => 'results-image', ), - )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), + )) . l($truncated_title, $obj_path, array('attributes' => array('class' => 'results-text'))), ); } if (!$results) { From ee2b6a95882bb3269c5668679e79667df516fb9b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:22:19 -0300 Subject: [PATCH 049/117] Use hook_islandora_tabs() to add ALL the tabs. ... Including those provided by islandora proper. --- fedora_repository.module | 109 +++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 45 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index a9209294..fec7256e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -951,6 +951,63 @@ function makeObject($pid, $dsID) { $objectHelper->makeObject($pid, $dsID); } +/** + * Implementation of hook_islandora_tabs(). + * + * @param $content_models array + * An array of ContentModel objects to which the current Fedora Object + * subscribes. + * @param $pid string + * A string containing the Fedora PID of the current Fedora Object. + * @param $page_number integer + * An integer for which page we should start on in the loaded object. + * @return array + * An array containing a tabset (an array of tabpages), renderable with + * drupal_render(). + */ +function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { + $cmodels_tabs = array( + '#type' => 'tabset', + ); + + foreach ($content_models as $content_model) { + $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); + + // Each content model may return either a tabpage array or plain HTML. If + // it is HTML, stick it in a tabpage. + if (is_array($content_model_fieldset)) { + $cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset); + } + else { + $cmodels_tabs[$content_model->pid] = array( + '#type' => 'tabpage', + '#title' => $content_model->name, + '#content' => $content_model_fieldset, + ); + } + } + + // Add a 'manage object' tab for all objects, where detailed list of content is shown. + // XXX: Perhaps this should be extracted into its own object? + module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); + $obj = new FedoraObjectDetailedContent($pid); + + //can disable showing the object details tab in admin UI + if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + $object_details = $obj->showFieldSets(); + if ($object_details['fedora_object_details']['#selected'] == TRUE) { + foreach (element_children($cmodels_tabs) as $key) { + $cmodels_tabs[$key]['#selected'] = FALSE; + } + } + } + else { + $object_details = array(); + } + + return array_merge($cmodels_tabs, $object_details); +} + /** * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) * Reads the pid and datastream id as url parameters. Queries the collection object for the query @@ -984,7 +1041,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $pid = variable_get('fedora_repository_pid', 'islandora:root'); } - $item = new fedora_item($pid); + $item = new Fedora_Item($pid); if (!$item->exists()) { drupal_not_found(); exit(); @@ -1023,57 +1080,19 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU return makeObject($pid, $dsId); } - $content = '
    '; - - module_load_include('inc', 'fedora_repository', 'CollectionClass'); - $collectionClass = new CollectionClass(); - module_load_include('inc', 'fedora_repository', 'ContentModel'); - module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); $breadcrumbs = array(); $objectHelper->getBreadcrumbs($pid, $breadcrumbs); drupal_set_breadcrumb(array_reverse($breadcrumbs)); - $offset = $limit * $page_number; $content_models = $objectHelper->get_content_models_list($pid); -// Each content model may return either a tabset array or plain HTML. If it's HTML, stick it in a tab. - $cmodels_tabs = array( - '#type' => 'tabset', - ); - foreach ($content_models as $content_model) { - $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); - if (is_array($content_model_fieldset)) { - $cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset); - } - else { - $cmodels_tabs[$content_model->pid] = array( - '#type' => 'tabpage', - '#title' => $content_model->name, - '#content' => $content_model_fieldset, - ); - } - } -// Add a 'manage object' tab for all objects, where detailed list of content is shown. - $obj = new FedoraObjectDetailedContent($pid); - - //can disable showing the object details tab in admin UI - if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { - $object_details = $obj->showFieldSets(); - if ($object_details['fedora_object_details']['#selected'] == TRUE) { - foreach ($cmodels_tabs as &$cmodel_tab) { - if (is_array($cmodel_tab)) { - $cmodel_tab['#selected'] = FALSE; - } - } - } - } - else { - $object_details = array(); - } - $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); - $cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs); - + + $cmodels_tabs = array( + '#type' => 'tabset', + ); + + $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); return tabs_render($cmodels_tabs); } From 83cd4b871a063992589d0ff3245747036b310744 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:46:45 -0300 Subject: [PATCH 050/117] Introduce hook_islandora_tabs_alter(). Called just before return of drupal_render()'d markup. Passed the tabset and associative array of the parameters with which hook_islandora_tabs() was called; that is: array( 'content_models' => {an array of ContentModel objects}, 'pid' => {the PID of the object being rendered}, 'page' => {the page of the object to be displayed}, ) --- fedora_repository.module | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index fec7256e..7a1c7946 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1086,13 +1086,24 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $content_models = $objectHelper->get_content_models_list($pid); + //Get the tabs from all modules... $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); $cmodels_tabs = array( '#type' => 'tabset', ); - $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); + + //Assemble parameters, to pass during alter + $params = array( + 'content_models' => $content_models, + 'pid' => $pid, + 'page' => $page_number, + ); + + //Allow returned tabs to be altered, before return. + drupal_alter('islandora_tabs', $cmodels_tabs, $params); + return tabs_render($cmodels_tabs); } From 73c55ca3caffa0f8e8c5c4ad295d955af9f25b98 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 15:10:09 -0300 Subject: [PATCH 051/117] Use hook_islandora_tabs_alter() to ensure that fedora_object_details tab remains selected. --- fedora_repository.module | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 7a1c7946..a1151afd 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -994,20 +994,36 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { //can disable showing the object details tab in admin UI if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { - $object_details = $obj->showFieldSets(); - if ($object_details['fedora_object_details']['#selected'] == TRUE) { - foreach (element_children($cmodels_tabs) as $key) { - $cmodels_tabs[$key]['#selected'] = FALSE; - } - } - } - else { - $object_details = array(); + $object_details = $obj->showFieldSets(); + $cmodel_tabs = array_merge($cmodels_tabs, $object_details); } return array_merge($cmodels_tabs, $object_details); } +/** + * Implementation of hook_islandora_tabs_alter(). + * + * @param &$tabs array + * The array of tabs/tabset to alter. + * @param $params array + * An associative array containing the parameters with which the original + * hook was called. + * @see fedora_repository_get_items() + */ +function fedora_repository_islandora_tabs_alter(&$tabs, $params) { + //Deselect all other tabs if the fedora_object_details tab is supposed + // to be selected. + $object_details_key = 'fedora_object_details'; + if ($tabs[$object_details_key]['#selected']) { + foreach (element_children($tabs) as $key) { + if ($key != $object_details_key) { + $tabs[$key]['#selected'] = FALSE; + } + } + } +} + /** * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) * Reads the pid and datastream id as url parameters. Queries the collection object for the query From c7e05f4c3004ac7a58ebab0b558cc39314e68639 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 15:52:04 -0300 Subject: [PATCH 052/117] Improve code documentation. --- fedora_repository.module | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index a1151afd..886ab4d6 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -966,9 +966,7 @@ function makeObject($pid, $dsID) { * drupal_render(). */ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { - $cmodels_tabs = array( - '#type' => 'tabset', - ); + $cmodels_tabs = array(); foreach ($content_models as $content_model) { $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); @@ -1025,17 +1023,26 @@ function fedora_repository_islandora_tabs_alter(&$tabs, $params) { } /** - * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) - * Reads the pid and datastream id as url parameters. Queries the collection object for the query - * if there is no query datastream falls back to the query shipped with the module. + * Menu callback for "fedora/repository". + * + * If user is allow, and we are given a PID and a sensical DSID, return the + * datastream via the makeObject() function; otherwise, call out to the PIDs' + * ContentModels and all Drupal modules for Islandora tabs. * - * @global type $user - * @param type $pid - * @param type $dsId - * @param type $collection - * @param type $page_number - * @param type $limit - * @return type + * @global $user stdObject + * @param $pid string + * An optional string containing the PID of an object. (defaults to islandora:root) + * @param $dsId string + * An optional string containing the dsid of an object. ("-" will be ignored + * to allow later parameters without including one). + * @param $collection string + * The collection name... Deprecated. + * @param $page_number string/integer(?) + * A page number to start on... Seems to be going towards deprecation? + * @param $limit string/integer(?) + * Used to limit the number of results returned? Deprecated? + * @return string + * A string containing markup for the rendered tabs. */ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NULL, $page_number = NULL, $limit = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -1108,7 +1115,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $cmodels_tabs = array( '#type' => 'tabset', ); - $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); + $cmodels_tabs += $hook_tabs; //Assemble parameters, to pass during alter $params = array( From 61204b9168d3a4bf1e1451078436f5b12debe9ed Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 2 May 2012 16:06:54 -0400 Subject: [PATCH 053/117] Fix datastream replacement errors. --- fedora_repository.module | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 886ab4d6..7235aa36 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -741,7 +741,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $dsLabel = $form_state['values']['dsLabel']; $streamUrl = ($file !== NULL) ? - url($file->filepath, array('absolute' => TRUE)): + $file->filepath: url($form_state['values']['reference'], array('absolute' => TRUE)); // Remove the original file extension from the label and add the new one @@ -751,10 +751,9 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label. } - - $dformat = $form_state['storage']['mime_type']; + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); From 48c155153302b4c19a2eaeee019230cfeabf3f4e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 12 Jul 2011 14:14:25 -0300 Subject: [PATCH 054/117] Fix Headers for FlowPlayer FlowPlayer requires the "Content-Length" header to be returned in order to work properly, but it wasn't getting returned in the header when a user was not logged in. A slight change to the semantics, and opening up of the getDatastream API-M method via XACML seems to work. --- ObjectHelper.inc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e866f62f..d054f233 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -107,14 +107,13 @@ class ObjectHelper { if ((!isset($user)) || $user->uid == 0) { $fedoraUser = 'anonymous'; $fedoraPass = 'anonymous'; - $contentSize = 0; - } - else { + } else { $fedoraUser = $user->name; $fedoraPass = $user->pass; - $dataStreamInfo = $item->get_datastream_info($dsID); - $contentSize = $dataStreamInfo->datastream->size; } + + $dataStreamInfo = $item->get_datastream_info($dsID); + $contentSize = $dataStreamInfo->datastream->size; if (function_exists("curl_init")) { if (!isset($mimeType)) { From 2d9c55fc5d30bc8e4165adeb0d9745a79a8621a3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 16:05:48 -0300 Subject: [PATCH 055/117] Make a little closed to convertQDC.xsl --- ObjectHelper.inc | 39 +++++++++++++++++++++++++++++---------- plugins/tagging_form.inc | 3 ++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index d054f233..975a3344 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -426,16 +426,35 @@ class ObjectHelper { $rows = array(); foreach ($simplexml->getNamespaces(TRUE) as $ns) { foreach ($simplexml->children($ns) as $child) { - $rows[] = array( - array( - 'data' => $child->getName(), - 'class' => 'dc-tag-name', - ), - array( - 'data' => (string)$child, - 'class' => 'dc-content', - ), - ); + $data = array(); + $rendered_data = ''; + if ($grand_children = $child->children()) { + foreach($grand_children as $grand_child) { + $data[] = $grand_child->tagName() . ' = ' . (string)$grand_child; + } + } + else { + $rendered_data = (string)$child; + } + + if ($data) { + $rendered_data = theme('item_list', $data); + } + + if ($rendered_data) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => $rendered_data, + 'class' => 'dc-content', + ), + ); + } + + } } diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index f00274d4..ae3bba92 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -61,10 +61,11 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tagset = new TagSet($obj); $tags = array(); foreach ($tagset->tags as $tag) { - $form_tag =& $form['tags-wrapper']['tags'][$tag['name']] = array( + $form['tags-wrapper']['tags'][$tag['name']] = array( '#prefix' => '
  • ', '#suffix' => '
  • ', ); + $form_tag =& $form['tags-wrapper']['tags'][$tag['name']]; $tag_title_text = t('Added by @creator.', array( '@creator' => $tag['creator'], From fe7628559f0099b709f336ce7a4578b820b0af07 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 24 Apr 2012 14:19:47 -0300 Subject: [PATCH 056/117] Use wrapping modify_datastream wrapper in replace datastream callback. --- fedora_repository.module | 45 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index e83d91f5..208e028e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -646,27 +646,27 @@ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLab * @return type */ function fedora_repository_replace_stream_form_validate($form, &$form_state) { -// If a file was uploaded, process it. + // If a file was uploaded, process it. if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) { -// attempt to save the uploaded file + // attempt to save the uploaded file $file = file_save_upload('file', array(), file_directory_path()); -// set error is file was not uploaded + // set error is file was not uploaded if (!$file) { form_set_error('file', 'Error uploading file.'); return; } - - $doc = new DOMDocument(); - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); + + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); - if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) { + + if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); return; } -// set files to form_state, to process when form is submitted + // set files to form_state, to process when form is submitted $form_state['values']['file'] = $file; } } @@ -683,39 +683,32 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; -// Remove the original file extension from the label and add the new one + + // Remove the original file extension from the label and add the new one $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot if ($indexOfDot !== FALSE) { $dsLabel = substr($dsLabel, 0, $indexOfDot); $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; } - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $file_basename = basename($file->filepath); - $file_directory = dirname($file->filepath); - $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); + $streamUrl = url($file->filepath, array( + 'absolute' => TRUE, + )); /* ----------------------------------------------------------------- * TODO: need a better way to get mimetypes */ + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - $info = $item->get_datastream_info($dsid); - - if($info->datastream->controlGroup == 'M') { - $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); - } elseif ($info->datastream->controlGroup == 'X') { - if($dformat == 'text/xml') { - $item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat); - } - else { - drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error'); - } + + if(in_array($info->datastream->controlGroup, array('M', 'X'))) { + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); } else { - drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error'); + drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); } $form_state['redirect'] = 'fedora/repository/' . $pid; From 842b8b5a311c50912f26bf5dffda24086ffa43a9 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 09:22:14 -0300 Subject: [PATCH 057/117] Get the extension without exploding. --- MimeClass.inc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MimeClass.inc b/MimeClass.inc index 42c11e37..b2950f6e 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -231,9 +231,7 @@ class MimeClass { * @return type */ public function get_mimetype($filename, $debug = FALSE) { - - $file_name_and_extension = explode('.', $filename); - $ext = strtolower(array_pop($file_name_and_extension)); + $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if (!empty($this->private_mime_types[$ext])) { if (TRUE === $debug) From c3ccdec4b671873c9f37cd7a3cbe504195d10970 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 10:05:45 -0300 Subject: [PATCH 058/117] Allow the addition of Redirect and External datastreams. --- ObjectHelper.inc | 14 ++++--- fedora_repository.module | 83 +++++++++++++++++++++------------------- formClass.inc | 83 +++++++++++++++++++++++++++++----------- 3 files changed, 113 insertions(+), 67 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 975a3344..8af4d06c 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -72,7 +72,6 @@ class ObjectHelper { return ' '; } - if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) { if (($cm = ContentModel::loadFromObject($pid)) == FALSE) { drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error'); @@ -91,7 +90,6 @@ class ObjectHelper { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - if (isset($item->datastreams[$dsID])) { $mimeType = $item->datastreams[$dsID]['MIMEType']; if ($label == NULL) { @@ -122,8 +120,14 @@ class ObjectHelper { $mimeType = 'image/jpeg'; } $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/objects/' . $pid . '/datastreams/' . $dsID . '/content'; + $query_options = array(); if ($version) { - $url .= '/' . $version; //drupal_urlencode($version); + $query_options['asOfDateTime'] = $version; //drupal_urlencode($version); + } + if ($query_options) { + $url = url($url, array( + 'query' => $query_options, + )); } $ch = curl_init(); $user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)"; @@ -183,7 +187,6 @@ class ObjectHelper { $curl_out = curl_exec($ch); if ($curl_out !== FALSE) { $info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); - //dd($info, 'effective URL'); if ($url !== $info) { //Handle redirect streams (the final URL is not the same as the Fedora URL) //Add the parameters passed to Drupal, leaving out the 'q' @@ -194,7 +197,7 @@ class ObjectHelper { } header('HTTP/1.1 307 Moved Temporarily'); - header('Location: ' . $info . '?' . http_build_query($query)); //Fedora seems to discard the query portion. + header('Location: ' . url($info, array('query' => $query))); } elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS //Have the webserver mediate the transfer (download and restream) @@ -210,6 +213,7 @@ class ObjectHelper { } else { //Curl error... + watchdog('fedora_repository', 'Curl error. Info: @info', array('@info' => print_r(curl_getinfo($ch), TRUE)), WATCHDOG_WARNING); } } curl_close($ch); diff --git a/fedora_repository.module b/fedora_repository.module index 208e028e..28dc4e8e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -377,37 +377,25 @@ function add_stream_form_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; return; } - module_load_include('inc', 'fedora_repository', 'MimeClass'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $pathToModule = drupal_get_path('module', 'fedora_repository'); - $file = $form_state['values']['add-stream-file-location']; - $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; - $file_basename = basename($file); - $file_directory = dirname($file); - $streamUrl = $base_url . '/' . $file_directory . '/' . drupal_urlencode($file_basename); - /* ----------------------------------------------------------------- - * need a better way to get mimetypes - */ - $mimetype = new MimeClass(); - $dformat = $mimetype->getType($file); - $controlGroup = "M"; - if ($dformat == 'text/xml') { - $controlGroup = 'X'; - } try { $item = new Fedora_Item($pid); - $item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); - $object_helper = new ObjectHelper(); - $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); + if ($file = $form_state['values']['add-stream-file-location']) { + $object_helper = new ObjectHelper(); + $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); - file_delete($file); + file_delete($file); + } } catch (exception $e) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); return; @@ -434,6 +422,7 @@ function add_stream_form(&$form_state, $pid) { * @return type */ function add_stream_form_validate($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'MimeClass'); if ($form_state['clicked_button']['#value'] == 'OK') { $form_state['rebuild'] = TRUE; return; @@ -444,15 +433,15 @@ function add_stream_form_validate($form, &$form_state) { form_set_error('', t('Data stream ID cannot be more than 64 characters.')); return FALSE; } - if (!(preg_match("/^[a-zA-Z]/", $dsid))) { - form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); + elseif (!(preg_match("/^[a-zA-Z]/", $dsid))) { + form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => $dsid))); return FALSE; } - if (strlen($dsLabel) > 64) { + elseif (strlen($dsLabel) > 64) { form_set_error('', t('Data stream Label cannot be more than 64 characters.')); return FALSE; } - if (strpos($dsLabel, '/')) { + elseif (strpos($dsLabel, '/') !== FALSE) { form_set_error('', t('Data stream Label cannot contain a "/".')); return FALSE; } @@ -462,12 +451,30 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_size' => array(30 * 1024), ); - $fileObject = file_save_upload('add-stream-file-location', $validators); - -// Move the uploaded file to Drupal's files directory. - file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); - $form_state['values']['add-stream-file-location'] = $fileObject->filepath; -// TODO: Add error checking here. + $mimetype = new MimeClass(); + $controlGroup = $form_state['values']['control_group']; + if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) { + // Move the uploaded file to Drupal's files directory. + file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); + $form_state['values']['add-stream-file-location'] = $fileObject->filepath; + $form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath); + + $file_basename = basename($fileObject->filepath); + $file_directory = dirname($fileObject->filepath); + + $form_state['storage']['stream_url'] = url($file_directory . '/' . drupal_urlencode($file_basename), array( + 'absolute' => TRUE, + )); + } + elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { + $form_state['storage']['ds_mimetype'] = $mimetype->getType($ref); + $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; + } + else { + form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); + } + + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } @@ -680,6 +687,11 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { function fedora_repository_replace_stream_form_submit($form, &$form_state) { global $base_url; $file = $form_state['values']['file']; + + if ($file !== NULL) { + $file = $form_state['values']['reference']; + } + $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; @@ -702,14 +714,9 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - if(in_array($info->datastream->controlGroup, array('M', 'X'))) { - $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); - } else { - drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); - } + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $form_state['redirect'] = 'fedora/repository/' . $pid; } @@ -1052,7 +1059,6 @@ function fedora_repository_urlencode_string($str) { * @return type */ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { - global $user; module_load_include('inc', 'fedora_repository', 'ObjectHelper'); if ($pid == NULL || $dsId == NULL) { @@ -1061,7 +1067,7 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { } $objectHelper = new ObjectHelper(); - $objectHelper->makeObject($pid, $dsId, 1, $label, FALSE, $version); + $objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version); } /** @@ -2266,9 +2272,6 @@ function theme_fedora_repository_solution_packs_list($solution_packs) { $header = array(); $rows = array(); - - - drupal_add_css(drupal_get_path('module', 'update') . '/update.css'); return $output; } diff --git a/formClass.inc b/formClass.inc index 713f1fcb..db90798c 100644 --- a/formClass.inc +++ b/formClass.inc @@ -656,17 +656,21 @@ class formClass { } } - $form['add_datastream_label'] = array( - '#value' => t('

    Add Datastream:

    '), - '#weight' => -10, + $form['fieldset'] = array( + '#type' => 'fieldset', + '#title' => t('Add datastream'), ); + //$form['add_datastream_label'] = array( + // '#value' => t('

    Add Datastream:

    '), + // '#weight' => -10, + //); - $form['pid'] = array( + $form['fieldset']['pid'] = array( '#type' => 'hidden', '#value' => "$pid" ); - $form['stream_label'] = array( + $form['fieldset']['stream_label'] = array( '#title' => 'Datastream Label', '#required' => 'TRUE', '#description' => t('A Human readable label'), @@ -674,35 +678,37 @@ class formClass { ); $form['#attributes']['enctype'] = 'multipart/form-data'; - $form['add-stream-file-location'] = array( + $form['fieldset']['add-stream-file-location'] = array( '#type' => 'file', '#title' => t('Upload Document'), '#size' => 48, // '#required'=>'TRUE', - '#description' => t('The file to upload.') + '#description' => t('The file to upload. (Only for Managed and Inline)') + ); + $form['fieldset']['ds_reference'] = array( + '#type' => 'textfield', + '#title' => t('Datastream reference'), + '#size' => 48, + '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), ); $form['#redirect'] = "fedora/repository/$pid/"; - $form['submit'] = array( + $form['fieldset']['submit'] = array( '#type' => 'submit', '#value' => t('Add Datastream') ); if (!empty($unused_dsids)) { - $dsidsForForm = array(); - foreach ($unused_dsids as $dsid) { - $dsidsForForm[$dsid] = $dsid; - } - $form['stream_id'] = array( + $form['fieldset']['stream_id'] = array( '#type' => 'select', '#title' => t('Datastream ID'), '#default_value' => variable_get('feed_item_length', 'teaser'), - '#weight' => '-1', + '#weight' => -1, '#description' => t('Datastream IDs defined by the content model.'), + '#options' => array_combine($unused_dsids, $unused_dsids), ); - $form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids); } else { - $form['stream_id'] = array( + $form['fieldset']['stream_id'] = array( '#title' => 'Datastream ID', '#required' => 'TRUE', '#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'), @@ -710,6 +716,18 @@ class formClass { '#weight' => -1, ); } + $form['fieldset']['control_group'] = array( + '#type' => 'select', + '#title' => t('Control group'), + '#options' => array( + 'X' => t('Inline XML'), + 'M' => t('Managed datastream'), + 'E' => t('Externally Referenced/managed datastream'), + 'R' => t('Redirect datastream'), + ), + '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), + '#weight' => 0, + ); return $form; } @@ -836,12 +854,33 @@ class formClass { $form = array(); $form['#attributes']['enctype'] = 'multipart/form-data'; - $form['file'] = array( - '#type' => 'file', - '#title' => t('Upload Document'), - '#description' => t('The file to upload.') - ); - + + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new Fedora_Item($pid); + $info = $item->get_datastream_info($dsId); + $control_group = $info->datastream->controlGroup; + if (in_array($control_group, array('M', 'X'))) { + $form['file'] = array( + '#type' => 'file', + '#title' => t('Upload Document'), + '#description' => t('A file with which to replace the contents of this datastream.'), + ); + } + if ($control_group != 'X') { + $form['reference'] = array( + '#type' => 'textfield', + '#title' => t('Reference to object'), + '#description' => t('A URL the datastream will be updated to reference.'), + ); + } + if ($control_group == 'M') { + $form['note'] = array( + '#type' => 'item', + '#title' => t('NOTE'), + '#value' => t('If both a file and a reference are given, the file will be given preference.'), + ); + } + $form['pid'] = array( '#type' => 'value', '#value' => $pid, From b609a8fd5c19c1c525272d9514e4cd32a3facf83 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 11:04:13 -0300 Subject: [PATCH 059/117] Make control group selection optional. --- fedora_repository.module | 62 +++++++++++++++++++++------------------- formClass.inc | 50 ++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 28dc4e8e..f5e8602e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -388,7 +388,7 @@ function add_stream_form_submit($form, &$form_state) { try { $item = new Fedora_Item($pid); - $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); + $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['storage']['control_group']); if ($file = $form_state['values']['add-stream-file-location']) { $object_helper = new ObjectHelper(); @@ -450,14 +450,12 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_image_resolution' => array('85x85'), // 'file_validate_size' => array(30 * 1024), ); - - $mimetype = new MimeClass(); - $controlGroup = $form_state['values']['control_group']; - if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) { + + $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group']; + if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0)) { // Move the uploaded file to Drupal's files directory. file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); $form_state['values']['add-stream-file-location'] = $fileObject->filepath; - $form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath); $file_basename = basename($fileObject->filepath); $file_directory = dirname($fileObject->filepath); @@ -466,14 +464,25 @@ function add_stream_form_validate($form, &$form_state) { 'absolute' => TRUE, )); } - elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { - $form_state['storage']['ds_mimetype'] = $mimetype->getType($ref); + elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; } else { form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); } + $mimeClass = new MimeClass(); + $mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']); + + if (!$controlGroup) { + if ($mimetype == 'text/xml') { + $form_state['storage']['control_group'] = 'X'; + } + else { + $form_state['storage']['control_group'] = 'M'; + } + } + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } @@ -665,10 +674,14 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { return; } + /* ----------------------------------------------------------------- + * TODO: need a better way to get mimetypes + */ module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); + $mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath); - if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { + if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); return; } @@ -685,37 +698,28 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { * @param array $form_state */ function fedora_repository_replace_stream_form_submit($form, &$form_state) { - global $base_url; $file = $form_state['values']['file']; - - if ($file !== NULL) { - $file = $form_state['values']['reference']; - } - + $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; + $streamUrl = ($file !== NULL) ? + url($file->filepath, array('absolute' => TRUE)): + url($form_state['values']['reference'], array('absolute' => TRUE)); + // Remove the original file extension from the label and add the new one - $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot - if ($indexOfDot !== FALSE) { - $dsLabel = substr($dsLabel, 0, $indexOfDot); - $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; + // use strrpos to get the last dot + if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) { + $dsLabel = substr($dsLabel, 0, $indexOfDot) . + substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label. } - $streamUrl = url($file->filepath, array( - 'absolute' => TRUE, - )); + - /* ----------------------------------------------------------------- - * TODO: need a better way to get mimetypes - */ - module_load_include('inc', 'fedora_repository', 'MimeClass'); - $mimetype = new MimeClass(); - $dformat = $mimetype->getType($file->filepath); + $dformat = $form_state['storage']['mime_type']; $item = new Fedora_Item($pid); - $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $form_state['redirect'] = 'fedora/repository/' . $pid; diff --git a/formClass.inc b/formClass.inc index db90798c..a5f9bef6 100644 --- a/formClass.inc +++ b/formClass.inc @@ -331,6 +331,13 @@ class formClass { '#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')), '#description' => t('Determines when to display the list of objects when viewing a collection page.'), ); + + $form['advanced']['fedora_control_group_control_during_ingest'] = array( + '#type' => 'checkbox', + '#title' => t('Allow control groups select in datastream ingest'), + '#description' => t('Whether or not we should allow the user to select which control group to ingest a stream as, or to follow the old paradigm--to add stream IDed as XML as inline, and everything else as managed.'), + '#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE), + ); //Export functionality $form['advanced']['module']['export_area'] = array( @@ -685,12 +692,16 @@ class formClass { // '#required'=>'TRUE', '#description' => t('The file to upload. (Only for Managed and Inline)') ); - $form['fieldset']['ds_reference'] = array( - '#type' => 'textfield', - '#title' => t('Datastream reference'), - '#size' => 48, - '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), - ); + + if (variable_get('fedora_control_group_control_during_ingest', FALSE)) { + $form['fieldset']['ds_reference'] = array( + '#type' => 'textfield', + '#title' => t('Datastream reference'), + '#size' => 48, + '#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), + ); + } + $form['#redirect'] = "fedora/repository/$pid/"; $form['fieldset']['submit'] = array( '#type' => 'submit', @@ -716,18 +727,21 @@ class formClass { '#weight' => -1, ); } - $form['fieldset']['control_group'] = array( - '#type' => 'select', - '#title' => t('Control group'), - '#options' => array( - 'X' => t('Inline XML'), - 'M' => t('Managed datastream'), - 'E' => t('Externally Referenced/managed datastream'), - 'R' => t('Redirect datastream'), - ), - '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), - '#weight' => 0, - ); + + if (variable_get('fedora_control_group_control_during_ingest', FALSE)) { + $form['fieldset']['control_group'] = array( + '#type' => 'select', + '#title' => t('Control group'), + '#options' => array( + 'X' => t('Inline XML'), + 'M' => t('Managed datastream'), + 'E' => t('Externally Referenced/managed datastream'), + 'R' => t('Redirect datastream'), + ), + '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), + '#weight' => 0, + ); + } return $form; } From c76891ff256f574aad6517c0ac2762affd985ffb Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 09:48:03 -0300 Subject: [PATCH 060/117] Use Sparql query for breadcrumbs. --- ObjectHelper.inc | 52 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 8af4d06c..54b384be 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -987,21 +987,33 @@ class ObjectHelper { $breadcrumbs[] = l(t('Home'), ''); } else { - $query_string = 'select $parentObject $title $content from <#ri> - where ( - $title - and $parentObject $content - and ( - $parentObject - or $parentObject - or $parentObject - ) - and $parentObject - ) - minus $content - order by $title desc'; - - if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) { + $sparql_query_string = << +PREFIX rels-ext: +SELECT ?parentObject ?title ?content +FROM <#ri> +WHERE { + ?this fedora-model:label ?title ; + ?relationship ?parentObject . + ?parentObject fedora-model:state fedora-model:Active ; + fedora-model:hasModel ?content . + FILTER( + sameTerm(?this, ) && + ( + sameTerm(?relationship, rels-ext:isMemberOfCollection) || + sameTerm(?relationship, rels-ext:isMemberOf) || + sameTerm(?relationship, rels-ext:isPartOf) + ) && + !sameTerm(?content, ) + ) . +} +ORDER BY DESC(?title) +EOQ; + + $results = self::performSparqlQuery($sparql_query_string); + $next_pid = NULL; + + if (count($results) > 0 && $level > 0) { $parent = $results[0]['parentObject']; $this_title = $results[0]['title']; @@ -1011,13 +1023,17 @@ class ObjectHelper { $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); - $level--; - $this->getBreadcrumbs($parent, $breadcrumbs); + $next_pid = $parent; } else { watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. - $this->getBreadcrumbs($root, $breadcrumbs); //And render the last two links and break (on the next pass). + $next_pid = $root; //And cue the last two links to render and break recursion (on the next pass). + } + + if ($next_pid !== NULL) { + $level--; + $this->getBreadcrumbs($next_pid, $breadcrumbs); } } } From 948bba982726d4aad154db8ae98dcf0f8e40a26b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 26 Apr 2012 10:03:45 -0300 Subject: [PATCH 061/117] Generate the download form. ... As opposed to spitting out markup for it directly. --- ObjectHelper.inc | 20 ++++---------------- fedora_repository.module | 36 ++++++++++++++++++++++++++++++++++++ plugins/tagging_form.inc | 2 +- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 54b384be..fb28a9ef 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -358,7 +358,7 @@ class ObjectHelper { $content = ''; $id = $dataStreamValue->ID; $label = $dataStreamValue->label; - $label = str_replace("_", " ", $label); + //$label = str_replace("_", " ", $label); $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $mimeType = $dataStreamValue->MIMEType; @@ -367,20 +367,8 @@ class ObjectHelper { 'target' => '_blank', ), )); - $action = url("fedora/repository/object_download/$pid/$id/$label_deslashed"); - $downloadVersion = '
    '; - if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { - $versions = $item->get_datastream_history($id); - if (is_array($versions)) { - $downloadVersion = '
    '; - $downloadVersion .= ''; - $downloadVersion .= '
    '; - } - } + + $downloadVersion = drupal_get_form('fedora_repository_download_datastream_form', $pid, $id, $label_deslashed); return array( array( @@ -1026,7 +1014,7 @@ EOQ; $next_pid = $parent; } else { - watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_depth), WATCHDOG_WARNING); + watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_level), WATCHDOG_WARNING); $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. $next_pid = $root; //And cue the last two links to render and break recursion (on the next pass). } diff --git a/fedora_repository.module b/fedora_repository.module index f5e8602e..5b6052b1 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -623,6 +623,42 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) { $form_state['redirect'] = $base_url . "/fedora/repository/$pid"; } +function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { + $form = array( + '#action' => url("fedora/repository/object_download/$pid/$dsid/$label"), + 'submit' => array( + '#type' => 'submit', + '#value' => t('Download'), + ), + ); + + if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { + $item = new Fedora_Item($pid); + $versions = $item->get_datastream_history($dsid); + $version_array = array(); + if (is_array($versions)) { + foreach ($versions as $version) { + $version_array[] = $version->createDate; + } + } + else { + $version_array[] = $versions->createDate; + } + + if (count($version_array) > 1) { + $form['#attributes'] = array( + 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;' + ); + $form['version'] = array( + '#type' => 'select', + '#options' => array_combine($version_array, $version_array), + ); + } + } + + return $form; +} + /** * fedora repository replace stream * @param type $pid diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index ae3bba92..9b7c4658 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -70,7 +70,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tag_title_text = t('Added by @creator.', array( '@creator' => $tag['creator'], )); - $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}" + $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}"; $form_tag['tag'] = array( '#value' => l($tag['name'], $tag_mnpl_search_path, array('attributes' => array( 'title' => $tag_title_text From 373c390a8761b86508286edb747f120bfa9eefa5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:12:21 -0300 Subject: [PATCH 062/117] Try to use covertQDC.xsl before using the Drupal's table generating business. --- ObjectHelper.inc | 87 ++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index fb28a9ef..a90b3544 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -407,50 +407,59 @@ class ObjectHelper { return ''; } - $simplexml = new SimpleXMLElement($xmlstr); + if (($xsl_path = "$path/xsl/convertQDC.xsl") && + ($xsl = DOMDocument::load($xsl_path)) && + ($ds = DOMDocument::loadXML($xmlstr))) { + $transform = new XSLTProcessor(); + $transform->importStylesheet($xsl); + return $transform->transformToXML($ds); + } + else { + $simplexml = new SimpleXMLElement($xmlstr); - $headers = array( - array( - 'data' => t('Metadata'), - 'colspan' => 2, - ), - ); - $rows = array(); - foreach ($simplexml->getNamespaces(TRUE) as $ns) { - foreach ($simplexml->children($ns) as $child) { - $data = array(); - $rendered_data = ''; - if ($grand_children = $child->children()) { - foreach($grand_children as $grand_child) { - $data[] = $grand_child->tagName() . ' = ' . (string)$grand_child; + $headers = array( + array( + 'data' => t('Metadata'), + 'colspan' => 2, + ), + ); + $rows = array(); + foreach ($simplexml->getNamespaces(TRUE) as $ns) { + foreach ($simplexml->children($ns) as $child) { + $data = array(); + $rendered_data = ''; + if ($grand_children = $child->children()) { + foreach($grand_children as $grand_child) { + $data[] = $grand_child->getName() . ' = ' . (string)$grand_child; + } } + else { + $rendered_data = (string)$child; + } + + if ($data) { + $rendered_data = theme('item_list', $data); + } + + if ($rendered_data) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => $rendered_data, + 'class' => 'dc-content', + ), + ); + } + + } - else { - $rendered_data = (string)$child; - } - - if ($data) { - $rendered_data = theme('item_list', $data); - } - - if ($rendered_data) { - $rows[] = array( - array( - 'data' => $child->getName(), - 'class' => 'dc-tag-name', - ), - array( - 'data' => $rendered_data, - 'class' => 'dc-content', - ), - ); - } - - } - } - return theme('table', $headers, $rows, array('class' => 'dc-table')); + return theme('table', $headers, $rows, array('class' => 'dc-table')); + } } /** From d44aca62d12b810ba5a3c570d8ce982174cd0a47 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:38:21 -0300 Subject: [PATCH 063/117] Format XSLT and pass parameters. --- ObjectHelper.inc | 10 +++++++- xsl/convertQDC.xsl | 62 +++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index a90b3544..19c2cfc7 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -410,9 +410,17 @@ class ObjectHelper { if (($xsl_path = "$path/xsl/convertQDC.xsl") && ($xsl = DOMDocument::load($xsl_path)) && ($ds = DOMDocument::loadXML($xmlstr))) { + $xslt_opts = array( + 'BASEURL' => $base_url, + 'PATH' => url($path, array('absolute' => TRUE)), + 'baseUrl' => $base_url, //XXX: Deprecated; just here for legacy cases. + 'path' => url($path, array('absolute' => TRUE)), //XXX: Deprecated; just here for legacy cases. + ); $transform = new XSLTProcessor(); $transform->importStylesheet($xsl); - return $transform->transformToXML($ds); + $transform->setParameter('', $xslt_opts); + $transformed = $transform->transformToDoc($ds); + return $transformed->saveHTML(); } else { $simplexml = new SimpleXMLElement($xmlstr); diff --git a/xsl/convertQDC.xsl b/xsl/convertQDC.xsl index 5d881e35..62edd12e 100644 --- a/xsl/convertQDC.xsl +++ b/xsl/convertQDC.xsl @@ -1,33 +1,33 @@ - - - - - - - - -
    - - - - - - - - - - -

    MetaData

    - -
    - = -
    -
    -
    - -
    - - -
    \ No newline at end of file + + + + + +
    + + + + + + + + + + + + + + + + + +

    MetaData

    + +
    +
    +
    +
    +
    + From 1068dbde0afe3b7f171cb07b22f9639cb1fced39 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 27 Apr 2012 10:45:56 -0300 Subject: [PATCH 064/117] Add comments and rename XSLT so it is not used by default... The XSLT will still be used if it is present, though. --- ObjectHelper.inc | 3 +-- xsl/{convertQDC.xsl => convertQDC.xsl.deprecated} | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) rename xsl/{convertQDC.xsl => convertQDC.xsl.deprecated} (85%) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 19c2cfc7..bf1d1100 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -398,7 +398,6 @@ class ObjectHelper { function getFormattedDC($item) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); - module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; $xmlstr = $item->get_datastream_dissemination($dsid); @@ -408,7 +407,7 @@ class ObjectHelper { } if (($xsl_path = "$path/xsl/convertQDC.xsl") && - ($xsl = DOMDocument::load($xsl_path)) && + ($xsl = DOMDocument::load($xsl_path)) && //Fails loading XSLT -> FALSE ($ds = DOMDocument::loadXML($xmlstr))) { $xslt_opts = array( 'BASEURL' => $base_url, diff --git a/xsl/convertQDC.xsl b/xsl/convertQDC.xsl.deprecated similarity index 85% rename from xsl/convertQDC.xsl rename to xsl/convertQDC.xsl.deprecated index 62edd12e..724f7c70 100644 --- a/xsl/convertQDC.xsl +++ b/xsl/convertQDC.xsl.deprecated @@ -1,4 +1,5 @@ + From 0d6c34e10f10920c5a2c9dafe266573e1b444ca0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:08:46 -0300 Subject: [PATCH 065/117] Avoid warning/error when file does not exist. --- ObjectHelper.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index bf1d1100..9b7753f7 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -2,7 +2,7 @@ /** - * @file + * @file * Object Helper Class */ @@ -407,6 +407,7 @@ class ObjectHelper { } if (($xsl_path = "$path/xsl/convertQDC.xsl") && + (is_readable($xsl_path)) && ($xsl = DOMDocument::load($xsl_path)) && //Fails loading XSLT -> FALSE ($ds = DOMDocument::loadXML($xmlstr))) { $xslt_opts = array( From ee4427910b6fe44e8540c3302f968b3feab686b1 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:19:57 -0300 Subject: [PATCH 066/117] Extract Drupal collection view assembly into separate function. Hurray for enabling code reuse! --- CollectionClass.inc | 118 ++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 42 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5882a460..93733259 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -672,6 +672,75 @@ class CollectionClass { return $page; } + /** + * Assemble results in a somewhat more logical manner... + * + * ... Compared to generating a table in XSLT to contain a list (as + * renderCollection() used to do/does by default). + * + * @param $sparql_results array + * The array of results as yielded by ObjectHelper::parseSparqlResults() + * (and those associated functions which make use of it) + * @return + * An array to be passed to drupal_render, containing a pager, an unordered + * list of items, and another pager. + */ + public static function assembleCollectionView($sparql_results) { + $per_page = 20; //XXX: Make this configurable. + $pager_name = 0; + $total = count($sparql_results); + $pager_page = self::hackPager($pager_name, $per_page, $total); + + $results = array(); + foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) { + $title = $result['title']; + $obj_path = "fedora/repository/{$result['object']}"; + $tn_path = ($result['thumbnail'] ? + "fedora/repository/{$result['thumbnail']}": + "$obj_path/TN"); + $thumbnail = theme('image', $tn_path, $title, $title, array(), FALSE); + $results[] = array( + 'data' => l($thumbnail, $obj_path, array( + 'html' => TRUE, + 'attributes' => array( + 'class' => 'results-image', + ), + )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), + ); + } + if (!$results) { + drupal_set_message(t("No objects in this collection (or bad query).")); + } + else { + $first = $per_page * $pager_page; + $last = (($total - $first) > $per_page)? + ($first + $per_page): + $total; + $results_range_text = t('Results @first to @last of @total', array( + '@first' => $first + 1, + '@last' => $last, + '@total' => $total, + )); + + return array( + array( + '#type' => 'markup', + '#value' => theme('pager', array(), $per_page, $pager_name), + ), + array( + '#type' => 'markup', + '#value' => theme('item_list', $results, $result_range_text, 'ul', array( + 'class' => 'islandora-collection-results-list', + )) + ), + array( + '#type' => 'markup', + '#value' => theme('pager', array(), $per_page, $pager_name) + ), + ); + } + } + /** * render collection * @global type $base_url @@ -703,48 +772,13 @@ class CollectionClass { $objectList = ''; if (isset($content) && $content != FALSE) { if (!$xslContent) { //Didn't find an XSLT. - $intermediate_results = ObjectHelper::parse_sparql_results($content); - unset($content); - - $per_page = 20; //XXX: Make this configurable. - $pager_name = 0; - $total = count($intermediate_results); - $pager_page = self::hackPager($pager_name, $per_page, $total); - - $results = array(); - foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) { - $title = $result['title']; - $obj_path = "fedora/repository/{$result['object']}"; - $thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE); - $results[] = array( - 'data' => l($thumbnail, $obj_path, array( - 'html' => TRUE, - 'attributes' => array( - 'class' => 'results-image', - ), - )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), - ); - } - if (!$results) { - drupal_set_message(t("No objects in this collection (or bad query).")); - } - else { - $first = $per_page * $pager_page; - $last = (($total - $first) > $per_page)? - ($first + $per_page): - $total; - $results_range_text = t('Results @first to @last of @total', array( - '@first' => $first + 1, - '@last' => $last, - '@total' => $total, - )); - //$objectList = '

    ' . $results_range_text . '

    '; - $objectList .= theme('pager', array(), $per_page, $pager_name); - $objectList .= theme('item_list', $results, $result_range_text, 'ul', array( - 'class' => 'islandora-collection-results-list', - )); - $objectList .= theme('pager', array(), $per_page, $pager_name); - } + return drupal_render( + self::assembleCollectionView( + $this->collectionObject->parseSparqlResults( + $content + ) + ) + ); } else { if (!$pageNumber) { From c01495947a0f8accea96f4d2c3361b6711d6052f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 30 Apr 2012 18:20:50 -0300 Subject: [PATCH 067/117] Add the page parameter to the islandora_tabs hook call. ... Facilitates implementation of equivalent functionality, where the object was instantiated with the PID, and then the page was passed to the method declared in your ISLANDORACM stream. --- CollectionClass.inc | 8 +++----- ObjectHelper.inc | 2 -- fedora_repository.module | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 93733259..18d5a107 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -28,11 +28,9 @@ class CollectionClass { * @return CollectionClass */ function __construct($pid = NULL) { - if (!empty($pid)) { - module_load_include('inc', 'fedora_repository', 'ObjectHelper'); - $this->collectionObject = new ObjectHelper($pid); - $this->pid = $pid; - } + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + $this->collectionObject = new ObjectHelper(); + $this->pid = $pid; } public static function getCollectionQuery($pid) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 9b7753f7..eead665e 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -32,8 +32,6 @@ class ObjectHelper { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $connectionHelper = new ConnectionHelper(); - //$this->fedoraUser = $connectionHelper->getUser(); - //$this->fedoraPass = $connectionHelper->getPassword(); } /** diff --git a/fedora_repository.module b/fedora_repository.module index 5b6052b1..a9209294 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1071,7 +1071,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $object_details = array(); } - $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid); + $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); $cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs); return tabs_render($cmodels_tabs); From 6d6342c269e4d7ca0168c4510e10d22303dba374 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:20:46 -0300 Subject: [PATCH 068/117] Truncate titles for regular display to 60 character +/- a word. Should make the length an actual configurable value... Shouldn't be hard, though. --- CollectionClass.inc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 18d5a107..b027ac4c 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -687,23 +687,27 @@ class CollectionClass { $per_page = 20; //XXX: Make this configurable. $pager_name = 0; $total = count($sparql_results); - $pager_page = self::hackPager($pager_name, $per_page, $total); + $pager_page = self::hackPager($pager_name, $per_page, $total); + $max_title_length = 60; $results = array(); foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) { - $title = $result['title']; + $title = $result['title']; + $truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5); $obj_path = "fedora/repository/{$result['object']}"; $tn_path = ($result['thumbnail'] ? "fedora/repository/{$result['thumbnail']}": - "$obj_path/TN"); - $thumbnail = theme('image', $tn_path, $title, $title, array(), FALSE); + "$obj_path/TN"); + + $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + $results[] = array( 'data' => l($thumbnail, $obj_path, array( 'html' => TRUE, 'attributes' => array( 'class' => 'results-image', ), - )) . l($title, $obj_path, array('attributes' => array('class' => 'results-text'))), + )) . l($truncated_title, $obj_path, array('attributes' => array('class' => 'results-text'))), ); } if (!$results) { From f51cdfe115b720d8b26c77ff05d6cce6b945e0a7 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:22:19 -0300 Subject: [PATCH 069/117] Use hook_islandora_tabs() to add ALL the tabs. ... Including those provided by islandora proper. --- fedora_repository.module | 109 +++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 45 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index a9209294..fec7256e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -951,6 +951,63 @@ function makeObject($pid, $dsID) { $objectHelper->makeObject($pid, $dsID); } +/** + * Implementation of hook_islandora_tabs(). + * + * @param $content_models array + * An array of ContentModel objects to which the current Fedora Object + * subscribes. + * @param $pid string + * A string containing the Fedora PID of the current Fedora Object. + * @param $page_number integer + * An integer for which page we should start on in the loaded object. + * @return array + * An array containing a tabset (an array of tabpages), renderable with + * drupal_render(). + */ +function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { + $cmodels_tabs = array( + '#type' => 'tabset', + ); + + foreach ($content_models as $content_model) { + $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); + + // Each content model may return either a tabpage array or plain HTML. If + // it is HTML, stick it in a tabpage. + if (is_array($content_model_fieldset)) { + $cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset); + } + else { + $cmodels_tabs[$content_model->pid] = array( + '#type' => 'tabpage', + '#title' => $content_model->name, + '#content' => $content_model_fieldset, + ); + } + } + + // Add a 'manage object' tab for all objects, where detailed list of content is shown. + // XXX: Perhaps this should be extracted into its own object? + module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); + $obj = new FedoraObjectDetailedContent($pid); + + //can disable showing the object details tab in admin UI + if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + $object_details = $obj->showFieldSets(); + if ($object_details['fedora_object_details']['#selected'] == TRUE) { + foreach (element_children($cmodels_tabs) as $key) { + $cmodels_tabs[$key]['#selected'] = FALSE; + } + } + } + else { + $object_details = array(); + } + + return array_merge($cmodels_tabs, $object_details); +} + /** * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) * Reads the pid and datastream id as url parameters. Queries the collection object for the query @@ -984,7 +1041,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $pid = variable_get('fedora_repository_pid', 'islandora:root'); } - $item = new fedora_item($pid); + $item = new Fedora_Item($pid); if (!$item->exists()) { drupal_not_found(); exit(); @@ -1023,57 +1080,19 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU return makeObject($pid, $dsId); } - $content = '
    '; - - module_load_include('inc', 'fedora_repository', 'CollectionClass'); - $collectionClass = new CollectionClass(); - module_load_include('inc', 'fedora_repository', 'ContentModel'); - module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); $breadcrumbs = array(); $objectHelper->getBreadcrumbs($pid, $breadcrumbs); drupal_set_breadcrumb(array_reverse($breadcrumbs)); - $offset = $limit * $page_number; $content_models = $objectHelper->get_content_models_list($pid); -// Each content model may return either a tabset array or plain HTML. If it's HTML, stick it in a tab. - $cmodels_tabs = array( - '#type' => 'tabset', - ); - foreach ($content_models as $content_model) { - $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); - if (is_array($content_model_fieldset)) { - $cmodels_tabs = array_merge($cmodels_tabs, $content_model_fieldset); - } - else { - $cmodels_tabs[$content_model->pid] = array( - '#type' => 'tabpage', - '#title' => $content_model->name, - '#content' => $content_model_fieldset, - ); - } - } -// Add a 'manage object' tab for all objects, where detailed list of content is shown. - $obj = new FedoraObjectDetailedContent($pid); - - //can disable showing the object details tab in admin UI - if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { - $object_details = $obj->showFieldSets(); - if ($object_details['fedora_object_details']['#selected'] == TRUE) { - foreach ($cmodels_tabs as &$cmodel_tab) { - if (is_array($cmodel_tab)) { - $cmodel_tab['#selected'] = FALSE; - } - } - } - } - else { - $object_details = array(); - } - $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); - $cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs); - + + $cmodels_tabs = array( + '#type' => 'tabset', + ); + + $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); return tabs_render($cmodels_tabs); } From 67bd855852f654155ac1c68c2e5310e48da54911 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 14:46:45 -0300 Subject: [PATCH 070/117] Introduce hook_islandora_tabs_alter(). Called just before return of drupal_render()'d markup. Passed the tabset and associative array of the parameters with which hook_islandora_tabs() was called; that is: array( 'content_models' => {an array of ContentModel objects}, 'pid' => {the PID of the object being rendered}, 'page' => {the page of the object to be displayed}, ) --- fedora_repository.module | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index fec7256e..7a1c7946 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1086,13 +1086,24 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $content_models = $objectHelper->get_content_models_list($pid); + //Get the tabs from all modules... $hook_tabs = module_invoke_all('islandora_tabs', $content_models, $pid, $page_number); $cmodels_tabs = array( '#type' => 'tabset', ); - $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); + + //Assemble parameters, to pass during alter + $params = array( + 'content_models' => $content_models, + 'pid' => $pid, + 'page' => $page_number, + ); + + //Allow returned tabs to be altered, before return. + drupal_alter('islandora_tabs', $cmodels_tabs, $params); + return tabs_render($cmodels_tabs); } From 828c6965f7973fa52fea3c2a0e1f4d6e49678aba Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 15:10:09 -0300 Subject: [PATCH 071/117] Use hook_islandora_tabs_alter() to ensure that fedora_object_details tab remains selected. --- fedora_repository.module | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 7a1c7946..a1151afd 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -994,20 +994,36 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { //can disable showing the object details tab in admin UI if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { - $object_details = $obj->showFieldSets(); - if ($object_details['fedora_object_details']['#selected'] == TRUE) { - foreach (element_children($cmodels_tabs) as $key) { - $cmodels_tabs[$key]['#selected'] = FALSE; - } - } - } - else { - $object_details = array(); + $object_details = $obj->showFieldSets(); + $cmodel_tabs = array_merge($cmodels_tabs, $object_details); } return array_merge($cmodels_tabs, $object_details); } +/** + * Implementation of hook_islandora_tabs_alter(). + * + * @param &$tabs array + * The array of tabs/tabset to alter. + * @param $params array + * An associative array containing the parameters with which the original + * hook was called. + * @see fedora_repository_get_items() + */ +function fedora_repository_islandora_tabs_alter(&$tabs, $params) { + //Deselect all other tabs if the fedora_object_details tab is supposed + // to be selected. + $object_details_key = 'fedora_object_details'; + if ($tabs[$object_details_key]['#selected']) { + foreach (element_children($tabs) as $key) { + if ($key != $object_details_key) { + $tabs[$key]['#selected'] = FALSE; + } + } + } +} + /** * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) * Reads the pid and datastream id as url parameters. Queries the collection object for the query From 1463c78a382e90060c8954855a4a012fe20d1976 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 1 May 2012 15:52:04 -0300 Subject: [PATCH 072/117] Improve code documentation. --- fedora_repository.module | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index a1151afd..7235aa36 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -741,7 +741,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $dsLabel = $form_state['values']['dsLabel']; $streamUrl = ($file !== NULL) ? - url($file->filepath, array('absolute' => TRUE)): + $file->filepath: url($form_state['values']['reference'], array('absolute' => TRUE)); // Remove the original file extension from the label and add the new one @@ -751,10 +751,9 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label. } - - $dformat = $form_state['storage']['mime_type']; + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); @@ -966,9 +965,7 @@ function makeObject($pid, $dsID) { * drupal_render(). */ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { - $cmodels_tabs = array( - '#type' => 'tabset', - ); + $cmodels_tabs = array(); foreach ($content_models as $content_model) { $content_model_fieldset = $content_model->displayExtraFieldset($pid, $page_number); @@ -1025,17 +1022,26 @@ function fedora_repository_islandora_tabs_alter(&$tabs, $params) { } /** - * Sends an ITQL query to the Fedora Resource index (can only communicate with Kowari or mulgara) - * Reads the pid and datastream id as url parameters. Queries the collection object for the query - * if there is no query datastream falls back to the query shipped with the module. + * Menu callback for "fedora/repository". + * + * If user is allow, and we are given a PID and a sensical DSID, return the + * datastream via the makeObject() function; otherwise, call out to the PIDs' + * ContentModels and all Drupal modules for Islandora tabs. * - * @global type $user - * @param type $pid - * @param type $dsId - * @param type $collection - * @param type $page_number - * @param type $limit - * @return type + * @global $user stdObject + * @param $pid string + * An optional string containing the PID of an object. (defaults to islandora:root) + * @param $dsId string + * An optional string containing the dsid of an object. ("-" will be ignored + * to allow later parameters without including one). + * @param $collection string + * The collection name... Deprecated. + * @param $page_number string/integer(?) + * A page number to start on... Seems to be going towards deprecation? + * @param $limit string/integer(?) + * Used to limit the number of results returned? Deprecated? + * @return string + * A string containing markup for the rendered tabs. */ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NULL, $page_number = NULL, $limit = NULL) { module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -1108,7 +1114,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $cmodels_tabs = array( '#type' => 'tabset', ); - $cmodels_tabs = array_merge($cmodels_tabs, $hook_tabs); + $cmodels_tabs += $hook_tabs; //Assemble parameters, to pass during alter $params = array( From 2d1e6409caf87656cb1241ec1cdd17a83e73a9bf Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 4 May 2012 09:45:22 -0300 Subject: [PATCH 073/117] Add usage of imagecache_external, if available. --- CollectionClass.inc | 22 +++++++++++++++++++--- fedora_repository.module | 23 ++++++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index b027ac4c..9cebc3ce 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -678,7 +678,12 @@ class CollectionClass { * * @param $sparql_results array * The array of results as yielded by ObjectHelper::parseSparqlResults() - * (and those associated functions which make use of it) + * (and those associated functions which make use of it). + * Each result must contain: + * - 'object': The PID/URI of the child object. + * - 'title': A title for the child object. + * and may contain: + * - 'thumbnail': URI to a datastream. (will default to the 'TN' stream on the child) * @return * An array to be passed to drupal_render, containing a pager, an unordered * list of items, and another pager. @@ -695,11 +700,22 @@ class CollectionClass { $title = $result['title']; $truncated_title = truncate_utf8($title, $max_title_length, TRUE, TRUE, 5); $obj_path = "fedora/repository/{$result['object']}"; + + //Get a thumbnail $tn_path = ($result['thumbnail'] ? "fedora/repository/{$result['thumbnail']}": "$obj_path/TN"); - - $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + + $thumbnail = NULL; + if ($thumbnail === NULL && + module_exists('imagecache_external') && + is_callable('theme_imagecache_external_image') && + variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { + $thumbnail = theme('imagecache_external_image', 'fedora_repository_collection_thumbnail', $tn_path, $truncated_title, $title); + } + if ($thumbnail === NULL) { + $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + } $results[] = array( 'data' => l($thumbnail, $obj_path, array( diff --git a/fedora_repository.module b/fedora_repository.module index 7235aa36..67397716 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -620,10 +620,11 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) { } catch (exception $e) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); } - $form_state['redirect'] = $base_url . "/fedora/repository/$pid"; + $form_state['redirect'] = "fedora/repository/$pid"; } function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); $form = array( '#action' => url("fedora/repository/object_download/$pid/$dsid/$label"), 'submit' => array( @@ -2382,3 +2383,23 @@ function fedora_repository_forms($form_id) { } return $forms; } + +function usc_mirc_imagecache_default_presets() { + return array( + 'fedora_repository_collection_thumbnail' => array( + 'presetname' => 'fedora_repository_collection_thumbnail', + 'actions' => array( + 0 => array( + 'weight' => 0, + 'module' => 'imagecache', + 'action' => 'imagecache_scale', + 'data' => array( + 'width' => 200, + 'height' => 200, + 'upscale' => TRUE, + ), + ), + ), + ), + ); +} From 830b597c4a01b18c510441cda59981eacef161a0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 4 May 2012 10:44:30 -0300 Subject: [PATCH 074/117] Add parameter to suppress error messages on get_datastream --- api/fedora_item.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index fdb4a00d..1b9f9798 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -506,13 +506,13 @@ RDF; * @param type $as_of_date_time * @return type */ - function get_datastream($dsid, $as_of_date_time = '') { + function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) { $params = array( 'pid' => $this->pid, 'dsID' => $dsid, 'asOfDateTime' => $as_of_date_time, ); - $object = self::soap_call('getDatastream', $params); + $object = self::soap_call('getDatastream', $params, $quiet); return $object->datastream; } From f674a99b0b043e11c18b1b08ed10f499f9adfea4 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 4 May 2012 10:45:26 -0300 Subject: [PATCH 075/117] Use url() to build query. --- ObjectHelper.inc | 2 +- api/fedora_utils.inc | 23 +++++++++++++++++------ fedora_repository.module | 36 ------------------------------------ 3 files changed, 18 insertions(+), 43 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 67be7161..de871cdc 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -163,7 +163,6 @@ class ObjectHelper { CURLOPT_FOLLOWLOCATION => TRUE, // allow redirects //CURLOPT_TIMEOUT => 15, // times out after 15s CURLOPT_USERAGENT => $user_agent, - CURLOPT_URL => $url, CURLOPT_USERPWD => "$fedoraUser:$fedoraPass", // There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error. //CURLOPT_HTTPAUTH => CURLAUTH_ANY, @@ -243,6 +242,7 @@ class ObjectHelper { CURLOPT_HTTPGET => TRUE, //CURLOPT_NOBODY sets it to 'HEAD' CURLOPT_RETURNTRANSFER => FALSE, //Want to output as efficiently as possible now... ); + curl_setopt_array($ch, $opts); $curl_stat = curl_exec($ch); if (!$curl_stat) { diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index 459c86ba..a730d7a4 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -239,13 +239,24 @@ function get_collections_as_option_array() { $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); $namespaces = explode(':', $allowed_string); $query = 'select $object $title from <#ri> - where ($object $title - and $object - and $object ) - order by $title'; + where ($object $title + and $object + and $object ) + order by $title'; $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); - $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query="; - $content = do_curl($url . htmlentities(urlencode($query))); + + $options = array( + 'type' => 'tuples', + 'flush' => 'TRUE', + 'format' => 'csv', + 'limit' => '1000', + 'lang' => 'itql', + 'stream' => 'on', + 'query' => $query, + ); + //The url function will take care of URL encoding... + $content = do_curl(url($url, array('query' => $options))); + $list = explode("\n", $content); array_shift($list); $list = preg_replace('/info:fedora\//', '', $list); diff --git a/fedora_repository.module b/fedora_repository.module index 57c7f5ae..67397716 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -660,42 +660,6 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $ return $form; } -function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) { - $form = array( - '#action' => url("fedora/repository/object_download/$pid/$dsid/$label"), - 'submit' => array( - '#type' => 'submit', - '#value' => t('Download'), - ), - ); - - if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) { - $item = new Fedora_Item($pid); - $versions = $item->get_datastream_history($dsid); - $version_array = array(); - if (is_array($versions)) { - foreach ($versions as $version) { - $version_array[] = $version->createDate; - } - } - else { - $version_array[] = $versions->createDate; - } - - if (count($version_array) > 1) { - $form['#attributes'] = array( - 'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;' - ); - $form['version'] = array( - '#type' => 'select', - '#options' => array_combine($version_array, $version_array), - ); - } - } - - return $form; -} - /** * fedora repository replace stream * @param type $pid From 7749a2f39f2f86aac5dd85ae66897a0d39e5e0e9 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 4 May 2012 11:26:50 -0300 Subject: [PATCH 076/117] Introduce and use function to render an image. This function tries to make use of imagecache(_external) if it is avaiable; otherwise, falls back to using theme('image'). --- CollectionClass.inc | 11 +------- fedora_repository.module | 55 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 9cebc3ce..81f5f143 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -706,16 +706,7 @@ class CollectionClass { "fedora/repository/{$result['thumbnail']}": "$obj_path/TN"); - $thumbnail = NULL; - if ($thumbnail === NULL && - module_exists('imagecache_external') && - is_callable('theme_imagecache_external_image') && - variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { - $thumbnail = theme('imagecache_external_image', 'fedora_repository_collection_thumbnail', $tn_path, $truncated_title, $title); - } - if ($thumbnail === NULL) { - $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); - } + $thumbnail = _fedora_repository_render_image($tn_path); $results[] = array( 'data' => l($thumbnail, $obj_path, array( diff --git a/fedora_repository.module b/fedora_repository.module index 67397716..3ff8b292 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2384,7 +2384,10 @@ function fedora_repository_forms($form_id) { return $forms; } -function usc_mirc_imagecache_default_presets() { +/** + * Implementation of hook_imagecache_default_presets(). + */ +function fedora_repository_imagecache_default_presets() { return array( 'fedora_repository_collection_thumbnail' => array( 'presetname' => 'fedora_repository_collection_thumbnail', @@ -2403,3 +2406,53 @@ function usc_mirc_imagecache_default_presets() { ), ); } + +/** + * Actually render an image, given an arbitrary path and preset. + * + * Note: If imagecache_external is not available, the full-sized image will be + * produced... Might want to look into restricting the display size by adding + * the width and height attributes to the theme('image') call, based on the + * selected preset? (get the presets and figure out the size from its actions?) + * + * @param $tn_path string + * @param $imagecache_preset string + * @return + * Markup for the image, making use of imagecache_external if it is available. + */ +function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_repository_collection_thumbnail') { + $thumbnail = NULL; + if ($thumbnail === NULL && + module_exists('imagecache_external') && + is_callable('theme_imagecache_external_image') && + variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { + $thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title); + } + if ($thumbnail === NULL) { + $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + } + + return $thumbnail; +} + +/** + * Render an image, given a PID, DSID and preset. + * + * Produces a Drupal path for the image, passes to + * _fedora_repository_render_image(), and returns the result. + * + * @see _fedora_repository_render_image() + * @param $pid string + * A string containing a Fedora PID. + * @param $dsid + * A string indicating a DSID on the object indicated by $pid. + * @param $imagecache_preset + * An imagecache preset with which to render the image; defaults to + * fedora_repository_collection_thumbnail, which is added in this module's + * implementation of hook_imagecache_default_presets(). + */ +function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedora_repository_collection_thumbnail') { + $tn_path = "fedora/repository/$pid/$dsid"; + + return _fedora_repository_render_image($tn_path, $imagecache_preset); +} From 9a52580ed95e7fca637eb216ead988535f00a949 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 7 May 2012 14:19:55 -0300 Subject: [PATCH 077/117] Comment refinement. --- api/fedora_item.inc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 1b9f9798..bc378471 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -230,6 +230,8 @@ class Fedora_Item { * The predicate namespace. * @param boolean $literal_value * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). + * @return ??? + * Value returned from SOAP call for modify_datastream. */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { //dd($this, 'The Fedora_Item'); @@ -847,11 +849,10 @@ RDF; /** * Get Next PID in Namespace - * @param type $pid_namespace - * @return type + * @param $pid_namespace string + * @return string */ static function get_next_PID_in_namespace($pid_namespace = '') { - if (empty($pid_namespace)) { // Just get the first one in the config settings. $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); @@ -925,11 +926,11 @@ RDF; /** * Modify Object - * @param type $label - * @param type $state - * @param type $ownerId - * @param type $logMessage - * @param type $quiet + * @param $label string + * @param $state string + * @param $ownerId string + * @param $logMessage string + * @param $quiet boolean * @return type */ function modify_object($label = '', $state = NULL, $ownerId = NULL, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { From 933d0bc5980f44e6198042d650240e3a98e0c71a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 7 May 2012 19:24:40 -0300 Subject: [PATCH 078/117] Fix stream addition with language prefixes. --- fedora_repository.module | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 3ff8b292..985761d1 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -384,7 +384,7 @@ function add_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; - $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; + $dsLabel = $form_state['values']['stream_label'] . substr($form_state['storage']['stream_url'], strrpos($form_state['storage']['stream_url'], '.')); // Add the file extention to the end of the label.; try { $item = new Fedora_Item($pid); @@ -400,6 +400,7 @@ function add_stream_form_submit($form, &$form_state) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); return; } + unset($form_state['storage']); //Using storage; need to unset it for forms to work properly... $form_state['rebuild'] = TRUE; } @@ -452,17 +453,13 @@ function add_stream_form_validate($form, &$form_state) { ); $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group']; - if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0)) { + if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)))) { // Move the uploaded file to Drupal's files directory. - file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); - $form_state['values']['add-stream-file-location'] = $fileObject->filepath; + $file_path = $fileObject->filepath; + file_move($file_path, 0, FILE_EXISTS_RENAME); + $form_state['values']['add-stream-file-location'] = $file_path; - $file_basename = basename($fileObject->filepath); - $file_directory = dirname($fileObject->filepath); - - $form_state['storage']['stream_url'] = url($file_directory . '/' . drupal_urlencode($file_basename), array( - 'absolute' => TRUE, - )); + $form_state['storage']['stream_url'] = file_create_url($file_path); } elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; @@ -726,6 +723,9 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { // set files to form_state, to process when form is submitted $form_state['values']['file'] = $file; } + elseif (!$form_state['values']['ds_reference']) { + form_set_error('', 'Need either a file or a reference!'); + } } /** @@ -742,7 +742,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $dsLabel = $form_state['values']['dsLabel']; $streamUrl = ($file !== NULL) ? - $file->filepath: + file_create_url($file->filepath): url($form_state['values']['reference'], array('absolute' => TRUE)); // Remove the original file extension from the label and add the new one @@ -758,6 +758,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $item = new Fedora_Item($pid); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); + unset($form_state['storage']); $form_state['redirect'] = 'fedora/repository/' . $pid; } From 8bd4b29e385e6ff07e62534d5afad1697b1d598b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 7 May 2012 19:46:46 -0300 Subject: [PATCH 079/117] Test and add configuration. --- fedora_repository.module | 3 ++- formClass.inc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index 985761d1..6371c52e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2426,7 +2426,8 @@ function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_ if ($thumbnail === NULL && module_exists('imagecache_external') && is_callable('theme_imagecache_external_image') && - variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { + variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE) && + imagecache_external_can_fetch($tn_path, TRUE)) { $thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title); } if ($thumbnail === NULL) { diff --git a/formClass.inc b/formClass.inc index a5f9bef6..7dc1ca6f 100644 --- a/formClass.inc +++ b/formClass.inc @@ -323,6 +323,21 @@ class formClass { '#default_value' => variable_get('fedora_object_restrict_datastreams', FALSE), '#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'), ); + + $form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array( + '#type' => 'checkbox', + '#title' => t('Allow imagecache_external use for thumbnails in collection view'), + '#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE), + '#description' => t('If enabled, the default collection list view (or ' . + 'anywhere the function "@function" is used) will try to use ' . + 'imagecache_external, defaulting to the "@preset" preset. Note that ' . + 'this means it will NOT (currently) work with collections rendered via "@xsl".', + array( + '@function' => '_fedora_repository_render_image()', + '@preset' => 'fedora_repository_collection_thumbnail', + '@xsl' => 'sparql_to_html.xsl', + )), + ); $form['advanced']['fedora_collection_display_list'] = array( '#type' => 'select', From c1615e48750eaf2d1ab8efa6c5af732be8acd2ea Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 7 May 2012 20:36:36 -0300 Subject: [PATCH 080/117] Use Drupal functions in XSLT to generate URLs. Also, use imagecache_external! --- fedora_repository.module | 10 ++++++++++ formClass.inc | 4 ++-- xsl/sparql_to_html.xsl | 28 ++++++++++++++++------------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 6371c52e..8642de9c 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2458,3 +2458,13 @@ function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedor return _fedora_repository_render_image($tn_path, $imagecache_preset); } + +/** + * Convenience function used in XSLT callback... + * + * @param $string string + * A string containing some markup to convert to a domnode. + */ +function fedora_repository_string_to_domnode($string) { + return DOMDocument::loadXML($string); +} diff --git a/formClass.inc b/formClass.inc index 7dc1ca6f..40b2cb4e 100644 --- a/formClass.inc +++ b/formClass.inc @@ -330,8 +330,8 @@ class formClass { '#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE), '#description' => t('If enabled, the default collection list view (or ' . 'anywhere the function "@function" is used) will try to use ' . - 'imagecache_external, defaulting to the "@preset" preset. Note that ' . - 'this means it will NOT (currently) work with collections rendered via "@xsl".', + 'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' . + 'be updated to use this function.', array( '@function' => '_fedora_repository_render_image()', '@preset' => 'fedora_repository_collection_thumbnail', diff --git a/xsl/sparql_to_html.xsl b/xsl/sparql_to_html.xsl index c5974403..0c9c5bcc 100644 --- a/xsl/sparql_to_html.xsl +++ b/xsl/sparql_to_html.xsl @@ -1,11 +1,14 @@ - - - + + + + + + fedora_repository_collection_thumbnail + - @@ -42,7 +45,7 @@
  • - + <Prev @@ -53,7 +56,7 @@
  • - + Next> @@ -64,7 +67,7 @@
  • - + <Prev   @@ -72,7 +75,7 @@
  • - + Next> @@ -101,12 +104,12 @@ - + - + @@ -116,10 +119,11 @@ - + +
    From 536c6e58aa1788bf50c5f882a7852f91ada79a9a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 8 May 2012 10:48:17 -0300 Subject: [PATCH 081/117] Add missing include. --- ObjectHelper.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index de871cdc..25dd8c53 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1193,6 +1193,7 @@ EOQ; $queryUrl = url(variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), array('query' => $options)); //Perform the query. + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); $curl_result = do_curl_ext($queryUrl); //If the query failed, write message to the logs and return. From 06907b7a866f50f8d9930dac2e0bb7d00d7f38e2 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Wed, 9 May 2012 11:39:25 -0300 Subject: [PATCH 082/117] fixes for tickets ISLANDORA-596 and ISLANDORA-597 --- CollectionClass.inc | 3 +++ plugins/tagging_form.inc | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5882a460..fcd59d00 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -687,6 +687,9 @@ class CollectionClass { global $base_url; $collection_pid = $pid; //we will be changing the pid later maybe $parsedContent = NULL; + if(!isset($this->collectionObject)){ + $this->collectionObject = new ObjectHelper($pid); + } $contentModels = $this->collectionObject->get_content_models_list($pid); $isCollection = FALSE; //if this is a collection object store the $pid in the session as it will come in handy diff --git a/plugins/tagging_form.inc b/plugins/tagging_form.inc index f00274d4..718459b2 100644 --- a/plugins/tagging_form.inc +++ b/plugins/tagging_form.inc @@ -61,7 +61,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tagset = new TagSet($obj); $tags = array(); foreach ($tagset->tags as $tag) { - $form_tag =& $form['tags-wrapper']['tags'][$tag['name']] = array( + $form_tag = $form['tags-wrapper']['tags'][$tag['name']] = array( '#prefix' => '
  • ', '#suffix' => '
  • ', ); @@ -69,7 +69,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) { $tag_title_text = t('Added by @creator.', array( '@creator' => $tag['creator'], )); - $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}" + $tag_mnpl_search_path = "fedora/repository/mnpl_advanced_search/tag:{$tag['name']}"; $form_tag['tag'] = array( '#value' => l($tag['name'], $tag_mnpl_search_path, array('attributes' => array( 'title' => $tag_title_text From df42d77c10789bc82cdb87ad117ba70690cc1033 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Thu, 10 May 2012 08:47:50 -0300 Subject: [PATCH 083/117] fix for ISLANDORA 604 and added some defines to FedoraItem.inc --- CollectionClass.inc | 2 +- api/fedora_item.inc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index fcd59d00..6992a34c 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -105,7 +105,7 @@ class CollectionClass { */ function getRelatedItems($pid, $query_string = NULL, $limit = NULL, $offset = NULL) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid)) { drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); return ' '; diff --git a/api/fedora_item.inc b/api/fedora_item.inc index fdb4a00d..d287225c 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -7,6 +7,8 @@ define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#'); define("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#'); define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#'); +define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#'); +define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#"); /** * Fedora Item Class From 1c7666842b1b517c0eb41c717e794961e45b7939 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:26:51 -0300 Subject: [PATCH 084/117] invoke custom hooks to retrieve metadata display instead of hard-coding it --- plugins/FedoraObjectDetailedContent.inc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 30e222a6..a6656571 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -48,8 +48,29 @@ class FedoraObjectDetailedContent { $tabset['fedora_object_details']['tabset'] = array( '#type' => 'tabset', ); - - $dc_html = $objectHelper->getFormattedDC($this->item); + + // ***** Jason: begin object details display profiles + module_load_include('inc', 'fedora_repository', 'ObjectDetails'); + $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt_dc'); + $profiles = module_invoke_all("islandora_object_details_display"); + $profile = $profiles[$object_details_profile]; + if (!isset($profile)) { + // default behaviour + drupal_set_message(t("There was an error reading the default object details display profile"), "error"); + $dc_html = $objectHelper->getFormattedDC($this->item); + } + else { + // invoke the requested display profile + require_once(drupal_get_path('module', $profile['module']) ."/". $profile['file']); + $details_function = $profile['function']; + if (function_exists($details_function)) { + $dc_html = $details_function($this->item); + } + else { + // problem + } + } + // ***** Jason: end object details display profiles $i = 0; if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { From 6701587fd4df77ed7b946b30a4e93a4916b73ff5 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:34:39 -0300 Subject: [PATCH 085/117] added menu path to load object profile configurations, setup admin page to request all profiles and create a table for user selection --- formClass.inc | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/formClass.inc b/formClass.inc index 713f1fcb..4d899ef1 100644 --- a/formClass.inc +++ b/formClass.inc @@ -179,6 +179,16 @@ class formClass { 'access arguments' => array('view fedora collection'), ); + // ***** Jason: begin menu path for xslt config page + $items['admin/settings/fedora_repository/object_details_xslt'] = array( + 'title' => "", + 'type' => MENU_CALLBACK, + 'page callback' => 'drupal_get_form', + 'page arguments' => array('fedora_repository_object_details_XSLT_config'), + 'file' => 'ObjectDetails.inc', + 'access arguments' => array('administer site configuration'), + ); + // ***** Jason: end menu path for xslt config page return $items; } @@ -233,7 +243,7 @@ class formClass { theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) : theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '

    ', ); - + $form['fedora_soap_manage_url'] = array( '#type' => 'textfield', '#title' => t('Fedora SOAP management URL'), @@ -241,7 +251,7 @@ class formClass { '#required' => TRUE, '#weight' => -10 ); - + // will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php if (variable_get('allow_open_namespace', TRUE)) { $form['fedora_namespace'] = array( @@ -286,6 +296,7 @@ class formClass { '#collapsible' => TRUE, '#collapsed' => TRUE, ); + //when checked show object details tab $form['tabs']['fedora_repository_show_object_details_tab'] = array( '#type' => 'checkbox', @@ -293,7 +304,29 @@ class formClass { '#default_value' => variable_get('fedora_repository_show_object_details_tab', TRUE), '#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"), ); - + + // ***** Jason: begin object details display profiles + module_load_include('inc', 'fedora_repository', 'ObjectDetails'); + $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); + $profiles = module_invoke_all("islandora_object_details_display"); + + $display_options = array(); + foreach ($profiles as $machine_name => $profile) { + $display_options[$machine_name] = $profile['name']; + $config_path = $profile['config']; + if (isset($config_path) && $config_path != ""){ + $display_options[$machine_name] .= " (". l("config", $config_path, array()) .")"; + } + } + $form['tabs']['islandora_object_details_display_table'] = array( + '#type' => 'radios', + '#title' => t('Show object details as'), + '#options' => $display_options, + '#default_value' => $primary_display_mode, +// '#description' => t("Tells Islandora how to display the object details page for each object"), + ); + // ***** Jason: end object details display profiles + $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced configuration options'), From a88fee9fa9b1ae78cb371872b3e720e08a1ce4b9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:36:56 -0300 Subject: [PATCH 086/117] added core object details code --- ObjectDetails.inc | 151 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 ObjectDetails.inc diff --git a/ObjectDetails.inc b/ObjectDetails.inc new file mode 100644 index 00000000..76b11590 --- /dev/null +++ b/ObjectDetails.inc @@ -0,0 +1,151 @@ + array( + "name" => "Hidden", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_hidden", + "description" => t("No object details page"), + ), + 'xslt' => array( + "name" => "XSLT", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_xslt", + "description" => t("Show a datastream with an XSLT"), + "config" => "admin/settings/fedora_repository/object_details_xslt", + ), + 'table' => array( + "name" => "Table", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_table", + "description" => t("Show a datastream with a table"), + ) + ); + return $profiles; +} + +function fedora_repository_object_details_hidden($item) { + // do nothing + return ""; +} + +function fedora_repository_object_details_XSLT($item) { + global $base_url; + $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); + + $dsid = variable_get('islandora_object_details_xslt_datastream', 'DC'); + // special case for DC+QDC + if ($dsid == 'DC' || $dsid == 'QDC') { + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + } + $xmlstr = $item->get_datastream_dissemination($dsid); + + if (empty($xmlstr)) { + return ''; + } + + try { + $proc = new XsltProcessor(); + } catch (Exception $e) { + drupal_set_message($e->getMessage(), 'error'); + return; + } + + $proc->setParameter('', 'baseUrl', $base_url); + $proc->setParameter('', 'path', $base_url . '/' . $path); + $input = NULL; + $xsl = new DomDocument(); + try { + $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); + $input = new DomDocument(); + $input->loadXML(trim($xmlstr)); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + } + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); + return $output; +} + +function fedora_repository_object_details_table($item) { + global $base_url; + $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); + + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + $xmlstr = $item->get_datastream_dissemination($dsid); + + if (empty($xmlstr)) { + return ''; + } + + $simplexml = new SimpleXMLElement($xmlstr); + + $headers = array( + array( + 'data' => t('Metadata'), + 'colspan' => 2, + ), + ); + $rows = array(); + foreach ($simplexml->getNamespaces(TRUE) as $ns) { + foreach ($simplexml->children($ns) as $child) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => (string)$child, + 'class' => 'dc-content', + ), + ); + } + } + + return theme('table', $headers, $rows, array('class' => 'dc-table')); +} + +// configuration pages +function fedora_repository_object_details_XSLT_config() { + $form = array(); + $form['config'] = array( + '#type' => 'fieldset', + '#title' => t("XSLT Options"), + ); + + $form['config']['warning'] = array( + '#value' => 'Note: the elements here do not currently work', + '#weight' => 0, + ); + $form['config']['xslt'] = array( + '#type' => 'textfield', + '#title' => t("XSL transform to use"), + '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'), + '#required' => TRUE, + ); + $form['config']['dsid'] = array( + '#type' => 'textfield', + '#title' => t("Datastream to transform"), + '#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'), + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t("Submit"), + '#weight' => 1, + ); + + return $form; +} + +function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { + variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); + variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); +} From c05e3dab32dfd230c15099c8a5e148258c3d6530 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:39:56 -0300 Subject: [PATCH 087/117] add the mod2html stylesheet for testing transforms --- xsl/mods2html.xsl | 207 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 xsl/mods2html.xsl diff --git a/xsl/mods2html.xsl b/xsl/mods2html.xsl new file mode 100644 index 00000000..194fcec2 --- /dev/null +++ b/xsl/mods2html.xsl @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + ( + + + + + + + Edition + ) + + + + ="", + + + + + () + + +
    From 55a355ffcea99118702669e0a63d3760ea27fef9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 09:42:10 -0300 Subject: [PATCH 088/117] removed 'jason' code guards --- formClass.inc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/formClass.inc b/formClass.inc index 4d899ef1..52cef748 100644 --- a/formClass.inc +++ b/formClass.inc @@ -179,7 +179,6 @@ class formClass { 'access arguments' => array('view fedora collection'), ); - // ***** Jason: begin menu path for xslt config page $items['admin/settings/fedora_repository/object_details_xslt'] = array( 'title' => "", 'type' => MENU_CALLBACK, @@ -188,7 +187,7 @@ class formClass { 'file' => 'ObjectDetails.inc', 'access arguments' => array('administer site configuration'), ); - // ***** Jason: end menu path for xslt config page + return $items; } @@ -305,7 +304,6 @@ class formClass { '#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"), ); - // ***** Jason: begin object details display profiles module_load_include('inc', 'fedora_repository', 'ObjectDetails'); $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); $profiles = module_invoke_all("islandora_object_details_display"); @@ -325,7 +323,6 @@ class formClass { '#default_value' => $primary_display_mode, // '#description' => t("Tells Islandora how to display the object details page for each object"), ); - // ***** Jason: end object details display profiles $form['advanced'] = array( '#type' => 'fieldset', From a0891d6111491d6136af5e64d7ac176dd0964307 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 09:42:59 -0300 Subject: [PATCH 089/117] remove 'jason' code guards --- plugins/FedoraObjectDetailedContent.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index a6656571..1940d41f 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -49,7 +49,6 @@ class FedoraObjectDetailedContent { '#type' => 'tabset', ); - // ***** Jason: begin object details display profiles module_load_include('inc', 'fedora_repository', 'ObjectDetails'); $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt_dc'); $profiles = module_invoke_all("islandora_object_details_display"); @@ -70,7 +69,6 @@ class FedoraObjectDetailedContent { // problem } } - // ***** Jason: end object details display profiles $i = 0; if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { From 672179a133ff7ae765d526bea6ee3683b62cdc34 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:32:38 -0300 Subject: [PATCH 090/117] remove an erroneous text widget (from development) and completed the table display mode (with configuration) --- ObjectDetails.inc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 76b11590..5da6a063 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -23,6 +23,7 @@ function fedora_repository_islandora_object_details_display() { "file" => "ObjectDetails.inc", "function" => "fedora_repository_object_details_table", "description" => t("Show a datastream with a table"), + "config" => "admin/settings/fedora_repository/object_details_table", ) ); return $profiles; @@ -39,7 +40,7 @@ function fedora_repository_object_details_XSLT($item) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $dsid = variable_get('islandora_object_details_xslt_datastream', 'DC'); - // special case for DC+QDC + // special case for DC+QDC for backward compatibility if ($dsid == 'DC' || $dsid == 'QDC') { $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; } @@ -53,6 +54,7 @@ function fedora_repository_object_details_XSLT($item) { $proc = new XsltProcessor(); } catch (Exception $e) { drupal_set_message($e->getMessage(), 'error'); + watchdog('fedora_repository', "Error while creating XSLT processor: @e", array('@e' => $e->getMessage()), WATCHDOG_ERROR); return; } @@ -78,7 +80,11 @@ function fedora_repository_object_details_table($item) { $path = drupal_get_path('module', 'fedora_repository'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); - $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + $dsid = variable_get('islandora_object_details_table_datastream', 'DC'); + // special case for DC+QDC for backward compatibility + if ($dsid == 'DC' || $dsid == 'QDC') { + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + } $xmlstr = $item->get_datastream_dissemination($dsid); if (empty($xmlstr)) { @@ -117,13 +123,9 @@ function fedora_repository_object_details_XSLT_config() { $form = array(); $form['config'] = array( '#type' => 'fieldset', - '#title' => t("XSLT Options"), + '#title' => t("XSLT display options"), ); - $form['config']['warning'] = array( - '#value' => 'Note: the elements here do not currently work', - '#weight' => 0, - ); $form['config']['xslt'] = array( '#type' => 'textfield', '#title' => t("XSL transform to use"), @@ -145,7 +147,33 @@ function fedora_repository_object_details_XSLT_config() { return $form; } +function fedora_repository_object_details_table_config() { + $form = array(); + $form['config'] = array( + '#type' => 'fieldset', + '#title' => t("Table display options"), + ); + + $form['config']['dsid'] = array( + '#type' => 'textfield', + '#title' => t("Datastream to transform"), + '#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'), + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t("Submit"), + '#weight' => 1, + ); + + return $form; +} + function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); } + +function fedora_repository_object_details_table_config_submit($form, &$form_state) { + variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); +} From 2e427bb4d10ad6cd83a292f69f73cc4cc75c13d9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:33:11 -0300 Subject: [PATCH 091/117] moved alert message to watchdog and fixed an incorrect default value --- plugins/FedoraObjectDetailedContent.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 1940d41f..4eeef78b 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -50,12 +50,12 @@ class FedoraObjectDetailedContent { ); module_load_include('inc', 'fedora_repository', 'ObjectDetails'); - $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt_dc'); + $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt'); $profiles = module_invoke_all("islandora_object_details_display"); $profile = $profiles[$object_details_profile]; if (!isset($profile)) { // default behaviour - drupal_set_message(t("There was an error reading the default object details display profile"), "error"); + watchdog('fedora_repository', "Error while reading the default object details display profile: @e", array("@e" => $e->getMessage()), WATCHDOG_WARNING); $dc_html = $objectHelper->getFormattedDC($this->item); } else { From 1fcdfbd83682047edbb1123c88362c72479254d0 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:34:00 -0300 Subject: [PATCH 092/117] added menu hook so table config works, fixed an incorrect default value, added description to radiogroup --- formClass.inc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/formClass.inc b/formClass.inc index 52cef748..97f46c43 100644 --- a/formClass.inc +++ b/formClass.inc @@ -187,6 +187,14 @@ class formClass { 'file' => 'ObjectDetails.inc', 'access arguments' => array('administer site configuration'), ); + $items['admin/settings/fedora_repository/object_details_table'] = array( + 'title' => "", + 'type' => MENU_CALLBACK, + 'page callback' => 'drupal_get_form', + 'page arguments' => array('fedora_repository_object_details_table_config'), + 'file' => 'ObjectDetails.inc', + 'access arguments' => array('administer site configuration'), + ); return $items; } @@ -291,7 +299,7 @@ class formClass { $form['tabs'] = array( '#type' => 'fieldset', '#title' => t('Tabs Configuration'), - '#description' => t('Configure the tabs avaialble when viewing Fedora objects.'), + '#description' => t('Configure the tabs available when viewing Fedora objects.'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); @@ -305,7 +313,7 @@ class formClass { ); module_load_include('inc', 'fedora_repository', 'ObjectDetails'); - $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); + $primary_display_mode = variable_get('islandora_object_details_display_table', 'xslt'); $profiles = module_invoke_all("islandora_object_details_display"); $display_options = array(); @@ -321,7 +329,7 @@ class formClass { '#title' => t('Show object details as'), '#options' => $display_options, '#default_value' => $primary_display_mode, -// '#description' => t("Tells Islandora how to display the object details page for each object"), + '#description' => t("Tells Islandora how to display the object details page for each object"), ); $form['advanced'] = array( From 48c63fad766f05e1f5eadcb4f5bd7b6b3b321e6a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 14 May 2012 17:11:53 -0300 Subject: [PATCH 093/117] Simplify logic in get datastream list and allow multiple pids to be obtained. --- api/fedora_item.inc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index bc378471..5305cae1 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -637,18 +637,15 @@ RDF; // datastream, instead of returning it as an array, only // the single item will be returned directly. We have to // check for this. - if (count($this->datastreams_list->datastreamDef) > 1) { - foreach ($this->datastreams_list->datastreamDef as $ds) { - if (!is_object($ds)) { - print_r($ds); - } - $ds_list[$ds->ID]['label'] = $ds->label; - $ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType; - $ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label); - } + $xml_list = $this->datastreams_list->datastreamDef; + if (!is_array($this->datastreams_list->datastreamDef)) { + $xml_list = array($xml_list); } - else { - $ds = $this->datastreams_list->datastreamDef; + + foreach ($xml_list as $ds) { + if (!is_object($ds)) { + print_r($ds); + } $ds_list[$ds->ID]['label'] = $ds->label; $ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType; $ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label); @@ -852,7 +849,7 @@ RDF; * @param $pid_namespace string * @return string */ - static function get_next_PID_in_namespace($pid_namespace = '') { + static function get_next_PID_in_namespace($pid_namespace = '', $number_of_pids = 1) { if (empty($pid_namespace)) { // Just get the first one in the config settings. $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); @@ -866,11 +863,12 @@ RDF; } $params = array( - 'numPIDs' => '', + 'numPIDs' => $number_of_pids, 'pidNamespace' => $pid_namespace, ); $result = self::soap_call('getNextPID', $params); + return $result->pid; } @@ -1147,6 +1145,7 @@ RDF; $pid = self::get_next_PID_in_namespace(); } if (empty($owner)) { + global $user; if (!empty($user->uid)) { // Default to current Drupal user. $owner = $user->uid; } From 7b5d3cbee90f0031b2771bdf0e695cc06f137fd7 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 10:02:13 -0300 Subject: [PATCH 094/117] Fix move_to_trash function. --- api/fedora_item.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 5305cae1..3a4a134a 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -771,9 +771,9 @@ RDF; /** * Set the object to a deleted state */ - function move_to_trash($log_message = 'Flagged deleted using Islandora API.') { + function move_to_trash($log_message = 'Flagged deleted using Islandora API.', $quiet = TRUE) { // Loop through the datastreams and mark them deleted - foreach ($this->get_datastreams_list_as_array() as $dsid) { + foreach ($this->get_datastreams_list_as_array() as $dsid => $info) { $this->set_datastream_state($dsid, 'D'); } @@ -781,7 +781,7 @@ RDF; $params = array( 'pid' => $this->pid, 'state' => 'D', - 'logMessage' => $logMessage, + 'logMessage' => $log_message, 'label' => $this->objectProfile->objLabel, 'ownerId' => null, ); From 582d735f07c8f1d416dcc23089707f676d043941 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 14:34:53 -0300 Subject: [PATCH 095/117] Minor cleanup. --- fedora_repository.module | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 8642de9c..351ad359 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -986,18 +986,18 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { } } - // Add a 'manage object' tab for all objects, where detailed list of content is shown. - // XXX: Perhaps this should be extracted into its own object? - module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); - $obj = new FedoraObjectDetailedContent($pid); - //can disable showing the object details tab in admin UI - if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + // Add a 'manage object' tab for all objects, where detailed list of content is shown. + // XXX: Perhaps this should be extracted into its own object? + module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); + $obj = new FedoraObjectDetailedContent($pid); + $object_details = $obj->showFieldSets(); - $cmodel_tabs = array_merge($cmodels_tabs, $object_details); + $cmodels_tabs = array_merge($cmodels_tabs, $object_details); } - return array_merge($cmodels_tabs, $object_details); + return $cmodels_tabs; } /** From be55312b3efbc8cdc4994549b9a2f14547876f00 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 14:52:44 -0300 Subject: [PATCH 096/117] Clean up renderCollection function. --- CollectionClass.inc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5e6d3bbd..598250bd 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -763,17 +763,8 @@ class CollectionClass { function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; - $collection_pid = $pid; //we will be changing the pid later maybe - $parsedContent = NULL; - if(!isset($this->collectionObject)){ - $this->collectionObject = new ObjectHelper($pid); - } + $contentModels = $this->collectionObject->get_content_models_list($pid); - $isCollection = FALSE; - //if this is a collection object store the $pid in the session as it will come in handy - //after a purge or ingest to return to the correct collection. - - $fedoraItem = NULL; if (empty($collectionName)) { $collectionName = menu_get_active_title(); @@ -805,7 +796,7 @@ class CollectionClass { try { $proc = new XsltProcessor(); $options = array( //Could make this the return of a hook? - 'collectionPid' => $collection_pid, + 'collectionPid' => $pid, 'collectionTitle' => $collectionName, 'baseUrl' => $base_url, 'path' => "$base_url/$path", @@ -817,10 +808,7 @@ class CollectionClass { $proc->registerPHPFunctions(); $xsl = new DomDocument(); $xsl->loadXML($xslContent); - // php xsl does not seem to work with namespaces so removing it below - // I may have just been being stupid here - // $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content); - + $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($input); From a592be85a9ba62c0edab1d48459e22b07087400d Mon Sep 17 00:00:00 2001 From: Randy Fischer Date: Fri, 18 May 2012 18:30:30 -0400 Subject: [PATCH 097/117] to-do list --- TODO | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 00000000..04c0648e --- /dev/null +++ b/TODO @@ -0,0 +1,15 @@ +These are the sites/all/modules/islandora files that need correcting: + + 1 CollectionClass.inc + 2 CollectionPolicy.inc + 3 fedora_repository.module + 4 fedora_repository.solutionpacks.inc + 5 ObjectHelper.inc + 6 plugins/fedora_imageapi.module + 7 plugins/QtFormBuilder.php + 8 XMLDatastream.inc + +Also need to find + index.php + sites/all/modules/islandora_xml_forms/builder/XMLFormDatabase.inc + From 4bdc2347216fdc0877677204e65c83b56846f560 Mon Sep 17 00:00:00 2001 From: Randy Fischer Date: Tue, 22 May 2012 11:40:32 -0400 Subject: [PATCH 098/117] path requests for Fedora_Repository lowercased - Postgres does case-sensitive matching --- CollectionClass.inc | 10 +++++----- CollectionPolicy.inc | 2 +- ObjectHelper.inc | 4 ++-- SearchClass.inc | 10 +++++----- SecurityClass.inc | 6 +++--- XMLDatastream.inc | 2 +- fedora_repository.module | 14 +++++++------- plugins/DarwinCore.inc | 2 +- plugins/FlvFormBuilder.inc | 2 +- plugins/FormBuilder.inc | 8 ++++---- plugins/ModsFormBuilder.inc | 2 +- plugins/PersonalCollectionClass.inc | 8 ++++---- plugins/QtFormBuilder.php | 4 ++-- plugins/ShowStreamsInFieldSets.inc | 6 +++--- plugins/fedora_imageapi.module | 2 +- plugins/qt_viewer.inc | 2 +- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 6992a34c..ee2bacca 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -226,7 +226,7 @@ class CollectionClass { * @return ContentModel */ function getContentModels($collection_pid, $showError = TRUE) { - module_load_include('inc', 'Fedora_Repository', 'ContentModel'); + module_load_include('inc', 'fedora_repository', 'ContentModel'); $collection_stream = $this->getCollectionPolicyStream($collection_pid); try { $xml = new SimpleXMLElement($collection_stream); @@ -253,7 +253,7 @@ class CollectionClass { * $dsid is the datastream id of the content model. */ function getNextPid($pid, $dsid) { - module_load_include('inc', 'Fedora_Repository', 'ConnectionHelper'); + module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $pidNameSpace = $this->getPidNameSpace($pid, $dsid); $pname = substr($pidNameSpace, 0, strpos($pidNameSpace, ":")); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -371,7 +371,7 @@ class CollectionClass { $parametersArray["$name"] = $value; } } - // module_load_include( $phpFile, 'Fedora_Repository', ' '); + // module_load_include( $phpFile, 'fedora_repository', ' '); require_once(drupal_get_path('module', 'fedora_repository') . '/' . $phpFile); $thisClass = new $phpClass (); $returnValue = $thisClass->$phpMethod($parametersArray, $dsid, $file, $file_ext); @@ -448,7 +448,7 @@ class CollectionClass { $phpClass = strip_tags($ingest_form->form_builder_method->class_name->asXML()); $phpMethod = strip_tags($ingest_form->form_builder_method->method_name->asXML()); $dsid = strip_tags($ingest_form['dsid']); - // module_load_include('php', 'Fedora_Repository', $phpFile); + // module_load_include('php', 'fedora_repository', $phpFile); require_once(drupal_get_path('module', $drupal_module) . '/' . $phpFile); $thisClass = new $phpClass (); @@ -592,7 +592,7 @@ class CollectionClass { * @return string */ function getIngestInterface() { - module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy'); + module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); $collectionPolicyExists = $this->collectionObject->getMimeType($this->pid, CollectionPolicy::getDefaultDSID()); if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (!empty($collectionPolicyExists)) { diff --git a/CollectionPolicy.inc b/CollectionPolicy.inc index 71d95a6c..a6957974 100644 --- a/CollectionPolicy.inc +++ b/CollectionPolicy.inc @@ -392,7 +392,7 @@ class CollectionPolicy extends XMLDatastream { function getContentModels() { $ret = FALSE; if ($this->validate()) { - module_load_include('inc', 'Fedora_Repository', 'ContentModel'); + module_load_include('inc', 'fedora_repository', 'ContentModel'); $ret = array(); $content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); for ($i = 0; $i < $content_models->length; $i++) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e866f62f..40af739c 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -598,7 +598,7 @@ class ObjectHelper { try { $sxml = new SimpleXMLElement($content_models); } catch (exception $e) { - watchdog(t("Fedora_Repository"), "Could not find a parent object for %s", $pid, NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Could not find a parent object for %s", $pid, NULL, WATCHDOG_ERROR); return $pids; } @@ -692,7 +692,7 @@ class ObjectHelper { //show the collections datastreams if ($results->length > 0 || $isCollection == TRUE) { // if(strlen($objectList)>22||$contentModel=='Collection'||$contentModel=='Community')//length of empty dom still equals 22 because of etc - module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy'); + module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); $collectionPolicyExists = $this->getMimeType($pid, CollectionPolicy::getDefaultDSID()); if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (!empty($collectionPolicyExists)) { diff --git a/SearchClass.inc b/SearchClass.inc index 751dbbfa..473076a1 100644 --- a/SearchClass.inc +++ b/SearchClass.inc @@ -36,7 +36,7 @@ class SearchClass { try { $implementation = new $solrClass(); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), "Error getting solr search results class: !message", array('!message' => $e->getMessage()), NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Error getting solr search results class: !message", array('!message' => $e->getMessage()), NULL, WATCHDOG_ERROR); return 'Error getting solr search results class. Check watchdog for more info.'; } return $implementation->$solrFunction($query, $startPage, $fq, $dismax); @@ -253,7 +253,7 @@ class SearchClass { $objectHelper = new ObjectHelper(); $resultData = do_curl($searchString, 1); - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); $output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName); //$output .= '
    '.$alpha_out; @@ -367,7 +367,7 @@ class SearchClass { * @param $query the query that was executed. May want to pass this on. */ function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) { - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); $test = $xslt_file; $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); if (!isRestricted && $xslt_file == NULL) { @@ -425,7 +425,7 @@ class SearchClass { * @return type */ function applyXSLT($resultData, $orderBy = 0) { - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); $proc = NULL; if (!$resultData) { //drupal_set_message(t('No Results!')); @@ -590,7 +590,7 @@ class SearchClass { */ function get_search_terms_array($path = NULL, $file = NULL) { if (!isset($path)) { - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); } $xmlDoc = new DomDocument(); if (!isset($file)) { diff --git a/SecurityClass.inc b/SecurityClass.inc index 970b108b..e2bf71ba 100644 --- a/SecurityClass.inc +++ b/SecurityClass.inc @@ -71,7 +71,7 @@ class SecurityClass { try { $xml = new SimpleXMLElement($policyStream); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), "No roles found in security policy, could not parse policy stream.", NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "No roles found in security policy, could not parse policy stream.", NULL, WATCHDOG_ERROR); //we may not want to send this to the screen. drupal_set_message(t('No roles found in security policy, could not parse policy stream: !message', array('!message' => check_plain($e->getMessage()))), 'error'); return NULL; @@ -108,9 +108,9 @@ class SecurityClass { function createPersonalPolicy($user) { $doc = new DOMDocument(); try { - $doc->load(drupal_get_path('module', 'Fedora_Repository') . '/policies/noObjectEditPolicy.xml'); + $doc->load(drupal_get_path('module', 'fedora_repository') . '/policies/noObjectEditPolicy.xml'); } catch (exception $e) { - watchdog(t("Fedora_Repository"), "Problem loading policy file.", NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Problem loading policy file.", NULL, WATCHDOG_ERROR); } $conditions = $doc->getElementsByTagName('Condition'); foreach ($conditions as $condition) { diff --git a/XMLDatastream.inc b/XMLDatastream.inc index ab8044f4..460affc8 100644 --- a/XMLDatastream.inc +++ b/XMLDatastream.inc @@ -227,7 +227,7 @@ abstract class XMLDatastream { * @return boolean $success */ public function saveToFedora() { - module_load_include('inc', 'Fedora_Repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); if ($this->validate()) { $item = new Fedora_Item($this->pid); $item->modify_datastream_by_value($this->dumpXml(), $this->dsid, $this->name, 'application/xml'); diff --git a/fedora_repository.module b/fedora_repository.module index e83d91f5..71b03e4c 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -634,7 +634,7 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectio * @return type */ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) { - module_load_include('inc', 'Fedora_Repository', 'formClass'); + module_load_include('inc', 'fedora_repository', 'formClass'); $replaceDataStreamForm = new formClass(); return $replaceDataStreamForm->createReplaceDataStreamForm($pid, $dsId, $dsLabel, $form_state); } @@ -659,7 +659,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { } $doc = new DOMDocument(); - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); @@ -689,7 +689,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $dsLabel = substr($dsLabel, 0, $indexOfDot); $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; } - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); + module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $file_basename = basename($file->filepath); @@ -2110,19 +2110,19 @@ function theme_add_to_basket_link($pid, $type = 'object') { $save = "export_big.png"; $saved = "exported_big.png"; -// $path = drupal_get_path('module', 'Fedora_Repository').'/images/'.$save ; +// $path = drupal_get_path('module', 'fedora_repository').'/images/'.$save ; /* var_dump($path); - var_dump(theme('image',drupal_get_path('module', 'Fedora_Repository').'/images/'.$save)); + var_dump(theme('image',drupal_get_path('module', 'fedora_repository').'/images/'.$save)); die(); */ if (!_is_added_to_basket($pid)) { return l( - theme('image', drupal_get_path('module', 'Fedora_Repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE) + theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE) ); } - return theme('image', drupal_get_path('module', 'Fedora_Repository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object))); + return theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object))); } /** diff --git a/plugins/DarwinCore.inc b/plugins/DarwinCore.inc index 2d66d60a..2b25ef7e 100644 --- a/plugins/DarwinCore.inc +++ b/plugins/DarwinCore.inc @@ -247,7 +247,7 @@ class DarwinCore { * @return type */ public function asHTML() { - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'CollectionClass'); diff --git a/plugins/FlvFormBuilder.inc b/plugins/FlvFormBuilder.inc index 8c2b5777..57a8058c 100644 --- a/plugins/FlvFormBuilder.inc +++ b/plugins/FlvFormBuilder.inc @@ -58,7 +58,7 @@ class FlvFormBuilder extends FormBuilder { $ds1v->appendChild($ds1content); $rootElement->appendChild($ds1); - $createdFile = drupal_get_path('module', 'Fedora_Repository') . '/images/flashThumb.jpg'; + $createdFile = drupal_get_path('module', 'fedora_repository') . '/images/flashThumb.jpg'; $fileUrl = $base_url . '/' . drupal_urlencode($createdFile); //'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile; $ds1 = $dom->createElement("foxml:datastream"); $ds1->setAttribute("ID", "TN"); diff --git a/plugins/FormBuilder.inc b/plugins/FormBuilder.inc index 715ca6af..edc3e919 100644 --- a/plugins/FormBuilder.inc +++ b/plugins/FormBuilder.inc @@ -95,21 +95,21 @@ class FormBuilder { try { $xml = new SimpleXMLElement($policyStreamDoc); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), "Problem getting security policy.", NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Problem getting security policy.", NULL, WATCHDOG_ERROR); drupal_set_message(t('Problem getting security policy: @e', array('@e' => check_plain($e->getMessage()))), 'error'); return FALSE; } $policyElement = $dom->createDocumentFragment(); if (!$policyElement) { drupal_set_message(t('Error parsing security policy stream.')); - watchdog(t("Fedora_Repository"), "Error parsing security policy stream, could not parse policy stream.", NULL, WATCHDOG_NOTICE); + watchdog(t("fedora_repository"), "Error parsing security policy stream, could not parse policy stream.", NULL, WATCHDOG_NOTICE); return FALSE; } $dom->importNode($policyElement, TRUE); $value = $policyElement->appendXML($policyStreamDoc); if (!$value) { drupal_set_message(t('Error creating security policy stream.')); - watchdog(t("Fedora_Repository"), "Error creating security policy stream, could not parse collection policy template file.", NULL, WATCHDOG_NOTICE); + watchdog(t("fedora_repository"), "Error creating security policy stream, could not parse collection policy template file.", NULL, WATCHDOG_NOTICE); return FALSE; } @@ -183,7 +183,7 @@ class FormBuilder { file_delete($form_values['ingest-file-location']); } catch (exception $e) { drupal_set_message(t('Error ingesting object: @e', array('@e' => check_plain($e->getMessage()))), 'error'); - watchdog(t("Fedora_Repository"), "Error ingesting object: @e", array('@e' => check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Error ingesting object: @e", array('@e' => check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); return; } } diff --git a/plugins/ModsFormBuilder.inc b/plugins/ModsFormBuilder.inc index aa0f6f92..e6376a14 100644 --- a/plugins/ModsFormBuilder.inc +++ b/plugins/ModsFormBuilder.inc @@ -317,7 +317,7 @@ class ModsFormBuilder extends FormBuilder { file_delete($form_values['ingest-file-location']); } catch (exception $e) { drupal_set_message(t('Error ingesting object: @e', array('@e' => check_plain($e->getMessage()))), 'error'); - watchdog(t("Fedora_Repository"), "Error ingesting object: @e", array('@e' => check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Error ingesting object: @e", array('@e' => check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); return; } } diff --git a/plugins/PersonalCollectionClass.inc b/plugins/PersonalCollectionClass.inc index 9ed6af07..3e23f1a0 100644 --- a/plugins/PersonalCollectionClass.inc +++ b/plugins/PersonalCollectionClass.inc @@ -71,11 +71,11 @@ class PersonalCollectionClass { * @return type */ function createCollectionPolicyStream($user, $dom, $rootElement) { - $collectionTemplate = file_get_contents(drupal_get_path('module', 'Fedora_Repository') . '/collection_policies/PERSONAL-COLLECTION-POLICY.xml'); + $collectionTemplate = file_get_contents(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PERSONAL-COLLECTION-POLICY.xml'); try { $xml = new SimpleXMLElement($collectionTemplate); } catch (Exception $e) { - watchdog(t("Fedora_Repository"), "Problem creating personal collection policy, could not parse collection policy stream.", NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Problem creating personal collection policy, could not parse collection policy stream.", NULL, WATCHDOG_ERROR); drupal_set_message(t('Problem creating personal collection policy, could not parse collection policy stream: @e', array('@e' => check_plain($e->getMessage()))), 'error'); return FALSE; } @@ -83,7 +83,7 @@ class PersonalCollectionClass { if (!$policyElement) { drupal_set_message(t('Error parsing policy stream.')); - watchdog(t("Fedora_Repository"), "Error parsing policy stream, could not parse policy stream.", NULL, WATCHDOG_NOTICE); + watchdog(t("fedora_repository"), "Error parsing policy stream, could not parse policy stream.", NULL, WATCHDOG_NOTICE); return FALSE; } $dom->importNode($policyElement, TRUE); @@ -91,7 +91,7 @@ class PersonalCollectionClass { $value = $policyElement->appendXML($collectionTemplate); if (!$value) { drupal_set_message(t('Error creating collection policy stream.')); - watchdog(t("Fedora_Repository"), "Error creating collection policy stream, could not parse collection policy template file.", NULL, WATCHDOG_NOTICE); + watchdog(t("fedora_repository"), "Error creating collection policy stream, could not parse collection policy template file.", NULL, WATCHDOG_NOTICE); return FALSE; } diff --git a/plugins/QtFormBuilder.php b/plugins/QtFormBuilder.php index 28645d6b..262f1a98 100644 --- a/plugins/QtFormBuilder.php +++ b/plugins/QtFormBuilder.php @@ -18,7 +18,7 @@ class QtFormBuilder extends FormBuilder { * Constructor */ function QtFormBuilder() { - module_load_include('php', 'Fedora_Repository', 'plugins/FormBuilder'); + module_load_include('php', 'fedora_repository', 'plugins/FormBuilder'); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); } @@ -57,7 +57,7 @@ class QtFormBuilder extends FormBuilder { $rootElement->appendChild($ds1); if (empty($_SESSION['fedora_ingest_files']) || !isset($_SESSION['fedora_ingest_files']['TN'])) { - $createdFile = drupal_get_path('module', 'Fedora_Repository') . '/images/qtThumb.jpg'; + $createdFile = drupal_get_path('module', 'fedora_repository') . '/images/qtThumb.jpg'; $fileUrl = $base_url . '/' . drupal_urlencode($createdFile); //'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile; $ds1 = $dom->createElement("foxml:datastream"); $ds1->setAttribute("ID", "TN"); diff --git a/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index 0bbf9403..e75ddec1 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -28,10 +28,10 @@ class ShowStreamsInFieldSets { */ function showFlv() { //FLV is the datastream id - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); $fullPath = url($path); $content = ""; - $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js'; + $pathTojs = drupal_get_path('module', 'fedora_repository') . '/js/swfobject.js'; drupal_add_js("$pathTojs"); $div_id = "player' . $this->pid . 'FLV"; $content .= <<getStream($this->pid, "ROMEO", 0); diff --git a/plugins/fedora_imageapi.module b/plugins/fedora_imageapi.module index f3bd4481..9f5d6e41 100644 --- a/plugins/fedora_imageapi.module +++ b/plugins/fedora_imageapi.module @@ -22,7 +22,7 @@ function fedora_imageapi_menu() { * @param string $params */ function fedora_repository_image_manip($pid = '', $dsid = '', $op = '', $params = '') { - module_load_include('inc', 'Fedora_Repository', 'ObjectHelper'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('module', 'imageapi'); $obj = new ObjectHelper(); $mimetype = $obj->getMimeType($pid, $dsid); diff --git a/plugins/qt_viewer.inc b/plugins/qt_viewer.inc index e321f00f..74f34a3e 100644 --- a/plugins/qt_viewer.inc +++ b/plugins/qt_viewer.inc @@ -126,7 +126,7 @@ class ShowQtStreamsInFieldSets { return ''; } - $path = drupal_get_path('module', 'Fedora_Repository'); + $path = drupal_get_path('module', 'fedora_repository'); drupal_add_js("$path/js/AC_Quicktime.js"); From 8d44579f6937bde2d930b9f047f2a805624618da Mon Sep 17 00:00:00 2001 From: Randy Fischer Date: Tue, 22 May 2012 11:46:50 -0400 Subject: [PATCH 099/117] FEDORA_REPOSITORY lower-cased as well - this is only for consistencies' sake --- plugins/Refworks.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Refworks.inc b/plugins/Refworks.inc index 70b0abeb..b1688292 100644 --- a/plugins/Refworks.inc +++ b/plugins/Refworks.inc @@ -290,13 +290,13 @@ class Refworks { if ($client == NULL) { drupal_set_message(t('Error getting SOAP client.'), 'error'); - watchdog(t("FEDORA_REPOSITORY"), "Error getting SOAP client: @e", array('@e' => $e), NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), "Error getting SOAP client: @e", array('@e' => $e), NULL, WATCHDOG_ERROR); return; } $object = $client->__soapCall('ingest', array( $params )); - watchdog(t("FEDORA_REPOSITORY"), "Successfully added repository item " . $pid . " - ". $item_title, NULL, WATCHDOG_INFO); + watchdog(t("fedora_repository"), "Successfully added repository item " . $pid . " - ". $item_title, NULL, WATCHDOG_INFO); $deleteFiles = $form_values['delete_file']; //remove files from drupal file system if ($deleteFiles > 0) { @@ -305,7 +305,7 @@ class Refworks { } catch (exception $e) { $errors++; $errorMessage = 'yes'; - watchdog(t("FEDORA_REPOSITORY"), t("Error during ingest !it @e", array('!it' => $item_title, '@e' => $e)), NULL, WATCHDOG_ERROR); + watchdog(t("fedora_repository"), t("Error during ingest !it @e", array('!it' => $item_title, '@e' => $e)), NULL, WATCHDOG_ERROR); } $success++; } From 998743460675e16cefcf089a08802b3b0712954f Mon Sep 17 00:00:00 2001 From: Randy Fischer Date: Tue, 22 May 2012 12:02:12 -0400 Subject: [PATCH 100/117] removed incomplete checklist --- TODO | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 04c0648e..00000000 --- a/TODO +++ /dev/null @@ -1,15 +0,0 @@ -These are the sites/all/modules/islandora files that need correcting: - - 1 CollectionClass.inc - 2 CollectionPolicy.inc - 3 fedora_repository.module - 4 fedora_repository.solutionpacks.inc - 5 ObjectHelper.inc - 6 plugins/fedora_imageapi.module - 7 plugins/QtFormBuilder.php - 8 XMLDatastream.inc - -Also need to find - index.php - sites/all/modules/islandora_xml_forms/builder/XMLFormDatabase.inc - From 6370a12bb97e872c7885a85d72878fef74719adf Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:11:17 -0300 Subject: [PATCH 101/117] Fix breadcrumbs, so that an entry for the current object is not added. --- ObjectHelper.inc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 25dd8c53..465487ef 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1047,9 +1047,9 @@ PREFIX rels-ext: SELECT ?parentObject ?title ?content FROM <#ri> WHERE { - ?this fedora-model:label ?title ; - ?relationship ?parentObject . - ?parentObject fedora-model:state fedora-model:Active ; + ?this ?relationship ?parentObject . + ?parentObject fedora-model:label ?title ; + fedora-model:state fedora-model:Active ; fedora-model:hasModel ?content . FILTER( sameTerm(?this, ) && @@ -1068,16 +1068,18 @@ EOQ; $next_pid = NULL; if (count($results) > 0 && $level > 0) { - $parent = $results[0]['parentObject']; - $this_title = $results[0]['title']; + $parent_pid = $results[0]['parentObject']; + $parent_title = $results[0]['title']; if (empty($this_title)) { $this_title = t('Unlabeled Object'); } - $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); + if ($parent_pid != $root) { + $breadcrumbs[] = l($parent_title, "fedora/repository/$parent_pid"); + } - $next_pid = $parent; + $next_pid = $parent_pid; } else { watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_level), WATCHDOG_WARNING); @@ -1138,6 +1140,18 @@ EOQ; if (!empty($attrs['uri'])) { $val = self::pidUriToBarePid((string)$attrs['uri']); } + elseif(!empty($attrs['datatype'])) { + $dt = (string)$attrs['datatype']; + $val = (string)$element; //Default to a string... + if ($dt == 'http://www.w3.org/2001/XMLSchema#int') { + $val = intval($val); + } + else { + watchdog('fedora_repository', 'Datatype @dt_uri handled as string.', array( + '@dt_uri' => $dt, + ), WATCHDOG_DEBUG); + } + } else { $val = (string)$element; } From 94c73ff625d2d420b69d5f4b51283ce9c7d6f0c8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:11:54 -0300 Subject: [PATCH 102/117] Suppress warnings for XSLTs that do not exist for Object Details tab. --- ObjectDetails.inc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 5da6a063..96349868 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -61,18 +61,23 @@ function fedora_repository_object_details_XSLT($item) { $proc->setParameter('', 'baseUrl', $base_url); $proc->setParameter('', 'path', $base_url . '/' . $path); $input = NULL; - $xsl = new DomDocument(); - try { - $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); - $input = new DomDocument(); + + $xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'); + if (is_readable($xsl_file)) { + $xsl = new DOMDocument(); + $xsl->load($xsl_file); + $input = new DOMDocument(); $input->loadXML(trim($xmlstr)); - } catch (Exception $e) { - watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); + return $output; + } + else { + watchdog('fedora_repository', 'The XSLT file @xslt_name is not readable.', array( + '@xslt_name' => $xsl_file, + )); } - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); - $output = $newdom->saveHTML(); - return $output; } function fedora_repository_object_details_table($item) { From d2474b91121e9083395e71a95191a12e94b344d8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:12:43 -0300 Subject: [PATCH 103/117] Set the title. --- fedora_repository.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fedora_repository.module b/fedora_repository.module index 351ad359..56790fbc 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1107,6 +1107,8 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $breadcrumbs = array(); $objectHelper->getBreadcrumbs($pid, $breadcrumbs); drupal_set_breadcrumb(array_reverse($breadcrumbs)); + + drupal_set_title(truncate_utf8($item->objectProfile->objLabel, 56, TRUE, TRUE)); $content_models = $objectHelper->get_content_models_list($pid); From c636034d955d8cf998fb2a45dc47f3e830eaedbd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:13:11 -0300 Subject: [PATCH 104/117] Improve relationship management. Can now use some basic typing (int, string) for RDF literals. --- api/fedora_item.inc | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 21585135..38dd4195 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -10,6 +10,12 @@ define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#'); define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#'); define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#"); +define("RELS_TYPE_URI", 0); +define("RELS_TYPE_PLAIN_LITERAL", 1); +define("RELS_TYPE_STRING", 2); +define("RELS_TYPE_INT", 3); +define("RELS_TYPE_DATETIME", 4); + /** * Fedora Item Class */ @@ -230,12 +236,17 @@ class Fedora_Item { * The object to be related to. * @param string $namespaceURI * The predicate namespace. - * @param boolean $literal_value - * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). + * @param int $literal_value + * Used to type the value. + * - 0: URI + * - 1: plain literal + * - 2: string (explicitly typed) + * - 3: integer + * - 4: dateTime * @return ??? * Value returned from SOAP call for modify_datastream. */ - function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { + function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) { //dd($this, 'The Fedora_Item'); $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; @@ -251,7 +262,7 @@ RDF; $relsext = $this->get_datastream_dissemination('RELS-EXT'); - if (!$literal_value && strpos($object, $f_prefix) !== 0) { + if ($literal_value == REL_TYPE_URI && strpos($object, $f_prefix) !== 0) { $object = $f_prefix . $object; } @@ -271,8 +282,20 @@ RDF; // Create the new relationship node. $newrel = $relsextxml->createElementNS($namespaceURI, $relationship); - if ($literal_value) { + if ($literal_value > 0) { $newrel->appendChild($relsextxml->createTextNode($object)); + if ($literal_value == RELS_TYPE_STRING) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#string'); + } + elseif ($literal_value == RELS_TYPE_INT) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#int'); + } + elseif ($literal_value == RELS_TYPE_DATETIME) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#dateTime'); + } + else { + //plain literal. + } } else { $newrel->setAttribute('rdf:resource', $object); @@ -305,8 +328,8 @@ RDF; * The object to be related to. (NULL/value for which empty() evaluates to true will remove all relations of the given type, ignoring $literal_value) * @param string $namespaceURI * The predicate namespace. - * @param boolean $literal_value - * Whether or not the object should be looked for as a URI (FALSE) or a literal (TRUE). + * @param int $literal_value + * Same as add_relationship. NOTE: dateTime implemented. * @return boolean * Whether or not this operation has produced any changes in the RELS-EXT */ @@ -321,8 +344,10 @@ RDF; foreach ($rels as $rel) { if ( //If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed. empty($object) || - (!$literal_value && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || - ($literal_value && $rel->textContent == $object)) { + (($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || + (($literal_value == RELS_TYPE_PLAIN_LITERAL) && $rel->textContent == $object) || + (($literal_value == RELS_TYPE_STRING) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#string' && $rel->textContent == $object) || + (($literal_value == RELS_TYPE_INT) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#int' && intval($rel->textContent) == $object)) { $rel->parentNode->removeChild($rel); $modified = TRUE; } From b14ba233c26e697741665777b12d06291252b690 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:17:10 -0300 Subject: [PATCH 105/117] Stop setting the title. --- plugins/FedoraObjectDetailedContent.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 4eeef78b..c193c588 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -32,7 +32,6 @@ class FedoraObjectDetailedContent { */ public function showFieldSets() { global $user; - drupal_set_title($this->item->objectProfile->objLabel); $objectHelper = new ObjectHelper(); $tabset = array(); $show_purge_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_purge_object_form'); From 694c4039fe937f5ce8474f086ceaa775a03f89d4 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 4 Jun 2012 20:29:53 +0200 Subject: [PATCH 106/117] Bit safer with labels and minor optimization. --- api/fedora_item.inc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 38dd4195..d9a1202d 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -165,7 +165,7 @@ class Fedora_Item { 'pid' => $this->pid, 'dsID' => $datastream_id, 'altIDs' => NULL, - 'dsLabel' => $datastream_label, + 'dsLabel' => truncate_utf8($datastream_label, 255, TRUE, TRUE), 'versionable' => TRUE, 'MIMEType' => $datastream_mimetype, 'formatURI' => NULL, @@ -247,7 +247,11 @@ class Fedora_Item { * Value returned from SOAP call for modify_datastream. */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) { - //dd($this, 'The Fedora_Item'); + static $relsextxml = NULL; + if ($relsextxml === NULL) { + $relsextxml = new DOMDocument(); //Avoid new instantiations in long-running processes + } + $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; if (!array_key_exists('RELS-EXT', $ds_list)) { @@ -266,8 +270,6 @@ RDF; $object = $f_prefix . $object; } - $relsextxml = new DOMDocument(); - $relsextxml->loadXML($relsext); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); if ($description->length == 0) { @@ -911,7 +913,6 @@ RDF; 'logMessage' => 'Fedora Object Ingested' ); $object = self::soap_call('ingest', $params); - //dd($object, 'Soap return'); return new Fedora_Item($object->objectPID); } @@ -1195,7 +1196,7 @@ RDF; $label_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $label_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#label"); - $label_property->setAttribute("VALUE", $label); + $label_property->setAttribute("VALUE", truncate_utf8($label, 255, TRUE, TRUE)); $owner_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId"); From 8ed4573edd7fd22eb140d653292346086de0f109 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Tue, 5 Jun 2012 11:07:46 -0300 Subject: [PATCH 107/117] updated object details page --- ObjectDetails.inc | 109 ++++++++--- formClass.inc | 28 ++- object_details_xslts/convertQDC.xsl | 33 ++++ object_details_xslts/mods2html.xsl | 232 ++++++++++++++++++++++++ plugins/FedoraObjectDetailedContent.inc | 3 +- 5 files changed, 369 insertions(+), 36 deletions(-) create mode 100644 object_details_xslts/convertQDC.xsl create mode 100644 object_details_xslts/mods2html.xsl diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 96349868..8c2b7b45 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -1,5 +1,17 @@ array( @@ -29,11 +41,25 @@ function fedora_repository_islandora_object_details_display() { return $profiles; } +/** + * The renderer for the "hidden" display mode. In this mode, no data is + * displayed. This is supplied so you can disable the object details metadata + * display without disabling the tab entirely. + * @param item The item with the metadata to display. + * @return The fully composed object details metadata display. + */ function fedora_repository_object_details_hidden($item) { // do nothing return ""; } +/** + * The renderer for the "xslt" display mode. In this mode, an xslt is applied + * to the selected datastream to produce a user defined look and feel to the + * output data. + * @param item The item with the metadata to display. + * @return The fully composed object details metadata display. + */ function fedora_repository_object_details_XSLT($item) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); @@ -47,13 +73,13 @@ function fedora_repository_object_details_XSLT($item) { $xmlstr = $item->get_datastream_dissemination($dsid); if (empty($xmlstr)) { - return ''; + return t('Error - could not find datastream @dsid on object @pid
    Please contact the site administrator.', + array('@dsid' => $dsid, '@pid' => $item->pid)); } try { $proc = new XsltProcessor(); } catch (Exception $e) { - drupal_set_message($e->getMessage(), 'error'); watchdog('fedora_repository', "Error while creating XSLT processor: @e", array('@e' => $e->getMessage()), WATCHDOG_ERROR); return; } @@ -61,25 +87,27 @@ function fedora_repository_object_details_XSLT($item) { $proc->setParameter('', 'baseUrl', $base_url); $proc->setParameter('', 'path', $base_url . '/' . $path); $input = NULL; - - $xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'); - if (is_readable($xsl_file)) { - $xsl = new DOMDocument(); - $xsl->load($xsl_file); - $input = new DOMDocument(); + $xsl = new DomDocument(); + try { + $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); + $input = new DomDocument(); $input->loadXML(trim($xmlstr)); - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); - $output = $newdom->saveHTML(); - return $output; - } - else { - watchdog('fedora_repository', 'The XSLT file @xslt_name is not readable.', array( - '@xslt_name' => $xsl_file, - )); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); } + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); + return $output; } +/** + * The renderer for the "table" display mode. In this mode, the requested + * datastream is rendered using a simple table with keys(tags) on the left and + * values on the right. + * @param item The item with the metadata to display. + * @return The fully composed object details metadata display. + */ function fedora_repository_object_details_table($item) { global $base_url; $path = drupal_get_path('module', 'fedora_repository'); @@ -93,7 +121,8 @@ function fedora_repository_object_details_table($item) { $xmlstr = $item->get_datastream_dissemination($dsid); if (empty($xmlstr)) { - return ''; + return t('Error - could not find datastream @dsid on object @pid
    Please contact the site administrator.', + array('@dsid' => $dsid, '@pid' => $item->pid)); } $simplexml = new SimpleXMLElement($xmlstr); @@ -123,7 +152,11 @@ function fedora_repository_object_details_table($item) { return theme('table', $headers, $rows, array('class' => 'dc-table')); } -// configuration pages +/** + * Configuration page for the xslt display mode. This mode requires two + * parameters: the datastream to render, and the xslt to apply to it. + * @return The configuration page. + */ function fedora_repository_object_details_XSLT_config() { $form = array(); $form['config'] = array( @@ -131,10 +164,22 @@ function fedora_repository_object_details_XSLT_config() { '#title' => t("XSLT display options"), ); + // locate the xslts available + $xslt_folder = "object_details_xslts/"; + $folder = drupal_get_path("module", "fedora_repository") ."/". $xslt_folder; + // retrieve the filenames from the system + $xslts = file_scan_directory($folder, ".xsl"); + $options = array(); + foreach ($xslts as $xsl) { + $options[$xslt_folder . $xsl->basename] = $xsl->basename; + } + $form['config']['xslt'] = array( - '#type' => 'textfield', + '#type' => 'select', '#title' => t("XSL transform to use"), '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'), + '#options' => $options, + '#key_type' => 'associative', '#required' => TRUE, ); $form['config']['dsid'] = array( @@ -151,7 +196,21 @@ function fedora_repository_object_details_XSLT_config() { return $form; } +/** + * Custom submit handler for the xslt configuration page. + * @param form + * @pararm form_state The user supplied values for the form. + */ +function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { + variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); + variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); +} +/** + * Configuration page for the table display mode. This mode requires only one + * parameter: the datastream to render. + * @return The configuration page. + */ function fedora_repository_object_details_table_config() { $form = array(); $form['config'] = array( @@ -174,11 +233,11 @@ function fedora_repository_object_details_table_config() { return $form; } -function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { - variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); - variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); -} - +/** + * Custom submit handler for the table configuration page. + * @param form + * @pararm form_state The user supplied values for the form. + */ function fedora_repository_object_details_table_config_submit($form, &$form_state) { variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); } diff --git a/formClass.inc b/formClass.inc index c7d57843..fc3b1748 100644 --- a/formClass.inc +++ b/formClass.inc @@ -317,11 +317,19 @@ class formClass { $profiles = module_invoke_all("islandora_object_details_display"); $display_options = array(); - foreach ($profiles as $machine_name => $profile) { - $display_options[$machine_name] = $profile['name']; - $config_path = $profile['config']; - if (isset($config_path) && $config_path != ""){ - $display_options[$machine_name] .= " (". l("config", $config_path, array()) .")"; + // suppress php warnings from empty lists + if ($profiles) { + foreach ($profiles as $machine_name => $profile) { + // make sure the name exists (the bare minimum) + if (array_key_exists('name', $profile)) { + $display_options[$machine_name] = $profile['name']; + if (array_key_exists('config', $profile)) { + $config_path = $profile['config']; + if (isset($config_path) && $config_path != "") { + $display_options[$machine_name] .= " (". l("config", $config_path, array()) .")"; + } + } + } } } $form['tabs']['islandora_object_details_display_table'] = array( @@ -362,10 +370,10 @@ class formClass { '#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'), ); - $form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array( - '#type' => 'checkbox', - '#title' => t('Allow imagecache_external use for thumbnails in collection view'), - '#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE), + $form['advanced']['fedora_repository_use_imagecache_external_in_collection_view'] = array( + '#type' => 'checkbox', + '#title' => t('Allow imagecache_external use for thumbnails in collection view'), + '#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE), '#description' => t('If enabled, the default collection list view (or ' . 'anywhere the function "@function" is used) will try to use ' . 'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' . @@ -374,7 +382,7 @@ class formClass { '@function' => '_fedora_repository_render_image()', '@preset' => 'fedora_repository_collection_thumbnail', '@xsl' => 'sparql_to_html.xsl', - )), + )), ); $form['advanced']['fedora_collection_display_list'] = array( diff --git a/object_details_xslts/convertQDC.xsl b/object_details_xslts/convertQDC.xsl new file mode 100644 index 00000000..5d881e35 --- /dev/null +++ b/object_details_xslts/convertQDC.xsl @@ -0,0 +1,33 @@ + + + + + + + + + + +
    + + + + + + + + + + +

    MetaData

    + +
    + = +
    +
    +
    + + + + +
    \ No newline at end of file diff --git a/object_details_xslts/mods2html.xsl b/object_details_xslts/mods2html.xsl new file mode 100644 index 00000000..3f794523 --- /dev/null +++ b/object_details_xslts/mods2html.xsl @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + + : + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + ( + + + + + + + Edition + ) + + + + ="", + + + + + () + + +
    diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index c193c588..f1d7949b 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -65,7 +65,8 @@ class FedoraObjectDetailedContent { $dc_html = $details_function($this->item); } else { - // problem + // problem - display profile not found + watchdog('fedora_repository', "Error - could not find object details display function @function", array('@function' => $details_function), WATCHDOG_WARNING); } } From 1b43b3169d7d1eddd831372557c24b143a9f62dd Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Tue, 5 Jun 2012 13:42:54 -0300 Subject: [PATCH 108/117] fixed xslt paths --- ObjectDetails.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 8c2b7b45..46f5fdf7 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -89,7 +89,7 @@ function fedora_repository_object_details_XSLT($item) { $input = NULL; $xsl = new DomDocument(); try { - $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); + $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl')); $input = new DomDocument(); $input->loadXML(trim($xmlstr)); } catch (Exception $e) { @@ -177,7 +177,7 @@ function fedora_repository_object_details_XSLT_config() { $form['config']['xslt'] = array( '#type' => 'select', '#title' => t("XSL transform to use"), - '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'), + '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl'), '#options' => $options, '#key_type' => 'associative', '#required' => TRUE, From 1872a0f47ef811c467a6065fb1cc57e79fc97de1 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Tue, 5 Jun 2012 13:44:03 -0300 Subject: [PATCH 109/117] moved mods2html file to object_details_xslts/ --- xsl/mods2html.xsl | 207 ---------------------------------------------- 1 file changed, 207 deletions(-) delete mode 100644 xsl/mods2html.xsl diff --git a/xsl/mods2html.xsl b/xsl/mods2html.xsl deleted file mode 100644 index 194fcec2..00000000 --- a/xsl/mods2html.xsl +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - : - - - - - - - - ( - - - - - - - Edition - ) - - - - ="", - - - - - () - - -
    From 8428eb239378ca2b4e3ecc69d18dc757f23403a7 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Tue, 5 Jun 2012 13:57:58 -0300 Subject: [PATCH 110/117] configured better error detection around a missing xslt file --- ObjectDetails.inc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 46f5fdf7..bc6bf02f 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -87,17 +87,24 @@ function fedora_repository_object_details_XSLT($item) { $proc->setParameter('', 'baseUrl', $base_url); $proc->setParameter('', 'path', $base_url . '/' . $path); $input = NULL; - $xsl = new DomDocument(); - try { - $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl')); + + $xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl'); + // set an error message in case xslt parsing fails + $output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file)); + if (is_readable($xsl_file)) { + $xsl = new DomDocument(); $input = new DomDocument(); - $input->loadXML(trim($xmlstr)); - } catch (Exception $e) { - watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + try { + $xsl->load($xsl_file); + + $input->loadXML(trim($xmlstr)); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + } + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); } - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); - $output = $newdom->saveHTML(); return $output; } From 95e401ccb8a6a278f530de00c884b2f70831e748 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Wed, 6 Jun 2012 11:45:42 -0300 Subject: [PATCH 111/117] islandora now uses a hook to get a list of available xslts (for xslt view) so other modules can supply more. it also means the path to the xslt has to be from higher than islandora/, i chose the site root for simplicity (it could be the modules folder) --- ObjectDetails.inc | 56 ++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index bc6bf02f..b7b04c8e 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -85,10 +85,10 @@ function fedora_repository_object_details_XSLT($item) { } $proc->setParameter('', 'baseUrl', $base_url); - $proc->setParameter('', 'path', $base_url . '/' . $path); + $proc->setParameter('', 'path', $path); $input = NULL; - $xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl'); + $xsl_file = variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'); // set an error message in case xslt parsing fails $output = t("Failed to parse xslt file at @xsltFile", array('@xsltFile' => $xsl_file)); if (is_readable($xsl_file)) { @@ -160,9 +160,13 @@ function fedora_repository_object_details_table($item) { } /** - * Configuration page for the xslt display mode. This mode requires two - * parameters: the datastream to render, and the xslt to apply to it. - * @return The configuration page. + * Configuration page for the xslt display mode. + * + * This mode requires two parameters: the datastream to render, and the xslt to + * apply to it. + * + * @return + * The configuration page. */ function fedora_repository_object_details_XSLT_config() { $form = array(); @@ -171,20 +175,12 @@ function fedora_repository_object_details_XSLT_config() { '#title' => t("XSLT display options"), ); - // locate the xslts available - $xslt_folder = "object_details_xslts/"; - $folder = drupal_get_path("module", "fedora_repository") ."/". $xslt_folder; - // retrieve the filenames from the system - $xslts = file_scan_directory($folder, ".xsl"); - $options = array(); - foreach ($xslts as $xsl) { - $options[$xslt_folder . $xsl->basename] = $xsl->basename; - } + $options = module_invoke_all("object_details_get_available_xslts"); $form['config']['xslt'] = array( '#type' => 'select', '#title' => t("XSL transform to use"), - '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'object_details_xslts/convertQDC.xsl'), + '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'sites/all/modules/islandora/object_details_xslts/convertQDC.xsl'), '#options' => $options, '#key_type' => 'associative', '#required' => TRUE, @@ -205,18 +201,36 @@ function fedora_repository_object_details_XSLT_config() { } /** * Custom submit handler for the xslt configuration page. - * @param form - * @pararm form_state The user supplied values for the form. + * + * @param $form + * @param &$form_state + * The user supplied values for the form. */ function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); } +/** + * Base function to supply the available xslt files. + */ +function fedora_repository_object_details_get_available_xslts() { + $folder = drupal_get_path("module", "fedora_repository") ."/object_details_xslts/"; + // retrieve the filenames from the system + $xslts = file_scan_directory($folder, ".xsl"); + $options = array(); + foreach ($xslts as $xsl) { + $options[$xsl->filename] = $xsl->basename; + } + return $options; +} + /** * Configuration page for the table display mode. This mode requires only one * parameter: the datastream to render. - * @return The configuration page. + * + * @return + * The configuration page. */ function fedora_repository_object_details_table_config() { $form = array(); @@ -242,8 +256,10 @@ function fedora_repository_object_details_table_config() { /** * Custom submit handler for the table configuration page. - * @param form - * @pararm form_state The user supplied values for the form. + * + * @param $form + * @param &$form_state + * The user supplied values for the form. */ function fedora_repository_object_details_table_config_submit($form, &$form_state) { variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); From 12e80ef0c476bace666cd76a1d71c02d1f24394d Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Wed, 6 Jun 2012 11:52:36 -0300 Subject: [PATCH 112/117] updated docs for hook_object_details_get_available_xslts --- ObjectDetails.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index b7b04c8e..9ee2d88b 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -213,6 +213,12 @@ function fedora_repository_object_details_XSLT_config_submit($form, &$form_state /** * Base function to supply the available xslt files. + * + * Modules implementing this hook need to return an array describing where the + * XSLT is. The array key is the path to the XSLT (paths start with sites/) and + * the value in the array is the display name. In the simplest form you can use + * file_scan_directory like we do here - this puts the filename as the display + * name and will automatically detect new files as they are added. */ function fedora_repository_object_details_get_available_xslts() { $folder = drupal_get_path("module", "fedora_repository") ."/object_details_xslts/"; From cfe5efd06b33eb35296a67f072c2a195be1d6cdd Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:09:34 -0300 Subject: [PATCH 113/117] added checks to get_datastream and get_datastream_dissemination to filter for missing datastreams, also updated add_datastream_from_* and purge_datastrea to resync the datastream list so the checks are consistent --- api/fedora_item.inc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index d9a1202d..f051c38a 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -10,9 +10,9 @@ define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#'); define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#'); define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#"); -define("RELS_TYPE_URI", 0); -define("RELS_TYPE_PLAIN_LITERAL", 1); -define("RELS_TYPE_STRING", 2); +define("RELS_TYPE_URI", 0); +define("RELS_TYPE_PLAIN_LITERAL", 1); +define("RELS_TYPE_STRING", 2); define("RELS_TYPE_INT", 3); define("RELS_TYPE_DATETIME", 4); @@ -130,6 +130,7 @@ class Fedora_Item { $datastream_url = drupal_urlencode($datastream_file); $url = file_create_url($datastream_url); + // add_datastream_from_url forces a re-sync of the datastream list $return_value = $this->add_datastream_from_url($url, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage); if ($original_path != $datastream_file) { @@ -177,8 +178,10 @@ class Fedora_Item { 'logMessage' => ($logMessage != NULL) ? $logMessage : 'Ingested object ' . $datastream_id ); - - return $this->soap_call('addDataStream', $params); + $soap_result = $this->soap_call('addDataStream', $params); + // make sure to refresh the datastream list after adding so this item stays in sync with the repository + $this->datastreams = $this->get_datastreams_list_as_array(); + return $soap_result; } /** @@ -197,6 +200,7 @@ class Fedora_Item { $tmpfile = fopen($tmpfilename, 'w'); fwrite($tmpfile, $str, strlen($str)); fclose($tmpfile); + // add_datastream_from_file forces a re-sync of the datastream list $returnvalue = $this->add_datastream_from_file($tmpfilename, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage); unlink($tmpfilename); return $returnvalue; @@ -513,6 +517,12 @@ RDF; * @return null */ function get_datastream_dissemination($dsid, $as_of_date_time = "", $quiet=TRUE) { + if (!array_key_exists($dsid, $this->datastreams)) { + watchdog('fedora_repository', 'Requested invalid datastream dissemination @dsid on object @pid', + array('@dsid' => $dsid, '@pid' => $pid)); + return NULL; + } + $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -538,6 +548,9 @@ RDF; * @return type */ function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) { + if (!array_key_exists($dsid, datastreams)) { + return NULL; + } $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -859,7 +872,10 @@ RDF; 'logMessage' => $log_message, 'force' => $force, ); - return $this->soap_call('purgeDatastream', $params); + $soap_result = $this->soap_call('purgeDatastream', $params); + // make sure to refresh the datastream list after adding so this item stays in sync with the repository + $this->datastreams = $this->get_datastreams_list_as_array(); + return $soap_result; } /** From b345b01a2072c09148f7845d8ecac8535fbc4202 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:10:18 -0300 Subject: [PATCH 114/117] updated createDQCEditForm to use fedora_item instead of calling __soap:getDatastreamDissemination directly, now the request is error filtered --- formClass.inc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/formClass.inc b/formClass.inc index fc3b1748..06d840de 100644 --- a/formClass.inc +++ b/formClass.inc @@ -817,15 +817,12 @@ class formClass { * @return string */ function createQDCEditForm($pid, $dsid, $client, &$form_state) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $dsid = empty($dsid) ? 'QDC' : $dsid; - try { - $params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => ""); - $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params)); - } catch (Exception $e) { - return array(); - } - $content = $object->dissemination->stream; - $content = trim($content); + + $item = new fedora_item($pid); + $content = trim($item->get_datastream_dissemination($dsid)); + $doc = new DOMDocument(); if (!$doc->loadXML($content)) { echo "error loading xml"; From 4e0d243a79c410547ea34d3d73b5a83ac71cabf8 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:10:57 -0300 Subject: [PATCH 115/117] removed old commented out code this is now wrong and would cause errors if someone used it again --- api/fedora_export.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/api/fedora_export.inc b/api/fedora_export.inc index f3c82160..32d7b49d 100644 --- a/api/fedora_export.inc +++ b/api/fedora_export.inc @@ -57,7 +57,6 @@ function export_objects_for_pid($pid, $dir, &$log) { $file = $dir . '/' . $ds->label . '.' . get_file_extension($ds->MIMEType); $paths[$ds->ID] = $file; - //$content = $ob_helper->getDatastreamDissemination($pid, $ds->ID); if ($content = $ob_helper->getStream($pid, $ds->ID, FALSE)) { if (!$fp = @fopen($file, 'w')) { $log[] = log_line(t("Failed to open file %file to write datastream %dsid for pid %pid", array('%file' => $file, '%dsid' => $ds->ID, '%pid' => $pid)), 'error'); From 13781d24f764bd5035e2d20f4af79a3adca44843 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:11:43 -0300 Subject: [PATCH 116/117] updated getStream function to use fedora_item to retrieve the datastream dissemination instead of calling soap directly, the result error filtering on the output --- ObjectHelper.inc | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e9bebdfb..12f8dd9b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -233,8 +233,8 @@ class ObjectHelper { elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS //Have the webserver mediate the transfer (download and restream) - if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) { - header("Content-Length: $contentSize"); + if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) { + header("Content-Length: $contentSize"); } $opts = array( @@ -624,30 +624,9 @@ class ObjectHelper { * */ function getStream($pid, $dsid, $showError = FALSE) { - module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); - $soapHelper = new ConnectionHelper(); - try { - $client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); - $params = array( - 'pid' => "$pid", - 'dsID' => "$dsid", - 'asOfDateTime' => "" - ); - - if (!isset($client)) { - drupal_set_message(t('Error connection to Fedora using soap client.')); - return NULL; - } - $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params)); - } catch (Exception $e) { - if ($showError) { - drupal_set_message(t('Error getting Datastream for %pid and %datastream
    ', array('%pid' => $pid, '%datastream' => $dsid)), 'error'); - } - return NULL; - } - $content = $object->dissemination->stream; - $content = trim($content); - return $content; + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new fedora_item($pid); + return $item->get_datastream_dissemination($dsid); } /** From c781b4e78d0ccdc2a9080b0766756c830d904bbc Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:14:14 -0300 Subject: [PATCH 117/117] fixed error trap in get_datastream to log it in the watchdog - also fixed a syntax bug --- api/fedora_item.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index f051c38a..93e2b65e 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -548,7 +548,9 @@ RDF; * @return type */ function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) { - if (!array_key_exists($dsid, datastreams)) { + if (!array_key_exists($dsid, $this->datastreams)) { + watchdog('fedora_repository', 'Requested invalid datastream dissemination @dsid on object @pid', + array('@dsid' => $dsid, '@pid' => $pid)); return NULL; } $params = array(