Broken Link Checker - Version 0.3.2

Version Description

Download this release

Release Info

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

Code changes from version 0.3.1 to 0.3.2

Files changed (3) hide show
  1. broken-link-checker.php +40 -10
  2. readme.txt +1 -1
  3. wsblc_ajax.php +21 -9
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.3.1
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
@@ -20,7 +20,7 @@ class ws_broken_link_checker {
20
  var $options_name='wsblc_options';
21
  var $postdata_name;
22
  var $linkdata_name;
23
- var $version='0.3.1';
24
  var $myfile='';
25
  var $myfolder='';
26
  var $mybasename='';
@@ -76,7 +76,7 @@ class ws_broken_link_checker {
76
  }
77
 
78
  function header_css(){
79
- echo '<style>',$this->options['broken_link_css'],'</style>';
80
  }
81
 
82
  function the_content($content){
@@ -187,6 +187,7 @@ class ws_broken_link_checker {
187
  }
188
 
189
  function is_excluded($url){
 
190
  foreach($this->options['exclusion_list'] as $excluded_word){
191
  if (stristr($url, $excluded_word)){
192
  return true;
@@ -511,10 +512,10 @@ class ws_broken_link_checker {
511
  <td><a href='".($link->guid)."' class='edit'>View</a></td>
512
 
513
  <td><a href='post.php?action=edit&amp;post=$link->post_id' class='edit'>Edit Post</a></td>
514
- <td><a href='javascript:void(0);' class='delete'
515
  onclick='discardLinkMessage($link->id);return false;' );' title='Discard This Message'>Discard</a></td>
516
 
517
- <td><a href='javascript:void(0);' class='delete'
518
  onclick='removeLinkFromPost($link->id);return false;' );' title='Remove the link from the post'>Unlink</a></td>
519
  </tr>";
520
 
@@ -526,18 +527,47 @@ class ws_broken_link_checker {
526
 
527
  <script type='text/javascript'>
528
  function discardLinkMessage(link_id){
 
529
  new Ajax.Request('<?php
530
  echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
531
  ?>action=discard_link&id='+link_id,
532
- { method:'get' });
533
- $('link-'+link_id).hide();
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  }
535
  function removeLinkFromPost(link_id){
536
- new Ajax.Request('<?php
 
 
 
537
  echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
538
  ?>action=remove_link&id='+link_id,
539
- { method:'get' });
540
- $('link-'+link_id).hide();
 
 
 
 
 
 
 
 
 
 
 
 
541
  }
542
  </script>
543
  </div>
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.3.2
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
20
  var $options_name='wsblc_options';
21
  var $postdata_name;
22
  var $linkdata_name;
23
+ var $version='0.3.2';
24
  var $myfile='';
25
  var $myfolder='';
26
  var $mybasename='';
76
  }
77
 
78
  function header_css(){
79
+ echo '<style type="text/css">',$this->options['broken_link_css'],'</style>';
80
  }
81
 
82
  function the_content($content){
187
  }
188
 
189
  function is_excluded($url){
190
+ if (!is_array($this->options['exclusion_list'])) return false;
191
  foreach($this->options['exclusion_list'] as $excluded_word){
192
  if (stristr($url, $excluded_word)){
193
  return true;
512
  <td><a href='".($link->guid)."' class='edit'>View</a></td>
513
 
514
  <td><a href='post.php?action=edit&amp;post=$link->post_id' class='edit'>Edit Post</a></td>
515
+ <td><a href='javascript:void(0);' class='delete' id='discard_button-$link->id'
516
  onclick='discardLinkMessage($link->id);return false;' );' title='Discard This Message'>Discard</a></td>
517
 
518
+ <td><a href='javascript:void(0);' class='delete' id='unlink_button-$link->id'
519
  onclick='removeLinkFromPost($link->id);return false;' );' title='Remove the link from the post'>Unlink</a></td>
520
  </tr>";
521
 
527
 
528
  <script type='text/javascript'>
529
  function discardLinkMessage(link_id){
530
+ $('discard_button-'+link_id).innerHTML = 'Wait...';
531
  new Ajax.Request('<?php
532
  echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
533
  ?>action=discard_link&id='+link_id,
534
+ {
535
+ method:'get',
536
+ onSuccess: function(transport){
537
+ var re = /OK:.*/i
538
+ var response = transport.responseText || "";
539
+ if (re.test(response)){
540
+ $('link-'+link_id).hide();
541
+ } else {
542
+ $('discard_button-'+link_id).innerHTML = 'Discard';
543
+ alert(response);
544
+ }
545
+ }
546
+ }
547
+ );
548
+
549
  }
550
  function removeLinkFromPost(link_id){
551
+ $('unlink_button-'+link_id).innerHTML = 'Wait...';
552
+
553
+ new Ajax.Request(
554
+ '<?php
555
  echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
556
  ?>action=remove_link&id='+link_id,
557
+ {
558
+ method:'get',
559
+ onSuccess: function(transport){
560
+ var re = /OK:.*/i
561
+ var response = transport.responseText || "";
562
+ if (re.test(response)){
563
+ $('link-'+link_id).hide();
564
+ } else {
565
+ $('unlink_button-'+link_id).innerHTML = 'Unlink';
566
+ alert(response);
567
+ }
568
+ }
569
+ }
570
+ );
571
  }
572
  </script>
573
  </div>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: whiteshadow
3
  Tags: links, broken, maintenance
4
  Requires at least: 2.0.2
5
  Tested up to: 2.3.3
6
- Stable tag: 0.3.1
7
 
8
  This plugin will check your posts for broken links and missing images in background and notify you on the dashboard if any are found.
9
 
3
  Tags: links, broken, maintenance
4
  Requires at least: 2.0.2
5
  Tested up to: 2.3.3
6
+ Stable tag: 0.3.2
7
 
8
  This plugin will check your posts for broken links and missing images in background and notify you on the dashboard if any are found.
9
 
wsblc_ajax.php CHANGED
@@ -92,7 +92,7 @@
92
  echo "<!-- run_check -->";
93
 
94
  $sql="SELECT b.* FROM $postdata_name a, $wpdb->posts b
95
- WHERE a.last_check<'$check_treshold' AND a.post_id=b.id ORDER BY a.last_check ASC LIMIT 20";
96
 
97
  $rows=$wpdb->get_results($sql, OBJECT);
98
  if($rows && (count($rows)>0)){
@@ -143,6 +143,10 @@
143
  }
144
  $id=intval($_GET['id']);
145
  $wpdb->query("DELETE FROM $linkdata_name WHERE id=$id LIMIT 1");
 
 
 
 
146
 
147
  } else if ($action=='remove_link'){
148
 
@@ -155,18 +159,25 @@
155
  $sql="SELECT * FROM $linkdata_name WHERE id = $id LIMIT 1";
156
  $the_link=$wpdb->get_row($sql, OBJECT, 0);
157
  if (!$the_link){
158
- die('<!-- link not found -->');
159
  }
160
  $the_post = get_post($the_link->post_id, ARRAY_A);
161
  if (!$the_post){
162
- die('<!-- post not found -->');
163
  }
164
 
165
  $new_content = unlink_the_link($the_post['post_content'], $the_link->url);
166
  $new_content = $wpdb->escape($new_content);
167
  $wpdb->query("UPDATE $wpdb->posts SET post_content = '$new_content' WHERE id = $the_link->post_id");
 
 
 
168
  $wpdb->query("DELETE FROM $linkdata_name WHERE id=$id LIMIT 1");
169
- die('<!-- link deleted -->');
 
 
 
 
170
  };
171
 
172
  function parse_link($matches, $post_id){
@@ -240,8 +251,8 @@
240
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
241
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
242
 
243
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
244
- curl_setopt($ch, CURLOPT_TIMEOUT, 25);
245
 
246
  curl_setopt($ch, CURLOPT_FAILONERROR, false);
247
 
@@ -251,7 +262,8 @@
251
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
252
  } else {
253
  $nobody=true;
254
- curl_setopt($ch, CURLOPT_NOBODY, true);
 
255
  }
256
  curl_setopt($ch, CURLOPT_HEADER, true);
257
 
@@ -263,7 +275,7 @@
263
  if ( (($code<200) || ($code>=400)) && $nobody) {
264
  curl_setopt($ch, CURLOPT_NOBODY, false);
265
  curl_setopt($ch, CURLOPT_HTTPGET, true);
266
- curl_setopt($ch, CURLOPT_RANGE, '0-1023');
267
  $response = curl_exec($ch);
268
  //echo 'Response 2 : <pre>',$response,'</pre>';
269
  $code=intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
@@ -284,7 +296,7 @@
284
  }
285
 
286
  function unlink_link_callback($matches){
287
- global $url_to_replace;
288
  $url = $ws_link_checker->normalize_url($matches[2]);
289
  $text = $matches[4];
290
 
92
  echo "<!-- run_check -->";
93
 
94
  $sql="SELECT b.* FROM $postdata_name a, $wpdb->posts b
95
+ WHERE a.last_check<'$check_treshold' AND a.post_id=b.id ORDER BY a.last_check ASC LIMIT 40";
96
 
97
  $rows=$wpdb->get_results($sql, OBJECT);
98
  if($rows && (count($rows)>0)){
143
  }
144
  $id=intval($_GET['id']);
145
  $wpdb->query("DELETE FROM $linkdata_name WHERE id=$id LIMIT 1");
146
+ if($wpdb->rows_affected<1){
147
+ die('Error: Couldn\'t remove the link record (DB error).');
148
+ }
149
+ die('OK: Link discarded');
150
 
151
  } else if ($action=='remove_link'){
152
 
159
  $sql="SELECT * FROM $linkdata_name WHERE id = $id LIMIT 1";
160
  $the_link=$wpdb->get_row($sql, OBJECT, 0);
161
  if (!$the_link){
162
+ die('Error: Link not found');
163
  }
164
  $the_post = get_post($the_link->post_id, ARRAY_A);
165
  if (!$the_post){
166
+ die('Error: Post not found');
167
  }
168
 
169
  $new_content = unlink_the_link($the_post['post_content'], $the_link->url);
170
  $new_content = $wpdb->escape($new_content);
171
  $wpdb->query("UPDATE $wpdb->posts SET post_content = '$new_content' WHERE id = $the_link->post_id");
172
+ if($wpdb->rows_affected<1){
173
+ die('Error: Couldn\'t update the post (DB error).');
174
+ }
175
  $wpdb->query("DELETE FROM $linkdata_name WHERE id=$id LIMIT 1");
176
+ if($wpdb->rows_affected<1){
177
+ die('Error: Couldn\'t remove the link record (DB error).');
178
+ }
179
+
180
+ die('OK: Link deleted');
181
  };
182
 
183
  function parse_link($matches, $post_id){
251
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
252
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
253
 
254
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
255
+ curl_setopt($ch, CURLOPT_TIMEOUT, 35);
256
 
257
  curl_setopt($ch, CURLOPT_FAILONERROR, false);
258
 
262
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
263
  } else {
264
  $nobody=true;
265
+ //curl_setopt($ch, CURLOPT_NOBODY, true);
266
+ curl_setopt($ch, CURLOPT_RANGE, '0-1023');
267
  }
268
  curl_setopt($ch, CURLOPT_HEADER, true);
269
 
275
  if ( (($code<200) || ($code>=400)) && $nobody) {
276
  curl_setopt($ch, CURLOPT_NOBODY, false);
277
  curl_setopt($ch, CURLOPT_HTTPGET, true);
278
+ curl_setopt($ch, CURLOPT_RANGE, '0-4095');
279
  $response = curl_exec($ch);
280
  //echo 'Response 2 : <pre>',$response,'</pre>';
281
  $code=intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
296
  }
297
 
298
  function unlink_link_callback($matches){
299
+ global $url_to_replace, $ws_link_checker;
300
  $url = $ws_link_checker->normalize_url($matches[2]);
301
  $text = $matches[4];
302