Browse Source

Merge pull request #4 from bwoodhead/6.x

6.x
pull/5/merge
Ben Woodhead 14 years ago
parent
commit
65eed8f424
  1. 33
      api/dublin_core.inc
  2. 49
      api/fedora_collection.inc
  3. 56
      api/fedora_export.inc
  4. 168
      api/fedora_item.inc
  5. 68
      api/fedora_utils.inc
  6. 70
      api/rels-ext.inc
  7. 25
      api/tagging.inc
  8. 32
      plugins/CollectionFormBuilder.inc
  9. 26
      plugins/CreateCollection.inc
  10. 55
      plugins/DarwinCore.inc
  11. 32
      plugins/DemoFormBuilder.inc
  12. 26
      plugins/DocumentConverter.inc
  13. 93
      plugins/Exiftool.inc
  14. 33
      plugins/Ffmpeg.inc
  15. 105
      plugins/Flv.inc
  16. 24
      plugins/FlvFormBuilder.inc
  17. 165
      plugins/FormBuilder.inc
  18. 75
      plugins/ImageManipulation.inc
  19. 665
      plugins/ModsFormBuilder.inc
  20. 78
      plugins/PersonalCollectionClass.inc
  21. 143
      plugins/QtFormBuilder.php
  22. 146
      plugins/Refworks.inc
  23. 22
      plugins/ShowDemoStreamsInFieldSets.inc
  24. 103
      plugins/ShowStreamsInFieldSets.inc
  25. 23
      plugins/fedoraObject.inc
  26. 73
      plugins/herbarium.inc
  27. 29
      plugins/map_viewer.inc
  28. 140
      plugins/qt_viewer.inc
  29. 28
      plugins/slide_viewer.inc
  30. 42
      plugins/tagging_form.inc

33
api/dublin_core.inc

@ -1,13 +1,19 @@
<?php <?php
// $Id$ // $Id$
/* /**
* @file
* Implements a simple class for working with Dublin Core data and exporting it * Implements a simple class for working with Dublin Core data and exporting it
* back to XML. Inspiration and design shamelessly stolen from the pyfedora * back to XML. Inspiration and design shamelessly stolen from the pyfedora
* project at http://pypi.python.org/pypi/pyfedora/0.1.0 * project at http://pypi.python.org/pypi/pyfedora/0.1.0
*/ */
/**
* Dublin Core Class
*/
class Dublin_Core { class Dublin_Core {
public $dc = array( public $dc = array(
'dc:title' => array(), 'dc:title' => array(),
'dc:creator' => array(), 'dc:creator' => array(),
@ -41,21 +47,21 @@ class Dublin_Core {
} }
/** /**
* * Add Elements
* @param <type> $element_name * @param <type> $element_name
* @param <type> $value * @param <type> $value
*/ */
function add_element( $element_name, $value ) { function add_element($element_name, $value) {
if (is_string($value) && is_array($this->dc[$element_name])) { if (is_string($value) && is_array($this->dc[$element_name])) {
$this->dc[$element_name][] = $value; $this->dc[$element_name][] = $value;
} }
} }
/** /**
* Replace the given DC element with the values in $values * Replace the given DC element with the values in $values
* @param string $elemnt_name * @param string $elemnt_name
* @param array $values * @param array $values
*/ */
function set_element($element_name, $values) { function set_element($element_name, $values) {
if (is_array($values)) { if (is_array($values)) {
$this->dc[$element_name] = $values; $this->dc[$element_name] = $values;
@ -67,8 +73,10 @@ class Dublin_Core {
/** /**
* Serialize this object to XML and return it. * Serialize this object to XML and return it.
* @param type $with_preamble
* @return type
*/ */
function as_xml( $with_preamble = FALSE ) { function as_xml($with_preamble = FALSE) {
$dc_xml = new DomDocument(); $dc_xml = new DomDocument();
$oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc'); $oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc');
$oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
@ -88,10 +96,17 @@ class Dublin_Core {
return $dc_xml->saveXML(); return $dc_xml->saveXML();
} }
/**
* Create dc from dict ( does nothing )
*/
static function create_dc_from_dict() { static function create_dc_from_dict() {
} }
/**
* Save ??
* @param type $alt_owner
*/
function save($alt_owner = NULL) { function save($alt_owner = NULL) {
$item_to_update = (!empty($alt_owner) ? $alt_owner : $this->owner); $item_to_update = (!empty($alt_owner) ? $alt_owner : $this->owner);
// My Java roots showing, trying to do polymorphism in PHP. // My Java roots showing, trying to do polymorphism in PHP.

49
api/fedora_collection.inc

@ -1,10 +1,11 @@
<?php <?php
// $Id$ // $Id$
/* /**
* @file
* Operations that affect a Fedora repository at a collection level. * Operations that affect a Fedora repository at a collection level.
*/ */
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -13,9 +14,12 @@ module_load_include('module', 'fedora_repository');
/** /**
* Exports a fedora collection object and all of its children in a format * Exports a fedora collection object and all of its children in a format
* that will let you import them into another repository. * that will let you import them into another repository.
* @param <type> $format * @param type $collection_pid
* @param type $relationship
* @param type $format
* @return type
*/ */
function export_collection($collection_pid, $relationship = 'isMemberOfCollection', $format = 'info:fedora/fedora-system:FOXML-1.1' ) { function export_collection($collection_pid, $relationship = 'isMemberOfCollection', $format = 'info:fedora/fedora-system:FOXML-1.1') {
$collection_item = new Fedora_Item($collection_pid); $collection_item = new Fedora_Item($collection_pid);
$foxml = $collection_item->export_as_foxml(); $foxml = $collection_item->export_as_foxml();
@ -25,15 +29,15 @@ function export_collection($collection_pid, $relationship = 'isMemberOfCollectio
$container = tempnam($file_dir, 'export_'); $container = tempnam($file_dir, 'export_');
file_delete($container); file_delete($container);
print $container; print $container;
if (mkdir($container) && mkdir($container . '/'. $collection_pid)) { if (mkdir($container) && mkdir($container . '/' . $collection_pid)) {
$foxml_dir = $container . '/'. $collection_pid; $foxml_dir = $container . '/' . $collection_pid;
$file = fopen($foxml_dir . '/'. $collection_pid . '.xml', 'w'); $file = fopen($foxml_dir . '/' . $collection_pid . '.xml', 'w');
fwrite($file, $foxml); fwrite($file, $foxml);
fclose($file); fclose($file);
$member_pids = get_related_items_as_array($collection_pid, $relationship); $member_pids = get_related_items_as_array($collection_pid, $relationship);
foreach ($member_pids as $member) { foreach ($member_pids as $member) {
$file = fopen($foxml_dir . '/'. $member . '.xml', 'w'); $file = fopen($foxml_dir . '/' . $member . '.xml', 'w');
$item = new Fedora_Item($member); $item = new Fedora_Item($member);
$item_foxml = $item->export_as_foxml(); $item_foxml = $item->export_as_foxml();
fwrite($file, $item_foxml); fwrite($file, $item_foxml);
@ -41,13 +45,13 @@ function export_collection($collection_pid, $relationship = 'isMemberOfCollectio
} }
if (system("cd $container;zip -r $collection_pid.zip $collection_pid/* >/dev/NULL") == 0) { if (system("cd $container;zip -r $collection_pid.zip $collection_pid/* >/dev/NULL") == 0) {
header("Content-type: application/zip"); header("Content-type: application/zip");
header('Content-Disposition: attachment; filename="' . $collection_pid . '.zip'. '"'); header('Content-Disposition: attachment; filename="' . $collection_pid . '.zip' . '"');
$fh = fopen($container . '/'. $collection_pid . '.zip', 'r'); $fh = fopen($container . '/' . $collection_pid . '.zip', 'r');
$the_data = fread($fh, filesize($container . '/'. $collection_pid . '.zip')); $the_data = fread($fh, filesize($container . '/' . $collection_pid . '.zip'));
fclose($fh); fclose($fh);
echo $the_data; echo $the_data;
} }
if (file_exists($container . '/'. $collection_pid)) { if (file_exists($container . '/' . $collection_pid)) {
system("rm -rf $container"); // I'm sorry. system("rm -rf $container"); // I'm sorry.
} }
} }
@ -82,21 +86,21 @@ function get_related_items_as_xml($collection_pid, $relationship = array('isMemb
if (is_array($relationship)) { if (is_array($relationship)) {
foreach ($relationship as $rel) { foreach ($relationship as $rel) {
$query_string .= '$object <fedora-rels-ext:'. $rel . '> <info:fedora/'. $collection_pid . '>'; $query_string .= '$object <fedora-rels-ext:' . $rel . '> <info:fedora/' . $collection_pid . '>';
if (next($relationship)) { if (next($relationship)) {
$query_string .= ' OR '; $query_string .= ' OR ';
} }
} }
} }
elseif (is_string($relationship)) { elseif (is_string($relationship)) {
$query_string .= '$object <fedora-rels-ext:'. $relationship . '> <info:fedora/'. $collection_pid . '>'; $query_string .= '$object <fedora-rels-ext:' . $relationship . '> <info:fedora/' . $collection_pid . '>';
} }
else { else {
return ''; return '';
} }
$query_string .= ') '; $query_string .= ') ';
$query_string .= $active_objects_only ? 'and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>' : ''; $query_string .= $active_objects_only ? 'and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>' : '';
if ($cmodel) { if ($cmodel) {
$query_string .= ' and $content <mulgara:is> <info:fedora/' . $cmodel . '>'; $query_string .= ' and $content <mulgara:is> <info:fedora/' . $cmodel . '>';
@ -104,19 +108,30 @@ function get_related_items_as_xml($collection_pid, $relationship = array('isMemb
$query_string .= ') $query_string .= ')
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by '.$orderby; order by ' . $orderby;
$query_string = htmlentities(urlencode($query_string)); $query_string = htmlentities(urlencode($query_string));
$content = ''; $content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=". $query_string; $url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query_string;
$content .= do_curl($url); $content .= do_curl($url);
return $content; return $content;
} }
/**
* Get Related Items as Arrays
* @param type $collection_pid
* @param type $relationship
* @param type $limit
* @param type $offset
* @param type $active_objects_only
* @param type $cmodel
* @param type $orderby
* @return type
*/
function get_related_items_as_array($collection_pid, $relationship = 'isMemberOfCollection', $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { function get_related_items_as_array($collection_pid, $relationship = 'isMemberOfCollection', $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') {
$content = get_related_items_as_xml($collection_pid, $relationship, $limit, $offset, $active_objects_only, $cmodel, $orderby); $content = get_related_items_as_xml($collection_pid, $relationship, $limit, $offset, $active_objects_only, $cmodel, $orderby);
if (empty($content)) { if (empty($content)) {

56
api/fedora_export.inc

@ -2,6 +2,10 @@
// $Id$ // $Id$
/**
* @file
* Fedora Export
*/
define('FOXML_10', 'info:fedora/fedora-system:FOXML-1.0'); define('FOXML_10', 'info:fedora/fedora-system:FOXML-1.0');
define('FOXML_11', 'info:fedora/fedora-system:FOXML-1.1'); define('FOXML_11', 'info:fedora/fedora-system:FOXML-1.1');
define('METS_10', 'info:fedora/fedora-system:METSFedoraExt-1.0'); define('METS_10', 'info:fedora/fedora-system:METSFedoraExt-1.0');
@ -11,6 +15,11 @@ define('ATOMZip_11', 'info:fedora/fedora-system:ATOMZip-1.1');
/** /**
* Function to to export all objects assocoiated with a given pid to the export area * Function to to export all objects assocoiated with a given pid to the export area
* @param type $pid
* @param type $foxml_dir
* @param type $ob_dir
* @param type $log
* @return type
*/ */
function export_to_export_area($pid, $foxml_dir, $ob_dir, &$log = array()) { function export_to_export_area($pid, $foxml_dir, $ob_dir, &$log = array()) {
if (!$paths = export_objects_for_pid($pid, $ob_dir, $log)) { if (!$paths = export_objects_for_pid($pid, $ob_dir, $log)) {
@ -24,6 +33,13 @@ function export_to_export_area($pid, $foxml_dir, $ob_dir, &$log = array()) {
return TRUE; return TRUE;
} }
/**
* Export objects for pids ??
* @param type $pid
* @param type $dir
* @param type $log
* @return string
*/
function export_objects_for_pid($pid, $dir, &$log) { function export_objects_for_pid($pid, $dir, &$log) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
@ -38,7 +54,7 @@ function export_objects_for_pid($pid, $dir, &$log) {
$paths = array(); $paths = array();
foreach ($object->datastreamDef as $ds) { foreach ($object->datastreamDef as $ds) {
if (!in_array($ds->ID, $ignore_dsids)) { if (!in_array($ds->ID, $ignore_dsids)) {
$file = $dir .'/'. $ds->label .'.'. get_file_extension($ds->MIMEType); $file = $dir . '/' . $ds->label . '.' . get_file_extension($ds->MIMEType);
$paths[$ds->ID] = $file; $paths[$ds->ID] = $file;
//$content = $ob_helper->getDatastreamDissemination($pid, $ds->ID); //$content = $ob_helper->getDatastreamDissemination($pid, $ds->ID);
@ -58,6 +74,16 @@ function export_objects_for_pid($pid, $dir, &$log) {
return $paths; return $paths;
} }
/**
* Export foxml for pid
* @param type $pid
* @param type $dir
* @param type $paths
* @param type $log
* @param type $format
* @param type $remove_islandora
* @return type
*/
function export_foxml_for_pid($pid, $dir, $paths, &$log, $format = FOXML_11, $remove_islandora = FALSE) { function export_foxml_for_pid($pid, $dir, $paths, &$log, $format = FOXML_11, $remove_islandora = FALSE) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$ob_helper = new ObjectHelper(); $ob_helper = new ObjectHelper();
@ -136,29 +162,29 @@ function export_foxml_for_pid($pid, $dir, $paths, &$log, $format = FOXML_11, $re
foreach ($xpath->query('METS:file[@OWNERID!="E"][@OWNERID!="R"]/METS:FLocat[@xlink:href]', $dsNode) as $Floc) { foreach ($xpath->query('METS:file[@OWNERID!="E"][@OWNERID!="R"]/METS:FLocat[@xlink:href]', $dsNode) as $Floc) {
$Floc->setAttribute('xlink:href', url($paths[$dsId], array('absolute' => TRUE))); $Floc->setAttribute('xlink:href', url($paths[$dsId], array('absolute' => TRUE)));
} }
/* /*
foreach ($dsNode->getElementsByTagName('METS:file') as $contentNode) { foreach ($dsNode->getElementsByTagName('METS:file') as $contentNode) {
// Don't update datastreams having external uris // Don't update datastreams having external uris
if (in_array($dsNode->getAttribute('OWNERID'), $disallowed_groups)) { if (in_array($dsNode->getAttribute('OWNERID'), $disallowed_groups)) {
continue; continue;
} }
foreach ($xpath->('METS:FLocat[@xlink:href]', $contentNode) as $Floc) { foreach ($xpath->('METS:FLocat[@xlink:href]', $contentNode) as $Floc) {
$Floc->setAttribute('xlink:href', url($paths[$dsId], array('absolute' => true))); $Floc->setAttribute('xlink:href', url($paths[$dsId], array('absolute' => true)));
} }
`} `}
*/ */
} }
break; break;
default: default:
$log[] = log_line(t("Unknown or invalid format: ". $format), 'error'); $log[] = log_line(t("Unknown or invalid format: " . $format), 'error');
return FALSE; return FALSE;
} }
} //if $remove_islandora } //if $remove_islandora
$file = $dir .'/'. $pid .'.xml'; $file = $dir . '/' . $pid . '.xml';
if (!$foxml->save($file)) { if (!$foxml->save($file)) {
$log[] = log_line(t("Failed to write datastream %dsid for pid %pid to %file", array('%dsid' => $ds->ID, '%pid' => $pid, '%file' => $file)), 'error'); $log[] = log_line(t("Failed to write datastream %dsid for pid %pid to %file", array('%dsid' => $ds->ID, '%pid' => $pid, '%file' => $file)), 'error');
return FALSE; return FALSE;
@ -170,10 +196,22 @@ function export_foxml_for_pid($pid, $dir, $paths, &$log, $format = FOXML_11, $re
return TRUE; return TRUE;
} }
/**
* Get file extension
* @param type $mimeType
* @return type
*/
function get_file_extension($mimeType) { function get_file_extension($mimeType) {
return substr(strstr($mimeType, '/'), 1); return substr(strstr($mimeType, '/'), 1);
} }
/**
* Log line
* @param type $msg
* @param type $severity
* @param type $sep
* @return type
*/
function log_line($msg, $severity = 'info', $sep = "\t") { function log_line($msg, $severity = 'info', $sep = "\t") {
return date("Y-m-d H:i:s") . $sep . ucfirst($severity) . $sep . $msg; return date("Y-m-d H:i:s") . $sep . ucfirst($severity) . $sep . $msg;
} }

168
api/fedora_item.inc

@ -2,9 +2,16 @@
// $Id$ // $Id$
/**
* @file
* Fedora Item
*/
define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#'); define('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#');
define("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#'); define("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#');
/**
* Fedora Item Class
*/
class Fedora_Item { class Fedora_Item {
public $pid = NULL; // The $pid of the fedora object represented by an instance of this class. public $pid = NULL; // The $pid of the fedora object represented by an instance of this class.
@ -51,10 +58,24 @@ class Fedora_Item {
} }
} }
/**
* Exists
* @return type
*/
function exists() { function exists() {
return (!empty($this->objectProfile)); return (!empty($this->objectProfile));
} }
/**
* Add datastream from file
* @param type $datastream_file
* @param type $datastream_id
* @param type $datastream_label
* @param type $datastream_mimetype
* @param type $controlGroup
* @param type $logMessage
* @return type
*/
function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) { function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
if (empty($datastream_mimetype)) { if (empty($datastream_mimetype)) {
@ -76,6 +97,16 @@ class Fedora_Item {
return $return_value; return $return_value;
} }
/**
* Add datastream from url
* @param type $datastream_url
* @param type $datastream_id
* @param type $datastream_label
* @param type $datastream_mimetype
* @param type $controlGroup
* @param type $logMessage
* @return type
*/
function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) { function add_datastream_from_url($datastream_url, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = null) {
if (empty($datastream_label)) { if (empty($datastream_label)) {
$datastream_label = $datastream_id; $datastream_label = $datastream_id;
@ -98,10 +129,19 @@ class Fedora_Item {
); );
return $this->soap_call( 'addDataStream', $params ); return $this->soap_call('addDataStream', $params);
} }
/**
* Add datastream from string
* @param type $str
* @param type $datastream_id
* @param type $datastream_label
* @param type $datastream_mimetype
* @param type $controlGroup
* @param type $logMessage
* @return type
*/
function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = null) { function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M', $logMessage = null) {
$dir = sys_get_temp_dir(); $dir = sys_get_temp_dir();
$tmpfilename = tempnam($dir, 'fedoratmp'); $tmpfilename = tempnam($dir, 'fedoratmp');
@ -116,8 +156,9 @@ class Fedora_Item {
/** /**
* Add a relationship string to this object's RELS-EXT. * Add a relationship string to this object's RELS-EXT.
* does not support rels-int yet. * does not support rels-int yet.
* @param string $relationship * @param type $relationship
* @param <type> $object * @param type $object
* @param type $namespaceURI
*/ */
function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) { function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) {
$ds_list = $this->get_datastreams_list_as_array(); $ds_list = $this->get_datastreams_list_as_array();
@ -214,6 +255,10 @@ class Fedora_Item {
//print ($description->dump_node()); //print ($description->dump_node());
} }
/**
* Export as foxml
* @return type
*/
function export_as_foxml() { function export_as_foxml() {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -290,6 +335,12 @@ class Fedora_Item {
return $results; return $results;
} }
/**
* Get datastream dissemination
* @param type $dsid
* @param type $as_of_date_time
* @return string
*/
function get_datastream_dissemination($dsid, $as_of_date_time = "") { function get_datastream_dissemination($dsid, $as_of_date_time = "") {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -307,6 +358,12 @@ class Fedora_Item {
return $content; return $content;
} }
/**
* Get datastream
* @param type $dsid
* @param type $as_of_date_time
* @return type
*/
function get_datastream($dsid, $as_of_date_time = "") { function get_datastream($dsid, $as_of_date_time = "") {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -318,6 +375,11 @@ class Fedora_Item {
return $object->datastream; return $object->datastream;
} }
/**
* Get datastream history
* @param type $dsid
* @return type
*/
function get_datastream_history($dsid) { function get_datastream_history($dsid) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -332,6 +394,14 @@ class Fedora_Item {
return $ret; return $ret;
} }
/**
* Get dissemination
* @param type $service_definition_pid
* @param type $method_name
* @param type $parameters
* @param type $as_of_date_time
* @return string
*/
function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = null) { function get_dissemination($service_definition_pid, $method_name, $parameters = array(), $as_of_date_time = null) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -530,6 +600,9 @@ class Fedora_Item {
/** /**
* Removes this object form the repository. * Removes this object form the repository.
* @param type $log_message
* @param type $force
* @return type
*/ */
function purge($log_message = 'Purged using Islandora API.', $force = FALSE) { function purge($log_message = 'Purged using Islandora API.', $force = FALSE) {
$params = array( $params = array(
@ -541,6 +614,15 @@ class Fedora_Item {
return $this->soap_call('purgeObject', $params); return $this->soap_call('purgeObject', $params);
} }
/**
* Purge datastream
* @param type $dsID
* @param type $start_date
* @param type $end_date
* @param type $log_message
* @param type $force
* @return type
*/
function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) { function purge_datastream($dsID, $start_date = NULL, $end_date = NULL, $log_message = 'Purged datastream using Islandora API', $force = FALSE) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -553,11 +635,21 @@ class Fedora_Item {
return $this->soap_call('purgeDatastream', $params); return $this->soap_call('purgeDatastream', $params);
} }
/**
* URL
* @global type $base_url
* @return type
*/
function url() { function url() {
global $base_url; global $base_url;
return $base_url . '/fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : ''); return $base_url . '/fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : '');
} }
/**
* Get Next PID in Namespace
* @param type $pid_namespace
* @return type
*/
static function get_next_PID_in_namespace($pid_namespace = '') { static function get_next_PID_in_namespace($pid_namespace = '') {
if (empty($pid_namespace)) { if (empty($pid_namespace)) {
@ -581,18 +673,32 @@ class Fedora_Item {
return $result->pid; return $result->pid;
} }
/**
* ingest from FOXML
* @param type $foxml
* @return Fedora_Item
*/
static function ingest_from_FOXML($foxml) { static function ingest_from_FOXML($foxml) {
$params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested"); $params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested");
$object = self::soap_call('ingest', $params); $object = self::soap_call('ingest', $params);
return new Fedora_Item($object->objectPID); return new Fedora_Item($object->objectPID);
} }
/**
* ingest from FOXML file
* @param type $foxml_file
* @return type
*/
static function ingest_from_FOXML_file($foxml_file) { static function ingest_from_FOXML_file($foxml_file) {
$foxml = new DOMDocument(); $foxml = new DOMDocument();
$foxml->load($foxml_file); $foxml->load($foxml_file);
return self::ingest_from_FOXML($foxml); return self::ingest_from_FOXML($foxml);
} }
/**
* ingest from FOXML files in directory
* @param type $path
*/
static function ingest_from_FOXML_files_in_directory($path) { static function ingest_from_FOXML_files_in_directory($path) {
// Open the directory // Open the directory
$dir_handle = @opendir($path); $dir_handle = @opendir($path);
@ -612,6 +718,15 @@ class Fedora_Item {
closedir($dir_handle); closedir($dir_handle);
} }
/**
* Modify Object
* @param type $label
* @param type $state
* @param type $ownerId
* @param type $logMessage
* @param type $quiet
* @return type
*/
function modify_object($label = '', $state = null, $ownerId = null, $logMessage = 'Modified by Islandora API', $quiet=TRUE) { function modify_object($label = '', $state = null, $ownerId = null, $logMessage = 'Modified by Islandora API', $quiet=TRUE) {
$params = array( $params = array(
@ -625,6 +740,17 @@ class Fedora_Item {
return self::soap_call('modifyObject', $params, $quiet); return self::soap_call('modifyObject', $params, $quiet);
} }
/**
* Modify datastream by reference
* @param type $external_url
* @param type $dsid
* @param type $label
* @param type $mime_type
* @param type $force
* @param type $logMessage
* @param type $quiet
* @return type
*/
function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { function modify_datastream_by_reference($external_url, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -642,6 +768,17 @@ class Fedora_Item {
return self::soap_call('modifyDatastreamByReference', $params, $quiet); return self::soap_call('modifyDatastreamByReference', $params, $quiet);
} }
/**
* Modify datastream by value
* @param type $content
* @param type $dsid
* @param type $label
* @param type $mime_type
* @param type $force
* @param type $logMessage
* @param type $quiet
* @return type
*/
function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) { function modify_datastream_by_value($content, $dsid, $label, $mime_type, $force = FALSE, $logMessage = 'Modified by Islandora API', $quiet=FALSE) {
$params = array( $params = array(
'pid' => $this->pid, 'pid' => $this->pid,
@ -659,6 +796,13 @@ class Fedora_Item {
return self::soap_call('modifyDatastreamByValue', $params, $quiet); return self::soap_call('modifyDatastreamByValue', $params, $quiet);
} }
/**
* Soap call
* @param type $function_name
* @param type $params_array
* @param type $quiet
* @return type
*/
static function soap_call($function_name, $params_array, $quiet = FALSE) { static function soap_call($function_name, $params_array, $quiet = FALSE) {
if (!self::$connection_helper) { if (!self::$connection_helper) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
@ -730,6 +874,9 @@ class Fedora_Item {
* *
* @param string $pid if none given, getnextpid will be called. * @param string $pid if none given, getnextpid will be called.
* @param string $state The initial state, A - Active, I - Inactive, D - Deleted * @param string $state The initial state, A - Active, I - Inactive, D - Deleted
* @param type $label
* @param type $owner
* @return DOMDocument
*/ */
static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') { static function create_object_FOXML($pid = '', $state = 'A', $label = 'Untitled', $owner = '') {
$foxml = new DOMDocument("1.0", "UTF-8"); $foxml = new DOMDocument("1.0", "UTF-8");
@ -778,10 +925,23 @@ class Fedora_Item {
return $foxml; return $foxml;
} }
/**
* ingest new item
* @param type $pid
* @param type $state
* @param type $label
* @param type $owner
* @return type
*/
static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') { static function ingest_new_item($pid = '', $state = 'A', $label = '', $owner = '') {
return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner)); return self::ingest_from_FOXML(self::create_object_FOXML($pid, $state, $label, $owner));
} }
/**
* fedora item exists
* @param type $pid
* @return type
*/
static function fedora_item_exists($pid) { static function fedora_item_exists($pid) {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
return $item->exists(); return $item->exists();

68
api/fedora_utils.inc

@ -1,35 +1,49 @@
<?php <?php
// $Id$ // $Id$
// @file fedora_utils.inc /**
// Base utilities used by the Islansora fedora module. * @file
* Base utilities used by the Islandora fedora module.
*/
/* /*
* Functions that emulate php5.3 functionality for backwards compatiablity * Functions that emulate php5.3 functionality for backwards compatiablity
*/ */
if (!function_exists('str_getcsv')) { if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=null, $eol=null) { function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=null, $eol=null) {
$temp=fopen("php://memory", "rw"); $temp = fopen("php://memory", "rw");
fwrite($temp, $input); fwrite($temp, $input);
fseek($temp, 0); fseek($temp, 0);
$r=fgetcsv($temp, 4096, $delimiter, $enclosure); $r = fgetcsv($temp, 4096, $delimiter, $enclosure);
fclose($temp); fclose($temp);
return $r; return $r;
} }
} }
/* /*
* Functions that emulate php5.3 functionality for backwards compatiablity * Functions that emulate php5.3 functionality for backwards compatiablity
*/ */
/* /*
* Static functions used by the Fedora PHP API. * Static functions used by the Fedora PHP API.
*/ */
/**
* do curl
* @global type $user
* @param type $url
* @param type $return_to_variable
* @param type $number_of_post_vars
* @param type $post
* @return type
*/
function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) { function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
global $user; global $user;
// Check if we are inside Drupal and there is a valid user. // Check if we are inside Drupal and there is a valid user.
if ((!isset ($user)) || $user->uid == 0) { if ((!isset($user)) || $user->uid == 0) {
$fedora_user = 'anonymous'; $fedora_user = 'anonymous';
$fedora_pass = 'anonymous'; $fedora_pass = 'anonymous';
} }
@ -51,7 +65,7 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass"); curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
if ($number_of_post_vars>0&&$post) { if ($number_of_post_vars > 0 && $post) {
curl_setopt($ch, CURLOPT_POST, $number_of_post_vars); curl_setopt($ch, CURLOPT_POST, $number_of_post_vars);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$post"); curl_setopt($ch, CURLOPT_POSTFIELDS, "$post");
} }
@ -65,21 +79,23 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
} }
} }
/**
* Fedora available
* @return type
*/
function fedora_available() { function fedora_available() {
$response = do_curl(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe'); $response = do_curl(variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/describe');
return strstr($response, 'Repository Information HTML Presentation') !== FALSE; return strstr($response, 'Repository Information HTML Presentation') !== FALSE;
} }
/** /**
* Returns a UTF-8-encoded transcripiton of the string given in $in_str. * Returns a UTF-8-encoded transcripiton of the string given in $in_str.
* @param string $in_str * @param string $in_str
* @return string A UTF-8 encoded string. * @return string A UTF-8 encoded string.
*/ */
function fix_encoding($in_str) { function fix_encoding($in_str) {
$cur_encoding = mb_detect_encoding($in_str) ; $cur_encoding = mb_detect_encoding($in_str);
if ($cur_encoding == "UTF-8" && mb_check_encoding($in_str, "UTF-8")) { if ($cur_encoding == "UTF-8" && mb_check_encoding($in_str, "UTF-8")) {
return $in_str; return $in_str;
} }
@ -88,6 +104,11 @@ function fix_encoding($in_str) {
} }
} }
/**
* valid pid ??
* @param type $pid
* @return boolean
*/
function validPid($pid) { function validPid($pid) {
$valid = FALSE; $valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) { if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
@ -97,6 +118,11 @@ function validPid($pid) {
return $valid; return $valid;
} }
/**
* Valid Dsid ??
* @param type $dsid
* @return boolean
*/
function validDsid($dsid) { function validDsid($dsid) {
$valid = FALSE; $valid = FALSE;
if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) { if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
@ -106,6 +132,11 @@ function validDsid($dsid) {
return $valid; return $valid;
} }
/**
* fixDsid ??
* @param type $dsid
* @return string
*/
function fixDsid($dsid) { function fixDsid($dsid) {
$new_dsid = trim($dsid); $new_dsid = trim($dsid);
@ -113,16 +144,15 @@ function fixDsid($dsid) {
$replace = ''; $replace = '';
$new_dsid = preg_replace($find, $replace, $new_dsid); $new_dsid = preg_replace($find, $replace, $new_dsid);
if( strlen($new_dsid) > 63 ) if (strlen($new_dsid) > 63)
$new_dsid = substr($new_dsid, -63); $new_dsid = substr($new_dsid, -63);
if( preg_match('/^[^a-zA-Z]/', $dsid ) ) if (preg_match('/^[^a-zA-Z]/', $dsid))
$new_dsid = 'x' . $new_dsid; $new_dsid = 'x' . $new_dsid;
if( strlen($new_dsid) == 0 ) if (strlen($new_dsid) == 0)
$new_dsid = 'item' . rand(1, 100); $new_dsid = 'item' . rand(1, 100);
return $new_dsid; return $new_dsid;
} }

70
api/rels-ext.inc

@ -1,43 +1,47 @@
<?php <?php
// $Id$ // $Id$
/* /**
* To change this template, choose Tools | Templates * @file
* and open the template in the editor. * RelsExt class
*/ */
/** /**
* Description of relsext * RelsExt class
*
* @author aoneill
*/ */
class RelsExt { class RelsExt {
// Instance variables
public $relsExtArray = array(); // Instance variables
private $originalRelsExtArray = array(); // Used to determine the result of modified() funciton. public $relsExtArray = array();
// Member functions private $originalRelsExtArray = array(); // Used to determine the result of modified() funciton.
/** /**
* Constructor that builds itself by retrieving the RELS-EXT stream from * Constructor that builds itself by retrieving the RELS-EXT stream from
* the repository for the given Fedora_Item. * the repository for the given Fedora_Item.
* @param Fedora_Item $item * @param Fedora_Item $item
*/ */
function RelsExt( $item ) {
$relsextxml = $item->get_datastream_dissemination('RELS-EXT'); function RelsExt($item) {
$relsextxml = $item->get_datastream_dissemination('RELS-EXT');
} }
function modified() { /**
return !(empty(array_diff($this->relsExtArray, $this->originalRelsExtArray)) && * modified
empty(array_diff($this->originalRelsExtArray, $this->relsExtArray))); * @return type
} */
function modified() {
/** return!(empty(array_diff($this->relsExtArray, $this->originalRelsExtArray)) &&
* Save the current state of the RELS-EXT array out to the repository item empty(array_diff($this->originalRelsExtArray, $this->relsExtArray)));
* as a datastream. }
*/
function save() { /**
* Save the current state of the RELS-EXT array out to the repository item
} * as a datastream.
*/
function save() {
}
} }

25
api/tagging.inc

@ -1,20 +1,25 @@
<?php <?php
// $Id$ // $Id$
/* /**
* @file tagging.inc * @file
* TagSet Class
*/ */
/** /**
* Description of tagging * TagSet Class
*
* @author aoneill
*/ */
class TagSet { class TagSet {
public $tags = array(); public $tags = array();
public $item = NULL; public $item = NULL;
public $tagsDSID = 'TAGS'; public $tagsDSID = 'TAGS';
/**
* Constructor
* @param type $item
*/
function TagSet($item = NULL) { function TagSet($item = NULL) {
if (!empty($item) && get_class($item) == 'Fedora_Item') { if (!empty($item) && get_class($item) == 'Fedora_Item') {
$this->item = $item; $this->item = $item;
@ -22,8 +27,12 @@ class TagSet {
} }
} }
/**
* Load ??
* @return type
*/
function load() { function load() {
$tagsxml = isset($this->item->datastreams[$this->tagsDSID])? $this->item->get_datastream_dissemination($this->tagsDSID) : NULL; $tagsxml = isset($this->item->datastreams[$this->tagsDSID]) ? $this->item->get_datastream_dissemination($this->tagsDSID) : NULL;
if (empty($tagsxml)) { if (empty($tagsxml)) {
$this->tags = array(); $this->tags = array();
return FALSE; return FALSE;
@ -59,11 +68,11 @@ class TagSet {
else { else {
$this->item->modify_datastream_by_value($tagdoc->saveXML(), $this->tagsDSID, 'Tags', 'text/xml', 'X'); $this->item->modify_datastream_by_value($tagdoc->saveXML(), $this->tagsDSID, 'Tags', 'text/xml', 'X');
} }
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message('There was an error saving the tags datastream: !e', array('!e' => $e), 'error'); drupal_set_message('There was an error saving the tags datastream: !e', array('!e' => $e), 'error');
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
} }

32
plugins/CollectionFormBuilder.inc

@ -1,37 +1,52 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* Collection Form Builder
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/*
* Created on 19-Feb-08 /**
*
*
* implements methods from content model ingest form xml * implements methods from content model ingest form xml
* builds a dc metadata form * builds a dc metadata form
*/ */
class CollectionFormBuilder extends FormBuilder { class CollectionFormBuilder extends FormBuilder {
/**
* Constructor
*/
function CollectionFormBuilder() { function CollectionFormBuilder() {
module_load_include('inc', 'CollectionFormBuilder', ''); module_load_include('inc', 'CollectionFormBuilder', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* Create Fedora Datastream
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement) { function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
global $base_url; global $base_url;
$mimetype = new MimeClass(); $mimetype = new MimeClass();
$server = NULL; $server = NULL;
$file=$form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
$fileUrl = $base_url . '/'. drupal_urlencode($file); $fileUrl = $base_url . '/' . drupal_urlencode($file);
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = substr($dtitle, 0, strpos($dtitle, ".")); $dtitle = substr($dtitle, 0, strpos($dtitle, "."));
$ds1 = $dom->createElement("foxml:datastream"); $ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "COLLECTION_POLICY"); //set the ID $ds1->setAttribute("ID", "COLLECTION_POLICY"); //set the ID
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "COLLECTION_POLICY.0"); $ds1v->setAttribute("ID", "COLLECTION_POLICY.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -42,4 +57,5 @@ class CollectionFormBuilder extends FormBuilder {
$ds1v->appendChild($ds1content); $ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
} }
} }

26
plugins/CreateCollection.inc

@ -1,22 +1,34 @@
<?php <?php
// $Id$ // $Id$
/* /**
* * @file
* * Create Collection Class
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/ */
/**
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/
class CreateCollection { class CreateCollection {
function CreateCollection() {
/**
* Constructor
*/
function CreateCollection() {
} }
/**
* ingest collection policy ???
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function ingestCollectionPolicy($parameterArray = NULL, $dsid, $file, $file_ext = NULL) { function ingestCollectionPolicy($parameterArray = NULL, $dsid, $file, $file_ext = NULL) {
return TRUE; //nothing needed here as we are not transforming any files return TRUE; //nothing needed here as we are not transforming any files
} }
} }

55
plugins/DarwinCore.inc

@ -2,13 +2,25 @@
// $Id$ // $Id$
/**
* @file
* Darwin Core class
*/
/**
* Darwin Core ???
*/
class DarwinCore { class DarwinCore {
/**
* Constructor
* @param type $item
*/
function __construct($item = NULL) { function __construct($item = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!empty($item)) { if (!empty($item)) {
$this->owner = $item; $this->owner = $item;
if ( array_key_exists('DARWIN_CORE', $item->get_datastreams_list_as_array())) { if (array_key_exists('DARWIN_CORE', $item->get_datastreams_list_as_array())) {
$dwc = $item->get_datastream_dissemination('DARWIN_CORE'); $dwc = $item->get_datastream_dissemination('DARWIN_CORE');
if (!empty($dwc)) { if (!empty($dwc)) {
$this->darwinCoreXML = $dwc; $this->darwinCoreXML = $dwc;
@ -17,6 +29,11 @@ class DarwinCore {
} }
} }
/**
* Build Drupal Form
* @param type $form
* @return int
*/
public function buildDrupalForm($form = array()) { public function buildDrupalForm($form = array()) {
$dwc_xml = $this->darwinCoreXML; $dwc_xml = $this->darwinCoreXML;
@ -162,17 +179,22 @@ class DarwinCore {
$date = $dwc->getElementsByTagNameNS('http://rs.tdwg.org/dwc/terms/', 'eventDate')->item(0)->nodeValue; $date = $dwc->getElementsByTagNameNS('http://rs.tdwg.org/dwc/terms/', 'eventDate')->item(0)->nodeValue;
$format = 'Y-m-d H:i:s'; $format = 'Y-m-d H:i:s';
$form['dwceventDate'] = array( $form['dwceventDate'] = array(
'#type' => 'date_popup', // types 'date_text' and 'date_timezone' are also supported. See .inc file. '#type' => 'date_popup', // types 'date_text' and 'date_timezone' are also supported. See .inc file.
'#title' => 'select a date', '#title' => 'select a date',
'#default_value' => $date, '#default_value' => $date,
'#date_format' => $format, '#date_format' => $format,
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc '#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds. '#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#description' => '', '#description' => '',
); );
return $form; return $form;
} }
/**
* Handle Form ??
* @global type $user
* @param type $form_values
*/
public function handleForm($form_values) { public function handleForm($form_values) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $user; global $user;
@ -208,12 +230,20 @@ class DarwinCore {
$this->darwinCoreXML = $dwc->saveXML(); $this->darwinCoreXML = $dwc->saveXML();
} }
/**
* asXML ??
* @return type
*/
public function asXML() { public function asXML() {
return $this->darwinCoreXML; return $this->darwinCoreXML;
} }
/**
* asHTML ??
* @return type
*/
public function asHTML() { public function asHTML() {
$path=drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
@ -226,8 +256,7 @@ class DarwinCore {
try { try {
$proc = new XsltProcessor(); $proc = new XsltProcessor();
} } catch (Exception $e) {
catch (Exception $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error');
return " "; return " ";
} }
@ -238,7 +267,7 @@ class DarwinCore {
$input->loadXML(trim($xmlstr)); $input->loadXML(trim($xmlstr));
$xsl = $proc->importStylesheet($xsl); $xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input); $newdom = $proc->transformToDoc($input);
$content=$newdom->saveXML(); $content = $newdom->saveXML();
return $content; return $content;
} }
@ -256,9 +285,7 @@ class DarwinCore {
'MachineObservation' => 'MachineObservation', 'MachineObservation' => 'MachineObservation',
'NomenclaturalChecklist' => 'NomenclaturalChecklist', 'NomenclaturalChecklist' => 'NomenclaturalChecklist',
), ),
); );
public $dwcFields = array( public $dwcFields = array(
'dc:type', 'dc:type',
'dc:language', 'dc:language',
@ -283,8 +310,6 @@ class DarwinCore {
'dwc:eventDate', 'dwc:eventDate',
'dwc:eventTime', 'dwc:eventTime',
); );
public $darwinCoreXML = ' public $darwinCoreXML = '
<SimpleDarwinRecordSet xmlns="http://rs.tdwg.org/dwc/xsd/simpledarwincore/" xmlns:dc="http://purl.org/dc/terms/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rs.tdwg.org/dwc/xsd/simpledarwincore/ http://rs.tdwg.org/dwc/xsd/tdwg_dwc_simple.xsd"> <SimpleDarwinRecordSet xmlns="http://rs.tdwg.org/dwc/xsd/simpledarwincore/" xmlns:dc="http://purl.org/dc/terms/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rs.tdwg.org/dwc/xsd/simpledarwincore/ http://rs.tdwg.org/dwc/xsd/tdwg_dwc_simple.xsd">
<SimpleDarwinRecord> <SimpleDarwinRecord>

32
plugins/DemoFormBuilder.inc

@ -1,31 +1,44 @@
<?php <?php
// $Id$ // $Id$
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); /**
/* * @file
* Created on 19-Feb-08
*
* *
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/**
* implements methods from content model ingest form xml * implements methods from content model ingest form xml
* builds a dc metadata form * builds a dc metadata form
*/ */
class DemoFormBuilder extends FormBuilder { class DemoFormBuilder extends FormBuilder {
/**
* Constructor
*/
function DemoFormBuilder() { function DemoFormBuilder() {
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
//Override this so we can specify the datastream id of FULL_SIZE should make this easier /**
* Override this so we can specify the datastream id of FULL_SIZE should make this easier
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement) { function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
global $base_url; global $base_url;
$mimetype = new MimeClass(); $mimetype = new MimeClass();
$server = NULL; $server = NULL;
$file=$form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
if (!empty($file)) { if (!empty($file)) {
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
$fileUrl = $base_url .'/'. drupal_urlencode($file); $fileUrl = $base_url . '/' . drupal_urlencode($file);
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = urldecode($dtitle); $dtitle = urldecode($dtitle);
@ -50,7 +63,7 @@ class DemoFormBuilder extends FormBuilder {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
$createdFile = strstr($createdFile, $file); $createdFile = strstr($createdFile, $file);
$dformat = $mimetype->getType($createdFile); $dformat = $mimetype->getType($createdFile);
$fileUrl = $base_url .'/'. drupal_urlencode( $createdFile ); $fileUrl = $base_url . '/' . drupal_urlencode($createdFile);
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = urldecode($dtitle); $dtitle = urldecode($dtitle);
@ -60,7 +73,7 @@ class DemoFormBuilder extends FormBuilder {
$ds1->setAttribute("ID", "$dsid"); $ds1->setAttribute("ID", "$dsid");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "$dsid.0"); $ds1v->setAttribute("ID", "$dsid.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -73,5 +86,6 @@ class DemoFormBuilder extends FormBuilder {
} }
} }
} }
} }

26
plugins/DocumentConverter.inc

@ -3,20 +3,35 @@
// $Id$ // $Id$
/** /**
* * @file
* Document Converter Class
*/
/**
* This class implements document (doc, odt, pdf, etc.) conversion for a generic * This class implements document (doc, odt, pdf, etc.) conversion for a generic
* multi-format document collection. * multi-format document collection.
*/ */
class DocumentConverter { class DocumentConverter {
private $converter_service_url = "http://localhost:8080/converter/service"; private $converter_service_url = "http://localhost:8080/converter/service";
/**
* Constructor
* @param type $converter_url
*/
public function __construct($converter_url = NULL) { public function __construct($converter_url = NULL) {
if (!empty($converter_url)) if (!empty($converter_url))
$this->converter_service_url = $converter_url; $this->converter_service_url = $converter_url;
} }
/**
* Convert ???
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $output_ext
* @return string
*/
function convert($parameterArray = NULL, $dsid, $file, $output_ext) { function convert($parameterArray = NULL, $dsid, $file, $output_ext) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
@ -32,7 +47,7 @@ class DocumentConverter {
$outputType = $helper->get_mimetype($output_ext); $outputType = $helper->get_mimetype($output_ext);
$inputData = file_get_contents($file); $inputData = file_get_contents($file);
$outputFile = $file ."_". $dsid .".". $output_ext; $outputFile = $file . "_" . $dsid . "." . $output_ext;
#debug: #debug:
#drupal_set_message("inputType: $inputType", 'status'); #drupal_set_message("inputType: $inputType", 'status');
@ -40,8 +55,8 @@ class DocumentConverter {
#drupal_set_message("outputFile: $outputFile", 'status'); #drupal_set_message("outputFile: $outputFile", 'status');
$ch = curl_init($this->converter_service_url); $ch = curl_init($this->converter_service_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: $inputType", "Accept: $outputType" ) ); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: $inputType", "Accept: $outputType"));
curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120); // times out after 2 minutes curl_setopt($ch, CURLOPT_TIMEOUT, 120); // times out after 2 minutes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_POSTFIELDS, $inputData); // add POST fields curl_setopt($ch, CURLOPT_POSTFIELDS, $inputData); // add POST fields
@ -69,6 +84,7 @@ class DocumentConverter {
return FALSE; return FALSE;
} }
} }
} }
/* /*

93
plugins/Exiftool.inc

@ -1,17 +1,24 @@
<?php <?php
// $Id$ // $Id$
/* /**
* * @file
* * Exiftool
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/ */
/**
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/
class Exiftool { class Exiftool {
private $pid = NULL; private $pid = NULL;
private $item = NULL; private $item = NULL;
/**
* Constructor
* @param type $pid
*/
function __construct($pid) { function __construct($pid) {
//drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); //drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$this->pid = $pid; $this->pid = $pid;
@ -19,48 +26,60 @@ class Exiftool {
$this->item = new Fedora_Item($this->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 extractMetadata($parameterArray, $dsid, $file, $file_ext) { function extractMetadata($parameterArray, $dsid, $file, $file_ext) {
$system = getenv('System'); $system = getenv('System');
$file_suffix = '_'. $dsid . '.xml'; $file_suffix = '_' . $dsid . '.xml';
$returnValue=TRUE; $returnValue = TRUE;
$output=array(); $output = array();
exec('exiftool -X ' . escapeshellarg($file) . '', $output); exec('exiftool -X ' . escapeshellarg($file) . '', $output);
file_put_contents($file.$file_suffix, implode("\n", $output)); file_put_contents($file . $file_suffix, implode("\n", $output));
$_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_suffix; $_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_suffix;
return TRUE; return TRUE;
} }
/**
* display metadata ???
* @return type
*/
function displayMetadata() { function displayMetadata() {
$output=''; $output = '';
$exif = $this->item->get_datastream_dissemination('EXIF'); $exif = $this->item->get_datastream_dissemination('EXIF');
if (trim($exif) != '') { if (trim($exif) != '') {
$exifDom = DOMDocument::loadXML($this->item->get_datastream_dissemination('EXIF')); $exifDom = DOMDocument::loadXML($this->item->get_datastream_dissemination('EXIF'));
if ($exifDom != NULL) { if ($exifDom != NULL) {
$description = $exifDom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#','Description'); $description = $exifDom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
if ($description->length > 0) { if ($description->length > 0) {
$description=$description->item(0); $description = $description->item(0);
$output .= '<div class="fedora_technical_metadata"><ul>'; $output .= '<div class="fedora_technical_metadata"><ul>';
for ($i=0;$i<$description->childNodes->length;$i++){ for ($i = 0; $i < $description->childNodes->length; $i++) {
$name=$description->childNodes->item($i)->nodeName; $name = $description->childNodes->item($i)->nodeName;
$value=$description->childNodes->item($i)->nodeValue; $value = $description->childNodes->item($i)->nodeValue;
if ($name != '#text' && !preg_match('/^System\:.*$/',$name) && trim($value) != '') { if ($name != '#text' && !preg_match('/^System\:.*$/', $name) && trim($value) != '') {
list($type,$name) = preg_split('/\:/',$name); list($type, $name) = preg_split('/\:/', $name);
$name = trim(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])/'," $1", $name)); $name = trim(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])/', " $1", $name));
$output .= '<li><b>'.$name. '</b>: '. $value .' </li>'; $output .= '<li><b>' . $name . '</b>: ' . $value . ' </li>';
} }
} }
$output.='</ul></div>'; $output.='</ul></div>';
$fieldset = array( $fieldset = array(
'#title' => t("!text", array('!text' => 'Technical Metadata')), '#title' => t("!text", array('!text' => 'Technical Metadata')),
'#collapsible' => TRUE, '#collapsible' => TRUE,
'#collapsed' => TRUE, '#collapsed' => TRUE,
'#value' => $output '#value' => $output
); );
$output = theme('fieldset', $fieldset); $output = theme('fieldset', $fieldset);
} }
} }
} }
return $output; return $output;
} }

33
plugins/Ffmpeg.inc

@ -1,26 +1,44 @@
<?php <?php
// $Id$ // $Id$
/* /**
* * @file
* Ffmpeg wrapper class
*/
/**
* FFMpeg wrapper class for generating movie thumbnails
* *
* This Class implements the methods defined in the STANDARD_QT content model * This Class implements the methods defined in the STANDARD_QT content model
*/ */
class Ffmpeg { class Ffmpeg {
/**
* Default constructor
*/
function Ffmpeg() { function Ffmpeg() {
} }
/**
* Extract a thumbnail from the movie
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function extract_thumbnail($parameterArray, $dsid, $file, $file_ext) { function extract_thumbnail($parameterArray, $dsid, $file, $file_ext) {
$defaults = array('ss' => '00:00:10', 's' => null); $defaults = array('ss' => '00:00:10', 's' => null);
$params = array_merge($defaults, $parameterArray); $params = array_merge($defaults, $parameterArray);
$system = getenv('System'); $system = getenv('System');
$file_suffix = '_'. $dsid . '.' . $file_ext; $file_suffix = '_' . $dsid . '.' . $file_ext;
$returnValue=TRUE; $returnValue = TRUE;
$output=array(); $output = array();
$size = ''; $size = '';
if($params['s'] != null) { if ($params['s'] != null) {
$size = ' -s ' . escapeshellarg($params['s']); $size = ' -s ' . escapeshellarg($params['s']);
} }
exec('ffmpeg -i ' . escapeshellarg($file) . ' -r 1 -ss ' . escapeshellarg($params['ss']) . ' ' . $size . ' -t 1 ' . escapeshellarg($file . $file_suffix)); exec('ffmpeg -i ' . escapeshellarg($file) . ' -r 1 -ss ' . escapeshellarg($params['ss']) . ' ' . $size . ' -t 1 ' . escapeshellarg($file . $file_suffix));
@ -32,4 +50,5 @@ class Ffmpeg {
$_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_suffix; $_SESSION['fedora_ingest_files']["$dsid"] = $file . $file_suffix;
return TRUE; return TRUE;
} }
} }

105
plugins/Flv.inc

@ -1,18 +1,31 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on 19-Feb-08 * @file
* * Form Builder class
* */
/**
* implements method from content model ingest form xml * implements method from content model ingest form xml
*/ */
class FormBuilder { class FormBuilder {
/**
* Constructor
*/
function FormBuilder() { function FormBuilder() {
module_load_include('inc', 'Flv', ''); module_load_include('inc', 'Flv', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* Create QDC Stream ???
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createQDCStream($form_values, &$dom, &$rootElement) { function createQDCStream($form_values, &$dom, &$rootElement) {
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
$datastream->setAttribute("ID", "QDC"); $datastream->setAttribute("ID", "QDC");
@ -33,7 +46,7 @@ class FormBuilder {
$oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$content->appendChild($oai); $content->appendChild($oai);
//dc elements //dc elements
$previousElement=NULL; //used in case we have to nest elements for qualified dublin core $previousElement = NULL; //used in case we have to nest elements for qualified dublin core
foreach ($form_values as $key => $value) { foreach ($form_values as $key => $value) {
$index = strrpos($key, '-'); $index = strrpos($key, '-');
if ($index > 01) { if ($index > 01) {
@ -42,7 +55,7 @@ class FormBuilder {
$test = substr($key, 0, 2); $test = substr($key, 0, 2);
if ($test=='dc'||$test=='ap') {//don't try to process other form values if ($test == 'dc' || $test == 'ap') {//don't try to process other form values
try { try {
if (!strcmp(substr($key, 0, 4), 'app_')) { if (!strcmp(substr($key, 0, 4), 'app_')) {
$key = substr($key, 4); $key = substr($key, 4);
@ -52,8 +65,7 @@ class FormBuilder {
$previousElement = $dom->createElement($key, $value); $previousElement = $dom->createElement($key, $value);
$oai->appendChild($previousElement); $oai->appendChild($previousElement);
} }
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error');
continue; continue;
} }
@ -62,10 +74,15 @@ class FormBuilder {
} }
} }
/**
* Handle QDC Form ???
* @param type $form_values
* @return type
*/
function handleQDCForm($form_values) { function handleQDCForm($form_values) {
$dom = new DomDocument("1.0", "UTF-8"); $dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
$pid=$form_values['pid']; $pid = $form_values['pid'];
$rootElement = $dom->createElement("foxml:digitalObject"); $rootElement = $dom->createElement("foxml:digitalObject");
$rootElement->setAttribute('PID', "$pid"); $rootElement->setAttribute('PID', "$pid");
$rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#"); $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#");
@ -87,13 +104,13 @@ class FormBuilder {
try { try {
$soapHelper = new ConnectionHelper(); $soapHelper = new ConnectionHelper();
$client=$soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl'));
if ($client == NULL) { if ($client == NULL) {
drupal_set_message(t('Error getting SOAP client.'), 'error'); drupal_set_message(t('Error getting SOAP client.'), 'error');
return; return;
} }
$object=$client->__soapCall('ingest', array($params)); $object = $client->__soapCall('ingest', array($params));
$deleteFiles = $form_values['delete_file']; //remove files from drupal file system $deleteFiles = $form_values['delete_file']; //remove files from drupal file system
if ($deleteFiles > 0) { if ($deleteFiles > 0) {
@ -102,20 +119,25 @@ class FormBuilder {
} }
unlink($form_values['fullpath']); unlink($form_values['fullpath']);
} }
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
return; return;
} }
} }
/**
* Create Fedora DataStream
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement) { function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimetype = new MimeClass(); $mimetype = new MimeClass();
$server = NULL; $server = NULL;
$file=$form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
$fileUrl = 'http://'. $_SERVER['HTTP_HOST'] . $file; $fileUrl = 'http://' . $_SERVER['HTTP_HOST'] . $file;
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = substr($dtitle, 0, strpos($dtitle, ".")); $dtitle = substr($dtitle, 0, strpos($dtitle, "."));
@ -123,7 +145,7 @@ class FormBuilder {
$ds1->setAttribute("ID", "OBJ"); $ds1->setAttribute("ID", "OBJ");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "OBJ.0"); $ds1v->setAttribute("ID", "OBJ.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -137,16 +159,16 @@ class FormBuilder {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
$createdFile = strstr($createdFile, $file); $createdFile = strstr($createdFile, $file);
$dformat = $mimetype->getType($createdFile); $dformat = $mimetype->getType($createdFile);
$fileUrl = 'http://'. $_SERVER['HTTP_HOST'] . $createdFile; $fileUrl = 'http://' . $_SERVER['HTTP_HOST'] . $createdFile;
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = substr($dtitle, 0, strpos($dtitle, ".")); $dtitle = substr($dtitle, 0, strpos($dtitle, "."));
$dtitle = $dtitle . '_'. $dsid; $dtitle = $dtitle . '_' . $dsid;
$ds1 = $dom->createElement("foxml:datastream"); $ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "$dsid"); $ds1->setAttribute("ID", "$dsid");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "$dsid.0"); $ds1v->setAttribute("ID", "$dsid.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -161,6 +183,9 @@ class FormBuilder {
/** /**
* creates the RELS-EXT for the foxml * creates the RELS-EXT for the foxml
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/ */
function createRelationShips($form_values, &$dom, &$rootElement) { function createRelationShips($form_values, &$dom, &$rootElement) {
$drdf = $dom->createElement("foxml:datastream"); $drdf = $dom->createElement("foxml:datastream");
@ -190,14 +215,16 @@ class FormBuilder {
$rdf->appendChild($rdfdesc); $rdf->appendChild($rdfdesc);
$rdfdesc->appendChild($member); $rdfdesc->appendChild($member);
$rootElement->appendChild($drdf); $rootElement->appendChild($drdf);
} }
/** /**
* creates the standard foxml properties * creates the standard foxml properties
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/ */
function createStandardFedoraStuff($form_values, &$dom, &$rootElement) { function createStandardFedoraStuff($form_values, &$dom, &$rootElement) {
/*foxml object properties section */ /* foxml object properties section */
$objproperties = $dom->createElement("foxml:objectProperties"); $objproperties = $dom->createElement("foxml:objectProperties");
$prop1 = $dom->createElement("foxml:property"); $prop1 = $dom->createElement("foxml:property");
$prop1->setAttribute("NAME", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); $prop1->setAttribute("NAME", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
@ -222,11 +249,17 @@ class FormBuilder {
$rootElement->appendChild($objproperties); $rootElement->appendChild($objproperties);
} }
/**
* Build QDC Form
* @param type $form
* @param type $ingest_form_definition
* @param type $form_values
* @return type
*/
function buildQDCForm(&$form, $ingest_form_definition, &$form_values) { function buildQDCForm(&$form, $ingest_form_definition, &$form_values) {
$form['indicator2'] = array( $form['indicator2'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Ingest Digital Object Step #2') '#title' => t('Ingest Digital Object Step #2')
); );
foreach ($ingest_form_definition->form_elements->element as $element) { foreach ($ingest_form_definition->form_elements->element as $element) {
$name = strip_tags($element->name->asXML()); $name = strip_tags($element->name->asXML());
@ -234,7 +267,7 @@ class FormBuilder {
$required = strip_tags($element->required->asXML()); $required = strip_tags($element->required->asXML());
$required = strtolower($required); $required = strtolower($required);
if ($required != 'TRUE') { if ($required != 'TRUE') {
$required='0'; $required = '0';
} }
$description = strip_tags($element->description->asXML()); $description = strip_tags($element->description->asXML());
@ -247,20 +280,19 @@ class FormBuilder {
$options["$field"] = $value; $options["$field"] = $value;
} }
$form['indicator2']["$name"] = array( $form['indicator2']["$name"] = array(
'#title' => $title, '#title' => $title,
'#required' => $required, '#required' => $required,
'#description' => $description, '#description' => $description,
'#type' => $type, '#type' => $type,
'#options' => $options, '#options' => $options,
); );
} }
else { else {
$form['indicator2']["$name"] = array( $form['indicator2']["$name"] = array(
'#title' => $title, '#title' => $title,
'#required' => $required, '#required' => $required,
'#description' => $description, '#description' => $description,
'#type' => $type '#type' => $type
); );
} }
} }
@ -269,3 +301,4 @@ class FormBuilder {
} }
} }

24
plugins/FlvFormBuilder.inc

@ -1,20 +1,33 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* FLVFormBuilder
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/* /**
* implements methods from content model ingest form xml * implements methods from content model ingest form xml
* builds a dc metadata form * builds a dc metadata form
*/ */
class FlvFormBuilder extends FormBuilder { class FlvFormBuilder extends FormBuilder {
/**
* Constructor
*/
function FlvFormBuilder() { function FlvFormBuilder() {
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/* /**
* method overrides method in FormBuilder. We changed the dsid from OBJ to FLV and added the TN datastream * method overrides method in FormBuilder. We changed the dsid from OBJ to FLV and added the TN datastream
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/ */
function createFedoraDataStreams($form_values, &$dom, &$rootElement) { function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
@ -24,7 +37,7 @@ class FlvFormBuilder extends FormBuilder {
$file = $form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
//$fileUrl = 'http://'.$_SERVER['HTTP_HOST'].$file; //$fileUrl = 'http://'.$_SERVER['HTTP_HOST'].$file;
$fileUrl = $base_url .'/'. drupal_urlencode($file); $fileUrl = $base_url . '/' . drupal_urlencode($file);
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = substr($dtitle, 0, strpos($dtitle, ".")); $dtitle = substr($dtitle, 0, strpos($dtitle, "."));
@ -32,7 +45,7 @@ class FlvFormBuilder extends FormBuilder {
$ds1->setAttribute("ID", "FLV"); $ds1->setAttribute("ID", "FLV");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "FLV.0"); $ds1v->setAttribute("ID", "FLV.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -44,7 +57,7 @@ class FlvFormBuilder extends FormBuilder {
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
$createdFile = drupal_get_path('module', 'Fedora_Repository') . '/images/flashThumb.jpg'; $createdFile = drupal_get_path('module', 'Fedora_Repository') . '/images/flashThumb.jpg';
$fileUrl = $base_url .'/'. drupal_urlencode($createdFile); //'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile; $fileUrl = $base_url . '/' . drupal_urlencode($createdFile); //'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile;
$ds1 = $dom->createElement("foxml:datastream"); $ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "TN"); $ds1->setAttribute("ID", "TN");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
@ -60,5 +73,6 @@ class FlvFormBuilder extends FormBuilder {
$ds1v->appendChild($ds1content); $ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
} }
} }

165
plugins/FormBuilder.inc

@ -2,19 +2,31 @@
// $Id$ // $Id$
/* /**
* Created on 19-Feb-08 * @file
* * FormBuilder class
* */
/**
* implements methods from content model ingest form xml * implements methods from content model ingest form xml
* builds a dc metadata form * builds a dc metadata form
*/ */
class FormBuilder { class FormBuilder {
/**
* Constructor
*/
function FormBuilder() { function FormBuilder() {
module_load_include('inc', 'FormBuilder', ''); module_load_include('inc', 'FormBuilder', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* Create QDC Stream ??
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createQDCStream($form_values, &$dom, &$rootElement) { function createQDCStream($form_values, &$dom, &$rootElement) {
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
$datastream->setAttribute("ID", "DC"); $datastream->setAttribute("ID", "DC");
@ -35,7 +47,7 @@ class FormBuilder {
$oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$content->appendChild($oai); $content->appendChild($oai);
//dc elements //dc elements
$previousElement=NULL;//used in case we have to nest elements for qualified dublin core $previousElement = NULL; //used in case we have to nest elements for qualified dublin core
foreach ($form_values as $key => $value) { foreach ($form_values as $key => $value) {
$key = str_replace('_', ':', $key); $key = str_replace('_', ':', $key);
$index = strrpos($key, '-'); $index = strrpos($key, '-');
@ -55,18 +67,22 @@ class FormBuilder {
$previousElement = $dom->createElement($key, $value); $previousElement = $dom->createElement($key, $value);
$oai->appendChild($previousElement); $oai->appendChild($previousElement);
} }
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error');
continue; continue;
} }
} }
$rootElement->appendChild($datastream); $rootElement->appendChild($datastream);
} }
} }
//create the security Policy /**
* Create the security policy
* @param type $collectionPid
* @param type $dom
* @param type $rootElement
* @return type
*/
function createPolicy($collectionPid, &$dom, &$rootElement) { function createPolicy($collectionPid, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
@ -78,8 +94,7 @@ class FormBuilder {
} }
try { try {
$xml = new SimpleXMLElement($policyStreamDoc); $xml = new SimpleXMLElement($policyStreamDoc);
} } catch (Exception $e) {
catch (Exception $e) {
watchdog(t("Fedora_Repository"), t("Problem getting security policy."), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("Problem getting security policy."), NULL, WATCHDOG_ERROR);
drupal_set_message(t('Problem getting security policy: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Problem getting security policy: !e', array('!e' => $e->getMessage())), 'error');
return FALSE; return FALSE;
@ -91,7 +106,7 @@ class FormBuilder {
return FALSE; return FALSE;
} }
$dom->importNode($policyElement, TRUE); $dom->importNode($policyElement, TRUE);
$value=$policyElement->appendXML($policyStreamDoc); $value = $policyElement->appendXML($policyStreamDoc);
if (!$value) { if (!$value) {
drupal_set_message(t('Error creating security policy stream.')); drupal_set_message(t('Error creating security policy stream.'));
watchdog(t("Fedora_Repository"), t("Error creating security policy stream, could not parse collection policy template file."), NULL, WATCHDOG_NOTICE); watchdog(t("Fedora_Repository"), t("Error creating security policy stream, could not parse collection policy template file."), NULL, WATCHDOG_NOTICE);
@ -114,14 +129,18 @@ class FormBuilder {
return TRUE; return TRUE;
} }
/**
* Handle QDC Form ??
* @param type $form_values
* @return type
*/
function handleQDCForm($form_values) { function handleQDCForm($form_values) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$dom = new DomDocument("1.0", "UTF-8"); $dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
$pid=$form_values['pid']; $pid = $form_values['pid'];
$rootElement = $dom->createElement("foxml:digitalObject"); $rootElement = $dom->createElement("foxml:digitalObject");
$rootElement->setAttribute('VERSION', '1.1'); $rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('PID', "$pid"); $rootElement->setAttribute('PID', "$pid");
@ -154,30 +173,36 @@ class FormBuilder {
$object = Fedora_Item::ingest_from_FOXML($dom); $object = Fedora_Item::ingest_from_FOXML($dom);
if (!empty($object->pid)) { if (!empty($object->pid)) {
// drupal_set_message("Item ". l($object->pid, 'fedora/repository/'. $object->pid) . " created successfully.", "status"); // drupal_set_message("Item ". l($object->pid, 'fedora/repository/'. $object->pid) . " created successfully.", "status");
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/'. $object->pid))), "status"); drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/' . $object->pid))), "status");
} }
if (!empty( $_SESSION['fedora_ingest_files'])) { if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
file_delete($createdFile); file_delete($createdFile);
} }
} }
file_delete($form_values['ingest-file-location']); file_delete($form_values['ingest-file-location']);
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
return; return;
} }
} }
/**
* Create Fedora Data stream
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement) { function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
global $base_url; global $base_url;
$mimetype = new MimeClass(); $mimetype = new MimeClass();
$server=NULL; $server = NULL;
$file=$form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
if (!empty( $file)) { if (!empty($file)) {
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
$parts = explode('/', $file); $parts = explode('/', $file);
@ -194,7 +219,7 @@ class FormBuilder {
$ds1->setAttribute("ID", "OBJ"); $ds1->setAttribute("ID", "OBJ");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
$ds1v->setAttribute("ID", "OBJ.0"); $ds1v->setAttribute("ID", "OBJ.0");
@ -208,20 +233,17 @@ class FormBuilder {
} }
if (!empty($_SESSION['fedora_ingest_files'])) { if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
if (!empty($file)) { if (!empty($file)) {
$found = strstr($createdFile, $file); $found = strstr($createdFile, $file);
if ($found !== FALSE) { if ($found !== FALSE) {
$createdFile = $found; $createdFile = $found;
} }
} }
$dformat = $mimetype->getType($createdFile); $dformat = $mimetype->getType($createdFile);
$parts = explode('/', $createdFile); $parts = explode('/', $createdFile);
foreach ($parts as $n => $part) { foreach ($parts as $n => $part) {
$parts[$n] = rawurlencode($part); $parts[$n] = rawurlencode($part);
} }
@ -236,7 +258,7 @@ class FormBuilder {
$ds1->setAttribute("ID", "$dsid"); $ds1->setAttribute("ID", "$dsid");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "$dsid.0"); $ds1v->setAttribute("ID", "$dsid.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -250,9 +272,11 @@ class FormBuilder {
} }
} }
/** /**
* Creates the RELS-EXT for the foxml * Creates the RELS-EXT for the foxml
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/ */
function createRelationShips($form_values, &$dom, &$rootElement) { function createRelationShips($form_values, &$dom, &$rootElement) {
$drdf = $dom->createElement("foxml:datastream"); $drdf = $dom->createElement("foxml:datastream");
@ -278,11 +302,11 @@ class FormBuilder {
if (!isset($relationship)) { if (!isset($relationship)) {
$relationship = 'isMemberOfCollection'; $relationship = 'isMemberOfCollection';
} }
$member = $dom->createElement("fedora:". $relationship); $member = $dom->createElement("fedora:" . $relationship);
$membr = $form_values['collection_pid']; $membr = $form_values['collection_pid'];
$member->setAttribute("rdf:resource", "info:fedora/$membr"); $member->setAttribute("rdf:resource", "info:fedora/$membr");
$rdfHasModel = $dom->createElement("fedora-model:hasModel"); $rdfHasModel = $dom->createElement("fedora-model:hasModel");
$contentModelPid=$form_values['content_model_pid']; $contentModelPid = $form_values['content_model_pid'];
$rdfHasModel->setAttribute("rdf:resource", "info:fedora/$contentModelPid"); $rdfHasModel->setAttribute("rdf:resource", "info:fedora/$contentModelPid");
$drdf->appendChild($dvrdf); $drdf->appendChild($dvrdf);
$dvrdf->appendChild($dvcontent); $dvrdf->appendChild($dvcontent);
@ -293,9 +317,11 @@ class FormBuilder {
$rootElement->appendChild($drdf); $rootElement->appendChild($drdf);
} }
/** /**
* Creates the standard foxml properties * Creates the standard foxml properties
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/ */
function createStandardFedoraStuff($form_values, &$dom, &$rootElement) { function createStandardFedoraStuff($form_values, &$dom, &$rootElement) {
// Foxml object properties section // Foxml object properties section
@ -315,7 +341,13 @@ class FormBuilder {
$rootElement->appendChild($objproperties); $rootElement->appendChild($objproperties);
} }
/**
* Build QDC Form
* @param type $form
* @param type $elements
* @param type $form_values
* @return string
*/
function buildQDCForm(&$form, $elements, &$form_values) { function buildQDCForm(&$form, $elements, &$form_values) {
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time. $form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
$form['indicator2'] = array( $form['indicator2'] = array(
@ -325,41 +357,44 @@ class FormBuilder {
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element['type'] == 'markup') { if ($element['type'] == 'markup') {
$el = array('#value'=> $element['description']); $el = array('#value' => $element['description']);
} else { }
$el = array( else {
'#title' => $element['label'], $el = array(
'#required' => ($element['required'] ? 1 : 0), '#title' => $element['label'],
'#description' => $element['description'], '#required' => ($element['required'] ? 1 : 0),
'#type' => $element['type'] '#description' => $element['description'],
); '#type' => $element['type']
} );
}
$name = explode('][', $element['name']); $name = explode('][', $element['name']);
$elLocation = &$form['indicator2']; $elLocation = &$form['indicator2'];
while (isset($elLocation[$name[0]]) && ($partial = array_shift($name)) != NULL) { while (isset($elLocation[$name[0]]) && ($partial = array_shift($name)) != NULL) {
$elLocation = &$elLocation[$partial]; $elLocation = &$elLocation[$partial];
} }
$autocomplete_path = FALSE; $autocomplete_path = FALSE;
$autocomplete_omit_collection = FALSE; $autocomplete_omit_collection = FALSE;
foreach ($element['parameters'] as $key => $val) { foreach ($element['parameters'] as $key => $val) {
if ($key == '#autocomplete_path') { if ($key == '#autocomplete_path') {
$autocomplete_path = $val; $autocomplete_path = $val;
} elseif ($key == '#autocomplete_omit_collection') { }
$autocomplete_omit_collection = TRUE; elseif ($key == '#autocomplete_omit_collection') {
} else { $autocomplete_omit_collection = TRUE;
$el[$key]=$val; }
} else {
$el[$key] = $val;
}
} }
if ($autocomplete_path !== FALSE) { if ($autocomplete_path !== FALSE) {
$el['#autocomplete_path'] = $autocomplete_path . (!$autocomplete_omit_collection?'/'.$form_values['storage']['collection_pid']:'/'); $el['#autocomplete_path'] = $autocomplete_path . (!$autocomplete_omit_collection ? '/' . $form_values['storage']['collection_pid'] : '/');
} }
if ($element['type'] == 'select' || $element['type'] == 'other_select') { if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options']= isset($element['authoritative_list'])?$element['authoritative_list']:array(); $el['#options'] = isset($element['authoritative_list']) ? $element['authoritative_list'] : array();
} }
$elLocation[join('][', $name)] = $el; $elLocation[join('][', $name)] = $el;

75
plugins/ImageManipulation.inc

@ -2,40 +2,54 @@
// $Id$ // $Id$
/* /**
* * @file
* * Image Manipulation class
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/ */
/**
* This Class implements the methods defined in the STANDARD_IMAGE content model
*/
class ImageManipulation { class ImageManipulation {
/**
* Constructor
*/
function ImageManipulation() { function ImageManipulation() {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
} }
/**
* Create a preview ??
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return string
*/
function createPreview($parameterArray, $dsid, $file, $file_ext) { function createPreview($parameterArray, $dsid, $file, $file_ext) {
$system = getenv('System'); $system = getenv('System');
$file_suffix = '_' . $dsid . '.' . $file_ext; $file_suffix = '_' . $dsid . '.' . $file_ext;
$width = $parameterArray['width']; $width = $parameterArray['width'];
if (!isset($parameterArray['height'])) { if (!isset($parameterArray['height'])) {
$height = $width; $height = $width;
} else { }
$height = $parameterArray['height']; else {
$height = $parameterArray['height'];
} }
$returnValue = TRUE; $returnValue = TRUE;
$output = array(); $output = array();
$destDir = dirname($file).'/work'; $destDir = dirname($file) . '/work';
$destFile = $destDir .'/'. basename($file) . $file_suffix; $destFile = $destDir . '/' . basename($file) . $file_suffix;
if (!is_dir($destDir)) { if (!is_dir($destDir)) {
@mkdir($destDir); @mkdir($destDir);
} }
if (!file_exists($destFile)) { if (!file_exists($destFile)) {
exec('convert -resize ' . $width . 'x'.$height.' -quality 85 "' . $file . '"[0] -strip "' .$destFile . '" 2>&1 &', $output, $returnValue); exec('convert -resize ' . $width . 'x' . $height . ' -quality 85 "' . $file . '"[0] -strip "' . $destFile . '" 2>&1 &', $output, $returnValue);
} }
else else
$returnValue = '0'; $returnValue = '0';
@ -49,6 +63,14 @@ class ImageManipulation {
} }
} }
/**
* Create PNG
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return string
*/
function createPNG($parameterArray = NULL, $dsid, $file, $file_ext) { function createPNG($parameterArray = NULL, $dsid, $file, $file_ext) {
$file_suffix = '_' . $dsid . '.' . $file_ext; $file_suffix = '_' . $dsid . '.' . $file_ext;
$returnValue = TRUE; $returnValue = TRUE;
@ -69,6 +91,14 @@ class ImageManipulation {
} }
} }
/**
* Create JPEG 2000
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function createJP2($parameterArray = NULL, $dsid, $file, $file_ext) { function createJP2($parameterArray = NULL, $dsid, $file, $file_ext) {
$file_suffix = "_$dsid.$file_ext"; $file_suffix = "_$dsid.$file_ext";
$return_value = TRUE; $return_value = TRUE;
@ -115,7 +145,14 @@ class ImageManipulation {
} }
} }
//use imagemapi to manipulate images instead of going directly to imagemagick or whatever /**
* use imagemapi to manipulate images instead of going directly to imagemagick or whatever
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return type
*/
function manipulateImage($parameterArray = NULL, $dsid, $file, $file_ext) { function manipulateImage($parameterArray = NULL, $dsid, $file, $file_ext) {
$height = $parameterArray['height']; $height = $parameterArray['height'];
$width = $parameterArray['width']; $width = $parameterArray['width'];
@ -151,6 +188,14 @@ class ImageManipulation {
} }
} }
/**
* Create Thumbnail from PDF
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return boolean
*/
function createThumbnailFromPDF($parameterArray, $dsid, $file, $file_ext) { function createThumbnailFromPDF($parameterArray, $dsid, $file, $file_ext) {
$height = $parameterArray['height']; $height = $parameterArray['height'];
$width = $parameterArray['width']; $width = $parameterArray['width'];
@ -185,6 +230,14 @@ class ImageManipulation {
} }
} }
/**
* Create Thumbnail
* @param type $parameterArray
* @param type $dsid
* @param type $file
* @param type $file_ext
* @return boolean
*/
function createThumbnail($parameterArray, $dsid, $file, $file_ext) { function createThumbnail($parameterArray, $dsid, $file, $file_ext) {
// var_dump($parameterArray);exit(0); // var_dump($parameterArray);exit(0);
$file_suffix = '_' . $dsid . '.' . $file_ext; $file_suffix = '_' . $dsid . '.' . $file_ext;

665
plugins/ModsFormBuilder.inc

@ -2,244 +2,268 @@
// $Id$ // $Id$
/**
* @file
* ModsFormBuilder class
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder'); module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/**
* ModsFormBuilder class ???
*/
class ModsFormBuilder extends FormBuilder { class ModsFormBuilder extends FormBuilder {
static $MODS_NS = 'http://www.loc.gov/mods/v3'; static $MODS_NS = 'http://www.loc.gov/mods/v3';
protected $cm; protected $cm;
protected $item; protected $item;
protected $pid; protected $pid;
function __construct($pid=null) /**
{ * Constructor
parent::__construct(); * @param type $pid
if ($pid !== null) */
{ function __construct($pid=null) {
module_load_include('inc', 'fedora_repository', 'ContentModel'); parent::__construct();
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); if ($pid !== null) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
$this->pid=$pid; module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$this->cm = ContentModel::loadFromObject($pid);
$this->item = new fedora_item($pid); $this->pid = $pid;
} $this->cm = ContentModel::loadFromObject($pid);
} $this->item = new fedora_item($pid);
}
function handleEditMetadataForm(&$form_id, &$form_values, &$soap_client) }
{
/**
* Handle Edit Metadata Form ???
* @param &$form_id
* @param &$form_values
* @param &$soap_client
*/
function handleEditMetadataForm(&$form_id, &$form_values, &$soap_client) {
$dom = new DomDocument("1.0", "UTF-8"); $dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
$mods = $this->modsFromForm($form_values,$dom); $mods = $this->modsFromForm($form_values, $dom);
$dom->appendChild($mods); $dom->appendChild($mods);
if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) { if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) {
drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid'=>$this->pid))); drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid' => $this->pid)));
} }
drupal_goto('/fedora/repository/'.$this->pid); drupal_goto('/fedora/repository/' . $this->pid);
} }
function buildEditMetadataForm() /**
{ * Build Edit Metadata Form
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time. * @return array
$form['indicator2'] = array( */
'#type' => 'fieldset', function buildEditMetadataForm() {
'#title' => t('Edit metadata'), $form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
); $form['indicator2'] = array(
'#type' => 'fieldset',
'#title' => t('Edit metadata'),
);
if ($this->cm !== FALSE && $this->item != NULL) { if ($this->cm !== FALSE && $this->item != NULL) {
$form['pid'] = array('#type'=>'hidden','#value'=>$this->pid); $form['pid'] = array('#type' => 'hidden', '#value' => $this->pid);
$elements = $this->cm->getIngestFormElements(); $elements = $this->cm->getIngestFormElements();
$content = $this->item->get_datastream_dissemination('MODS'); $content = $this->item->get_datastream_dissemination('MODS');
if (trim($content) != '') { if (trim($content) != '') {
$dom = DOMDocument::loadXML($content); $dom = DOMDocument::loadXML($content);
$xpath = new DOMXPath($dom); $xpath = new DOMXPath($dom);
// Register the php: namespace (required) // Register the php: namespace (required)
$xpath->registerNamespace("php", "http://php.net/xpath"); $xpath->registerNamespace("php", "http://php.net/xpath");
// Register PHP functions (no restrictions) // Register PHP functions (no restrictions)
$xpath->registerPHPFunctions(); $xpath->registerPHPFunctions();
foreach ($elements as $element) { foreach ($elements as $element) {
$el = array( $el = array(
'#title' => $element['label'], '#title' => $element['label'],
'#required' => ($element['required'] ? 1 : 0), '#required' => ($element['required'] ? 1 : 0),
'#description' => $element['description'], '#description' => $element['description'],
'#type' => $element['type'] '#type' => $element['type']
); );
$includeEl = true; $includeEl = true;
$elname = explode('][', $element['name']); $elname = explode('][', $element['name']);
$elLocation = &$form['indicator2']; $elLocation = &$form['indicator2'];
while (isset($elLocation[$name[0]]) && ($partial = array_shift($elname)) != NULL) { while (isset($elLocation[$name[0]]) && ($partial = array_shift($elname)) != NULL) {
$elLocation = &$elLocation[$partial]; $elLocation = &$elLocation[$partial];
} }
foreach ($element['parameters'] as $key => $val) { foreach ($element['parameters'] as $key => $val) {
switch ($key) { switch ($key) {
case '#autocomplete_path': case '#autocomplete_path':
$val .= '/'. $form_values['storage']['collection_pid']; $val .= '/' . $form_values['storage']['collection_pid'];
break; break;
case '#exclude_from_edit_metadata': case '#exclude_from_edit_metadata':
$includeEl=FALSE; $includeEl = FALSE;
break; break;
case '#edit_metadata_xpath': case '#edit_metadata_xpath':
$nodeList = $xpath->evaluate($val); $nodeList = $xpath->evaluate($val);
// echo $val. ' '.$nodeList->length.' '; // echo $val. ' '.$nodeList->length.' ';
// echo $nodeList->item(0)->nodeValue.' '; // echo $nodeList->item(0)->nodeValue.' ';
// echo '<br/>'; // echo '<br/>';
if (is_string($nodeList)) if (is_string($nodeList)) {
{ $el['#default_value'] = $nodeList;
$el['#default_value']=$nodeList; }
} else if ($nodeList->length > 1) else if ($nodeList->length > 1) {
{ $el['#default_value'] = array();
$el['#default_value'] = array(); foreach ($nodeList as $node) {
foreach ($nodeList as $node) $el['#default_value'][] = $node->nodeValue;
{ }
$el['#default_value'][] = $node->nodeValue; }
} else if ($nodeList->length > 0) {
} else if ($nodeList->length > 0) if ($el['#type'] == 'list') {
{ $values = array();
if ($el['#type'] == 'list') { for ($i = 0; $i < $nodeList->length; $i++) {
$values=array(); $values[] = $nodeList->item($i)->nodeValue;
for ($i=0;$i<$nodeList->length;$i++) { }
$values[]=$nodeList->item($i)->nodeValue; $el['#default_value'] = join('; ', $values);
} }
$el['#default_value']=join('; ',$values); else {
} else { $el['#default_value'] = $nodeList->item(0)->nodeValue;
$el['#default_value'] = $nodeList->item(0)->nodeValue; }
} }
} break;
break; }
}
if ($key != '#sticky') {
if ($key != '#sticky') { $el[$key] = $val;
$el[$key]=$val; }
} }
} if ($element['type'] == 'people') {
if ($element['type'] == 'people') $names = $xpath->evaluate('/mods:mods/mods:name');
{ $people = array();
foreach ($names as $mname) {
$names = $xpath->evaluate('/mods:mods/mods:name');
$people=array(); $type = $mname->getAttribute('type');
foreach ($names as $mname) { $role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue;
$type = $mname->getAttribute('type'); $nameParts = $mname->getElementsByTagName('namePart');
$role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue; foreach ($nameParts as $namePart) {
switch ($namePart->getAttribute('type')) {
$nameParts = $mname->getElementsByTagName('namePart'); case 'given': $given = $namePart->nodeValue;
foreach ($nameParts as $namePart) break;
{ case 'family': $family = $namePart->nodeValue;
switch ($namePart->getAttribute('type')) { break;
case 'given': $given = $namePart->nodeValue; break; case 'termsOfAddress': $title = $namePart->nodeValue;
case 'family': $family = $namePart->nodeValue; break; break;
case 'termsOfAddress': $title = $namePart->nodeValue; break; case 'date': $date = $namePart->nodeValue;
case 'date': $date = $namePart->nodeValue; break; break;
default: $name = $namePart->nodeValue; break; default: $name = $namePart->nodeValue;
break;
}
}
$person = array('role' => $role);
switch ($type) {
case 'personal':
if (isset($given) && isset($family) && !isset($name)) {
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
$person['name'] = $name;
$person['date'] = $date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference'] = $name;
$person['date'] = $date;
break;
}
$people[] = $person;
}
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
foreach ($names as $mname) {
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart) {
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue;
break;
case 'family': $family = $namePart->nodeValue;
break;
case 'termsOfAddress': $title = $namePart->nodeValue;
break;
case 'date': $date = $namePart->nodeValue;
break;
default: $name = $namePart->nodeValue;
break;
}
}
$person = array('subject' => 1);
switch ($type) {
case 'personal':
if (isset($given) && isset($family) && !isset($name)) {
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
$person['name'] = $name;
$person['date'] = $date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference'] = $name;
$person['date'] = $date;
break;
}
$people[] = $person;
}
$el['#default_value'] = $people;
} }
}
$person=array('role'=>$role);
switch ($type)
{
case 'personal':
if (isset($given) && isset($family) && !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '.$family;
}
$person['name']=$name;
$person['date']=$date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference']=$name;
$person['date']=$date;
break;
}
$people[]=$person;
}
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
foreach ($names as $mname) {
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart)
{
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue; break;
case 'family': $family = $namePart->nodeValue; break;
case 'termsOfAddress': $title = $namePart->nodeValue; break;
case 'date': $date = $namePart->nodeValue; break;
default: $name = $namePart->nodeValue; break;
}
}
$person=array('subject'=>1);
switch ($type)
{
case 'personal':
if (isset($given) && isset($family) && !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '.$family;
}
$person['name']=$name;
$person['date']=$date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference']=$name;
$person['date']=$date;
break;
}
$people[]=$person;
}
$el['#default_value'] = $people;
}
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options']= isset($element['authoritative_list'])?$element['authoritative_list']:array();
}
if ($includeEl) {
$elLocation[join('][', $elname)] = $el;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_edit_qdc_form_submit'),
'#value' => 'Save Metadata'
);
return $form;
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options'] = isset($element['authoritative_list']) ? $element['authoritative_list'] : array();
}
if ($includeEl) {
$elLocation[join('][', $elname)] = $el;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_edit_qdc_form_submit'),
'#value' => 'Save Metadata'
);
return $form;
} }
} }
}
} /**
* Handle Mods Form
function handleModsForm(&$form_values,&$form_state) { * @param &$form_values
* @param &$form_state
*/
function handleModsForm(&$form_values, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$form_state['storage']['people']=NULL; //clears out old entities for the next run of the formbuilder. $form_state['storage']['people'] = NULL; //clears out old entities for the next run of the formbuilder.
$dom = new DomDocument("1.0", "UTF-8"); $dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
$pid=$form_values['pid']; $pid = $form_values['pid'];
$rootElement = $dom->createElement("foxml:digitalObject"); $rootElement = $dom->createElement("foxml:digitalObject");
$rootElement->setAttribute('VERSION', '1.1'); $rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('PID', "$pid"); $rootElement->setAttribute('PID', "$pid");
@ -257,9 +281,9 @@ class ModsFormBuilder extends FormBuilder {
$collectionPid = $form_values['collection_pid']; $collectionPid = $form_values['collection_pid'];
if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) { if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) {
$collectionName =trim($cp->getName()); $collectionName = trim($cp->getName());
if (trim($collectionName)!='') { if (trim($collectionName) != '') {
$form_values['dc_relation']=$collectionName; $form_values['dc_relation'] = $collectionName;
} }
} }
// Create MODS // Create MODS
@ -276,31 +300,35 @@ class ModsFormBuilder extends FormBuilder {
// echo $dom->saveXML(); exit(); // echo $dom->saveXML(); exit();
try { try {
$object = Fedora_Item::ingest_from_FOXML($dom); $object = Fedora_Item::ingest_from_FOXML($dom);
//for some reason, ingest_from_FOXML does not generate a JMS message //for some reason, ingest_from_FOXML does not generate a JMS message
//I just modify the workflow DS and it sends a JMS message. //I just modify the workflow DS and it sends a JMS message.
$item = new Fedora_Item($object->pid); $item = new Fedora_Item($object->pid);
$item->modify_datastream_by_value( $item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml'); $item->modify_datastream_by_value($item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml');
if (!empty($object->pid)) { if (!empty($object->pid)) {
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/'. $object->pid))), "status"); drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/' . $object->pid))), "status");
} }
if (!empty( $_SESSION['fedora_ingest_files'])) { if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
file_delete($createdFile); file_delete($createdFile);
} }
} }
file_delete($form_values['ingest-file-location']); file_delete($form_values['ingest-file-location']);
} } catch (exception $e) {
catch (exception $e) {
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
return; return;
} }
} }
/**
function createCollectionPolicy($form_values, &$dom, &$rootElement) { * Create Collection Policy ??
* @param $form_values
* @param &$dom
* @param &$rootElement
*/
function createCollectionPolicy($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']); $model = new fedora_item($form_values['content_model_pid']);
$ds_list = $model->get_datastreams_list_as_array(); $ds_list = $model->get_datastreams_list_as_array();
@ -308,8 +336,8 @@ class ModsFormBuilder extends FormBuilder {
$cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL'); $cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL');
$cpDom = DOMDocument::loadXML($cp); $cpDom = DOMDocument::loadXML($cp);
$cpRootEl = $cpDom->getElementsByTagName('collection_policy'); $cpRootEl = $cpDom->getElementsByTagName('collection_policy');
if ($cpRootEl->length >0) { if ($cpRootEl->length > 0) {
$cpRootEl=$cpRootEl->item(0); $cpRootEl = $cpRootEl->item(0);
$newNode = $dom->importNode($cpRootEl, TRUE); $newNode = $dom->importNode($cpRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
@ -329,6 +357,12 @@ class ModsFormBuilder extends FormBuilder {
} }
} }
/**
* Create Workflow Stream ??
* @param $form_values
* @param &$dom
* @param &$rootElement
*/
function createWorkflowStream($form_values, &$dom, &$rootElement) { function createWorkflowStream($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']); $model = new fedora_item($form_values['content_model_pid']);
@ -337,8 +371,8 @@ class ModsFormBuilder extends FormBuilder {
$workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL'); $workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL');
$workflowDom = DOMDocument::loadXML($workflow); $workflowDom = DOMDocument::loadXML($workflow);
$workflowRootEl = $workflowDom->getElementsByTagName('workflow'); $workflowRootEl = $workflowDom->getElementsByTagName('workflow');
if ($workflowRootEl->length >0) { if ($workflowRootEl->length > 0) {
$workflowRootEl=$workflowRootEl->item(0); $workflowRootEl = $workflowRootEl->item(0);
$newNode = $dom->importNode($workflowRootEl, TRUE); $newNode = $dom->importNode($workflowRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
@ -358,6 +392,12 @@ class ModsFormBuilder extends FormBuilder {
} }
} }
/**
* Create mods Stream ??
* @param $form_values
* @param &$dom
* @param &$rootElement
*/
function createModsStream($form_values, &$dom, &$rootElement) { function createModsStream($form_values, &$dom, &$rootElement) {
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
@ -372,17 +412,21 @@ class ModsFormBuilder extends FormBuilder {
$content = $dom->createElement("foxml:xmlContent"); $content = $dom->createElement("foxml:xmlContent");
$version->appendChild($content); $version->appendChild($content);
$mods = $this->modsFromForm($form_values,$dom); $mods = $this->modsFromForm($form_values, $dom);
$content->appendChild($mods); $content->appendChild($mods);
$rootElement->appendChild($datastream); $rootElement->appendChild($datastream);
} }
/**
* Mods From From ?????
* @param type $form_values
* @param type $dom
* @return type
*/
function modsFromForm(&$form_values, &$dom) {
function modsFromForm(&$form_values,&$dom) ///begin writing MODS
{
///begin writing MODS
$mods = $dom->createElement("mods:mods"); $mods = $dom->createElement("mods:mods");
$mods->setAttribute('version', '3.4'); $mods->setAttribute('version', '3.4');
$mods->setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink"); $mods->setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
@ -393,37 +437,37 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_title']) && trim($form_values['mods_title']) != '') { if (isset($form_values['mods_title']) && trim($form_values['mods_title']) != '') {
$titleinfo = $dom->createElement('mods:titleInfo'); $titleinfo = $dom->createElement('mods:titleInfo');
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_title'])); $title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_title']));
$titleinfo->appendChild($title); $titleinfo->appendChild($title);
$mods->appendChild($titleinfo); $mods->appendChild($titleinfo);
} }
if (isset($form_values['mods_alternative_titles']) && trim($form_values['mods_alternative_titles']) != '') { if (isset($form_values['mods_alternative_titles']) && trim($form_values['mods_alternative_titles']) != '') {
$titles=preg_split('/\s+\;\s+/',trim($form_values['mods_alternative_titles'])); $titles = preg_split('/\s+\;\s+/', trim($form_values['mods_alternative_titles']));
foreach ($titles as $t) { foreach ($titles as $t) {
$titleinfo = $dom->createElement('mods:titleInfo'); $titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ; $titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',$t); $title = $dom->createElement('mods:title', $t);
$titleinfo->appendChild($title); $titleinfo->appendChild($title);
$mods->appendChild($titleinfo); $mods->appendChild($titleinfo);
} }
} }
if (isset($form_values['mods_alternative_title']) && trim($form_values['mods_alternative_title']) != '') { if (isset($form_values['mods_alternative_title']) && trim($form_values['mods_alternative_title']) != '') {
$titleinfo = $dom->createElement('mods:titleInfo'); $titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ; $titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',trim($form_values['mods_alternative_title'])); $title = $dom->createElement('mods:title', trim($form_values['mods_alternative_title']));
$titleinfo->appendChild($title); $titleinfo->appendChild($title);
$mods->appendChild($titleinfo); $mods->appendChild($titleinfo);
} }
if (isset($form_values['mods_description']) && trim($form_values['mods_description']) != '') { if (isset($form_values['mods_description']) && trim($form_values['mods_description']) != '') {
$abstract = $dom->createElement('mods:abstract', htmlspecialchars(trim($form_values['mods_description']))); $abstract = $dom->createElement('mods:abstract', htmlspecialchars(trim($form_values['mods_description'])));
$mods->appendChild($abstract); $mods->appendChild($abstract);
} }
if (isset($form_values['pid']) && trim($form_values['pid']) != '') { if (isset($form_values['pid']) && trim($form_values['pid']) != '') {
$identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/','\/',$form_values['pid'])))); $identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/', '\/', $form_values['pid']))));
$identifier->setAttribute('type', 'hdl'); $identifier->setAttribute('type', 'hdl');
$mods->appendChild($identifier); $mods->appendChild($identifier);
} }
@ -457,7 +501,7 @@ class ModsFormBuilder extends FormBuilder {
$addOriginInfo = FALSE; $addOriginInfo = FALSE;
if (isset($form_values['mods_pubinfo_place']) && trim($form_values['mods_pubinfo_place']) != '') { if (isset($form_values['mods_pubinfo_place']) && trim($form_values['mods_pubinfo_place']) != '') {
$place = $dom->createElement('mods:place'); $place = $dom->createElement('mods:place');
$placeTerm=$dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place']))); $placeTerm = $dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place'])));
$placeTerm->setAttribute('type', 'text'); $placeTerm->setAttribute('type', 'text');
$place->appendChild($placeTerm); $place->appendChild($placeTerm);
$originInfo->appendChild($place); $originInfo->appendChild($place);
@ -479,52 +523,52 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_pubinfo_date']) && trim($form_values['mods_pubinfo_date']) != '' && if (isset($form_values['mods_pubinfo_date']) && trim($form_values['mods_pubinfo_date']) != '' &&
isset($form_values['mods_pubinfo_dateType']) && trim($form_values['mods_pubinfo_dateType']) != '') { isset($form_values['mods_pubinfo_dateType']) && trim($form_values['mods_pubinfo_dateType']) != '') {
if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) { if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) {
$date = $dom->createElement('mods:'. trim($form_values['mods_pubinfo_dateType']) .'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date']))); $date = $dom->createElement('mods:' . trim($form_values['mods_pubinfo_dateType']) . 'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
} }
else { else {
//how to handle other types? otherDate? //how to handle other types? otherDate?
$date= $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date']))); $date = $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType']))); $date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType'])));
} }
$originInfo->appendChild($date); $originInfo->appendChild($date);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} else { }
else {
if (isset($form_values['mods_createdDate'])) { if (isset($form_values['mods_createdDate'])) {
$date = $dom->createElement('mods:createdDate',htmlspecialchars(trim($form_values['mods_createdDate']))); $date = $dom->createElement('mods:createdDate', htmlspecialchars(trim($form_values['mods_createdDate'])));
$originInfo->appendChild($date); $originInfo->appendChild($date);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} }
if (isset($form_values['mods_issuedDate'])) { if (isset($form_values['mods_issuedDate'])) {
$date = $dom->createElement('mods:issuedDate',htmlspecialchars(trim($form_values['mods_issuedDate']))); $date = $dom->createElement('mods:issuedDate', htmlspecialchars(trim($form_values['mods_issuedDate'])));
$originInfo->appendChild($date); $originInfo->appendChild($date);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} }
if (isset($form_values['mods_copyrightDate'])) { if (isset($form_values['mods_copyrightDate'])) {
$date = $dom->createElement('mods:copyrightDate',htmlspecialchars(trim($form_values['mods_copyrightDate']))); $date = $dom->createElement('mods:copyrightDate', htmlspecialchars(trim($form_values['mods_copyrightDate'])));
$originInfo->appendChild($date); $originInfo->appendChild($date);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} }
if (isset($form_values['mods_capturedDate'])) { if (isset($form_values['mods_capturedDate'])) {
$date = $dom->createElement('mods:capturedDate',htmlspecialchars(trim($form_values['mods_capturedDate']))); $date = $dom->createElement('mods:capturedDate', htmlspecialchars(trim($form_values['mods_capturedDate'])));
$originInfo->appendChild($date); $originInfo->appendChild($date);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} }
} }
if (isset($form_values['mods_pubinfo_journalFreq']) && trim($form_values['mods_pubinfo_journalFreq']) != '') { if (isset($form_values['mods_pubinfo_journalFreq']) && trim($form_values['mods_pubinfo_journalFreq']) != '') {
$frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq']))); $frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq'])));
$originInfo->appendChild($frequency); $originInfo->appendChild($frequency);
$issuance= $dom->createElement('mods:issuance', 'journal'); $issuance = $dom->createElement('mods:issuance', 'journal');
$originInfo->appendChild($issuance); $originInfo->appendChild($issuance);
$addOriginInfo = TRUE; $addOriginInfo = TRUE;
} }
elseif (isset($form_values['mods_pubinfo_journalFreq'])) { elseif (isset($form_values['mods_pubinfo_journalFreq'])) {
$issuance= $dom->createElement('mods:issuance', 'monographic'); $issuance = $dom->createElement('mods:issuance', 'monographic');
$originInfo->appendChild($issuance); $originInfo->appendChild($issuance);
} }
@ -540,7 +584,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_caption']) && trim($form_values['mods_caption']) != '') { if (isset($form_values['mods_caption']) && trim($form_values['mods_caption']) != '') {
$note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption']))); $note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption'])));
$note->setAttribute('type','caption'); $note->setAttribute('type', 'caption');
$mods->appendChild($note); $mods->appendChild($note);
} }
@ -550,16 +594,14 @@ class ModsFormBuilder extends FormBuilder {
} }
if (isset($form_values['mods_language']) && trim($form_values['mods_language']) != '') if (isset($form_values['mods_language']) && trim($form_values['mods_language']) != '') {
{
$languageList = explode(';', htmlspecialchars($form_values['mods_language'])); $languageList = explode(';', htmlspecialchars($form_values['mods_language']));
foreach ($languageList as $lang) foreach ($languageList as $lang) {
{ $language = $dom->createElement('mods:language');
$language = $dom->createElement('mods:language'); $langTerm = $dom->createElement('mods:languageTerm', htmlspecialchars($lang));
$langTerm = $dom->createElement('mods:languageTerm',htmlspecialchars($lang)); $langTerm->setAttribute('type', 'text');
$langTerm->setAttribute('type','text'); $language->appendChild($langTerm);
$language->appendChild($langTerm); $mods->appendChild($language);
$mods->appendChild($language);
} }
} }
@ -573,7 +615,7 @@ class ModsFormBuilder extends FormBuilder {
$hasSubject = TRUE; $hasSubject = TRUE;
$geographic = $dom->createElement('mods:hierarchicalGeographic'); $geographic = $dom->createElement('mods:hierarchicalGeographic');
$country=$dom->createElement('mods:country', htmlspecialchars($form_values['mods_country'])); $country = $dom->createElement('mods:country', htmlspecialchars($form_values['mods_country']));
$geographic->appendChild($country); $geographic->appendChild($country);
if (isset($form_values['mods_province']) && trim($form_values['mods_province']) != '') { if (isset($form_values['mods_province']) && trim($form_values['mods_province']) != '') {
@ -608,7 +650,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_subjtitle']) && trim($form_values['mods_subjtitle']) != '') { if (isset($form_values['mods_subjtitle']) && trim($form_values['mods_subjtitle']) != '') {
$hasSubject = TRUE; $hasSubject = TRUE;
$titleInfo= $dom->createElement('mods:titleInfo'); $titleInfo = $dom->createElement('mods:titleInfo');
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle'])); $title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle']));
$titleInfo->appendChild($title); $titleInfo->appendChild($title);
$subject->appendChild($titleInfo); $subject->appendChild($titleInfo);
@ -633,23 +675,22 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_cc']['cc']) && $form_values['mods_cc']['cc']['cc_enable']) { if (isset($form_values['mods_cc']['cc']) && $form_values['mods_cc']['cc']['cc_enable']) {
$commercial = trim($form_values['mods_cc']['cc']['cc_commercial']); $commercial = trim($form_values['mods_cc']['cc']['cc_commercial']);
$modifications = trim($form_values['mods_cc']['cc']['cc_modifications']); $modifications = trim($form_values['mods_cc']['cc']['cc_modifications']);
$jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']); $jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']);
module_load_include('inc','islandora_form_elements','includes/creative_commons.inc'); // Include islandora form elements only if needed ??
module_load_include('inc', 'islandora_form_elements', 'includes/creative_commons.inc');
if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction])) if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction]))
$jurisdiction=''; $jurisdiction = '';
$version = CreativeCommons::$cc_versions[$jurisdiction]; $version = CreativeCommons::$cc_versions[$jurisdiction];
$license = 'by'. ($commercial != ''?'-'.$commercial:'') . ($modifications != ''?'-'.$modifications:'') . '/' . $version . '/'.($jurisdiction != ''?$jurisdiction.'/':'') ; $license = 'by' . ($commercial != '' ? '-' . $commercial : '') . ($modifications != '' ? '-' . $modifications : '') . '/' . $version . '/' . ($jurisdiction != '' ? $jurisdiction . '/' : '');
$accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license)); $accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license));
$accessCondition->setAttribute('type', 'Creative Commons License'); $accessCondition->setAttribute('type', 'Creative Commons License');
$mods->appendChild($accessCondition); $mods->appendChild($accessCondition);
} }
if (isset($form_values['mods_rights']) && trim($form_values['mods_rights']) != '') { if (isset($form_values['mods_rights']) && trim($form_values['mods_rights']) != '') {
@ -658,59 +699,59 @@ class ModsFormBuilder extends FormBuilder {
$mods->appendChild($accessCondition); $mods->appendChild($accessCondition);
} }
if (isset($form_values['mods_people']) && isset($form_values['mods_people']['people']) && is_array($form_values['mods_people']['people']) ) { if (isset($form_values['mods_people']) && isset($form_values['mods_people']['people']) && is_array($form_values['mods_people']['people'])) {
foreach ($form_values['mods_people']['people'] as $key => $val) { foreach ($form_values['mods_people']['people'] as $key => $val) {
$name = $dom->createElement('mods:name'); $name = $dom->createElement('mods:name');
$appendName=FALSE; $appendName = FALSE;
if (isset($val['role'])) { if (isset($val['role'])) {
$role = $dom->createElement('mods:role'); $role = $dom->createElement('mods:role');
$roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role']))); $roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role'])));
$roleTerm->setAttribute('type', 'text'); $roleTerm->setAttribute('type', 'text');
$roleTerm->setAttribute('authority', 'marcrelator'); $roleTerm->setAttribute('authority', 'marcrelator');
$role->appendChild($roleTerm); $role->appendChild($roleTerm);
$name->appendChild($role); $name->appendChild($role);
} }
if (isset($val['organization'])) { if (isset($val['organization'])) {
$name->setAttribute('type', 'organization'); $name->setAttribute('type', 'organization');
if (trim($val['organization']) != '') { if (trim($val['organization']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization']))); $namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization'])));
$name->appendChild($namePart); $name->appendChild($namePart);
$appendName=TRUE; $appendName = TRUE;
} }
} }
elseif (isset($val['conference'])) { elseif (isset($val['conference'])) {
$name->setAttribute('type', 'conference'); $name->setAttribute('type', 'conference');
if (trim($val['conference']) != '') { if (trim($val['conference']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference']))); $namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference'])));
$name->appendChild($namePart); $name->appendChild($namePart);
$appendName=TRUE; $appendName = TRUE;
} }
} }
else { else {
$name->setAttribute('type', 'personal'); $name->setAttribute('type', 'personal');
if (trim($val['name']) != '') { if (trim($val['name']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['name']))); $namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['name'])));
$name->appendChild($namePart); $name->appendChild($namePart);
$appendName=TRUE; $appendName = TRUE;
} }
} }
if (isset($val['date'])) { if (isset($val['date'])) {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['date']))); $namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['date'])));
$namePart->setAttribute('type','date'); $namePart->setAttribute('type', 'date');
$name->appendChild($namePart); $name->appendChild($namePart);
} }
if ($appendName) { if ($appendName) {
if (isset($val['subject'])) { if (isset($val['subject'])) {
$subject->appendChild($name); $subject->appendChild($name);
$hasSubject=TRUE; $hasSubject = TRUE;
} else { }
else {
$mods->appendChild($name); $mods->appendChild($name);
} }
} }
} }
} }

