jonathangreen
12 years ago
30 changed files with 2114 additions and 2533 deletions
@ -0,0 +1,62 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* Setups the globals for the Drupal pager. |
||||||
|
* |
||||||
|
* Does just what it says: Hacks the default Drupal pager such that it might |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
function fedora_repository_setup_pager($pager_name, $per_page = NULL, $total_items = NULL) { |
||||||
|
global $pager_total, $pager_page_array; |
||||||
|
|
||||||
|
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) { |
||||||
|
$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; |
||||||
|
} |
||||||
|
|
@ -1,612 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* SearchClass Class |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* SearchClass ?? |
|
||||||
*/ |
|
||||||
class SearchClass { |
|
||||||
|
|
||||||
public static $SEARCH_CLASS_ADVANCED_SEARCH_NUMBER_FIELDS = 5; |
|
||||||
|
|
||||||
/** |
|
||||||
* solr_search ?? |
|
||||||
* @param type $query |
|
||||||
* @param type $startPage |
|
||||||
* @param type $fq |
|
||||||
* @param type $dismax |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function solr_search($query, $startPage=1, $fq = NULL, $dismax = NULL) { |
|
||||||
$solrFile = trim(variable_get('islandora_solr_search_block_handler_file', 'plugins/SolrResults.inc')); |
|
||||||
|
|
||||||
// Don't let us bust out of fedora_repository modules directory when looking for a handler |
|
||||||
if (strpos($solrField, '../')) { |
|
||||||
drupal_set_message(t('You have illegal characters in your solr handler function in the Islandora solr block config.'), 'error'); |
|
||||||
} |
|
||||||
|
|
||||||
$solrClass = trim(variable_get('islandora_solr_search_block_handler_class', 'SolrResults')); |
|
||||||
$solrFunction = trim(variable_get('islandora_solr_search_block_handler_function', 'SearchAndDisplay')); |
|
||||||
require_once(drupal_get_path('module', 'fedora_repository') . '/' . $solrFile); |
|
||||||
try { |
|
||||||
$implementation = new $solrClass(); |
|
||||||
} catch (Exception $e) { |
|
||||||
watchdog(t("fedora_repository"), "Error getting solr search results class: !message", array('!message' => $e->getMessage()), NULL, WATCHDOG_ERROR); |
|
||||||
return 'Error getting solr search results class. Check watchdog for more info.'; |
|
||||||
} |
|
||||||
return $implementation->$solrFunction($query, $startPage, $fq, $dismax); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* build solr search form ?? |
|
||||||
* @param type $repeat |
|
||||||
* @param type $pathToSearchTerms |
|
||||||
* @param type $query |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) { |
|
||||||
$types = $this->get_search_terms_array(NULL, 'solrSearchTerms.xml'); |
|
||||||
$queryArray = NULL; |
|
||||||
if (isset($query)) { |
|
||||||
$queryArray = explode('AND', $query); |
|
||||||
} |
|
||||||
|
|
||||||
$andOrArray = array( |
|
||||||
'AND' => 'and', |
|
||||||
//'OR' => 'or' //removed or for now as it would be a pain to parse |
|
||||||
); |
|
||||||
$form = array(); |
|
||||||
|
|
||||||
if (!isset($repeat)) { |
|
||||||
$repeat = variable_get('islandora_solr_search_block_repeat', t('3')); |
|
||||||
} |
|
||||||
$var0 = explode(':', $queryArray[0]); |
|
||||||
$var1 = explode(':', $queryArray[1]); |
|
||||||
$form['search_type']['type1'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => trim($var0[0]) |
|
||||||
); |
|
||||||
$form['fedora_terms1'] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#required' => TRUE, |
|
||||||
'#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), |
|
||||||
); |
|
||||||
$form['andor1'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#default_value' => 'AND', |
|
||||||
'#options' => $andOrArray |
|
||||||
); |
|
||||||
$form['search_type']['type2'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), |
|
||||||
); |
|
||||||
$form['fedora_terms2'] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''), |
|
||||||
); |
|
||||||
if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9 |
|
||||||
for ($i = 3; $i < $repeat + 1; $i++) { |
|
||||||
$t = $i - 1; |
|
||||||
$field_and_term = explode(':', $queryArray[$t]); |
|
||||||
$form["andor$t"] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#default_value' => 'AND', |
|
||||||
'#options' => $andOrArray |
|
||||||
); |
|
||||||
$form['search_type']["type$i"] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => trim($field_and_term[0]) |
|
||||||
); |
|
||||||
$form["fedora_terms$i"] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$form['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('search') |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* build simple solr form ?? |
|
||||||
* @return string |
|
||||||
*/ |
|
||||||
function build_simple_solr_form() { |
|
||||||
//$form = array(); |
|
||||||
$form["search_query"] = array( |
|
||||||
'#size' => '30', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
// '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), |
|
||||||
); |
|
||||||
$form['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('search') |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* theme solr search form ?? |
|
||||||
* @param type $form |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function theme_solr_search_form($form) { |
|
||||||
if (!isset($repeat)) { |
|
||||||
$repeat = variable_get('islandora_solr_search_block_repeat', t('3')); |
|
||||||
} |
|
||||||
|
|
||||||
$output = drupal_render($form['search_type']['type1']); |
|
||||||
$output .= drupal_render($form['fedora_terms1']); |
|
||||||
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']); |
|
||||||
$output .= drupal_render($form['fedora_terms2']); |
|
||||||
if ($repeat > 2 && $repeat < 9) { |
|
||||||
for ($i = 3; $i < $repeat + 1; $i++) { |
|
||||||
$t = $i - 1; |
|
||||||
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]); |
|
||||||
$output .= drupal_render($form["fedora_terms$i"]); |
|
||||||
} |
|
||||||
} |
|
||||||
$output .= drupal_render($form['submit']); |
|
||||||
$output .= drupal_render($form); |
|
||||||
return $output; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* quick search ?? |
|
||||||
* @param type $type |
|
||||||
* @param type $query |
|
||||||
* @param type $showForm |
|
||||||
* @param type $orderBy |
|
||||||
* @param type $userArray |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function quickSearch($type, $query, $showForm = 1, $orderBy = 0, & $userArray) { |
|
||||||
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); |
|
||||||
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); |
|
||||||
if (user_access('view fedora collection')) { |
|
||||||
$numberOfHistPerPage = '5000'; //hack for IR they do not want next button |
|
||||||
$luceneQuery = NULL; |
|
||||||
// Demo search string ?operation=gfindObjects&indexName=DemoOnLucene&query=fgs.DS.first.text%3Achristmas&hitPageStart=11&hitPageSize=10 |
|
||||||
$keywords = explode(' ', $query); |
|
||||||
|
|
||||||
foreach ($keywords as $keyword) { |
|
||||||
$luceneQuery .= $type . ':' . $keyword . '+AND+'; |
|
||||||
} |
|
||||||
$luceneQuery = substr($luceneQuery, 0, strlen($luceneQuery) - 5); |
|
||||||
|
|
||||||
$indexName = variable_get('fedora_index_name', 'DemoOnLucene'); |
|
||||||
$keys = htmlentities(urlencode($query)); |
|
||||||
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); |
|
||||||
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $luceneQuery; |
|
||||||
$searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=1'; |
|
||||||
//$searchString = htmlentities($searchString); |
|
||||||
$searchUrl .= $searchString; |
|
||||||
|
|
||||||
// $objectHelper = new ObjectHelper(); |
|
||||||
|
|
||||||
$resultData = do_curl($searchUrl, 1); |
|
||||||
if (isset($userArray)) { |
|
||||||
$doc = new DOMDocument(); |
|
||||||
$doc->loadXML($resultData); |
|
||||||
$xPath = new DOMXPath($doc); |
|
||||||
// Add users to department list. This is a hack as not all users will be in dupal |
|
||||||
$nodeList = $xPath->query('//field[@name="refworks.u1"]'); |
|
||||||
foreach ($nodeList as $node) { |
|
||||||
if (!in_array($node->nodeValue, $userArray)) { |
|
||||||
$userArray[] = $node->nodeValue; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
if ($showForm) { |
|
||||||
$output = '<Strong>Quick Search</strong><br /><table class="table-form"><tr>' . drupal_get_form('fedora_repository_quick_search_form') . '</tr></table>'; |
|
||||||
} |
|
||||||
$output .= $this->applyXSLT($resultData, $orderBy); |
|
||||||
return $output; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* gets term from a lucene index and displays them in a list |
|
||||||
* @param type $fieldName |
|
||||||
* @param type $startTerm |
|
||||||
* @param type $displayName |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function getTerms($fieldName, $startTerm, $displayName = NULL) { |
|
||||||
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); |
|
||||||
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); |
|
||||||
$indexName = variable_get('fedora_index_name', 'DemoOnLucene'); |
|
||||||
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); |
|
||||||
if ($startTerm == NULL) { |
|
||||||
$startTerm = ""; |
|
||||||
} |
|
||||||
$startTerm = drupal_urlencode($startTerm); |
|
||||||
$query = 'operation=browseIndex&startTerm=' . $startTerm . '&fieldName=' . $fieldName . '&termPageSize=20&indexName=' . $indexName . '&restXslt=copyXml&resultPageXslt=copyXml'; |
|
||||||
// $query=drupal_urlencode($query); |
|
||||||
$query = '?' . $query; |
|
||||||
$searchString = $searchUrl . $query; |
|
||||||
|
|
||||||
$objectHelper = new ObjectHelper(); |
|
||||||
|
|
||||||
$resultData = do_curl($searchString, 1); |
|
||||||
$path = drupal_get_path('module', 'fedora_repository'); |
|
||||||
|
|
||||||
$output .= $this->applySpecifiedXSLT($resultData, $path . '/xsl/browseIndexToResultPage.xslt', $displayName); |
|
||||||
//$output .= '<br />'.$alpha_out; |
|
||||||
return $output; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* custom search ?? |
|
||||||
* @param type $query |
|
||||||
* @param type $startPage |
|
||||||
* @param type $xslt |
|
||||||
* @param type $numberOfHistPerPage |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) { |
|
||||||
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); |
|
||||||
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); |
|
||||||
|
|
||||||
if (user_access('view fedora collection')) { |
|
||||||
//$numberOfHistPerPage = '50';//hack for IR they do not want next button |
|
||||||
$luceneQuery = NULL; |
|
||||||
$indexName = variable_get('fedora_index_name', 'DemoOnLucene'); |
|
||||||
$copyXMLFile = 'copyXml'; |
|
||||||
// if($indexName=='ilives' || $indexName=='BasicIndex'){ |
|
||||||
// $copyXMLFile = 'copyXmliLives'; |
|
||||||
// } |
|
||||||
$query = trim($query); |
|
||||||
$query = htmlentities(urlencode($query)); |
|
||||||
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); |
|
||||||
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query; |
|
||||||
$searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage; |
|
||||||
//$searchString = htmlentities($searchString); |
|
||||||
$searchUrl .= $searchString; |
|
||||||
|
|
||||||
//$objectHelper = new ObjectHelper(); |
|
||||||
|
|
||||||
$resultData = do_curl($searchUrl, 1); |
|
||||||
//var_dump($resultData);exit(0); |
|
||||||
// $doc = new DOMDocument(); |
|
||||||
// $doc->loadXML($resultData); |
|
||||||
|
|
||||||
$output .= $this->applyLuceneXSLT($resultData, $startPage, $xslt, $query); |
|
||||||
return $output; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* apply specified xslt ?? |
|
||||||
* @global type $user |
|
||||||
* @param type $resultData |
|
||||||
* @param type $pathToXSLT |
|
||||||
* @param type $displayName |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function applySpecifiedXSLT($resultData, $pathToXSLT, $displayName = NULL) { |
|
||||||
$proc = NULL; |
|
||||||
global $user; |
|
||||||
if (!$resultData) { |
|
||||||
drupal_set_message(t('No data found!')); |
|
||||||
return ' '; //no results |
|
||||||
} |
|
||||||
try { |
|
||||||
$proc = new XsltProcessor(); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!') . $e->getMessage()); |
|
||||||
return ' '; |
|
||||||
} |
|
||||||
|
|
||||||
//$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl |
|
||||||
$proc->setParameter('', 'objectsPage', base_path()); |
|
||||||
$proc->setParameter('', 'userID', $user->uid); |
|
||||||
if (isset($displayName)) { |
|
||||||
$proc->setParameter('', 'displayName', $displayName); |
|
||||||
} |
|
||||||
else { |
|
||||||
$proc->setParameter('', 'displayName', "test"); |
|
||||||
} |
|
||||||
|
|
||||||
$xsl = new DomDocument(); |
|
||||||
|
|
||||||
$test = $xsl->load($pathToXSLT); |
|
||||||
|
|
||||||
if (!isset($test)) { |
|
||||||
drupal_set_message(t('Error loading ' . $pathToXSLT . ' xslt!')); |
|
||||||
return t('Error loading !pathToXSLT xslt.', array('!pathToXSLT' => $pathToXSLT)); |
|
||||||
} |
|
||||||
|
|
||||||
$input = new DomDocument(); |
|
||||||
|
|
||||||
$didLoadOk = $input->loadXML($resultData); |
|
||||||
|
|
||||||
if (!isset($didLoadOk)) { |
|
||||||
drupal_set_message(t('Error loading XML data!')); |
|
||||||
return t('Error loading XML data.'); |
|
||||||
} |
|
||||||
else { |
|
||||||
$proc->importStylesheet($xsl); |
|
||||||
$newdom = $proc->transformToDoc($input); |
|
||||||
return $newdom->saveXML(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//default function for lucene results |
|
||||||
|
|
||||||
/** |
|
||||||
* apply an xslt to lucene gsearch search results |
|
||||||
* |
|
||||||
* @param <type> $resultData |
|
||||||
* @param <type> $startPage |
|
||||||
* @param <type> $xslt_file |
|
||||||
* @param <type> $query the query that was executed. May want to pass this on. |
|
||||||
*/ |
|
||||||
function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) { |
|
||||||
$path = drupal_get_path('module', 'fedora_repository'); |
|
||||||
$test = $xslt_file; |
|
||||||
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); |
|
||||||
if (!isRestricted && $xslt_file == NULL) { |
|
||||||
$xslt_file = '/xsl/unfilteredresults.xsl'; |
|
||||||
} |
|
||||||
$proc = NULL; |
|
||||||
if (!$resultData) { |
|
||||||
//drupal_set_message(t('No Results!')); |
|
||||||
return ' '; //no results |
|
||||||
} |
|
||||||
try { |
|
||||||
$proc = new XsltProcessor(); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Error loading results xslt!') . $e->getMessage()); |
|
||||||
return ' '; |
|
||||||
} |
|
||||||
if (isset($query)) { |
|
||||||
$proc->setParameter('', 'fullQuery', $query); |
|
||||||
} |
|
||||||
//inject into xsl stylesheet |
|
||||||
global $user; |
|
||||||
$proc->setParameter('', 'userID', $user->uid); |
|
||||||
$proc->setParameter('', 'searchToken', drupal_get_token('fedora_repository_advanced_search')); //token generated by Drupal, keeps tack of what tab etc we are on |
|
||||||
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl |
|
||||||
$proc->setParameter('', 'objectsPage', base_path()); |
|
||||||
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); |
|
||||||
$proc->setParameter('', 'hitPageStart', $startPage); |
|
||||||
$proc->registerPHPFunctions(); |
|
||||||
$xsl = new DomDocument(); |
|
||||||
|
|
||||||
$test = $xsl->load($path . $xslt_file); |
|
||||||
if (!isset($test)) { |
|
||||||
drupal_set_message(t('Error loading search results xslt!')); |
|
||||||
return t('Error loading search results XSLT.'); |
|
||||||
} |
|
||||||
|
|
||||||
$input = new DomDocument(); |
|
||||||
$didLoadOk = $input->loadXML($resultData); |
|
||||||
|
|
||||||
if (!isset($didLoadOk)) { |
|
||||||
drupal_set_message(t('Error loading search results!')); |
|
||||||
return t('Error loading search results.'); |
|
||||||
} |
|
||||||
else { |
|
||||||
$proc->importStylesheet($xsl); |
|
||||||
$newdom = $proc->transformToDoc($input); |
|
||||||
return $newdom->saveXML(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* xslt for islandscholar these xslt functions can probably be pulled into one |
|
||||||
* @param type $resultData |
|
||||||
* @param type $orderBy |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function applyXSLT($resultData, $orderBy = 0) { |
|
||||||
$path = drupal_get_path('module', 'fedora_repository'); |
|
||||||
$proc = NULL; |
|
||||||
if (!$resultData) { |
|
||||||
//drupal_set_message(t('No Results!')); |
|
||||||
return ' '; //no results |
|
||||||
} |
|
||||||
try { |
|
||||||
$proc = new XsltProcessor(); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Error loading results xslt!') . " " . $e->getMessage()); |
|
||||||
return ' '; |
|
||||||
} |
|
||||||
|
|
||||||
//inject into xsl stylesheet |
|
||||||
//$proc->setParameter('', 'searchToken', drupal_get_token('search_form')); //token generated by Drupal, keeps tack of what tab etc we are on |
|
||||||
$proc->setParameter('', 'userID', $user->uid); |
|
||||||
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl |
|
||||||
$proc->setParameter('', 'objectsPage', base_path()); |
|
||||||
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); |
|
||||||
$proc->setParameter('', 'orderBy', $orderBy); |
|
||||||
$xsl = new DomDocument(); |
|
||||||
|
|
||||||
$test = $xsl->load($path . '/ir/xsl/results.xsl'); |
|
||||||
if (!isset($test)) { |
|
||||||
drupal_set_message(t('Error loading search results xslt!')); |
|
||||||
return t('Error loading search results XSLT.'); |
|
||||||
} |
|
||||||
|
|
||||||
$input = new DomDocument(); |
|
||||||
$didLoadOk = $input->loadXML($resultData); |
|
||||||
|
|
||||||
if (!isset($didLoadOk)) { |
|
||||||
drupal_set_message(t('Error loading search results!')); |
|
||||||
return t('Error loading search results.'); |
|
||||||
} |
|
||||||
else { |
|
||||||
$xsl = $proc->importStylesheet($xsl); |
|
||||||
$newdom = $proc->transformToDoc($input); |
|
||||||
return $newdom->saveXML(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* theme advanced search form ?? |
|
||||||
* @param type $form |
|
||||||
* @param type $repeat |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function theme_advanced_search_form($form, $repeat=NULL) { |
|
||||||
if (!isset($repeat)) { |
|
||||||
$repeat = variable_get('fedora_repository_advanced_block_repeat', t('3')); |
|
||||||
} |
|
||||||
|
|
||||||
$output = drupal_render($form['search_type']['type1']); |
|
||||||
$output .= drupal_render($form['fedora_terms1']); |
|
||||||
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']); |
|
||||||
$output .= drupal_render($form['fedora_terms2']); |
|
||||||
if ($repeat > 2 && $repeat < 9) { |
|
||||||
for ($i = 3; $i < $repeat + 1; $i++) { |
|
||||||
$t = $i - 1; |
|
||||||
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]); |
|
||||||
$output .= drupal_render($form["fedora_terms$i"]); |
|
||||||
} |
|
||||||
} |
|
||||||
$output .= drupal_render($form['submit']); |
|
||||||
$output .= drupal_render($form); |
|
||||||
return $output; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* build search form, custom blocks should set the number of repeats or it will use the default |
|
||||||
* @param type $repeat |
|
||||||
* @param type $pathToSearchTerms |
|
||||||
* @param type $query |
|
||||||
* @return string |
|
||||||
*/ |
|
||||||
function build_advanced_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) { |
|
||||||
$types = $this->get_search_terms_array($pathToSearchTerms); |
|
||||||
$queryArray = NULL; |
|
||||||
if (isset($query)) { |
|
||||||
$queryArray = explode('AND', $query); |
|
||||||
} |
|
||||||
|
|
||||||
$andOrArray = array( |
|
||||||
'AND' => 'and', |
|
||||||
//'OR' => 'or' //removed or for now as it would be a pain to parse |
|
||||||
); |
|
||||||
$form = array(); |
|
||||||
|
|
||||||
if (!isset($repeat)) { |
|
||||||
$repeat = variable_get('fedora_repository_advanced_block_repeat', t('3')); |
|
||||||
} |
|
||||||
$var0 = explode(':', $queryArray[0]); |
|
||||||
$var1 = explode(':', $queryArray[1]); |
|
||||||
$form['search_type']['type1'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => trim($var0[0]) |
|
||||||
); |
|
||||||
$form['fedora_terms1'] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#required' => TRUE, |
|
||||||
'#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''), |
|
||||||
); |
|
||||||
$form['andor1'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#default_value' => 'AND', |
|
||||||
'#options' => $andOrArray |
|
||||||
); |
|
||||||
$form['search_type']['type2'] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''), |
|
||||||
); |
|
||||||
$form['fedora_terms2'] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''), |
|
||||||
); |
|
||||||
if ($repeat > 2 && $repeat < 9) { //don't want less then 2 or more then 9 |
|
||||||
for ($i = 3; $i < $repeat + 1; $i++) { |
|
||||||
$t = $i - 1; |
|
||||||
$field_and_term = explode(':', $queryArray[$t]); |
|
||||||
$form["andor$t"] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#default_value' => 'AND', |
|
||||||
'#options' => $andOrArray |
|
||||||
); |
|
||||||
$form['search_type']["type$i"] = array( |
|
||||||
'#title' => t(''), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $types, |
|
||||||
'#default_value' => trim($field_and_term[0]) |
|
||||||
); |
|
||||||
$form["fedora_terms$i"] = array( |
|
||||||
'#size' => '24', |
|
||||||
'#type' => 'textfield', |
|
||||||
'#title' => t(''), |
|
||||||
'#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''), |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$form['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('search') |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* get search terms array |
|
||||||
* @param type $path |
|
||||||
* @param string $file |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function get_search_terms_array($path = NULL, $file = NULL) { |
|
||||||
if (!isset($path)) { |
|
||||||
$path = drupal_get_path('module', 'fedora_repository'); |
|
||||||
} |
|
||||||
$xmlDoc = new DomDocument(); |
|
||||||
if (!isset($file)) { |
|
||||||
$file = 'searchTerms.xml'; |
|
||||||
} |
|
||||||
$xmlDoc->load($path . '/' . $file); |
|
||||||
$nodeList = $xmlDoc->getElementsByTagName('term'); |
|
||||||
$types = array(); |
|
||||||
for ($i = 0; $i < $nodeList->length; $i++) { |
|
||||||
$field = $nodeList->item($i)->getElementsByTagName('field'); |
|
||||||
$value = $nodeList->item($i)->getElementsByTagName('value'); |
|
||||||
$fieldValue = $field->item(0)->nodeValue; |
|
||||||
$valueValue = $value->item(0)->nodeValue; |
|
||||||
$types["$fieldValue"] = "$valueValue"; |
|
||||||
} |
|
||||||
return $types; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,137 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* This file defines the hooks that fedora_repository (islandora) |
||||||
|
* makes available. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_islandora_tabs(). |
||||||
|
* This hook lets one add tabs to the object page in Islandora. |
||||||
|
* |
||||||
|
* @param array $content_models |
||||||
|
* An Array of content model objects. A content model is only included |
||||||
|
* if the object actualy exists with a ISLANDORACM datastream. |
||||||
|
* @param string $pid |
||||||
|
* The Fedora PID of the object who's page is firing the hook. |
||||||
|
* @param int $page_number |
||||||
|
* Page number for collection views. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* $tabset a tab definition. |
||||||
|
*/ |
||||||
|
function hook_islandora_tabs($content_models, $pid, $page_number) { |
||||||
|
|
||||||
|
$tabset['A TAB'] = array( |
||||||
|
'#type' => 'tabpage', |
||||||
|
'#title' => t('A TITLE'), |
||||||
|
'#content' => 'content') |
||||||
|
); |
||||||
|
|
||||||
|
return $tabset; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_postprocess_solution_pack(). |
||||||
|
* This hook fires after the batch job to ingest a solution pack finishes. |
||||||
|
* |
||||||
|
* @param string $module |
||||||
|
* Name of the module that spcified the solution pack. |
||||||
|
*/ |
||||||
|
function hook_fedora_repository_postprocess_solution_pack($module) { |
||||||
|
|
||||||
|
// Do something that requires the objects to be ingested ie. add XACML. |
||||||
|
return; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_required_fedora_objects(). |
||||||
|
* This hook lets one add objects to the repository through the |
||||||
|
* solution pack interface. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', |
||||||
|
* int dsversion, boolean required) |
||||||
|
*/ |
||||||
|
function hook_required_fedora_objects() { |
||||||
|
return array( |
||||||
|
'fedora_repository' => array( |
||||||
|
'module' => 'fedora_repository', |
||||||
|
'title' => 'Islandora Core', |
||||||
|
'objects' => array( |
||||||
|
array( |
||||||
|
'pid' => 'islandora:collectionCModel', |
||||||
|
'label' => 'Islandora Collection Content Model', |
||||||
|
'dsid' => 'ISLANDORACM', |
||||||
|
'datastream_file' => "./$module_path/content_models/COLLECTIONCM.xml", |
||||||
|
'dsversion' => 2, |
||||||
|
'cmodel' => 'fedora-system:ContentModel-3.0', |
||||||
|
), |
||||||
|
array( |
||||||
|
'pid' => 'islandora:root', |
||||||
|
'label' => 'Islandora Top-level Collection', |
||||||
|
'cmodel' => 'islandora:collectionCModel', |
||||||
|
'datastreams' => array( |
||||||
|
array( |
||||||
|
'dsid' => 'COLLECTION_POLICY', |
||||||
|
'datastream_file' => "./$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml", |
||||||
|
), |
||||||
|
array( |
||||||
|
'dsid' => 'TN', |
||||||
|
'datastream_file' => "./$module_path/images/Gnome-emblem-photos.png", |
||||||
|
'mimetype' => 'image/png', |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_fedora_repository_can_ingest(). |
||||||
|
* Override ingest permissions. |
||||||
|
* (from islandora_workflow) |
||||||
|
* |
||||||
|
* @deprecated |
||||||
|
* Deprecated in favour of hook_fedora_repository_check_perm(). |
||||||
|
* @param string $collection_pid |
||||||
|
* The PID of the collection |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
* TRUE if the user can ingest into the specified collection, FALSE otherwise. |
||||||
|
*/ |
||||||
|
function hook_fedora_repository_can_ingest($collection_pid) { |
||||||
|
|
||||||
|
module_load_include('inc', 'islandora_workflow', 'islandora_workflow.permissions'); |
||||||
|
return (islandora_workflow_user_collection_permission_check($collection_pid) !== FALSE); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_fedora_repository_check_perm(). |
||||||
|
* |
||||||
|
* Hook to allow other modules to allow or deny operations on conditions other |
||||||
|
* than the explicit Drupal permissions. |
||||||
|
* |
||||||
|
* @param string $op |
||||||
|
* A string representing the operation to be performed. |
||||||
|
* @param string|null $pid |
||||||
|
* A string containing the Fedora PID on which the operation is to be |
||||||
|
* performed. The (default) value of NULL will use the PID indicated by the |
||||||
|
* fedora_repository_pid Drupal variable. |
||||||
|
* @param object|null $as_user |
||||||
|
* An object representing the user for whom to check the permissions (as |
||||||
|
* given by user_load or the $user global). The (default) value of NULL will |
||||||
|
* cause permissions to be evaluated for the current user (from the $user |
||||||
|
* global). |
||||||
|
* |
||||||
|
* @return boolean|null |
||||||
|
* Either a boolean permitting (TRUE) or forbidding (FALSE) an operation, or |
||||||
|
* NULL to make no assertion. |
||||||
|
*/ |
||||||
|
function hook_fedora_repository_check_perm($op, $pid = NULL, $as_user = NULL) { |
||||||
|
return NULL; |
||||||
|
} |
@ -1,106 +1,134 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
/** |
/** |
||||||
* @file fedora_repository.install |
* @file fedora_repository.install |
||||||
*/ |
*/ |
||||||
|
|
||||||
/** |
/** |
||||||
* Implementation of hook_enable(). |
* Implementation of hook_enable(). |
||||||
*/ |
*/ |
||||||
function fedora_collections_enable() { |
function fedora_collections_enable() { |
||||||
//nothing to do as we do not currently touch the drupal database. |
//nothing to do as we do not currently touch the drupal database. |
||||||
//other than the variables table |
//other than the variables table |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Implementation of hook_requirements(). |
* Implementation of hook_requirements(). |
||||||
* |
* |
||||||
* @return |
* @return |
||||||
* An array describing the status of the site regarding available updates. |
* An array describing the status of the site regarding available updates. |
||||||
* If there is no update data, only one record will be returned, indicating |
* If there is no update data, only one record will be returned, indicating |
||||||
* that the status of core can't be determined. If data is available, there |
* that the status of core can't be determined. If data is available, there |
||||||
* will be two records: one for core, and another for all of contrib |
* will be two records: one for core, and another for all of contrib |
||||||
* (assuming there are any contributed modules or themes enabled on the |
* (assuming there are any contributed modules or themes enabled on the |
||||||
* site). In addition to the fields expected by hook_requirements ('value', |
* site). In addition to the fields expected by hook_requirements ('value', |
||||||
* 'severity', and optionally 'description'), this array will contain a |
* 'severity', and optionally 'description'), this array will contain a |
||||||
* 'reason' attribute, which is an integer constant to indicate why the |
* 'reason' attribute, which is an integer constant to indicate why the |
||||||
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or |
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or |
||||||
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail |
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail |
||||||
* notification messages during update_cron(), and might be useful for other |
* notification messages during update_cron(), and might be useful for other |
||||||
* modules that invoke update_requirements() to find out if the site is up |
* modules that invoke update_requirements() to find out if the site is up |
||||||
* to date or not. |
* to date or not. |
||||||
* |
* |
||||||
* @see _update_message_text() |
* @see _update_message_text() |
||||||
* @see _update_cron_notify() |
* @see _update_cron_notify() |
||||||
*/ |
*/ |
||||||
function fedora_repository_requirements($phase) { |
function fedora_repository_requirements($phase) { |
||||||
$requirements = array(); |
$requirements = array(); |
||||||
$t = get_t(); //May not have access to the regular t() function; and so Drupal provides... |
$t = get_t(); //May not have access to the regular t() function; and so Drupal provides... |
||||||
|
|
||||||
if ($phase == 'install') { |
if ($phase == 'install') { |
||||||
|
|
||||||
// Test for SOAP |
// 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')) { |
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']['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 { |
else { |
||||||
$requirements['fedora-soap']['value'] = $t("Installed"); |
$requirements['fedora-soap']['value'] = $t("Installed"); |
||||||
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK; |
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK; |
||||||
} |
} |
||||||
|
|
||||||
// Test for Curl |
// Test for Curl |
||||||
$requirements['curl']['title'] = $t('PHP Curl extension library'); |
$requirements['curl']['title'] = $t('PHP Curl extension library'); |
||||||
if (!function_exists('curl_init')) { |
if (!function_exists('curl_init')) { |
||||||
$requirements['curl']['value'] = $t("Not installed"); |
$requirements['curl']['value'] = $t("Not installed"); |
||||||
$requirements['curl']['severity'] = REQUIREMENT_ERROR; |
$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 { |
else { |
||||||
$requirements['curl']['value'] = $t("Installed"); |
$requirements['curl']['value'] = $t("Installed"); |
||||||
$requirements['curl']['severity'] = REQUIREMENT_OK; |
$requirements['curl']['severity'] = REQUIREMENT_OK; |
||||||
} |
} |
||||||
|
|
||||||
// Test for DOM |
// 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')) { |
if (!method_exists('DOMDocument', 'loadHTML')) { |
||||||
$requirements['dom']['value'] = $t("Not installed"); |
$requirements['dom']['value'] = $t("Not installed"); |
||||||
$requirements['dom']['severity'] = REQUIREMENT_ERROR; |
$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 { |
else { |
||||||
$requirements['dom']['value'] = $t("Installed"); |
$requirements['dom']['value'] = $t("Installed"); |
||||||
$requirements['dom']['severity'] = REQUIREMENT_OK; |
$requirements['dom']['severity'] = REQUIREMENT_OK; |
||||||
} |
} |
||||||
|
|
||||||
// Test for XSLT |
// Test for XSLT |
||||||
$requirements['xsl']['title'] = $t("PHP XSL extension library"); |
$requirements['xsl']['title'] = $t("PHP XSL extension library"); |
||||||
if (!class_exists('XSLTProcessor')) { |
if (!class_exists('XSLTProcessor')) { |
||||||
$requirements['xslt']['value'] = $t("Not installed"); |
$requirements['xslt']['value'] = $t("Not installed"); |
||||||
$requirements['xslt']['severity'] = REQUIREMENT_ERROR; |
$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 { |
else { |
||||||
$requirements['xslt']['value'] = $t("Installed"); |
$requirements['xslt']['value'] = $t("Installed"); |
||||||
$requirements['xslt']['severity'] = REQUIREMENT_OK; |
$requirements['xslt']['severity'] = REQUIREMENT_OK; |
||||||
} |
} |
||||||
} |
} |
||||||
elseif ($phase == 'runtime') { |
elseif ($phase == 'runtime') { |
||||||
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); |
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()) { |
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']['severity'] = REQUIREMENT_ERROR; |
||||||
$requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => url('admin/settings/fedora_repository'))); |
$requirements['fedora-repository']['description'] = $t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.', array('@collection-settings' => url('admin/settings/fedora_repository'))); |
||||||
} |
} |
||||||
else { |
else { |
||||||
$requirements['fedora-repository']['value'] = $t("Available"); |
$requirements['fedora-repository']['value'] = $t("Available"); |
||||||
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK; |
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return $requirements; |
return $requirements; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_update_N(). |
||||||
|
* |
||||||
|
* This function will try and update the SOAP WSDLs |
||||||
|
* as they were set wrong in previous releases. |
||||||
|
*/ |
||||||
|
function fedora_repository_update_6001() { |
||||||
|
// Get variables to check for update. |
||||||
|
$API_A_WSDL = variable_get('fedora_soap_url', $default = NULL); |
||||||
|
$API_M_WSDL = variable_get('fedora_soap_manage_url', $default = NULL); |
||||||
|
|
||||||
|
// Update API A if necessary. |
||||||
|
$A_WSDL = parse_url($API_A_WSDL, PHP_URL_PATH) . '?' . parse_url($API_A_WSDL, PHP_URL_QUERY); |
||||||
|
if ($A_WSDL == '/fedora/services/access?wsdl') { |
||||||
|
variable_set('fedora_soap_url', str_replace('/fedora/services/access?wsdl', '/fedora/wsdl?api=API-A', $API_A_WSDL)); |
||||||
|
} |
||||||
|
|
||||||
|
// Update API M if necessary. |
||||||
|
$M_WSDL = parse_url($API_M_WSDL, PHP_URL_PATH) . '?' . parse_url($API_M_WSDL, PHP_URL_QUERY); |
||||||
|
if ($M_WSDL == '/fedora/services/management?wsdl') { |
||||||
|
variable_set('fedora_soap_manage_url', str_replace('/fedora/services/management?wsdl', '/fedora/wsdl?api=API-M', $API_M_WSDL)); |
||||||
|
} |
||||||
|
|
||||||
|
return array( |
||||||
|
array('success' => TRUE, 'query' => 'Please check your WSDL paths in Islandora\'s config, this update requires them to be set correctly: access; /fedora/wsdl?api=API-A, management; /fedora/wsdl?api=API-M'), |
||||||
|
); |
||||||
|
} |
||||||
|
@ -0,0 +1,161 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* Generic test case to be extended to implement Islandora testing. |
||||||
|
* |
||||||
|
* In order to use this properly, you must place a test user in |
||||||
|
* your Fedora installation. Please add the follwing snippet to your |
||||||
|
* $FEDORA_HOME/server/config/fedora-users.xml: |
||||||
|
* |
||||||
|
* <user name="simpletestuser" password="41fe63c9636c6649f0a4747400f0f95e"> |
||||||
|
* <attribute name="fedoraRole"> |
||||||
|
* <value>administrator</value> |
||||||
|
* </attribute> |
||||||
|
* </user> |
||||||
|
*/ |
||||||
|
abstract class IslandoraTestCase extends DrupalWebTestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* User with the rights required to perform the test |
||||||
|
*/ |
||||||
|
protected $privileged_user; |
||||||
|
|
||||||
|
/** |
||||||
|
* Override this method to provide the name of the module, |
||||||
|
* e.g. the name of the .module file |
||||||
|
* |
||||||
|
* @return string - The name of the module |
||||||
|
*/ |
||||||
|
abstract protected function getModuleName(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns basic permissions needed for running Islandora tests. |
||||||
|
* Override this method to provide additional permissions, but |
||||||
|
* be sure to append your new permissions to the return value |
||||||
|
* of parent::getUserPermissions and return that. |
||||||
|
* |
||||||
|
* @return array - An array of strings describing permissions |
||||||
|
*/ |
||||||
|
protected function getUserPermissions() { |
||||||
|
return array( |
||||||
|
'access content', |
||||||
|
'add fedora datastreams', |
||||||
|
'edit fedora meta data', |
||||||
|
'edit tags datastream', |
||||||
|
'ingest new fedora objects', |
||||||
|
'purge objects and datastreams', |
||||||
|
'view fedora collection', |
||||||
|
'view detailed list of content', |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a user with permissions required for the test, and logs in. |
||||||
|
*/ |
||||||
|
protected function createPrivilegedUser() { |
||||||
|
// Create a role with the permissions from getUserPermissions() |
||||||
|
$role = $this->drupalCreateRole($this->getUserPermissions()); |
||||||
|
|
||||||
|
// Create a user model |
||||||
|
$user = array( |
||||||
|
'name' => 'simpletestuser', |
||||||
|
'mail' => 'simpletestuser@example.com', |
||||||
|
'roles' => array( $role => $role ), |
||||||
|
'pass' => 'simpletestpass', |
||||||
|
'status' => 1, |
||||||
|
); |
||||||
|
|
||||||
|
// Create a user from the model |
||||||
|
$this->privileged_user = user_save('', $user); |
||||||
|
|
||||||
|
// Add the raw password so we can log in |
||||||
|
$this->privileged_user->pass_raw = $user['pass']; |
||||||
|
|
||||||
|
// Log in |
||||||
|
!$this->drupalLogin($this->privileged_user); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Automatically generates all module dependencies and enables them in order. |
||||||
|
* Also logs in a privileged user with the appropriate permissions for the |
||||||
|
* test. |
||||||
|
* |
||||||
|
* If you need to override this method to provide extra functionality, |
||||||
|
* please be sure to call parent::setUp so dependency resolution and |
||||||
|
* authentication still happen. |
||||||
|
*/ |
||||||
|
public function setUp() { |
||||||
|
// Grab all the available modules |
||||||
|
$modules = module_rebuild_cache(); |
||||||
|
|
||||||
|
// Grab the module to test's dependencies |
||||||
|
$dependencies = $modules[$this->getModuleName()]->info['dependencies']; |
||||||
|
|
||||||
|
// Sort them so they're in the correct order to enable |
||||||
|
$dependencies = array_reverse($dependencies); |
||||||
|
|
||||||
|
// Add our module to the end |
||||||
|
$dependencies[] = $this->getModuleName(); |
||||||
|
|
||||||
|
// Enable the module's dependencies in order |
||||||
|
call_user_func_array('parent::setUp', $dependencies); |
||||||
|
|
||||||
|
// Authenticate the privileged user |
||||||
|
$this->createPrivilegedUser(); |
||||||
|
} |
||||||
|
|
||||||
|
public function invoke($hook_name) { |
||||||
|
$args = func_get_args(); |
||||||
|
array_unshift($args, $this->getModuleName()); |
||||||
|
return call_user_func_array('module_invoke', $args); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Class containing tests that are common to all solution packs. |
||||||
|
*/ |
||||||
|
abstract class SolutionPackTestCase extends IslandoraTestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* Tests the fedora_repository_required_fedora_objects hook. |
||||||
|
* |
||||||
|
* Validates the schema of the array returned by the hook. The array should |
||||||
|
* be roughly of the form: |
||||||
|
* [ |
||||||
|
* module_name => |
||||||
|
* [ |
||||||
|
* 'module' => module_name, |
||||||
|
* 'title' => module_title, |
||||||
|
* 'objects' => |
||||||
|
* [ |
||||||
|
* ... |
||||||
|
* ] |
||||||
|
* ] |
||||||
|
* ] |
||||||
|
* |
||||||
|
* Where each entry of the 'objects' sub-array should be arrays themselves, |
||||||
|
* each containing the information needed for drupal_get_form(). |
||||||
|
* |
||||||
|
* Note that the root key of the array is the actual module name (e.g. |
||||||
|
* islandora_audio_sp, islandora_image_sp, etc...), not 'module_name' |
||||||
|
*/ |
||||||
|
public function testFedoraRepositoryRequiredFedoraObjects() { |
||||||
|
|
||||||
|
// Invoke the hook |
||||||
|
$results = $this->invoke('fedora_repository_required_fedora_objects'); |
||||||
|
|
||||||
|
// Validate the schema of the returned data structure |
||||||
|
$this->assertNotNull($results, 'A non-null result was returned from the fedora_repository_required_fedora_objects hook.'); |
||||||
|
$this->assertTrue(is_array($results), 'An array was returned from the fedora_repository_required_fedora_objects hook.'); |
||||||
|
$this->assertTrue(array_key_exists($this->getModuleName(), $results), "Returned array has top level key that is equal to the module's short form name"); |
||||||
|
$this->assertTrue(is_array($results[$this->getModuleName()]), "Value associated with top level key that is equal to the module's short form name is an array"); |
||||||
|
$this->assertTrue(array_key_exists('module', $results[$this->getModuleName()]), "Top level array has 'module' key"); |
||||||
|
$this->assertEqual($results[$this->getModuleName()]['module'], $this->getModuleName(), "Value associated with 'module' key is equal to the module's short form name"); |
||||||
|
$this->assertTrue(array_key_exists('title', $results[$this->getModuleName()]), "Top level array has 'title' key"); |
||||||
|
$this->assertTrue($results[$this->getModuleName()]['title'], "Title string is not empty"); |
||||||
|
$this->assertTrue(array_key_exists('objects', $results[$this->getModuleName()]), "Returned array has second level key equal to 'object'"); |
||||||
|
$this->assertTrue(is_array($results[$this->getModuleName()]['objects']), "Value associated with second level 'object' key is an array"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* Fits |
||||||
|
* fits.sh must be in the apache user's path |
||||||
|
* |
||||||
|
* Download FITS from http://code.google.com/p/fits/ |
||||||
|
* Installing: http://code.google.com/p/fits/wiki/installing |
||||||
|
* Edit line 5 in fits.sh (FITS_HOME='') and give it a home. |
||||||
|
* Make sure that home is in the apache user's path. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* This Class implements the methods defined in the STANDARD_IMAGE content model |
||||||
|
*/ |
||||||
|
class fits { |
||||||
|
|
||||||
|
private $pid = NULL; |
||||||
|
private $item = NULL; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor |
||||||
|
* @param type $pid |
||||||
|
*/ |
||||||
|
function __construct($pid = NULL) { |
||||||
|
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); |
||||||
|
if (!empty($pid)) { |
||||||
|
$this->pid = $pid; |
||||||
|
$this->item = new Fedora_Item($this->pid); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* extract metadata |
||||||
|
* @param type $parameterArray |
||||||
|
* @param type $dsid |
||||||
|
* @param type $file |
||||||
|
* @param type $file_ext |
||||||
|
* @return type |
||||||
|
*/ |
||||||
|
function extractFits($parameterArray, $dsid, $file, $file_ext) { |
||||||
|
if (variable_get('enable_fits', FALSE) == 1) { |
||||||
|
$file_name = '_' . $dsid . '.xml'; |
||||||
|
$output = array(); |
||||||
|
exec(variable_get('fits_path', '/usr/local/bin/fits.sh') .' -i ' . escapeshellarg($file) . '', $output); |
||||||
|
if ( !file_put_contents($file . $file_name, implode("\n", $output)) ) { |
||||||
|
//drupal_set_message(t("error writing fits file %s", array('%s' => "$file.$file_name"))); |
||||||
|
return FALSE; |
||||||
|
} |
||||||
|
$_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_name; |
||||||
|
return TRUE; |
||||||
|
} |
||||||
|
return TRUE; //this prevents getting the error following content model rules message when fits generation is turned off |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* display metadata |
||||||
|
* @return type |
||||||
|
*/ |
||||||
|
function displayFits() { |
||||||
|
$output = ''; |
||||||
|
$fits = $this->item->get_datastream_dissemination('TECHMD_FITS'); |
||||||
|
if (trim($fits) != '') { |
||||||
|
$fitsDom = DOMDocument::loadXML($this->item->get_datastream_dissemination('FITS')); |
||||||
|
if ($fitsDom != NULL) { |
||||||
|
$description = $fitsDom->getElementsByTagName('fits'); |
||||||
|
if ($description->length > 0) { |
||||||
|
$description = $description->item(0); |
||||||
|
$output .= '<div class="fedora_technical_metadata"><ul>'; |
||||||
|
for ($i = 0; $i < $description->childNodes->length; $i++) { |
||||||
|
$name = $description->childNodes->item($i)->nodeName; |
||||||
|
$value = $description->childNodes->item($i)->nodeValue; |
||||||
|
if ($name != '#text' && !preg_match('/^System\:.*$/', $name) && trim($value) != '') { |
||||||
|
list($type, $name) = preg_split('/\:/', $name); |
||||||
|
$name = trim(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])/', " $1", $name)); |
||||||
|
$output .= '<li><b>' . $name . '</b>: ' . $value . ' </li>'; |
||||||
|
} |
||||||
|
} |
||||||
|
$output .= '</ul></div>'; |
||||||
|
|
||||||
|
$fieldset = array( |
||||||
|
'#title' => t("!text", array('!text' => 'FITS Technical Metadata')), |
||||||
|
'#collapsible' => TRUE, |
||||||
|
'#collapsed' => TRUE, |
||||||
|
'#value' => $output |
||||||
|
); |
||||||
|
$output = theme('fieldset', $fieldset); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return $output; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue