Version Description
Download this release
Release Info
| Developer | whiteshadow |
| Plugin | |
| Version | 0.4.5 |
| Comparing to | |
| See all releases | |
Code changes from version 0.4.4 to 0.4.5
- broken-link-checker.php +8 -2
- readme.txt +2 -2
- wsblc_ajax.php +25 -8
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.4.
|
| 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.4.
|
| 24 |
var $myfile='';
|
| 25 |
var $myfolder='';
|
| 26 |
var $mybasename='';
|
|
@@ -242,6 +242,12 @@ class ws_broken_link_checker {
|
|
| 242 |
function post_saved($post_id){
|
| 243 |
global $wpdb;
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
$found=$wpdb->get_var("SELECT post_id FROM $this->postdata_name WHERE post_id=$post_id LIMIT 1");
|
| 246 |
if($found===NULL){
|
| 247 |
//this post hasn't been saved previously, save the additional data now
|
| 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.4.5
|
| 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.4.5';
|
| 24 |
var $myfile='';
|
| 25 |
var $myfolder='';
|
| 26 |
var $mybasename='';
|
| 242 |
function post_saved($post_id){
|
| 243 |
global $wpdb;
|
| 244 |
|
| 245 |
+
$post = get_post($post_id);
|
| 246 |
+
//Only check links in posts, not revisions and attachments
|
| 247 |
+
if ( ($post->post_type != 'post') && ($post->post_type != 'page') ) return null;
|
| 248 |
+
//Only check published posts
|
| 249 |
+
if ( $post->post_status != 'publish' ) return null;
|
| 250 |
+
|
| 251 |
$found=$wpdb->get_var("SELECT post_id FROM $this->postdata_name WHERE post_id=$post_id LIMIT 1");
|
| 252 |
if($found===NULL){
|
| 253 |
//this post hasn't been saved previously, save the additional data now
|
readme.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
Contributors: whiteshadow
|
| 3 |
Tags: links, broken, maintenance
|
| 4 |
Requires at least: 2.0.2
|
| 5 |
-
Tested up to: 2.6
|
| 6 |
-
Stable tag: 0.4.
|
| 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 |
|
| 2 |
Contributors: whiteshadow
|
| 3 |
Tags: links, broken, maintenance
|
| 4 |
Requires at least: 2.0.2
|
| 5 |
+
Tested up to: 2.6.1
|
| 6 |
+
Stable tag: 0.4.5
|
| 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
|
@@ -22,7 +22,8 @@
|
|
| 22 |
die('Fatal error : undefined object; plugin may not be active.');
|
| 23 |
};
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
$url_to_replace = '';
|
| 27 |
|
| 28 |
$postdata_name=$wpdb->prefix . "blc_postdata";
|
|
@@ -124,17 +125,32 @@
|
|
| 124 |
$links=$wpdb->get_results($sql, OBJECT);
|
| 125 |
if($links && (count($links)>0)){
|
| 126 |
//some unchecked links found
|
| 127 |
-
echo "<!-- checking links (rand : ".rand(1,1000).") -->";
|
| 128 |
foreach ($links as $link) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
if( $ws_link_checker->is_excluded($link->url) || page_exists_simple($link->url) ){
|
| 130 |
//link OK, remove from queue
|
| 131 |
$wpdb->query("DELETE FROM $linkdata_name WHERE id=$link->id");
|
| 132 |
} else {
|
| 133 |
-
$wpdb->query("UPDATE $linkdata_name SET broken=1
|
| 134 |
-
" last_check=NOW(), check_count=check_count+1 WHERE id=$link->id");
|
| 135 |
};
|
| 136 |
|
| 137 |
-
|
| 138 |
if(execution_time()>$max_execution_time){
|
| 139 |
die('<!-- url loop timeout -->');
|
| 140 |
}
|
|
@@ -227,7 +243,8 @@
|
|
| 227 |
function parse_link($matches, $post_id){
|
| 228 |
global $wpdb, $linkdata_name, $ws_link_checker;
|
| 229 |
|
| 230 |
-
$url
|
|
|
|
| 231 |
|
| 232 |
$url = $ws_link_checker->normalize_url($url);
|
| 233 |
if (!$url) return false;
|
|
@@ -235,7 +252,7 @@
|
|
| 235 |
if(strlen($url)>5){
|
| 236 |
$wpdb->query(
|
| 237 |
"INSERT INTO $linkdata_name(post_id, url, link_text)
|
| 238 |
-
VALUES($post_id, '".$wpdb->escape($url)."', '".$wpdb->escape(strip_tags($
|
| 239 |
);
|
| 240 |
};
|
| 241 |
|
|
@@ -363,7 +380,7 @@
|
|
| 363 |
}
|
| 364 |
|
| 365 |
function edit_the_link($content, $url, $newurl){
|
| 366 |
-
global
|
| 367 |
$url_to_replace = $url;
|
| 368 |
$new_url = $newurl;
|
| 369 |
$url_pattern='/(<a[\s]+[^>]*href\s*=\s*[\"\']?)([^\'\" >]+)([\'\"]+[^<>]*>)((?sU).*)(<\/a>)/i';
|
| 22 |
die('Fatal error : undefined object; plugin may not be active.');
|
| 23 |
};
|
| 24 |
|
| 25 |
+
//Regexp for HTML links
|
| 26 |
+
$url_pattern='/<a[\s]+[^>]*href\s*=\s*([\"\']+)([^\'\" >]+)\1[^<>]*>((?sU).*)<\/a>/i';
|
| 27 |
$url_to_replace = '';
|
| 28 |
|
| 29 |
$postdata_name=$wpdb->prefix . "blc_postdata";
|
| 125 |
$links=$wpdb->get_results($sql, OBJECT);
|
| 126 |
if($links && (count($links)>0)){
|
| 127 |
//some unchecked links found
|
| 128 |
+
echo "<!-- checking ".count($links)." links (rand : ".rand(1,1000).") -->";
|
| 129 |
foreach ($links as $link) {
|
| 130 |
+
/*
|
| 131 |
+
Check for problematic (though not necessarily "broken") links.
|
| 132 |
+
If a link has been checked multiple times and still hasn't been marked as broken
|
| 133 |
+
or removed from the queue then probably the checking algorithm is having problems
|
| 134 |
+
with that link. Mark it as broken and hope the user sorts it out.
|
| 135 |
+
*/
|
| 136 |
+
if ($link->check_count >=5){
|
| 137 |
+
$wpdb->query("UPDATE $linkdata_name SET broken=1 WHERE id=$link->id");
|
| 138 |
+
//can afford to skip the $max_execution_time check here, the above op. should be very fast.
|
| 139 |
+
continue;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
//Update the check_count & last_check fields before actually performing the check.
|
| 143 |
+
//Useful if something goes terribly wrong in page_exists_simple() with this particular URL.
|
| 144 |
+
$wpdb->query("UPDATE $linkdata_name SET last_check=NOW(), check_count=check_count+1
|
| 145 |
+
WHERE id=$link->id");
|
| 146 |
+
|
| 147 |
if( $ws_link_checker->is_excluded($link->url) || page_exists_simple($link->url) ){
|
| 148 |
//link OK, remove from queue
|
| 149 |
$wpdb->query("DELETE FROM $linkdata_name WHERE id=$link->id");
|
| 150 |
} else {
|
| 151 |
+
$wpdb->query("UPDATE $linkdata_name SET broken=1 WHERE id=$link->id");
|
|
|
|
| 152 |
};
|
| 153 |
|
|
|
|
| 154 |
if(execution_time()>$max_execution_time){
|
| 155 |
die('<!-- url loop timeout -->');
|
| 156 |
}
|
| 243 |
function parse_link($matches, $post_id){
|
| 244 |
global $wpdb, $linkdata_name, $ws_link_checker;
|
| 245 |
|
| 246 |
+
$url = $matches[2];
|
| 247 |
+
$text = $matches[3];
|
| 248 |
|
| 249 |
$url = $ws_link_checker->normalize_url($url);
|
| 250 |
if (!$url) return false;
|
| 252 |
if(strlen($url)>5){
|
| 253 |
$wpdb->query(
|
| 254 |
"INSERT INTO $linkdata_name(post_id, url, link_text)
|
| 255 |
+
VALUES($post_id, '".$wpdb->escape($url)."', '".$wpdb->escape(strip_tags($text))."')"
|
| 256 |
);
|
| 257 |
};
|
| 258 |
|
| 380 |
}
|
| 381 |
|
| 382 |
function edit_the_link($content, $url, $newurl){
|
| 383 |
+
global /*$url_pattern, */$url_to_replace, $new_url;
|
| 384 |
$url_to_replace = $url;
|
| 385 |
$new_url = $newurl;
|
| 386 |
$url_pattern='/(<a[\s]+[^>]*href\s*=\s*[\"\']?)([^\'\" >]+)([\'\"]+[^<>]*>)((?sU).*)(<\/a>)/i';
|
