diff --git a/print.module b/print.module
index 67b596c16b22035c687e6fc3f210e835b2eb273b..39ac80f83af391a501afd0798d5fa8796aaf9d9f 100644
--- a/print.module
+++ b/print.module
@@ -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 .'
';
+ }
+ }
+ }
+ return $block;
+ break;
+ }
+}
+
/**
* Implementation of hook_link().
*/
@@ -176,15 +212,17 @@ 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 ''. print_insert_link() .'';
+ $link = print_insert_link();
+ if ($link) {
+ return "$link";
+ }
}
}
}
@@ -196,21 +234,15 @@ function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
$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;
- }
- else {
- $path = NULL;
+ $link = print_insert_link(NULL, $node);
+ if ($link) {
+ $node->content['print_link'] = array(
+ '#value' => "$link",
+ '#weight' => -1,
+ );
}
- $link = print_insert_link($path);
- $node->content['print_link'] = array(
- '#value' => "$link",
- '#weight' => -1,
- );
}
}
}
@@ -299,10 +331,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 +398,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 +443,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 ''. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'';
}
+ else {
+ return FALSE;
+ }
}
/**
@@ -437,6 +495,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;
diff --git a/print_mail/print_mail.module b/print_mail/print_mail.module
index 0de40a6d9631ecd1f637133445a935a6493a1db3..ecfb92d595e1d368df82557e8a7c5df5af1d413f 100644
--- a/print_mail/print_mail.module
+++ b/print_mail/print_mail.module
@@ -3,7 +3,7 @@
/**
* @file
- * Display printer-friendly versions of Drupal pages
+ * Displays Printer-friendly versions of Drupal pages.
*/
define('PRINTMAIL_PATH', 'printmail');
@@ -110,7 +110,9 @@ function print_mail_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
}
- return;
+ else {
+ return;
+ }
}
/**
@@ -118,15 +120,17 @@ 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 ''. print_mail_insert_link() .'';
+
+ $link = print_mail_insert_link();
+ if ($link) {
+ return "$link";
+ }
}
}
}
@@ -138,21 +142,15 @@ function print_mail_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
$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;
- }
- else {
- $path = NULL;
+ $link = print_mail_insert_link(NULL, $node);
+ if ($link) {
+ $node->content['print_mail_link'] = array(
+ '#value' => "$link",
+ '#weight' => -2,
+ );
}
- $link = print_mail_insert_link($path);
- $node->content['print_mail_link'] = array(
- '#value' => "$link",
- '#weight' => -2,
- );
}
}
}
@@ -205,18 +203,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'));
@@ -227,9 +254,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 ''. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'';
}
+ else {
+ return FALSE;
+ }
}
/**
@@ -248,6 +279,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;
@@ -264,7 +301,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;
@@ -275,7 +312,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;
diff --git a/print_pdf/print_pdf.module b/print_pdf/print_pdf.module
index b63d8189e2fe073c9f3d9741e7434661fa27e3d1..f3f155955cc6c1fe47aa48fba846288edf285620 100644
--- a/print_pdf/print_pdf.module
+++ b/print_pdf/print_pdf.module
@@ -3,7 +3,7 @@
/**
* @file
- * Display printer-friendly versions of Drupal pages
+ * Displays Printer-friendly versions of Drupal pages.
*/
define('PRINTPDF_PATH', 'printpdf');
@@ -154,7 +154,9 @@ function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
}
- return;
+ else {
+ return;
+ }
}
/**
@@ -162,15 +164,17 @@ 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 ''. print_pdf_insert_link() .'';
+
+ $link = print_pdf_insert_link();
+ if ($link) {
+ return "$link";
+ }
}
}
}
@@ -182,21 +186,15 @@ function print_pdf_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
$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(
+ '#value' => "$link",
+ '#weight' => -3,
+ );
}
- else {
- $path = NULL;
- }
- $link = print_pdf_insert_link($path);
- $node->content['print_pdf_link'] = array(
- '#value' => "$link",
- '#weight' => -3,
- );
}
}
}
@@ -248,20 +246,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
*
- * @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_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'));
@@ -272,9 +299,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 ''. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'';
}
+ else {
+ return FALSE;
+ }
}
/**
@@ -294,6 +325,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;
@@ -310,7 +347,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;
@@ -321,7 +358,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;
diff --git a/tests/print_basic.test b/tests/print_basic.test
index 011f09d21a37d793b32bdf6204debed65e444e32..6ad38c2cad5646795a606312364f27adf5d331d2 100644
--- a/tests/print_basic.test
+++ b/tests/print_basic.test
@@ -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