Index: janode.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/janode/janode.module,v retrieving revision 1.5 diff -u -p -r1.5 janode.module --- janode.module 30 May 2006 21:11:30 -0000 1.5 +++ janode.module 30 May 2006 22:40:29 -0000 @@ -36,6 +36,9 @@ class _janode_defaults { // should we display links on the main body? (prob YES) var $show_link_on_body = 1; + // should we inwardly redirect (and thus log) + var $inward_redirect = 0; + // place a limit on how many nodes to 404 check on each cron run var $index_how_many_per_cron = 10; var $enable_404_check = 1; @@ -111,12 +114,19 @@ function janode_access($op, $node) { function janode_menu($may_cache) { $items = array(); - if ($may_cache) { + if (1 || $may_cache) { $items[] = array( 'path' => 'node/add/janode', 'title' => t('janode'), 'access' => user_access('create janode') ); + $items[] = array( + 'path' => 'janode', + 'title' => t('Janode redirect'), + 'access' => user_access('access content'), + 'callback' => '_janode_redirect', + 'type' => MENU_CALLBACK + ); } return $items; @@ -147,6 +157,12 @@ function janode_settings() { '#default_value' => _janode_local_settings('show_link_on_body'), '#description' => t('Set this to enable the link display on node main body') ); + $form['janode']['inward_redirect'] = array( + '#type' => 'checkbox', + '#title' => t('Use "inward" redirection to external link'), + '#default_value' => _janode_local_settings('inward_redirect'), + '#description' => t('Set this to enable "inward" redirecting') + ); $form['janode']['index_how_many_per_cron'] = array( '#type' => 'textfield', '#title' => t('How many janodes to 404 test'), @@ -330,6 +346,12 @@ function janode_view(&$node, $teaser = F /* {{{ theme_janode_http_link() */ function theme_janode_http_link($node) { + $display_link = $node->http_link; + + if (_janode_local_settings('inward_redirect')) { + $node->http_link = 'janode/' . $node->nid . '/redirect'; + } + $link_class = _janode_local_settings('html_link_class'); $link_class_array = (strlen($link_class)) ? array('class' => $link_class) : array(); @@ -340,7 +362,7 @@ function theme_janode_http_link($node) { $link_suffix = _janode_local_settings('html_link_wrapperB'); $link_suffix_text = (strlen($link_suffix)) ? (check_markup($link_suffix,FILTER_FORMAT_DEFAULT, FALSE)) : (''); - $link_text = l($node->http_link, $node->http_link, $link_class_array, NULL, NULL, FALSE, FALSE); + $link_text = l($display_link, $node->http_link, $link_class_array, NULL, NULL, FALSE, FALSE); return $link_prefix.$link_text.$link_suffix; } /* }}} */ @@ -495,6 +517,29 @@ function _janode_error_handler($errno, $ } /* }}} */ +/* {{{ _janode_redirect() */ +/** + * _janode_redirect() + * + * redirect to the link and log the transaction in the watchdog if needed + */ +function _janode_redirect() { + + _janode_debug("_janode_redirect()"); + $num_args = func_num_args(); + if (func_num_args() > 0) { + $args = func_get_args(); + // $args[0] must be node id and args[1] must be keyword "redirect" + if (ctype_digit($args[0]) && 'redirect' == $args[1]) { + $node = node_load($args[0]); + watchdog('janode', 'Redirect to external link "' . $node->http_link . '"', WATCHDOG_NOTICE); + ob_clean(); + header("Location: ". $node->http_link); + } + } +} +/* }}} */ + /* {{{ _janode_local_settings() */ /** * _janode_local_settings($name = FALSE)