You are here

function _print_var_generator in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print.pages.inc \_print_var_generator()
  2. 5.2 print.module \_print_var_generator()
  3. 5.3 print.pages.inc \_print_var_generator()
  4. 7 print.pages.inc \_print_var_generator()
  5. 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 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 151

Code

function _print_var_generator($node, $message = NULL, $cid = NULL) {
  global $base_url, $language, $_print_urls;
  $path = empty($node->nid) ? $node->path : "node/{$node->nid}";

  // Needed because of the theme_get_setting() calls below
  init_theme();

  // 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', 'core');
  }
  $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,
  ));
  $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 => $types) {

      // Unset the theme's CSS
      $drupal_css[$key]['theme'] = array();
    }
  }

  // If we are sending a message via email, 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));
      }
    }
    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 ? 'window.close();' : '';
  $print['sendtoprinter'] = $print_html_sendtoprinter ? '<script type="text/javascript">Drupal.behaviors.print = function(context) {$(window).load(function() {window.print();' . $window_close . '})};</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', $logo_url, $site_name, '', array(
    'class' => 'print-logo',
    'id' => 'logo',
  ), FALSE) : '';
  switch ($print_footer_options) {
    case 0:

      // none
      $footer = '';
      break;
    case 1:

      // theme's
      $footer = variable_get('site_footer', FALSE) . "\n" . theme('blocks', 'footer');
      break;
    case 2:

      // user-specifed
      $footer = $print_footer_user;
      break;
  }
  $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(time(), 'small');
    $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;
}