Commit dcd3fc93 authored by jcnventura's avatar jcnventura

Improve link enabled detection routines

parent c92040a3
......@@ -38,6 +38,9 @@ define('PRINT_ROBOTS_NOARCHIVE_DEFAULT', 0);
define('PRINT_TYPE_SHOW_LINK_DEFAULT', 1);
define('PRINT_TYPE_COMMENT_LINK_DEFAULT', 0);
define('PRINT_ALLOW_NORMAL_LINK', 1);
define('PRINT_ALLOW_BOOK_LINK', 2);
/**
* Implementation of hook_perm().
*/
......@@ -82,7 +85,7 @@ function print_menu() {
);
$items['admin/settings/print/html'] = array(
'title' => 'Web page',
'weight' => 0,
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/print/common'] = array(
......@@ -102,27 +105,8 @@ function print_menu() {
* Implementation of hook_link().
*/
function print_link($type, $node = NULL, $teaser = FALSE) {
$print_html_show_link = variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT);
$print_html_node_link_visibility = variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT);
$print_html_node_link_pages = variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT);
static $print_display_comment = FALSE;
if (($print_display_comment == FALSE) && (isset($node->type))) {
$node_type = $node->type;
$print_display_comment = variable_get('print_display_comment_'. $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$print_display = variable_get('print_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
}
else {
$node_type = '';
$print_display = 1;
}
// No link is shown for several motives...
if ( !($teaser) && ($node_type != 'book') && (!isset($node->book)) &&
($print_html_show_link) && user_access('access print') &&
_print_page_match($print_html_node_link_visibility, $print_html_node_link_pages) &&
(($type == 'comment' && $print_display_comment) ||
($type == 'node' && $print_display))) {
$allowed_type = print_link_allowed(array('type' => $type, 'node' => $node, 'teaser' => $teaser));
if ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
$links = array();
$format = theme('print_format_link');
......@@ -177,13 +161,7 @@ function print_help($path, $arg) {
return filter_filter('process', 1, NULL, file_get_contents(drupal_get_path('module', 'print') .'/README.txt') );
}
$print_html_show_link = variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT);
$print_html_sys_link_visibility = variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT);
$print_html_sys_link_pages = variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT);
if (($print_html_show_link) && user_access('access print') &&
_print_page_match($print_html_sys_link_visibility, $print_html_sys_link_pages) &&
(preg_match('!^node/!i', $path) == 0)) {
if (print_link_allowed(array('path' => $path)) && (preg_match('!^node/!i', $path) == 0)) {
static $output = FALSE;
if ($output === FALSE) {
......@@ -201,18 +179,10 @@ function print_help($path, $arg) {
function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
switch ($op) {
case 'view':
$print_html_show_link = variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT);
$print_html_node_link_visibility = variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT)
$print_html_node_link_pages = variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT);
$print_display = variable_get('print_display_'. $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
if ((!$teaser) && (!$node->printing) && ($print_html_show_link) &&
user_access('access print') && ($print_display) &&
_print_page_match($print_html_node_link_visibility, $print_html_node_link_pages)) {
$allowed_type = print_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_html_book_link = variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT);
if (($print_html_book_link) && user_access('access printer-friendly version') &&
(($node->type == 'book') || isset($node->book))) {
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
$path = PRINT_PATH .'/book/export/html/'. $node->nid;
}
$link = print_insert_link($path);
......@@ -419,3 +389,74 @@ function _print_page_match($visibility, $pages) {
return TRUE;
}
}
/**
* Determine a the link to the PF 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_link_allowed($args) {
$print_html_show_link = variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT);
if ($args['teaser'] || !user_access('access print') || !$print_html_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_html_node_link_visibility = variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT);
$print_html_node_link_pages = variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT);
if ($node->printing ||
!_print_page_match($print_html_node_link_visibility, $print_html_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_display_comment_'. $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
}
else {
// Node link
if (isset($node_type) &&
!variable_get('print_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_html_book_link = variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT);
if (!$print_html_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_html_sys_link_visibility = variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT);
$print_html_sys_link_pages = variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT);
return _print_page_match($print_html_sys_link_visibility, $print_html_sys_link_pages);
}
}
......@@ -56,7 +56,7 @@ function print_mail_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('print_mail_settings'),
'access arguments' => array('administer print'),
'weight' => 3,
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'file' => 'print_mail.admin.inc',
);
......@@ -154,7 +154,7 @@ 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_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);
......
......@@ -53,7 +53,7 @@ function print_pdf_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('print_pdf_settings'),
'access arguments' => array('administer print'),
'weight' => 2,
'weight' => 3,
'type' => MENU_LOCAL_TASK,
'file' => 'print_pdf.admin.inc',
);
......
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