<?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);
define('PRINT_FOOTER_USER_DEFAULT', '');
define('PRINT_CSS_DEFAULT', '');
define('PRINT_URLS_DEFAULT', 1);
+define('PRINT_URLS_ANCHORS_DEFAULT', 0);
define('PRINT_COMMENTS_DEFAULT', 0);
define('PRINT_NEWWINDOW_DEFAULT', 1);
define('PRINT_HTML_LINK_POS_DEFAULT', 'link');
+define('PRINT_HTML_LINK_TEASER_DEFAULT', 0);
define('PRINT_HTML_SHOW_LINK_DEFAULT', 1);
define('PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT', 0);
define('PRINT_HTML_NODE_LINK_PAGES_DEFAULT', '');
*/
function print_permission() {
return array(
- 'access print' => array(
- 'title' => t('Access the printer-friendly page'),
- 'description' => t('View the printer-friendly pages and the links to them in the original pages.'),
- ),
'administer print' => array(
'title' => t('Administer the module'),
'description' => t('Perform maintenance tasks for the print module.'),
'title' => t('Node-specific configuration'),
'description' => t('Enable access to the per-node settings.'),
),
+ 'access print' => array(
+ 'title' => t('Access the printer-friendly page'),
+ 'description' => t('View the printer-friendly pages and the links to them in the original pages.'),
+ ),
);
}
function print_theme() {
return array(
'print_format_link' => array(
- 'arguments' => array(),
+ 'variables' => array(),
+ ),
+ 'print_node' => array(
+ 'variables' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE, 'type' => PRINT_HTML_FORMAT),
+ 'render element' => 'elements',
+ 'template' => 'print_node',
+ ),
+ 'print' => array(
+ 'variables' => array('print' => array(), 'type' => PRINT_HTML_FORMAT, 'node' => NULL),
+ 'render element' => 'page',
+ 'template' => 'print',
),
);
}
/**
+ * Implements hook_preprocess_HOOK().
+ */
+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'][] = "print_node";
+// $variables['theme_hook_suggestions'][] = "print_node_{$format}";
+// $variables['theme_hook_suggestions'][] = "print_node_{$format}.node__{$type}";
+}
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+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}";
+}
+
+/**
* Implements hook_menu().
*/
function print_menu() {
$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_list().
+ * Implements hook_block_info().
*/
-function print_block_list() {
- $block[0]['info'] = t('Printer, e-mail and PDF versions');
- $block[1]['info'] = t('Most printed');
+function print_block_info() {
+ $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;
}
/**
* Implements hook_block_view().
*/
-function print_block_view($delta = 0) {
+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();
/**
* Implements hook_node_view().
*/
-function print_node_view($node, $build_mode) {
+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' => ($build_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')),
);
}
- if ($build_mode == 'full') {
+ if ($view_mode == 'full') {
// Insert content corner links
$node->content['print_links'] = array(
- '#markup' => "<span class='print-link'></span>",
+ '#prefix' => '<span class="print-link">',
+ '#markup' => '',
+ '#suffix' => '</span>',
'#weight' => -101,
);
if (!empty($print_html_link_pos['corner'])) {
- $link = print_insert_link(NULL, $node);
- if ($link) {
- $node->content['print_links']['#markup'] = preg_replace('!</span>$!', $link . '</span>', $node->content['print_links']['#markup']);
- }
+ $node->content['print_links']['#markup'] .= print_insert_link(NULL, $node);
}
}
}
}
/**
+ * Implements hook_node_insert().
+ */
+function print_node_insert($node) {
+ if (user_access('administer print') || user_access('node-specific print configuration')) {
+ if ($node->print_display === NULL) $node->print_display = variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
+ if ($node->print_display_comment === NULL) $node->print_display_comment = variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ if ($node->print_display_urllist === NULL) $node->print_display_urllist = variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
+
+ _print_node_conf_modify($node->nid, $node->print_display, $node->print_display_comment, $node->print_display_urllist);
+ }
+}
+
+/**
* Implements hook_node_update().
*/
function print_node_update($node) {
if (user_access('administer print') || user_access('node-specific print configuration')) {
+ if ($node->print_display === NULL) $node->print_display = variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
+ if ($node->print_display_comment === NULL) $node->print_display_comment = variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ if ($node->print_display_urllist === NULL) $node->print_display_urllist = variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
+
_print_node_conf_modify($node->nid, $node->print_display, $node->print_display_comment, $node->print_display_urllist);
}
}
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => (function_exists('cck_extra_field_weight') && isset($form['type'])) ? cck_extra_field_weight($form['type']['#value'], 'print') : PRINT_TYPE_FIELDS_WEIGHT,
+ '#group' => 'additional_settings',
);
$form['print']['label'] = array(
$form['print']['print_display']['#default_value'] = variable_get('print_display_' . $form['#node_type']->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$form['print']['print_display_comment']['#default_value'] = variable_get('print_display_comment_' . $form['#node_type']->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$form['print']['print_display_urllist']['#default_value'] = variable_get('print_display_urllist_' . $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT);
- $form['print']['label']['#markup'] = '<p><em>' . t('The settings below only apply when some of the corresponding module-wide link settings are enabled.') . '</em></p>' . $form['print']['label']['#markup'];
}
else {
$node = $form['#node'];
- $form['print']['print_display']['#default_value'] = isset($node->print_display) ? $node->print_display : PRINT_TYPE_SHOW_LINK_DEFAULT;
- $form['print']['print_display_comment']['#default_value'] = isset($node->print_display_comment) ? $node->print_display_comment : PRINT_TYPE_COMMENT_LINK_DEFAULT;
- $form['print']['print_display_urllist']['#default_value'] = isset($node->print_display_urllist) ? $node->print_display_urllist : PRINT_TYPE_URLLIST_DEFAULT;
- $form['print']['label']['#markup'] = '<p><em>' . t('The settings below only apply in case the corresponding type-specific setting is also enabled (except for the "Show link in individual comments").') . '</em></p>' . $form['print']['label']['#markup'];
+ $form['print']['print_display']['#default_value'] = isset($node->print_display) ? $node->print_display : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
+ $form['print']['print_display_comment']['#default_value'] = isset($node->print_display_comment) ? $node->print_display_comment : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ $form['print']['print_display_urllist']['#default_value'] = isset($node->print_display_urllist) ? $node->print_display_urllist : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
}
}
}
/**
- * 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,
),
);
}
else {
$res = FALSE;
}
- $node->print_display = $res ? intval($res->link) : PRINT_TYPE_SHOW_LINK_DEFAULT;
- $node->print_display_comment = $res ? intval($res->comments) : PRINT_TYPE_COMMENT_LINK_DEFAULT;
- $node->print_display_urllist = $res ? intval($res->url_list) : PRINT_TYPE_URLLIST_DEFAULT;
+ $node->print_display = $res ? intval($res->link) : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
+ $node->print_display_comment = $res ? intval($res->comments) : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ $node->print_display_urllist = $res ? intval($res->url_list) : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
/**
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();
}
* value of the url_list field (0 or 1)
*/
function _print_node_conf_modify($nid, $link, $comments, $url_list) {
- if (($link == PRINT_TYPE_SHOW_LINK_DEFAULT) && ($comments == PRINT_TYPE_COMMENT_LINK_DEFAULT) &&
- ($url_list == PRINT_TYPE_URLLIST_DEFAULT)) {
- db_delete('print_node_conf')
- ->condition('nid', $nid)
- ->execute();
- }
- else {
db_merge('print_node_conf')
->key(array('nid' => $nid))
->fields(array(
'url_list' => $url_list,
))
->execute();
- }
}
/**
$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']) || !user_access('access print')) {
- // If showing only the teaser or the user is not allowed or link is disabled
+ $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);
}
}
$print_html_node_link_visibility = variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT);
$print_html_node_link_pages = variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT);
- if (!_print_page_match($print_html_node_link_visibility, "node/". $node->nid, $print_html_node_link_pages)) {
+ if (!_print_page_match($print_html_node_link_visibility, "node/" . $node->nid, $print_html_node_link_pages)) {
// Page not in visibility list
return FALSE;
}
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) : PRINT_TYPE_COMMENT_LINK_DEFAULT;
- if (($print_display_comment) ||
- 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;
}
}
else {
// Node link
- if ((!$node->print_display) || (isset($node_type) &&
- !variable_get('print_display_' . $node_type, PRINT_TYPE_SHOW_LINK_DEFAULT))) {
- // Link for this node type is disabled
+ if (!$node->print_display) {
+ // Link for this node is disabled
return FALSE;
}
elseif (isset($node->book)) {
}
}
- return implode('&', $params);
+ return $params;
}