Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/janode/README.txt,v
retrieving revision 1.2
diff -u -p -r1.2 README.txt
--- README.txt 24 May 2006 14:07:27 -0000 1.2
+++ README.txt 26 May 2006 08:38:40 -0000
@@ -27,7 +27,10 @@ site admin should decide what to do with
Note, in order for cron to check a link, your server must be
able to make HTTP (TCP Port 80) outgoing requests. Firewalls
may block this thus sending all ur links back into the
-moderation queue.
+moderation queue. If this is the case and you are unable to
+chamge any external firewall rule sets but wish to continue
+using Janodes then you can disable the automatic link check
+facility as show below.
Settings
========
@@ -42,6 +45,10 @@ How many janodes to 404 test
Does what it says on the tin. Don't set this too high.
The module batch tests the links.
+Enable link checking by cron
+ You can disable the link checking feature by unchecking
+ this checkbox and saving.
+
The class name applied to the link's HREF
If you want a specific style class applying to the
link enter the class name here. A blank input here
Index: janode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/janode/janode.module,v
retrieving revision 1.2
diff -u -p -r1.2 janode.module
--- janode.module 24 May 2006 00:12:55 -0000 1.2
+++ janode.module 26 May 2006 08:38:41 -0000
@@ -20,7 +20,11 @@
*/
if(!defined("JANODE_DEBUG")) {
- define("JANODE_DEBUG", 0); // 0 - disabled, 1 - enabled
+ define("_JANODE_DEBUG", 0); // 0 - disabled, 1 - enabled
+ define("_JANODE_NOT_HTTP", 251);
+ define("_JANODE_NO_MATA_DATA", 252);
+ define("_JANODE_FILE_OPEN_FAILURE", 353);
+ define("_JANODE_FAILURE_PIVOT", 299);
}
/* {{{ defaults place holder */
@@ -34,9 +38,10 @@ class _janode_defaults {
// 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;
// the follow control theme appearence
- var $html_link_class = 'class="janode_link"';
+ var $html_link_class = 'janode_link';
var $html_link_wrapperA = '
';
var $html_link_wrapperB = '
';
}
@@ -147,6 +152,12 @@ function janode_settings() {
'#description' => t('The maximum janodes to 404 test on each cron run. '.
"Don't set this too high or the cron may stall.")
);
+ $form['janode']['enable_404_check'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable link checking by cron'),
+ '#default_value' => _janode_local_settings('enable_404_check'),
+ '#description' => t('Uncheck to disable link checking by cron')
+ );
$form['janode']['markup1'] = array(
'#type' => 'markup',
'#value' => t('The following allow the admin to "wrap" the link up in custom html')
@@ -316,10 +327,10 @@ function theme_janode_http_link($node) {
array('class' => $link_class) : array();
$link_prefix = _janode_local_settings('html_link_wrapperA');
- $link_prefix_text = (strlen($link_prefix)) ? ($link_prefix) : ('');
+ $link_prefix_text = (strlen($link_prefix)) ? (check_markup($link_prefix,FILTER_FORMAT_DEFAULT, FALSE)) : ('');
$link_suffix = _janode_local_settings('html_link_wrapperB');
- $link_suffix_text = (strlen($link_suffix)) ? ($link_suffix) : ('');
+ $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);
return $link_prefix.$link_text.$link_suffix;
@@ -332,6 +343,10 @@ function theme_janode_http_link($node) {
*/
function janode_cron() {
+ if (!(int)_janode_local_settings('enable_404_check')) {
+ return;
+ }
+
$max_to_do = (int)_janode_local_settings('index_how_many_per_cron');
$limit_sql = ($max_to_do > 0) ? ("LIMIT $max_to_do") : ("");
$r = db_query("SELECT * FROM {janode} ORDER BY last_checked ASC $limit_sql");
@@ -356,6 +371,16 @@ function janode_cron() {
* void, act's directly on the db table
*/
function _janode_check_404($janode) {
+ static $message_once = TRUE;
+
+ // check php var "allow_url_fopen" is true as we need it to fetch the URL
+ if (!ini_get('allow_url_fopen')) {
+ if ($message_once) {
+ watchdog('cron', 'PHP INI "allow_url_fopen" is false', WATCHDOG_NOTICE);
+ $message_once = FALSE;
+ return;
+ }
+ }
// There are a number of HTTP status return codes. However, below 300
// usually means all went ok. We use 250 series for our own internal
@@ -365,26 +390,30 @@ function _janode_check_404($janode) {
$status = 0; // provide a default value to ensure var exists
+ // use my error handler for this part
+ set_error_handler("_janode_error_handler");
+
// create a full URL
$url_parts = parse_url($janode->http_link);
if (isset($url_parts['port']) && strlen($url_parts['port']) > 0) {
$url_parts['host'] .= ':' . $url_parts['port'];
}
- $full_url = $url_parts['scheme'] . "://" . $url_parts['host'] . "/" . urlencode($url_parts['path']);
+ $url_parts['path'] = (isset($url_parts['path'])) ? $url_parts['path'] : ('');
+ $full_url = $url_parts['scheme'] . "://" . $url_parts['host'] . $url_parts['path'];
if (isset($url_parts['query']) && strlen($url_parts['query']) > 0) {
$full_url .= "?" . urlencode($url_parts['query']);
}
// currently only support http
if ($url_parts['scheme'] != 'http') {
- $status = 251;
+ $status = _JANODE_NOT_HTTP;
}
else {
if(!function_exists('stream_get_meta_data')) { // needed next
- $status = 252;
+ $status = _JANODE_NO_MATA_DATA;
}
elseif(!($fp = @fopen($full_url, 'r'))) {
- $status = 353;
+ $status = _JANODE_FILE_OPEN_FAILURE;
unset($_SESSION['messages']['error']); // rough but gets rid of hostname errors, @fopen didn't work
}
else {
@@ -401,12 +430,15 @@ function _janode_check_404($janode) {
}
}
+ // restore system error handler
+ restore_error_handler();
+
// tell the db what we have discovered...
$sql = "UPDATE {janode} SET last_checked = NOW(), status = '%s' WHERE nid = %d AND vid = %d";
db_query($sql, (string)$status, $janode->nid, $janode->vid);
- // force the node into the moderation queue
- if ((int)$status > 299) {
+ // unpublish and force the node into the moderation queue
+ if ((int)$status > _JANODE_FAILURE_PIVOT) {
db_query("UPDATE {node} SET status = 0, moderate = 1 WHERE nid = %d", $janode->nid);
}
}
@@ -432,6 +464,29 @@ function _janode_is_http_link($s, $check
}
/* }}} */
+/* {{{ _janode_error_handler() */
+/**
+ * PHP callback error handler function
+ *
+ * have found that the @ error suppressor in drupal doesn't
+ * work as expected. The last thing I want is any msgs during
+ * the file open operations ending up on the browser. So this
+ * handler exists to ensure these are suppressed.
+ */
+function _janode_error_handler($errno, $errstr, $errfile = NULL, $errline = NULL, $errcont = NULL) {
+
+ // was @ in operation?
+ if (error_reporting() == 0) {
+ return NULL; // yes, be silent
+ }
+
+ $errfile = ($errfile) ? ("in file '$errfile'") : ("");
+ $errline = ($errline) ? ("at line $errline") : ("");
+
+ watchdog('php', "Error number $errno : '$errstr' $errfile $errline", WATCHDOG_ERROR);
+}
+/* }}} */
+
/* {{{ _janode_local_settings() */
/**
* _janode_local_settings($name = FALSE)
@@ -474,7 +529,7 @@ function _janode_local_settings($name =
/* {{{ _janode_debug() */
function _janode_debug($s) {
- if (defined("JANODE_DEBUG") && JANODE_DEBUG) {
+ if (defined("_JANODE_DEBUG") && _JANODE_DEBUG) {
error_log($s);
}
}