Browse Source

Merge pull request #371 from MorganDawe/7.x

Drupal islandora print update.
pull/378/merge
William Panting 12 years ago
parent
commit
3d56c4e1f9
  1. 72
      css/islandora.print.css
  2. BIN
      images/print-icon.png
  3. 4
      includes/solution_packs.inc
  4. 24
      islandora.api.php
  5. 134
      islandora.module
  6. 18
      js/add_print.js
  7. 18
      theme/islandora-object-img-print.tpl.php
  8. 30
      theme/islandora-object-print.tpl.php
  9. 1
      theme/islandora-object.tpl.php

72
css/islandora.print.css

@ -0,0 +1,72 @@
/**
* @file
* Print styling
*
* We provide some sane print styling for Drupal, hiding most visuals.
*/
a:link,
a:visited { /* underline all links */
text-decoration: underline !important;
}
#site-name a:link,
#site-name a:visited { /* Don't underline header */
text-decoration: none !important;
}
#content a[href^="javascript:"]:after,
#content a[href^="#"]:after { /* Only display useful links. */
/* content: ""; */
}
#content abbr[title]:after { /* Add visible title after abbreviations. */
/* content: " (" attr(title) ")"; */
}
#content {
left: 0 !important;
width: 100% !important;
}
uncomment when ready to test printing
#header {
display: none !important;
}
#content { /* Un-float the content */
float: none !important;
width: 100% !important;
margin: 0 !important;
padding: 0 !important;
}
body,
#page,
#main,
#content { /* Turn off any background colors or images */
color: #000;
background-color: transparent !important;
background-image: none !important;
}
body.sidebar-first {
left: 0 !important;
width: 100% !important;
}
#skip-link,
#toolbar,
#navigation,
/* .region-sidebar-first, */
/* .region-sidebar-second, */
#header,
#footer,
.breadcrumb,
.tabs,
.action-links,
.links,
.book-navigation,
.forum-topic-navigation,
.pager,
.feed-icons { /* Hide sidebars and nav elements */
visibility: hidden !important;
display: none !important;
}

BIN
images/print-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

4
includes/solution_packs.inc

@ -173,7 +173,7 @@ function islandora_solution_pack_form(array $form, array &$form_state, $solution
'#markup' => t('<strong>Object status:</strong> !image !status', array( '#markup' => t('<strong>Object status:</strong> !image !status', array(
'!image' => $solution_pack_status_info['image'], '!image' => $solution_pack_status_info['image'],
'!status' => $solution_pack_status_info['solution_pack'], '!status' => $solution_pack_status_info['solution_pack'],
)), )),
'#prefix' => '<div class="islandora-solution-pack-install-status">', '#prefix' => '<div class="islandora-solution-pack-install-status">',
'#suffix' => '</div>', '#suffix' => '</div>',
), ),
@ -720,7 +720,7 @@ function theme_islandora_viewers_table($variables) {
'header' => $header, 'header' => $header,
'rows' => $rows, 'rows' => $rows,
'attributes' => array('id' => 'islandora-viewers-table'), 'attributes' => array('id' => 'islandora-viewers-table'),
)); ));
$output .= drupal_render_children($form); $output .= drupal_render_children($form);
return $output; return $output;
} }

24
islandora.api.php

