Commit 24247060 authored by jcnventura's avatar jcnventura

Coder fixes and update of library URLs

parent 5cc5aeb7
......@@ -2,21 +2,21 @@
/**
* @file
* common drush functions for the print submodules.
* Common drush functions for the print submodules.
*/
/**
* Download and extract the lib
* Download and extract the lib.
*
* @param string $library
* library to download.
* Library to download.
* @param string $url
* URL of the file to download
* URL of the file to download.
*/
function _print_drush_download_lib($library, $url) {
$path = drush_get_option('path');
if (empty($path)) {
$path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
$path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/' . $library;
}
// Create the path if it does not exist.
......@@ -29,18 +29,21 @@ function _print_drush_download_lib($library, $url) {
$olddir = getcwd();
drush_op('chdir', $path);
// Warn about an existing dir
// Warn about an existing dir.
if (is_dir($library)) {
// drush_op('rmdir', $library); // Directory must be empty for the php rmdir to work..
drush_log(dt('An existing @library was overwritten at @path', array('@library' => $library, '@path' => $path . '/' . $library)), 'notice');
}
// Download the archive
if (preg_match('!api.github.com/repos/.*/releases/latest!', $url)) {
$url = _print_drush_github_latest_url($url);
}
// Download the archive.
$filename = _print_drush_download_file($url);
if ($filename) {
$extract_ret = _print_drush_download_extract($filename);
if ($extract_ret) {
// Remove the archive
// Remove the archive.
drush_op('unlink', $filename);
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
}
......@@ -58,23 +61,41 @@ function _print_drush_download_lib($library, $url) {
}
/**
* Download a file using wget or curl
* Get filename of latest from github.
*
* @param string $github_url
* The github URL to the latest project release.
*
* @return string
* The URL to the latest file release.
*/
function _print_drush_github_latest_url($github_url) {
$filename = _print_drush_download_file($github_url);
$contents = file_get_contents($filename);
$json = json_decode($contents);
$download_url = $json->assets[0]->browser_download_url;
drush_op('unlink', $filename);
return $download_url;
}
/**
* Download a file using wget or curl.
*
* Adapted from a function in drush/includes/drush.inc to support 302 redirects.
*
* @param string $download_url
* The path to the file to download
* The path to the file to download.
*
* @return string
* The filename that was downloaded, or NULL if the file could not be
* downloaded.
*/
function _print_drush_download_file($download_url) {
$wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
if (!drush_get_context('DRUSH_SIMULATE')) {
$wget_ret = drush_shell_exec("wget -nv --content-disposition %s", $download_url);
if ($wget_ret) {
// Get the filename of the saved file from the output
// Get the filename of the saved file from the output.
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
$filename = $wget_out[1];
}
......@@ -83,13 +104,12 @@ function _print_drush_download_file($download_url) {
$curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
if ($curl_ret) {
// File was donwloaded with the tempname
// Find the effective name
// File was downloaded with the temporary name.
// Find the effective name.
$filename = explode('/', array_shift(drush_shell_exec_output()));
$filename = array_pop($filename);
// Rename file from tempname to effective name
// Rename file from tempname to effective name.
if (!drush_op('rename', $tempnam, './' . $filename)) {
$filename = $tempnam;
}
......@@ -110,7 +130,7 @@ function _print_drush_download_file($download_url) {
* Helper to extract the downloaded zip/tar archive.
*
* @param string $filename
* filename of the file to extract
* Filename of the file to extract.
*
* @return bool
* TRUE on success, FALSE on failure
......@@ -119,28 +139,36 @@ function _print_drush_download_extract($filename) {
$arch_ret = FALSE;
if (drush_op('is_file', $filename)) {
switch (drush_op('mime_content_type', $filename)) {
$mime_type = drush_op('mime_content_type', $filename);
switch ($mime_type) {
case 1:
$arch_ret = TRUE;
break;
case 'application/zip':
// Decompress the zip archive
// Decompress the zip archive.
$arch_ret = drush_shell_exec('unzip -qq -o %s', $filename);
// ZIP archives usually get the access rights wrong
// ZIP archives usually get the access rights wrong.
drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
break;
case 'application/x-gzip':
// Decompress the tar gz archive
// Decompress the tar gz archive.
$arch_ret = drush_shell_exec('tar xzf %s', $filename);
break;
case 'application/x-bzip2':
// Decompress the tar bz2 archive
// Decompress the tar bz2 archive.
$arch_ret = drush_shell_exec('tar xjf %s', $filename);
break;
case 'application/x-xz':
// Decompress the tar xz archive
// Decompress the tar xz archive.
$arch_ret = drush_shell_exec('tar xJf %s', $filename);
break;
default:
drush_log(dt('Unknown MIME type: @type', array('@type' => $mime_type)), 'error');
}
}
else {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Common functions used by several of the print modules
* Common functions used by several of the print modules.
*
* @ingroup print
*/
......@@ -29,18 +29,18 @@ function _print_scan_libs($lib, $mask) {
}
/**
* Callback function for the preg_replace_callback replacing spaces with %20
* Callback function for the preg_replace_callback replacing spaces with %20.
*
* Replace spaces in URLs with %20
*
* @param array $matches
* array with the matched tag patterns, usually <a...>+text+</a>
* Array with the matched tag patterns, usually <a...>+text+</a>.
*
* @return string
* tag with re-written URL
*/
function _print_replace_spaces($matches) {
// first, split the html into the different tag attributes
// Split the html into the different tag attributes.
$pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!';
$attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($attribs as $key => $value) {
......@@ -48,8 +48,8 @@ function _print_replace_spaces($matches) {
}
$size = count($attribs);
for ($i=1; $i < $size; $i++) {
// If the attribute is href or src, we may need to rewrite the URL in the value
for ($i = 1; $i < $size; $i++) {
// If the attribute is href or src, we need to rewrite the URL in the value.
if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\x0B\"'");
$new_url = str_replace(' ', '%20', $url);
......@@ -66,7 +66,7 @@ function _print_replace_spaces($matches) {
}
/**
* Convert image paths to the file:// protocol
* Convert image paths to the file:// protocol.
*
* In some Drupal setups, the use of the 'private' filesystem or Apache's
* configuration prevent access to the images of the page. This function
......@@ -74,9 +74,9 @@ function _print_replace_spaces($matches) {
* filesystem.
*
* @param string $html
* contents of the post-processed template already with the node data
* Contents of the post-processed template already with the node data.
* @param bool $images_via_file
* if TRUE, convert also files in the 'public' filesystem to local paths
* If TRUE, convert also files in the 'public' filesystem to local paths.
*
* @return string
* converted file names
......@@ -86,7 +86,7 @@ function _print_access_images_via_file($html, $images_via_file) {
$lang = (function_exists('language_negotiation_get_any') && language_negotiation_get_any('locale-url')) ? $language->language : '';
// Always convert private to local paths
// Always convert private to local paths.
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
$replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2';
$html = preg_replace($pattern, $replacement, $html);
......
......@@ -19,7 +19,9 @@ function print_main_settings() {
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
// Check that the stylesheet path is indeed valid and relative to base_path()
if (!empty($print_css) && empty($_POST)) {
$css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default', 'garland'))));
$css_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . strtr($print_css, array(
'%t' => drupal_get_path('theme', variable_get('theme_default', 'garland')),
));
if (!is_file($css_path) || !is_readable($css_path)) {
drupal_set_message(t("File %file is not readable by the web server.", array('%file' => $css_path)), 'warning', FALSE);
}
......@@ -37,8 +39,10 @@ function print_main_settings() {
'#size' => 60,
'#maxlength' => 250,
'#description' => t('The path to your custom print cascading stylesheet, if any. The path provided must be relative to the base path. When none is specified, the default module CSS file is used.') . '<br />' .
t('Macros: %t (path to theme: "%theme")', array('%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')))) . '<br />' .
t('Requires the <em>Administer site configuration</em> permission.'),
t('Macros: %t (path to theme: "%theme")', array(
'%theme' => drupal_get_path('theme', variable_get('theme_default', 'bartik')),
)) . '<br />' .
t('Requires the <em>Administer site configuration</em> permission.'),
'#disabled' => !user_access('administer site configuration'),
);
......@@ -54,7 +58,9 @@ function print_main_settings() {
'#title' => t('Printer-friendly URLs list'),
'#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT),
'#description' => t('If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.') . '<br />' .
t('Note that you can enable/disable the URL list for each content type individually from the !url.', array('!url' => l(t('Content Types page'), 'admin/structure/types'))),
t('Note that you can enable/disable the URL list for each content type individually from the !url.', array(
'!url' => l(t('Content Types page'), 'admin/structure/types'),
)),
);
$form['settings']['print_urls_anchors'] = array(
......@@ -89,7 +95,11 @@ function print_main_settings() {
$form['settings']['logo']['print_logo_options'] = array(
'#type' => 'radios',
'#title' => t('Logo type'),
'#options' => array(t('None (Disabled)'), t("Current theme's logo"), t('User-specified')),
'#options' => array(
t('None (Disabled)'),
t("Current theme's logo"),
t('User-specified'),
),
'#default_value' => variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT),
'#description' => t("Select the type of logo to display on the printer-friendly version. In case of a user-specified location, insert the path or URL below."),
);
......@@ -120,7 +130,11 @@ function print_main_settings() {
$form['settings']['footer']['print_footer_options'] = array(
'#type' => 'radios',
'#title' => t('Footer type'),
'#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
'#options' => array(
t('None (Disabled)'),
t("Site's footer"),
t('User-specified'),
),
'#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
'#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
);
......@@ -179,6 +193,7 @@ function _print_main_settings_validate($form, &$form_state) {
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
if ($filename = file_unmanaged_copy($file->uri)) {
/** @var DrupalStreamWrapperInterface $wrapper */
$wrapper = file_stream_wrapper_get_instance_by_uri($filename);
$form_state['values']['print_logo_options'] = 2;
......
......@@ -2,7 +2,7 @@
/**
* @file
* Main API entry point for the Printer, email and PDF versions
* Main API entry point for the Printer, email and PDF versions.
*
* @ingroup print
*/
......@@ -109,7 +109,7 @@
* etc.).
*
* @param string $url
* the url to be modified.
* The url to be modified.
*
* @ingroup print_hooks
*/
......
......@@ -21,7 +21,7 @@ function print_install() {
* Implements hook_enable().
*/
function print_enable() {
// Module weight
// Module weight.
db_update('system')
->fields(array(
'weight' => 0,
......@@ -146,7 +146,7 @@ function print_schema() {
}
/**
* Remove hardcoded numeric deltas from all blocks
* Remove hardcoded numeric deltas from all blocks.
*/
function print_update_7000(&$sandbox) {
$renamed_deltas = array(
......@@ -160,14 +160,14 @@ function print_update_7000(&$sandbox) {
}
/**
* Enable the print UI module
* Enable the print UI module.
*/
function print_update_7199(&$sandbox) {
module_enable(array('print_ui'), FALSE);
}
/**
* Delete old variables
* Delete old variables.
*/
function print_update_7200(&$sandbox) {
variable_del('print_settings');
......@@ -193,7 +193,7 @@ function print_update_7200(&$sandbox) {
}
/**
* Enable block and help area links
* Enable block and help area links.
*/
function print_update_7202(&$sandbox) {
$link_pos = variable_get('print_html_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
......@@ -203,11 +203,16 @@ function print_update_7202(&$sandbox) {
}
/**
* Increase size of the path field in the print_page_counter table
* Increase size of the path field in the print_page_counter table.
*/
function print_update_7203(&$sandbox) {
db_drop_primary_key('print_page_counter');
db_change_field('print_page_counter', 'path', 'path',
array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Page path',
),
array('primary key' => array('path')));
}
......@@ -85,7 +85,13 @@ function print_permission() {
function print_theme() {
return array(
'print' => array(
'variables' => array('node' => NULL, 'query' => NULL, 'format' => '', 'expand_css' => FALSE, 'message' => ''),
'variables' => array(
'node' => NULL,
'query' => NULL,
'format' => '',
'expand_css' => FALSE,
'message' => '',
),
'template' => 'print',
'file' => 'print.pages.inc',
),
......@@ -207,7 +213,7 @@ function print_block_view($delta = '') {
case 'print-top':
$block['subject'] = t('Most printed');
$result = db_query_range("SELECT path FROM {print_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY totalcount DESC", 0, 3)
->fetchAll();
->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
......@@ -224,11 +230,13 @@ function print_block_view($delta = '') {
* Implements hook_help().
*/
function print_help($path, $arg) {
$ret = '';
switch ($path) {
case 'admin/help#print':
// Return a line-break version of the module README
return _filter_autop(file_get_contents(drupal_get_path('module', 'print') . '/README.txt'));
// Return a line-break version of the module README.
$ret = _filter_autop(file_get_contents(drupal_get_path('module', 'print') . '/README.txt'));
}
return $ret;
}
/**
......@@ -251,7 +259,7 @@ function print_entity_info_alter(&$info) {
'custom settings' => FALSE,
),
);
// Add the 'Print' view mode for field_collections
// Add the 'Print' view mode for field_collections.
if (module_exists('field_collection')) {
$info['field_collection_item']['view modes'] += array(
PRINT_VIEW_MODE => array(
......@@ -263,10 +271,10 @@ function print_entity_info_alter(&$info) {
}
/**
* Auxiliary function to discover a given page's title
* Auxiliary function to discover a given page's title.
*
* @param string $path
* path of the page being identified
* Path of the page being identified.
*
* @return string
* string with the page's title
......@@ -276,16 +284,16 @@ function _print_get_title($path) {
$nid = preg_replace('!^node/!', '', $path);
if (ctype_digit($nid)) {
return db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid))
->fetchField();
->fetchField();
}
else {
// Not a node, try to get title from the menu system
// Not a node, try to get title from the menu system.
$menu_item = menu_get_item($path);
if (!empty($menu_item['title'])) {
return $menu_item['title'];
}
elseif (drupal_substr($menu_item['page_callback'], 0, 6) == 'views_') {
// It's a view, load the view to have access to the title
// It's a view, load the view to have access to the title.
$view = views_get_view($menu_item['page_arguments']['0']);
return $view->get_title();
}
......@@ -296,7 +304,7 @@ function _print_get_title($path) {
}
/**
* Auxiliary function to display a formatted Printer-friendly link
* Auxiliary function to display a formatted Printer-friendly link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
......@@ -307,7 +315,7 @@ function _print_get_title($path) {
* node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
* where in the page where the link is being inserted ('link', 'corner',
* Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return string
......@@ -317,7 +325,11 @@ function _print_get_title($path) {
*/
function print_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
return print_ui_insert_link(print_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
return print_ui_insert_link(print_print_link(), array(
'path' => $path,
'node' => $node,
'location' => $location,
));
}
else {
return FALSE;
......@@ -325,11 +337,11 @@ function print_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
* Check if the link to the PF version is allowed depending on the settings
* Check if the link to the PF version is allowed depending on the settings.
*
* @param array $args
* array containing the possible parameters:
* view_mode, node, type, path
* Array containing the possible parameters:
* view_mode, node, type, path.
*
* @return bool
* FALSE if not allowed, TRUE otherwise
......@@ -342,7 +354,7 @@ function print_link_allowed($args) {
* Implements hook_contextual_links_view_alter().
*/
function print_contextual_links_view_alter(&$element, $items) {
// Hide all contextual links
// Hide all contextual links.
if (preg_match('!^print!', $_GET['q'])) {
unset($element['#links']);
}
......
......@@ -14,23 +14,27 @@
$_print_urls = PRINT_URLS_DEFAULT;
/**
* Generate an HTML version of the printer-friendly page
* Generate an HTML version of the printer-friendly page.
*
* @see print_controller()
*/
function print_controller_html() {
$args = func_get_args();
$path = filter_xss(implode('/', $args));
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
$cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
$link = print_print_link();
$node = print_controller($path, $link['format'], $cid);
if ($node) {
// Handle the query
// Handle the query.
$query = $_GET;
unset($query['q']);
$html = theme('print', array('node' => $node, 'query' => $query, 'format' => $link['format']));
$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;
......@@ -48,19 +52,19 @@ function print_controller_html() {
}
/**
* Select the print generator function based on the page type
* Select the print generator function based on the page type.
*
* Depending on the type of node, this functions chooses the appropriate
* generator function.
*
* @param string $path
* path of the original page
* Path of the original page.
* @param string $format
* format of the page being generated
* Format of the page being generated.
* @param int $cid
* comment ID of the individual comment to be rendered
* Comment ID of the individual comment to be rendered.
* @param string $view_mode
* (optional) view mode to be used when rendering the content
* (Optional) view mode to be used when rendering the content.
*
* @return object
* node-like object to be used in the print template
......@@ -72,7 +76,7 @@ function print_controller_html() {
*/
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
// If no path was provided, let's try to generate a page for the referer.
global $base_url;
$ref = $_SERVER['HTTP_REFERER'];
......@@ -83,7 +87,8 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
}
if ($alias = drupal_lookup_path('source', $path)) {
// Indirect call with print/alias
// If there is a path alias with these arguments, generate a printer-friendly version for it
// If there is a path alias with these arguments, generate a
// printer-friendly version for it.
$path = $alias;
}
$parts = explode('/', $path);
......@@ -99,11 +104,12 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
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
// This is a book PF page link, handle trough the book handling functions.
$node = _print_generate_book($matches[1], $format);
}
else {
// If no content node was found, handle the page printing with the 'printable' engine
// If no content node was found, handle the page printing with the
// 'printable' engine.
$node = _print_generate_path($path, $format);
}
}
......@@ -115,8 +121,6 @@ function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_M
* 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");
......@@ -129,7 +133,7 @@ function print_preprocess_print(&$variables) {
$variables['page']['#show_messages'] = FALSE;
// Stolen from theme() so that ALL preprocess functions are called
// Stolen from theme() so that ALL preprocess functions are called.
$hook = 'page';
$info = $hooks[$hook];
if (isset($info['preprocess functions']) || isset($info['process functions'])) {
......@@ -149,35 +153,49 @@ function print_preprocess_print(&$variables) {
$logo_url = FALSE;
switch (variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT)) {
case 1: // theme's
// Theme logo.
case 1:
$logo_url = theme_get_setting('logo');
break;
case 2: // user-specifed
// 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'] = 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']);
$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'] = 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>';
$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 : '';
......@@ -195,7 +213,7 @@ function print_preprocess_print(&$variables) {
* Returns HTML for the published line of the print template.
*
* @param array $vars
* An empty associative array
* An empty associative array.
*
* @return string
* HTML text with the published line
......@@ -215,7 +233,7 @@ function theme_print_published($vars) {
*
* @param array $vars
* An associative array containing:
* - $node: the node object
* - $node: the node object.
*
* @return string
* HTML text with the breadcrumb
......@@ -245,7 +263,7 @@ function theme_print_breadcrumb($vars) {
* Returns HTML for the footer of the print template.
*
* @param array $vars
* An empty associative array
* An empty associative array.
*
* @return string
* HTML text with the footer
......@@ -257,15 +275,18 @@ function theme_print_footer($vars) {
$footer = '';
switch (variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT)) {
case 1: // theme's
// Theme footer.
case 1:
$footer_blocks = block_get_blocks_by_region('footer');
$footer = variable_get('site_footer', FALSE) . "\n" . drupal_render($footer_blocks);
break;
case 2: // user-specifed
// User-specified footer.
case 2:
$footer = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
break;
}
// Delete the contextual links
// Delete the contextual links.
$footer = preg_replace('!\s*<div class="contextual-links-wrapper">.*?</div>!sim', '', $footer);
return filter_xss_admin($footer);
......@@ -308,7 +329,7 @@ function theme_print_sourceurl($vars) {
* Returns HTML for the URL list of the print template.
*
* @param array $vars
* An empty associative array
* An empty associative array