<?php
-// $Id$
/**
* @defgroup print Printer, e-mail and PDF versions
define('PRINT_PATH', 'print');
define('PRINT_HTML_FORMAT', 'html');
-
+define('PRINT_MAIL_FORMAT', 'mail');
+define('PRINT_PDF_FORMAT', 'pdf');
define('PRINT_LOGO_OPTIONS_DEFAULT', 1);
define('PRINT_LOGO_URL_DEFAULT', '');
define('PRINT_FOOTER_OPTIONS_DEFAULT', 1);
),
'print_node' => array(
'variables' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE, 'type' => PRINT_HTML_FORMAT),
+ 'render element' => 'elements',
'template' => 'print_node',
),
- 'print_page' => array(
+ 'print' => array(
'variables' => array('print' => array(), 'type' => PRINT_HTML_FORMAT, 'node' => NULL),
+ 'render element' => 'page',
'template' => 'print',
),
);
}
/**
- * Clones the node theme registry for print_node so that it works with existing node templates
- */
-function print_theme_registry_alter(&$theme_registry) {
-// $theme_registry['print_node']['theme path'] += $theme_registry['node']['theme path'];
-}
-
-/**
- * Renders the content of the node using the theme api
+ * Implements hook_preprocess_HOOK().
*/
-function print_preprocess_print_node(&$vars) {
- $format = $vars['type'];
- $type = $vars['node']->type;
- template_preprocess_node($vars);
-
+function print_preprocess_print_node(&$variables) {
+ $variables['node'] = $variables['elements']['#node'];
+ $type = $variables['node']->type;
+// $format = $variables['type'];
+ template_preprocess_node($variables);
$variables['theme_hook_suggestions'][] = "node";
- $variables['theme_hook_suggestions'][] = "node__$type";
+ $variables['theme_hook_suggestions'][] = "node__{$type}";
$variables['theme_hook_suggestions'][] = "print_node";
- $variables['theme_hook_suggestions'][] = "print_node_$format";
- $variables['theme_hook_suggestions'][] = "print_node_$format.node__$type";
+// $variables['theme_hook_suggestions'][] = "print_node_{$format}";
+// $variables['theme_hook_suggestions'][] = "print_node_{$format}.node__{$type}";
}
/**
- * Renders the print page, where the node content gets embedded
+ * Implements hook_preprocess_HOOK().
*/
-function print_preprocess_print_page(&$vars) {
- $format = $vars['type'];
- $type = $vars['node']->type;
+function print_preprocess_print(&$variables) {
+ $format = $variables['type'];
+ if (isset($variables['node']->type)) {
+ $type = $variables['node']->type;
+ $variables['show_blocks'] = FALSE;
+ $variables['page']['#show_messages'] = FALSE;
+ template_preprocess_page($variables);
+ }
+ else {
+ $type = '';
+ }
$variables['theme_hook_suggestions'][] = "print";
- $variables['theme_hook_suggestions'][] = "print.node__$type";
- $variables['theme_hook_suggestions'][] = "print_$format";
- $variables['theme_hook_suggestions'][] = "print_$format.node__$type";
+ $variables['theme_hook_suggestions'][] = "print__node__{$type}";
+ $variables['theme_hook_suggestions'][] = "print__{$format}";
+ $variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}";
}
/**
$items[PRINT_PATH . '/' . PRINT_PATH] = array(
'access callback' => FALSE,
);
- $items['admin/config/print'] = array(
+ $items['admin/config/user-interface/print'] = array(
'title' => 'Printer, e-mail and PDF versions',
'description' => 'Adds a printer-friendly version link to content and administrative pages.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer print'),
'file' => 'print.admin.inc',
);
- $items['admin/config/print/html'] = array(
+ $items['admin/config/user-interface/print/html'] = array(
'title' => 'Web page',
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['admin/config/print/html/options'] = array(
+ $items['admin/config/user-interface/print/html/options'] = array(
'title' => 'Options',
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['admin/config/print/html/strings'] = array(
+ $items['admin/config/user-interface/print/html/strings'] = array(
'title' => 'Text strings',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_html_strings_settings'),
'type' => MENU_LOCAL_TASK,
'file' => 'print.admin.inc',
);
- $items['admin/config/print/common'] = array(
+ $items['admin/config/user-interface/print/common'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_main_settings'),
'type' => MENU_LOCAL_TASK,
'file' => 'print.admin.inc',
);
- $items['admin/config/print/common/options'] = array(
+ $items['admin/config/user-interface/print/common/options'] = array(
'title' => 'Options',
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['admin/config/print/common/strings'] = array(
+ $items['admin/config/user-interface/print/common/strings'] = array(
'title' => 'Text strings',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_main_strings_settings'),
* Implements hook_block_info().
*/
function print_block_info() {
- $block[0]['info'] = t('Printer, e-mail and PDF versions');
- $block[0]['cache'] = DRUPAL_CACHE_PER_PAGE;
- $block[1]['info'] = t('Most printed');
- $block[1]['cache'] = DRUPAL_CACHE_GLOBAL;
+ $block['print-links']['info'] = t('Printer, e-mail and PDF versions');
+ $block['print-links']['cache'] = DRUPAL_CACHE_PER_PAGE;
+ $block['print-top']['info'] = t('Most printed');
+ $block['print-top']['cache'] = DRUPAL_CACHE_GLOBAL;
return $block;
}
*/
function print_block_view($delta = '') {
switch ($delta) {
- case 0:
+ case 'print-links':
$nid = preg_replace('!^node/!', '', $_GET['q']);
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$node = node_load($nid);
}
else {
}
}
break;
- case 1:
+ case 'print-top':
$block['subject'] = t('Most printed');
$result = db_query_range("SELECT path FROM {print_page_counter} ORDER BY totalcount DESC", 0, 3)
->fetchAll();
function print_node_view($node, $view_mode) {
$print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT));
$print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT);
- $allowed_type = print_link_allowed(array('type' => 'node', 'node' => $node, 'teaser' => ($view_mode == 'teaser')));
+ $allowed_type = print_link_allowed(array('type' => 'node', 'node' => $node, 'view_mode' => $view_mode));
if (($allowed_type === PRINT_ALLOW_NORMAL_LINK) && !isset($node->book) && !empty($print_html_link_pos['link'])) {
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
$links = array();
$node->content['links']['print_html'] = array(
'#theme' => 'links',
'#links' => $links,
- '#attributes' => array('class' => 'links inline'),
+ '#attributes' => array('class' => array('links', 'inline')),
);
}
}
/**
- * Implements hook_field_build_modes().
+ * Implements hook_entity_info_alter().
*/
-function print_field_build_modes() {
- return array(
+function print_entity_info_alter(&$info) {
+ // Add the 'Print' view mode for nodes.
+ $info['node']['view modes'] += array(
'print' => array(
- 'title' => t('Print'),
- 'build modes' => array(
- 'print' => array(
- 'title' => t('Print'),
- 'views style' => TRUE,
- ),
- ),
+ 'label' => t('Print'),
+ 'custom settings' => FALSE,
),
);
}
function _print_get_title($path) {
$path = drupal_get_normal_path($path);
$nid = preg_replace('!^node/!', '', $path);
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$res = db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid))
->fetchField();
}
$attributes = array();
$attributes['title'] = $title;
if (!empty($class)) {
- $attributes['class'] = $class;
+ $attributes['class'] = array($class);
}
if ($new_window) {
$html = TRUE;
switch ($type) {
case 2:
- $text = theme('image', $img, $text, $text, array('class' => 'print-icon'));
+ $text = theme('image', array('path' => $img, 'alt' => $text, 'title' => $text, 'attributes' => array('class' => array('print-icon'))));
break;
case 3:
- $text = theme('image', $img, $text, $text, array('class' => 'print-icon print-icon-margin')) . $text;
+ $text = theme('image', array('path' => $img, 'alt' => $text, 'title' => $text, 'attributes' => array('class' => array('print-icon', 'print-icon-margin')))) . $text;
break;
}
}
* PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
*/
function print_link_allowed($args) {
- if ((!empty($args['teaser']) && !variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT))
- || !user_access('access print')) {
+ $view_mode = isset($args['view_mode']) ? $args['view_mode'] : '';
+ if ((($view_mode == 'teaser') && !variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT))
+ || !in_array($view_mode, array('full', 'teaser')) || !user_access('access print')) {
// If the teaser link is disabled or the user is not allowed
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$args['node'] = node_load($nid);
}
}
}
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
// Link is for a comment, return the configured setting
- $res = db_query("SELECT comments FROM {print_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
- ->fetch();
- $print_display_comment = $res ? intval($res->comments) : variable_get('print_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ // Cache this statically to avoid duplicate queries for every comment.
+ static $res = array();
+ if (!isset($res[$node->nid])) {
+ $res[$node->nid] = db_query("SELECT comments FROM {print_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
+ ->fetch();
+ }
+ $print_display_comment = $res ? intval($res[$node->nid]->comments) : variable_get('print_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}
}
}
- return implode('&', $params);
+ return $params;
}