function _print_var_generator in Printer, email and PDF versions 5.3
Same name and namespace in other branches
- 5.4 print.pages.inc \_print_var_generator()
- 5.2 print.module \_print_var_generator()
- 6 print.pages.inc \_print_var_generator()
- 7 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
$message: optional sender's message (used by the send e-mail 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 126 - Contains the functions to generate Printer-friendly pages.
Code
function _print_var_generator($node, $message = NULL, $cid = NULL) {
global $base_url;
$path = empty($node->nid) ? $node->path : "node/{$node->nid}";
$themed = theme('print_text');
// print module settings
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
$print_urls = variable_get('print_urls', PRINT_URLS_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_sendtoprinter = variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_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'] = $GLOBALS['locale'];
$print['title'] = $node->title;
$print['head'] = drupal_get_html_head();
$print['scripts'] = drupal_get_js();
$print['robots_meta'] = _print_robots_meta_generator();
$print['url'] = url($path, NULL, NULL, TRUE);
$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)) {
$replace_pairs = array(
'%b' => base_path(),
'%t' => path_to_theme(),
);
$user_css = strip_tags(strtr($print_css, $replace_pairs));
}
else {
drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css');
}
$drupal_css = drupal_add_css();
foreach ($drupal_css as $key => $types) {
// Unset the theme's CSS
$drupal_css[$key]['theme'] = array();
}
// If we are sending a message via e-mail, the CSS must be embedded
if (!empty($message)) {
$style = '';
$css_files = array();
foreach ($drupal_css as $types) {
foreach ($types as $values) {
$css_files = array_merge($css_files, array_keys($values));
}
}
if (!empty($print_css)) {
// Convert to a local path, by removing the base_path
$pattern = '!^' . base_path() . '!';
$css_files[] = preg_replace($pattern, '', $user_css);
}
foreach ($css_files as $filename) {
$res = file_get_contents($filename, TRUE);
if ($res != FALSE) {
$style .= $res;
}
}
$print['css'] = "<style type='text/css' media='all'>{$style}</style>\n";
}
else {
$print['css'] = drupal_get_css($drupal_css);
if (!empty($print_css)) {
$print['css'] .= "<link type='text/css' rel='stylesheet' media='all' href='{$user_css}' />\n";
}
}
$print['sendtoprinter'] = $print_html_sendtoprinter ? ' onload="window.print();"' : '';
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;
}
$print['logo'] = $logo_url ? "<img class='print-logo' src='{$logo_url}' alt='' />\n" : '';
switch ($print_footer_options) {
case 0:
// none
$footer = '';
break;
case 1:
// theme's
$footer = filter_xss_admin(variable_get('site_footer', FALSE)) . "\n" . theme('blocks', 'footer');
$logo_url = theme_get_setting('logo');
break;
case 2:
// user-specifed
$footer = $print_footer_user;
break;
}
$print['footer_message'] = $footer;
$published_site = variable_get('site_name', 0);
if ($published_site) {
$published = empty($themed['published']) ? t('Published on %site_name', array(
'%site_name' => $published_site,
)) : $themed['published'] . ' ' . $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(time(), 'small');
$retrieved = empty($themed['retrieved']) ? t('retrieved on %date', array(
'%date' => $retrieved_date,
)) : $themed['retrieved'] . ' ' . $retrieved_date;
$print['printdate'] = $print_sourceurl_date ? " ({$retrieved})" : '';
$source_url = empty($themed['sourceURL']) ? t('Source URL') : $themed['sourceURL'];
$print['source_url'] = '<strong>' . $source_url . $print['printdate'] . ':</strong> ' . l($url, $url);
}
else {
$print['source_url'] = '';
}
if (isset($node->type)) {
$node_type = $node->type;
if (theme_get_setting("toggle_node_info_{$node_type}")) {
$by_author = $node->name ? $node->name : variable_get('anonymous', t('Anonymous'));
$by = empty($themed['by']) ? t('By %author', array(
'%author' => $by_author,
)) : $themed['by'] . ' ' . $by_author;
$print['submitted'] = $by;
$created_datetime = format_date($node->created, 'small');
$created = empty($themed['created']) ? t('Created %date', array(
'%date' => $created_datetime,
)) : $themed['created'] . ' ' . $created_datetime;
$print['created'] = $created;
}
else {
$print['submitted'] = '';
$print['created'] = '';
}
$print['type'] = $node->type;
}
else {
$print['submitted'] = '';
$print['created'] = '';
$print['type'] = '';
}
menu_set_active_item($path);
$breadcrumb = drupal_get_breadcrumb();
if (!empty($breadcrumb)) {
$breadcrumb[] = menu_get_active_title();
$print['breadcrumb'] = 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) . '] ' . $urls[$i] . "<br />\n";
}
$links = empty($themed['links']) ? t('Links') : $themed['links'];
$print['pfp_links'] = "<p><strong>{$links}:</strong><br />{$pfp_links}</p>";
}
}
if (module_exists('taxonomy')) {
$terms = taxonomy_link('taxonomy terms', $node);
$print['taxonomy'] = theme('links', $terms);
}
$print['content'] = $node->body;
$print['node'] = $node;
$print['message'] = $message;
return $print;
}