Version Description
Download this release
Release Info
| Developer | whiteshadow |
| Plugin | |
| Version | 0.3.8 |
| Comparing to | |
| See all releases | |
Code changes from version 0.3.7 to 0.3.8
- broken-link-checker.php +59 -4
- readme.txt +3 -2
- wsblc_ajax.php +66 -1
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.
|
| 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.
|
| 24 |
var $myfile='';
|
| 25 |
var $myfolder='';
|
| 26 |
var $mybasename='';
|
|
@@ -494,7 +494,8 @@ class ws_broken_link_checker {
|
|
| 494 |
?>
|
| 495 |
<div class="wrap">
|
| 496 |
<h2><?php
|
| 497 |
-
echo ($broken_links>0)?"
|
|
|
|
| 498 |
?></h2>
|
| 499 |
<br style="clear:both;" />
|
| 500 |
<?php
|
|
@@ -528,7 +529,14 @@ class ws_broken_link_checker {
|
|
| 528 |
<td>$link->post_title</td>
|
| 529 |
|
| 530 |
<td>$link->link_text</td>
|
| 531 |
-
<td
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
<td><a href='".($link->guid)."' class='edit'>View</a></td>
|
| 533 |
|
| 534 |
<td><a href='post.php?action=edit&post=$link->post_id' class='edit'>Edit Post</a></td>";
|
|
@@ -552,8 +560,19 @@ class ws_broken_link_checker {
|
|
| 552 |
echo '</tbody></table>';
|
| 553 |
};
|
| 554 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
|
| 556 |
<script type='text/javascript'>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
function discardLinkMessage(link_id){
|
| 558 |
$('discard_button-'+link_id).innerHTML = 'Wait...';
|
| 559 |
new Ajax.Request('<?php
|
|
@@ -566,6 +585,7 @@ class ws_broken_link_checker {
|
|
| 566 |
var response = transport.responseText || "";
|
| 567 |
if (re.test(response)){
|
| 568 |
$('link-'+link_id).hide();
|
|
|
|
| 569 |
} else {
|
| 570 |
$('discard_button-'+link_id).innerHTML = 'Discard';
|
| 571 |
alert(response);
|
|
@@ -589,6 +609,7 @@ class ws_broken_link_checker {
|
|
| 589 |
var response = transport.responseText || "";
|
| 590 |
if (re.test(response)){
|
| 591 |
$('link-'+link_id).hide();
|
|
|
|
| 592 |
} else {
|
| 593 |
$('unlink_button-'+link_id).innerHTML = 'Unlink';
|
| 594 |
alert(response);
|
|
@@ -597,6 +618,40 @@ class ws_broken_link_checker {
|
|
| 597 |
}
|
| 598 |
);
|
| 599 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
</script>
|
| 601 |
</div>
|
| 602 |
<?php
|
| 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.8
|
| 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.8';
|
| 24 |
var $myfile='';
|
| 25 |
var $myfolder='';
|
| 26 |
var $mybasename='';
|
| 494 |
?>
|
| 495 |
<div class="wrap">
|
| 496 |
<h2><?php
|
| 497 |
+
echo ($broken_links>0)?"<span id='broken_link_count'>$broken_links</span> Broken Links":
|
| 498 |
+
"No broken links found";
|
| 499 |
?></h2>
|
| 500 |
<br style="clear:both;" />
|
| 501 |
<?php
|
| 529 |
<td>$link->post_title</td>
|
| 530 |
|
| 531 |
<td>$link->link_text</td>
|
| 532 |
+
<td>
|
| 533 |
+
<a href='$link->url'>".$this->mytruncate($link->url)."</a>
|
| 534 |
+
| <a href='javascript:editBrokenLink($link->id, \"$link->url\")'
|
| 535 |
+
id='link-editor-button-$link->id'>Edit</a>
|
| 536 |
+
<br />
|
| 537 |
+
<input type='text' size='50' id='link-editor-$link->id' value='$link->url'
|
| 538 |
+
class='link-editor' style='display:none' />
|
| 539 |
+
</td>
|
| 540 |
<td><a href='".($link->guid)."' class='edit'>View</a></td>
|
| 541 |
|
| 542 |
<td><a href='post.php?action=edit&post=$link->post_id' class='edit'>Edit Post</a></td>";
|
| 560 |
echo '</tbody></table>';
|
| 561 |
};
|
| 562 |
?>
|
| 563 |
+
<style type='text/css'>
|
| 564 |
+
.link-editor {
|
| 565 |
+
font-size: 1em;
|
| 566 |
+
}
|
| 567 |
+
</style>
|
| 568 |
|
| 569 |
<script type='text/javascript'>
|
| 570 |
+
function alterLinkCounter(factor){
|
| 571 |
+
cnt = parseInt($('broken_link_count').innerHTML);
|
| 572 |
+
cnt = cnt + factor;
|
| 573 |
+
$('broken_link_count').innerHTML = cnt;
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
function discardLinkMessage(link_id){
|
| 577 |
$('discard_button-'+link_id).innerHTML = 'Wait...';
|
| 578 |
new Ajax.Request('<?php
|
| 585 |
var response = transport.responseText || "";
|
| 586 |
if (re.test(response)){
|
| 587 |
$('link-'+link_id).hide();
|
| 588 |
+
alterLinkCounter(-1);
|
| 589 |
} else {
|
| 590 |
$('discard_button-'+link_id).innerHTML = 'Discard';
|
| 591 |
alert(response);
|
| 609 |
var response = transport.responseText || "";
|
| 610 |
if (re.test(response)){
|
| 611 |
$('link-'+link_id).hide();
|
| 612 |
+
alterLinkCounter(-1);
|
| 613 |
} else {
|
| 614 |
$('unlink_button-'+link_id).innerHTML = 'Unlink';
|
| 615 |
alert(response);
|
| 618 |
}
|
| 619 |
);
|
| 620 |
}
|
| 621 |
+
|
| 622 |
+
function editBrokenLink(link_id, orig_link){
|
| 623 |
+
if ($('link-editor-button-'+link_id).innerHTML == 'Edit'){
|
| 624 |
+
$('link-editor-'+link_id).show();
|
| 625 |
+
$('link-editor-button-'+link_id).innerHTML = 'Save';
|
| 626 |
+
} else {
|
| 627 |
+
$('link-editor-'+link_id).hide();
|
| 628 |
+
new_url = $('link-editor-'+link_id).value;
|
| 629 |
+
if (new_url != orig_link){
|
| 630 |
+
//Save the changed link
|
| 631 |
+
new Ajax.Request(
|
| 632 |
+
'<?php
|
| 633 |
+
echo get_option( "siteurl" ).'/wp-content/plugins/'.$this->myfolder.'/wsblc_ajax.php?';
|
| 634 |
+
?>action=edit_link&id='+link_id+'&new_url='+escape(new_url),
|
| 635 |
+
{
|
| 636 |
+
method:'post',
|
| 637 |
+
onSuccess: function(transport){
|
| 638 |
+
var re = /OK:.*/i
|
| 639 |
+
var response = transport.responseText || "";
|
| 640 |
+
if (re.test(response)){
|
| 641 |
+
$('link-'+link_id).hide();
|
| 642 |
+
alterLinkCounter(-1);
|
| 643 |
+
//alert(response);
|
| 644 |
+
} else {
|
| 645 |
+
alert(response);
|
| 646 |
+
}
|
| 647 |
+
}
|
| 648 |
+
}
|
| 649 |
+
);
|
| 650 |
+
|
| 651 |
+
}
|
| 652 |
+
$('link-editor-button-'+link_id).innerHTML = 'Edit';
|
| 653 |
+
}
|
| 654 |
+
}
|
| 655 |
</script>
|
| 656 |
</div>
|
| 657 |
<?php
|
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.5
|
| 6 |
-
Stable tag: 0.3.
|
| 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 |
|
|
@@ -16,6 +16,7 @@ This plugin is will monitor your blog looking for broken links and let you know
|
|
| 16 |
* Makes broken links display differently in posts (optional).
|
| 17 |
* Link checking intervals can be configured.
|
| 18 |
* New/modified posts are checked ASAP.
|
|
|
|
| 19 |
|
| 20 |
**How To Use It**
|
| 21 |
The broken links, if any are found, will show up in a new tab of WP admin panel - Manage -> Broken Links. A notification will also appear on the Dashboard.
|
| 2 |
Contributors: whiteshadow
|
| 3 |
Tags: links, broken, maintenance
|
| 4 |
Requires at least: 2.0.2
|
| 5 |
+
Tested up to: 2.5.1
|
| 6 |
+
Stable tag: 0.3.8
|
| 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 |
|
| 16 |
* Makes broken links display differently in posts (optional).
|
| 17 |
* Link checking intervals can be configured.
|
| 18 |
* New/modified posts are checked ASAP.
|
| 19 |
+
* You can unlink or edit broken links in the *Manage -> Broken Links* tab (experimental).
|
| 20 |
|
| 21 |
**How To Use It**
|
| 22 |
The broken links, if any are found, will show up in a new tab of WP admin panel - Manage -> Broken Links. A notification will also appear on the Dashboard.
|
wsblc_ajax.php
CHANGED
|
@@ -46,7 +46,11 @@
|
|
| 46 |
$check_treshold=date('Y-m-d H:i:s', strtotime('-'.$options['check_treshold'].' hours'));
|
| 47 |
$recheck_treshold=date('Y-m-d H:i:s', strtotime('-20 minutes'));
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
if($action=='dashboard_status'){
|
| 52 |
/* displays a notification if broken links have been found */
|
|
@@ -178,6 +182,44 @@
|
|
| 178 |
}
|
| 179 |
|
| 180 |
die('OK: Link deleted');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
};
|
| 182 |
|
| 183 |
function parse_link($matches, $post_id){
|
|
@@ -314,4 +356,27 @@
|
|
| 314 |
return $matches[0];
|
| 315 |
}
|
| 316 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
?>
|
| 46 |
$check_treshold=date('Y-m-d H:i:s', strtotime('-'.$options['check_treshold'].' hours'));
|
| 47 |
$recheck_treshold=date('Y-m-d H:i:s', strtotime('-20 minutes'));
|
| 48 |
|
| 49 |
+
if (!empty($_POST['action'])){
|
| 50 |
+
$action = $_POST['action'];
|
| 51 |
+
} else {
|
| 52 |
+
$action=isset($_GET['action'])?$_GET['action']:'run_check';
|
| 53 |
+
}
|
| 54 |
|
| 55 |
if($action=='dashboard_status'){
|
| 56 |
/* displays a notification if broken links have been found */
|
| 182 |
}
|
| 183 |
|
| 184 |
die('OK: Link deleted');
|
| 185 |
+
|
| 186 |
+
} else if ($action == 'edit_link'){
|
| 187 |
+
//edits the link's URL inside the post
|
| 188 |
+
if (!current_user_can('edit_posts')) {
|
| 189 |
+
die("Error: You can't do that. Access denied.");
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
$id = intval($_GET['id']);
|
| 193 |
+
$new_url = $_GET['new_url'];
|
| 194 |
+
|
| 195 |
+
$sql="SELECT * FROM $linkdata_name WHERE id = $id LIMIT 1";
|
| 196 |
+
$the_link=$wpdb->get_row($sql, OBJECT, 0);
|
| 197 |
+
if (!$the_link){
|
| 198 |
+
die('Error: Link not found');
|
| 199 |
+
}
|
| 200 |
+
$the_post = get_post($the_link->post_id, ARRAY_A);
|
| 201 |
+
if (!$the_post){
|
| 202 |
+
die('Error: Post not found');
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
$new_content = edit_the_link($the_post['post_content'], $the_link->url, $new_url);
|
| 206 |
+
if (function_exists('mysql_real_escape_string')){
|
| 207 |
+
$new_content = mysql_real_escape_string($new_content);
|
| 208 |
+
} else {
|
| 209 |
+
$new_content = $wpdb->escape($new_content);
|
| 210 |
+
}
|
| 211 |
+
$q = "UPDATE $wpdb->posts SET post_content = '$new_content' WHERE id = $the_link->post_id";
|
| 212 |
+
//@file_put_contents('q.txt', $q);
|
| 213 |
+
$wpdb->query($q);
|
| 214 |
+
if($wpdb->rows_affected<1){
|
| 215 |
+
die('Error: Couldn\'t update the post ('.mysql_error().').');
|
| 216 |
+
}
|
| 217 |
+
$wpdb->query("DELETE FROM $linkdata_name WHERE id=$id LIMIT 1");
|
| 218 |
+
if($wpdb->rows_affected<1){
|
| 219 |
+
die('Error: Couldn\'t remove the link record (DB error).');
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
die('OK: Link changed and deleted from the list of broken links.');
|
| 223 |
};
|
| 224 |
|
| 225 |
function parse_link($matches, $post_id){
|
| 356 |
return $matches[0];
|
| 357 |
}
|
| 358 |
}
|
| 359 |
+
|
| 360 |
+
function edit_the_link($content, $url, $newurl){
|
| 361 |
+
global $url_pattern, $url_to_replace, $new_url;
|
| 362 |
+
$url_to_replace = $url;
|
| 363 |
+
$new_url = $newurl;
|
| 364 |
+
$url_pattern='/(<a[\s]+[^>]*href\s*=\s*[\"\']?)([^\'\" >]+)([\'\"]+[^<>]*>)((?sU).*)(<\/a>)/i';
|
| 365 |
+
$content = preg_replace_callback($url_pattern, edit_link_callback, $content);
|
| 366 |
+
return $content;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
function edit_link_callback($matches){
|
| 370 |
+
global $url_to_replace, $new_url, $ws_link_checker;
|
| 371 |
+
$url = $ws_link_checker->normalize_url($matches[2]);
|
| 372 |
+
$text = $matches[4];
|
| 373 |
+
|
| 374 |
+
//echo "$url || $url_to_replace\n";
|
| 375 |
+
if ($url == $url_to_replace){
|
| 376 |
+
//return $text;
|
| 377 |
+
return $matches[1].$new_url.$matches[3].$text.$matches[5];
|
| 378 |
+
} else {
|
| 379 |
+
return $matches[0];
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
?>
|
