Browse Source

Code cleanup following addition of namespace restriction flag

pull/105/head
Alan Stanley 14 years ago
parent
commit
eab0289dde
  1. 5
      ObjectHelper.inc
  2. 94
      SearchClass.inc
  3. 3
      api/fedora_item.inc
  4. 5
      api/fedora_utils.inc
  5. 11
      fedora_repository.module
  6. 43
      formClass.inc
  7. 1
      ilives/fedora_ilives.module
  8. 6
      plugins/fedora_attach/fedora_attach.admin.inc

5
ObjectHelper.inc

@ -606,7 +606,12 @@ class ObjectHelper {
function fedora_repository_access($op, $pid) { function fedora_repository_access($op, $pid) {
global $user; global $user;
$returnValue = FALSE; $returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if(!$isRestricted){
return TRUE;
}
if ($pid == NULL) { if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:top'); $pid = variable_get('fedora_repository_pid', 'islandora:top');
} }

94
SearchClass.inc

@ -208,42 +208,7 @@ class SearchClass {
} }
/*
function custom_search($query,$pathToXslt=NULL){
module_load_include('php', 'Fedora_Repository', 'ObjectHelper');
module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils');
if (user_access('view fedora collection')) {
$numberOfHistPerPage = '1000';//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
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$query=htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $query;
$searchString .= '&hitPageSize='.$numberOfHistPerPage.'&hitPageStart=1';
//$searchString = htmlentities($searchString);
$searchUrl .= $searchString;
$objectHelper = new ObjectHelper();
$resultData = do_curl($searchUrl,1);
//var_dump($resultData);exit(0);
// $doc = new DOMDocument();
// $doc->loadXML($resultData);
if($pathToXslt==NULL) {
$output.=$this->applyLuceneXSLT($resultData,$query);
}else{
$output.=$this->applySpecifiedXSLT($resultData,$pathToXslt);
}
return $output;
}
}
*/
function custom_search($query, $startPage=1, $xslt= '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) { 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', 'ObjectHelper');
@ -327,53 +292,7 @@ class SearchClass {
} }
} }
//default function for lucene results //default function for lucene results
/*
function applyLuceneXSLT($resultData, $query = NULL){
$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
if(isset($query)){
$proc->setParameter('', 'fullQuery', $query);
}
$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', 'demo: changeme:'));
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$test= $xsl->load($path . '/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 {
$proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
return $newdom->saveXML();
}
}
*/
/** /**
* apply an xslt to lucene gsearch search results * apply an xslt to lucene gsearch search results
@ -385,6 +304,11 @@ class SearchClass {
*/ */
function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) { function applyLuceneXSLT($resultData, $startPage = 1, $xslt_file = '/xsl/results.xsl', $query=NULL) {
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$test = $xslt_file;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if(!isRestricted && $xslt_file == null){
$xslt_file = '/xsl/unfilteredresults.xsl';
}
$proc = NULL; $proc = NULL;
if (!$resultData) { if (!$resultData) {
//drupal_set_message(t('No Results!')); //drupal_set_message(t('No Results!'));
@ -405,7 +329,7 @@ class SearchClass {
$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('', '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('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path()); $proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ')); $proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$proc->setParameter('', 'hitPageStart', $startPage); $proc->setParameter('', 'hitPageStart', $startPage);
$proc->registerPHPFunctions(); $proc->registerPHPFunctions();
$xsl = new DomDocument(); $xsl = new DomDocument();
@ -450,7 +374,7 @@ class SearchClass {
$proc->setParameter('', 'userID', $user->uid); $proc->setParameter('', 'userID', $user->uid);
$proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl $proc->setParameter('', 'searchUrl', url('search') . '/fedora_repository'); //needed in our xsl
$proc->setParameter('', 'objectsPage', base_path()); $proc->setParameter('', 'objectsPage', base_path());
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ')); $proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$proc->setParameter('', 'orderBy', $orderBy); $proc->setParameter('', 'orderBy', $orderBy);
$xsl = new DomDocument(); $xsl = new DomDocument();

3
api/fedora_item.inc

@ -557,9 +557,10 @@ class Fedora_Item {
} }
static function get_next_PID_in_namespace( $pid_namespace = '') { static function get_next_PID_in_namespace( $pid_namespace = '') {
if (empty($pid_namespace)) { if (empty($pid_namespace)) {
// Just get the first one in the config settings. // Just get the first one in the config settings.
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ')); $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$pid_namespace = $allowed_namespaces[0]; $pid_namespace = $allowed_namespaces[0];
if (!empty($pid_namespace)) { if (!empty($pid_namespace)) {
$pid_namespace = substr($pid_namespace, 0, strpos($pid_namespace, ":")); $pid_namespace = substr($pid_namespace, 0, strpos($pid_namespace, ":"));

5
api/fedora_utils.inc

@ -72,7 +72,7 @@ function fedora_available() {
//return (strpos($ret, 'wsdl:definitions') != FALSE); //return (strpos($ret, 'wsdl:definitions') != FALSE);
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
return true;
try { try {
@ -84,11 +84,10 @@ function fedora_available() {
$result = $soap_client->__soapCall('describeRepository', array()); $result = $soap_client->__soapCall('describeRepository', array());
} }
print 'why am I here?';
return TRUE; return TRUE;
} }
catch (SoapFault $e) { catch (SoapFault $e) {
print 'what now?';
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection.")); watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection."));
return FALSE; return FALSE;

11
fedora_repository.module

@ -961,6 +961,7 @@ function fedora_repository_search($op = 'search', $keys = NULL) {
*/ */
function fedora_repository_search_page($resultData) { function fedora_repository_search_page($resultData) {
$path = drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
$proc = NULL; $proc = NULL;
if (!$resultData[0][0]['data']) { if (!$resultData[0][0]['data']) {
return ''; //no results return ''; //no results
@ -986,8 +987,13 @@ function fedora_repository_search_page($resultData) {
$proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ')); $proc->setParameter('', 'allowedPidNameSpaces', variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$proc->registerPHPFunctions(); $proc->registerPHPFunctions();
$xsl = new DomDocument(); $xsl = new DomDocument();
$xsl->load($path . '/xsl/results.xsl'); if($isRestricted){
$quimby = $xsl; $xsl->load($path . '/xsl/results.xsl');
}
else{
$xsl->load($path . '/xsl/unfilteredresults.xsl');
}
$input = new DomDocument(); $input = new DomDocument();
$didLoadOk = $input->loadXML(utf8_encode($resultData[0][0]['data'])); $didLoadOk = $input->loadXML(utf8_encode($resultData[0][0]['data']));
@ -1193,6 +1199,7 @@ function theme_fedora_repository_mnpl_advanced_search_form($form) {
function fedora_repository_mnpl_advanced_search($query, $startPage = 1) { function fedora_repository_mnpl_advanced_search($query, $startPage = 1) {
module_load_include('inc', 'fedora_repository', 'SearchClass'); module_load_include('inc', 'fedora_repository', 'SearchClass');
$searchClass = new SearchClass(); $searchClass = new SearchClass();
$retVal = $searchClass->custom_search($query, $startPage);
return $searchClass->custom_search($query, $startPage); return $searchClass->custom_search($query, $startPage);
} }

43
formClass.inc

@ -325,31 +325,30 @@ class formClass {
'#weight' => 0 '#weight' => 0
); );
/*
$form['fedora_default_display_pid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Object Pid' ),
'#default_value' => variable_get('fedora_default_display_pid', 'demo:10'),
'#description' => t('Object Pid of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
);
$form['fedora_default_display_dsid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Datastream ID' ),
'#default_value' => variable_get('fedora_default_display_dsid', 'TN'),
'#description' => t('Object Datastream id of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
);
*/
$form['fedora_pids_allowed'] = array(
$form['fedora_namespace'] = array(
'#type' => 'fieldset',
);
$form['fedora_namespace']['fedora_namespace_restriction_enforced'] = array(
'#weight' => -1,
'#type' => 'radios',
'#title' => t('Enforce namespace restrictions'),
'#options' => array(
TRUE => t('Enabled'),
FALSE => t('Disabled')
),
'#description' => t('Allow administrator to restrict user\'s access to the PID namepaces listed below' ),
'#default_value' => variable_get('fedora_namespace_restriction_enforced',TRUE)
);
$form['fedora_namespace']['fedora_pids_allowed'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'), '#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '), '#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '),
'#description' => t('The PID namespaces that you are allowed to see from this Drupal install. In reality this can be more than a namespace as it could include demo:mydemos etc. Can be a space seperated list to include more than one PID namespace.'), '#description' => t('A space separated list PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#required' => TRUE,
'#weight' => 0 '#weight' => 0
); );
/* /*

1
ilives/fedora_ilives.module

@ -548,6 +548,7 @@ function install_book_content_model_objects() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$allowed_pids_str = variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '); $allowed_pids_str = variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ');
$allowed_pids = explode(' ', $allowed_pids_str); $allowed_pids = explode(' ', $allowed_pids_str);
if (!in_array('ilives:', $allowed_pids)) { if (!in_array('ilives:', $allowed_pids)) {
variable_set('fedora_pids_allowed', $allowed_pids_str . ' ilives:'); variable_set('fedora_pids_allowed', $allowed_pids_str . ' ilives:');

6
plugins/fedora_attach/fedora_attach.admin.inc

@ -14,10 +14,12 @@
* @see system_settings_form(). * @see system_settings_form().
*/ */
function fedora_attach_admin() { function fedora_attach_admin() {
$options = drupal_map_assoc(explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '))); $options = drupal_map_assoc(explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: ')));
$default_value = variable_get('fedora_attach_pid_namespace', 'default:'); $default_value = variable_get('fedora_attach_pid_namespace', 'default:');
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if (!in_array($default_value, $options)) {
if (!in_array($default_value, $options) && $isRestricted) {
drupal_set_message( "The value last set here ($default_value) is not in the list of available PID namespaces (perhaps it has changed?). Please choose a valid option from the list.", 'warning' ); drupal_set_message( "The value last set here ($default_value) is not in the list of available PID namespaces (perhaps it has changed?). Please choose a valid option from the list.", 'warning' );
} }

Loading…
Cancel
Save