From aa7f8fe24597f366397212f77ad590bdd4ff4caa Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 14:42:02 -0300 Subject: [PATCH 1/6] Fix a tiny error introduced... --- formClass.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formClass.inc b/formClass.inc index c17bb35b..e6a3523b 100644 --- a/formClass.inc +++ b/formClass.inc @@ -288,7 +288,7 @@ class formClass { $form['fedora_repository_title'] = array( '#type' => 'textfield', '#title' => t('Digital Repository Title'), - '#default_value' => variable_get('fedora_repository_name', 'Digital Repository'), + '#default_value' => variable_get('fedora_repository_title', 'Digital Repository'), '#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'), ); $form['advanced'] = array( From 2c47f9bfb2db53a716e67654409bc03a814e4c87 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 17 Apr 2012 13:45:04 -0400 Subject: [PATCH 2/6] Allow returns from modifications... --- api/fedora_item.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index d107a844..66259275 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -268,7 +268,7 @@ RDF; $description->appendChild($newrel); - $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); + return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); //print ($description->dump_node()); /* $params = array( 'pid' => $this->pid, @@ -958,6 +958,8 @@ RDF; * Error suppression? Refer to soap_call for usage (just passed along here). */ function modify_datastream($filename_or_content, $dsid, $label, $mime_type, $force = FALSE, $logMessage='Modified by Islandora API', $quiet=FALSE) { + $toReturn = NULL; + //Determine if it's inline xml; if it is, modify by value if ($this->get_datastream($dsid)->controlGroup === 'X') { $content = ''; @@ -968,7 +970,7 @@ RDF; $content = $filename_or_content; } - $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_value($content, $dsid, $label, $mime_type, $force, $logMessage); } //Otherwise, write to web-accessible temp file and modify by reference. else { @@ -989,12 +991,14 @@ RDF; $file_url = file_create_url($file); - $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); + $toReturn = $this->modify_datastream_by_reference($file_url, $dsid, $label, $mime_type, $force, $logMessage); if ($created_temp && is_file($file) && is_writable($file)) { file_delete($file); } } + + return $toReturn; } /** From 33eb06b5cb0f8e9f9248e14b9acc7a5997eeebba Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 19 Apr 2012 16:31:30 -0300 Subject: [PATCH 3/6] 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 993a074f141e7db7bbaae61f0e63845883e4ef05 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 09:48:36 -0300 Subject: [PATCH 4/6] 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 5ae678d1df44e6dec1378fa4e58dbde4a3d0f9cc Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 09:48:52 -0300 Subject: [PATCH 5/6] 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 3f7f3207943087d3150f5104c851b2731be616ef Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 20 Apr 2012 10:13:08 -0300 Subject: [PATCH 6/6] 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...