Plugin Directory

Changeset 2054130


Ignore:
Timestamp:
03/20/2019 05:13:01 PM (7 years ago)
Author:
freediver
Message:

new BLC

Location:
broken-link-checker
Files:
98 added
61 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • broken-link-checker/trunk/broken-link-checker.php

    r1707025 r2054130  
    44Plugin URI: https://wordpress.org/plugins/broken-link-checker/
    55Description: Checks your blog for broken links and missing images and notifies you on the dashboard if any are found.
    6 Version: 1.11.5
    7 Author: Janis Elsts, Vladimir Prelovac
     6Version: 1.11.8
     7Author: ManageWP
     8Author URI: https://managewp.com
    89Text Domain: broken-link-checker
    910*/
  • broken-link-checker/trunk/core/core.php

    r1707025 r2054130  
    7474
    7575        //Add/remove Cron events
     76        add_filter( 'cron_schedules', array( $this, 'cron_add_every_10_minutes' ) );
    7677        $this->setup_cron_events();
    7778
     
    9697        add_action( 'admin_notices', array( $this, 'show_warnings_section_notice' ) );
    9798
    98         add_filter('cron_schedules', array( $this, 'cron_add_every_10_minutes'));
    9999
    100100    }
     
    471471
    472472            //Parse the custom field list
    473             $new_custom_fields = array_filter( 
     473            $new_custom_fields = array_filter(
    474474                preg_split( '/[\r\n]+/', $cleanPost['blc_custom_fields'], -1, PREG_SPLIT_NO_EMPTY )
    475475            );
    476            
     476
    477477            //Calculate the difference between the old custom field list and the new one (used later)
    478478            $diff1 = array_diff( $new_custom_fields, $this->conf->options['custom_fields'] );
     
    14141414     */
    14151415    function make_custom_field_input($html, $current_settings){
    1416         $html .= '<span class="description">' . 
     1416        $html .= '<span class="description">' .
    14171417                    __(
    14181418                        'Enter the names of custom fields you want to check (one per line). If a field contains HTML code, prefix its name with <code>html:</code>. For example, <code>html:field_name</code>.',
     
    21202120
    21212121        if ( count($selected_links) > 0 ){
     2122            $transactionManager = TransactionManager::getInstance();
     2123            $transactionManager->start();
    21222124            foreach($selected_links as $link_id){
    21232125                //Load the link
     
    21562158
    21572159        if ( $processed_links > 0 ){
     2160            $transactionManager->commit();
    21582161            $messages[] = sprintf(
    21592162                _n(
     
    21842187
    21852188        if ( count($selected_links) > 0 ){
     2189            $transactionManager = TransactionManager::getInstance();
     2190            $transactionManager->start();
    21862191            foreach($selected_links as $link_id){
    21872192                //Load the link
     
    22152220
    22162221        if ( $processed_links > 0 ){
     2222            $transactionManager->commit();
    22172223            $messages[] = sprintf(
    22182224                _n(
     
    26292635                //Check if we still have some execution time left
    26302636                if( $this->execution_time() > $max_execution_time ){
     2637                    $transactionManager->commit();
    26312638                    //FB::log('The allotted execution time has run out');
    26322639                    $blclog->info('The allotted execution time has run out.');
     
    26372644                //Check if the server isn't overloaded
    26382645                if ( $this->server_too_busy() ){
     2646                    $transactionManager->commit();
    26392647                    //FB::log('Server overloaded, bailing out.');
    26402648                    $blclog->info('Server load too high, stopping.');
     
    29622970
    29632971            $link->isOptionLinkChanged = true;
     2972
     2973            $transactionManager = TransactionManager::getInstance();
     2974            $transactionManager->start();
     2975
    29642976            //Save the changes
    29652977            if ( $link->save() ){
     2978                $transactionManager->commit();
    29662979                die( "OK" );
    29672980            } else {
     
    30013014            //Save the changes
    30023015            $link->isOptionLinkChanged = true;
     3016            $transactionManager = TransactionManager::getInstance();
     3017            $transactionManager->start();
    30033018            if ( $link->save() ){
     3019                $transactionManager->commit();
    30043020                die( "OK" );
    30053021            } else {
     
    32453261        }
    32463262
    3247         //In case the immediate check fails, this will ensure the link is checked during the next work() run.
     3263        $transactionManager = TransactionManager::getInstance();
     3264        $transactionManager->start();
     3265
     3266        //In case the immediate check fails, this will ensure the link is checked during the next work() run.
    32483267        $link->last_check_attempt = 0;
    32493268        $link->isOptionLinkChanged = true;
     
    32523271        //Check the link and save the results.
    32533272        $link->check(true);
     3273
     3274        $transactionManager->commit();
    32543275
    32553276        $status = $link->analyse_status();
  • broken-link-checker/trunk/includes/any-post.php

    r1139206 r2054130  
    111111    }
    112112   
    113   /**
    114    * Remove the synch. record and link instances associated with a post when it's deleted
    115    *
    116    * @param int $post_id
    117    * @return void
    118    */
     113    /**
     114    * Remove the synch. record and link instances associated with a post when it's deleted
     115    *
     116    * @param int $post_id
     117    * @return void
     118    */
    119119    function post_deleted($post_id){
     120        global $wpdb;
     121
     122        $post_id = intval( $post_id );
    120123        //Get the container type matching the type of the deleted post
    121         $post = get_post($post_id);
     124        $post = get_post( $post_id );
    122125        if ( !$post ){
    123126            return;
    124127        }
    125128        //Get the associated container object
    126         $post_container = blcContainerHelper::get_container( array($post->post_type, intval($post_id)) );
     129        $post_type = get_post_type( $post );
     130        $post_container = blcContainerHelper::get_container( array( $post_type, $post_id ) );
    127131       
    128132        if ( $post_container ){
    129             //Delete it
     133            //Delete the container
    130134            $post_container->delete();
     135
     136            // Firstly: See if we have any current instances
     137            $q_current_instance_ids = $wpdb->prepare(
     138                'SELECT instance_id FROM `'.$wpdb->prefix.'_blc_instances` WHERE container_id = %d AND container_type = %s',
     139                $post_id,
     140                $post_type );
     141
     142            $current_instance_ids_results = $wpdb->get_results( $q_current_instance_ids, ARRAY_A );
     143
     144            if( $wpdb->num_rows == 0 ) {
     145                // No current instances present, skip cleanup at once
     146                return;
     147            }
     148
     149            $current_instance_ids = wp_list_pluck( $current_instance_ids_results, 'instance_id' );
     150
     151            // Secondly: Get all link_ids used in our current instances
     152            $q_current_link_ids = 'SELECT DISTINCT link_id FROM `'.$wpdb->prefix.'_blc_instances` WHERE instance_id IN (\''.implode("', '", $current_instance_ids).'\')';
     153
     154            $q_current_link_ids_results = $wpdb->get_results( $q_current_link_ids, ARRAY_A );
     155
     156            $current_link_ids = wp_list_pluck( $q_current_link_ids_results, 'link_id' );
     157
     158            // Go ahead and remove blc_instances for this container, blc_cleanup_links( $current_link_ids ) will find and remove any dangling links in the blc_links table
     159            $wpdb->query( 'DELETE FROM `'.$wpdb->prefix.'_blc_instances` WHERE instance_id IN (\''.implode("', '", $current_instance_ids).'\')' );
     160
    131161            //Clean up any dangling links
    132             blc_cleanup_links();
     162            blc_cleanup_links( $current_link_ids );
    133163        }
    134164    }
  • broken-link-checker/trunk/includes/links.php

    r1381903 r2054130  
    22
    33/**
    4  * @author W-Shadow 
     4 * @author W-Shadow
    55 * @copyright 2010
    66 */
    7  
     7
    88if (!class_exists('blcLink')){
    9    
     9
    1010define('BLC_LINK_STATUS_UNKNOWN', 'unknown');
    1111define('BLC_LINK_STATUS_OK', 'ok');
     
    1313define('BLC_LINK_STATUS_WARNING', 'warning');
    1414define('BLC_LINK_STATUS_ERROR', 'error');
    15    
     15
    1616class blcLink {
    17    
     17
    1818    //Object state
    1919    var $is_new = false;
    20    
     20
    2121    //DB fields
    2222    var $link_id = 0;
    2323    var $url = '';
    24    
     24
    2525    var $being_checked = false;
    2626    var $last_check = 0;
     
    3030    var $request_duration = 0;
    3131    var $timeout = false;
    32    
     32
    3333    var $redirect_count = 0;
    3434    var $final_url = '';
    35    
     35
    3636    var $broken = false;
    3737    public $warning = false;
    3838    var $first_failure = 0;
    3939    var $last_success = 0;
    40     var $may_recheck = 1; 
    41    
     40    var $may_recheck = 1;
     41
    4242    var $false_positive = false;
    4343    var $result_hash = '';
    4444
    4545    var $dismissed = false;
    46    
     46
    4747    var $status_text = '';
    4848    var $status_code = '';
    49        
     49
    5050    var $log = '';
    51    
     51
    5252    //A list of DB fields and their storage formats
    5353    var $field_format;
    54    
     54
    5555    //A cached list of the link's instances
    5656    var $_instances = null;
    57    
     57
    5858    var $http_status_codes = array(
    59         // [Informational 1xx] 
    60         100=>'Continue', 
    61         101=>'Switching Protocols', 
    62         // [Successful 2xx] 
    63         200=>'OK', 
    64         201=>'Created', 
    65         202=>'Accepted', 
    66         203=>'Non-Authoritative Information', 
    67         204=>'No Content', 
    68         205=>'Reset Content', 
    69         206=>'Partial Content', 
    70         // [Redirection 3xx] 
    71         300=>'Multiple Choices', 
    72         301=>'Moved Permanently', 
    73         302=>'Found', 
    74         303=>'See Other', 
    75         304=>'Not Modified', 
    76         305=>'Use Proxy', 
    77         //306=>'(Unused)', 
    78         307=>'Temporary Redirect', 
    79         // [Client Error 4xx] 
    80         400=>'Bad Request', 
    81         401=>'Unauthorized', 
    82         402=>'Payment Required', 
    83         403=>'Forbidden', 
    84         404=>'Not Found', 
    85         405=>'Method Not Allowed', 
    86         406=>'Not Acceptable', 
    87         407=>'Proxy Authentication Required', 
    88         408=>'Request Timeout', 
    89         409=>'Conflict', 
    90         410=>'Gone', 
    91         411=>'Length Required', 
    92         412=>'Precondition Failed', 
    93         413=>'Request Entity Too Large', 
    94         414=>'Request-URI Too Long', 
    95         415=>'Unsupported Media Type', 
    96         416=>'Requested Range Not Satisfiable', 
    97         417=>'Expectation Failed', 
    98         // [Server Error 5xx] 
    99         500=>'Internal Server Error', 
    100         501=>'Not Implemented', 
    101         502=>'Bad Gateway', 
    102         503=>'Service Unavailable', 
    103         504=>'Gateway Timeout', 
     59        // [Informational 1xx]
     60        100=>'Continue',
     61        101=>'Switching Protocols',
     62        // [Successful 2xx]
     63        200=>'OK',
     64        201=>'Created',
     65        202=>'Accepted',
     66        203=>'Non-Authoritative Information',
     67        204=>'No Content',
     68        205=>'Reset Content',
     69        206=>'Partial Content',
     70        // [Redirection 3xx]
     71        300=>'Multiple Choices',
     72        301=>'Moved Permanently',
     73        302=>'Moved Temporarily',
     74        303=>'See Other',
     75        304=>'Not Modified',
     76        305=>'Use Proxy',
     77        //306=>'(Unused)',
     78        307=>'Temporary Redirect',
     79        // [Client Error 4xx]
     80        400=>'Bad Request',
     81        401=>'Unauthorized',
     82        402=>'Payment Required',
     83        403=>'Forbidden',
     84        404=>'Not Found',
     85        405=>'Method Not Allowed',
     86        406=>'Not Acceptable',
     87        407=>'Proxy Authentication Required',
     88        408=>'Request Timeout',
     89        409=>'Conflict',
     90        410=>'Gone',
     91        411=>'Length Required',
     92        412=>'Precondition Failed',
     93        413=>'Request Entity Too Large',
     94        414=>'Request-URI Too Long',
     95        415=>'Unsupported Media Type',
     96        416=>'Requested Range Not Satisfiable',
     97        417=>'Expectation Failed',
     98        // [Server Error 5xx]
     99        500=>'Internal Server Error',
     100        501=>'Not Implemented',
     101        502=>'Bad Gateway',
     102        503=>'Service Unavailable',
     103        504=>'Gateway Timeout',
    104104        505=>'HTTP Version Not Supported',
    105105        509=>'Bandwidth Limit Exceeded',
     
    109109    function __construct($arg = null){
    110110        global $wpdb, $blclog; /** @var wpdb $wpdb  */
    111        
     111
    112112        $this->field_format = array(
    113113            'url' => '%s',
     
    133133            'dismissed' => 'bool',
    134134        );
    135        
     135
    136136        if (is_numeric($arg)){
    137137            //Load a link with ID = $arg from the DB.
    138138            $q = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}blc_links WHERE link_id=%d LIMIT 1", $arg);
    139139            $arr = $wpdb->get_row( $q, ARRAY_A );
    140            
     140
    141141            if ( is_array($arr) ){ //Loaded successfully
    142142                $this->set_values($arr);
     
    145145                //I'd throw an error, but that wouldn't be PHP 4 compatible...
    146146                $blclog->warn(__CLASS__ .':' . __FUNCTION__ . ' Link not found.', $arg);
    147             }           
    148            
     147            }
     148
    149149        } else if (is_string($arg)){
    150150            //Load a link with URL = $arg from the DB. Create a new one if the record isn't found.
     
    152152            $q = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}blc_links WHERE url=%s LIMIT 1", $arg);
    153153            $arr = $wpdb->get_row( $q, ARRAY_A );
    154            
     154
    155155            if ( is_array($arr) ){ //Loaded successfully
    156156//              $blclog->debug(__CLASS__ .':' . __FUNCTION__ . ' Success!');
     
    160160                $this->url = $arg;
    161161                $this->is_new = true;
    162             }           
    163            
     162            }
     163
    164164        } else if (is_array($arg)){
    165165            $this->set_values($arg);
     
    170170        }
    171171    }
    172    
     172
    173173    function blcLink($arg = null){
    174174        $this->__construct($arg);
    175175    }
    176    
     176
    177177  /**
    178178   * blcLink::set_values()
     
    184184    function set_values($arr){
    185185        $arr = $this->to_native_format($arr);
    186        
     186
    187187        foreach( $arr as $key => $value ){
    188188            $this->$key = $value;
    189189        }
    190190    }
    191    
     191
    192192  /**
    193193   * Check whether the object represents a valid link
     
    198198        return !empty( $this->url ) && ( !empty($this->link_id) || $this->is_new );
    199199    }
    200    
     200
    201201  /**
    202202   * Check if the link is working.
    203203   *
    204    * @param bool $save_results Automatically save the results of the check. 
    205    * @return bool 
     204   * @param bool $save_results Automatically save the results of the check.
     205   * @return bool
    206206   */
    207207    function check( $save_results = true ){
    208208        if ( !$this->valid() ) return false;
    209        
     209
    210210        $this->last_check_attempt = time();
    211        
     211
    212212        /*
    213213        If the link is still marked as in the process of being checked, that probably means
    214         that the last time the plugin tried to check it the script got terminated by PHP for 
     214        that the last time the plugin tried to check it the script got terminated by PHP for
    215215        running over the execution time limit or causing a fatal error.
    216        
     216
    217217        This problem is likely to be temporary for most links, so we leave it be and treat it
    218         as any other link (i.e. check it again later using the default recheck periodicity). 
     218        as any other link (i.e. check it again later using the default recheck periodicity).
    219219        */
    220220        if ( $this->being_checked ) {
    221221            $this->being_checked = false;
    222            
     222
    223223            //Add an explanatory notice to the link's log
    224224            $error_notice = "[" . __("The plugin script was terminated while trying to check the link.", 'broken-link-checker') . "]";
     
    226226                $this->log = $error_notice . "\r\n" . $this->log;
    227227            }
    228            
     228
    229229            if ( $save_results ){
    230230                $this->save();
    231231            }
    232            
     232
    233233            return false;
    234234        }
    235        
     235
    236236        $this->being_checked = true;
    237237        $this->check_count++;
    238        
     238
    239239        if ( $save_results ) {
    240            
     240
    241241            //Update the DB record before actually performing the check.
    242             //Useful if something goes terribly wrong while checking this particular URL 
     242            //Useful if something goes terribly wrong while checking this particular URL
    243243            //(e.g. the server might kill the script for running over the exec. time limit).
    244244            //Note : might be unnecessary.
    245245            $this->save();
    246246        }
    247        
     247
    248248        $defaults = array(
    249249            'broken' => false,
     
    260260            'status_code' => '',
    261261        );
    262        
    263        
     262
     263
    264264        $checker = blcCheckerHelper::get_checker_for($this->get_ascii_url());
    265        
     265
    266266        if ( is_null($checker) ){
    267267            //Oops, there are no checker implementations that can handle this link.
     
    270270            $this->being_checked = false;
    271271            $this->log = __("The plugin doesn't know how to check this type of link.", 'broken-link-checker');
    272                        
     272
    273273            if ( $save_results ){
    274274                $this->save();
    275275            }
    276            
     276
    277277            return true;
    278278        }
    279        
     279
    280280        //Check the link
    281281        $rez = $checker->check($this->get_ascii_url());
     
    296296        //Update the object's fields with the new results
    297297        $this->set_values($results);
    298        
     298
    299299        //Update timestamps & state-dependent fields
    300300        $this->status_changed($results['broken'], $new_result_hash);
    301301        $this->being_checked = false;
    302        
    303         //Save results to the DB 
     302
     303        //Save results to the DB
    304304        if($save_results){
    305305            $this->save();
    306306        }
    307        
     307
    308308        return $this->broken;
    309309    }
     
    439439        return $check_results;
    440440    }
    441    
     441
    442442  /**
    443    * A helper method used to update timestamps & other state-dependent fields 
     443   * A helper method used to update timestamps & other state-dependent fields
    444444   * after the state of the link (broken vs working) has just been determined.
    445445   *
     
    462462            $this->dismissed = false;
    463463        }
    464        
     464
    465465        if ( $this->false_positive && !empty($new_result_hash) ){
    466             //If the link has been marked as a (probable) false positive, 
    467             //mark it as broken *only* if the new result is different from 
     466            //If the link has been marked as a (probable) false positive,
     467            //mark it as broken *only* if the new result is different from
    468468            //the one that caused the user to mark it as a false positive.
    469469            if ( $broken || $this->warning ){
     
    477477                }
    478478            } else {
    479                 //The plugin now thinks the link is working, 
     479                //The plugin now thinks the link is working,
    480480                //so it's no longer a false positive.
    481481                $this->false_positive = false;
    482482            }
    483483        }
    484        
     484
    485485        $this->broken = $broken;
    486486        $this->result_hash = $new_result_hash;
    487        
     487
    488488        //Update timestamps
    489489        $this->last_check = $this->last_check_attempt;
     
    497497            $this->check_count = 0;
    498498        }
    499        
     499
    500500        //Add a line indicating link status to the log
    501501        if ( $this->broken || $this->warning ) {
     
    505505        }
    506506    }
    507    
     507
    508508  /**
    509509   * blcLink::save()
     
    521521            $this->warning = false;
    522522        }
    523        
     523
    524524        //Make a list of fields to be saved and their values in DB format
    525525        $values = array();
     
    528528        }
    529529        $values = $this->to_db_format($values);
    530        
     530
    531531        if ( $this->is_new ){
    532 
    533                 TransactionManager::getInstance()->commit();
    534532
    535533            //BUG: Technically, there should be a 'LOCK TABLES wp_blc_links WRITE' here. In fact,
    536534            //the plugin should probably lock all involved tables whenever it parses something, lest
    537535            //the user (ot another plugin) modify the thing being parsed while we're working.
    538             //The problem with table locking, though, is that parsing takes a long time and having 
     536            //The problem with table locking, though, is that parsing takes a long time and having
    539537            //all of WP freeze while the plugin is working would be a Bad Thing. Food for thought.
    540            
     538
    541539            //Check if there's already a link with this URL present
    542540            $q = $wpdb->prepare(
     
    545543            );
    546544            $existing_id = $wpdb->get_var($q);
    547            
     545
    548546            if ( !empty($existing_id) ){
    549547                //Dammit.
     
    551549                $this->is_new = false;
    552550                return true;
    553             }       
    554            
     551            }
     552
    555553            //Insert a new row
    556554            $q = sprintf(
    557                 "INSERT INTO {$wpdb->prefix}blc_links( %s ) VALUES( %s )", 
    558                 implode(', ', array_keys($values)), 
     555                "INSERT INTO {$wpdb->prefix}blc_links( %s ) VALUES( %s )",
     556                implode(', ', array_keys($values)),
    559557                implode(', ', array_values($values))
    560558            );
     
    563561
    564562            $rez = $wpdb->query($q) !== false;
    565            
     563
    566564            if ($rez){
    567565                $this->link_id = $wpdb->insert_id;
     
    574572                //FB::error($wpdb->last_error, "Error adding link {$this->url}");
    575573            }
    576                
     574
     575            TransactionManager::getInstance()->commit();
     576
    577577            return $rez;
    578                                    
     578
    579579        } else {
    580580            if ($this->isOptionLinkChanged !== true ) {
     
    582582            }
    583583            $this->isOptionLinkChanged = false;
    584             //Generate the field = dbvalue expressions 
     584            //Generate the field = dbvalue expressions
    585585            $set_exprs = array();
    586586            foreach($values as $name => $value){
     
    588588            }
    589589            $set_exprs = implode(', ', $set_exprs);
    590            
     590
    591591            //Update an existing DB record
    592592            $q = sprintf(
     
    597597            //FB::log($q, 'Link update query');
    598598            $blclog->debug(__CLASS__ .':' . __FUNCTION__ . ' Updating a link. SQL query:'. "\n", $q);
    599            
     599
    600600            $rez = $wpdb->query($q) !== false;
    601601            if ( $rez ){
     
    606606                //FB::error($wpdb->last_error, "Error updating link {$this->url}");
    607607            }
    608            
    609             return $rez;           
    610         }
    611     }
    612    
     608
     609            TransactionManager::getInstance()->commit();
     610
     611            return $rez;
     612        }
     613    }
     614
    613615  /**
    614    * A helper method for converting the link's field values to DB format and escaping them 
    615    * for use in SQL queries. 
     616   * A helper method for converting the link's field values to DB format and escaping them
     617   * for use in SQL queries.
    616618   *
    617619   * @param array $values
     
    620622    function to_db_format($values){
    621623        global $wpdb; /** @var wpdb $wpdb  */
    622        
     624
    623625        $dbvalues = array();
    624        
     626
    625627        foreach($values as $name => $value){
    626628            //Skip fields that don't exist in the blc_links table.
     
    628630                continue;
    629631            }
    630            
     632
    631633            $format = $this->field_format[$name];
    632            
     634
    633635            //Convert native values to a format comprehensible to the DB
    634636            switch($format){
    635                
     637
    636638                case 'datetime' :
    637639                    if ( empty($value) ){
     
    642644                    $format = '%s';
    643645                    break;
    644                    
     646
    645647                case 'bool':
    646648                    if ( $value ){
     
    652654                    break;
    653655            }
    654            
     656
    655657            //Escapize
    656658            $value = $wpdb->prepare($format, $value);
    657            
     659
    658660            $dbvalues[$name] = $value;
    659661        }
    660        
    661         return $dbvalues;       
    662     }
    663    
     662
     663        return $dbvalues;
     664    }
     665
    664666  /**
    665667   * A helper method for converting values fetched from the database to native datatypes.
     
    669671   */
    670672    function to_native_format($values){
    671        
     673
    672674        foreach($values as $name => $value){
    673675            //Don't process fields that don't exist in the blc_links table.
     
    675677                continue;
    676678            }
    677            
     679
    678680            $format = $this->field_format[$name];
    679            
     681
    680682            //Convert values in DB format to native datatypes.
    681683            switch($format){
    682                
     684
    683685                case 'datetime' :
    684686                    if ( $value == '0000-00-00 00:00:00' ){
     
    688690                    }
    689691                    break;
    690                    
     692
    691693                case 'bool':
    692694                    $value = (bool)$value;
    693695                    break;
    694                    
     696
    695697                case '%d':
    696698                    $value = intval($value);
    697699                    break;
    698                    
     700
    699701                case '%f':
    700702                    $value = floatval($value);
    701703                    break;
    702                    
    703             }
    704            
     704
     705            }
     706
    705707            $values[$name] = $value;
    706708        }
    707        
     709
    708710        return $values;
    709711    }
    710    
     712
    711713  /**
    712714   * blcLink::edit()
     
    714716   *
    715717   * Here's how this really works : create a new link with the new URL. Then edit()
    716    * all instances and point them to the new link record. If some instance can't be 
     718   * all instances and point them to the new link record. If some instance can't be
    717719   * edited they will still point to the old record. The old record is deleted
    718    * if all instances were edited successfully.   
     720   * if all instances were edited successfully.
    719721   *
    720722   * @param string $new_url
    721723   * @param string $new_text Optional.
    722    * @return array An associative array with these keys : 
     724   * @return array An associative array with these keys :
    723725   *   new_link_id - the database ID of the new link.
    724726   *   new_link - the new link (an instance of blcLink).
    725    *   cnt_okay - the number of successfully edited link instances. 
     727   *   cnt_okay - the number of successfully edited link instances.
    726728   *   cnt_error - the number of instances that caused problems.
    727    *   errors - an array of WP_Error objects corresponding to the failed edits. 
     729   *   errors - an array of WP_Error objects corresponding to the failed edits.
    728730   */
    729731    function edit($new_url, $new_text = null){
     
    734736            );
    735737        }
    736        
     738
    737739        //FB::info('Changing link '.$this->link_id .' to URL "'.$new_url.'"');
    738        
     740
    739741        $instances = $this->get_instances();
    740742        //Fail if there are no instances
     
    753755            );
    754756        };
    755        
    756         //Load or create a link with the URL = $new_url 
     757
     758        //Load or create a link with the URL = $new_url
    757759        $new_link = new blcLink($new_url);
    758760        $was_new = $new_link->is_new;
     
    761763            $new_link->save(); //so that we get a valid link_id
    762764        }
    763        
     765
    764766        //FB::log("Changing link to $new_url");
    765        
     767
    766768        if ( empty($new_link->link_id) ){
    767769            //FB::error("Failed to create a new link record");
     
    779781            );
    780782        }
    781        
     783
    782784        $cnt_okay = $cnt_error = 0;
    783785        $errors = array();
    784        
     786
    785787        //Edit each instance.
    786788        //FB::info('Editing ' . count($instances) . ' instances');
     
    798800            }
    799801        }
    800        
     802
    801803        //If all instances were edited successfully we can delete the old link record.
    802804        //UNLESS this link is equal to the new link (which should never happen, but whatever).
     
    804806            $this->forget( false );
    805807        }
    806        
     808
    807809        //On the other hand, if no instances could be edited and the $new_link was really new,
    808810        //then delete it.
     
    811813            $new_link = $this;
    812814        }
    813        
     815
    814816        return array(
    815817            'new_link_id' => $new_link->link_id,
    816818            'new_link' => $new_link,
    817819            'cnt_okay' => $cnt_okay,
    818             'cnt_error' => $cnt_error, 
     820            'cnt_error' => $cnt_error,
    819821            'errors' => $errors,
    820          );         
    821     }
    822    
     822         );
     823    }
     824
    823825  /**
    824    * Edit all of of this link's instances and replace the URL with the URL that it redirects to. 
     826   * Edit all of of this link's instances and replace the URL with the URL that it redirects to.
    825827   * This method does nothing if the link isn't a redirect.
    826828   *
    827    * @see blcLink::edit() 
    828    *
    829    * @return array|WP_Error 
    830    */ 
     829   * @see blcLink::edit()
     830   *
     831   * @return array|WP_Error
     832   */
    831833    function deredirect(){
    832834        if ( !$this->valid() ){
     
    836838            );
    837839        }
    838        
     840
    839841        if ( ($this->redirect_count <= 0) || empty($this->final_url) ){
    840842            return new WP_Error(
     
    850852            $new_url .= '#' . $anchor;
    851853        }
    852        
     854
    853855        return $this->edit($new_url);
    854856    }
     
    857859   * Unlink all instances and delete the link record.
    858860   *
    859    * @return array|WP_Error An associative array with these keys : 
     861   * @return array|WP_Error An associative array with these keys :
    860862   *    cnt_okay - the number of successfully removed instances.
    861863   *    cnt_error - the number of instances that couldn't be removed.
     
    870872            );
    871873        }
    872        
     874
    873875        //FB::info($this, 'Removing link');
    874876        $instances = $this->get_instances();
    875        
     877
    876878        //No instances? Just remove the link then.
    877879        if (empty($instances)) {
    878880            //FB::warn("This link has no instances. Deleting the link.");
    879881            $rez = $this->forget( false ) !== false;
    880            
     882
    881883            if ( $rez ){
    882884                return array(
     
    884886                    'cnt_error' => 0,
    885887                    'link_deleted' => true,
    886                     'errors' => array(), 
     888                    'errors' => array(),
    887889                );
    888890            } else {
     
    896898                            __("Couldn't delete the link's database record", 'broken-link-checker')
    897899                        )
    898                     ), 
     900                    ),
    899901                );
    900902            }
    901903        }
    902        
    903        
     904
     905
    904906        //FB::info('Unlinking ' . count($instances) . ' instances');
    905        
     907
    906908        $cnt_okay = $cnt_error = 0;
    907909        $errors = array();
    908        
     910
    909911        //Unlink each instance.
    910912        foreach ( $instances as $instance ){
    911             $rez = $instance->unlink( $this->url ); 
    912            
     913            $rez = $instance->unlink( $this->url );
     914
    913915            if ( is_wp_error($rez) ){
    914916                $cnt_error++;
     
    920922            }
    921923        }
    922        
     924
    923925        //If all instances were unlinked successfully we can delete the link record.
    924926        if ( ( $cnt_error == 0 ) && ( $cnt_okay > 0 ) ){
    925927            //FB::log('Instances removed, deleting the link.');
    926928            $link_deleted = $this->forget() !== false;
    927            
     929
    928930            if ( !$link_deleted ){
    929931                array_push(
    930                     $errors, 
     932                    $errors,
    931933                    new WP_Error(
    932934                        "deletion_failed",
     
    935937                );
    936938            }
    937            
     939
    938940        } else {
    939941            //FB::error("Something went wrong. Unlinked instances : $cnt_okay, errors : $cnt_error");
    940942            $link_deleted = false;
    941943        }
    942        
     944
    943945        return array(
    944946            'cnt_okay' => $cnt_okay,
     
    946948            'link_deleted' => $link_deleted,
    947949            'errors' => $errors,
    948         ); 
     950        );
    949951    }
    950952
     
    958960        global $wpdb; /** @var wpdb $wpdb */
    959961        if ( !$this->valid() ) return false;
    960        
     962
    961963        if ( !empty($this->link_id) ){
    962964            //FB::info($this, 'Deleting link from DB');
    963            
     965
    964966            if ( $remove_instances ){
    965967                //Remove instances, if any
    966968                $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}blc_instances WHERE link_id=%d", $this->link_id) );
    967969            }
    968            
     970
    969971            //Remove the link itself
    970972            $rez = $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}blc_links WHERE link_id=%d", $this->link_id) );
    971973            $this->link_id = 0;
    972            
     974
    973975            return $rez;
    974976        } else {
    975977            return false;
    976978        }
    977        
    978     }
    979    
     979
     980    }
     981
    980982  /**
    981983   * Get a list of the link's instances
    982984   *
    983985   * @param bool $ignore_cache Don't use the internally cached instance list.
    984    * @param string $purpose 
     986   * @param string $purpose
    985987   * @return blcLinkInstance[] An array of instance objects or FALSE on failure.
    986988   */
    987989    function get_instances( $ignore_cache = false, $purpose = '' ){
    988990        if ( !$this->valid() || empty($this->link_id) ) return false;
    989        
     991
    990992        if ( $ignore_cache || is_null($this->_instances) ){
    991993            $instances = blc_get_instances( array($this->link_id), $purpose );
     
    994996            }
    995997        }
    996        
     998
    997999        return $this->_instances;
    9981000    }
    999    
     1001
    10001002    /**
    10011003     * Determine the status text and status code corresponding to the current state of this link.
    1002      * 
     1004     *
    10031005     * @return array Associative array with two keys, 'text' and 'code'.
    10041006     */
     
    10061008        $code = BLC_LINK_STATUS_UNKNOWN;
    10071009        $text = _x('Unknown', 'link status', 'broken-link-checker');
    1008        
     1010
    10091011        //Status text
    10101012        if ( isset($this->status_text) && !empty($this->status_text) && !empty($this->status_code) ){
    1011            
     1013
    10121014            //Lucky, the checker module has already set it for us.
    10131015            $text = $this->status_text;
    10141016            $code = $this->status_code;
    1015              
     1017
    10161018        } else {
    1017            
     1019
    10181020            if ( $this->broken || $this->warning ){
    10191021                $code = BLC_LINK_STATUS_WARNING;
    10201022                $text = __('Unknown Error', 'broken-link-checker');
    1021                
     1023
    10221024                if ( $this->timeout ){
    1023                    
     1025
    10241026                    $text = __('Timeout', 'broken-link-checker');
    10251027                    $code = BLC_LINK_STATUS_WARNING;
    1026                    
     1028
    10271029                } elseif ( $this->http_code ) {
    1028                    
     1030
    10291031                    //Only 404 (Not Found) and 410 (Gone) are treated as broken-for-sure.
    10301032                    if ( in_array($this->http_code, array(404, 410)) ){
     
    10331035                        $code = BLC_LINK_STATUS_WARNING;
    10341036                    }
    1035                    
     1037
    10361038                    if ( array_key_exists(intval($this->http_code), $this->http_status_codes) ){
    10371039                        $text = $this->http_status_codes[intval($this->http_code)];
    10381040                    }
    10391041                }
    1040                
     1042
    10411043            } else {
    1042                
     1044
    10431045                if ( !$this->last_check ) {
    10441046                    $text = __('Not checked', 'broken-link-checker');
     
    10511053                    $code = BLC_LINK_STATUS_OK;
    10521054                }
    1053                
    1054             }
    1055         }
    1056        
     1055
     1056            }
     1057        }
     1058
    10571059        return compact('text', 'code');
    10581060    }
    1059    
     1061
    10601062    /**
    10611063     * Get the link URL in ASCII-compatible encoding.
    1062      * 
     1064     *
    10631065     * @return string
    10641066     */
     
    11221124            WHERE
    11231125                {$wpdb->prefix}blc_instances.link_id IS NULL";
    1124                
     1126
    11251127    if ( $link_id !== null ) {
    11261128        if ( !is_array($link_id) ){
     
    11291131        $q .= " AND {$wpdb->prefix}blc_links.link_id IN (" . implode(', ', $link_id) . ')';
    11301132    }
    1131    
     1133
    11321134    $rez = $wpdb->query( $q );
    11331135    $elapsed = microtime(true) - $start;
    11341136    $blclog->log(sprintf('... %d links deleted in %.3f seconds', $wpdb->rows_affected, $elapsed));
    1135    
    1136     return $rez !== false; 
     1137
     1138    return $rez !== false;
    11371139}
    11381140
  • broken-link-checker/trunk/includes/transactions-manager.php

    r1383258 r2054130  
    1919    {
    2020        global $wpdb;
     21        global $blclog;
     22        $blclog->debug('Starting DB commit.');
    2123
    2224        $this->start();
     
    2426        try {
    2527            $wpdb->query('COMMIT');
     28            $blclog->debug('Commit executed.');
    2629            $this->isTransactionStarted = false;
    2730        } catch (Exception $e) {
    2831            $wpdb->query('ROLLBACK');
     32            $blclog->debug('Commit failed; rollback.');
    2933            $this->isTransactionStarted = false;
    3034        }
  • broken-link-checker/trunk/modules/checkers/http.php

    r1706472 r2054130  
    2424    /** @var  blcTokenBucketList */
    2525    private $token_bucket_list;
    26    
     26
    2727    function init(){
    2828        parent::init();
     
    3434            $conf->get('http_throttle_min_interval', 2)
    3535        );
    36        
     36
    3737        if ( function_exists('curl_init') || is_callable('curl_init') ) {
    3838            $this->implementation = new blcCurlHttp(
    39                 $this->module_id, 
     39                $this->module_id,
    4040                $this->cached_header,
    4141                $this->plugin_conf,
     
    5050                }
    5151            }
    52            
     52
    5353            //If Snoopy is available, it will be used in place of CURL.
    5454            if ( class_exists('Snoopy') ){
    5555                $this->implementation = new blcSnoopyHttp(
    56                     $this->module_id, 
     56                    $this->module_id,
    5757                    $this->cached_header,
    5858                    $this->plugin_conf,
     
    6262        }
    6363    }
    64    
     64
    6565    function can_check($url, $parsed){
    6666        if ( isset($this->implementation) ){
     
    7070        }
    7171    }
    72    
     72
    7373    function check($url, $use_get = false){
    7474        global $blclog;
     
    9393 */
    9494class blcHttpCheckerBase extends blcChecker {
    95    
     95
    9696    function clean_url($url){
    9797        $url = html_entity_decode($url);
     
    110110        );
    111111        $url = trim($url);
    112        
     112
    113113        return $url;
    114114    }
    115    
     115
    116116    function is_error_code($http_code){
    117117        /*"Good" response codes are anything in the 2XX range (e.g "200 OK") and redirects  - the 3XX range.
     
    121121        return !$good_code;
    122122    }
    123    
     123
    124124  /**
    125125   * This checker only accepts HTTP(s) links.
     
    131131    function can_check($url, $parsed){
    132132        if ( !isset($parsed['scheme']) ) return false;
    133        
     133
    134134        return in_array( strtolower($parsed['scheme']), array('http', 'https') );
    135135    }
    136    
     136
    137137  /**
    138138   * Takes an URL and replaces spaces and some other non-alphanumeric characters with their urlencoded equivalents.
     
    142142   */
    143143    function urlencodefix($url){
    144         //TODO: Remove/fix this. Probably not a good idea to "fix" invalid URLs like that. 
     144        //TODO: Remove/fix this. Probably not a good idea to "fix" invalid URLs like that.
    145145        return preg_replace_callback(
    146             '|[^a-z0-9\+\-\/\\#:.,;=?!&%@()$\|*~_]|i', 
    147             create_function('$str','return rawurlencode($str[0]);'),
     146            '|[^a-z0-9\+\-\/\\#:.,;=?!&%@()$\|*~_]|i',
     147            create_function('$str','return rawurlencode($str[0]);'),
    148148            $url
    149          );
    150     }
    151    
     149        );
     150    }
     151
    152152}
    153153
    154154class blcCurlHttp extends blcHttpCheckerBase {
    155    
     155
    156156    var $last_headers = '';
    157    
     157
    158158    function check($url, $use_get = false){
    159159        global $blclog;
     
    171171        );
    172172        $log = '';
    173        
     173
    174174        //Get the BLC configuration. It's used below to set the right timeout values and such.
    175175        $conf = blc_get_configuration();
    176        
     176
    177177        //Init curl.
    178178        $ch = curl_init();
     
    180180        curl_setopt($ch, CURLOPT_URL, $this->urlencodefix($url));
    181181        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    182        
    183         //Masquerade as Internet Explorer
    184         $ua = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';
    185         //$ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko';
     182
     183        //Masquerade as a recent version of Chrome
     184        $ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36';
    186185        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    187186
     
    191190        $request_headers[] = 'Connection: close';
    192191
    193         //Add a semi-plausible referer header to avoid tripping up some bot traps 
     192        //Add a semi-plausible referer header to avoid tripping up some bot traps
    194193        curl_setopt($ch, CURLOPT_REFERER, home_url());
    195        
     194
    196195        //Redirects don't work when safe mode or open_basedir is enabled.
    197196        if ( !blcUtility::is_safe_mode() && !blcUtility::is_open_basedir() ) {
     
    200199        //Set maximum redirects
    201200        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    202        
     201
    203202        //Set the timeout
    204203        curl_setopt($ch, CURLOPT_TIMEOUT, $conf->options['timeout']);
    205204        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $conf->options['timeout']);
    206        
    207         //Set the proxy configuration. The user can provide this in wp-config.php 
     205
     206        //Set the proxy configuration. The user can provide this in wp-config.php
    208207        if (defined('WP_PROXY_HOST')) {
    209208            curl_setopt($ch, CURLOPT_PROXY, WP_PROXY_HOST);
    210209        }
    211         if (defined('WP_PROXY_PORT')) { 
     210        if (defined('WP_PROXY_PORT')) {
    212211            curl_setopt($ch, CURLOPT_PROXYPORT, WP_PROXY_PORT);
    213212        }
     
    223222        curl_setopt($ch, CURLOPT_FAILONERROR, false);
    224223
    225        
     224
    226225        $nobody = !$use_get; //Whether to send a HEAD request (the default) or a GET request
    227        
     226
    228227        $parts = @parse_url($url);
    229228        if( $parts['scheme'] == 'https' ){
    230229            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Required to make HTTPS URLs work.
    231             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
     230            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    232231            //$nobody = false; //Can't use HEAD with HTTPS.
    233232        }
    234        
     233
    235234        if ( $nobody ){
    236235            //If possible, use HEAD requests for speed.
    237             curl_setopt($ch, CURLOPT_NOBODY, true); 
     236            curl_setopt($ch, CURLOPT_NOBODY, true);
    238237        } else {
    239238            //If we must use GET at least limit the amount of downloaded data.
     
    247246
    248247        //Register a callback function which will process the HTTP header(s).
    249         //It can be called multiple times if the remote server performs a redirect. 
     248        //It can be called multiple times if the remote server performs a redirect.
    250249        curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this,'read_header'));
    251250
     
    263262        $measured_request_duration = microtime_float() - $start_time;
    264263        $blclog->debug(sprintf('HTTP request took %.3f seconds', $measured_request_duration));
    265        
     264
    266265        $info = curl_getinfo($ch);
    267        
     266
    268267        //Store the results
    269268        $result['http_code'] = intval( $info['http_code'] );
     
    273272
    274273        //CURL doesn't return a request duration when a timeout happens, so we measure it ourselves.
    275         //It is useful to see how long the plugin waited for the server to respond before assuming it timed out.       
     274        //It is useful to see how long the plugin waited for the server to respond before assuming it timed out.
    276275        if( empty($result['request_duration']) ){
    277276            $result['request_duration'] = $measured_request_duration;
    278277        }
    279        
     278
    280279        //Determine if the link counts as "broken"
    281280        if ( $result['http_code'] == 0 ){
    282281            $result['broken'] = true;
    283            
     282
    284283            $error_code = curl_errno($ch);
    285284            $log .= sprintf( "%s [Error #%d]\n", curl_error($ch), $error_code );
    286            
     285
    287286            //We only handle a couple of CURL error codes; most are highly esoteric.
    288             //libcurl "CURLE_" constants can't be used here because some of them have 
     287            //libcurl "CURLE_" constants can't be used here because some of them have
    289288            //different names or values in PHP.
    290289            switch( $error_code ) {
     
    294293                    $result['error_code'] = 'couldnt_resolve_host';
    295294                    break;
    296                    
     295
    297296                case 28: //CURLE_OPERATION_TIMEDOUT
    298297                    $result['timeout'] = true;
    299298                    break;
    300                    
     299
    301300                case 7: //CURLE_COULDNT_CONNECT
    302                     //More often than not, this error code indicates that the connection attempt 
    303                     //timed out. This heuristic tries to distinguish between connections that fail 
     301                    //More often than not, this error code indicates that the connection attempt
     302                    //timed out. This heuristic tries to distinguish between connections that fail
    304303                    //due to timeouts and those that fail due to other causes.
    305304                    if ( $result['request_duration'] >= 0.9*$conf->options['timeout'] ){
     
    311310                    }
    312311                    break;
    313                    
     312
    314313                default:
    315314                    $result['status_code'] = BLC_LINK_STATUS_WARNING;
    316315                    $result['status_text'] = __('Unknown Error', 'broken-link-checker');
    317316            }
    318            
     317
    319318        } else {
    320319            $result['broken'] = $this->is_error_code($result['http_code']);
     
    333332            isset($result['status_text']) ? $result['status_text'] : 'N/A'
    334333        ));
    335        
    336         if ( $nobody && $result['broken'] ){
    337             //The site in question might be expecting GET instead of HEAD, so lets retry the request 
    338             //using the GET verb.
     334
     335        if ( $nobody && $result['broken'] && !$result['timeout'] && !$use_get){
     336            //The site in question might be expecting GET instead of HEAD, so lets retry the request
     337            //using the GET verb...but not in cases of timeout, or where we've already done it.
    339338            return $this->check($url, true);
    340              
     339
    341340            //Note : normally a server that doesn't allow HEAD requests on a specific resource *should*
    342341            //return "405 Method Not Allowed". Unfortunately, there are sites that return 404 or
    343             //another, even more general, error code instead. So just checking for 405 wouldn't be enough. 
    344         }
    345        
     342            //another, even more general, error code instead. So just checking for 405 wouldn't be enough.
     343        }
     344
    346345        //When safe_mode or open_basedir is enabled CURL will be forbidden from following redirects,
    347346        //so redirect_count will be 0 for all URLs. As a workaround, set it to 1 when the HTTP
     
    350349        if ( ($result['redirect_count'] == 0) && ( in_array( $result['http_code'], array(301, 302, 303, 307) ) ) ){
    351350            $result['redirect_count'] = 1;
    352         } 
    353        
     351        }
     352
    354353        //Build the log from HTTP code and headers.
    355354        $log .= '=== ';
     
    379378
    380379        $result['log'] = $log;
    381        
    382         //The hash should contain info about all pieces of data that pertain to determining if the 
    383         //link is working. 
     380
     381        //The hash should contain info about all pieces of data that pertain to determining if the
     382        //link is working.
    384383        $result['result_hash'] = implode('|', array(
    385384            $result['http_code'],
     
    388387            blcLink::remove_query_string($result['final_url']),
    389388        ));
    390        
     389
    391390        return $result;
    392391    }
    393    
     392
    394393    function read_header(/** @noinspection PhpUnusedParameterInspection */ $ch, $header){
    395394        $this->last_headers .= $header;
    396395        return strlen($header);
    397396    }
    398    
     397
    399398}
    400399
    401400class blcSnoopyHttp extends blcHttpCheckerBase {
    402    
     401
    403402    function check($url){
    404         $url = $this->clean_url($url); 
     403        $url = $this->clean_url($url);
    405404        //Note : Snoopy doesn't work too well with HTTPS URLs.
    406        
     405
    407406        $result = array(
    408407            'broken' => false,
     
    410409        );
    411410        $log = '';
    412        
    413         //Get the timeout setting from the BLC configuration. 
     411
     412        //Get the timeout setting from the BLC configuration.
    414413        $conf = blc_get_configuration();
    415414        $timeout = $conf->options['timeout'];
    416        
     415
    417416        $start_time = microtime_float();
    418        
     417
    419418        //Fetch the URL with Snoopy
    420419        $snoopy = new Snoopy;
     
    424423        $snoopy->maxlength = 1024*5; //load up to 5 kilobytes
    425424        $snoopy->fetch( $this->urlencodefix($url) );
    426        
     425
    427426        $result['request_duration'] = microtime_float() - $start_time;
    428427
    429428        $result['http_code'] = $snoopy->status; //HTTP status code
    430         //Snoopy returns -100 on timeout 
     429        //Snoopy returns -100 on timeout
    431430        if ( $result['http_code'] == -100 ){
    432431            $result['http_code'] = 0;
    433432            $result['timeout'] = true;
    434433        }
    435        
     434
    436435        //Build the log
    437436        $log .= '=== ';
     
    453452            $log .= implode("", $snoopy->headers)."\n"; //those headers already contain newlines
    454453
    455         //Redirected? 
     454        //Redirected?
    456455        if ( $snoopy->lastredirectaddr ) {
    457456            $result['final_url'] = $snoopy->lastredirectaddr;
     
    460459            $result['final_url'] = $url;
    461460        }
    462        
     461
    463462        //Determine if the link counts as "broken"
    464463        $result['broken'] = $this->is_error_code($result['http_code']) || $result['timeout'];
    465        
     464
    466465        $log .= "<em>(" . __('Using Snoopy', 'broken-link-checker') . ")</em>";
    467466        $result['log'] = $log;
    468        
    469         //The hash should contain info about all pieces of data that pertain to determining if the 
    470         //link is working. 
     467
     468        //The hash should contain info about all pieces of data that pertain to determining if the
     469        //link is working.
    471470        $result['result_hash'] = implode('|', array(
    472471            $result['http_code'],
    473             $result['broken']?'broken':'0', 
     472            $result['broken']?'broken':'0',
    474473            $result['timeout']?'timeout':'0',
    475474            blcLink::remove_query_string($result['final_url']),
    476475        ));
    477        
     476
    478477        return $result;
    479478    }
    480    
     479
    481480}
  • broken-link-checker/trunk/modules/containers/acf_field.php

    r1707025 r2054130  
    435435
    436436        //Intercept 2.9+ style metadata modification actions
    437         add_action("acf/save_post", array($this, 'acf_save'), 10, 4);
     437        add_action("acf/save_post", array($this, 'acf_save'), 20, 1);
    438438
    439439        //When a post is deleted, also delete the custom field container associated with it.
     
    654654        $selected_fields = array_keys($selected_fields);
    655655
    656         $keys = array();
    657         $fields = $_POST['acf'];
    658 
    659         $acfWalk = new blcAcfExtractedFieldWalker($keys, $selected_fields, $url_fields, $html_fields);
    660 
    661         array_walk_recursive($fields, array($acfWalk, 'walk_function'));
    662 
    663         if (empty($keys)) {
     656        $meta   = get_metadata( 'post', $post_id );
     657        $fields = array();
     658
     659        foreach ( $meta as $field => $value ) {
     660
     661            $value = explode( '|', str_replace( '_field', '|field', $value[0] ) );
     662
     663            if ( ! is_array( $value ) ) {
     664                continue;
     665            } else {
     666
     667                $value = $value[ count( $value ) - 1 ];
     668
     669                if ( in_array( $value, $url_fields ) ) {
     670                    $field = ltrim( $field, '_' );
     671                    if ( ! filter_var( $meta[ $field ][0], FILTER_VALIDATE_URL ) === false ) {
     672                        $fields[ $field ] = 'acf_field';
     673                    }
     674                }
     675
     676                if ( in_array( $value, $html_fields ) ) {
     677                    $field = ltrim( $field, '_' );
     678                    if ( $meta[ $field ][0] != '' ) {
     679                        $fields[ $field ] = 'html';
     680                    }
     681                }
     682
     683            }
     684        }
     685
     686        if (empty( $fields )) {
    664687            return;
    665688        }
    666689
    667         $container = blcContainerHelper::get_container(array($this->container_type, $post_id));
     690        $container = blcContainerHelper::get_container(array($this->container_type, intval($post_id)));
    668691        $container->mark_as_unsynched();
    669692
  • broken-link-checker/trunk/modules/parsers/html_link.php

    r1132662 r2054130  
    2828   */
    2929    function parse($content, $base_url = '', $default_link_text = ''){
     30        $content = apply_filters( 'blc-parser-html-link-content', $content );
     31
    3032        //remove all <code></code> blocks first
    3133        $content = preg_replace('/<code[^>]*>.+?<\/code>/si', ' ', $content);
  • broken-link-checker/trunk/readme.txt

    r1707025 r2054130  
    11=== Broken Link Checker ===
    2 Contributors: freediver
     2Contributors: managewp
    33Donate link:
    44Tags: links, broken, maintenance, blogroll, custom fields, admin, comments, posts
    55Requires at least: 3.2
    6 Tested up to: 4.8
    7 Stable tag: 1.11.5
     6Tested up to: 5.1
     7Stable tag: 1.11.8
    88
    99This plugin will check your posts, comments and other content for broken links and missing images, and notify you if any are found.
     
    4040You can also click on the contents of the "Status" or "Link Text" columns to get more info about the status of each link.
    4141
    42 **Translations**
    43 
    44 * Arabic - Yaser Maadan
    45 * Belorussian - [M. Comfi](http://www.comfi.com/)
    46 * Chinese Simplified - Kaijia Feng
    47 * Chinese Traditional - [YILIN](http://sh2153.com)
    48 * Czech - [Lelkoun](http://lelkoun.cz/)
    49 * Danish - [Georg S. Adamsen](http://wordpress.blogos.dk/)
    50 * Dutch - [Robin Roelofsen](http://www.dreamdesignsolutions.nl/)
    51 * Finnish - [Jani Alha](http://www.wysiwyg.fi)
    52 * French - [Whiler](http://blogs.wittwer.fr/whiler/), Luc Capronnier, [Guillaume Boda](http://www.michtoblog.com/)
    53 * German - [Ivan Graf](http://blog.bildergallery.com/)
    54 * Hebrew - [Ahrale](http://atar4u.com/), [Eitan Caspi](http://caspi.org.il/)
    55 * Hindi - [Outshine Solutions](http://outshinesolutions.com/)
    56 * Hungarian - [Language Connect](http://www.languageconnect.net/)
    57 * Irish - [Ray Gren](http://letsbefamous.com/)
    58 * Italian - [Gianni Diurno](http://gidibao.net/index.php/portfolio/) and [Giacomo Ross](http://www.luxemozione.com/) (alternative)
    59 * Japanese - [Shohei Tanak](http://artisanworkshop.biz/)
    60 * Korean - [MinHyeong Lim](http://ssamture.net/)
    61 * Persian - [Omid Sheerkavand](http://qanal.ir/)
    62 * Polish - [http://positionmaker.pl](http://positionmaker.pl/)
    63 * Portuguese - [mowster](http://wordpress.mowster.net/)
    64 * Brazilian Portuguese - [Paulino Michelazzo](http://www.michelazzo.com.br/)
    65 * Romanian - [Ovidiu](http://www.jibo.ro)
    66 * Russian - [Anna Ozeritskaya](http://hweia.ru/)
    67 * Serbo-Croatian - [Borisa Djuraskovic](http://www.webhostinghub.com)
    68 * Slovakian - [Patrik Žec](http://patwist.com/)
    69 * Spanish - [Neoshinji](http://blog.tuayudainformatica.com/traducciones-de-plugins-wordpress/)
    70 * Swedish - mepmepmep
    71 * Turkish - [Murat Durgun](http://www.lanwifi.net/)
    72 * Ukrainian - [Stas Mykhajlyuk](http://www.kosivart.com/)
    73 * Vietnamese - [Biz.O](http://bizover.net/)
    74 
    75 *Note: Some translations are not entirely up to date with the latest release, so parts of the interface may appear untranslated.*
    76 
    7742**Other Credits**
    7843
     
    10166
    10267== Changelog ==
     68
     69= 1.11.7 =
     70* Fixed a PHP 7.2 compatibility issue
     71
     72= 1.11.6 =
     73* Fixed link check not saving
    10374
    10475= 1.11.5 =
Note: See TracChangeset for help on using the changeset viewer.