@ -1,11 +1,13 @@
<?php
<?php
/**
/**
* @file datastream.inc
* @file
* This file contains the admin form and callback functions for datastream manipulations.
*/
*/
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
/**
/**
* Callback function to view or download a datastream.
*
*
* @global object $user
* @global object $user
* @param string $object_id
* @param string $object_id
@ -15,12 +17,12 @@ define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
*/
*/
function islandora_view_datastream($object, $dsid, $method = 'view') {
function islandora_view_datastream($object, $dsid, $method = 'view') {
// if the object exists but the datastream doesn't
// if the object exists but the datastream doesn't
if(!isset($object[$dsid])) {
if (!isset($object[$dsid])) {
return drupal_not_found();
return drupal_not_found();
}
}
header('Content-type: ' . $object[$dsid]->mimetype);
header('Content-type: ' . $object[$dsid]->mimetype);
if($object[$dsid]->controlGroup == 'M' || $object[$dsid]->controlGroup == 'X') {
if ($object[$dsid]->controlGroup == 'M' || $object[$dsid]->controlGroup == 'X') {
header('Content-length: ' . $object[$dsid]->size);
header('Content-length: ' . $object[$dsid]->size);
}
}
@ -45,7 +47,7 @@ function islandora_datastream_get_parents($islandora_object) {
}
}
$collections = array_merge($collections1, $collections2);
$collections = array_merge($collections1, $collections2);
foreach($collections as $collection) {
foreach ($collections as $collection) {
try {
try {
$pid = $collection['object']['value'];
$pid = $collection['object']['value'];
$object = $repository->getObject($collection['object']['value']);
$object = $repository->getObject($collection['object']['value']);
@ -55,7 +57,9 @@ function islandora_datastream_get_parents($islandora_object) {
$parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
}
}
catch (RepositoryException $e) {}
catch (RepositoryException $e) {
}
}
}
return $parent_collections;
return $parent_collections;
@ -94,7 +98,7 @@ function islandora_get_unused_dsids($object) {
$defined_dsids = array();
$defined_dsids = array();
if(!$object) {
if (!$object) {
return $defined_dsids;
return $defined_dsids;
}
}
@ -168,9 +172,9 @@ function islandora_get_add_datastream_form($object, &$form_state) {
);
);
if (!empty($unused_dsids)) {
if (!empty($unused_dsids)) {
$dsidsForF orm = array();
$dsids_for_f orm = array();
foreach ($unused_dsids as $key => $value) {
foreach ($unused_dsids as $key => $value) {
$dsidsForF orm[$key] = $key;
$dsids_for_f orm[$key] = $key;
}
}
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
'#type' => 'select',
'#type' => 'select',
@ -179,7 +183,7 @@ function islandora_get_add_datastream_form($object, &$form_state) {
'#weight' => '-1',
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
'#description' => t('Datastream IDs defined by the content model.'),
);
);
$form['add_fieldset']['stream_id']['#options'] = $dsidsForF orm;
$form['add_fieldset']['stream_id']['#options'] = $dsids_for_f orm;
}
}
else {
else {
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
@ -220,11 +224,11 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
$dsid = $form_state['values']['stream_id'];
$dsid = $form_state['values']['stream_id'];
$ds_label = $form_state['values']['stream_label'];
$ds_label = $form_state['values']['stream_label'];
$dformat = $mimetype->getMimeType($file);
$dformat = $mimetype->getMimeType($file);
$controlG roup = "M";
$control_g roup = "M";
try {
try {
$fedora_object = islandora_object_load($object_id);
$fedora_object = islandora_object_load($object_id);
$ds = $fedora_object->constructDatastream($dsid, $controlG roup);
$ds = $fedora_object->constructDatastream($dsid, $control_g roup);
$ds->label = $ds_label;
$ds->label = $ds_label;
$ds->mimetype = $dformat;
$ds->mimetype = $dformat;
$ds->setContentFromFile($file);
$ds->setContentFromFile($file);
@ -235,7 +239,7 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return;
return;
}
}
drupal_set_message("Successfully Added Datastream!");
drupal_set_message(t( "Successfully Added Datastream!") );
drupal_goto("islandora/object/$object_id");
drupal_goto("islandora/object/$object_id");
}
}
@ -254,8 +258,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
return;
return;
}
}
$dsid = $form_state['values']['stream_id'];
$dsid = $form_state['values']['stream_id'];
$dsL abel = $form_state['values']['stream_label'];
$ds_l abel = $form_state['values']['stream_label'];
if (strlen($dsid) > 64) {
if (drupal_ strlen($dsid) > 64) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE;
return FALSE;
}
}
@ -263,11 +267,11 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
return FALSE;
return FALSE;
}
}
if (strlen($dsL abel) > 64) {
if (drupal_strlen($ds_l abel) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
return FALSE;
}
}
if (strpos($dsL abel, '/')) {
if (strpos($ds_l abel, '/')) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
return FALSE;
}
}
@ -275,7 +279,7 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
$object_id = $form_state['values']['pid'];
$object_id = $form_state['values']['pid'];
$fedora_object = islandora_object_load($object_id);
$fedora_object = islandora_object_load($object_id);
if(isset($fedora_object[$dsid])) {
if (isset($fedora_object[$dsid])) {
form_set_error('', t('Data stream ID already exists in object.'));
form_set_error('', t('Data stream ID already exists in object.'));
return FALSE;
return FALSE;
}
}
@ -283,7 +287,7 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
$mimetype = new MimeDetect();
$mimetype = new MimeDetect();
$object = islandora_object_load($form_state['values']['pid']);
$object = islandora_object_load($form_state['values']['pid']);
$unused_dsids = islandora_get_unused_dsids($object);
$unused_dsids = islandora_get_unused_dsids($object);
if(isset($unused_dsids[$dsid])) {
if (isset($unused_dsids[$dsid])) {
$types_allowed = $unused_dsids[$dsid];
$types_allowed = $unused_dsids[$dsid];
$arr = array();
$arr = array();
foreach ($types_allowed as $type) {
foreach ($types_allowed as $type) {
@ -356,19 +360,19 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
);
);
$unused_dsids = islandora_get_unused_dsids($object);
$unused_dsids = islandora_get_unused_dsids($object);
$dsidsForF orm = '';
$dsids_for_f orm = '';
$i = 0;
$i = 0;
foreach ($unused_dsids as $key => $value) {
foreach ($unused_dsids as $key => $value) {
if($i++) {
if ($i++) {
$dsidsForF orm .= ", ";
$dsids_for_f orm .= ", ";
}
}
$dsidsForF orm .= "'$key'";
$dsids_for_f orm .= "'$key'";
}
}
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
'#title' => 'Datastream ID',
'#title' => 'Datastream ID',
'#required' => 'TRUE',
'#required' => 'TRUE',
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model dont currently exist: < b > ' . $dsidsForF orm . '< / b > .'),
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model dont currently exist: < b > ' . $dsids_for_f orm . '< / b > .'),
'#type' => 'textfield',
'#type' => 'textfield',
'#weight' => -1,
'#weight' => -1,
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",
@ -379,13 +383,13 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
function islandora_datastream_autocomplete_callback($object, $string = '') {
function islandora_datastream_autocomplete_callback($object, $string = '') {
$dsids = islandora_get_unused_dsids($object);
$dsids = islandora_get_unused_dsids($object);
$output = array();
$output = array();
foreach($dsids as $id => $ds) {
foreach ($dsids as $id => $ds) {
if(trim($string) == '') {
if (trim($string) == '') {
$output[$id] = $id;
$output[$id] = $id;
}
}
else {
else {
$ret = stripos($id, $string);
$ret = stripos($id, $string);
if($ret !== FALSE) {
if ($ret !== FALSE) {
$output[$id] = $id;
$output[$id] = $id;
}
}
}
}
@ -397,7 +401,7 @@ function islandora_datastream_get_human_readable_size($ds) {
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/utilities');
// we return - if we don't have a size
// we return - if we don't have a size
if($ds->controlGroup == 'M' || $ds->controlGroup == 'X') {
if ($ds->controlGroup == 'M' || $ds->controlGroup == 'X') {
return islandora_convert_bytes_to_human_readable($ds->size);
return islandora_convert_bytes_to_human_readable($ds->size);
}
}
else {
else {
@ -406,7 +410,7 @@ function islandora_datastream_get_human_readable_size($ds) {
}
}
function islandora_datastream_get_url($ds, $type = 'download') {
function islandora_datastream_get_url($ds, $type = 'download') {
if($ds->controlGroup == 'R') {
if ($ds->controlGroup == 'R') {
return $ds->url;
return $ds->url;
}
}
else {
else {
@ -417,7 +421,7 @@ function islandora_datastream_get_url($ds, $type = 'download') {
function islandora_datastream_get_delete_link($ds) {
function islandora_datastream_get_delete_link($ds) {
$datastreams = module_invoke_all('islandora_undeletable_datastreams', $ds->parent->models);
$datastreams = module_invoke_all('islandora_undeletable_datastreams', $ds->parent->models);
if(in_array($ds->id, $datastreams)) {
if (in_array($ds->id, $datastreams)) {
return '';
return '';
}
}
else {
else {