Browse Source

added ingest to basic image types using a default mods form

pull/120/merge
Paul Pound 13 years ago
parent
commit
13825faf5f
  1. 1
      includes/datastream.inc
  2. 2
      includes/islandora.ingest.inc
  3. 39
      islandora_basic_image/includes/image_process.inc
  4. 57
      islandora_basic_image/islandora_basic_image.module

1
includes/datastream.inc

@ -32,6 +32,7 @@ function islandora_datastream_as_attachment($object_id, $dsid) {
if (isset($method) && $method == 'download') { if (isset($method) && $method == 'download') {
header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label); header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label);
} }
//maybe able to use drupal's file transfer here
print($fedora_object[$dsid]->content); print($fedora_object[$dsid]->content);
exit(); exit();
} }

2
includes/islandora.ingest.inc

@ -21,7 +21,7 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation
} }
function islandora_ingest_add_object(&$object) { function islandora_ingest_add_object(&$object) {
$object->repository->ingestObject($object); //$object->repository->ingestObject($object);
module_invoke_all('islandora_ingest_post_ingest', $object); module_invoke_all('islandora_ingest_post_ingest', $object);
return $object; return $object;
} }

39
islandora_basic_image/includes/image_process.inc

@ -0,0 +1,39 @@
<?php
/**
*
* @param object $file
* stdclass
*/
function islandora_basic_image_create_derivative($file, $width, $height) {
$real_path = drupal_realpath($file->uri);
$image = image_load($real_path);
if (!empty($image)) {
$scale = image_scale($image, $width, $height, TRUE);
if($scale){
return image_save($image);
}
}
return FALSE;
}
/**
* adds a datastream and deletes the tmp file from local file system
* @param object $object
* @param string $dsid
* @param object $file
*/
function islandora_basic_image_add_datastream($object, $dsid, $file) {
try {
$ds = $object->constructDatastream($dsid, 'M');
$ds->label = $dsid;
$ds->mimeType = $object['OBJ']->mimeType;
$ds->setContentFromFile(drupal_realpath($file->uri));
$object->ingestDatastream($ds);
file_delete($file);
} catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
}
}

57
islandora_basic_image/islandora_basic_image.module