@ -21,8 +21,30 @@
* An array whose values are markup. * An array whose values are markup.
*/ */
function hook_islandora_view_object($object, $user, $page_number, $page_size) { function hook_islandora_view_object($object, $user, $page_number, $page_size) {
} $output = array();
if (in_array('islandora:sp_basic_image', $object->models)) {
$resource_url = url("islandora/object/{$object->id}/datastream/OBJ/view");
$params = array(
'title' => $object->label,
'path' => $resource_url,
);
// Theme the image seperatly.
$variables['islandora_img'] = theme('image', $params);
$output = theme('islandora_default_print', array(
'islandora_content' => $variables['islandora_img']));
}
return $output;
}
/**
* Generate a print friendly page for the given object.
*
* @param object $object
* The object form to print.
*/
function hook_islandora_view_print_object($object) {
}
/** /**
* Generate an object's display for the given content model. * Generate an object's display for the given content model.
* *

134
islandora.module

@ -37,6 +37,7 @@ define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions');
// Hooks. // Hooks.
define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
define('ISLANDORA_PRINT_HOOK', 'islandora_view_print_object');
define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object');
define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object'); define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object');
define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest');
@ -103,6 +104,13 @@ function islandora_menu() {
'access callback' => 'islandora_object_access_callback', 'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
); );
$items['islandora/object/%islandora_object/print'] = array(
'page callback' => 'islandora_printer_object',
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
);
$items['islandora/object/%islandora_object/view'] = array( $items['islandora/object/%islandora_object/view'] = array(
'title' => 'View', 'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK, 'type' => MENU_DEFAULT_LOCAL_TASK,
@ -264,15 +272,6 @@ function islandora_menu() {
'access arguments' => array(ISLANDORA_VIEW_DATASTREAM_HISTORY, 4), 'access arguments' => array(ISLANDORA_VIEW_DATASTREAM_HISTORY, 4),
'load arguments' => array(2), 'load arguments' => array(2),
); );
$items['islandora/object/%islandora_object/print'] = array(
'title' => 'Print Object',
'page callback' => 'islandora_print_object',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/download_clip'] = array( $items['islandora/object/%islandora_object/download_clip'] = array(
'page callback' => 'islandora_download_clip', 'page callback' => 'islandora_download_clip',
'page arguments' => array(2), 'page arguments' => array(2),
@ -330,7 +329,11 @@ function islandora_theme() {
// Print object view. // Print object view.
'islandora_object_print' => array( 'islandora_object_print' => array(
'file' => 'theme/theme.inc', 'file' => 'theme/theme.inc',
'variables' => array('object' => NULL, 'content' => array()), 'template' => 'theme/islandora-object-print',
'variables' => array(
'object' => NULL,
'content' => NULL,
'islandora_content' => NULL),
), ),
// Render a bunch of objects as either a grid or a list. // Render a bunch of objects as either a grid or a list.
'islandora_objects' => array( 'islandora_objects' => array(
@ -788,8 +791,24 @@ function islandora_view_default_object() {
function islandora_view_object(AbstractObject $object) { function islandora_view_object(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/breadcrumb');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
// Add the print button via JavaScript.
$path = drupal_get_path('module', 'islandora');
drupal_add_js(array(
'islandora' => array(
'print_img' => $path . '/images/print-icon.png'),
), array(
'type' => 'setting'));
drupal_add_js(array(
'islandora' => array(
'print_link' => '/islandora/object/' . $object->id . '/print')),
array('type' => 'setting'));
drupal_add_js($path . '/js/add_print.js');
drupal_set_title($object->label); drupal_set_title($object->label);
drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); drupal_set_breadcrumb(islandora_get_breadcrumbs($object));
// Optional pager parameters. // Optional pager parameters.
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
@ -808,12 +827,47 @@ function islandora_view_object(AbstractObject $object) {
// No results, use the default view. // No results, use the default view.
$output = islandora_default_islandora_view_object($object); $output = islandora_default_islandora_view_object($object);
} }
arsort($output); arsort($output);
drupal_alter($hooks, $object, $output); drupal_alter($hooks, $object, $output);
islandora_as_renderable_array($output); islandora_as_renderable_array($output);
return $output; return $output;
} }
/**
* This will prepare an object to be printed.
*
* By default, all fedora objects can print DC record data,
* however, Solution packs that wish to modify the form
* to be printed must implement hook_islandora_view_print_object_alter,
* create a theme.tpl.php file, and return its markup by calling
* theme(themename.tpl.php).
*
* @param AbstractObject $object
* The object to print.
*
* @return string
* An HTML representation of this object.
*/
function islandora_printer_object(AbstractObject $object) {
$output = array();
$temp_arr = array();
// Dispatch print hook.
foreach (islandora_build_hook_list(ISLANDORA_PRINT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object);
islandora_as_renderable_array($temp);
if (!empty($temp)) {
$temp_arr = array_merge_recursive($temp_arr, $temp);
}
}
$output = islandora_default_islandora_printer_object($object, drupal_render($temp_arr));
arsort($output);
islandora_as_renderable_array($output);
// Prompt to print.
drupal_add_js('jQuery(document).ready(function () { window.print(); });', 'inline');
return $output;
}
/** /**
* Title callback for drupal title. * Title callback for drupal title.
@ -851,6 +905,48 @@ function islandora_default_islandora_view_object($object) {
); );
} }
/**
* Append the image alter to the printable form.
*
* @param AbstractObject $object
* The fedora object to print.
* @param unknown $alter
* The string representation of the themed viewable object.
*
* @return array
* A renderable array
*/
function islandora_default_islandora_printer_object($object, $alter) {
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/datastream');
$path = drupal_get_path('module', 'islandora');
drupal_add_css($path . '/css/islandora.print.css');
$islandora_object = islandora_object_load($object->id);
$repository = $islandora_object->repository;
try {
$dc = $islandora_object['DC']->content;
$dc_object = DublinCore::importFromXMLString($dc);
}
catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
}
$variables = isset($dc_object) ? $dc_object->asArray() : array();
$output = theme('islandora_object_print', array(
'object' => $object,
'dc_array' => $variables,
'islandora_content' => $alter));
return array(
'Default output' => array(
'#markup' => $output,
),
);
}
/** /**
* Just a wrapper around fetchings the IslandoraTuque object. * Just a wrapper around fetchings the IslandoraTuque object.
* *
@ -1245,24 +1341,6 @@ function islandora_entity_property_info() {
return $info; return $info;
} }
/**
* Renders the print page for the given object.
*
* Modules can either implement preprocess functions to append content onto the
* 'content' variable, or override the display by providing a theme suggestion.
*
* @param AbstractObject $object
* The object.
*
* @return array
* A renderable array.
*/
function islandora_print_object(AbstractObject $object) {
drupal_set_title($object->label);
return theme('islandora_object_print', array('object' => $object));
}
/** /**
* Menu callback downloads the given clip. * Menu callback downloads the given clip.
*/ */

