summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--print.module4
-rw-r--r--print_mail.module126
-rw-r--r--print_pdf.module126
3 files changed, 162 insertions, 94 deletions
diff --git a/print.module b/print.module
index 540b5fa..b8e22e9 100644
--- a/print.module
+++ b/print.module
@@ -180,7 +180,7 @@ function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
$allowed_type = print_link_allowed(array('node' => $node, 'teaser' => $teaser));
- if (($allowed_type != FALSE) && (preg_match('!^print/!i', $_GET['q']) == 0)) {
+ if (($allowed_type != FALSE) && (preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/printlinks.css');
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINT_PATH .'/book/export/html/'. $node->nid;
@@ -352,7 +352,7 @@ function theme_print_text() {
function print_insert_link($path = NULL) {
if (user_access('access print')) {
if ($path === NULL) {
- $path = PRINT_PATH .'/'. $_GET['q'];
+ $path = PRINT_PATH .'/'. preg_replace('!^node/!', '', $_GET['q']);
$query = drupal_query_string_encode($_GET, array('q'));
if (empty($query)) {
$query = NULL;
diff --git a/print_mail.module b/print_mail.module
index bf263bc..9102b3b 100644
--- a/print_mail.module
+++ b/print_mail.module
@@ -68,29 +68,12 @@ function print_mail_menu() {
* Implementation of hook_link().
*/
function print_mail_link($type, $node = NULL, $teaser = FALSE) {
- $print_mail_book_link = variable_get('print_mail_book_link', PRINT_MAIL_BOOK_LINK_DEFAULT);
- $print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
- $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);
- static $print_mail_display_comment = FALSE;
-
- if (($print_mail_display_comment == FALSE) && (isset($node->type))) {
- $node_type = $node->type;
- $print_mail_display_comment = variable_get('print_mail_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
- $print_mail_display = variable_get('print_mail_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
- }
- else {
- $node_type = '';
- $print_mail_display = 1;
- }
-
- if (!$teaser) {
+ $allowed_type = print_mail_link_allowed(array('type' => $type, 'node' => $node, 'teaser' => $teaser));
+ if ($allowed_type) {
$links = array();
$format = theme('print_mail_format_link');
// Show book link
- if (($print_mail_book_link) && user_access('access printer-friendly version') &&
- (($node_type == 'book') || isset($node->book))) {
-
+ if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$links['book_mail'] = array('href' => PRINTMAIL_PATH .'/book/export/html/'. $node->nid,
'title' => $format['text'],
'attributes' => $format['attributes'],
@@ -99,13 +82,7 @@ function print_mail_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
- // No link is shown for several motives...
- elseif (($node_type != 'book') && (!isset($node->book)) &&
- ($print_mail_show_link) && user_access('access print') &&
- _print_page_match($print_mail_node_link_visibility, $print_mail_node_link_pages) &&
- (($type == 'comment' && $print_mail_display_comment) ||
- ($type == 'node' && $print_mail_display))) {
-
+ elseif ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
$query_arr = $_GET;
if ($type == 'comment') {
$query_arr['comment'] = $node->cid;
@@ -129,13 +106,7 @@ function print_mail_link($type, $node = NULL, $teaser = FALSE) {
* Implementation of hook_help().
*/
function print_mail_help($path, $arg) {
- $print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
- $print_mail_sys_link_visibility = variable_get('print_mail_sys_link_visibility', PRINT_MAIL_SYS_LINK_VISIBILITY_DEFAULT);
- $print_mail_sys_link_pages = variable_get('print_mail_sys_link_pages', PRINT_MAIL_SYS_LINK_PAGES_DEFAULT);
-
- if (($print_mail_show_link) && user_access('access print') &&
- _print_page_match($print_mail_sys_link_visibility, $print_mail_sys_link_pages) &&
- (preg_match('!^node/!i', $path) == 0)) {
+ if (print_mail_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0)) {
static $output = FALSE;
if ($output === FALSE) {
@@ -153,18 +124,10 @@ function print_mail_help($path, $arg) {
function print_mail_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
- $print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
- $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);
- $print_mail_display = variable_get('print_mail_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
-
- if ((!$teaser) && (!$node->printing) && ($print_mail_show_link) &&
- user_access('access print') && ($print_mail_display) &&
- _print_page_match($print_mail_node_link_visibility, $print_mail_node_link_pages)) {
+ $allowed_type = print_mail_link_allowed(array('node' => $node, 'teaser' => $teaser));
+ if (($allowed_type != FALSE) && (preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/printlinks.css');
- $print_mail_book_link = variable_get('print_mail_book_link', PRINT_MAIL_BOOK_LINK_DEFAULT);
- if (($print_mail_book_link) && user_access('access printer-friendly version') &&
- (($node->type == 'book') || isset($node->book))) {
+ if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINTMAIL_PATH .'/book/export/html/'. $node->nid;
}
$link = print_mail_insert_link($path);
@@ -229,7 +192,7 @@ function theme_print_mail_format_link() {
function print_mail_insert_link($path = NULL) {
if (user_access('access print')) {
if ($path === NULL) {
- $path = PRINTMAIL_PATH .'/'. $_GET['q'];
+ $path = PRINTMAIL_PATH .'/'. preg_replace('!^node/!', '', $_GET['q']);
$query = drupal_query_string_encode($_GET, array('q'));
if (empty($query)) {
$query = NULL;
@@ -239,3 +202,74 @@ function print_mail_insert_link($path = NULL) {
return '<span class="print_mail">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
}
}
+
+/**
+ * Determine a the link to send by e-mail is allowed depending on all possible settings
+ *
+ * @param $args
+ * array containing the possible parameters:
+ * teaser, node, type, path
+ * @return
+ * FALSE if not allowed
+ * PRINT_ALLOW_NORMAL_LINK if a normal link is allowed
+ * PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
+ */
+function print_mail_link_allowed($args) {
+ $print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
+ if ($args['teaser'] || !user_access('access print') || !$print_mail_show_link) {
+ // If showing only the teaser or the user is not allowed or link is disabled
+ return FALSE;
+ }
+ $node = $args['node'];
+ if (isset($node) && $node) {
+ static $node_type = FALSE;
+ if (($node_type === FALSE) && isset($node->type)) {
+ $node_type = $node->type;
+ }
+ else {
+ $node_type = '';
+ }
+ // Node
+ $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 ($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;
+ }
+ elseif (($args['type'] == 'comment') && isset($node_type)) {
+ // Link is for a comment, return the configured setting
+ return variable_get('print_mail_display_comment_'. $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ }
+ else {
+ // Node link
+ 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;
+ }
+ elseif (($node_type == 'book') || isset($node->book)) {
+ // Node is a book;
+ $print_mail_book_link = variable_get('print_mail_book_link', PRINT_MAIL_BOOK_LINK_DEFAULT);
+ if (!$print_mail_book_link || !user_access('access printer-friendly version')) {
+ // Book link is disabled
+ return FALSE;
+ }
+ else {
+ return PRINT_ALLOW_BOOK_LINK;
+ }
+ }
+ else {
+ return PRINT_ALLOW_NORMAL_LINK;
+ }
+ }
+ }
+ else {
+ // 'System' page
+ $print_mail_sys_link_visibility = variable_get('print_mail_sys_link_visibility', PRINT_MAIL_SYS_LINK_VISIBILITY_DEFAULT);
+ $print_mail_sys_link_pages = variable_get('print_mail_sys_link_pages', PRINT_MAIL_SYS_LINK_PAGES_DEFAULT);
+
+ return _print_page_match($print_mail_sys_link_visibility, $print_mail_sys_link_pages);
+ }
+}
diff --git a/print_pdf.module b/print_pdf.module
index 3958054..5190d68 100644
--- a/print_pdf.module
+++ b/print_pdf.module
@@ -87,29 +87,12 @@ function print_pdf_requirements($phase) {
* Implementation of hook_link().
*/
function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
- $print_pdf_book_link = variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT);
- $print_pdf_show_link = variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT);
- $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);
- static $print_pdf_display_comment = FALSE;
-
- if (($print_pdf_display_comment == FALSE) && (isset($node->type))) {
- $node_type = $node->type;
- $print_pdf_display_comment = variable_get('print_pdf_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
- $print_pdf_display = variable_get('print_pdf_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
- }
- else {
- $node_type = '';
- $print_pdf_display = 1;
- }
-
- if (!$teaser) {
+ $allowed_type = print_pdf_link_allowed(array('type' => $type, 'node' => $node, 'teaser' => $teaser));
+ if ($allowed_type) {
$links = array();
$format = theme('print_pdf_format_link');
// Show book link
- if (($print_pdf_book_link) && user_access('access printer-friendly version') &&
- (($node_type == 'book') || isset($node->book))) {
-
+ if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$links['book_pdf'] = array('href' => PRINTPDF_PATH .'/book/export/html/'. $node->nid,
'title' => $format['text'],
'attributes' => $format['attributes'],
@@ -118,13 +101,7 @@ function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
return $links;
}
- // No link is shown for several motives...
- elseif (($node_type != 'book') && (!isset($node->book)) &&
- ($print_pdf_show_link) && user_access('access print') &&
- _print_page_match($print_pdf_node_link_visibility, $print_pdf_node_link_pages) &&
- (($type == 'comment' && $print_pdf_display_comment) ||
- ($type == 'node' && $print_pdf_display))) {
-
+ elseif ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
$query_arr = $_GET;
if ($type == 'comment') {
$query_arr['comment'] = $node->cid;
@@ -148,13 +125,7 @@ function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
* Implementation of hook_help().
*/
function print_pdf_help($path, $arg) {
- $print_pdf_show_link = variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT);
- $print_pdf_sys_link_visibility = variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT);
- $print_pdf_sys_link_pages = variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT);
-
- if (($print_pdf_show_link) && user_access('access print') &&
- _print_page_match($print_pdf_sys_link_visibility, $print_pdf_sys_link_pages) &&
- (preg_match('!^node/!i', $path) == 0)) {
+ if (print_pdf_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0)) {
static $output = FALSE;
if ($output === FALSE) {
@@ -172,18 +143,10 @@ function print_pdf_help($path, $arg) {
function print_pdf_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
- $print_pdf_show_link = variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT);
- $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);
- $print_pdf_display = variable_get('print_pdf_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
-
- if ((!$teaser) && (!$node->printing) && ($print_pdf_show_link) &&
- user_access('access print') && ($print_pdf_display) &&
- _print_page_match($print_pdf_node_link_visibility, $print_pdf_node_link_pages)) {
+ $allowed_type = print_pdf_link_allowed(array('node' => $node, 'teaser' => $teaser));
+ if (($allowed_type != FALSE) && (preg_match('!^print!i', $_GET['q']) == 0)) {
drupal_add_css(drupal_get_path('module', 'print') .'/printlinks.css');
- $print_pdf_book_link = variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT);
- if (($print_pdf_book_link) && user_access('access printer-friendly version') &&
- (($node->type == 'book') || isset($node->book))) {
+ if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINTPDF_PATH .'/book/export/html/'. $node->nid;
}
$link = print_pdf_insert_link($path);
@@ -249,7 +212,7 @@ function theme_print_pdf_format_link() {
function print_pdf_insert_link($path = NULL) {
if (user_access('access print')) {
if ($path === NULL) {
- $path = PRINTPDF_PATH .'/'. $_GET['q'];
+ $path = PRINTPDF_PATH .'/'. preg_replace('!^node/!', '', $_GET['q']);
$query = drupal_query_string_encode($_GET, array('q'));
if (empty($query)) {
$query = NULL;
@@ -259,3 +222,74 @@ function print_pdf_insert_link($path = NULL) {
return '<span class="print_pdf">'. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .'</span>';
}
}
+
+/**
+ * Determine a the link to the PDF version is allowed depending on all possible settings
+ *
+ * @param $args
+ * array containing the possible parameters:
+ * teaser, node, type, path
+ * @return
+ * FALSE if not allowed
+ * PRINT_ALLOW_NORMAL_LINK if a normal link is allowed
+ * PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
+ */
+function print_pdf_link_allowed($args) {
+ $print_pdf_show_link = variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT);
+ if ($args['teaser'] || !user_access('access print') || !$print_pdf_show_link) {
+ // If showing only the teaser or the user is not allowed or link is disabled
+ return FALSE;
+ }
+ $node = $args['node'];
+ if (isset($node) && $node) {
+ static $node_type = FALSE;
+ if (($node_type === FALSE) && isset($node->type)) {
+ $node_type = $node->type;
+ }
+ else {
+ $node_type = '';
+ }
+ // Node
+ $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 ($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;
+ }
+ elseif (($args['type'] == 'comment') && isset($node_type)) {
+ // Link is for a comment, return the configured setting
+ return variable_get('print_pdf_display_comment_'. $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ }
+ else {
+ // Node link
+ 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;
+ }
+ elseif (($node_type == 'book') || isset($node->book)) {
+ // Node is a book;
+ $print_pdf_book_link = variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT);
+ if (!$print_pdf_book_link || !user_access('access printer-friendly version')) {
+ // Book link is disabled
+ return FALSE;
+ }
+ else {
+ return PRINT_ALLOW_BOOK_LINK;
+ }
+ }
+ else {
+ return PRINT_ALLOW_NORMAL_LINK;
+ }
+ }
+ }
+ else {
+ // 'System' page
+ $print_pdf_sys_link_visibility = variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT);
+ $print_pdf_sys_link_pages = variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT);
+
+ return _print_page_match($print_pdf_sys_link_visibility, $print_pdf_sys_link_pages);
+ }
+}