@ -2,8 +2,7 @@
/**
* Drupal hook for admin form
* fedora_repository_name is the name of the top level collection this module will query
* fedora_repository_pid is the name of the top level pid.
*
* Stores this info in the drupal variables table.
* the name and pid can also be passed as url parameters
*/
@ -146,14 +145,13 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
$form_state['submitted'] = FALSE;
return;
}
if ($form_state['storage']['xml']) {
if (module_exists('islandora_content_model_forms')) {
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
$xml_form = new IngestObjectMetadataForm();
$xml_form->submit($form, $form_state);
}
//ddebug_backtrace();
if ($form_state['storage']['xml'] && module_exists('islandora_content_model_forms')) {
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
$xml_form = new IngestObjectMetadataForm();
$xml_form->submit($form, $form_state);
}
elseif ($form_state['clicked_button']['#id'] == 'edit-submit' ) {
elseif (strpos( $form_state['clicked_button']['#id'], 'edit-submit') === 0 ) {
global $base_url;
module_load_include('inc', 'fedora_repository', 'CollectionClass');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
@ -188,7 +186,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
}
if ($redirect) {
$form_state['redirect'] = ($err) ? ' ' : $base_url . "/ fedora/repository/{$form_state['values']['collection_pid']}";
$form_state['redirect'] = ($err) ? ' ' : url(" fedora/repository/{$form_state['values']['collection_pid']}") ;
}
}
}
@ -205,7 +203,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
$form_state['submitted'] = FALSE;
return;
}
if ($form_state['clicked_button']['#id'] == 'edit-submit' && $form_state['ahah_submission'] != 1) {
if (strpos( $form_state['clicked_button']['#id'], 'edit-submit') === 0 && $form_state['ahah_submission'] != 1) {
switch ($form_state['storage']['step']) {
case 1:
$form_state['storage']['step']++;
@ -286,7 +284,8 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio
$ingestForm = new formClass();
$form_state['storage']['content_model'] = $content_model;
$form_state['storage']['collection_pid'] = $collection_pid;
return $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state);
$form = $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state);
return $form;
}
/**
@ -378,41 +377,30 @@ 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);
$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.;
/* -----------------------------------------------------------------
* 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['storage']['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;
}
unset($form_state['storage']); //Using storage; need to unset it for forms to work properly...
$form_state['rebuild'] = TRUE;
}
@ -435,6 +423,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;
@ -445,15 +434,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) )));
else if (!(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) {
else if (strlen($dsLabel) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
}
if (strpos($dsLabel, '/')) {
else if (strpos($dsLabel, '/') !== FALSE ) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
}
@ -462,13 +451,36 @@ function add_stream_form_validate($form, &$form_state) {
// 'file_validate_image_resolution' => array('85x85'),
// '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.
$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)))) {
// Move the uploaded file to Drupal's files directory.
$file_path = $fileObject->filepath;
file_move($file_path, 0, FILE_EXISTS_RENAME);
$form_state['values']['add-stream-file-location'] = $file_path;
$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'];
}
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;
}
@ -605,7 +617,44 @@ 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(
'#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;
}
/**
@ -635,7 +684,7 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectio
* @return type
*/
function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) {
module_load_include('inc', 'Fedora_R epository', 'formClass');
module_load_include('inc', 'fedora_r epository', 'formClass');
$replaceDataStreamForm = new formClass();
return $replaceDataStreamForm->createReplaceDataStreamForm($pid, $dsId, $dsLabel, $form_state);
}
@ -647,29 +696,37 @@ 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;
}
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
$doc = new DOMDocument();
module_load_include('inc', 'Fedora_Repository', 'MimeClass');
module_load_include('inc', 'fedora_r epository', 'MimeClass');
$mime = new MimeClass();
if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) {
form_set_error('file', 'Invalid XML format.');
$mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath);
if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) {
form_set_error('file', 'Invalid XML format. (XML could not be parsed)');
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;
}
elseif (!$form_state['values']['ds_reference']) {
form_set_error('', 'Need either a file or a reference!');
}
}
/**
@ -679,46 +736,30 @@ 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'];
$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
$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.;
$streamUrl = ($file !== NULL) ?
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
// 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.
}
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);
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
$dformat = $form_state['storage']['mime_type'];
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');
}
} else {
drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error');
}
$item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
unset($form_state['storage']);
$form_state['redirect'] = 'fedora/repository/' . $pid;
}
@ -771,13 +812,6 @@ function fedora_repository_edit_qdc_form(&$form_state, $pid, $dsId = NULL) {
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
// Check if there is a custom edit metadata function defined in the content model.
$breadcrumbs = array();
$objectHelper = new ObjectHelper();
$objectHelper->getBreadcrumbs($pid, $breadcrumbs);
drupal_set_breadcrumb(array_reverse($breadcrumbs));
$output = '';
if (($cm = ContentModel::loadFromObject($pid)) !== FALSE) {
$output = $cm->buildEditMetadataForm($pid, $dsId);
@ -821,7 +855,7 @@ function fedora_repository_edit_qdc_form_validate($form, &$form_state) {
function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
if ($form_state['storage']['xml']) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
$xml_form = new EditObjectMetadataForm($form_state );
$xml_form = new EditObjectMetadataForm();
$xml_form->submit($form, $form_state);
}
else {
@ -877,7 +911,7 @@ function fedora_repository_perm() {
* @param type $account
* @return type
*/
function fedora_repository_access($op, $node, $account) {
function fedora_repository_access($op, $node = NULL , $account = NULL ) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper();
return $objectHelper->fedora_repository_access($op, $node, $account);
@ -920,17 +954,97 @@ function makeObject($pid, $dsID) {
}
/**
* 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.
* 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();
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,
);
}
}
//can disable showing the object details tab in admin UI
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();
$cmodels_tabs = array_merge($cmodels_tabs, $object_details);
}
return $cmodels_tabs;
}
/**
* 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;
}
}
}
}
/**
* 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');
@ -952,7 +1066,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
$pid = variable_get('fedora_repository_pid', 'islandora:root');
}
$item = new fedora_i tem($pid);
$item = new Fedora_I tem($pid);
if (!$item->exists()) {
drupal_not_found();
exit();
@ -991,62 +1105,38 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
return makeObject($pid, $dsId);
}
$content = '<div id="content-fedora">';
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));
drupal_set_title(truncate_utf8($item->objectProfile->objLabel, 56, TRUE, TRUE));
$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',
//Get the tabs from all modules...
$hook_tabs = module_invoke_all('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);
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,
);
}
}
$cmodels_tabs += $hook_tabs;
// Add a 'manage object' tab for all objects, where detailed list of content is shown.
$obj = new FedoraObjectDetailedContent($pid);
//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);
//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);
$cmodels_tabs = array_merge($cmodels_tabs, $object_details, $hook_tabs);
return tabs_render($cmodels_tabs);
}
/**
* fedora repository urlencode string
* FIXME: URL-encoding is not the same as HTML/XML encoding...
* @param type $str
* @return type
*/
@ -1066,7 +1156,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) {
@ -1075,7 +1164,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);
}
/**
@ -1722,7 +1811,7 @@ function fedora_repository_required_fedora_objects() {
'pid' => 'islandora:collectionCModel',
'label' => 'Islandora Collection Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/content_models/COLLECTIONCM.xml",
'datastream_file' => "./ $module_path/content_models/COLLECTIONCM.xml",
'dsversion' => 2,
'cmodel' => 'fedora-system:ContentModel-3.0',
),
@ -1733,11 +1822,11 @@ function fedora_repository_required_fedora_objects() {
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
'datastream_file' => "./ $module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
),
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Gnome-emblem-photos.png",
'datastream_file' => "./ $module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
),
@ -2117,19 +2206,19 @@ function theme_add_to_basket_link($pid, $type = 'object') {
$save = "export_big.png";
$saved = "exported_big.png";
// $path = drupal_get_path('module', 'Fedora_R epository').'/images/'.$save ;
// $path = drupal_get_path('module', 'fedora_r epository').'/images/'.$save ;
/*
var_dump($path);
var_dump(theme('image',drupal_get_path('module', 'Fedora_R epository').'/images/'.$save));
var_dump(theme('image',drupal_get_path('module', 'fedora_r epository').'/images/'.$save));
die();
*/
if (!_is_added_to_basket($pid)) {
return l(
theme('image', drupal_get_path('module', 'Fedora_R epository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE)
theme('image', drupal_get_path('module', 'fedora_r epository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE)
);
}
return theme('image', drupal_get_path('module', 'Fedora_R epository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object)));
return theme('image', drupal_get_path('module', 'fedora_r epository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object)));
}
/**
@ -2169,56 +2258,68 @@ function fedora_repository_batch_reingest_object($object, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
if (!empty($object) && is_array($object)) {
$pid = $object['pid'];
if (!valid_pid($pid)) {
return NULL;
}
// Does the object exist? If so, purge it.
// Does the object exist? If so, purge it.
//dd("About to test existence of PID: $pid");
$item = new Fedora_Item($pid);
if ($item->exists()) {
//dd(' Found');
$item->purge(t('Remove during re-install batch job'));
//dd(' Purged');
}
$new_item = NULL; //Need to have this a couple places... (After trying from FOXML and later for individual DSs)
$datastreams = array(); //Seems like this might be getting messed up due to scope?
// Ingest the object from the source file.
if (!empty($object['foxml_file'])) {
$foxml_file = $object['foxml_file'];
$new_item = Fedora_Item::ingest_from_FOXML_file($foxml_file);
if ($new_item->exists()) {
// Batch operation was successful.
$context['message'][] = "$new_item->pid installed." ;
// Batch operation was successful; can still add additional DSs, though
$context['message'][] = t('%pid installed.', array('%pid' => $new_item->pid)) ;
}
}
if (!empty($object['dsid']) && !empty($object['datastream_file'])) {
$datastreams = array(
array(
'dsid' => $object['dsid'],
'datastream_file' => $object['datastream_file'],
)
$datastreams[] = array(
'dsid' => $object['dsid'],
'datastream_file' => $object['datastream_file'],
);
}
elseif (!empty($object['datastreams'])) {
$datastreams = $object['datastreams'];
}
if (!empty($datastreams) && is_array($datastreams)) {
$label = !empty($object['label']) ? $object['label'] : '';
if (empty($object['foxml_file']) && !isset($new_item)) {
$new_item = Fedora_Item::ingest_new_item($object['pid'], 'A', $label);
}
$label = !empty($object['label']) ? $object['label'] : '';
if (!isset($new_item)) {
//dd(' Not found, creating');
$new_item = Fedora_Item::ingest_new_item($pid, 'A', $label);
//dd(' Created');
}
elseif (!empty($label)) {
$new_item->modify_object($label);
}
if (isset($new_item)) {
if (!empty($object['cmodel'])) {
//dd(' relating to cmodel');
$new_item->add_relationship('hasModel', $object['cmodel'], FEDORA_MODEL_URI);
//dd(' related to cmodel');
}
if (!empty($object['parent'])) {
//dd(' adding parent');
$new_item->add_relationship('isMemberOfCollection', $object['parent']);
//dd(' parent added');
}
foreach ($datastreams as $ds) {
foreach ((array)$datastreams as $ds) {
//dd("trying to add ds: {$ds['dsid']}");
if ($ds['dsid'] == 'DC') {
$new_item->modify_datastream_by_value(file_get_contents($ds['datastream_file']), $ds['dsid'], $ds['label'], 'text/xml');
}
@ -2242,22 +2343,17 @@ function fedora_repository_batch_reingest_object($object, &$context) {
*/
function fedora_repository_get_islandora_datastream_version($item = NULL, $dsid = NULL, $datastream_file = NULL) {
$return = NULL;
if (isset($item )) {
if (!empty($item) && !empty($dsid )) {
$doc = simplexml_load_string($item->get_datastream_dissemination($dsid));
}
elseif (isset ($datastream_file)) {
elseif (!empty ($datastream_file)) {
$doc = simplexml_load_file($datastream_file);
}
if (!empty($doc)) {
$attrs = $doc->attributes();
foreach ($attrs as $name => $value) {
if ($name == 'version') {
$return = (int) $value;
break;
}
}
if (!empty($doc) && $version = (int)$doc->attributes()->version) {
$return = $version;
}
return $return;
}
@ -2273,9 +2369,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;
}
@ -2294,3 +2387,87 @@ function fedora_repository_forms($form_id) {
}
return $forms;
}
/**
* Implementation of hook_imagecache_default_presets().
*/
function fedora_repository_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,
),
),
),
),
);
}
/**
* 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) &&
imagecache_external_can_fetch($tn_path, TRUE)) {
$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);
}
/**
* 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);
}