Commit 24247060 authored by jcnventura's avatar jcnventura

Coder fixes and update of library URLs

parent 5cc5aeb7
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
/** /**
* @file * @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 * @param string $library
* library to download. * Library to download.
* @param string $url * @param string $url
* URL of the file to download * URL of the file to download.
*/ */
function _print_drush_download_lib($library, $url) { function _print_drush_download_lib($library, $url) {
$path = drush_get_option('path'); $path = drush_get_option('path');
if (empty($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. // Create the path if it does not exist.
...@@ -29,18 +29,21 @@ function _print_drush_download_lib($library, $url) { ...@@ -29,18 +29,21 @@ function _print_drush_download_lib($library, $url) {
$olddir = getcwd(); $olddir = getcwd();
drush_op('chdir', $path); drush_op('chdir', $path);
// Warn about an existing dir // Warn about an existing dir.
if (is_dir($library)) { 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'); 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); $filename = _print_drush_download_file($url);
if ($filename) { if ($filename) {
$extract_ret = _print_drush_download_extract($filename); $extract_ret = _print_drush_download_extract($filename);
if ($extract_ret) { if ($extract_ret) {
// Remove the archive // Remove the archive.
drush_op('unlink', $filename); drush_op('unlink', $filename);
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success'); 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) { ...@@ -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. * Adapted from a function in drush/includes/drush.inc to support 302 redirects.
* *
* @param string $download_url * @param string $download_url
* The path to the file to download * The path to the file to download.
* *
* @return string * @return string
* The filename that was downloaded, or NULL if the file could not be * The filename that was downloaded, or NULL if the file could not be
* downloaded. * downloaded.
*/ */
function _print_drush_download_file($download_url) { 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')) { if (!drush_get_context('DRUSH_SIMULATE')) {
$wget_ret = drush_shell_exec("wget -nv --content-disposition %s", $download_url);
if ($wget_ret) { 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())); $wget_out = explode('"', array_shift(drush_shell_exec_output()));
$filename = $wget_out[1]; $filename = $wget_out[1];
} }
...@@ -83,13 +104,12 @@ function _print_drush_download_file($download_url) { ...@@ -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); $curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
if ($curl_ret) { if ($curl_ret) {
// File was donwloaded with the tempname // File was downloaded with the temporary name.
// Find the effective name.
// Find the effective name
$filename = explode('/', array_shift(drush_shell_exec_output())); $filename = explode('/', array_shift(drush_shell_exec_output()));
$filename = array_pop($filename); $filename = array_pop($filename);
// Rename file from tempname to effective name // Rename file from tempname to effective name.
if (!drush_op('rename', $tempnam, './' . $filename)) { if (!drush_op('rename', $tempnam, './' . $filename)) {
$filename = $tempnam; $filename = $tempnam;
} }
...@@ -110,7 +130,7 @@ function _print_drush_download_file($download_url) { ...@@ -110,7 +130,7 @@ function _print_drush_download_file($download_url) {
* Helper to extract the downloaded zip/tar archive. * Helper to extract the downloaded zip/tar archive.
* *
* @param string $filename * @param string $filename
* filename of the file to extract * Filename of the file to extract.
* *
* @return bool * @return bool
* TRUE on success, FALSE on failure * TRUE on success, FALSE on failure
...@@ -119,28 +139,36 @@ function _print_drush_download_extract($filename) { ...@@ -119,28 +139,36 @@ function _print_drush_download_extract($filename) {
$arch_ret = FALSE; $arch_ret = FALSE;
if (drush_op('is_file', $filename)) { 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: case 1:
$arch_ret = TRUE; $arch_ret = TRUE;
break; break;
case 'application/zip': case 'application/zip':
// Decompress the zip archive // Decompress the zip archive.
$arch_ret = drush_shell_exec('unzip -qq -o %s', $filename); $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'); drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
break; break;
case 'application/x-gzip': case 'application/x-gzip':
// Decompress the tar gz archive // Decompress the tar gz archive.
$arch_ret = drush_shell_exec('tar xzf %s', $filename); $arch_ret = drush_shell_exec('tar xzf %s', $filename);
break; break;
case 'application/x-bzip2': case 'application/x-bzip2':
// Decompress the tar bz2 archive // Decompress the tar bz2 archive.
$arch_ret = drush_shell_exec('tar xjf %s', $filename); $arch_ret = drush_shell_exec('tar xjf %s', $filename);
break; break;
case 'application/x-xz': case 'application/x-xz':
// Decompress the tar xz archive // Decompress the tar xz archive.
$arch_ret = drush_shell_exec('tar xJf %s', $filename); $arch_ret = drush_shell_exec('tar xJf %s', $filename);
break; break;
default:
drush_log(dt('Unknown MIME type: @type', array('@type' => $mime_type)), 'error');
} }
} }
else { else {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Common functions used by several of the print modules * Common functions used by several of the print modules.
* *
* @ingroup print * @ingroup print
*/ */
...@@ -29,18 +29,18 @@ function _print_scan_libs($lib, $mask) { ...@@ -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 * Replace spaces in URLs with %20
* *
* @param array $matches * @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 * @return string
* tag with re-written URL * tag with re-written URL
*/ */
function _print_replace_spaces($matches) { 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+!'; $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); $attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($attribs as $key => $value) { foreach ($attribs as $key => $value) {
...@@ -48,8 +48,8 @@ function _print_replace_spaces($matches) { ...@@ -48,8 +48,8 @@ function _print_replace_spaces($matches) {
} }
$size = count($attribs); $size = count($attribs);
for ($i=1; $i < $size; $i++) { for ($i = 1; $i < $size; $i++) {
// If the attribute is href or src, we may need to rewrite the URL in the value // 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) { if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
$url = trim($urls[1], " \t\n\r\0\x0B\"'"); $url = trim($urls[1], " \t\n\r\0\x0B\"'");
$new_url = str_replace(' ', '%20', $url); $new_url = str_replace(' ', '%20', $url);
...@@ -66,7 +66,7 @@ function _print_replace_spaces($matches) { ...@@ -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 * In some Drupal setups, the use of the 'private' filesystem or Apache's
* configuration prevent access to the images of the page. This function * configuration prevent access to the images of the page. This function
...@@ -74,9 +74,9 @@ function _print_replace_spaces($matches) { ...@@ -74,9 +74,9 @@ function _print_replace_spaces($matches) {
* filesystem. * filesystem.
* *
* @param string $html * @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 * @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 * @return string
* converted file names * converted file names
...@@ -86,7 +86,7 @@ function _print_access_images_via_file($html, $images_via_file) { ...@@ -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 : ''; $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"; $pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
$replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2'; $replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2';
$html = preg_replace($pattern, $replacement, $html); $html = preg_replace($pattern, $replacement, $html);
......
...@@ -19,7 +19,9 @@ function print_main_settings() { ...@@ -19,7 +19,9 @@ function print_main_settings() {
$print_css = variable_get('print_css', PRINT_CSS_DEFAULT); $print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
// Check that the stylesheet path is indeed valid and relative to base_path() // Check that the stylesheet path is indeed valid and relative to base_path()
if (!empty($print_css) && empty($_POST)) { 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)) { 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); 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() { ...@@ -37,8 +39,10 @@ function print_main_settings() {
'#size' => 60, '#size' => 60,
'#maxlength' => 250, '#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 />' . '#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('Macros: %t (path to theme: "%theme")', array(
t('Requires the <em>Administer site configuration</em> permission.'), '%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'), '#disabled' => !user_access('administer site configuration'),
); );
...@@ -54,7 +58,9 @@ function print_main_settings() { ...@@ -54,7 +58,9 @@ function print_main_settings() {
'#title' => t('Printer-friendly URLs list'), '#title' => t('Printer-friendly URLs list'),
'#default_value' => variable_get('print_urls', PRINT_URLS_DEFAULT), '#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 />' . '#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( $form['settings']['print_urls_anchors'] = array(
...@@ -89,7 +95,11 @@ function print_main_settings() { ...@@ -89,7 +95,11 @@ function print_main_settings() {
$form['settings']['logo']['print_logo_options'] = array( $form['settings']['logo']['print_logo_options'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Logo type'), '#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), '#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."), '#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() { ...@@ -120,7 +130,11 @@ function print_main_settings() {
$form['settings']['footer']['print_footer_options'] = array( $form['settings']['footer']['print_footer_options'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Footer type'), '#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), '#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."), '#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) { ...@@ -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 // files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload. // collector delete the original upload.
if ($filename = file_unmanaged_copy($file->uri)) { if ($filename = file_unmanaged_copy($file->uri)) {
/** @var DrupalStreamWrapperInterface $wrapper */
$wrapper = file_stream_wrapper_get_instance_by_uri($filename); $wrapper = file_stream_wrapper_get_instance_by_uri($filename);
$form_state['values']['print_logo_options'] = 2; $form_state['values']['print_logo_options'] = 2;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @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 * @ingroup print
*/ */
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
* etc.). * etc.).
* *
* @param string $url * @param string $url
* the url to be modified. * The url to be modified.
* *
* @ingroup print_hooks * @ingroup print_hooks
*/ */
......
...@@ -21,7 +21,7 @@ function print_install() { ...@@ -21,7 +21,7 @@ function print_install() {
* Implements hook_enable(). * Implements hook_enable().
*/ */
function print_enable() { function print_enable() {
// Module weight // Module weight.
db_update('system') db_update('system')
->fields(array( ->fields(array(
'weight' => 0, 'weight' => 0,
...@@ -146,7 +146,7 @@ function print_schema() { ...@@ -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) { function print_update_7000(&$sandbox) {
$renamed_deltas = array( $renamed_deltas = array(
...@@ -160,14 +160,14 @@ function print_update_7000(&$sandbox) { ...@@ -160,14 +160,14 @@ function print_update_7000(&$sandbox) {
} }
/** /**
* Enable the print UI module * Enable the print UI module.
*/ */
function print_update_7199(&$sandbox) { function print_update_7199(&$sandbox) {
module_enable(array('print_ui'), FALSE); module_enable(array('print_ui'), FALSE);
} }
/** /**
* Delete old variables * Delete old variables.
*/ */
function print_update_7200(&$sandbox) { function print_update_7200(&$sandbox) {
variable_del('print_settings'); variable_del('print_settings');
...@@ -193,7 +193,7 @@ function print_update_7200(&$sandbox) { ...@@ -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) { function print_update_7202(&$sandbox) {
$link_pos = variable_get('print_html_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }')); $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) { ...@@ -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) { function print_update_7203(&$sandbox) {
db_drop_primary_key('print_page_counter'); db_drop_primary_key('print_page_counter');
db_change_field('print_page_counter', 'path', 'path', 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'))); array('primary key' => array('path')));
} }
...@@ -85,7 +85,13 @@ function print_permission() { ...@@ -85,7 +85,13 @@ function print_permission() {
function print_theme() { function print_theme() {
return array( return array(
'print' => 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', 'template' => 'print',
'file' => 'print.pages.inc', 'file' => 'print.pages.inc',
), ),
...@@ -207,7 +213,7 @@ function print_block_view($delta = '') { ...@@ -207,7 +213,7 @@ function print_block_view($delta = '') {
case 'print-top': case 'print-top':
$block['subject'] = t('Most printed'); $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) $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)) { if (count($result)) {
$items = array(); $items = array();
foreach ($result as $obj) { foreach ($result as $obj) {
...@@ -224,11 +230,13 @@ function print_block_view($delta = '') { ...@@ -224,11 +230,13 @@ function print_block_view($delta = '') {
* Implements hook_help(). * Implements hook_help().
*/ */
function print_help($path, $arg) { function print_help($path, $arg) {
$ret = '';
switch ($path) { switch ($path) {
case 'admin/help#print': case 'admin/help#print':
// Return a line-break version of the module README // Return a line-break version of the module README.
return _filter_autop(file_get_contents(drupal_get_path('module', 'print') . '/README.txt')); $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) { ...@@ -251,7 +259,7 @@ function print_entity_info_alter(&$info) {
'custom settings' => FALSE, 'custom settings' => FALSE,
), ),
); );
// Add the 'Print' view mode for field_collections // Add the 'Print' view mode for field_collections.
if (module_exists('field_collection')) { if (module_exists('field_collection')) {
$info['field_collection_item']['view modes'] += array( $info['field_collection_item']['view modes'] += array(
PRINT_VIEW_MODE => array( PRINT_VIEW_MODE => array(
...@@ -263,10 +271,10 @@ function print_entity_info_alter(&$info) { ...@@ -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 * @param string $path
* path of the page being identified * Path of the page being identified.
* *
* @return string * @return string
* string with the page's title * string with the page's title
...@@ -276,16 +284,16 @@ function _print_get_title($path) { ...@@ -276,16 +284,16 @@ function _print_get_title($path) {
$nid = preg_replace('!^node/!', '', $path); $nid = preg_replace('!^node/!', '', $path);
if (ctype_digit($nid)) { if (ctype_digit($nid)) {
return db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid)) return db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid))
->fetchField(); ->fetchField();
} }
else { 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); $menu_item = menu_get_item($path);
if (!empty($menu_item['title'])) { if (!empty($menu_item['title'])) {
return $menu_item['title']; return $menu_item['title'];
} }
elseif (drupal_substr($menu_item['page_callback'], 0, 6) == 'views_') { 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']); $view = views_get_view($menu_item['page_arguments']['0']);
return $view->get_title(); return $view->get_title();
} }
...@@ -296,7 +304,7 @@ function _print_get_title($path) { ...@@ -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 * Function made available so that developers may call this function from
* their defined pages/blocks. * their defined pages/blocks.
...@@ -307,7 +315,7 @@ function _print_get_title($path) { ...@@ -307,7 +315,7 @@ function _print_get_title($path) {
* node object, to be used in checking node access. If the path argument is * node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid. * not provided, the path used will be node/nid.
* @param string $location * @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'). * 'block', 'help').
* *
* @return string * @return string
...@@ -317,7 +325,11 @@ function _print_get_title($path) { ...@@ -317,7 +325,11 @@ function _print_get_title($path) {
*/ */
function print_insert_link($path = NULL, $node = NULL, $location = '') { function print_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) { 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 { else {
return FALSE; return FALSE;
...@@ -325,11 +337,11 @@ function print_insert_link($path = NULL, $node = NULL, $location = '') { ...@@ -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 * @param array $args
* array containing the possible parameters: * Array containing the possible parameters:
* view_mode, node, type, path * view_mode, node, type, path.
* *
* @return bool * @return bool
* FALSE if not allowed, TRUE otherwise * FALSE if not allowed, TRUE otherwise
...@@ -342,7 +354,7 @@ function print_link_allowed($args) { ...@@ -342,7 +354,7 @@ function print_link_allowed($args) {
* Implements hook_contextual_links_view_alter(). * Implements hook_contextual_links_view_alter().
*/ */
function print_contextual_links_view_alter(&$element, $items) { function print_contextual_links_view_alter(&$element, $items) {
// Hide all contextual links // Hide all contextual links.
if (preg_match('!^print!', $_GET['q'])) { if (preg_match('!^print!', $_GET['q'])) {
unset($element['#links']); unset($element['#links']);