From 7ad0b140ab2151b0958f85b10fdbf91676d50444 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 14:42:02 -0300 Subject: [PATCH 01/21] 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 02/21] 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 03/21] 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 04/21] 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 05/21] 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 06/21] 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 07/21] 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 08/21] 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 09/21] 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 10/21] 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 11/21] 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 12/21] 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 13/21] 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 14/21] 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 15/21] 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 16/21] 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 17/21] 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 18/21] 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 19/21] 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 20/21] 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 21/21] 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