18
js/add_print.js

@ -0,0 +1,18 @@
/**
* @file
* JavaScript file responsable for the print button behaviour.
*
* The print button is added automatically to every view, as metadata
* can be printed from every object.
*
*/
(function ($) {
$(document).ready(function() {
$('.tabs .primary').append('<img id="print_btn" title="Print" src="/' + Drupal.settings.islandora.print_img + '"></img>');
$('#print_btn').css("cursor","pointer");
$('#print_btn').click(function() {
window.location=Drupal.settings.islandora.print_link;
});
});
})(jQuery);

18
theme/islandora-object-img-print.tpl.php

@ -0,0 +1,18 @@
<?php
/**
* @file
* The default view to theme an image of an object.
*
* This view is passed into 'islandora-object-print' theme file
* and is rendred as an image. Allows for seperate theming of image
* and metadata.
*
*/
?>
<?php if (isset($islandora_content)): ?>
<div>
<?php print $islandora_content; ?>
</div>
<?php endif; ?>

30
theme/islandora-object-print.tpl.php

@ -0,0 +1,30 @@
<?php
/**
* @file
* The default view to print objects.
*
*/
?>
<div>
<div>
<?php print $islandora_content; ?>
</div>
<fieldset class="islandora-basic-image-metadata islandora">
<legend><span class="fieldset-legend"><?php print t('Details'); ?></span></legend>
<div class="fieldset-wrapper">
<dl class="islandora-inline-metadata islandora-basic-image-fields">
<?php $row_field = 0; ?>
<?php foreach( $dc_array as $key => $value): ?>
<dt class="<?php print $value['class']; ?><?php print $row_field == 0 ? ' first' : ''; ?>">
<?php print $value['label']; ?>
</dt>
<dd class="<?php print $value['class']; ?><?php print $row_field == 0 ? ' first' : ''; ?>">
<?php print $value['value']; ?>
</dd>
<?php $row_field++; ?>
<?php endforeach; ?>
</dl>
</div>
</fieldset>
</div>

1
theme/islandora-object.tpl.php

@ -60,6 +60,7 @@
?> ?>
<div class="islandora-object islandora"> <div class="islandora-object islandora">
<h2><?php print t('Details'); ?></h2> <h2><?php print t('Details'); ?></h2>
<dl class="islandora-object-tn"> <dl class="islandora-object-tn">
<dt> <dt>
<?php if (isset($variables['islandora_thumbnail_url'])): ?> <?php if (isset($variables['islandora_thumbnail_url'])): ?>

Loading…
Cancel
Save