function print_preprocess_print in Printer, email and PDF versions 7.2
Same name and namespace in other branches
- 7 print.module \print_preprocess_print()
Implements hook_preprocess_HOOK().
File
- ./
print.pages.inc, line 127
Code
function print_preprocess_print(&$variables) {
$node = $variables['node'];
$format = $variables['format'];
$path = drupal_get_path_alias(empty($node->nid) ? $node->path : "node/{$node->nid}");
static $hooks = NULL;
if (!isset($hooks)) {
drupal_theme_initialize();
$hooks = theme_get_registry();
}
$variables['page']['#show_messages'] = FALSE;
$variables['theme_hook_suggestions'] = array();
// Stolen from theme() so that ALL preprocess functions are called.
$hook = 'page';
$info = $hooks[$hook];
if (isset($info['preprocess functions']) || isset($info['process functions'])) {
foreach (array(
'preprocess functions',
'process functions',
) as $phase) {
if (!empty($info[$phase])) {
foreach ($info[$phase] as $processor_function) {
if (function_exists($processor_function)) {
// We don't want a poorly behaved process function changing $hook.
$hook_clone = $hook;
$processor_function($variables, $hook_clone);
}
}
}
}
}
$logo_url = FALSE;
switch (variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT)) {
// Theme logo.
case 1:
$logo_url = theme_get_setting('logo');
break;
// User-specifed logo.
case 2:
$logo_url = strip_tags(variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT));
break;
}
$logo_url = preg_replace('!^' . base_path() . '!', '', $logo_url);
$variables['print_logo'] = $logo_url ? theme('image', array(
'path' => $logo_url,
'alt' => variable_get('site_name', 'Drupal'),
'attributes' => array(
'class' => array(
'print-logo',
),
'id' => 'logo',
),
)) : NULL;
$variables['print_node'] = $node;
$variables['content'] = $node->content;
$variables['scripts'] = drupal_get_js();
$variables['footer_scripts'] = drupal_get_js('footer');
$variables['sourceurl_enabled'] = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
$variables['url'] = url($path, array(
'absolute' => TRUE,
'query' => $variables['query'],
));
$variables['source_url'] = url(variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT) ? drupal_get_normal_path($path) : $path, array(
'alias' => TRUE,
'absolute' => TRUE,
'query' => $variables['query'],
));
$variables['cid'] = isset($node->cid) ? $node->cid : NULL;
$variables['print_title'] = html_entity_decode(check_plain($node->title));
$variables['head'] = drupal_get_html_head();
$variables['robots_meta'] = _print_robots_meta_generator();
$variables['css'] = _print_css_generator($variables['expand_css']);
if (variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT) && $format == 'html') {
drupal_add_js('misc/drupal.js', array(
'group' => JS_LIBRARY,
));
$window_close = variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT) && variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT) ? 'setTimeout(function(){window.close();}, 1);' : '';
$variables['sendtoprinter'] = '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function() {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>';
}
$type = isset($node->type) ? $node->type : '';
$nid = isset($node->nid) ? $node->nid : '';
$variables['theme_hook_suggestions'][] = "print__node__{$type}";
$variables['theme_hook_suggestions'][] = "print__node__{$type}__{$nid}";
$variables['theme_hook_suggestions'][] = "print__{$format}";
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}";
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}__{$nid}";
}