|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @file islandora_basic_image.module
|
|
|
|
*
|
|
|
|
* an Islandora module to handle basic image cmodels
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This file is part of Islandora.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of hook_menu.
|
|
|
|
* If you need to add secondary tabs to either view or manage you would create a
|
|
|
|
* hook_menu function similar to below. You would also need to create an access function
|
|
|
|
* to tell islandora when to show your tabs. There is an example below.
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_menu() {
|
|
|
|
$items = array();
|
|
|
|
$items['admin/islandora/basic_image'] = array(
|
|
|
|
'title' => 'Islandora Basic Image',
|
|
|
|
'description' => 'Configure the basic image solution pack.',
|
|
|
|
'page callback' => 'drupal_get_form',
|
|
|
|
'access arguments' => array('administer site configuration'),
|
|
|
|
'page arguments' => array('islandora_basic_image_admin'),
|
|
|
|
'file' => 'admin/islandora_basic_image.admin.inc',
|
|
|
|
'type' => MENU_NORMAL_ITEM,
|
|
|
|
);
|
|
|
|
/* example menu paths
|
|
|
|
$items['islandora/object/%/manage/image'] = array(
|
|
|
|
'title' => 'Manage Image Types',
|
|
|
|
'page callback' => 'islandora_basic_image_manage_object',
|
|
|
|
'page arguments' => array(2),
|
|
|
|
'type' => MENU_LOCAL_TASK,
|
|
|
|
'access callback' => 'islandora_basic_image_access',
|
|
|
|
'access arguments' => array(2),
|
|
|
|
);
|
|
|
|
|
|
|
|
$items['islandora/object/%/view/image'] = array(
|
|
|
|
'title' => 'Image View 1',
|
|
|
|
'page callback' => 'islandora_basic_image_view1',
|
|
|
|
'page arguments' => array(2),
|
|
|
|
'type' => MENU_LOCAL_TASK,
|
|
|
|
'access callback' => 'islandora_basic_image_access',
|
|
|
|
'access arguments' => array(2),
|
|
|
|
);
|
|
|
|
$items['islandora/object/%/view/image2'] = array(
|
|
|
|
'title' => 'Image View 2',
|
|
|
|
'page callback' => 'islandora_basic_image_view2',
|
|
|
|
'page arguments' => array(2),
|
|
|
|
'type' => MENU_LOCAL_TASK,
|
|
|
|
'access callback' => 'islandora_basic_image_access',
|
|
|
|
'access arguments' => array(2),
|
|
|
|
);*/
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* an example of adding a new managment section to the manage section of islandora.
|
|
|
|
* The islandora_basic_image_access function determines whether or not to show this
|
|
|
|
* section.
|
|
|
|
*
|
|
|
|
* This is an example function used by hook_menu above.
|
|
|
|
* @param string $object_id
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function islandora_basic_image_manage_object($object_id){
|
|
|
|
return 'Image CModel edit function '.$object_id;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* /**
|
|
|
|
* An example function used by hook_menu
|
|
|
|
* /
|
|
|
|
* @param type $object_id
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function islandora_basic_image_view1($object_id){
|
|
|
|
return 'A view returned by the image cmodel';
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An example function needed by this modules hook_menu
|
|
|
|
* @param type $object_id
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function islandora_basic_image_view2($object_id){
|
|
|
|
return 'Another view returned by the image cmodel';
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* determines whether or not to show this modules manage tab
|
|
|
|
* @global object $user
|
|
|
|
* @param string $object_id
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_access($object_id){
|
|
|
|
module_load_include('inc', 'islandora', 'RestConnection');
|
|
|
|
global $user;
|
|
|
|
try {
|
|
|
|
$restConnection = new RestConnection($user);
|
|
|
|
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!isset($fedora_object)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
$models = $fedora_object->models;
|
|
|
|
$cmodel_list = islandora_basic_image_islandora_get_types();
|
|
|
|
foreach ($fedora_object->models as $model) {
|
|
|
|
if (isset($cmodel_list[$model])){
|
|
|
|
return user_access(FEDORA_MODIFY_STATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme registry function
|
|
|
|
* We supply a pattern so we can overide templates at the theme level if needed.
|
|
|
|
* we can append a pid to a template and the new template file will be called (the pids
|
|
|
|
* colon should be replaced with a dash)
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_theme($existing, $type, $theme, $path) {
|
|
|
|
return array(
|
|
|
|
'islandora_basic_image_objects' => array(
|
|
|
|
'template' => 'islandora-basic-image-view-objects',
|
|
|
|
'variables' => array('islandora_objects' => NULL),
|
|
|
|
),
|
|
|
|
'islandora_basic_image' => array(
|
|
|
|
'template' => 'islandora-basic-image',
|
|
|
|
'pattern' => 'islandora_basic_image__', //we can add pids to the end of this pattern in our preprocess function
|
|
|
|
// and templates will be able to have have a pid appended to the template name to overide a template on a per object basis
|
|
|
|
//an example template would be named islandora-basic-image--islandora-27.tpl.phps
|
|
|
|
'variables' => array('islandora_object' => NULL),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tells the main module what types of objects we support. This is used to determine whether or not
|
|
|
|
* this module should attempt to respond.
|
|
|
|
* @return array
|
|
|
|
* array of content model pids that this module supports
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_islandora_get_types() {
|
|
|
|
$types = array();
|
|
|
|
$types['islandora:sp_basic_image'][ISLANDORA_VIEW_HOOK] = variable_get('islandora_basic_image_use_for_default_tab', TRUE);
|
|
|
|
//$types['islandora:sp_basic_image'][ISLANDORA_EDIT_HOOK] = FALSE;
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this modules implentation of view_object hook will handle objects of type islandora:basicImageCModel and islandora:sp_basic_image
|
|
|
|
* as registered in its return types
|
|
|
|
* Other modules would handle objects of other types.
|
|
|
|
* @param Object $object
|
|
|
|
* a tuque fedora object
|
|
|
|
* @param object $user
|
|
|
|
* @param string $page_number
|
|
|
|
* @param string $page_size
|
|
|
|
* @return string
|
|
|
|
* themed html
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_islandora_view_object($object, $user, $page_number, $page_size) {
|
|
|
|
//global $user;
|
|
|
|
$cmodel_list = islandora_basic_image_islandora_get_types();
|
|
|
|
$models = $object->models;
|
|
|
|
foreach ($object->models as $model) {
|
|
|
|
if (isset($cmodel_list[$model][ISLANDORA_VIEW_HOOK]) && $cmodel_list[$model][ISLANDORA_VIEW_HOOK] == TRUE) {
|
|
|
|
$output = theme('islandora_basic_image', array('islandora_object' => $object));
|
|
|
|
return array('' => $output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @global type $base_url
|
|
|
|
* @param array $variables
|
|
|
|
* an array of variables that will be passed to the theme function
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_preprocess_islandora_basic_image(&$variables) {
|
|
|
|
$islandora_object = $variables['islandora_object'];
|
|
|
|
module_load_include('inc', 'islandora', 'includes/islandora_dublin_core');
|
|
|
|
try {
|
|
|
|
$dc = $islandora_object['DC']->content;
|
|
|
|
$dc_object = Dublin_Core::import_from_xml_string($dc);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error');
|
|
|
|
}
|
|
|
|
$variables['islandora_dublin_core'] = $dc_object;
|
|
|
|
//create a nicer array for themers
|
|
|
|
//TODO: give this a better home
|
|
|
|
//$dc_array = array();
|
|
|
|
//foreach ($dc_object as $element) {
|
|
|
|
// if (!empty($element)) {
|
|
|
|
// foreach ($element as $field => $value) {
|
|
|
|
// // split value if the result value is an array
|
|
|
|
// if (is_array($value)) {
|
|
|
|
// $value = implode(", ", $value);
|
|
|
|
// }
|
|
|
|
// $dc_label = explode(':', $field);
|
|
|
|
// $element_label = ucfirst($dc_label[1]);
|
|
|
|
// $dc_array[$field]['label'] = $element_label;
|
|
|
|
// $dc_array[$field]['value'] = strip_tags($value);
|
|
|
|
// $dc_array[$field]['class'] = strtolower( preg_replace('/[^A-Za-z0-9]/', '-', $field));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
$variables['dc_array'] = $dc_object->as_formatted_array();
|
|
|
|
$variables['islandora_object_label'] = $islandora_object->label;
|
|
|
|
$variables['theme_hook_suggestions'][] = 'islandora_basic_image__' . str_replace(':', '_', $islandora_object->id);
|
|
|
|
global $base_url;
|
|
|
|
if (isset($islandora_object['OBJ'])) {
|
|
|
|
$full_size_url = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/OBJ/view';
|
|
|
|
$variables['islandora_full_img'] = '<img src="' . $full_size_url . '"/>';
|
|
|
|
}
|
|
|
|
if (isset($islandora_object['TN'])) {
|
|
|
|
$thumbnail_size_url = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view';
|
|
|
|
$variables['islandora_thumbnail_img'] = '<img src="' . $thumbnail_size_url . '"/>';
|
|
|
|
}
|
|
|
|
if (isset($islandora_object['MEDIUM_SIZE'])) {
|
|
|
|
$medium_size_url = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/MEDIUM_SIZE/view';
|
|
|
|
$variables['islandora_medium_img'] = '<img src="' . $medium_size_url . '"/>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|