@ -30,7 +30,7 @@
*/ */
function islandora_basic_image_menu() { function islandora_basic_image_menu() {
$items = array(); $items = array();
$items['admin/islandora/basic_image'] = array( $items['admin/islandora/basic_image'] = array(
'title' => 'Islandora Basic Image', 'title' => 'Islandora Basic Image',
'description' => 'Configure the basic image solution pack.', 'description' => 'Configure the basic image solution pack.',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
@ -38,33 +38,33 @@ function islandora_basic_image_menu() {
'page arguments' => array('islandora_basic_image_admin'), 'page arguments' => array('islandora_basic_image_admin'),
'file' => 'admin/islandora_basic_image.admin.inc', 'file' => 'admin/islandora_basic_image.admin.inc',
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
); );
/* example menu paths /* example menu paths
$items['islandora/object/%/manage/image'] = array( $items['islandora/object/%/manage/image'] = array(
'title' => 'Manage Image Types', 'title' => 'Manage Image Types',
'page callback' => 'islandora_basic_image_manage_object', 'page callback' => 'islandora_basic_image_manage_object',
'page arguments' => array(2), 'page arguments' => array(2),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_basic_image_access', 'access callback' => 'islandora_basic_image_access',
'access arguments' => array(2), 'access arguments' => array(2),
); );
$items['islandora/object/%/view/image'] = array( $items['islandora/object/%/view/image'] = array(
'title' => 'Image View 1', 'title' => 'Image View 1',
'page callback' => 'islandora_basic_image_view1', 'page callback' => 'islandora_basic_image_view1',
'page arguments' => array(2), 'page arguments' => array(2),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_basic_image_access', 'access callback' => 'islandora_basic_image_access',
'access arguments' => array(2), 'access arguments' => array(2),
); );
$items['islandora/object/%/view/image2'] = array( $items['islandora/object/%/view/image2'] = array(
'title' => 'Image View 2', 'title' => 'Image View 2',
'page callback' => 'islandora_basic_image_view2', 'page callback' => 'islandora_basic_image_view2',
'page arguments' => array(2), 'page arguments' => array(2),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_basic_image_access', 'access callback' => 'islandora_basic_image_access',
'access arguments' => array(2), 'access arguments' => array(2),
);*/ ); */
return $items; return $items;
} }
@ -78,9 +78,9 @@ function islandora_basic_image_menu() {
* @return string * @return string
*/ */
/* /*
function islandora_basic_image_manage_object($object_id){ function islandora_basic_image_manage_object($object_id){
return 'Image CModel edit function '.$object_id; return 'Image CModel edit function '.$object_id;
}*/ } */
/** /**
* /** * /**
@ -90,9 +90,9 @@ function islandora_basic_image_manage_object($object_id){
* @return string * @return string
*/ */
/* /*
function islandora_basic_image_view1($object_id){ function islandora_basic_image_view1($object_id){
return 'A view returned by the image cmodel'; return 'A view returned by the image cmodel';
}*/ } */
/** /**
* An example function needed by this modules hook_menu * An example function needed by this modules hook_menu
@ -100,9 +100,9 @@ function islandora_basic_image_view1($object_id){
* @return string * @return string
*/ */
/* /*
function islandora_basic_image_view2($object_id){ function islandora_basic_image_view2($object_id){
return 'Another view returned by the image cmodel'; return 'Another view returned by the image cmodel';
}*/ } */
/** /**
* determines whether or not to show this modules manage tab * determines whether or not to show this modules manage tab
@ -110,22 +110,22 @@ function islandora_basic_image_view2($object_id){
* @param string $object_id * @param string $object_id
* @return boolean * @return boolean
*/ */
function islandora_basic_image_access($object_id){ function islandora_basic_image_access($object_id) {
module_load_include('inc', 'islandora', 'RestConnection'); module_load_include('inc', 'islandora', 'RestConnection');
global $user; global $user;
try { try {
$restConnection = new RestConnection($user); $restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository); $fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) { } catch (Exception $e) {
return FALSE; return FALSE;
} }
if (!isset($fedora_object)) { if (!isset($fedora_object)) {
return FALSE; return FALSE;
} }
$models = $fedora_object->models; $models = $fedora_object->models;
$cmodel_list = islandora_basic_image_islandora_get_types(); $cmodel_list = islandora_basic_image_islandora_get_types();
foreach ($fedora_object->models as $model) { foreach ($fedora_object->models as $model) {
if (isset($cmodel_list[$model])){ if (isset($cmodel_list[$model])) {
return user_access(FEDORA_MODIFY_STATE); return user_access(FEDORA_MODIFY_STATE);
} }
} }
@ -193,6 +193,25 @@ function islandora_basic_image_islandora_view_object($object, $user, $page_numbe
return NULL; return NULL;
} }
function islandora_basic_image_islandora_ingest_post_ingest($object) {
module_load_include('inc', 'islandora', 'includes/MimeClass');
module_load_include('inc', 'islandora_basic_image','includes/image_process');
$mime_class = new MimeClass();
$ext = $mime_class->getExtension($object['OBJ']->mimeType);
$file_name = str_replace(':', '-', $object->id);
$original_file = file_save_data($object['OBJ']->content, 'temporary://' . $file_name . 'OBJ.' . $ext);
$tn_file = file_copy($original_file, 'temporary://' . $file_name . 'TN.' . $ext);
if(islandora_basic_image_create_derivative($tn_file, 200, 200)){
islandora_basic_image_add_datastream($object, 'TN', $tn_file);
}
$medium_file = file_copy($original_file, 'temporary://' . $file_name . 'MEDIUM.' . $ext);
if(islandora_basic_image_create_derivative($medium_file, 500, 700)){
islandora_basic_image_add_datastream($object, 'MEDIUM_SIZE', $medium_file);
}
}
/** /**
* *
* @global type $base_url * @global type $base_url

Loading…
Cancel
Save