PRINT_PATH,
'title' => t('Printer-friendly'),
'callback' => 'print_controller',
'access' => user_access('access print'),
'type' => MENU_CALLBACK
);
$items[] = array(
'path' => 'admin/settings/print',
'title' => t('Printer-friendly'),
'description' => t('Adds a printer-friendly version link to node pages.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('print_main_settings'),
'access' => user_access('administer print'),
);
}
return $items;
}
/**
* Implementation of hook_link().
*/
function print_link($type, $node = NULL, $teaser = FALSE) {
$print_settings = variable_get('print_settings', print_settings_default());
// No link is shown for several motives...
if ( !($teaser) && ($node->type != 'book') && (!$node->parent) &&
($print_settings['show_link']) && user_access('access print') &&
(($type == 'comment' && variable_get('print_display_comment', '0')) ||
($type == 'node' && variable_get('print_display_'. $node->type, '1')))) {
$links = array();
$format = theme('print_format_link');
if ($type == 'comment') {
$query = "comment=$node->cid";
}
$links['print'] = array('href' => PRINT_PATH ."/". $node->nid,
'title' => $format['text'],
'attributes' => $format['attributes'],
'html' => $format['html'],
'query' => $query);
return $links;
}
else {
return;
}
}
/**
* Implementation of hook_link_alter().
*/
function print_link_alter(&$node, &$links) {
foreach ($links AS $module => $link) {
if (strstr($module, 'book_printer')) {
$print_settings = variable_get('print_settings', print_settings_default());
if ($print_settings['book_link']) {
$format = theme('print_format_link');
$format['attributes']['title'] = $link['attributes']['title'];
$links[$module]['href'] = PRINT_PATH ."/". $link['href'];
$links[$module]['attributes'] = $format['attributes'];
}
}
}
}
/**
* Implementation of hook_help()
*/
function print_help($path) {
$print_settings = variable_get('print_settings', print_settings_default());
if (($print_settings['show_link']) && ($print_settings['show_sys_link']) &&
user_access('access print') && (preg_match("/^node\//i", $path) == 0)) {
static $output = FALSE;
if ($output === FALSE) {
$output = TRUE;
return print_insert_link();
}
}
}
/**
* Implementation of hook_form_alter()
*/
function print_form_alter($form_id, &$form) {
// Add the node-type settings option to activate the printer-friendly version link
if ('node_type_form' == $form_id) {
$form['workflow']['print_display'] = array(
'#type' => 'checkbox',
'#title' => t('Show printer-friendly version link'),
'#return_value' => 1,
'#default_value' => variable_get('print_display_'. $form['#node_type']->type, '1'),
'#description' => t('Displays the link to a printer-friendly version of the content. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))),
);
}
elseif ('comment_admin_settings' == $form_id) {
$form['viewing_options']['print_display_comment'] = array(
'#type' => 'checkbox',
'#title' => t('Show printer-friendly version link in individual comments'),
'#return_value' => 1,
'#default_value' => variable_get('print_display_comment', '0'),
'#description' => t('Displays the link to a printer-friendly version of the comment. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))),
);
}
}
/********************************************************************
* Admin Settings: Print
********************************************************************/
/**
* Default values of the print_settings variable
*/
function print_settings_default() {
return array('show_link' => 1, 'show_sys_link' => 1, 'book_link' => 1, 'logo_url' => '', 'css' => '', 'urls' => 1, 'comments' => 0, 'newwindow' => 0, 'sendtoprinter' => 0);
}
/**
* Default values of the print_sourceurl_settings variable
*/
function print_sourceurl_settings_default() {
return array('enabled' => 1, 'date' => 0, 'forcenode' => 0);
}
/**
* Default values of the print_robot_settings variable
*/
function print_robot_settings_default() {
return array('noindex' => 1, 'nofollow' => 1, 'noarchive' => 0, 'nocache' => 0);
}
/**
* Print module settings form
*/
function print_main_settings() {
$print_settings = variable_get('print_settings', print_settings_default());
$form['print_settings'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
);
$form['print_settings']['show_link'] = array(
'#type' => 'radios',
'#title' => t('Printer-friendly page link'),
'#default_value' => $print_settings['show_link'],
'#options' => array(t("Disabled"), t("Enabled")),
'#description' => t("Enable or disable the printer-friendly page link for each node. Even if the link is disabled, you can still view the print version of a node by going to print/nid where nid is the numeric id of the node."),
);
$form['print_settings']['show_sys_link'] = array(
'#type' => 'checkbox',
'#title' => t('Show link in system (non-content) pages'),
'#return_value' => 1,
'#default_value' => $print_settings['show_sys_link'],
'#description' => t('Setting this option will add a printer-friendly version page link on pages created by Drupal or the enabled modules.'),
);
$form['print_settings']['book_link'] = array(
'#type' => 'checkbox',
'#title' => t('Take control of the book module printer-friendly link'),
'#return_value' => 1,
'#default_value' => $print_settings['book_link'],
'#description' => t('Activate this to have the printer-friendly link in book nodes handled by this module. Requires the (core) book module.'),
);
$form['print_settings']['logo_url'] = array(
'#type' => 'textfield',
'#title' => t('Logo URL'),
'#default_value' => $print_settings['logo_url'],
'#size' => 60,
'#maxlength' => 250,
'#description' => t('An alternative logo to display on the printer-friendly version. If left empty, the current theme\'s logo is used.'),
);
$form['print_settings']['css'] = array(
'#type' => 'textfield',
'#title' => t('Stylesheet URL'),
'#default_value' => $print_settings['css'],
'#size' => 60,
'#maxlength' => 64,
'#description' => t('The URL to your custom print cascading stylesheet, if any. When none is specified, the default module CSS file is used.'),
);
$form['print_settings']['urls'] = array(
'#type' => 'checkbox',
'#title' => t('Printer-friendly URLs list'),
'#return_value' => 1,
'#default_value' => $print_settings['urls'],
'#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.'),
);
$form['print_settings']['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Include comments in printer-friendly version'),
'#return_value' => 1,
'#default_value' => $print_settings['comments'],
'#description' => t('When this option is active, user comments are also included in the printer-friendly version. Requires the comment module.'),
);
$form['print_settings']['newwindow'] = array(
'#type' => 'radios',
'#title' => t('Open the printer-friendly version in a new window'),
'#options' => array(t("Disabled"), t("Use HTML target (does not validate as XHTML Strict)"), t("Use Javascript (requires browser support)")),
'#default_value' => $print_settings['newwindow'],
'#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
);
$form['print_settings']['sendtoprinter'] = array(
'#type' => 'checkbox',
'#title' => t('Send to printer'),
'#return_value' => 1,
'#default_value' => $print_settings['sendtoprinter'],
'#description' => t('Automatically calls the browser\'s print function when the printer-friendly version is displayed.'),
);
$print_sourceurl_settings = variable_get('print_sourceurl_settings', print_sourceurl_settings_default());
$form['print_sourceurl_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Source URL'),
'#collapsible' => true,
'#collapsed' => true,
'#tree' => true,
);
$form['print_sourceurl_settings']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Display source URL'),
'#return_value' => 1,
'#default_value' => $print_sourceurl_settings['enabled'],
'#description' => t('When this option is selected, the URL for the original page will be displayed at the bottom of the printer-friendly version.'),
);
$form['print_sourceurl_settings']['date'] = array(
'#type' => 'checkbox',
'#title' => t('Add current time/date to the source URL'),
'#return_value' => 1,
'#default_value' => $print_sourceurl_settings['date'],
'#description' => t('Display the current date and time in the Source URL line.'),
);
$form['print_sourceurl_settings']['forcenode'] = array(
'#type' => 'checkbox',
'#title' => t('Force use of node ID in source URL'),
'#return_value' => 1,
'#default_value' => $print_sourceurl_settings['forcenode'],
'#description' => t('Drupal will attempt to use the page\'s defined alias in case there is one. To force the use of the fixed URL, activate this option.'),
);
$print_robot_settings = variable_get('print_robot_settings', print_robot_settings_default());
$form['print_robot_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Robots META tags'),
'#collapsible' => true,
'#collapsed' => true,
'#tree' => TRUE,
);
$form['print_robot_settings']['noindex'] = array(
'#type' => 'checkbox',
'#title' => t('Add noindex'),
'#return_value' => 1,
'#default_value' => $print_robot_settings['noindex'],
'#description' => t('Instruct robots to not index printer-friendly pages. Recommended for good search engine karma.')
);
$form['print_robot_settings']['nofollow'] = array(
'#type' => 'checkbox',
'#title' => t('Add nofollow'),
'#return_value' => 1,
'#default_value' => $print_robot_settings['nofollow'],
'#description' => t('Instruct robots to not follow outgoing links on printer-friendly pages.')
);
$form['print_robot_settings']['noarchive'] = array(
'#type' => 'checkbox',
'#title' => t('Add noarchive'),
'#return_value' => 1,
'#default_value' => $print_robot_settings['noarchive'],
'#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages. Recognized by Googlebot.')
);
$form['print_robot_settings']['nocache'] = array(
'#type' => 'checkbox',
'#title' => t('Add nocache'),
'#return_value' => 1,
'#default_value' => $print_robot_settings['nocache'],
'#description' => t('Non-standard tag to instruct search engines to not show a "Cached" link for your printer-friendly pages')
);
return system_settings_form($form);
}
/********************************************************************
* Module Functions :: Controller
********************************************************************/
/**
* Print module path catcher
*/
function print_controller() {
// Remove the print/ prefix
$args = substr($_GET['q'], strlen(PRINT_PATH)+1);
$cid = $_GET['comment'];
$nid = $args;
if (!is_numeric($nid)) {
// Indirect call with print/alias
// If there is a path alias with these arguments, generate a printer-friendly version for it
$path = drupal_get_normal_path($args);
$ret = preg_match("/^node\/(.*)/i", $path, $matches);
if ($ret == 1) {
$nid = $matches[1];
}
}
if (is_numeric($nid)) {
print_generate_node($nid, $cid);
}
else {
$ret = preg_match("/^book\/export\/html\/(.*)/i", $args, $matches);
if ($ret == 1) {
// This is a book PF page link, handle trough the book handling functions
print_generate_book($matches[1]);
}
else {
// If no content node was found, handle the page printing with the 'printable' engine
print_generate_path($args);
}
}
}
/********************************************************************
* Module Functions : Auxiliary
********************************************************************/
/**
* Generates a meta tag to tell robots what they may index based on module settings
*
* @return string
*/
function _print_robots_meta_generator() {
$robots_settings = variable_get('print_robot_settings', print_robot_settings_default());
$robots_meta = array();
if (!empty($robots_settings['noindex'])) {
$robots_meta[] = 'noindex';
}
if (!empty($robots_settings['nofollow'])) {
$robots_meta[] = 'nofollow';
}
if (!empty($robots_settings['noarchive'])) {
$robots_meta[] = 'noarchive';
}
if (!empty($robots_settings['nocache'])) {
$robots_meta[] = 'nocache';
}
if (sizeof($robots_meta) > 0) {
$robots_meta = isset($robots_meta[1]) ? implode(', ', $robots_meta) : $robots_meta[0];
$robots_meta = '\n";
}
else {
$robots_meta = '';
}
return $robots_meta;
}
/**
* Generates the HTML to insert in the template file
*
* @return string
*/
function _print_var_generator($node, $cid = NULL) {
global $base_url;
$themed = theme('print_text');
// print module settings
$print_settings = variable_get('print_settings', print_settings_default());
$print_sourceurl_settings = variable_get('print_sourceurl_settings', print_sourceurl_settings_default());
$print["language"] = $GLOBALS['locale'];
$print["title"] = $node->title;
$print["robots_meta"] = _print_robots_meta_generator();
// $print["base_href"] = "
\n";
}
$print["pfp_links"] = "
". $themed['links'] ."
". $print["pfp_links"] ."