function _print_var_generator in Printer, email and PDF versions 7
Same name and namespace in other branches
- 5.4 print.pages.inc \_print_var_generator()
- 5.2 print.module \_print_var_generator()
- 5.3 print.pages.inc \_print_var_generator()
- 6 print.pages.inc \_print_var_generator()
- 5.x print.pages.inc \_print_var_generator()
Post-processor that fills the array for the template with common details
Parameters
$node: generated node with a printer-friendly node body
array $query: (optional) array of key/value pairs as used in the url() function for the query
$message: optional sender's message (used by the send email module)
$cid: id of current comment being generated (NULL when not generating an individual comment)
Return value
array with the fields to be used in the template
3 calls to _print_var_generator()
- _print_generate_book in ./
print.pages.inc - Prepare a Printer-friendly-ready node body for book pages
- _print_generate_node in ./
print.pages.inc - Prepare a Printer-friendly-ready node body for content nodes
- _print_generate_path in ./
print.pages.inc - Prepare a Printer-friendly-ready node body for non-content pages
File
- ./
print.pages.inc, line 163
Code
function _print_var_generator($node, $query = NULL, $message = NULL, $cid = NULL) {
global $base_url, $language, $_print_urls;
$path = empty($node->nid) ? $node->path : "node/{$node->nid}";
// print module settings
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
$print_keep_theme_css = variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT);
$print_logo_options = variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT);
$print_logo_url = variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT);
$print_html_new_window = variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT);
$print_html_sendtoprinter = variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT);
$print_html_windowclose = variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT);
$print_sourceurl_enabled = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
$print_sourceurl_forcenode = variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT);
$print_sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT);
$print_footer_options = variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT);
$print_footer_user = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
$print['language'] = $language->language;
$print['title'] = check_plain($node->title);
$print['head'] = drupal_get_html_head();
if ($print_html_sendtoprinter) {
drupal_add_js('misc/drupal.js', array(
'weight' => JS_LIBRARY,
));
}
$print['scripts'] = drupal_get_js();
$print['footer_scripts'] = drupal_get_js('footer');
$print['robots_meta'] = _print_robots_meta_generator();
$print['url'] = url($path, array(
'absolute' => TRUE,
'query' => $query,
));
$print['base_href'] = "<base href='" . $print['url'] . "' />\n";
$print['favicon'] = theme_get_setting('toggle_favicon') ? "<link rel='shortcut icon' href='" . theme_get_setting('favicon') . "' type='image/x-icon' />\n" : '';
if (!empty($print_css)) {
drupal_add_css(strtr($print_css, array(
'%t' => drupal_get_path('theme', variable_get('theme_default')),
)));
}
else {
drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css');
}
$drupal_css = drupal_add_css();
if (!$print_keep_theme_css) {
foreach ($drupal_css as $key => $css_file) {
if ($css_file['group'] == CSS_THEME) {
// Unset the theme's CSS
unset($drupal_css[$key]);
}
}
}
// If we are sending a message via email, the CSS must be embedded
if (!empty($message)) {
$style = '';
$css_files = array_keys($drupal_css);
foreach ($css_files as $filename) {
$res = file_exists($filename) ? file_get_contents($filename, TRUE) : FALSE;
if ($res != FALSE) {
$style .= $res;
}
}
$print['css'] = "<style type='text/css' media='all'>{$style}</style>\n";
}
else {
$print['css'] = drupal_get_css($drupal_css);
}
$window_close = $print_html_new_window && $print_html_windowclose ? 'setTimeout(function(){window.close();},1);' : '';
$print['sendtoprinter'] = $print_html_sendtoprinter ? '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function(context) {$(window).load(function() {window.print();' . $window_close . '})}}})(jQuery);</script>' : '';
switch ($print_logo_options) {
case 0:
// none
$logo_url = 0;
break;
case 1:
// theme's
$logo_url = theme_get_setting('logo');
break;
case 2:
// user-specifed
$logo_url = strip_tags($print_logo_url);
break;
}
$logo_url = preg_replace('!^' . base_path() . '!', '', $logo_url);
$site_name = variable_get('site_name', 'Drupal');
$print['logo'] = $logo_url ? theme('image', array(
'path' => $logo_url,
'alt' => $site_name,
'attributes' => array(
'class' => array(
'print-logo',
),
'id' => 'logo',
),
)) : '';
switch ($print_footer_options) {
case 0:
// none
$footer = '';
break;
case 1:
// theme's
$footer_blocks = block_get_blocks_by_region('footer');
$footer = variable_get('site_footer', FALSE) . "\n" . drupal_render($footer_blocks);
break;
case 2:
// user-specifed
$footer = $print_footer_user;
break;
}
// Delete the contextual links
$footer = preg_replace('!\\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer);
$print['footer_message'] = filter_xss_admin($footer);
$published_site = variable_get('site_name', 0);
if ($published_site) {
$print_text_published = filter_xss(variable_get('print_text_published', t('Published on %site_name')));
$published = t($print_text_published, array(
'%site_name' => $published_site,
));
$print['site_name'] = $published . ' (' . l($base_url, $base_url) . ')';
}
else {
$print['site_name'] = '';
}
if ($print_sourceurl_enabled == 1) {
/* Grab and format the src URL */
if (empty($print_sourceurl_forcenode)) {
$url = $print['url'];
}
else {
$url = $base_url . '/' . ((bool) variable_get('clean_url', '0') ? '' : '?q=') . $path;
}
if (is_int($cid)) {
$url .= "#comment-{$cid}";
}
$retrieved_date = format_date(REQUEST_TIME, 'short');
$print_text_retrieved = filter_xss(variable_get('print_text_retrieved', t('retrieved on %date')));
$retrieved = t($print_text_retrieved, array(
'%date' => $retrieved_date,
));
$print['printdate'] = $print_sourceurl_date ? " ({$retrieved})" : '';
$source_url = filter_xss(variable_get('print_text_source_url', t('Source URL')));
$print['source_url'] = '<strong>' . $source_url . $print['printdate'] . ':</strong> ' . l($url, $url);
}
else {
$print['source_url'] = '';
}
$print['type'] = isset($node->type) ? $node->type : '';
menu_set_active_item($path);
$breadcrumb = drupal_get_breadcrumb();
if (!empty($breadcrumb)) {
$breadcrumb[] = menu_get_active_title();
$print['breadcrumb'] = filter_xss(implode(' > ', $breadcrumb));
}
else {
$print['breadcrumb'] = '';
}
// Display the collected links at the bottom of the page. Code once taken from Kjartan Mannes' project.module
$print['pfp_links'] = '';
if (!empty($_print_urls)) {
$urls = _print_friendly_urls();
$max = count($urls);
$pfp_links = '';
if ($max) {
for ($i = 0; $i < $max; $i++) {
$pfp_links .= '[' . ($i + 1) . '] ' . check_plain($urls[$i]) . "<br />\n";
}
$links = filter_xss(variable_get('print_text_links', t('Links')));
$print['pfp_links'] = "<p><strong>{$links}:</strong><br />{$pfp_links}</p>";
}
}
$print['node'] = $node;
$print['message'] = $message;
return $print;
}