Browse Source

Merge pull request #152 from ruebot/6.x

6.x FITS integration
pull/161/merge
Jonathan Green 13 years ago
parent
commit
0d885f779a
  1. 20
      formClass.inc
  2. 96
      plugins/fits.inc

20
formClass.inc

@ -1,7 +1,5 @@
<?php
/**
* @file
* formClass class
@ -370,12 +368,28 @@ class formClass {
'#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE),
);
//FITS functionality
$form['advanced']['enable_fits'] = array(
'#type' => 'checkbox',
'#title' => t('Enable FITS support?'),
'#description' => t('Whether or not we should create a FITS datastream upon object ingest.'),
'#default_value' => variable_get('enable_fits', FALSE),
);
//FITS Path
$form['advanced']['fits_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to FITS executable'),
'#description' => t("Path to FITS program on your server. It must be accessible by Drupal (i.e. apache user)."),
'#default_value' => variable_get('fits_path','/usr/local/bin/fits.sh'),
);
//Export functionality
$form['advanced']['module']['export_area'] = array(
'#type' => 'textfield',
'#title' => t('Export area'),
'#default_value' => variable_get('export_area', file_directory_path() . '/fedora_export_area'),
'#description' => t("Path to the export area. It must be accessible by druapl (i.e. apache user)."),
'#description' => t("Path to the export area. It must be accessible by drupal (i.e. apache user)."),
'#required' => TRUE,
);

96
plugins/fits.inc

@ -0,0 +1,96 @@
<?php
/**
* @file
* Fits
* fits.sh must be in the apache user's path
*
* Download FITS from http://code.google.com/p/fits/
* Installing: http://code.google.com/p/fits/wiki/installing
* Edit line 5 in fits.sh (FITS_HOME='') and give it a home.
* Make sure that home is in the apache user's path.
*
*/
/**
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/
class fits {
private $pid = NULL;
private $item = NULL;
/**
* Constructor
* @param type $pid
*/
function __construct($pid = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!empty($pid)) {
$this->pid = $pid;
$this->item = new Fedora_Item($this->pid);
}
}
/**
* extract metadata
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function extractFits($parameterArray, $dsid, $file, $file_ext) {
if (variable_get('enable_fits', FALSE) == 1) {
$file_name = '_' . $dsid . '.xml';
$output = array();
exec(variable_get('fits_path', '/usr/local/bin/fits.sh') .' -i ' . escapeshellarg($file) . '', $output);
if ( !file_put_contents($file . $file_name, implode("\n", $output)) ) {
//drupal_set_message(t("error writing fits file %s", array('%s' => "$file.$file_name")));
return FALSE;
}
$_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_name;
return TRUE;
}
return TRUE; //this prevents getting the error following content model rules message when fits generation is turned off
}
/**
* display metadata
* @return type
*/
function displayFits() {
$output = '';
$fits = $this->item->get_datastream_dissemination('TECHMD_FITS');
if (trim($fits) != '') {
$fitsDom = DOMDocument::loadXML($this->item->get_datastream_dissemination('FITS'));
if ($fitsDom != NULL) {
$description = $fitsDom->getElementsByTagName('fits');
if ($description->length > 0) {
$description = $description->item(0);
$output .= '<div class="fedora_technical_metadata"><ul>';
for ($i = 0; $i < $description->childNodes->length; $i++) {
$name = $description->childNodes->item($i)->nodeName;
$value = $description->childNodes->item($i)->nodeValue;
if ($name != '#text' && !preg_match('/^System\:.*$/', $name) && trim($value) != '') {
list($type, $name) = preg_split('/\:/', $name);
$name = trim(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])/', " $1", $name));
$output .= '<li><b>' . $name . '</b>: ' . $value . ' </li>';
}
}
$output .= '</ul></div>';
$fieldset = array(
'#title' => t("!text", array('!text' => 'FITS Technical Metadata')),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output
);
$output = theme('fieldset', $fieldset);
}
}
}
return $output;
}
}
Loading…
Cancel
Save