Commit e60934b7 authored by jcnventura's avatar jcnventura

Fix #258095: Add block with links to PF versions

Fix #318939: Add title tag to icons
parent 902d30af
......@@ -106,6 +106,42 @@ function print_menu() {
return $items;
}
/**
* Implementation of hook_block().
*/
function print_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$block[$delta]['info'] = t('Printer, e-mail and PDF versions');
return $block;
break;
case 'configure':
return '';
case 'save':
return;
case 'view':
$nid = preg_replace('!^node/!', '', $_GET['q']);
if (is_numeric($nid)) {
$node = node_load(array('nid' => $nid));
}
else {
$node = NULL;
}
$funcs = get_defined_functions();
$block['content'] = '';
foreach ($funcs['user'] as $func) {
if (preg_match('!^print.*?_insert_link$!', $func)) {
$link = $func(NULL, $node);
if (!empty($link)) {
$block['content'] .= $link .'<br />';
}
}
}
return $block;
break;
}
}
/**
* Implementation of hook_link().
*/
......@@ -176,43 +212,36 @@ function print_help($path, $arg) {
}
$print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT));
if (print_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0) &&
if ((preg_match('!^node/!i', $path) == 0) &&
!(empty($print_html_link_pos['link']) && empty($print_html_link_pos['corner']))) {
static $output = FALSE;
if ($output === FALSE) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$output = TRUE;
return '<span class="print-syslink">'. print_insert_link() .'</span>';
$link = print_insert_link();
if ($link) {
return "<span class='print-syslink'>$link</span>";
}
}
}
}
/**
* Implementation of hook_nodeapi().
* Implementation of hook_nodeapi_view().
*/
function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
function print_nodeapi_view(&$node, $teaser, $page) {
$print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT));
$allowed_type = print_link_allowed(array('node' => $node, 'teaser' => $teaser));
if (($allowed_type != FALSE) && !empty($print_html_link_pos['corner']) &&
if (($teaser === FALSE) && !empty($print_html_link_pos['corner']) &&
(preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINT_PATH .'/book/export/html/'. $node->nid;
$link = print_insert_link(NULL, $node);
if ($link) {
$node->content['print_link'] = array(
'#markup' => "<span class='print-link'>$link</span>",
'#weight' => -1,
);
}
else {
$path = NULL;
}
$link = print_insert_link($path);
$node->content['print_link'] = array(
'#value' => "<span class='print-link'>$link</span>",
'#weight' => -1,
);
}
}
}
/**
......@@ -299,10 +328,10 @@ function _print_format_link_aux($type = 0, $text = '', $img = '') {
$html = TRUE;
switch ($type) {
case 2:
$text = theme('image', $img, $text, '', array('class' => 'print-icon'));
$text = theme('image', $img, $text, $text, array('class' => 'print-icon'));
break;
case 3:
$text = theme('image', $img, $text, '', array('class' => 'print-icon print-icon-margin')) . $text;
$text = theme('image', $img, $text, $text, array('class' => 'print-icon print-icon-margin')) . $text;
break;
}
}
......@@ -366,19 +395,41 @@ function theme_print_text() {
* @param $path
* path of the original page (optional). If not specified, the current URL
* is used
* @param $node
* an optional node object, to be used in defining the path, if used, the
* path argument is irrelevant
* @return
* string with the HTML link to the printer-friendly page
*/
function print_insert_link($path = NULL) {
if (user_access('access print')) {
function print_insert_link($path = NULL, $node = NULL) {
if ($node !== NULL) {
$nid = $node->nid;
$path = 'node/'. $nid;
$allowed_type = print_link_allowed(array('node' => $node));
}
else {
if ($path === NULL) {
$print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT);
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
else {
$nid = NULL;
}
$allowed_type = print_link_allowed(array('path' => $path));
}
if ($print_html_link_use_alias) {
$path = drupal_get_path_alias($_GET['q']);
if ($allowed_type) {
if ($nid !== NULL) {
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = 'book/export/html/'. $nid;
}
else {
$path = preg_replace('!^node/!', '', $_GET['q']);
if (variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT)) {
$path = drupal_get_path_alias($path);
}
else {
$path = $nid;
}
}
$path = PRINT_PATH .'/'. $path;
$query = print_query_string_encode($_GET, array('q'));
......@@ -389,9 +440,13 @@ function print_insert_link($path = NULL) {
else {
$query = NULL;
}
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$format = theme('print_format_link');
return '<span class="print">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
}
else {
return FALSE;
}
}
/**
......@@ -437,6 +492,12 @@ function print_link_allowed($args) {
// If showing only the teaser or the user is not allowed or link is disabled
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (is_numeric($nid)) {
$args['node'] = node_load(array('nid' => $nid));
}
}
if (!empty($args['node'])) {
static $node_type = FALSE;
......
......@@ -3,7 +3,7 @@
/**
* @file
* Display printer-friendly versions of Drupal pages
* Displays Printer-friendly versions of Drupal pages.
*/
define('PRINTMAIL_PATH', 'printmail');
......@@ -107,7 +107,9 @@ function print_mail_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
}
return;
else {
return;
}
}
/**
......@@ -115,43 +117,36 @@ function print_mail_link($type, $node = NULL, $teaser = FALSE) {
*/
function print_mail_help($path, $arg) {
$print_mail_link_pos = variable_get('print_mail_link_pos', array(PRINT_MAIL_LINK_POS_DEFAULT => PRINT_MAIL_LINK_POS_DEFAULT));
if (print_mail_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0) &&
if ((preg_match('!^node/!i', $path) == 0) &&
!(empty($print_mail_link_pos['link']) && empty($print_mail_link_pos['corner']))) {
static $output = FALSE;
if ($output === FALSE) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$output = TRUE;
return '<span class="print-syslink">'. print_mail_insert_link() .'</span>';
$link = print_mail_insert_link();
if ($link) {
return "<span class='print-syslink'>$link</span>";
}
}
}
}
/**
* Implementation of hook_nodeapi().
* Implementation of hook_nodeapi_view().
*/
function print_mail_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
function print_mail_nodeapi_view(&$node, $teaser, $page) {
$print_mail_link_pos = variable_get('print_mail_link_pos', array(PRINT_MAIL_LINK_POS_DEFAULT => PRINT_MAIL_LINK_POS_DEFAULT));
$allowed_type = print_mail_link_allowed(array('node' => $node, 'teaser' => $teaser));
if (($allowed_type != FALSE) && !empty($print_mail_link_pos['corner']) &&
if (($teaser === FALSE) && !empty($print_mail_link_pos['corner']) &&
(preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINTMAIL_PATH .'/book/export/html/'. $node->nid;
$link = print_mail_insert_link(NULL, $node);
if ($link) {
$node->content['print_mail_link'] = array(
'#markup' => "<span class='print-link'>$link</span>",
'#weight' => -2,
);
}
else {
$path = NULL;
}
$link = print_mail_insert_link($path);
$node->content['print_mail_link'] = array(
'#value' => "<span class='print-link'>$link</span>",
'#weight' => -2,
);
}
}
}
/**
......@@ -202,18 +197,47 @@ function theme_print_mail_format_link() {
/**
* Auxiliary function to display a formatted send by e-mail link
*
* @return string
* Function made available so that developers may call this function from
* their defined pages/blocks.
*
* @param $path
* path of the original page (optional). If not specified, the current URL
* is used
* @param $node
* an optional node object, to be used in defining the path, if used, the
* path argument is irrelevant
* @return
* string with the HTML link to the printer-friendly page
*/
function print_mail_insert_link($path = NULL) {
if (user_access('access print')) {
function print_mail_insert_link($path = NULL, $node = NULL) {
if ($node !== NULL) {
$nid = $node->nid;
$path = 'node/'. $nid;
$allowed_type = print_mail_link_allowed(array('node' => $node));
}
else {
if ($path === NULL) {
$print_mail_link_use_alias = variable_get('print_mail_link_use_alias', PRINT_MAIL_LINK_USE_ALIAS_DEFAULT);
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
else {
$nid = NULL;
}
$allowed_type = print_mail_link_allowed(array('path' => $path));
}
if ($print_mail_link_use_alias) {
$path = drupal_get_path_alias($_GET['q']);
if ($allowed_type) {
if ($nid !== NULL) {
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = 'book/export/html/'. $nid;
}
else {
$path = preg_replace('!^node/!', '', $_GET['q']);
if (variable_get('print_mail_link_use_alias', PRINT_MAIL_LINK_USE_ALIAS_DEFAULT)) {
$path = drupal_get_path_alias($path);
}
else {
$path = $nid;
}
}
$path = PRINTMAIL_PATH .'/'. $path;
$query = print_query_string_encode($_GET, array('q'));
......@@ -224,9 +248,13 @@ function print_mail_insert_link($path = NULL) {
else {
$query = NULL;
}
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$format = theme('print_mail_format_link');
return '<span class="print_mail">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
}
else {
return FALSE;
}
}
/**
......@@ -245,6 +273,12 @@ function print_mail_link_allowed($args) {
// If showing only the teaser or the user is not allowed or link is disabled
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (is_numeric($nid)) {
$args['node'] = node_load(array('nid' => $nid));
}
}
if (!empty($args['node'])) {
static $node_type = FALSE;
......@@ -261,7 +295,7 @@ function print_mail_link_allowed($args) {
$print_mail_node_link_visibility = variable_get('print_mail_node_link_visibility', PRINT_MAIL_NODE_LINK_VISIBILITY_DEFAULT);
$print_mail_node_link_pages = variable_get('print_mail_node_link_pages', PRINT_MAIL_NODE_LINK_PAGES_DEFAULT);
if (!empty($node->printing) ||
if (!empty($node->printing) ||
!_print_page_match($print_mail_node_link_visibility, $print_mail_node_link_pages)) {
// Page not in visibility list or we are working!
return FALSE;
......@@ -272,7 +306,7 @@ function print_mail_link_allowed($args) {
}
else {
// Node link
if (isset($node_type) &&
if (isset($node_type) &&
!variable_get('print_mail_display_'. $node_type, PRINT_TYPE_SHOW_LINK_DEFAULT)) {
// Link for this node type is disabled
return FALSE;
......
......@@ -3,7 +3,7 @@
/**
* @file
* Display printer-friendly versions of Drupal pages
* Displays Printer-friendly versions of Drupal pages.
*/
define('PRINTPDF_PATH', 'printpdf');
......@@ -146,7 +146,9 @@ function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
}
return;
else {
return;
}
}
/**
......@@ -154,43 +156,36 @@ function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
*/
function print_pdf_help($path, $arg) {
$print_pdf_link_pos = variable_get('print_pdf_link_pos', array(PRINT_PDF_LINK_POS_DEFAULT => PRINT_PDF_LINK_POS_DEFAULT));
if (print_pdf_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0) &&
if ((preg_match('!^node/!i', $path) == 0) &&
!(empty($print_pdf_link_pos['link']) && empty($print_pdf_link_pos['corner']))) {
static $output = FALSE;
if ($output === FALSE) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$output = TRUE;
return '<span class="print-syslink">'. print_pdf_insert_link() .'</span>';
$link = print_pdf_insert_link();
if ($link) {
return "<span class='print-syslink'>$link</span>";
}
}
}
}
/**
* Implementation of hook_nodeapi().
* Implementation of hook_nodeapi_view().
*/
function print_pdf_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
function print_pdf_nodeapi_view(&$node, $teaser, $page) {
$print_pdf_link_pos = variable_get('print_pdf_link_pos', array(PRINT_PDF_LINK_POS_DEFAULT => PRINT_PDF_LINK_POS_DEFAULT));
$allowed_type = print_pdf_link_allowed(array('node' => $node, 'teaser' => $teaser));
if (($allowed_type != FALSE) && !empty($print_pdf_link_pos['corner']) &&
if (($teaser === FALSE) && !empty($print_pdf_link_pos['corner']) &&
(preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINTPDF_PATH .'/book/export/html/'. $node->nid;
$link = print_pdf_insert_link(NULL, $node);
if ($link) {
$node->content['print_pdf_link'] = array(
'#markup' => "<span class='print-link'>$link</span>",
'#weight' => -3,
);
}
else {
$path = NULL;
}
$link = print_pdf_insert_link($path);
$node->content['print_pdf_link'] = array(
'#value' => "<span class='print-link'>$link</span>",
'#weight' => -3,
);
}
}
}
/**
......@@ -240,20 +235,49 @@ function theme_print_pdf_format_link() {
}
/**
* Auxiliary function to display a formatted Printer-friendly link
* Auxiliary function to display a formatted PDF version link
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
*
* @return string
* @param $path
* path of the original page (optional). If not specified, the current URL
* is used
* @param $node
* an optional node object, to be used in defining the path, if used, the
* path argument is irrelevant
* @return
* string with the HTML link to the printer-friendly page
*/
function print_pdf_insert_link($path = NULL) {
if (user_access('access print')) {
function print_pdf_insert_link($path = NULL, $node = NULL) {
if ($node !== NULL) {
$nid = $node->nid;
$path = 'node/'. $nid;
$allowed_type = print_pdf_link_allowed(array('node' => $node));
}
else {
if ($path === NULL) {
$print_pdf_link_use_alias = variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT);
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
else {
$nid = NULL;
}
$allowed_type = print_pdf_link_allowed(array('path' => $path));
}
if ($print_pdf_link_use_alias) {
$path = drupal_get_path_alias($_GET['q']);
if ($allowed_type) {
if ($nid !== NULL) {
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = 'book/export/html/'. $nid;
}
else {
$path = preg_replace('!^node/!', '', $_GET['q']);
if (variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT)) {
$path = drupal_get_path_alias($path);
}
else {
$path = $nid;
}
}
$path = PRINTPDF_PATH .'/'. $path;
$query = print_query_string_encode($_GET, array('q'));
......@@ -264,9 +288,13 @@ function print_pdf_insert_link($path = NULL) {
else {
$query = NULL;
}
drupal_add_css(drupal_get_path('module', 'print') .'/css/printlinks.css');
$format = theme('print_pdf_format_link');
return '<span class="print_pdf">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
}
else {
return FALSE;
}
}
/**
......@@ -286,6 +314,12 @@ function print_pdf_link_allowed($args) {
// If showing only the teaser or the user is not allowed or link is disabled
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (is_numeric($nid)) {
$args['node'] = node_load(array('nid' => $nid));
}
}
if (!empty($args['node'])) {
static $node_type = FALSE;
......@@ -302,7 +336,7 @@ function print_pdf_link_allowed($args) {
$print_pdf_node_link_visibility = variable_get('print_pdf_node_link_visibility', PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT);
$print_pdf_node_link_pages = variable_get('print_pdf_node_link_pages', PRINT_PDF_NODE_LINK_PAGES_DEFAULT);
if (!empty($node->printing) ||
if (!empty($node->printing) ||
!_print_page_match($print_pdf_node_link_visibility, $print_pdf_node_link_pages)) {
// Page not in visibility list or we are working!
return FALSE;
......@@ -313,7 +347,7 @@ function print_pdf_link_allowed($args) {
}
else {
// Node link
if (isset($node_type) &&
if (isset($node_type) &&
!variable_get('print_pdf_display_'. $node_type, PRINT_TYPE_SHOW_LINK_DEFAULT)) {
// Link for this node type is disabled
return FALSE;
......
......@@ -20,6 +20,8 @@ require_once(drupal_get_path('module', 'print') .'/print.pages.inc');
* @see _print_pdf_tcpdf()
*/
function print_pdf_controller() {
global $base_url;
$args = func_get_args();
// Remove the printpdf/ prefix
$path = implode('/', $args);
......@@ -37,6 +39,15 @@ function print_pdf_controller() {
$print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
$print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
$print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);
// And converted from private to public paths
$file_downloads = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?${base_url}/)system/files(/[^>]*?>)!is";
$replacement = '$1'. file_directory_path() .'$2';
$print['content'] = preg_replace($pattern, $replacement, $print['content']);
$print['logo'] = preg_replace($pattern, $replacement, $print['logo']);
$print['footer_message'] = preg_replace($pattern, $replacement, $print['footer_message']);
}
$node = $print['node'];
ob_start();
......
......@@ -15,7 +15,7 @@ class PrintBasicTest extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
public function getInfo() {
function getInfo() {
return array(
'name' => t('Printer, e-mail and PDF versions tests'),
'description' => t('Unit tests for the print, print_mail and print_pdf modules.'),
......@@ -26,7 +26,7 @@ class PrintBasicTest extends DrupalWebTestCase {
/**
* Implementation of setUp().
*/
public function setUp() {
function setUp() {
parent::setUp();
// User to set up print.
......@@ -42,13 +42,13 @@ class PrintBasicTest extends DrupalWebTestCase {
/**
* Implementation of tearDown().
*/
public function tearDown() {
function tearDown() {
$_GET['q'] = $this->getq;
parent::tearDown();
}
public function testPrintRewriteUrls() {
function testPrintRewriteUrls() {
global $base_url, $base_root;
//Must require it, since this function gets called via Drupal's dynamic loading
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment