From d36fdd291ce6d346f75e4414409b73241c286ac8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 12 Jul 2011 14:14:25 -0300 Subject: [PATCH 01/74] Fix Headers for FlowPlayer FlowPlayer requires the "Content-Length" header to be returned in order to work properly, but it wasn't getting returned in the header when a user was not logged in. A slight change to the semantics, and opening up of the getDatastream API-M method via XACML seems to work. --- ObjectHelper.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 0f8be1bb..4a12240b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -94,13 +94,13 @@ class ObjectHelper { if ((!isset($user)) || $user->uid == 0) { $fedoraUser = 'anonymous'; $fedoraPass = 'anonymous'; - $contentSize = 0; } else { $fedoraUser = $user->name; $fedoraPass = $user->pass; - $dataStreamInfo = $item->get_datastream_info($dsID); - $contentSize = $dataStreamInfo->datastream->size; } + + $dataStreamInfo = $item->get_datastream_info($dsID); + $contentSize = $dataStreamInfo->datastream->size; if (function_exists("curl_init")) { if (!isset($mimeType)) { From 5aefe46f85709cd5218a5f139616dc925f57b90c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 24 Apr 2012 14:19:47 -0300 Subject: [PATCH 02/74] Use wrapping modify_datastream wrapper in replace datastream callback. --- fedora_repository.module | 45 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index e83d91f5..208e028e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -646,27 +646,27 @@ function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLab * @return type */ function fedora_repository_replace_stream_form_validate($form, &$form_state) { -// If a file was uploaded, process it. + // If a file was uploaded, process it. if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) { -// attempt to save the uploaded file + // attempt to save the uploaded file $file = file_save_upload('file', array(), file_directory_path()); -// set error is file was not uploaded + // set error is file was not uploaded if (!$file) { form_set_error('file', 'Error uploading file.'); return; } - - $doc = new DOMDocument(); - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); + + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mime = new MimeClass(); - if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) { + + if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { form_set_error('file', 'Invalid XML format.'); return; } -// set files to form_state, to process when form is submitted + // set files to form_state, to process when form is submitted $form_state['values']['file'] = $file; } } @@ -683,39 +683,32 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; -// Remove the original file extension from the label and add the new one + + // Remove the original file extension from the label and add the new one $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot if ($indexOfDot !== FALSE) { $dsLabel = substr($dsLabel, 0, $indexOfDot); $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; } - module_load_include('inc', 'Fedora_Repository', 'MimeClass'); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - $file_basename = basename($file->filepath); - $file_directory = dirname($file->filepath); - $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); + $streamUrl = url($file->filepath, array( + 'absolute' => TRUE, + )); /* ----------------------------------------------------------------- * TODO: need a better way to get mimetypes */ + module_load_include('inc', 'fedora_repository', 'MimeClass'); $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - $info = $item->get_datastream_info($dsid); - - if($info->datastream->controlGroup == 'M') { - $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); - } elseif ($info->datastream->controlGroup == 'X') { - if($dformat == 'text/xml') { - $item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat); - } - else { - drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error'); - } + + if(in_array($info->datastream->controlGroup, array('M', 'X'))) { + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); } else { - drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error'); + drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); } $form_state['redirect'] = 'fedora/repository/' . $pid; From fa77552e57052ace01abef279e0a8cf3946083e2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 09:22:14 -0300 Subject: [PATCH 03/74] Get the extension without exploding. --- MimeClass.inc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MimeClass.inc b/MimeClass.inc index 42c11e37..b2950f6e 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -231,9 +231,7 @@ class MimeClass { * @return type */ public function get_mimetype($filename, $debug = FALSE) { - - $file_name_and_extension = explode('.', $filename); - $ext = strtolower(array_pop($file_name_and_extension)); + $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if (!empty($this->private_mime_types[$ext])) { if (TRUE === $debug) From 01ac63a3d98c996614f925e6f810098fe7e36117 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 25 Apr 2012 10:05:45 -0300 Subject: [PATCH 04/74] Allow the addition of Redirect and External datastreams. --- fedora_repository.module | 80 ++++++++++++++++++++------------------ formClass.inc | 83 +++++++++++++++++++++++++++++----------- 2 files changed, 104 insertions(+), 59 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 208e028e..940d1585 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -377,37 +377,25 @@ function add_stream_form_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; return; } - module_load_include('inc', 'fedora_repository', 'MimeClass'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $pathToModule = drupal_get_path('module', 'fedora_repository'); - $file = $form_state['values']['add-stream-file-location']; - $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; - $file_basename = basename($file); - $file_directory = dirname($file); - $streamUrl = $base_url . '/' . $file_directory . '/' . drupal_urlencode($file_basename); - /* ----------------------------------------------------------------- - * need a better way to get mimetypes - */ - $mimetype = new MimeClass(); - $dformat = $mimetype->getType($file); - $controlGroup = "M"; - if ($dformat == 'text/xml') { - $controlGroup = 'X'; - } try { $item = new Fedora_Item($pid); - $item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); - $object_helper = new ObjectHelper(); - $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); + if ($file = $form_state['values']['add-stream-file-location']) { + $object_helper = new ObjectHelper(); + $object_helper->get_and_do_datastream_rules($pid, $dsid, $file); - file_delete($file); + file_delete($file); + } } catch (exception $e) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); return; @@ -434,6 +422,7 @@ function add_stream_form(&$form_state, $pid) { * @return type */ function add_stream_form_validate($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'MimeClass'); if ($form_state['clicked_button']['#value'] == 'OK') { $form_state['rebuild'] = TRUE; return; @@ -444,15 +433,15 @@ function add_stream_form_validate($form, &$form_state) { form_set_error('', t('Data stream ID cannot be more than 64 characters.')); return FALSE; } - if (!(preg_match("/^[a-zA-Z]/", $dsid))) { - form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); + elseif (!(preg_match("/^[a-zA-Z]/", $dsid))) { + form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => $dsid))); return FALSE; } - if (strlen($dsLabel) > 64) { + elseif (strlen($dsLabel) > 64) { form_set_error('', t('Data stream Label cannot be more than 64 characters.')); return FALSE; } - if (strpos($dsLabel, '/')) { + elseif (strpos($dsLabel, '/') !== FALSE) { form_set_error('', t('Data stream Label cannot contain a "/".')); return FALSE; } @@ -462,12 +451,30 @@ function add_stream_form_validate($form, &$form_state) { // 'file_validate_size' => array(30 * 1024), ); - $fileObject = file_save_upload('add-stream-file-location', $validators); - -// Move the uploaded file to Drupal's files directory. - file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); - $form_state['values']['add-stream-file-location'] = $fileObject->filepath; -// TODO: Add error checking here. + $mimetype = new MimeClass(); + $controlGroup = $form_state['values']['control_group']; + if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) { + // Move the uploaded file to Drupal's files directory. + file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); + $form_state['values']['add-stream-file-location'] = $fileObject->filepath; + $form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath); + + $file_basename = basename($fileObject->filepath); + $file_directory = dirname($fileObject->filepath); + + $form_state['storage']['stream_url'] = url($file_directory . '/' . drupal_urlencode($file_basename), array( + 'absolute' => TRUE, + )); + } + elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { + $form_state['storage']['ds_mimetype'] = $mimetype->getType($ref); + $form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; + } + else { + form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); + } + + // TODO: Add error checking here. $form_state['rebuild'] = FALSE; } @@ -680,6 +687,11 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { function fedora_repository_replace_stream_form_submit($form, &$form_state) { global $base_url; $file = $form_state['values']['file']; + + if ($file !== NULL) { + $file = $form_state['values']['reference']; + } + $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; $dsLabel = $form_state['values']['dsLabel']; @@ -702,14 +714,9 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); - if(in_array($info->datastream->controlGroup, array('M', 'X'))) { - $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); - } else { - drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error'); - } + $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $form_state['redirect'] = 'fedora/repository/' . $pid; } @@ -1052,7 +1059,6 @@ function fedora_repository_urlencode_string($str) { * @return type */ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { - global $user; module_load_include('inc', 'fedora_repository', 'ObjectHelper'); if ($pid == NULL || $dsId == NULL) { @@ -1061,7 +1067,7 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { } $objectHelper = new ObjectHelper(); - $objectHelper->makeObject($pid, $dsId, 1, $label, FALSE, $version); + $objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version); } /** diff --git a/formClass.inc b/formClass.inc index 713f1fcb..db90798c 100644 --- a/formClass.inc +++ b/formClass.inc @@ -656,17 +656,21 @@ class formClass { } } - $form['add_datastream_label'] = array( - '#value' => t('

Add Datastream:

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

Add Datastream:

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

    MetaData

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

    MetaData

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

    ' . $results_range_text . '

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

    Add Datastream:

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

    Add Datastream:

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

    MetaData

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

    MetaData

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

    ' . $results_range_text . '

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

    ', ); - + $form['fedora_soap_manage_url'] = array( '#type' => 'textfield', '#title' => t('Fedora SOAP management URL'), @@ -241,7 +251,7 @@ class formClass { '#required' => TRUE, '#weight' => -10 ); - + // will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php if (variable_get('allow_open_namespace', TRUE)) { $form['fedora_namespace'] = array( @@ -286,6 +296,7 @@ class formClass { '#collapsible' => TRUE, '#collapsed' => TRUE, ); + //when checked show object details tab $form['tabs']['fedora_repository_show_object_details_tab'] = array( '#type' => 'checkbox', @@ -293,7 +304,29 @@ class formClass { '#default_value' => variable_get('fedora_repository_show_object_details_tab', TRUE), '#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"), ); - + + // ***** Jason: begin object details display profiles + module_load_include('inc', 'fedora_repository', 'ObjectDetails'); + $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); + $profiles = module_invoke_all("islandora_object_details_display"); + + $display_options = array(); + foreach ($profiles as $machine_name => $profile) { + $display_options[$machine_name] = $profile['name']; + $config_path = $profile['config']; + if (isset($config_path) && $config_path != ""){ + $display_options[$machine_name] .= " (". l("config", $config_path, array()) .")"; + } + } + $form['tabs']['islandora_object_details_display_table'] = array( + '#type' => 'radios', + '#title' => t('Show object details as'), + '#options' => $display_options, + '#default_value' => $primary_display_mode, +// '#description' => t("Tells Islandora how to display the object details page for each object"), + ); + // ***** Jason: end object details display profiles + $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced configuration options'), From a88fee9fa9b1ae78cb371872b3e720e08a1ce4b9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:36:56 -0300 Subject: [PATCH 58/74] added core object details code --- ObjectDetails.inc | 151 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 ObjectDetails.inc diff --git a/ObjectDetails.inc b/ObjectDetails.inc new file mode 100644 index 00000000..76b11590 --- /dev/null +++ b/ObjectDetails.inc @@ -0,0 +1,151 @@ + array( + "name" => "Hidden", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_hidden", + "description" => t("No object details page"), + ), + 'xslt' => array( + "name" => "XSLT", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_xslt", + "description" => t("Show a datastream with an XSLT"), + "config" => "admin/settings/fedora_repository/object_details_xslt", + ), + 'table' => array( + "name" => "Table", + "module" => "fedora_repository", + "file" => "ObjectDetails.inc", + "function" => "fedora_repository_object_details_table", + "description" => t("Show a datastream with a table"), + ) + ); + return $profiles; +} + +function fedora_repository_object_details_hidden($item) { + // do nothing + return ""; +} + +function fedora_repository_object_details_XSLT($item) { + global $base_url; + $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); + + $dsid = variable_get('islandora_object_details_xslt_datastream', 'DC'); + // special case for DC+QDC + if ($dsid == 'DC' || $dsid == 'QDC') { + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + } + $xmlstr = $item->get_datastream_dissemination($dsid); + + if (empty($xmlstr)) { + return ''; + } + + try { + $proc = new XsltProcessor(); + } catch (Exception $e) { + drupal_set_message($e->getMessage(), 'error'); + return; + } + + $proc->setParameter('', 'baseUrl', $base_url); + $proc->setParameter('', 'path', $base_url . '/' . $path); + $input = NULL; + $xsl = new DomDocument(); + try { + $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); + $input = new DomDocument(); + $input->loadXML(trim($xmlstr)); + } catch (Exception $e) { + watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + } + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); + return $output; +} + +function fedora_repository_object_details_table($item) { + global $base_url; + $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); + + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + $xmlstr = $item->get_datastream_dissemination($dsid); + + if (empty($xmlstr)) { + return ''; + } + + $simplexml = new SimpleXMLElement($xmlstr); + + $headers = array( + array( + 'data' => t('Metadata'), + 'colspan' => 2, + ), + ); + $rows = array(); + foreach ($simplexml->getNamespaces(TRUE) as $ns) { + foreach ($simplexml->children($ns) as $child) { + $rows[] = array( + array( + 'data' => $child->getName(), + 'class' => 'dc-tag-name', + ), + array( + 'data' => (string)$child, + 'class' => 'dc-content', + ), + ); + } + } + + return theme('table', $headers, $rows, array('class' => 'dc-table')); +} + +// configuration pages +function fedora_repository_object_details_XSLT_config() { + $form = array(); + $form['config'] = array( + '#type' => 'fieldset', + '#title' => t("XSLT Options"), + ); + + $form['config']['warning'] = array( + '#value' => 'Note: the elements here do not currently work', + '#weight' => 0, + ); + $form['config']['xslt'] = array( + '#type' => 'textfield', + '#title' => t("XSL transform to use"), + '#default_value' => variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'), + '#required' => TRUE, + ); + $form['config']['dsid'] = array( + '#type' => 'textfield', + '#title' => t("Datastream to transform"), + '#default_value' => variable_get('islandora_object_details_xslt_datastream', 'DC'), + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t("Submit"), + '#weight' => 1, + ); + + return $form; +} + +function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { + variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); + variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); +} From c05e3dab32dfd230c15099c8a5e148258c3d6530 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 11 May 2012 16:39:56 -0300 Subject: [PATCH 59/74] add the mod2html stylesheet for testing transforms --- xsl/mods2html.xsl | 207 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 xsl/mods2html.xsl diff --git a/xsl/mods2html.xsl b/xsl/mods2html.xsl new file mode 100644 index 00000000..194fcec2 --- /dev/null +++ b/xsl/mods2html.xsl @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + ( + + + + + + + Edition + ) + + + + ="", + + + + + () + + + From 55a355ffcea99118702669e0a63d3760ea27fef9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 09:42:10 -0300 Subject: [PATCH 60/74] removed 'jason' code guards --- formClass.inc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/formClass.inc b/formClass.inc index 4d899ef1..52cef748 100644 --- a/formClass.inc +++ b/formClass.inc @@ -179,7 +179,6 @@ class formClass { 'access arguments' => array('view fedora collection'), ); - // ***** Jason: begin menu path for xslt config page $items['admin/settings/fedora_repository/object_details_xslt'] = array( 'title' => "", 'type' => MENU_CALLBACK, @@ -188,7 +187,7 @@ class formClass { 'file' => 'ObjectDetails.inc', 'access arguments' => array('administer site configuration'), ); - // ***** Jason: end menu path for xslt config page + return $items; } @@ -305,7 +304,6 @@ class formClass { '#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"), ); - // ***** Jason: begin object details display profiles module_load_include('inc', 'fedora_repository', 'ObjectDetails'); $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); $profiles = module_invoke_all("islandora_object_details_display"); @@ -325,7 +323,6 @@ class formClass { '#default_value' => $primary_display_mode, // '#description' => t("Tells Islandora how to display the object details page for each object"), ); - // ***** Jason: end object details display profiles $form['advanced'] = array( '#type' => 'fieldset', From a0891d6111491d6136af5e64d7ac176dd0964307 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 09:42:59 -0300 Subject: [PATCH 61/74] remove 'jason' code guards --- plugins/FedoraObjectDetailedContent.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index a6656571..1940d41f 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -49,7 +49,6 @@ class FedoraObjectDetailedContent { '#type' => 'tabset', ); - // ***** Jason: begin object details display profiles module_load_include('inc', 'fedora_repository', 'ObjectDetails'); $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt_dc'); $profiles = module_invoke_all("islandora_object_details_display"); @@ -70,7 +69,6 @@ class FedoraObjectDetailedContent { // problem } } - // ***** Jason: end object details display profiles $i = 0; if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) { From 672179a133ff7ae765d526bea6ee3683b62cdc34 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:32:38 -0300 Subject: [PATCH 62/74] remove an erroneous text widget (from development) and completed the table display mode (with configuration) --- ObjectDetails.inc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 76b11590..5da6a063 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -23,6 +23,7 @@ function fedora_repository_islandora_object_details_display() { "file" => "ObjectDetails.inc", "function" => "fedora_repository_object_details_table", "description" => t("Show a datastream with a table"), + "config" => "admin/settings/fedora_repository/object_details_table", ) ); return $profiles; @@ -39,7 +40,7 @@ function fedora_repository_object_details_XSLT($item) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); $dsid = variable_get('islandora_object_details_xslt_datastream', 'DC'); - // special case for DC+QDC + // special case for DC+QDC for backward compatibility if ($dsid == 'DC' || $dsid == 'QDC') { $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; } @@ -53,6 +54,7 @@ function fedora_repository_object_details_XSLT($item) { $proc = new XsltProcessor(); } catch (Exception $e) { drupal_set_message($e->getMessage(), 'error'); + watchdog('fedora_repository', "Error while creating XSLT processor: @e", array('@e' => $e->getMessage()), WATCHDOG_ERROR); return; } @@ -78,7 +80,11 @@ function fedora_repository_object_details_table($item) { $path = drupal_get_path('module', 'fedora_repository'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); - $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + $dsid = variable_get('islandora_object_details_table_datastream', 'DC'); + // special case for DC+QDC for backward compatibility + if ($dsid == 'DC' || $dsid == 'QDC') { + $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC'; + } $xmlstr = $item->get_datastream_dissemination($dsid); if (empty($xmlstr)) { @@ -117,13 +123,9 @@ function fedora_repository_object_details_XSLT_config() { $form = array(); $form['config'] = array( '#type' => 'fieldset', - '#title' => t("XSLT Options"), + '#title' => t("XSLT display options"), ); - $form['config']['warning'] = array( - '#value' => 'Note: the elements here do not currently work', - '#weight' => 0, - ); $form['config']['xslt'] = array( '#type' => 'textfield', '#title' => t("XSL transform to use"), @@ -145,7 +147,33 @@ function fedora_repository_object_details_XSLT_config() { return $form; } +function fedora_repository_object_details_table_config() { + $form = array(); + $form['config'] = array( + '#type' => 'fieldset', + '#title' => t("Table display options"), + ); + + $form['config']['dsid'] = array( + '#type' => 'textfield', + '#title' => t("Datastream to transform"), + '#default_value' => variable_get('islandora_object_details_table_datastream', 'DC'), + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t("Submit"), + '#weight' => 1, + ); + + return $form; +} + function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); } + +function fedora_repository_object_details_table_config_submit($form, &$form_state) { + variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); +} From 2e427bb4d10ad6cd83a292f69f73cc4cc75c13d9 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:33:11 -0300 Subject: [PATCH 63/74] moved alert message to watchdog and fixed an incorrect default value --- plugins/FedoraObjectDetailedContent.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 1940d41f..4eeef78b 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -50,12 +50,12 @@ class FedoraObjectDetailedContent { ); module_load_include('inc', 'fedora_repository', 'ObjectDetails'); - $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt_dc'); + $object_details_profile = variable_get('islandora_object_details_display_table', 'xslt'); $profiles = module_invoke_all("islandora_object_details_display"); $profile = $profiles[$object_details_profile]; if (!isset($profile)) { // default behaviour - drupal_set_message(t("There was an error reading the default object details display profile"), "error"); + watchdog('fedora_repository', "Error while reading the default object details display profile: @e", array("@e" => $e->getMessage()), WATCHDOG_WARNING); $dc_html = $objectHelper->getFormattedDC($this->item); } else { From 1fcdfbd83682047edbb1123c88362c72479254d0 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Mon, 14 May 2012 12:34:00 -0300 Subject: [PATCH 64/74] added menu hook so table config works, fixed an incorrect default value, added description to radiogroup --- formClass.inc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/formClass.inc b/formClass.inc index 52cef748..97f46c43 100644 --- a/formClass.inc +++ b/formClass.inc @@ -187,6 +187,14 @@ class formClass { 'file' => 'ObjectDetails.inc', 'access arguments' => array('administer site configuration'), ); + $items['admin/settings/fedora_repository/object_details_table'] = array( + 'title' => "", + 'type' => MENU_CALLBACK, + 'page callback' => 'drupal_get_form', + 'page arguments' => array('fedora_repository_object_details_table_config'), + 'file' => 'ObjectDetails.inc', + 'access arguments' => array('administer site configuration'), + ); return $items; } @@ -291,7 +299,7 @@ class formClass { $form['tabs'] = array( '#type' => 'fieldset', '#title' => t('Tabs Configuration'), - '#description' => t('Configure the tabs avaialble when viewing Fedora objects.'), + '#description' => t('Configure the tabs available when viewing Fedora objects.'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); @@ -305,7 +313,7 @@ class formClass { ); module_load_include('inc', 'fedora_repository', 'ObjectDetails'); - $primary_display_mode = variable_get('islandora_object_details_display_table', 'convertQDC'); + $primary_display_mode = variable_get('islandora_object_details_display_table', 'xslt'); $profiles = module_invoke_all("islandora_object_details_display"); $display_options = array(); @@ -321,7 +329,7 @@ class formClass { '#title' => t('Show object details as'), '#options' => $display_options, '#default_value' => $primary_display_mode, -// '#description' => t("Tells Islandora how to display the object details page for each object"), + '#description' => t("Tells Islandora how to display the object details page for each object"), ); $form['advanced'] = array( From 48c63fad766f05e1f5eadcb4f5bd7b6b3b321e6a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 14 May 2012 17:11:53 -0300 Subject: [PATCH 65/74] Simplify logic in get datastream list and allow multiple pids to be obtained. --- api/fedora_item.inc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index bc378471..5305cae1 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -637,18 +637,15 @@ RDF; // datastream, instead of returning it as an array, only // the single item will be returned directly. We have to // check for this. - if (count($this->datastreams_list->datastreamDef) > 1) { - foreach ($this->datastreams_list->datastreamDef as $ds) { - if (!is_object($ds)) { - print_r($ds); - } - $ds_list[$ds->ID]['label'] = $ds->label; - $ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType; - $ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label); - } + $xml_list = $this->datastreams_list->datastreamDef; + if (!is_array($this->datastreams_list->datastreamDef)) { + $xml_list = array($xml_list); } - else { - $ds = $this->datastreams_list->datastreamDef; + + foreach ($xml_list as $ds) { + if (!is_object($ds)) { + print_r($ds); + } $ds_list[$ds->ID]['label'] = $ds->label; $ds_list[$ds->ID]['MIMEType'] = $ds->MIMEType; $ds_list[$ds->ID]['URL'] = $this->url() . '/' . $ds->ID . '/' . drupal_urlencode($ds->label); @@ -852,7 +849,7 @@ RDF; * @param $pid_namespace string * @return string */ - static function get_next_PID_in_namespace($pid_namespace = '') { + static function get_next_PID_in_namespace($pid_namespace = '', $number_of_pids = 1) { if (empty($pid_namespace)) { // Just get the first one in the config settings. $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); @@ -866,11 +863,12 @@ RDF; } $params = array( - 'numPIDs' => '', + 'numPIDs' => $number_of_pids, 'pidNamespace' => $pid_namespace, ); $result = self::soap_call('getNextPID', $params); + return $result->pid; } @@ -1147,6 +1145,7 @@ RDF; $pid = self::get_next_PID_in_namespace(); } if (empty($owner)) { + global $user; if (!empty($user->uid)) { // Default to current Drupal user. $owner = $user->uid; } From 7b5d3cbee90f0031b2771bdf0e695cc06f137fd7 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 10:02:13 -0300 Subject: [PATCH 66/74] Fix move_to_trash function. --- api/fedora_item.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 5305cae1..3a4a134a 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -771,9 +771,9 @@ RDF; /** * Set the object to a deleted state */ - function move_to_trash($log_message = 'Flagged deleted using Islandora API.') { + function move_to_trash($log_message = 'Flagged deleted using Islandora API.', $quiet = TRUE) { // Loop through the datastreams and mark them deleted - foreach ($this->get_datastreams_list_as_array() as $dsid) { + foreach ($this->get_datastreams_list_as_array() as $dsid => $info) { $this->set_datastream_state($dsid, 'D'); } @@ -781,7 +781,7 @@ RDF; $params = array( 'pid' => $this->pid, 'state' => 'D', - 'logMessage' => $logMessage, + 'logMessage' => $log_message, 'label' => $this->objectProfile->objLabel, 'ownerId' => null, ); From 582d735f07c8f1d416dcc23089707f676d043941 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 14:34:53 -0300 Subject: [PATCH 67/74] Minor cleanup. --- fedora_repository.module | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 8642de9c..351ad359 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -986,18 +986,18 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { } } - // Add a 'manage object' tab for all objects, where detailed list of content is shown. - // XXX: Perhaps this should be extracted into its own object? - module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); - $obj = new FedoraObjectDetailedContent($pid); - //can disable showing the object details tab in admin UI - if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { + // Add a 'manage object' tab for all objects, where detailed list of content is shown. + // XXX: Perhaps this should be extracted into its own object? + module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent'); + $obj = new FedoraObjectDetailedContent($pid); + $object_details = $obj->showFieldSets(); - $cmodel_tabs = array_merge($cmodels_tabs, $object_details); + $cmodels_tabs = array_merge($cmodels_tabs, $object_details); } - return array_merge($cmodels_tabs, $object_details); + return $cmodels_tabs; } /** From be55312b3efbc8cdc4994549b9a2f14547876f00 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 17 May 2012 14:52:44 -0300 Subject: [PATCH 68/74] Clean up renderCollection function. --- CollectionClass.inc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 5e6d3bbd..598250bd 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -763,17 +763,8 @@ class CollectionClass { function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) { $path = drupal_get_path('module', 'fedora_repository'); global $base_url; - $collection_pid = $pid; //we will be changing the pid later maybe - $parsedContent = NULL; - if(!isset($this->collectionObject)){ - $this->collectionObject = new ObjectHelper($pid); - } + $contentModels = $this->collectionObject->get_content_models_list($pid); - $isCollection = FALSE; - //if this is a collection object store the $pid in the session as it will come in handy - //after a purge or ingest to return to the correct collection. - - $fedoraItem = NULL; if (empty($collectionName)) { $collectionName = menu_get_active_title(); @@ -805,7 +796,7 @@ class CollectionClass { try { $proc = new XsltProcessor(); $options = array( //Could make this the return of a hook? - 'collectionPid' => $collection_pid, + 'collectionPid' => $pid, 'collectionTitle' => $collectionName, 'baseUrl' => $base_url, 'path' => "$base_url/$path", @@ -817,10 +808,7 @@ class CollectionClass { $proc->registerPHPFunctions(); $xsl = new DomDocument(); $xsl->loadXML($xslContent); - // php xsl does not seem to work with namespaces so removing it below - // I may have just been being stupid here - // $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content); - + $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($input); From 6370a12bb97e872c7885a85d72878fef74719adf Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:11:17 -0300 Subject: [PATCH 69/74] Fix breadcrumbs, so that an entry for the current object is not added. --- ObjectHelper.inc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 25dd8c53..465487ef 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1047,9 +1047,9 @@ PREFIX rels-ext: SELECT ?parentObject ?title ?content FROM <#ri> WHERE { - ?this fedora-model:label ?title ; - ?relationship ?parentObject . - ?parentObject fedora-model:state fedora-model:Active ; + ?this ?relationship ?parentObject . + ?parentObject fedora-model:label ?title ; + fedora-model:state fedora-model:Active ; fedora-model:hasModel ?content . FILTER( sameTerm(?this, ) && @@ -1068,16 +1068,18 @@ EOQ; $next_pid = NULL; if (count($results) > 0 && $level > 0) { - $parent = $results[0]['parentObject']; - $this_title = $results[0]['title']; + $parent_pid = $results[0]['parentObject']; + $parent_title = $results[0]['title']; if (empty($this_title)) { $this_title = t('Unlabeled Object'); } - $breadcrumbs[] = l($this_title, "fedora/repository/$pid"); + if ($parent_pid != $root) { + $breadcrumbs[] = l($parent_title, "fedora/repository/$parent_pid"); + } - $next_pid = $parent; + $next_pid = $parent_pid; } else { watchdog('fedora_repository', 'Error generating breadcrumbs for %pid. Verify there exists relationships back up to %root. (May also be due to a hierarchy deeper than %max_depth).', array('%pid' => $pid, '%root' => $root, '%max_depth' => $max_level), WATCHDOG_WARNING); @@ -1138,6 +1140,18 @@ EOQ; if (!empty($attrs['uri'])) { $val = self::pidUriToBarePid((string)$attrs['uri']); } + elseif(!empty($attrs['datatype'])) { + $dt = (string)$attrs['datatype']; + $val = (string)$element; //Default to a string... + if ($dt == 'http://www.w3.org/2001/XMLSchema#int') { + $val = intval($val); + } + else { + watchdog('fedora_repository', 'Datatype @dt_uri handled as string.', array( + '@dt_uri' => $dt, + ), WATCHDOG_DEBUG); + } + } else { $val = (string)$element; } From 94c73ff625d2d420b69d5f4b51283ce9c7d6f0c8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:11:54 -0300 Subject: [PATCH 70/74] Suppress warnings for XSLTs that do not exist for Object Details tab. --- ObjectDetails.inc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 5da6a063..96349868 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -61,18 +61,23 @@ function fedora_repository_object_details_XSLT($item) { $proc->setParameter('', 'baseUrl', $base_url); $proc->setParameter('', 'path', $base_url . '/' . $path); $input = NULL; - $xsl = new DomDocument(); - try { - $xsl->load('./'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl')); - $input = new DomDocument(); + + $xsl_file = './'. $path .'/'. variable_get('islandora_object_details_xslt_sheet', 'xsl/convertQDC.xsl'); + if (is_readable($xsl_file)) { + $xsl = new DOMDocument(); + $xsl->load($xsl_file); + $input = new DOMDocument(); $input->loadXML(trim($xmlstr)); - } catch (Exception $e) { - watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR); + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $output = $newdom->saveHTML(); + return $output; + } + else { + watchdog('fedora_repository', 'The XSLT file @xslt_name is not readable.', array( + '@xslt_name' => $xsl_file, + )); } - $xsl = $proc->importStylesheet($xsl); - $newdom = $proc->transformToDoc($input); - $output = $newdom->saveHTML(); - return $output; } function fedora_repository_object_details_table($item) { From d2474b91121e9083395e71a95191a12e94b344d8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:12:43 -0300 Subject: [PATCH 71/74] Set the title. --- fedora_repository.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fedora_repository.module b/fedora_repository.module index 351ad359..56790fbc 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1107,6 +1107,8 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU $breadcrumbs = array(); $objectHelper->getBreadcrumbs($pid, $breadcrumbs); drupal_set_breadcrumb(array_reverse($breadcrumbs)); + + drupal_set_title(truncate_utf8($item->objectProfile->objLabel, 56, TRUE, TRUE)); $content_models = $objectHelper->get_content_models_list($pid); From c636034d955d8cf998fb2a45dc47f3e830eaedbd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:13:11 -0300 Subject: [PATCH 72/74] Improve relationship management. Can now use some basic typing (int, string) for RDF literals. --- api/fedora_item.inc | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 21585135..38dd4195 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -10,6 +10,12 @@ define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#'); define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#'); define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#"); +define("RELS_TYPE_URI", 0); +define("RELS_TYPE_PLAIN_LITERAL", 1); +define("RELS_TYPE_STRING", 2); +define("RELS_TYPE_INT", 3); +define("RELS_TYPE_DATETIME", 4); + /** * Fedora Item Class */ @@ -230,12 +236,17 @@ class Fedora_Item { * The object to be related to. * @param string $namespaceURI * The predicate namespace. - * @param boolean $literal_value - * Whether or not the object should be added as a URI (FALSE) or a literal (TRUE). + * @param int $literal_value + * Used to type the value. + * - 0: URI + * - 1: plain literal + * - 2: string (explicitly typed) + * - 3: integer + * - 4: dateTime * @return ??? * Value returned from SOAP call for modify_datastream. */ - function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = FALSE) { + function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) { //dd($this, 'The Fedora_Item'); $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; @@ -251,7 +262,7 @@ RDF; $relsext = $this->get_datastream_dissemination('RELS-EXT'); - if (!$literal_value && strpos($object, $f_prefix) !== 0) { + if ($literal_value == REL_TYPE_URI && strpos($object, $f_prefix) !== 0) { $object = $f_prefix . $object; } @@ -271,8 +282,20 @@ RDF; // Create the new relationship node. $newrel = $relsextxml->createElementNS($namespaceURI, $relationship); - if ($literal_value) { + if ($literal_value > 0) { $newrel->appendChild($relsextxml->createTextNode($object)); + if ($literal_value == RELS_TYPE_STRING) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#string'); + } + elseif ($literal_value == RELS_TYPE_INT) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#int'); + } + elseif ($literal_value == RELS_TYPE_DATETIME) { + $newrel->setAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#dateTime'); + } + else { + //plain literal. + } } else { $newrel->setAttribute('rdf:resource', $object); @@ -305,8 +328,8 @@ RDF; * The object to be related to. (NULL/value for which empty() evaluates to true will remove all relations of the given type, ignoring $literal_value) * @param string $namespaceURI * The predicate namespace. - * @param boolean $literal_value - * Whether or not the object should be looked for as a URI (FALSE) or a literal (TRUE). + * @param int $literal_value + * Same as add_relationship. NOTE: dateTime implemented. * @return boolean * Whether or not this operation has produced any changes in the RELS-EXT */ @@ -321,8 +344,10 @@ RDF; foreach ($rels as $rel) { if ( //If either no object is specified, or the object matches (in either the literal or URI case), remove this node from it's parent, and mark as changed. empty($object) || - (!$literal_value && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || - ($literal_value && $rel->textContent == $object)) { + (($literal_value == RELS_TYPE_URI) && $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) || + (($literal_value == RELS_TYPE_PLAIN_LITERAL) && $rel->textContent == $object) || + (($literal_value == RELS_TYPE_STRING) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#string' && $rel->textContent == $object) || + (($literal_value == RELS_TYPE_INT) && $rel->getAttribute('rdf:datatype') == 'http://www.w3.org/2001/XMLSchema#int' && intval($rel->textContent) == $object)) { $rel->parentNode->removeChild($rel); $modified = TRUE; } From b14ba233c26e697741665777b12d06291252b690 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 May 2012 10:17:10 -0300 Subject: [PATCH 73/74] Stop setting the title. --- plugins/FedoraObjectDetailedContent.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/FedoraObjectDetailedContent.inc b/plugins/FedoraObjectDetailedContent.inc index 4eeef78b..c193c588 100644 --- a/plugins/FedoraObjectDetailedContent.inc +++ b/plugins/FedoraObjectDetailedContent.inc @@ -32,7 +32,6 @@ class FedoraObjectDetailedContent { */ public function showFieldSets() { global $user; - drupal_set_title($this->item->objectProfile->objLabel); $objectHelper = new ObjectHelper(); $tabset = array(); $show_purge_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_purge_object_form'); From 694c4039fe937f5ce8474f086ceaa775a03f89d4 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 4 Jun 2012 20:29:53 +0200 Subject: [PATCH 74/74] Bit safer with labels and minor optimization. --- api/fedora_item.inc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 38dd4195..d9a1202d 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -165,7 +165,7 @@ class Fedora_Item { 'pid' => $this->pid, 'dsID' => $datastream_id, 'altIDs' => NULL, - 'dsLabel' => $datastream_label, + 'dsLabel' => truncate_utf8($datastream_label, 255, TRUE, TRUE), 'versionable' => TRUE, 'MIMEType' => $datastream_mimetype, 'formatURI' => NULL, @@ -247,7 +247,11 @@ class Fedora_Item { * Value returned from SOAP call for modify_datastream. */ function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) { - //dd($this, 'The Fedora_Item'); + static $relsextxml = NULL; + if ($relsextxml === NULL) { + $relsextxml = new DOMDocument(); //Avoid new instantiations in long-running processes + } + $ds_list = $this->get_datastreams_list_as_array(); $f_prefix = 'info:fedora/'; if (!array_key_exists('RELS-EXT', $ds_list)) { @@ -266,8 +270,6 @@ RDF; $object = $f_prefix . $object; } - $relsextxml = new DOMDocument(); - $relsextxml->loadXML($relsext); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); if ($description->length == 0) { @@ -911,7 +913,6 @@ RDF; 'logMessage' => 'Fedora Object Ingested' ); $object = self::soap_call('ingest', $params); - //dd($object, 'Soap return'); return new Fedora_Item($object->objectPID); } @@ -1195,7 +1196,7 @@ RDF; $label_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $label_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#label"); - $label_property->setAttribute("VALUE", $label); + $label_property->setAttribute("VALUE", truncate_utf8($label, 255, TRUE, TRUE)); $owner_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property"); $owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId");