Broken Link Checker - Version 0.5.3

Version Description

Download this release

Release Info

Developer whiteshadow
Plugin Icon 128x128 Broken Link Checker
Version 0.5.3
Comparing to
See all releases

Code changes from version 0.5.2 to 0.5.3

Files changed (3) hide show
  1. broken-link-checker.php +45 -48
  2. link-classes.php +15 -7
  3. readme.txt +2 -2
broken-link-checker.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Broken Link Checker
4
  Plugin URI: http://w-shadow.com/blog/2007/08/05/broken-link-checker-for-wordpress/
5
  Description: Checks your posts for broken links and missing images and notifies you on the dashboard if any are found.
6
- Version: 0.5.2
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
@@ -57,14 +57,14 @@ if (!class_exists('ws_broken_link_checker')) {
57
  class ws_broken_link_checker {
58
  var $options;
59
  var $options_name='wsblc_options';
60
- var $myfile='';
61
- var $myfolder='';
62
- var $mybasename='';
63
- var $siteurl;
64
  var $defaults;
65
 
66
- var $execution_start_time;
67
- var $lockfile_handle = null;
68
 
69
  function ws_broken_link_checker() {
70
  global $wpdb;
@@ -78,14 +78,14 @@ class ws_broken_link_checker {
78
  'exclusion_list' => array(), //Links that contain a substring listed in this array won't be checked.
79
  'recheck_count' => 3, //[Internal] How many times a broken link should be re-checked (slightly buggy)
80
 
81
- //These are currently ignored. Everything is checked by default.
82
  'check_posts' => true,
83
  'check_custom_fields' => true,
84
  'check_blogroll' => true,
85
 
86
  'custom_fields' => array(), //List of custom fields that can contain URLs and should be checked.
87
 
88
- 'autoexpand_widget' => true,
89
 
90
  'need_resynch' => false, //[Internal flag]
91
 
@@ -149,13 +149,16 @@ class ws_broken_link_checker {
149
  {
150
  'action' : 'blc_work'
151
  },
152
- function (data, textStatus){}
 
 
153
  );
154
  }
155
  //Call it the first time
156
  blcDoWork();
157
- //...and every max_execution_time seconds
158
- setInterval(blcDoWork, <?php echo ($this->options['max_execution_time'] + 1 )*1000; ?>);
 
159
 
160
  })(jQuery);
161
  </script>
@@ -233,7 +236,7 @@ class ws_broken_link_checker {
233
  'action' : 'blc_dashboard_status'
234
  },
235
  function (data, textStatus){
236
- if ( typeof(data['text']) != 'undefined'){
237
  $('#wsblc_activity_box').html(data.text);
238
  <?php if ( $this->options['autoexpand_widget'] ) { ?>
239
  //Expand the widget if there are broken links.
@@ -251,6 +254,7 @@ class ws_broken_link_checker {
251
  }
252
  );
253
  }
 
254
  blcDashboardStatus();//Call it the first time
255
 
256
  });
@@ -562,7 +566,7 @@ class ws_broken_link_checker {
562
  ?>
563
  <div class="wrap"><h2>Broken Link Checker Options</h2>
564
 
565
- <form name="link_checker_options" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=link-checker-settings&amp;updated=true">
566
 
567
  <table class="form-table">
568
 
@@ -584,7 +588,7 @@ class ws_broken_link_checker {
584
  'action' : 'blc_full_status'
585
  },
586
  function (data, textStatus){
587
- if ( typeof(data['text']) != 'undefined'){
588
  $('#wsblc_full_status').html(data.text);
589
  } else {
590
  $('#wsblc_full_status').html('[ Network error ]');
@@ -599,7 +603,7 @@ class ws_broken_link_checker {
599
  })(jQuery);
600
  </script>
601
  <?php //JHS: Recheck all posts link: ?>
602
- <p><input class="button" type="button" name="recheckbutton" value="Re-check all pages" onclick="location.replace('<?php echo $_SERVER['PHP_SELF']; ?>?page=link-checker-settings&amp;recheck=true')" /></p>
603
  </td>
604
  </tr>
605
 
@@ -1094,7 +1098,7 @@ jQuery(function($){
1094
  function (data, textStatus){
1095
  var display_url = '';
1096
 
1097
- if ( typeof(data['error']) != 'undefined'){
1098
  //data.error is an error message
1099
  alert(data.error);
1100
  display_url = orig_url;
@@ -1179,7 +1183,7 @@ jQuery(function($){
1179
  function (data, textStatus){
1180
  eval('data = ' + data);
1181
 
1182
- if ( typeof(data['ok']) != 'undefined'){
1183
  //Hide the details
1184
  master.next('.blc-link-details').hide();
1185
  //Flash the main row green to indicate success, then hide it.
@@ -1216,7 +1220,7 @@ jQuery(function($){
1216
  function (data, textStatus){
1217
  eval('data = ' + data);
1218
 
1219
- if ( typeof(data['ok']) != 'undefined'){
1220
 
1221
  if ( 'broken' == blc_current_filter ){
1222
  //Flash the row green to indicate success, then hide it.
@@ -1243,32 +1247,6 @@ jQuery(function($){
1243
 
1244
  });
1245
 
1246
- function removeLinkFromPost(link_id){
1247
- if (!confirm('Do you really want to remove this link from all posts, custom fields and the blogroll?')) return;
1248
-
1249
- $('unlink_button-'+link_id).innerHTML = 'Wait...';
1250
-
1251
- new Ajax.Request(
1252
- '<?php
1253
- echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
1254
- ?>action=remove_link&id='+link_id,
1255
- {
1256
- method:'get',
1257
- onSuccess: function(transport){
1258
- var re = /OK:.*/i
1259
- var response = transport.responseText || "";
1260
- if (re.test(response)){
1261
- $('link-'+link_id).hide();
1262
- $('link-details-'+link_id).hide();
1263
- alterLinkCounter(-1);
1264
- } else {
1265
- $('unlink_button-'+link_id).innerHTML = 'Unlink';
1266
- alert(response);
1267
- }
1268
- }
1269
- }
1270
- );
1271
- }
1272
  </script>
1273
  <?php
1274
  }
@@ -1398,10 +1376,10 @@ jQuery(function($){
1398
 
1399
  function load_options(){
1400
  $this->options = get_option($this->options_name);
1401
- if(!is_array($this->options)){
1402
  $this->options = $this->defaults;
1403
  } else {
1404
- $this->options = array_merge($this->defaults, $this->options);
1405
  }
1406
  }
1407
 
@@ -1763,6 +1741,13 @@ jQuery(function($){
1763
  die();
1764
  }
1765
 
 
 
 
 
 
 
 
1766
  function status_text( $status ){
1767
  $text = '';
1768
 
@@ -1825,6 +1810,18 @@ jQuery(function($){
1825
  */
1826
  }
1827
 
 
 
 
 
 
 
 
 
 
 
 
 
1828
  function get_status(){
1829
  global $wpdb;
1830
 
@@ -1996,7 +1993,7 @@ jQuery(function($){
1996
  die('Error : link ID not specified');
1997
  }
1998
 
1999
- //Load the link. link_details_rwo needs it as an array, so
2000
  //we'll have to do this the long way.
2001
  $q = "SELECT
2002
  links.*,
3
  Plugin Name: Broken Link Checker
4
  Plugin URI: http://w-shadow.com/blog/2007/08/05/broken-link-checker-for-wordpress/
5
  Description: Checks your posts for broken links and missing images and notifies you on the dashboard if any are found.
6
+ Version: 0.5.3
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
57
  class ws_broken_link_checker {
58
  var $options;
59
  var $options_name='wsblc_options';
60
+ var $myfile=''; //should be removed
61
+ var $myfolder=''; //should be removed
62
+ var $mybasename=''; //should be removed
63
+ var $siteurl; //should be removed
64
  var $defaults;
65
 
66
+ var $execution_start_time; //Used for a simple internal execution timer in start_timer()/execution_time()
67
+ var $lockfile_handle = null;
68
 
69
  function ws_broken_link_checker() {
70
  global $wpdb;
78
  'exclusion_list' => array(), //Links that contain a substring listed in this array won't be checked.
79
  'recheck_count' => 3, //[Internal] How many times a broken link should be re-checked (slightly buggy)
80
 
81
+ //These three are currently ignored. Everything is checked by default.
82
  'check_posts' => true,
83
  'check_custom_fields' => true,
84
  'check_blogroll' => true,
85
 
86
  'custom_fields' => array(), //List of custom fields that can contain URLs and should be checked.
87
 
88
+ 'autoexpand_widget' => true, //Autoexpand the Dashboard widget if broken links are detected
89
 
90
  'need_resynch' => false, //[Internal flag]
91
 
149
  {
150
  'action' : 'blc_work'
151
  },
152
+ function (data, textStatus){
153
+
154
+ }
155
  );
156
  }
157
  //Call it the first time
158
  blcDoWork();
159
+
160
+ //Then call it periodically every X seconds
161
+ setInterval(blcDoWork, <?php echo (intval($this->options['max_execution_time']) + 1 )*1000; ?>);
162
 
163
  })(jQuery);
164
  </script>
236
  'action' : 'blc_dashboard_status'
237
  },
238
  function (data, textStatus){
239
+ if ( data && ( typeof(data.text) != 'undefined' ) ) {
240
  $('#wsblc_activity_box').html(data.text);
241
  <?php if ( $this->options['autoexpand_widget'] ) { ?>
242
  //Expand the widget if there are broken links.
254
  }
255
  );
256
  }
257
+
258
  blcDashboardStatus();//Call it the first time
259
 
260
  });
566
  ?>
567
  <div class="wrap"><h2>Broken Link Checker Options</h2>
568
 
569
+ <form name="link_checker_options" method="post" action="<?php echo basename($_SERVER['PHP_SELF']); ?>?page=link-checker-settings&amp;updated=true">
570
 
571
  <table class="form-table">
572
 
588
  'action' : 'blc_full_status'
589
  },
590
  function (data, textStatus){
591
+ if ( data && ( typeof(data['text']) != 'undefined' ) ){
592
  $('#wsblc_full_status').html(data.text);
593
  } else {
594
  $('#wsblc_full_status').html('[ Network error ]');
603
  })(jQuery);
604
  </script>
605
  <?php //JHS: Recheck all posts link: ?>
606
+ <p><input class="button" type="button" name="recheckbutton" value="Re-check all pages" onclick="location.replace('<?php echo basename($_SERVER['PHP_SELF']); ?>?page=link-checker-settings&amp;recheck=true')" /></p>
607
  </td>
608
  </tr>
609
 
1098
  function (data, textStatus){
1099
  var display_url = '';
1100
 
1101
+ if ( data && (typeof(data['error']) != 'undefined') ){
1102
  //data.error is an error message
1103
  alert(data.error);
1104
  display_url = orig_url;
1183
  function (data, textStatus){
1184
  eval('data = ' + data);
1185
 
1186
+ if ( data && ( typeof(data['ok']) != 'undefined') ){
1187
  //Hide the details
1188
  master.next('.blc-link-details').hide();
1189
  //Flash the main row green to indicate success, then hide it.
1220
  function (data, textStatus){
1221
  eval('data = ' + data);
1222
 
1223
+ if ( data && ( typeof(data['ok']) != 'undefined' ) ){
1224
 
1225
  if ( 'broken' == blc_current_filter ){
1226
  //Flash the row green to indicate success, then hide it.
1247
 
1248
  });
1249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1250
  </script>
1251
  <?php
1252
  }
1376
 
1377
  function load_options(){
1378
  $this->options = get_option($this->options_name);
1379
+ if( !is_array( $this->options ) ){
1380
  $this->options = $this->defaults;
1381
  } else {
1382
+ $this->options = array_merge( $this->defaults, $this->options );
1383
  }
1384
  }
1385
 
1741
  die();
1742
  }
1743
 
1744
+ /**
1745
+ * ws_broken_link_checker::status_text()
1746
+ * Generates a status message based on the status info in $status
1747
+ *
1748
+ * @param array $status
1749
+ * @return string
1750
+ */
1751
  function status_text( $status ){
1752
  $text = '';
1753
 
1810
  */
1811
  }
1812
 
1813
+ /**
1814
+ * ws_broken_link_checker::get_status()
1815
+ * Returns an array with various status information about the plugin. Array key reference:
1816
+ * check_threshold - date/time; links checked before this threshold should be checked again.
1817
+ * recheck_threshold - date/time; broken links checked before this threshold should be re-checked.
1818
+ * known_links - the number of detected unique URLs (a misleading name, yes).
1819
+ * known_instances - the number of detected link instances, i.e. actual link elements in posts and other places.
1820
+ * broken_links - the number of detected broken links.
1821
+ * unchecked_links - the number of URLs that need to be checked ASAP; based on check_threshold and recheck_threshold.
1822
+ *
1823
+ * @return array
1824
+ */
1825
  function get_status(){
1826
  global $wpdb;
1827
 
1993
  die('Error : link ID not specified');
1994
  }
1995
 
1996
+ //Load the link. link_details_row needs it as an array, so
1997
  //we'll have to do this the long way.
1998
  $q = "SELECT
1999
  links.*,
link-classes.php CHANGED
@@ -143,7 +143,7 @@ class blcLink {
143
  }
144
 
145
  //******* Use CURL if available ***********
146
- if (function_exists('curl_init')) {
147
  $ch = curl_init();
148
  curl_setopt($ch, CURLOPT_URL, $url);
149
  //Masquerade as Internet explorer
@@ -211,7 +211,7 @@ class blcLink {
211
 
212
  curl_close($ch);
213
 
214
- } elseif (class_exists('Snoopy')) {
215
  //******** Use Snoopy if CURL is not available *********
216
  //Note : Snoopy doesn't work too well with HTTPS URLs.
217
  $this->log .= "<em>(Using Snoopy)</em>\n";
@@ -220,11 +220,16 @@ class blcLink {
220
 
221
  $snoopy = new Snoopy;
222
  $snoopy->read_timeout = 60; //read timeout in seconds
 
223
  $snoopy->fetch($url);
224
 
225
- $this->request_duration = $start_time - microtime_float(true);
226
 
227
- $this->http_code = $snoopy->status; //HTTP status code
 
 
 
 
228
 
229
  if ($snoopy->error)
230
  $this->log .= $snoopy->error."\n";
@@ -234,10 +239,13 @@ class blcLink {
234
  if ( is_array($snoopy->headers) )
235
  $this->log .= implode("", $snoopy->headers)."\n"; //those headers already contain newlines
236
 
237
- if ($snoopy->lastredirectaddr) {
 
238
  $this->final_url = $snoopy->lastredirectaddr;
239
  $this->redirect_count = $snoopy->_redirectdepth;
240
- }
 
 
241
  }
242
 
243
  /*"Good" response codes are anything in the 2XX range (e.g "200 OK") and redirects - the 3XX range.
@@ -251,7 +259,7 @@ class blcLink {
251
  return true;
252
  } else {
253
  $this->log .= "Link is broken.";
254
- if ($this->http_code == 0){
255
  //This is probably a timeout
256
  $this->timeout = true;
257
  $this->log .= "\r\n(Most likely the connection timed out)";
143
  }
144
 
145
  //******* Use CURL if available ***********
146
+ if ( function_exists('curl_init') ) {
147
  $ch = curl_init();
148
  curl_setopt($ch, CURLOPT_URL, $url);
149
  //Masquerade as Internet explorer
211
 
212
  curl_close($ch);
213
 
214
+ } elseif ( class_exists('Snoopy') ) {
215
  //******** Use Snoopy if CURL is not available *********
216
  //Note : Snoopy doesn't work too well with HTTPS URLs.
217
  $this->log .= "<em>(Using Snoopy)</em>\n";
220
 
221
  $snoopy = new Snoopy;
222
  $snoopy->read_timeout = 60; //read timeout in seconds
223
+ $snoopy->maxlength = 1024*5; //load up to 5 kilobytes
224
  $snoopy->fetch($url);
225
 
226
+ $this->request_duration = microtime_float(true) - $start_time;
227
 
228
+ $this->http_code = $snoopy->status; //HTTP status code (note : Snoopy returns -100 on timeout)
229
+ if ( $this->http_code == -100 ){
230
+ $this->http_code = 0;
231
+ $this->timeout = true;
232
+ }
233
 
234
  if ($snoopy->error)
235
  $this->log .= $snoopy->error."\n";
239
  if ( is_array($snoopy->headers) )
240
  $this->log .= implode("", $snoopy->headers)."\n"; //those headers already contain newlines
241
 
242
+ //Redirected?
243
+ if ( $snoopy->lastredirectaddr ) {
244
  $this->final_url = $snoopy->lastredirectaddr;
245
  $this->redirect_count = $snoopy->_redirectdepth;
246
+ } else {
247
+ $this->final_url = $this->url;
248
+ }
249
  }
250
 
251
  /*"Good" response codes are anything in the 2XX range (e.g "200 OK") and redirects - the 3XX range.
259
  return true;
260
  } else {
261
  $this->log .= "Link is broken.";
262
+ if ( $this->http_code == 0 ){
263
  //This is probably a timeout
264
  $this->timeout = true;
265
  $this->log .= "\r\n(Most likely the connection timed out)";
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: whiteshadow
3
  Tags: links, broken, maintenance, blogroll, custom fields, admin
4
  Requires at least: 2.7.0
5
- Tested up to: 2.8
6
- Stable tag: 0.5.2
7
 
8
  This plugin will check your posts, custom fields and the blogroll for broken links and missing images and notify you on the dashboard if any are found.
9
 
2
  Contributors: whiteshadow
3
  Tags: links, broken, maintenance, blogroll, custom fields, admin
4
  Requires at least: 2.7.0
5
+ Tested up to: 2.9
6
+ Stable tag: 0.5.3
7
 
8
  This plugin will check your posts, custom fields and the blogroll for broken links and missing images and notify you on the dashboard if any are found.
9