78
plugins/PersonalCollectionClass.inc

@ -1,11 +1,31 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* PersonalCollectionClass class
*/
/**
* Personal Collection Class
*/
class PersonalCollectionClass { class PersonalCollectionClass {
/**
* Constructor
*/
function PersonalCollectionClass() { function PersonalCollectionClass() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} }
/**
* Create collection
* @param type $theUser
* @param type $pid
* @param type $soapClient
* @return type
*/
function createCollection($theUser, $pid, $soapClient) { function createCollection($theUser, $pid, $soapClient) {
$dom = new DomDocument("1.0", "UTF-8"); $dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE; $dom->formatOutput = TRUE;
@ -23,34 +43,38 @@ class PersonalCollectionClass {
$value = $this->createPolicyStream($theUser, $dom, $rootElement); $value = $this->createPolicyStream($theUser, $dom, $rootElement);
if (!$value) { if (!$value) {
return FALSE;//error should already be logged. return FALSE; //error should already be logged.
} }
$this->createCollectionPolicyStream($theUser, $dom, $rootElement); $this->createCollectionPolicyStream($theUser, $dom, $rootElement);
try { try {
$params = array( $params = array(
'objectXML' => $dom->saveXML(), 'objectXML' => $dom->saveXML(),
'format' => "foxml1.0", 'format' => "foxml1.0",
'logMessage' => "Fedora object ingested", 'logMessage' => "Fedora object ingested",
); );
$object = $soapClient->__soapCall('ingest', array( $object = $soapClient->__soapCall('ingest', array(
$params $params
)); ));
} catch (exception $e) {
}
catch (exception $e) {
drupal_set_message(t('Error ingesting personal collection object: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Error ingesting personal collection object: !e', array('!e' => $e->getMessage())), 'error');
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/**
* Create Collection Policy Stream ??
* @param type $user
* @param type $dom
* @param type $rootElement
* @return type
*/
function createCollectionPolicyStream($user, $dom, $rootElement) { function createCollectionPolicyStream($user, $dom, $rootElement) {
$collectionTemplate = file_get_contents(drupal_get_path('module', 'Fedora_Repository') . '/collection_policies/PERSONAL-COLLECTION-POLICY.xml'); $collectionTemplate = file_get_contents(drupal_get_path('module', 'Fedora_Repository') . '/collection_policies/PERSONAL-COLLECTION-POLICY.xml');
try { try {
$xml = new SimpleXMLElement($collectionTemplate); $xml = new SimpleXMLElement($collectionTemplate);
} } catch (Exception $e) {
catch (Exception $e) {
watchdog(t("Fedora_Repository"), t("Problem creating personal collection policy, could not parse collection policy stream."), NULL, WATCHDOG_ERROR); watchdog(t("Fedora_Repository"), t("Problem creating personal collection policy, could not parse collection policy stream."), NULL, WATCHDOG_ERROR);
drupal_set_message(t('Problem creating personal collection policy, could not parse collection policy stream: !e', array('!e' => $e->getMessage())), 'error'); drupal_set_message(t('Problem creating personal collection policy, could not parse collection policy stream: !e', array('!e' => $e->getMessage())), 'error');
return FALSE; return FALSE;
@ -88,6 +112,13 @@ class PersonalCollectionClass {
return TRUE; return TRUE;
} }
/**
* Create Policy Stream ??
* @param type $user
* @param type $dom
* @param type $rootElement
* @return type
*/
function createPolicyStream($user, $dom, $rootElement) { function createPolicyStream($user, $dom, $rootElement) {
module_load_include('inc', 'fedora_repository', 'SecurityClass'); module_load_include('inc', 'fedora_repository', 'SecurityClass');
@ -114,8 +145,14 @@ class PersonalCollectionClass {
return $this->createChildPolicyStream($dom, $rootElement, $policyStream->cloneNode(TRUE)); return $this->createChildPolicyStream($dom, $rootElement, $policyStream->cloneNode(TRUE));
} }
//right now this is the same as the policy stream for this object, may change /**
//objects in this collection will reference this datastream as their own POLICY stream * right now this is the same as the policy stream for this object, may change
* objects in this collection will reference this datastream as their own POLICY stream ???
* @param type $dom
* @param type $rootElement
* @param type $policyStream
* @return type
*/
function createChildPolicyStream($dom, $rootElement, $policyStream) { function createChildPolicyStream($dom, $rootElement, $policyStream) {
$ds1 = $dom->createElement("foxml:datastream"); $ds1 = $dom->createElement("foxml:datastream");
@ -135,8 +172,14 @@ class PersonalCollectionClass {
return TRUE; return TRUE;
} }
/**
* Create standard fedora stuff ??????????????????
* @param type $user
* @param type $dom
* @param type $rootElement
*/
function createStandardFedoraStuff($user, & $dom, & $rootElement) { function createStandardFedoraStuff($user, & $dom, & $rootElement) {
/*foxml object properties section */ /* foxml object properties section */
$objproperties = $dom->createElement("foxml:objectProperties"); $objproperties = $dom->createElement("foxml:objectProperties");
$prop1 = $dom->createElement("foxml:property"); $prop1 = $dom->createElement("foxml:property");
$prop1->setAttribute("NAME", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); $prop1->setAttribute("NAME", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
@ -161,6 +204,13 @@ class PersonalCollectionClass {
$rootElement->appendChild($objproperties); $rootElement->appendChild($objproperties);
} }
/**
* Create DC Stream ???
* @global type $user
* @param type $theUser
* @param type $dom
* @param type $rootElement
*/
function createDCStream($theUser, & $dom, & $rootElement) { function createDCStream($theUser, & $dom, & $rootElement) {
global $user; global $user;
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");

143
plugins/QtFormBuilder.php

@ -1,76 +1,86 @@
<?php <?php
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/*
*
*
*
* implements methods from content model ingest form xml
* builds a dc metadata form
*/
class QtFormBuilder extends FormBuilder{
function QtFormBuilder(){
module_load_include('php', 'Fedora_Repository', 'plugins/FormBuilder');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
} // $Id$
/* /**
* method overrides method in FormBuilder. We changed the dsid from OBJ to OBJ and added the TN datastream * @file
* QTFormBuilder class
*/ */
function createFedoraDataStreams($form_values,&$dom, &$rootElement){ module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
module_load_include('inc', 'fedora_repository', 'MimeClass');
global $base_url;
$mimetype = new MimeClass();
$server=null;
$file=$form_values['ingest-file-location'];
$dformat = $mimetype->getType($file);
//$fileUrl = 'http://'.$_SERVER['HTTP_HOST'].$file;
$fileUrl = $base_url.'/'.drupal_urlencode($file);
$beginIndex = strrpos($fileUrl,'/');
$dtitle = substr($fileUrl,$beginIndex+1);
$dtitle = substr($dtitle, 0, strpos($dtitle, "."));
$ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID","OBJ");
$ds1->setAttribute("STATE","A");
$ds1->setAttribute("CONTROL_GROUP","M");
$ds1v= $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID","OBJ.0");
$ds1v->setAttribute("MIMETYPE","$dformat");
$ds1v->setAttribute("LABEL","$dtitle");
$ds1content = $dom->createElement('foxml:contentLocation');
$ds1content->setAttribute("REF","$fileUrl");
$ds1content->setAttribute("TYPE","URL");
$ds1->appendChild($ds1v);
$ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1);
if(empty($_SESSION['fedora_ingest_files']) || !isset($_SESSION['fedora_ingest_files']['TN'])) { /**
$createdFile = drupal_get_path('module', 'Fedora_Repository').'/images/qtThumb.jpg'; * Implements methods from content model ingest form xml
$fileUrl = $base_url.'/'.drupal_urlencode($createdFile);//'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile; * builds a dc metadata form
$ds1 = $dom->createElement("foxml:datastream"); */
$ds1->setAttribute("ID","TN"); class QtFormBuilder extends FormBuilder {
$ds1->setAttribute("STATE","A");
$ds1->setAttribute("CONTROL_GROUP","M"); /**
$ds1v= $dom->createElement("foxml:datastreamVersion"); * Constructor
$ds1v->setAttribute("ID","TN.0"); */
$ds1v->setAttribute("MIMETYPE","image/jpeg"); function QtFormBuilder() {
$ds1v->setAttribute("LABEL","Thumbnail"); module_load_include('php', 'Fedora_Repository', 'plugins/FormBuilder');
$ds1content = $dom->createElement('foxml:contentLocation'); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$ds1content->setAttribute("REF","$fileUrl"); }
$ds1content->setAttribute("TYPE","URL");
$ds1->appendChild($ds1v);
$ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1);
}
if (!empty($_SESSION['fedora_ingest_files'])) { /**
* method overrides method in FormBuilder. We changed the dsid from OBJ to OBJ and added the TN datastream
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
global $base_url;
$mimetype = new MimeClass();
$server = null;
$file = $form_values['ingest-file-location'];
$dformat = $mimetype->getType($file);
//$fileUrl = 'http://'.$_SERVER['HTTP_HOST'].$file;
$fileUrl = $base_url . '/' . drupal_urlencode($file);
$beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = substr($dtitle, 0, strpos($dtitle, "."));
$ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "OBJ");
$ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "OBJ.0");
$ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle");
$ds1content = $dom->createElement('foxml:contentLocation');
$ds1content->setAttribute("REF", "$fileUrl");
$ds1content->setAttribute("TYPE", "URL");
$ds1->appendChild($ds1v);
$ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1);
if (empty($_SESSION['fedora_ingest_files']) || !isset($_SESSION['fedora_ingest_files']['TN'])) {
$createdFile = drupal_get_path('module', 'Fedora_Repository') . '/images/qtThumb.jpg';
$fileUrl = $base_url . '/' . drupal_urlencode($createdFile); //'http://'.$_SERVER['HTTP_HOST'].'/'.$createdFile;
$ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "TN");
$ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "TN.0");
$ds1v->setAttribute("MIMETYPE", "image/jpeg");
$ds1v->setAttribute("LABEL", "Thumbnail");
$ds1content = $dom->createElement('foxml:contentLocation');
$ds1content->setAttribute("REF", "$fileUrl");
$ds1content->setAttribute("TYPE", "URL");
$ds1->appendChild($ds1v);
$ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1);
}
if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
$createdFile = strstr($createdFile, $file); $createdFile = strstr($createdFile, $file);
$dformat = $mimetype->getType($createdFile); $dformat = $mimetype->getType($createdFile);
$fileUrl = $base_url . '/'. drupal_urlencode($createdFile); $fileUrl = $base_url . '/' . drupal_urlencode($createdFile);
$beginIndex = strrpos($fileUrl, '/'); $beginIndex = strrpos($fileUrl, '/');
$dtitle = substr($fileUrl, $beginIndex + 1); $dtitle = substr($fileUrl, $beginIndex + 1);
$dtitle = urldecode($dtitle); $dtitle = urldecode($dtitle);
@ -79,7 +89,7 @@ if(empty($_SESSION['fedora_ingest_files']) || !isset($_SESSION['fedora_ingest_fi
$ds1->setAttribute("ID", "$dsid"); $ds1->setAttribute("ID", "$dsid");
$ds1->setAttribute("STATE", "A"); $ds1->setAttribute("STATE", "A");
$ds1->setAttribute("CONTROL_GROUP", "M"); $ds1->setAttribute("CONTROL_GROUP", "M");
$ds1v= $dom->createElement("foxml:datastreamVersion"); $ds1v = $dom->createElement("foxml:datastreamVersion");
$ds1v->setAttribute("ID", "$dsid.0"); $ds1v->setAttribute("ID", "$dsid.0");
$ds1v->setAttribute("MIMETYPE", "$dformat"); $ds1v->setAttribute("MIMETYPE", "$dformat");
$ds1v->setAttribute("LABEL", "$dtitle"); $ds1v->setAttribute("LABEL", "$dtitle");
@ -91,12 +101,7 @@ if(empty($_SESSION['fedora_ingest_files']) || !isset($_SESSION['fedora_ingest_fi
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
} }
} }
}
}
}
}
?> ?>

146
plugins/Refworks.inc

@ -1,29 +1,43 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on 26-Feb-08 * @file
* * Refworks class
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ */
module_load_include('inc', 'fedora_repository', 'SecurityClass'); module_load_include('inc', 'fedora_repository', 'SecurityClass');
/**
* Refworks class ???
*/
class Refworks { class Refworks {
private $romeoUrlString = ""; private $romeoUrlString = "";
private $referenceList; private $referenceList;
private $securityHelper; private $securityHelper;
private $collectionPolicyStream; private $collectionPolicyStream;
private $issn = ''; private $issn = '';
/**
* Constructor
*/
function Refworks() { function Refworks() {
$this->romeoUrlString = "http://www.sherpa.ac.uk/romeo/api24.php?issn="; $this->romeoUrlString = "http://www.sherpa.ac.uk/romeo/api24.php?issn=";
} }
function buildForm( &$form, $ingest_form_definition, &$form_values) { /**
* Build Form ??
* @param type $form
* @param type $ingest_form_definition
* @param type $form_values
* @return type
*/
function buildForm(&$form, $ingest_form_definition, &$form_values) {
$form['indicator2'] = array( $form['indicator2'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Ingest digital object step #2'), '#title' => t('Ingest digital object step #2'),
); );
foreach ($ingest_form_definition->form_elements->element as $element) { foreach ($ingest_form_definition->form_elements->element as $element) {
$name = strip_tags($element->name->asXML()); $name = strip_tags($element->name->asXML());
@ -39,11 +53,11 @@ class Refworks {
$type = strip_tags($element->type->asXML()); $type = strip_tags($element->type->asXML());
$form['indicator2']["$name"] = array( $form['indicator2']["$name"] = array(
'#title' => $title, '#title' => $title,
'#required' => $required, '#required' => $required,
'#description' => $description, '#description' => $description,
'#prefix' => $prefix, '#prefix' => $prefix,
'#type' => $type '#type' => $type
); );
} }
@ -68,21 +82,26 @@ class Refworks {
//$xml=simplexml_load_string(trim(file_get_contents($file),NULL,TRUE)); //$xml=simplexml_load_string(trim(file_get_contents($file),NULL,TRUE));
//$dom = dom_import_simplexml($xml);//test to see if it behaves better //$dom = dom_import_simplexml($xml);//test to see if it behaves better
//$xml = new SimpleXMLElement(trim(file_get_contents($file))); //$xml = new SimpleXMLElement(trim(file_get_contents($file)));
} } catch (Exception $e) {
catch (Exception $e) {
drupal_set_message(t('Error processing Refworks file: ') . $e->getMessage()); drupal_set_message(t('Error processing Refworks file: ') . $e->getMessage());
return FALSE; return FALSE;
} }
$this->referenceList = array(); $this->referenceList = array();
foreach ($xml->reference as $reference) { foreach ($xml->reference as $reference) {
array_push( $this->referenceList, $reference ); array_push($this->referenceList, $reference);
} }
return $this->referenceList; return $this->referenceList;
} }
//create A DC stream with ID of DC /**
function createQDCStream( &$dom, &$rootElement, $reference ) { * Create a DC stream with ID of DC ???
* @param type $dom
* @param type $rootElement
* @param type $reference
* @return type
*/
function createQDCStream(&$dom, &$rootElement, $reference) {
$datastream = $dom->createElement("foxml:datastream"); $datastream = $dom->createElement("foxml:datastream");
$datastream->setAttribute("ID", "DC"); $datastream->setAttribute("ID", "DC");
$datastream->setAttribute("STATE", "A"); $datastream->setAttribute("STATE", "A");
@ -126,19 +145,19 @@ class Refworks {
$oai->appendChild($element); $oai->appendChild($element);
} }
foreach ($reference->vo as $value) { foreach ($reference->vo as $value) {
$source .= ' Volume: '. $value; $source .= ' Volume: ' . $value;
} }
foreach ($reference->is as $value) { foreach ($reference->is as $value) {
$source .= ' Issue: '. $value; $source .= ' Issue: ' . $value;
} }
foreach ($reference->sp as $value) { foreach ($reference->sp as $value) {
$source .= ' Start Page: '. $value; $source .= ' Start Page: ' . $value;
} }
foreach ($reference->op as $value) { foreach ($reference->op as $value) {
$source .= ' Other Pages: '. $value; $source .= ' Other Pages: ' . $value;
} }
foreach ($reference->ul as $value) { foreach ($reference->ul as $value) {
$source .= ' URL: '. $value; $source .= ' URL: ' . $value;
} }
foreach ($reference->k1 as $value) { foreach ($reference->k1 as $value) {
$element = $dom->createElement('dc:subject', htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8')); $element = $dom->createElement('dc:subject', htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8'));
@ -174,17 +193,17 @@ class Refworks {
$identifier .= ' ISSN/ISBN: ' . $value; $identifier .= ' ISSN/ISBN: ' . $value;
//$this->romeoUrlString = $this->romeoUrlString . $value; //$this->romeoUrlString = $this->romeoUrlString . $value;
if (!$this->issn == '') { if (!$this->issn == '') {
$this->issn=$value; $this->issn = $value;
} }
else { else {
$this->issn .= ','. $value; $this->issn .= ',' . $value;
} }
} }
foreach ($reference->ab as $value) { foreach ($reference->ab as $value) {
$description = ' abstract: '. $value; $description = ' abstract: ' . $value;
} }
foreach ($reference->cr as $value) { foreach ($reference->cr as $value) {
$description .= ' Cited reference: '. $value; $description .= ' Cited reference: ' . $value;
} }
$element = $dom->createElement('dc:description', htmlspecialchars($description, ENT_NOQUOTES, 'UTF-8')); $element = $dom->createElement('dc:description', htmlspecialchars($description, ENT_NOQUOTES, 'UTF-8'));
$oai->appendChild($element); $oai->appendChild($element);
@ -196,7 +215,12 @@ class Refworks {
return $datastream; return $datastream;
} }
function handleForm( &$form_values ) { /**
* Handle Form ??
* @param type $form_values
* @return type
*/
function handleForm(&$form_values) {
$errorMessage = NULL; $errorMessage = NULL;
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'ContentModel');
@ -204,10 +228,10 @@ class Refworks {
$contentModelPid = ContentModel::getPidFromIdentifier($form_values['models']); $contentModelPid = ContentModel::getPidFromIdentifier($form_values['models']);
$contentModelDsid = ContentModel::getDSIDFromIdentifier($form_values['models']); $contentModelDsid = ContentModel::getDSIDFromIdentifier($form_values['models']);
$collectionHelper = new CollectionClass(); $collectionHelper = new CollectionClass();
$startTime=time(); $startTime = time();
$collection_pid = $form_values['collection_pid']; $collection_pid = $form_values['collection_pid'];
$this->parse_refworks_item( $form_values ); $this->parse_refworks_item($form_values);
$this->securityHelper = new SecurityClass(); $this->securityHelper = new SecurityClass();
@ -238,11 +262,11 @@ class Refworks {
drupal_set_message(t('Error creating DC for Refworks'), 'error'); drupal_set_message(t('Error creating DC for Refworks'), 'error');
continue; continue;
} }
$item_title=''; $item_title = '';
foreach ($reference->t1 as $value) { foreach ($reference->t1 as $value) {
$item_title .= ' --- '. $value; $item_title .= ' --- ' . $value;
} }
$this->createStandardFedoraStuff($form_values, $dom, $rootElement, $reference ); $this->createStandardFedoraStuff($form_values, $dom, $rootElement, $reference);
$rootElement->appendChild($qdc_element); $rootElement->appendChild($qdc_element);
//create relationships //create relationships
$this->createRelationShips($form_values, $dom, $rootElement, $pid); $this->createRelationShips($form_values, $dom, $rootElement, $pid);
@ -250,14 +274,14 @@ class Refworks {
$this->createFedoraDataStreams($form_values, $dom, $rootElement, $reference); $this->createFedoraDataStreams($form_values, $dom, $rootElement, $reference);
if (!empty ( $this->collectionPolicyStream)) { if (!empty($this->collectionPolicyStream)) {
$this->create_security_policies($dom, $rootElement, $reference); $this->create_security_policies($dom, $rootElement, $reference);
} }
$params = array( $params = array(
'objectXML' => $dom->saveXML(), 'objectXML' => $dom->saveXML(),
'format' => 'info:fedora/fedora-system:FOXML-1.1', 'format' => 'info:fedora/fedora-system:FOXML-1.1',
'logMessage' => "Fedora Object Ingested", 'logMessage' => "Fedora Object Ingested",
); );
try { try {
@ -270,16 +294,15 @@ class Refworks {
return; return;
} }
$object = $client->__soapCall('ingest', array( $object = $client->__soapCall('ingest', array(
$params $params
)); ));
watchdog(t("FEDORA_REPOSITORY"), t("Successfully added repository item !pid - !it", array('!pid' => $pid, '!it' => $item_title)), NULL, WATCHDOG_INFO); watchdog(t("FEDORA_REPOSITORY"), t("Successfully added repository item !pid - !it", array('!pid' => $pid, '!it' => $item_title)), NULL, WATCHDOG_INFO);
$deleteFiles = $form_values['delete_file']; //remove files from drupal file system $deleteFiles = $form_values['delete_file']; //remove files from drupal file system
if ($deleteFiles > 0) { if ($deleteFiles > 0) {
unlink($form_values['fullpath']); unlink($form_values['fullpath']);
} }
} } catch (exception $e) {
catch (exception $e) {
$errors++; $errors++;
$errorMessage = 'yes'; $errorMessage = 'yes';
watchdog(t("FEDORA_REPOSITORY"), t("Error during ingest !it !e", array('!it' => $item_title, '!e' => $e)), NULL, WATCHDOG_ERROR); watchdog(t("FEDORA_REPOSITORY"), t("Error during ingest !it !e", array('!it' => $item_title, '!e' => $e)), NULL, WATCHDOG_ERROR);
@ -287,17 +310,20 @@ class Refworks {
$success++; $success++;
} }
if (isset($errorMessage)) { if (isset($errorMessage)) {
drupal_set_message(t('Error ingesting one or more records! Check Drupal watchdog logs for more info') , 'error'); drupal_set_message(t('Error ingesting one or more records! Check Drupal watchdog logs for more info'), 'error');
} }
$endTime = time(); $endTime = time();
drupal_set_message(t('Successfull ingest of %success records. %errors records failed. Ingest took %seconds seconds', drupal_set_message(t('Successfull ingest of %success records. %errors records failed. Ingest took %seconds seconds', array('%success' => $success - $errors, '%errors' => $errors, '%seconds' => $endTime - $startTime)), 'info');
array('%success' => $success-$errors, '%errors' => $errors, '%seconds' => $endTime-$startTime)) , 'info');
} }
/** /**
* Creates the RELS-EXT for the foxml * Creates the RELS-EXT for the foxml
* @param type $form_values
* @param type $dom
* @param type $rootElement
* @param type $pid
*/ */
function createRelationShips( $form_values, &$dom, &$rootElement, $pid = NULL ) { function createRelationShips($form_values, &$dom, &$rootElement, $pid = NULL) {
$drdf = $dom->createElement("foxml:datastream"); $drdf = $dom->createElement("foxml:datastream");
$drdf->setAttribute("ID", "RELS-EXT"); $drdf->setAttribute("ID", "RELS-EXT");
$drdf->setAttribute("CONTROL_GROUP", "X"); $drdf->setAttribute("CONTROL_GROUP", "X");
@ -326,9 +352,13 @@ class Refworks {
$rdfdesc->appendChild($member); $rdfdesc->appendChild($member);
$rdfdesc->appendChild($model); $rdfdesc->appendChild($model);
$rootElement->appendChild($drdf); $rootElement->appendChild($drdf);
} }
/**
* Create Romeo Datastream
* @param type $dom
* @param type $rootElement
*/
function createRomeoDataStream(&$dom, &$rootElement) { function createRomeoDataStream(&$dom, &$rootElement) {
$ds1 = $dom->createElement("foxml:datastream"); $ds1 = $dom->createElement("foxml:datastream");
$ds1->setAttribute("ID", "ROMEO"); $ds1->setAttribute("ID", "ROMEO");
@ -340,7 +370,7 @@ class Refworks {
$ds1v->setAttribute("LABEL", "ROMEO"); $ds1v->setAttribute("LABEL", "ROMEO");
$ds1content = $dom->createElement('foxml:contentLocation'); $ds1content = $dom->createElement('foxml:contentLocation');
$url = $this->romeoUrlString . $this->issn; $url = $this->romeoUrlString . $this->issn;
$this->issn=''; //clear the issn's for next ingest in case we are doing batch $this->issn = ''; //clear the issn's for next ingest in case we are doing batch
$ds1content->setAttribute("REF", "$url"); $ds1content->setAttribute("REF", "$url");
$ds1content->setAttribute("TYPE", "URL"); $ds1content->setAttribute("TYPE", "URL");
$ds1->appendChild($ds1v); $ds1->appendChild($ds1v);
@ -348,6 +378,14 @@ class Refworks {
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
} }
/**
* Create Fedora Datastream
* @global type $base_url
* @param type $form_values
* @param type $dom
* @param type $rootElement
* @param type $reference
*/
function createFedoraDataStreams($form_values, &$dom, &$rootElement, $reference) { function createFedoraDataStreams($form_values, &$dom, &$rootElement, $reference) {
global $base_url; global $base_url;
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
@ -374,6 +412,10 @@ class Refworks {
/** /**
* Creates the standard foxml properties * Creates the standard foxml properties
* @param type $form_values
* @param type $dom
* @param type $rootElement
* @param type $reference
*/ */
function createStandardFedoraStuff($form_values, &$dom, &$rootElement, $reference) { function createStandardFedoraStuff($form_values, &$dom, &$rootElement, $reference) {
// Foxml object properties section // Foxml object properties section
@ -397,10 +439,9 @@ class Refworks {
$rootElement->appendChild($objproperties); $rootElement->appendChild($objproperties);
} }
/** /**
* Read the list of Users from the U1 field and Roles from the U2 field and add elements * Read the list of Users from the U1 field and Roles from the U2 field and add elements
* to the security policy record for this item, then add the record as the security policy datastream. * to the security policy record for this item, then add the record as the security policy datastream.
* *
* @param array $form_values * @param array $form_values
* @param DOMDocument $dom * @param DOMDocument $dom
@ -417,7 +458,7 @@ class Refworks {
$ds1v->setAttribute("ID", "POLICY.0"); $ds1v->setAttribute("ID", "POLICY.0");
$ds1v->setAttribute("MIMETYPE", "text/xml"); $ds1v->setAttribute("MIMETYPE", "text/xml");
$ds1v->setAttribute("LABEL", "POLICY Record"); $ds1v->setAttribute("LABEL", "POLICY Record");
$ds1content = $dom->createElement( "foxml:xmlContent" ); $ds1content = $dom->createElement("foxml:xmlContent");
$custom_policy = $this->collectionPolicyStream; $custom_policy = $this->collectionPolicyStream;
$allowed_users_and_roles = array(); $allowed_users_and_roles = array();
@ -428,7 +469,7 @@ class Refworks {
array_push($allowed_users_and_roles['users'], $name); array_push($allowed_users_and_roles['users'], $name);
} }
} }
if (empty( $reference->u1)) { if (empty($reference->u1)) {
// If no "u1" value exists, add the currently logged-in user to the item's security policy. // If no "u1" value exists, add the currently logged-in user to the item's security policy.
array_push($allowed_users_and_roles['users'], $user->name); array_push($allowed_users_and_roles['users'], $user->name);
} }
@ -444,6 +485,7 @@ class Refworks {
$ds1v->appendChild($ds1content); $ds1v->appendChild($ds1content);
$rootElement->appendChild($ds1); $rootElement->appendChild($ds1);
$ds1content->appendChild($dom->importNode( dom_import_simplexml($custom_policy_sxe), TRUE)); $ds1content->appendChild($dom->importNode(dom_import_simplexml($custom_policy_sxe), TRUE));
} }
} }

22
plugins/ShowDemoStreamsInFieldSets.inc

@ -1,18 +1,32 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on 17-Apr-08 * @file
* * ShowDemoStreamsInFieldSets class
* */
/**
* Show Demo Streams in Field Sets ???
*/ */
class ShowDemoStreamsInFieldSets { class ShowDemoStreamsInFieldSets {
private $pid = NULL; private $pid = NULL;
/**
* Constructor
* @param type $pid
*/
function ShowDemoStreamsInFieldSets($pid) { function ShowDemoStreamsInFieldSets($pid) {
//drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); //drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$this->pid = $pid; $this->pid = $pid;
} }
/**
* Show Medium Size ??
* @global type $base_url
* @return type
*/
function showMediumSize() { function showMediumSize() {
global $base_url; global $base_url;
$collection_fieldset = array( $collection_fieldset = array(

103
plugins/ShowStreamsInFieldSets.inc

@ -1,15 +1,31 @@
<?php <?php
// $Id$ // $Id$
/* /**
* Created on 17-Apr-08 * @file
* ShowStreamsInFieldSets class
*/
/**
* Show Streams In Field Sets ??
*/ */
class ShowStreamsInFieldSets { class ShowStreamsInFieldSets {
private $pid = NULL; private $pid = NULL;
/**
* Constructor
* @param type $pid
*/
function ShowStreamsInFieldSets($pid) { function ShowStreamsInFieldSets($pid) {
$this->pid = $pid; $this->pid = $pid;
} }
/**
* Show the FLV ??
* @return type
*/
function showFlv() { function showFlv() {
//FLV is the datastream id //FLV is the datastream id
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
@ -17,11 +33,11 @@ class ShowStreamsInFieldSets {
$content = ""; $content = "";
$pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js'; $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/swfobject.js';
drupal_add_js("$pathTojs"); drupal_add_js("$pathTojs");
$content .= '<div id="player'. $this->pid . 'FLV"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>'; $content .= '<div id="player' . $this->pid . 'FLV"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
drupal_add_js('var s1 = new SWFObject("'. $fullPath . '/flash/flvplayer.swf","single","320","240","7"); drupal_add_js('var s1 = new SWFObject("' . $fullPath . '/flash/flvplayer.swf","single","320","240","7");
s1.addParam("allowfullscreen","TRUE"); s1.addParam("allowfullscreen","TRUE");
s1.addVariable("file","'. base_path() . 'fedora/repository/'. $this->pid . '/FLV/FLV.flv"); s1.addVariable("file","' . base_path() . 'fedora/repository/' . $this->pid . '/FLV/FLV.flv");
s1.write("player'. $this->pid . 'FLV");', 'inline', 'footer'); s1.write("player' . $this->pid . 'FLV");', 'inline', 'footer');
$collection_fieldset = array( $collection_fieldset = array(
'#title' => t('Flash Video'), '#title' => t('Flash Video'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
@ -30,30 +46,42 @@ class ShowStreamsInFieldSets {
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/**
* Show the TN ??
* @global type $base_url
* @return type
*/
function showTN() { function showTN() {
global $base_url; global $base_url;
$collection_fieldset = array( $collection_fieldset = array(
'#title' => '', '#title' => '',
'#attributes' => array(), '#attributes' => array(),
'#collapsible' => FALSE, '#collapsible' => FALSE,
'#value' => '<a href="'. $base_url . '/fedora/repository/'. $this->pid . '/OBJ/"><img src="'. $base_url . '/fedora/repository/'. $this->pid . '/TN/TN'.'" /></a>', '#value' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/OBJ/"><img src="' . $base_url . '/fedora/repository/' . $this->pid . '/TN/TN' . '" /></a>',
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/**
// Same as showTN but artinventory stores the image in a dsid of IMAGE instead of OBJ * Same as showTN but artinventory stores the image in a dsid of IMAGE instead of OBJ
* @global type $base_url
* @return type
*/
function showArtInventoryTN() { function showArtInventoryTN() {
global $base_url; global $base_url;
$collection_fieldset = array( $collection_fieldset = array(
'#collapsible' => FALSE, '#collapsible' => FALSE,
'#value' => '<a href="'. $base_url . '/fedora/repository/'. $this->pid . '/IMAGE/image.jpg"><img src="'. $base_url . '/fedora/repository/'. $this->pid . '/TN/TN'. '" /></a>', '#value' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/IMAGE/image.jpg"><img src="' . $base_url . '/fedora/repository/' . $this->pid . '/TN/TN' . '" /></a>',
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/** /**
* Embed Google Docs' PDF viewer into the page. * Embed Google Docs' PDF viewer into the page.
* @global type $base_url
* @global type $base_path
* @global type $user
* @return type
*/ */
function showPDFPreview() { function showPDFPreview() {
global $base_url; global $base_url;
@ -74,14 +102,14 @@ class ShowStreamsInFieldSets {
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
$item = new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
if (key_exists('TN', $item->datastreams)) { if (key_exists('TN', $item->datastreams)) {
$tn_url = $base_url.'/fedora/repository/'.$item->pid.'/TN'; $tn_url = $base_url . '/fedora/repository/' . $item->pid . '/TN';
} }
else { else {
$tn_url = $base_path.drupal_get_path('module', 'fedora_repository').'/images/Crystal_Clear_app_download_manager.png'; $tn_url = $base_path . drupal_get_path('module', 'fedora_repository') . '/images/Crystal_Clear_app_download_manager.png';
} }
$dc_html = $objectHelper->getFormattedDC($item); $dc_html = $objectHelper->getFormattedDC($item);
$dl_link = l('<div style="float:left; padding: 10px"><img src="'.$tn_url.'"><br />View Document</div>', 'fedora/repository/'.$this->pid.'/OBJ', array('html' => TRUE)); $dl_link = l('<div style="float:left; padding: 10px"><img src="' . $tn_url . '"><br />View Document</div>', 'fedora/repository/' . $this->pid . '/OBJ', array('html' => TRUE));
$tabset['first_tab']['tabs']['view'] = array( $tabset['first_tab']['tabs']['view'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
@ -101,19 +129,22 @@ class ShowStreamsInFieldSets {
$tabset['second_tab'] = array( $tabset['second_tab'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('Read Online'), '#title' => t('Read Online'),
'#content' => "<iframe src=\"http://docs.google.com/viewer?url=". $base_url . '/fedora/repository/'. '#content' => "<iframe src=\"http://docs.google.com/viewer?url=" . $base_url . '/fedora/repository/' .
$this->pid . '/OBJ/preview.pdf'. "&embedded=TRUE\" style=\"width:600px; height:500px;\" frameborder=\"0\"></iframe>" $this->pid . '/OBJ/preview.pdf' . "&embedded=TRUE\" style=\"width:600px; height:500px;\" frameborder=\"0\"></iframe>"
); );
// Render the tabset. // Render the tabset.
return $tabset; return $tabset;
} }
/**
* Show QDC ??
* @return type
*/
function showQdc() { function showQdc() {
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
$content=$objectHelper->getQDC($this->pid); $content = $objectHelper->getQDC($this->pid);
$collection_fieldset = array( $collection_fieldset = array(
'#title' => t('Description'), '#title' => t('Description'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
@ -123,29 +154,35 @@ class ShowStreamsInFieldSets {
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/**
* Show Object Link ??
* @global type $base_url
* @return type
*/
function showOBJLink() { function showOBJLink() {
global $base_url; global $base_url;
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($this->pid); $item = new Fedora_Item($this->pid);
$streams = $item->get_datastreams_list_as_array(); $streams = $item->get_datastreams_list_as_array();
return "<a href='". $base_url ."/fedora/repository/". $this->pid ."/OBJ/". $streams['OBJ']['label'] ."'>". $streams['OBJ']['label'] ."</a>"; return "<a href='" . $base_url . "/fedora/repository/" . $this->pid . "/OBJ/" . $streams['OBJ']['label'] . "'>" . $streams['OBJ']['label'] . "</a>";
} }
/**
* Show REF works ??
* @return type
*/
function showRefworks() { function showRefworks() {
$path=drupal_get_path('module', 'fedora_repository'); $path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$collectionHelper = new CollectionClass(); $collectionHelper = new CollectionClass();
$xmlstr=$collectionHelper->getStream($this->pid, "refworks"); $xmlstr = $collectionHelper->getStream($this->pid, "refworks");
html_entity_decode($xmlstr); html_entity_decode($xmlstr);
if ($xmlstr == NULL || strlen($xmlstr) < 5) { if ($xmlstr == NULL || strlen($xmlstr) < 5) {
return " "; return " ";
} }
try { try {
$proc = new XsltProcessor(); $proc = new XsltProcessor();
} } catch (Exception $e) {
catch (Exception $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error');
return " "; return " ";
} }
@ -165,9 +202,14 @@ class ShowStreamsInFieldSets {
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
/**
* Show JP2000
* @param type $collapsed
* @return type
*/
function showJP2($collapsed = FALSE) { function showJP2($collapsed = FALSE) {
$viewer_url = variable_get('fedora_base_url', '') . '/get/'. $this->pid . '/ilives:viewerSdef/getViewer'; $viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer';
$html = '<iframe src="'. $viewer_url . '" frameborder="0" style="width: 100%; height: 400px;">Errors: unable to load viewer</iframe>'; $html = '<iframe src="' . $viewer_url . '" frameborder="0" style="width: 100%; height: 400px;">Errors: unable to load viewer</iframe>';
$fieldset = array( $fieldset = array(
'#title' => t('Viewer'), '#title' => t('Viewer'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
@ -177,6 +219,11 @@ class ShowStreamsInFieldSets {
return theme('fieldset', $fieldset); return theme('fieldset', $fieldset);
} }
/**
* Show Romeo ??
* @param type $collapsed
* @return type
*/
function showRomeo($collapsed = FALSE) { function showRomeo($collapsed = FALSE) {
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
module_load_include('inc', 'fedora_repository', 'CollectionClass'); module_load_include('inc', 'fedora_repository', 'CollectionClass');
@ -189,8 +236,7 @@ class ShowStreamsInFieldSets {
try { try {
$proc = new XsltProcessor(); $proc = new XsltProcessor();
} } catch (Exception $e) {
catch (Exception $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error');
return; return;
} }
@ -210,4 +256,5 @@ class ShowStreamsInFieldSets {
); );
return theme('fieldset', $collection_fieldset); return theme('fieldset', $collection_fieldset);
} }
} }

23
plugins/fedoraObject.inc

@ -1,7 +1,22 @@
<?php <?php
// $Id$
/**
* @file
* FedoraObject class
*/
/**
* Fedora Object class ??
*/
class FedoraObject { class FedoraObject {
function __construct($pid = '') {
/**
* Constructor
* @param type $pid
*/
function __construct($pid = '') {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!empty($pid)) { if (!empty($pid)) {
@ -10,6 +25,11 @@ class FedoraObject {
} }
} }
/**
* Show Field Sets
* @global type $user
* @return type
*/
public function showFieldSets() { public function showFieldSets() {
global $user; global $user;
$objectHelper = new ObjectHelper(); $objectHelper = new ObjectHelper();
@ -49,4 +69,5 @@ class FedoraObject {
return $tabset; return $tabset;
} }
} }

73
plugins/herbarium.inc

@ -2,8 +2,17 @@
// $Id$ // $Id$
/**
* @file
* Herbarium class
*/
/**
* Herbarium ???
*/
class Herbarium { class Herbarium {
function __construct($pid = '') {
function __construct($pid = '') {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!empty($pid)) { if (!empty($pid)) {
$this->pid = $pid; $this->pid = $pid;
@ -11,6 +20,12 @@ class Herbarium {
} }
} }
/**
* Build a drupal form ??
* @param type $form
* @param type $form_state
* @return type
*/
public function buildDrupalForm($form = array(), $form_state = array()) { public function buildDrupalForm($form = array(), $form_state = array()) {
// We don't need to add anything beyond the standard Darwin Core form so just pass this through // We don't need to add anything beyond the standard Darwin Core form so just pass this through
// If we wanted to we could add other fields. // If we wanted to we could add other fields.
@ -20,6 +35,11 @@ class Herbarium {
return $dwc->buildDrupalForm($form); return $dwc->buildDrupalForm($form);
} }
/**
* Build edit metadata form
* @param type $form
* @return type
*/
public function buildEditMetadataForm($form = array()) { public function buildEditMetadataForm($form = array()) {
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
@ -38,6 +58,13 @@ class Herbarium {
return $this->buildDrupalForm($form); return $this->buildDrupalForm($form);
} }
/**
* handle edit metadata form ??
* @global type $user
* @param type $form_id
* @param type $form_values
* @return type
*/
public function handleEditMetadataForm($form_id, $form_values) { public function handleEditMetadataForm($form_id, $form_values) {
/* /*
* Process the metadata form * Process the metadata form
@ -51,11 +78,15 @@ class Herbarium {
$dwc = new DarwinCore($this->item); $dwc = new DarwinCore($this->item);
$dwc->handleForm($form_values); $dwc->handleForm($form_values);
$this->item->purge_datastream('DARWIN_CORE'); $this->item->purge_datastream('DARWIN_CORE');
$this->item->add_datastream_from_string($dwc->darwinCoreXML, 'DARWIN_CORE', $this->item->add_datastream_from_string($dwc->darwinCoreXML, 'DARWIN_CORE', 'Darwin Core Metadata', 'text/xml', 'X');
'Darwin Core Metadata', 'text/xml', 'X');
return TRUE; return TRUE;
} }
/**
* Handle Ingest Form
* @global type $user
* @param type $form_values
*/
public function handleIngestForm($form_values) { public function handleIngestForm($form_values) {
/* /*
* process the metadata form * process the metadata form
@ -70,20 +101,17 @@ class Herbarium {
$dwc = new DarwinCore(); $dwc = new DarwinCore();
$dwc->handleForm($form_values); $dwc->handleForm($form_values);
$label = $form_values['dwc:institutionCode'] . ':' $label = $form_values['dwc:institutionCode'] . ':'
. $form_values['dwc:collectionCode'] . ':' . $form_values['dwc:collectionCode'] . ':'
. $form_values['dwc:catalogNumber']; . $form_values['dwc:catalogNumber'];
$new_item = Fedora_Item::ingest_new_item($form_values['pid'], 'A', $label, $new_item = Fedora_Item::ingest_new_item($form_values['pid'], 'A', $label, $user->name);
$user->name);
$new_item->add_datastream_from_string($dwc->darwinCoreXML, 'DARWIN_CORE', $new_item->add_datastream_from_string($dwc->darwinCoreXML, 'DARWIN_CORE', 'Darwin Core Metadata', 'text/xml', 'X');
'Darwin Core Metadata', 'text/xml', 'X');
$file = $form_values['ingest-file-location']; $file = $form_values['ingest-file-location'];
if (!empty( $file)) { if (!empty($file)) {
$dformat = $mimetype->getType($file); $dformat = $mimetype->getType($file);
$new_item->add_datastream_from_file($file, 'FULL_SIZE', $new_item->add_datastream_from_file($file, 'FULL_SIZE', "$label-full-size", $dformat, 'M');
"$label-full-size", $dformat, 'M');
} }
$new_item->add_relationship('hasModel', $form_values['content_model_pid'], FEDORA_MODEL_URI); $new_item->add_relationship('hasModel', $form_values['content_model_pid'], FEDORA_MODEL_URI);
@ -93,13 +121,17 @@ class Herbarium {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $created_file) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $created_file) {
$created_file_format = $mimetype->getType($created_file); $created_file_format = $mimetype->getType($created_file);
$created_filename = strstr($created_file, $file); $created_filename = strstr($created_file, $file);
$new_item->add_datastream_from_file($created_file, $dsid, $new_item->add_datastream_from_file($created_file, $dsid, $created_filename, $created_file_format, 'M');
$created_filename, $created_file_format, 'M');
} }
} }
} }
/**
* Show Field Sets
* @global type $base_url
* @global type $user
* @return string
*/
public function showFieldSets() { public function showFieldSets() {
module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
module_load_include('inc', 'fedora_repository', 'plugins/DarwinCore'); module_load_include('inc', 'fedora_repository', 'plugins/DarwinCore');
@ -110,11 +142,11 @@ class Herbarium {
global $user; global $user;
$qs = ''; $qs = '';
if ($user->uid != 0) { if ($user->uid != 0) {
$qs = '?uid='. base64_encode($user->name . ':'. $user->pass); $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass);
} }
$viewer_url = variable_get('fedora_base_url', '') . '/get/'. $this->pid . '/ilives:viewerSdef/getViewer'. $qs; $viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs;
$html = '<iframe src="'. $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>'; $html = '<iframe src="' . $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>';
$tabset['second_tab'] = array( $tabset['second_tab'] = array(
// $collection_fieldset = array ( // $collection_fieldset = array (
'#type' => 'tabpage', '#type' => 'tabpage',
@ -126,8 +158,8 @@ class Herbarium {
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('View'), '#title' => t('View'),
// This will be the content of the tab. // This will be the content of the tab.
'#content' => '<a href="'. $base_url . '/fedora/repository/'. $this->pid . '/FULL_JPG/"><img src="'. $base_url . '/fedora/imageapi/'. '#content' => '<a href="' . $base_url . '/fedora/repository/' . $this->pid . '/FULL_JPG/"><img src="' . $base_url . '/fedora/imageapi/' .
$this->pid . '/JPG/JPG.jpg'. '" /></a>'. '<p>'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>', $this->pid . '/JPG/JPG.jpg' . '" /></a>' . '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
); );
$dwc = new DarwinCore($this->item); $dwc = new DarwinCore($this->item);
@ -168,4 +200,5 @@ class Herbarium {
} }
return $tabset; return $tabset;
} }
} }

29
plugins/map_viewer.inc

@ -1,13 +1,33 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* ShowMapStreamsInFieldSets class
*/
/**
* Show Map Streams in Field Sets Class ??
*/
class ShowMapStreamsInFieldSets { class ShowMapStreamsInFieldSets {
private $pid =NULL;
private $pid = NULL;
/**
* Constructor
* @param type $pid
*/
function ShowMapStreamsInFieldSets($pid) { function ShowMapStreamsInFieldSets($pid) {
$this->pid = $pid; $this->pid = $pid;
} }
/**
* Show JPEG
* @global type $base_url
* @global type $user
* @return type
*/
function showJPG() { function showJPG() {
module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets'); module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets');
@ -27,8 +47,8 @@ class ShowMapStreamsInFieldSets {
$qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass);
} }
$viewer_url = variable_get('fedora_base_url', '') . '/get/'. $this->pid . '/ilives:viewerSdef/getViewer'. $qs; $viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs;
$html = '<iframe src="'. $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>'; $html = '<iframe src="' . $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>';
drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme'); drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme');
drupal_add_css(drupal_get_path('module', 'fedora_repository') . '/js/iiv/css/jquery-ui/smoothness/jquery-ui-1.7.2.custom.css'); drupal_add_css(drupal_get_path('module', 'fedora_repository') . '/js/iiv/css/jquery-ui/smoothness/jquery-ui-1.7.2.custom.css');
@ -46,9 +66,10 @@ class ShowMapStreamsInFieldSets {
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('Description'), '#title' => t('Description'),
'#content' => $item->get_dissemination('islandora:mods2htmlSdef', 'mods2html') '#content' => $item->get_dissemination('islandora:mods2htmlSdef', 'mods2html')
. $objectHelper->get_formatted_datastream_list($this->pid, NULL, $item), . $objectHelper->get_formatted_datastream_list($this->pid, NULL, $item),
); );
// Render the tabset. // Render the tabset.
return tabs_render($tabset); return tabs_render($tabset);
} }
} }

140
plugins/qt_viewer.inc

@ -1,60 +1,96 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* ShowQTStreamsInFieldSets class
*/
/**
* Show QT Stream in Field Sets
*/
class ShowQtStreamsInFieldSets { class ShowQtStreamsInFieldSets {
private $pid =NULL;
private $pid = NULL;
/**
* Constructor
* @param type $pid
*/
function ShowQtStreamsInFieldSets($pid) { function ShowQtStreamsInFieldSets($pid) {
$this->pid = $pid; $this->pid = $pid;
} }
/**
* Returna a new Fedora Object with the QT movie ???
* @return fedora_item
*/
function fedoraObject() { function fedoraObject() {
return new fedora_item($this->pid); return new fedora_item($this->pid);
} }
/**
* Tecnical metadata ??
* @param type $defaults
* @param type $dsid
* @return type
*/
function technicalMetadata($defaults = array(), $dsid = 'OBJ_EXIFTOOL') { function technicalMetadata($defaults = array(), $dsid = 'OBJ_EXIFTOOL') {
$data = $defaults; $data = $defaults;
try { try {
$src = ObjectHelper::getStream($this->pid, $dsid); $src = ObjectHelper::getStream($this->pid, $dsid);
$doc = new SimpleXMLElement($src); $doc = new SimpleXMLElement($src);
$doc->registerXPathNamespace('File', 'http://ns.exiftool.ca/File/1.0/'); $doc->registerXPathNamespace('File', 'http://ns.exiftool.ca/File/1.0/');
$doc->registerXPathNamespace('Composite', 'http://ns.exiftool.ca/Composite/1.0/'); $doc->registerXPathNamespace('Composite', 'http://ns.exiftool.ca/Composite/1.0/');
$mime = reset($doc->xpath('//File:MIMEType')); $mime = reset($doc->xpath('//File:MIMEType'));
$data['mime'] = $mime; $data['mime'] = $mime;
if(strpos($mime, 'audio/') !== false) { if (strpos($mime, 'audio/') !== false) {
$data['width'] = 300; $data['width'] = 300;
$data['height'] = 0; $data['height'] = 0;
} else { }
$size = reset($doc->xpath('//Composite:ImageSize/text()')); else {
list($width, $height) = explode('x', $size); $size = reset($doc->xpath('//Composite:ImageSize/text()'));
$data['width'] = $width; list($width, $height) = explode('x', $size);
$data['height'] = $height; $data['width'] = $width;
} $data['height'] = $height;
}
$data['doc'] = $src; $data['doc'] = $src;
} catch(Exception $e) { } catch (Exception $e) {
$data = $defaults; $data = $defaults;
} }
return $data; return $data;
} }
/**
* Get Poster Frame Datastream Information ??
* @param type $dsid
* @return type
*/
function getPosterFrameDatastreamInfo($dsid = 'FULL_SIZE') { function getPosterFrameDatastreamInfo($dsid = 'FULL_SIZE') {
$p = ObjectHelper::getDatastreamInfo($this->pid, $dsid); $p = ObjectHelper::getDatastreamInfo($this->pid, $dsid);
if(empty($p) || $p == ' ' || $p === false) { if (empty($p) || $p == ' ' || $p === false) {
return false; return false;
} }
return $p; return $p;
} }
/**
* Get Media Datastream Information ??
* @param type $dsid
* @param type $alt
* @return type
*/
function getMediaDatastreamInfo($dsid = 'OBJ', $alt = array('')) { function getMediaDatastreamInfo($dsid = 'OBJ', $alt = array('')) {
$p = ObjectHelper::getDatastreamInfo($this->pid, $dsid); $p = ObjectHelper::getDatastreamInfo($this->pid, $dsid);
if(empty($p) || $p == ' ' || $p === false) { if (empty($p) || $p == ' ' || $p === false) {
if(!empty($alt)) { if (!empty($alt)) {
$ds = array_shift($alt); $ds = array_shift($alt);
return $this->getMediaDatastreamInfo($ds, $alt); return $this->getMediaDatastreamInfo($ds, $alt);
} }
return false; return false;
} }
@ -62,10 +98,19 @@ class ShowQtStreamsInFieldSets {
return $p; return $p;
} }
/**
* Is download enabled. It always returns false. ???
* @return FALSE
*/
function enableDownload() { function enableDownload() {
return false; return false;
} }
/**
* Show the QT ???
* @global type $base_url
* @return type
*/
function showQt() { function showQt() {
module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets'); module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets');
@ -77,32 +122,32 @@ class ShowQtStreamsInFieldSets {
$pframe = $this->getPosterFrameDatastreamInfo(); $pframe = $this->getPosterFrameDatastreamInfo();
$media = $this->getMediaDatastreamInfo('PROXY', array('OBJ')); $media = $this->getMediaDatastreamInfo('PROXY', array('OBJ'));
if($media === false ) { if ($media === false) {
return ''; return '';
} }
global $base_url; global $base_url;
$path = drupal_get_path('module', 'Fedora_Repository'); $path = drupal_get_path('module', 'Fedora_Repository');
$fullPath=base_path().$path; $fullPath = base_path() . $path;
$content= ''; $content = '';
$pathTojs = drupal_get_path('module', 'Fedora_Repository').'/js/AC_Quicktime.js'; $pathTojs = drupal_get_path('module', 'Fedora_Repository') . '/js/AC_Quicktime.js';
drupal_add_js($pathTojs); drupal_add_js($pathTojs);
$divid = 'player'.md5($this->pid).'MOV'; $divid = 'player' . md5($this->pid) . 'MOV';
$content .= '<div class="player" id="' . $divid .'">'; $content .= '<div class="player" id="' . $divid . '">';
if($pframe !== false) { if ($pframe !== false) {
$content .= '<div class="poster" style="cursor: pointer; position: relative; width: ' . $width .'px; min-height: ' . ($height) . 'px;">'; $content .= '<div class="poster" style="cursor: pointer; position: relative; width: ' . $width . 'px; min-height: ' . ($height) . 'px;">';
$content .= '<img src="' . base_path().'fedora/repository/'.$this->pid.'/'. $pframe->ID . '/poster.jpg' . '" />'; $content .= '<img src="' . base_path() . 'fedora/repository/' . $this->pid . '/' . $pframe->ID . '/poster.jpg' . '" />';
$content .= '<div class="play" style="font-size: 128px; color: white; position: absolute; top: 50%; left: 50%; margin-top: -0.085em; margin-left: -0.33em; opacity: 0.9; "></div>'; $content .= '<div class="play" style="font-size: 128px; color: white; position: absolute; top: 50%; left: 50%; margin-top: -0.085em; margin-left: -0.33em; opacity: 0.9; "></div>';
$content .= '</div>'; $content .= '</div>';
} }
$content .= '</div>'; $content .= '</div>';
if($this->enableDownload()) { if ($this->enableDownload()) {
$url = base_path().'fedora/repository/'.$this->pid.'/OBJ/MOV.mov'; $url = base_path() . 'fedora/repository/' . $this->pid . '/OBJ/MOV.mov';
$content .= '<a class="download" href="' . $url . '">Download Media File</a>'; $content .= '<a class="download" href="' . $url . '">Download Media File</a>';
} }
$src = base_path().'fedora/repository/'.$this->pid.'/' . $media->ID. '/MOV.mov'; $src = base_path() . 'fedora/repository/' . $this->pid . '/' . $media->ID . '/MOV.mov';
$qtparams = ''; $qtparams = '';
$qtparams .= "'autostart', '" . ($pframe !== false ? 'true' : 'false') . "', "; $qtparams .= "'autostart', '" . ($pframe !== false ? 'true' : 'false') . "', ";
$init = <<<EOD $init = <<<EOD
$(function() { $(function() {
src = "$src"; src = "$src";
@ -126,13 +171,14 @@ $qtparams = '';
}); });
EOD; EOD;
drupal_add_js($init, 'inline', 'footer'); drupal_add_js($init, 'inline', 'footer');
$collection_fieldset = array(
'#title' => t('Quicktime'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $content);
return theme('fieldset', $collection_fieldset);
}
$collection_fieldset = array(
'#title' => t('Quicktime'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $content);
return theme('fieldset',$collection_fieldset);
}
} }

28
plugins/slide_viewer.inc

@ -1,15 +1,34 @@
<?php <?php
// $Id$ // $Id$
/**
* @file
* ShowSlideStreamsInFieldSets class
*/
/**
* ShowSlideStreamInFieldSets ??????
*/
class ShowSlideStreamsInFieldSets { class ShowSlideStreamsInFieldSets {
private $pid = NULL; private $pid = NULL;
/**
* Contructor
* @param type $pid
*/
function ShowSlideStreamsInFieldSets($pid) { function ShowSlideStreamsInFieldSets($pid) {
//drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); //drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$this->pid = $pid; $this->pid = $pid;
} }
/**
* Show JPEG
* @global type $base_url
* @global type $user
* @return type
*/
function showJPG() { function showJPG() {
module_load_include('inc', 'fedora_repository', 'plugins/tagging_form'); module_load_include('inc', 'fedora_repository', 'plugins/tagging_form');
module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets'); module_load_include('inc', 'fedora_repository', 'plugins/ShowStreamsInFieldSets');
@ -23,8 +42,8 @@ class ShowSlideStreamsInFieldSets {
$qs = '?uid=' . base64_encode($user->name . ':' . $user->pass); $qs = '?uid=' . base64_encode($user->name . ':' . $user->pass);
} }
$viewer_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/'. $this->pid . '/ilives:viewerSdef/getViewer'. $qs; $viewer_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs;
$html = '<iframe src="'. $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>'; $html = '<iframe src="' . $viewer_url . '" scrolling="no" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>';
drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme'); drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme');
@ -38,10 +57,11 @@ class ShowSlideStreamsInFieldSets {
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('View'), '#title' => t('View'),
// This will be the content of the tab. // This will be the content of the tab.
'#content' => '<img src="'. $base_url . '#content' => '<img src="' . $base_url .
'/fedora/imageapi/'. $this->pid . '/JPG/JPG.jpg'. '" />'. '<p>'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>', '/fedora/imageapi/' . $this->pid . '/JPG/JPG.jpg' . '" />' . '<p>' . drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
); );
return $tabset; return $tabset;
} }
} }

42
plugins/tagging_form.inc

@ -1,11 +1,17 @@
<?php <?php
// $Id$ // $Id$
/* /**
* To change this template, choose Tools | Templates * @file
* and open the template in the editor. * Tagging Form???
*/ */
/**
* Show subject tags ???
* @param type $pid
* @return string
*/
function _show_subject_tags($pid) { function _show_subject_tags($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/dublin_core'); module_load_include('inc', 'fedora_repository', 'api/dublin_core');
@ -15,13 +21,20 @@ function _show_subject_tags($pid) {
if (!empty($tags->tags)) { if (!empty($tags->tags)) {
$output = "<ul>"; $output = "<ul>";
foreach ($tags->tags as $tag) { foreach ($tags->tags as $tag) {
$output .= "<li title=". $tag['creator'] . '>'. $tag['name'] . '</li> '; $output .= "<li title=" . $tag['creator'] . '>' . $tag['name'] . '</li> ';
} }
$output .= "</ul>"; $output .= "</ul>";
} }
return $output; return $output;
} }
/**
* Fedora repository image tagging form ????
* @global type $base_url
* @param type $form_state
* @param type $pid
* @return type
*/
function fedora_repository_image_tagging_form($form_state, $pid) { function fedora_repository_image_tagging_form($form_state, $pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/dublin_core'); module_load_include('inc', 'fedora_repository', 'api/dublin_core');
@ -29,7 +42,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
global $base_url; global $base_url;
if (!empty($form_state['post']['pid'])) { if (!empty($form_state['post']['pid'])) {
$pid = $form_state['post']['pid']; $pid = $form_state['post']['pid'];
} }
$obj = new Fedora_Item($pid); $obj = new Fedora_Item($pid);
$form['tags-wrapper'] = array( $form['tags-wrapper'] = array(
@ -49,8 +62,8 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
'#prefix' => '<li>', '#prefix' => '<li>',
'#suffix' => '</li>', '#suffix' => '</li>',
); );
$form['tags-wrapper']['tags'][$tag['name']]['tag'] = array( $form['tags-wrapper']['tags'][$tag['name']]['tag'] = array(
'#prefix' => '<a title="Added by '. $tag['creator'] . '" href="'. $base_url . '/fedora/repository/mnpl_advanced_search/tag:'. $tag['name'] . '">', '#prefix' => '<a title="Added by ' . $tag['creator'] . '" href="' . $base_url . '/fedora/repository/mnpl_advanced_search/tag:' . $tag['name'] . '">',
'#value' => $tag['name'], '#value' => $tag['name'],
'#suffix' => '</a>', '#suffix' => '</a>',
); );
@ -58,7 +71,7 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
// Delete button for each existing tag. // Delete button for each existing tag.
$form['tags-wrapper']['tags'][$tag['name']]['delete'] = array( $form['tags-wrapper']['tags'][$tag['name']]['delete'] = array(
'#type' => 'imagebutton', '#type' => 'imagebutton',
'#image' => $base_url . '/'. drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png', '#image' => $base_url . '/' . drupal_get_path('module', 'fedora_repository') . '/images/remove_icon.png',
'#default_value' => $tag['name'], '#default_value' => $tag['name'],
'#title' => t('Delete this tag'), '#title' => t('Delete this tag'),
); );
@ -88,6 +101,11 @@ function fedora_repository_image_tagging_form($form_state, $pid) {
return $form; return $form;
} }
/**
* Hook image button process ???
* @param type $form
* @return string
*/
function hook_imagebutton_process($form) { function hook_imagebutton_process($form) {
$form['op_x'] = array( $form['op_x'] = array(
'#name' => $form['#name'] . '_x', '#name' => $form['#name'] . '_x',
@ -98,6 +116,12 @@ function hook_imagebutton_process($form) {
return $form; return $form;
} }
/**
* Fedora repository image tagging from submit ???
* @global type $user
* @param type $form
* @param type $form_state
*/
function fedora_repository_image_tagging_form_submit($form, &$form_state) { function fedora_repository_image_tagging_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/tagging'); module_load_include('inc', 'fedora_repository', 'api/tagging');
@ -110,7 +134,7 @@ function fedora_repository_image_tagging_form_submit($form, &$form_state) {
array_push($tagset->tags, array('name' => $form_state['values']['addtag'], 'creator' => $user->name)); array_push($tagset->tags, array('name' => $form_state['values']['addtag'], 'creator' => $user->name));
} }
elseif (!empty($form_state['values']['delete'])) { elseif (!empty($form_state['values']['delete'])) {
for ( $i=0; $i < count($tagset->tags); $i++ ) { for ($i = 0; $i < count($tagset->tags); $i++) {
if ($tagset->tags[$i]['name'] == $form_state['clicked_button']['#value']) { if ($tagset->tags[$i]['name'] == $form_state['clicked_button']['#value']) {
unset($tagset->tags[$i]); unset($tagset->tags[$i]);
} }

Loading…
Cancel
Save