Changeset 45229

Show
Ignore:
Timestamp:
05/11/08 09:57:54 (2 months ago)
Author:
whiteshadow
Message:

Edit broken links @ Manage -> Broken Links (experimental)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • broken-link-checker/tags/0.3.8/broken-link-checker.php

    r41385 r45229  
    44Plugin URI: http://w-shadow.com/blog/2007/08/05/broken-link-checker-for-wordpress/ 
    55Description: Checks your posts for broken links and missing images and notifies you on the dashboard if any are found. 
    6 Version: 0.3.7 
     6Version: 0.3.8 
    77Author: Janis Elsts 
    88Author URI: http://w-shadow.com/blog/ 
     
    2121      var $postdata_name; 
    2222      var $linkdata_name; 
    23       var $version='0.3.7'; 
     23      var $version='0.3.8'; 
    2424      var $myfile=''; 
    2525      var $myfolder=''; 
     
    495495<div class="wrap"> 
    496496<h2><?php 
    497       echo ($broken_links>0)?"$broken_links Broken Links":"No broken links found"; 
     497      echo ($broken_links>0)?"<span id='broken_link_count'>$broken_links</span> Broken Links": 
     498                  "No broken links found"; 
    498499?></h2> 
    499500<br style="clear:both;" /> 
     
    529530 
    530531                        <td>$link->link_text</td> 
    531                         <td><a href='$link->url'>".$this->mytruncate($link->url)."</a></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> 
    532540                        <td><a href='".($link->guid)."' class='edit'>View</a></td> 
    533541 
     
    553561            }; 
    554562?> 
     563<style type='text/css'> 
     564.link-editor { 
     565      font-size: 1em; 
     566} 
     567</style> 
    555568 
    556569<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       
    557576      function discardLinkMessage(link_id){ 
    558577            $('discard_button-'+link_id).innerHTML = 'Wait...'; 
     
    567586                              if (re.test(response)){ 
    568587                                    $('link-'+link_id).hide(); 
     588                                    alterLinkCounter(-1); 
    569589                              } else { 
    570590                                    $('discard_button-'+link_id).innerHTML = 'Discard'; 
     
    590610                              if (re.test(response)){ 
    591611                                    $('link-'+link_id).hide(); 
     612                                    alterLinkCounter(-1); 
    592613                              } else { 
    593614                                    $('unlink_button-'+link_id).innerHTML = 'Unlink'; 
     
    598619            ); 
    599620      } 
     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      } 
    600655</script> 
    601656</div> 
  • broken-link-checker/tags/0.3.8/readme.txt

    r41385 r45229  
    33Tags: links, broken, maintenance 
    44Requires at least: 2.0.2 
    5 Tested up to: 2.5 
    6 Stable tag: 0.3.7 
     5Tested up to: 2.5.1 
     6Stable tag: 0.3.8 
    77 
    88This plugin will check your posts for broken links and missing images in background and notify you on the dashboard if any are found.  
     
    1717* Link checking intervals can be configured. 
    1818* New/modified posts are checked ASAP. 
     19* You can unlink or edit broken links in the *Manage -> Broken Links* tab (experimental).  
    1920 
    2021**How To Use It** 
  • broken-link-checker/tags/0.3.8/wsblc_ajax.php

    r41385 r45229  
    4747      $recheck_treshold=date('Y-m-d H:i:s', strtotime('-20 minutes')); 
    4848       
    49       $action=isset($_GET['action'])?$_GET['action']:'run_check'; 
     49      if (!empty($_POST['action'])){ 
     50            $action = $_POST['action']; 
     51      } else { 
     52            $action=isset($_GET['action'])?$_GET['action']:'run_check'; 
     53      } 
    5054       
    5155      if($action=='dashboard_status'){ 
     
    179183 
    180184            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.'); 
    181223      }; 
    182224       
     
    315357            } 
    316358      }      
     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      }      
    317382?> 
  • broken-link-checker/trunk/broken-link-checker.php

    r41385 r45229  
    44Plugin URI: http://w-shadow.com/blog/2007/08/05/broken-link-checker-for-wordpress/ 
    55Description: Checks your posts for broken links and missing images and notifies you on the dashboard if any are found. 
    6 Version: 0.3.7 
     6Version: 0.3.8 
    77Author: Janis Elsts 
    88Author URI: http://w-shadow.com/blog/ 
     
    2121      var $postdata_name; 
    2222      var $linkdata_name; 
    23       var $version='0.3.7'; 
     23      var $version='0.3.8'; 
    2424      var $myfile=''; 
    2525      var $myfolder=''; 
     
    495495<div class="wrap"> 
    496496<h2><?php 
    497       echo ($broken_links>0)?"$broken_links Broken Links":"No broken links found"; 
     497      echo ($broken_links>0)?"<span id='broken_link_count'>$broken_links</span> Broken Links": 
     498                  "No broken links found"; 
    498499?></h2> 
    499500<br style="clear:both;" /> 
     
    529530 
    530531                        <td>$link->link_text</td> 
    531                         <td><a href='$link->url'>".$this->mytruncate($link->url)."</a></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> 
    532540                        <td><a href='".($link->guid)."' class='edit'>View</a></td> 
    533541 
     
    553561            }; 
    554562?> 
     563<style type='text/css'> 
     564.link-editor { 
     565      font-size: 1em; 
     566} 
     567</style> 
    555568 
    556569<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       
    557576      function discardLinkMessage(link_id){ 
    558577            $('discard_button-'+link_id).innerHTML = 'Wait...'; 
     
    567586                              if (re.test(response)){ 
    568587                                    $('link-'+link_id).hide(); 
     588                                    alterLinkCounter(-1); 
    569589                              } else { 
    570590                                    $('discard_button-'+link_id).innerHTML = 'Discard'; 
     
    590610                              if (re.test(response)){ 
    591611                                    $('link-'+link_id).hide(); 
     612                                    alterLinkCounter(-1); 
    592613                              } else { 
    593614                                    $('unlink_button-'+link_id).innerHTML = 'Unlink'; 
     
    598619            ); 
    599620      } 
     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      } 
    600655</script> 
    601656</div> 
  • broken-link-checker/trunk/readme.txt

    r41385 r45229  
    33Tags: links, broken, maintenance 
    44Requires at least: 2.0.2 
    5 Tested up to: 2.5 
    6 Stable tag: 0.3.7 
     5Tested up to: 2.5.1 
     6Stable tag: 0.3.8 
    77 
    88This plugin will check your posts for broken links and missing images in background and notify you on the dashboard if any are found.  
     
    1717* Link checking intervals can be configured. 
    1818* New/modified posts are checked ASAP. 
     19* You can unlink or edit broken links in the *Manage -> Broken Links* tab (experimental).  
    1920 
    2021**How To Use It** 
  • broken-link-checker/trunk/wsblc_ajax.php

    r41385 r45229  
    4747      $recheck_treshold=date('Y-m-d H:i:s', strtotime('-20 minutes')); 
    4848       
    49       $action=isset($_GET['action'])?$_GET['action']:'run_check'; 
     49      if (!empty($_POST['action'])){ 
     50            $action = $_POST['action']; 
     51      } else { 
     52            $action=isset($_GET['action'])?$_GET['action']:'run_check'; 
     53      } 
    5054       
    5155      if($action=='dashboard_status'){ 
     
    179183 
    180184            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.'); 
    181223      }; 
    182224       
     
    315357            } 
    316358      }      
     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      }      
    317382?>