security updates
have to check views and entityreference for custom patches
This commit is contained in:
@@ -22,25 +22,25 @@ function print_controller_html() {
|
||||
$args = func_get_args();
|
||||
$path = filter_xss(implode('/', $args));
|
||||
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
|
||||
$link = print_print_link();
|
||||
|
||||
// Handle the query
|
||||
$query = $_GET;
|
||||
unset($query['q']);
|
||||
$node = print_controller($path, $link['format'], $cid);
|
||||
if ($node) {
|
||||
// Handle the query
|
||||
$query = $_GET;
|
||||
unset($query['q']);
|
||||
|
||||
$print = print_controller($path, $query, $cid, PRINT_HTML_FORMAT);
|
||||
if ($print !== FALSE) {
|
||||
$node = $print['node'];
|
||||
$html = theme('print', array('print' => $print, 'type' => PRINT_HTML_FORMAT, 'node' => $node));
|
||||
$html = theme('print', array('node' => $node, 'query' => $query, 'format' => $link['format']));
|
||||
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
|
||||
drupal_send_headers();
|
||||
print $html;
|
||||
|
||||
$nodepath = (isset($node->path) && is_string($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
|
||||
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
|
||||
db_merge('print_page_counter')
|
||||
->key(array('path' => $nodepath))
|
||||
->fields(array(
|
||||
'totalcount' => 1,
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'totalcount' => 1,
|
||||
'timestamp' => REQUEST_TIME,
|
||||
))
|
||||
->expression('totalcount', 'totalcount + 1')
|
||||
->execute();
|
||||
@@ -53,26 +53,24 @@ function print_controller_html() {
|
||||
* Depending on the type of node, this functions chooses the appropriate
|
||||
* generator function.
|
||||
*
|
||||
* @param $path
|
||||
* @param string $path
|
||||
* path of the original page
|
||||
* @param array $query
|
||||
* (optional) array of key/value pairs as used in the url() function for the
|
||||
* query
|
||||
* @param $cid
|
||||
* comment ID of the individual comment to be rendered
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format of the page being generated
|
||||
* @param $teaser
|
||||
* if set to TRUE, outputs only the node's teaser
|
||||
* @param $message
|
||||
* optional sender's message (used by the send email module)
|
||||
* @return
|
||||
* array with the fields to be used in the template
|
||||
* @param int $cid
|
||||
* comment ID of the individual comment to be rendered
|
||||
* @param string $view_mode
|
||||
* (optional) view mode to be used when rendering the content
|
||||
*
|
||||
* @return object
|
||||
* node-like object to be used in the print template
|
||||
*
|
||||
* @see _print_generate_node()
|
||||
* @see _print_generate_path()
|
||||
* @see _print_generate_book()
|
||||
* @see print_preprocess_print()
|
||||
*/
|
||||
function print_controller($path, $query = NULL, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
||||
function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
|
||||
if (empty($path)) {
|
||||
// If no path was provided, let's try to generate a page for the referer
|
||||
global $base_url;
|
||||
@@ -93,113 +91,301 @@ function print_controller($path, $query = NULL, $cid = NULL, $format = PRINT_HTM
|
||||
array_shift($parts);
|
||||
$path = implode('/', $parts);
|
||||
}
|
||||
if (ctype_digit($parts[0]) && (count($parts) == 1)) {
|
||||
$print = _print_generate_node($path, $query, $cid, $format, $teaser, $message);
|
||||
$revision_view = preg_match('!^[\d]*/revisions/[\d]*/view$!', $path);
|
||||
if (ctype_digit($parts[0]) && ((count($parts) == 1) || $revision_view)) {
|
||||
$vid = $revision_view ? $parts[2] : NULL;
|
||||
$node = _print_generate_node($path, $format, $vid, $cid, $view_mode);
|
||||
}
|
||||
else {
|
||||
$ret = preg_match('!^book/export/html/(.*)!i', $path, $matches);
|
||||
if ($ret == 1) {
|
||||
// This is a book PF page link, handle trough the book handling functions
|
||||
$print = _print_generate_book($matches[1], $query, $format, $teaser, $message);
|
||||
$node = _print_generate_book($matches[1], $format);
|
||||
}
|
||||
else {
|
||||
// If no content node was found, handle the page printing with the 'printable' engine
|
||||
$print = _print_generate_path($path, $query, $format, $teaser, $message);
|
||||
$node = _print_generate_path($path, $format);
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK().
|
||||
*/
|
||||
function print_preprocess_print(&$variables) {
|
||||
global $language;
|
||||
|
||||
$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;
|
||||
|
||||
// Stolen from theme() so that ALL preprocess functions are called
|
||||
$hook = 'page';
|
||||
$info = $hooks[$hook];
|
||||
if (isset($info['preprocess functions']) || isset($info['process functions'])) {
|
||||
$variables['theme_hook_suggestions'] = array();
|
||||
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)) {
|
||||
case 1: // theme's
|
||||
$logo_url = theme_get_setting('logo');
|
||||
break;
|
||||
case 2: // user-specifed
|
||||
$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' => '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'] = 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('weight' => JS_LIBRARY));
|
||||
|
||||
$window_close = (variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT) && variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT)) ? 'window.close();' : '';
|
||||
$variables['sendtoprinter'] = '<script type="text/javascript">(function ($) { Drupal.behaviors.print = {attach: function(context) {$(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'] = array();
|
||||
$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}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the published line of the print template.
|
||||
*
|
||||
* @param array $vars
|
||||
* An empty associative array
|
||||
*
|
||||
* @return string
|
||||
* HTML text with the published line
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_published($vars) {
|
||||
global $base_url;
|
||||
|
||||
$published_site = variable_get('site_name', 0);
|
||||
return $published_site ? t('Published on %site_name', array('%site_name' => $published_site)) . ' (' . l($base_url, $base_url) . ')' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the breadcrumb line of the print template.
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $node: the node object
|
||||
*
|
||||
* @return string
|
||||
* HTML text with the breadcrumb
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_breadcrumb($vars) {
|
||||
$node = $vars['node'];
|
||||
$old_path = $_GET['q'];
|
||||
|
||||
$path = empty($node->nid) ? $node->path : "node/$node->nid";
|
||||
menu_set_active_item($path);
|
||||
$breadcrumb = drupal_get_breadcrumb();
|
||||
if (!empty($breadcrumb)) {
|
||||
$breadcrumb[] = menu_get_active_title();
|
||||
menu_set_active_item($old_path);
|
||||
return filter_xss(implode(' > ', $breadcrumb));
|
||||
}
|
||||
else {
|
||||
menu_set_active_item($old_path);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the footer of the print template.
|
||||
*
|
||||
* @param array $vars
|
||||
* An empty associative array
|
||||
*
|
||||
* @return string
|
||||
* HTML text with the footer
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_footer($vars) {
|
||||
$footer = '';
|
||||
|
||||
switch (variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT)) {
|
||||
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 = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
|
||||
break;
|
||||
}
|
||||
// Delete the contextual links
|
||||
$footer = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer);
|
||||
|
||||
return filter_xss_admin($footer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the source URL line of the print template.
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $url: the URL to the full node view.
|
||||
* - $node: the node object.
|
||||
* - $cid; comment ID of the comment to display.
|
||||
*
|
||||
* @return string
|
||||
* HTML text with the footer
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_sourceurl($vars) {
|
||||
$sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT);
|
||||
$url = is_int($vars['cid']) ? $vars['url'] . '#comment-' . $vars['cid'] : $vars['url'];
|
||||
|
||||
$output = '<strong>' . t('Source URL');
|
||||
if ($sourceurl_date && isset($vars['node'])) {
|
||||
$output .= ' (';
|
||||
$date = format_date($vars['node']->changed, 'short');
|
||||
|
||||
$output .= empty($vars['node']->nid) ? t('retrieved on !date', array('!date' => $date)) : t('modified on !date', array('!date' => $date));
|
||||
|
||||
$output .= ')';
|
||||
}
|
||||
$output .= ':</strong> ' . $url;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the URL list of the print template.
|
||||
*
|
||||
* @param array $vars
|
||||
* An empty associative array
|
||||
*
|
||||
* @return string
|
||||
* HTML text with the URL list
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_url_list($vars) {
|
||||
global $_print_urls;
|
||||
|
||||
// Display the collected links at the bottom of the page. Code once taken from Kjartan Mannes' project.module
|
||||
if (!empty($_print_urls)) {
|
||||
$urls = _print_friendly_urls();
|
||||
$max = count($urls);
|
||||
$url_list = '';
|
||||
foreach ($urls as $key => $url) {
|
||||
drupal_alter('print_url_list', $url);
|
||||
$url_list .= '[' . ($key + 1) . '] ' . check_plain($url) . "<br />\n";
|
||||
}
|
||||
if (!empty($url_list)) {
|
||||
return "<p><strong>" . t('Links') . "</strong><br />$url_list</p>";
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $print;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a robots meta tag to tell them what they may index
|
||||
*
|
||||
* @return
|
||||
* string with the meta robots tag
|
||||
* @return string
|
||||
* meta robots tag
|
||||
*/
|
||||
function _print_robots_meta_generator() {
|
||||
$print_robots_noindex = variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT);
|
||||
$print_robots_nofollow = variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT);
|
||||
$print_robots_noarchive = variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT);
|
||||
$robots_meta = array();
|
||||
|
||||
if (!empty($print_robots_noindex)) {
|
||||
if (variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT)) {
|
||||
$robots_meta[] = 'noindex';
|
||||
}
|
||||
if (!empty($print_robots_nofollow)) {
|
||||
if (variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT)) {
|
||||
$robots_meta[] = 'nofollow';
|
||||
}
|
||||
if (!empty($print_robots_noarchive)) {
|
||||
if (variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT)) {
|
||||
$robots_meta[] = 'noarchive';
|
||||
}
|
||||
|
||||
if (count($robots_meta) > 0) {
|
||||
$robots_meta = implode(', ', $robots_meta);
|
||||
$robots_meta = "<meta name='robots' content='$robots_meta' />\n";
|
||||
return '<meta name="robots" content=' . implode(', ', $robots_meta) . ' />';
|
||||
}
|
||||
else {
|
||||
$robots_meta = '';
|
||||
return '';
|
||||
}
|
||||
|
||||
return $robots_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-processor that fills the array for the template with common details
|
||||
* Generates the CSS directive to include in the printer-friendly version
|
||||
*
|
||||
* @param $node
|
||||
* generated node with a printer-friendly node body
|
||||
* @param array $query
|
||||
* (optional) array of key/value pairs as used in the url() function for the
|
||||
* query
|
||||
* @param $message
|
||||
* optional sender's message (used by the send email module)
|
||||
* @param $cid
|
||||
* id of current comment being generated (NULL when not generating
|
||||
* an individual comment)
|
||||
* @return
|
||||
* array with the fields to be used in the template
|
||||
* @param bool $expand
|
||||
* If TRUE, the provided CSS will be expanded, instead of given as a list
|
||||
* of includes.
|
||||
*
|
||||
* @return string
|
||||
* applicable CSS
|
||||
*/
|
||||
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
|
||||
function _print_css_generator($expand = FALSE) {
|
||||
$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' => path_to_theme())));
|
||||
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) {
|
||||
if (!variable_get('print_keep_theme_css', PRINT_KEEP_THEME_CSS_DEFAULT)) {
|
||||
foreach ($drupal_css as $key => $css_file) {
|
||||
if ($css_file['group'] == CSS_THEME) {
|
||||
// Unset the theme's CSS
|
||||
@@ -208,131 +394,33 @@ function _print_var_generator($node, $query = NULL, $message = NULL, $cid = NULL
|
||||
}
|
||||
}
|
||||
|
||||
// If we are sending a message via email, the CSS must be embedded
|
||||
if (!empty($message)) {
|
||||
// Expand the CSS if requested
|
||||
if ($expand) {
|
||||
$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;
|
||||
if (file_exists($filename)) {
|
||||
$style .= file_get_contents($filename, TRUE);
|
||||
}
|
||||
}
|
||||
$print['css'] = "<style type='text/css' media='all'>$style</style>\n";
|
||||
return "<style type='text/css' media='all'>$style</style>\n";
|
||||
}
|
||||
else {
|
||||
$print['css'] = drupal_get_css($drupal_css);
|
||||
return 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">(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' => '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;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for the preg_replace_callback for URL-capable patterns
|
||||
*
|
||||
* Manipulate URLs to make them absolute in the URLs list, and to add a
|
||||
* [n] footnote marker.
|
||||
* Manipulate URLs to make them absolute in the URLs list, and add a [n]
|
||||
* footnote marker.
|
||||
*
|
||||
* @param $matches
|
||||
* @param array $matches
|
||||
* array with the matched tag patterns, usually <a...>+text+</a>
|
||||
* @return
|
||||
* tag with re-written URL and when appropriate the [n] index to the
|
||||
* URL list
|
||||
*
|
||||
* @return string
|
||||
* tag with re-written URL and, if applicable, the [n] index to the URL list
|
||||
*/
|
||||
function _print_rewrite_urls($matches) {
|
||||
global $base_url, $base_root, $_print_urls;
|
||||
@@ -387,7 +475,7 @@ function _print_rewrite_urls($matches) {
|
||||
}
|
||||
// Because base href is the original page, change the link to
|
||||
// still be usable inside the print page
|
||||
$matches[1] = str_replace($url, base_path() . $_GET['q'] . $url, $matches[1]);
|
||||
$matches[1] = str_replace($url, check_plain(base_path() . $_GET['q'] . $url), $matches[1]);
|
||||
}
|
||||
else {
|
||||
// URL is relative, convert it into absolute URL
|
||||
@@ -416,15 +504,16 @@ function _print_rewrite_urls($matches) {
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return filter_xss_admin($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to store the Printer-friendly URLs list as static.
|
||||
*
|
||||
* @param $url
|
||||
* @param string $url
|
||||
* absolute URL to be inserted in the list
|
||||
* @return
|
||||
*
|
||||
* @return array
|
||||
* list of URLs previously stored if $url is 0, or the current count
|
||||
* otherwise.
|
||||
*/
|
||||
@@ -448,43 +537,20 @@ function _print_friendly_urls($url = 0) {
|
||||
/**
|
||||
* Check URL list settings for this node
|
||||
*
|
||||
* @param node
|
||||
* @param object $node
|
||||
* node object
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format of the page being generated
|
||||
* @return
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if URL list should be displayed, FALSE otherwise
|
||||
*/
|
||||
function _print_url_list_enabled($node, $format = PRINT_HTML_FORMAT) {
|
||||
function _print_url_list_enabled($node, $format) {
|
||||
if (!isset($node->type)) {
|
||||
switch ($format) {
|
||||
case PRINT_HTML_FORMAT:
|
||||
$node_urllist = variable_get('print_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT);
|
||||
break;
|
||||
case PRINT_MAIL_FORMAT:
|
||||
$node_urllist = variable_get('print_mail_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT);
|
||||
break;
|
||||
case PRINT_PDF_FORMAT:
|
||||
$node_urllist = variable_get('print_pdf_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT);
|
||||
break;
|
||||
default:
|
||||
$node_urllist = PRINT_TYPE_SYS_URLLIST_DEFAULT;
|
||||
}
|
||||
$node_urllist = variable_get('print_' . $format . '_display_sys_urllist', PRINT_TYPE_SYS_URLLIST_DEFAULT);
|
||||
}
|
||||
else {
|
||||
switch ($format) {
|
||||
case PRINT_HTML_FORMAT:
|
||||
$node_urllist = isset($node->print_display_urllist) ? $node->print_display_urllist : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
break;
|
||||
case PRINT_MAIL_FORMAT:
|
||||
$node_urllist = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
break;
|
||||
case PRINT_PDF_FORMAT:
|
||||
$node_urllist = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : variable_get('print_pdf_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
break;
|
||||
default:
|
||||
$node_urllist = PRINT_TYPE_URLLIST_DEFAULT;
|
||||
}
|
||||
$node_urllist = isset($node->{'print_' . $format . '_display_urllist'}) ? $node->{'print_' . $format . '_display_urllist'} : variable_get('print_' . $format . '_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
||||
}
|
||||
|
||||
// Get value of Printer-friendly URLs setting
|
||||
@@ -494,23 +560,21 @@ function _print_url_list_enabled($node, $format = PRINT_HTML_FORMAT) {
|
||||
/**
|
||||
* Prepare a Printer-friendly-ready node body for content nodes
|
||||
*
|
||||
* @param $nid
|
||||
* @param int $nid
|
||||
* node ID of the node to be rendered into a printer-friendly page
|
||||
* @param array $query
|
||||
* (optional) array of key/value pairs as used in the url() function for the
|
||||
* query
|
||||
* @param $cid
|
||||
* comment ID of the individual comment to be rendered
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format of the page being generated
|
||||
* @param $teaser
|
||||
* if set to TRUE, outputs only the node's teaser
|
||||
* @param $message
|
||||
* optional sender's message (used by the send email module)
|
||||
* @return
|
||||
* filled array ready to be used in the template
|
||||
* @param int $vid
|
||||
* (optional) revision ID of the node to use
|
||||
* @param int $cid
|
||||
* (optional) comment ID of the individual comment to be rendered
|
||||
* @param string $view_mode
|
||||
* (optional) view mode to be used when rendering the content
|
||||
*
|
||||
* @return object
|
||||
* filled node-like object to be used in the print template
|
||||
*/
|
||||
function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
||||
function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
|
||||
global $_print_urls;
|
||||
|
||||
if (!isset($langcode)) {
|
||||
@@ -518,7 +582,7 @@ function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_
|
||||
}
|
||||
|
||||
// We can take a node id
|
||||
$node = node_load($nid);
|
||||
$node = node_load($nid, $vid);
|
||||
if (!$node) {
|
||||
// Node not found
|
||||
drupal_not_found();
|
||||
@@ -531,17 +595,6 @@ function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_
|
||||
}
|
||||
drupal_set_title($node->title);
|
||||
|
||||
$view_mode = $teaser ? 'teaser' : 'print';
|
||||
|
||||
// Turn off Pagination by the Paging module
|
||||
unset($node->pages);
|
||||
unset($node->page_count);
|
||||
|
||||
// Make this page a member of the original page's organic group
|
||||
if (function_exists('og_set_group_context') && isset($node->og_groups)) {
|
||||
og_set_group_context($node->og_groups);
|
||||
}
|
||||
|
||||
if ($cid === NULL) {
|
||||
// Adapted (simplified) version of node_view
|
||||
// Render the node content
|
||||
@@ -549,18 +602,13 @@ function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_
|
||||
|
||||
// Disable the links area
|
||||
unset($node->content['links']);
|
||||
// Disable fivestar widget output
|
||||
unset($node->content['fivestar_widget']);
|
||||
// Disable service links module output
|
||||
unset($node->content['service_links']);
|
||||
|
||||
$build = $node->content;
|
||||
unset($node->content);
|
||||
}
|
||||
|
||||
$print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT);
|
||||
|
||||
if (function_exists('comment_node_page_additions') && (($cid != NULL) || ($print_comments))) {
|
||||
if (function_exists('comment_node_page_additions') &&
|
||||
(($cid != NULL) || (variable_get('print_comments', PRINT_COMMENTS_DEFAULT)))) {
|
||||
// Print only the requested comment (or if $cid is NULL, all of them)
|
||||
|
||||
$comments = comment_node_page_additions($node);
|
||||
@@ -609,30 +657,23 @@ function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_
|
||||
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
|
||||
$content = preg_replace_callback($pattern, '_print_rewrite_urls', $content);
|
||||
|
||||
$print = _print_var_generator($node, $query, $message, $cid);
|
||||
$print['content'] = $content;
|
||||
$node->content = $content;
|
||||
|
||||
return $print;
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a Printer-friendly-ready node body for non-content pages
|
||||
*
|
||||
* @param $path
|
||||
* @param string $path
|
||||
* path of the node to be rendered into a printer-friendly page
|
||||
* @param array $query
|
||||
* (optional) array of key/value pairs as used in the url() function for the
|
||||
* query
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format of the page being generated
|
||||
* @param $teaser
|
||||
* if set to TRUE, outputs only the node's teaser
|
||||
* @param $message
|
||||
* optional sender's message (used by the send email module)
|
||||
* @return
|
||||
* filled array ready to be used in the template
|
||||
*
|
||||
* @return object
|
||||
* filled node-like object to be used in the print template
|
||||
*/
|
||||
function _print_generate_path($path, $query = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
||||
function _print_generate_path($path, $format) {
|
||||
global $_print_urls;
|
||||
|
||||
// Handle node tabs
|
||||
@@ -646,13 +687,13 @@ function _print_generate_path($path, $query = NULL, $format = PRINT_HTML_FORMAT,
|
||||
menu_set_active_item($path);
|
||||
// Adapted from index.php.
|
||||
$node = new stdClass();
|
||||
$node->body = menu_execute_active_handler($path, FALSE);
|
||||
if (is_array($node->body)) {
|
||||
$node->body = drupal_render($node->body);
|
||||
$node->content = menu_execute_active_handler($path, FALSE);
|
||||
if (is_array($node->content)) {
|
||||
$node->content = drupal_render($node->content);
|
||||
}
|
||||
|
||||
if (is_int($node->body)) {
|
||||
switch ($node->body) {
|
||||
if (is_int($node->content)) {
|
||||
switch ($node->content) {
|
||||
case MENU_NOT_FOUND:
|
||||
drupal_not_found();
|
||||
return FALSE;
|
||||
@@ -666,43 +707,37 @@ function _print_generate_path($path, $query = NULL, $format = PRINT_HTML_FORMAT,
|
||||
|
||||
$node->title = drupal_get_title();
|
||||
$node->path = $path;
|
||||
$node->changed = 0;
|
||||
$node->changed = REQUEST_TIME;
|
||||
|
||||
// Delete any links area
|
||||
$node->body = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->body);
|
||||
$node->content = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->content);
|
||||
|
||||
// Delete the contextual links also
|
||||
$node->content = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $node->content);
|
||||
|
||||
// Check URL list settings
|
||||
$_print_urls = _print_url_list_enabled($node, $format);
|
||||
|
||||
// Convert the a href elements
|
||||
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
|
||||
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
|
||||
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content);
|
||||
|
||||
$print = _print_var_generator($node, $query, $message);
|
||||
$print['content'] = $node->body;
|
||||
|
||||
return $print;
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a Printer-friendly-ready node body for book pages
|
||||
*
|
||||
* @param $nid
|
||||
* @param int $nid
|
||||
* node ID of the node to be rendered into a printer-friendly page
|
||||
* @param array $query
|
||||
* (optional) array of key/value pairs as used in the url() function for the
|
||||
* query
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format of the page being generated
|
||||
* @param $teaser
|
||||
* if set to TRUE, outputs only the node's teaser
|
||||
* @param $message
|
||||
* optional sender's message (used by the send email module)
|
||||
* @return
|
||||
* filled array ready to be used in the template
|
||||
*
|
||||
* @return object
|
||||
* filled node-like object to be used in the print template
|
||||
*/
|
||||
function _print_generate_book($nid, $query = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
|
||||
function _print_generate_book($nid, $format) {
|
||||
global $_print_urls;
|
||||
|
||||
$node = node_load($nid);
|
||||
@@ -718,20 +753,14 @@ function _print_generate_book($nid, $query = NULL, $format = PRINT_HTML_FORMAT,
|
||||
}
|
||||
|
||||
$tree = book_menu_subtree_data($node->book);
|
||||
$node->body = book_export_traverse($tree, 'book_node_export');
|
||||
$node->content = book_export_traverse($tree, 'book_node_export');
|
||||
|
||||
// Check URL list settings
|
||||
$_print_urls = _print_url_list_enabled($node, $format);
|
||||
|
||||
// Convert the a href elements
|
||||
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
|
||||
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
|
||||
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content);
|
||||
|
||||
$print = _print_var_generator($node, $query, $message);
|
||||
$print['content'] = $node->body;
|
||||
|
||||
// The title is already displayed by the book_recurse, so avoid duplication
|
||||
$print['title'] = '';
|
||||
|
||||
return $print;
|
||||
return $node;
|
||||
}
|
||||
|
Reference in New Issue
Block a user