Changeset 2054130
- Timestamp:
- 03/20/2019 05:13:01 PM (7 years ago)
- Location:
- broken-link-checker
- Files:
-
- 98 added
- 61 deleted
- 9 edited
-
tags/1.11.8 (added)
-
tags/1.11.8/broken-link-checker.php (added)
-
tags/1.11.8/core (added)
-
tags/1.11.8/core/core.php (added)
-
tags/1.11.8/core/init.php (added)
-
tags/1.11.8/css (added)
-
tags/1.11.8/css/links-page.css (added)
-
tags/1.11.8/css/options-page.css (added)
-
tags/1.11.8/idn (added)
-
tags/1.11.8/idn/LICENCE (added)
-
tags/1.11.8/idn/ReadMe.txt (added)
-
tags/1.11.8/idn/idna_convert.class.php (added)
-
tags/1.11.8/idn/transcode_wrapper.php (added)
-
tags/1.11.8/idn/uctc.php (added)
-
tags/1.11.8/images (added)
-
tags/1.11.8/images/blue_dot.png (added)
-
tags/1.11.8/images/dailymotion-embed.png (added)
-
tags/1.11.8/images/font-awesome (added)
-
tags/1.11.8/images/font-awesome/font-awesome-code.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-comment-alt.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-exclamation-sign.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-link.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-picture.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-user.png (added)
-
tags/1.11.8/images/font-awesome/font-awesome-warning-sign.png (added)
-
tags/1.11.8/images/font-awesome/readme.txt (added)
-
tags/1.11.8/images/googlevideo-embed.png (added)
-
tags/1.11.8/images/mwp250_2.png (added)
-
tags/1.11.8/images/red_highlight.png (added)
-
tags/1.11.8/images/vimeo-embed.png (added)
-
tags/1.11.8/images/youtube-embed.png (added)
-
tags/1.11.8/images/youtube-iframe.png (added)
-
tags/1.11.8/images/youtube-playlist-embed.png (added)
-
tags/1.11.8/includes (added)
-
tags/1.11.8/includes/activation.php (added)
-
tags/1.11.8/includes/admin (added)
-
tags/1.11.8/includes/admin/db-schema.php (added)
-
tags/1.11.8/includes/admin/db-upgrade.php (added)
-
tags/1.11.8/includes/admin/links-page-js.php (added)
-
tags/1.11.8/includes/admin/options-page-js.php (added)
-
tags/1.11.8/includes/admin/search-form.php (added)
-
tags/1.11.8/includes/admin/sidebar.php (added)
-
tags/1.11.8/includes/admin/table-printer.php (added)
-
tags/1.11.8/includes/any-post.php (added)
-
tags/1.11.8/includes/checkers.php (added)
-
tags/1.11.8/includes/config-manager.php (added)
-
tags/1.11.8/includes/containers.php (added)
-
tags/1.11.8/includes/extra-strings.php (added)
-
tags/1.11.8/includes/instances.php (added)
-
tags/1.11.8/includes/link-query.php (added)
-
tags/1.11.8/includes/links.php (added)
-
tags/1.11.8/includes/logger.php (added)
-
tags/1.11.8/includes/module-base.php (added)
-
tags/1.11.8/includes/module-manager.php (added)
-
tags/1.11.8/includes/modules.php (added)
-
tags/1.11.8/includes/parsers.php (added)
-
tags/1.11.8/includes/screen-meta-links.php (added)
-
tags/1.11.8/includes/screen-options (added)
-
tags/1.11.8/includes/screen-options/screen-options.js (added)
-
tags/1.11.8/includes/screen-options/screen-options.php (added)
-
tags/1.11.8/includes/token-bucket.php (added)
-
tags/1.11.8/includes/transactions-manager.php (added)
-
tags/1.11.8/includes/utility-class.php (added)
-
tags/1.11.8/includes/wp-mutex.php (added)
-
tags/1.11.8/js (added)
-
tags/1.11.8/js/jquery.cookie.js (added)
-
tags/1.11.8/js/sprintf.js (added)
-
tags/1.11.8/modules (added)
-
tags/1.11.8/modules/checkers (added)
-
tags/1.11.8/modules/checkers/http.php (added)
-
tags/1.11.8/modules/containers (added)
-
tags/1.11.8/modules/containers/acf_field.php (added)
-
tags/1.11.8/modules/containers/blogroll.php (added)
-
tags/1.11.8/modules/containers/comment.php (added)
-
tags/1.11.8/modules/containers/custom_field.php (added)
-
tags/1.11.8/modules/containers/dummy.php (added)
-
tags/1.11.8/modules/extras (added)
-
tags/1.11.8/modules/extras/dailymotion-embed.php (added)
-
tags/1.11.8/modules/extras/embed-parser-base.php (added)
-
tags/1.11.8/modules/extras/googlevideo-embed.php (added)
-
tags/1.11.8/modules/extras/mediafire.php (added)
-
tags/1.11.8/modules/extras/plaintext-url-parser-base.php (added)
-
tags/1.11.8/modules/extras/plaintext-url.php (added)
-
tags/1.11.8/modules/extras/rapidshare.php (added)
-
tags/1.11.8/modules/extras/smart-youtube-embed.php (added)
-
tags/1.11.8/modules/extras/vimeo-embed.php (added)
-
tags/1.11.8/modules/extras/youtube-embed.php (added)
-
tags/1.11.8/modules/extras/youtube-iframe.php (added)
-
tags/1.11.8/modules/extras/youtube-playlist-embed.php (added)
-
tags/1.11.8/modules/extras/youtube.php (added)
-
tags/1.11.8/modules/parsers (added)
-
tags/1.11.8/modules/parsers/acf_field.php (added)
-
tags/1.11.8/modules/parsers/html_link.php (added)
-
tags/1.11.8/modules/parsers/image.php (added)
-
tags/1.11.8/modules/parsers/metadata.php (added)
-
tags/1.11.8/modules/parsers/url_field.php (added)
-
tags/1.11.8/readme.txt (added)
-
tags/1.11.8/uninstall.php (added)
-
trunk/broken-link-checker.php (modified) (1 diff)
-
trunk/core/core.php (modified) (14 diffs)
-
trunk/includes/any-post.php (modified) (1 diff)
-
trunk/includes/links.php (modified) (61 diffs)
-
trunk/includes/transactions-manager.php (modified) (2 diffs)
-
trunk/languages/alternative.broken-link-checker-it_IT.mo (deleted)
-
trunk/languages/alternative.broken-link-checker-it_IT.po (deleted)
-
trunk/languages/broken-link-checker-ar_AR.mo (deleted)
-
trunk/languages/broken-link-checker-ar_AR.po (deleted)
-
trunk/languages/broken-link-checker-be_BY.mo (deleted)
-
trunk/languages/broken-link-checker-be_BY.po (deleted)
-
trunk/languages/broken-link-checker-cs_CZ.mo (deleted)
-
trunk/languages/broken-link-checker-cs_CZ.po (deleted)
-
trunk/languages/broken-link-checker-da_DK.mo (deleted)
-
trunk/languages/broken-link-checker-da_DK.po (deleted)
-
trunk/languages/broken-link-checker-de_DE.mo (deleted)
-
trunk/languages/broken-link-checker-de_DE.po (deleted)
-
trunk/languages/broken-link-checker-es_ES.mo (deleted)
-
trunk/languages/broken-link-checker-es_ES.po (deleted)
-
trunk/languages/broken-link-checker-fa_IR.mo (deleted)
-
trunk/languages/broken-link-checker-fa_IR.po (deleted)
-
trunk/languages/broken-link-checker-fi.mo (deleted)
-
trunk/languages/broken-link-checker-fi.po (deleted)
-
trunk/languages/broken-link-checker-fr_FR.mo (deleted)
-
trunk/languages/broken-link-checker-fr_FR.po (deleted)
-
trunk/languages/broken-link-checker-ga_IR.mo (deleted)
-
trunk/languages/broken-link-checker-ga_IR.po (deleted)
-
trunk/languages/broken-link-checker-he_IL.mo (deleted)
-
trunk/languages/broken-link-checker-he_IL.po (deleted)
-
trunk/languages/broken-link-checker-hi_IN.mo (deleted)
-
trunk/languages/broken-link-checker-hi_IN.po (deleted)
-
trunk/languages/broken-link-checker-hu_HU.mo (deleted)
-
trunk/languages/broken-link-checker-hu_HU.po (deleted)
-
trunk/languages/broken-link-checker-it_IT.mo (deleted)
-
trunk/languages/broken-link-checker-it_IT.po (deleted)
-
trunk/languages/broken-link-checker-ja.mo (deleted)
-
trunk/languages/broken-link-checker-ja.po (deleted)
-
trunk/languages/broken-link-checker-ko_KR.mo (deleted)
-
trunk/languages/broken-link-checker-ko_KR.po (deleted)
-
trunk/languages/broken-link-checker-nl_NL.mo (deleted)
-
trunk/languages/broken-link-checker-nl_NL.po (deleted)
-
trunk/languages/broken-link-checker-pl_PL.mo (deleted)
-
trunk/languages/broken-link-checker-pl_PL.po (deleted)
-
trunk/languages/broken-link-checker-pt_BR.mo (deleted)
-
trunk/languages/broken-link-checker-pt_BR.po (deleted)
-
trunk/languages/broken-link-checker-pt_PT.mo (deleted)
-
trunk/languages/broken-link-checker-pt_PT.po (deleted)
-
trunk/languages/broken-link-checker-ro_RO.mo (deleted)
-
trunk/languages/broken-link-checker-ro_RO.po (deleted)
-
trunk/languages/broken-link-checker-ru_RU.mo (deleted)
-
trunk/languages/broken-link-checker-ru_RU.po (deleted)
-
trunk/languages/broken-link-checker-sk_SK.mo (deleted)
-
trunk/languages/broken-link-checker-sk_SK.po (deleted)
-
trunk/languages/broken-link-checker-sr_RS.mo (deleted)
-
trunk/languages/broken-link-checker-sr_RS.po (deleted)
-
trunk/languages/broken-link-checker-sv_SE.mo (deleted)
-
trunk/languages/broken-link-checker-sv_SE.po (deleted)
-
trunk/languages/broken-link-checker-tr_TR.mo (deleted)
-
trunk/languages/broken-link-checker-tr_TR.po (deleted)
-
trunk/languages/broken-link-checker-uk_UK.mo (deleted)
-
trunk/languages/broken-link-checker-vi.mo (deleted)
-
trunk/languages/broken-link-checker-vi.po (deleted)
-
trunk/languages/broken-link-checker-zh_CN.po (deleted)
-
trunk/languages/broken-link-checker-zh_TW.mo (deleted)
-
trunk/languages/broken-link-checker-zh_TW.po (deleted)
-
trunk/languages/broken-link-checker.pot (deleted)
-
trunk/modules/checkers/http.php (modified) (28 diffs)
-
trunk/modules/containers/acf_field.php (modified) (2 diffs)
-
trunk/modules/parsers/html_link.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
broken-link-checker/trunk/broken-link-checker.php
r1707025 r2054130 4 4 Plugin URI: https://wordpress.org/plugins/broken-link-checker/ 5 5 Description: 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 6 Version: 1.11.8 7 Author: ManageWP 8 Author URI: https://managewp.com 8 9 Text Domain: broken-link-checker 9 10 */ -
broken-link-checker/trunk/core/core.php
r1707025 r2054130 74 74 75 75 //Add/remove Cron events 76 add_filter( 'cron_schedules', array( $this, 'cron_add_every_10_minutes' ) ); 76 77 $this->setup_cron_events(); 77 78 … … 96 97 add_action( 'admin_notices', array( $this, 'show_warnings_section_notice' ) ); 97 98 98 add_filter('cron_schedules', array( $this, 'cron_add_every_10_minutes'));99 99 100 100 } … … 471 471 472 472 //Parse the custom field list 473 $new_custom_fields = array_filter( 473 $new_custom_fields = array_filter( 474 474 preg_split( '/[\r\n]+/', $cleanPost['blc_custom_fields'], -1, PREG_SPLIT_NO_EMPTY ) 475 475 ); 476 476 477 477 //Calculate the difference between the old custom field list and the new one (used later) 478 478 $diff1 = array_diff( $new_custom_fields, $this->conf->options['custom_fields'] ); … … 1414 1414 */ 1415 1415 function make_custom_field_input($html, $current_settings){ 1416 $html .= '<span class="description">' . 1416 $html .= '<span class="description">' . 1417 1417 __( 1418 1418 '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>.', … … 2120 2120 2121 2121 if ( count($selected_links) > 0 ){ 2122 $transactionManager = TransactionManager::getInstance(); 2123 $transactionManager->start(); 2122 2124 foreach($selected_links as $link_id){ 2123 2125 //Load the link … … 2156 2158 2157 2159 if ( $processed_links > 0 ){ 2160 $transactionManager->commit(); 2158 2161 $messages[] = sprintf( 2159 2162 _n( … … 2184 2187 2185 2188 if ( count($selected_links) > 0 ){ 2189 $transactionManager = TransactionManager::getInstance(); 2190 $transactionManager->start(); 2186 2191 foreach($selected_links as $link_id){ 2187 2192 //Load the link … … 2215 2220 2216 2221 if ( $processed_links > 0 ){ 2222 $transactionManager->commit(); 2217 2223 $messages[] = sprintf( 2218 2224 _n( … … 2629 2635 //Check if we still have some execution time left 2630 2636 if( $this->execution_time() > $max_execution_time ){ 2637 $transactionManager->commit(); 2631 2638 //FB::log('The allotted execution time has run out'); 2632 2639 $blclog->info('The allotted execution time has run out.'); … … 2637 2644 //Check if the server isn't overloaded 2638 2645 if ( $this->server_too_busy() ){ 2646 $transactionManager->commit(); 2639 2647 //FB::log('Server overloaded, bailing out.'); 2640 2648 $blclog->info('Server load too high, stopping.'); … … 2962 2970 2963 2971 $link->isOptionLinkChanged = true; 2972 2973 $transactionManager = TransactionManager::getInstance(); 2974 $transactionManager->start(); 2975 2964 2976 //Save the changes 2965 2977 if ( $link->save() ){ 2978 $transactionManager->commit(); 2966 2979 die( "OK" ); 2967 2980 } else { … … 3001 3014 //Save the changes 3002 3015 $link->isOptionLinkChanged = true; 3016 $transactionManager = TransactionManager::getInstance(); 3017 $transactionManager->start(); 3003 3018 if ( $link->save() ){ 3019 $transactionManager->commit(); 3004 3020 die( "OK" ); 3005 3021 } else { … … 3245 3261 } 3246 3262 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. 3248 3267 $link->last_check_attempt = 0; 3249 3268 $link->isOptionLinkChanged = true; … … 3252 3271 //Check the link and save the results. 3253 3272 $link->check(true); 3273 3274 $transactionManager->commit(); 3254 3275 3255 3276 $status = $link->analyse_status(); -
broken-link-checker/trunk/includes/any-post.php
r1139206 r2054130 111 111 } 112 112 113 /**114 * Remove the synch. record and link instances associated with a post when it's deleted115 *116 * @param int $post_id117 * @return void118 */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 */ 119 119 function post_deleted($post_id){ 120 global $wpdb; 121 122 $post_id = intval( $post_id ); 120 123 //Get the container type matching the type of the deleted post 121 $post = get_post( $post_id);124 $post = get_post( $post_id ); 122 125 if ( !$post ){ 123 126 return; 124 127 } 125 128 //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 ) ); 127 131 128 132 if ( $post_container ){ 129 //Delete it133 //Delete the container 130 134 $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 131 161 //Clean up any dangling links 132 blc_cleanup_links( );162 blc_cleanup_links( $current_link_ids ); 133 163 } 134 164 } -
broken-link-checker/trunk/includes/links.php
r1381903 r2054130 2 2 3 3 /** 4 * @author W-Shadow 4 * @author W-Shadow 5 5 * @copyright 2010 6 6 */ 7 7 8 8 if (!class_exists('blcLink')){ 9 9 10 10 define('BLC_LINK_STATUS_UNKNOWN', 'unknown'); 11 11 define('BLC_LINK_STATUS_OK', 'ok'); … … 13 13 define('BLC_LINK_STATUS_WARNING', 'warning'); 14 14 define('BLC_LINK_STATUS_ERROR', 'error'); 15 15 16 16 class blcLink { 17 17 18 18 //Object state 19 19 var $is_new = false; 20 20 21 21 //DB fields 22 22 var $link_id = 0; 23 23 var $url = ''; 24 24 25 25 var $being_checked = false; 26 26 var $last_check = 0; … … 30 30 var $request_duration = 0; 31 31 var $timeout = false; 32 32 33 33 var $redirect_count = 0; 34 34 var $final_url = ''; 35 35 36 36 var $broken = false; 37 37 public $warning = false; 38 38 var $first_failure = 0; 39 39 var $last_success = 0; 40 var $may_recheck = 1; 41 40 var $may_recheck = 1; 41 42 42 var $false_positive = false; 43 43 var $result_hash = ''; 44 44 45 45 var $dismissed = false; 46 46 47 47 var $status_text = ''; 48 48 var $status_code = ''; 49 49 50 50 var $log = ''; 51 51 52 52 //A list of DB fields and their storage formats 53 53 var $field_format; 54 54 55 55 //A cached list of the link's instances 56 56 var $_instances = null; 57 57 58 58 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', 104 104 505=>'HTTP Version Not Supported', 105 105 509=>'Bandwidth Limit Exceeded', … … 109 109 function __construct($arg = null){ 110 110 global $wpdb, $blclog; /** @var wpdb $wpdb */ 111 111 112 112 $this->field_format = array( 113 113 'url' => '%s', … … 133 133 'dismissed' => 'bool', 134 134 ); 135 135 136 136 if (is_numeric($arg)){ 137 137 //Load a link with ID = $arg from the DB. 138 138 $q = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}blc_links WHERE link_id=%d LIMIT 1", $arg); 139 139 $arr = $wpdb->get_row( $q, ARRAY_A ); 140 140 141 141 if ( is_array($arr) ){ //Loaded successfully 142 142 $this->set_values($arr); … … 145 145 //I'd throw an error, but that wouldn't be PHP 4 compatible... 146 146 $blclog->warn(__CLASS__ .':' . __FUNCTION__ . ' Link not found.', $arg); 147 } 148 147 } 148 149 149 } else if (is_string($arg)){ 150 150 //Load a link with URL = $arg from the DB. Create a new one if the record isn't found. … … 152 152 $q = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}blc_links WHERE url=%s LIMIT 1", $arg); 153 153 $arr = $wpdb->get_row( $q, ARRAY_A ); 154 154 155 155 if ( is_array($arr) ){ //Loaded successfully 156 156 // $blclog->debug(__CLASS__ .':' . __FUNCTION__ . ' Success!'); … … 160 160 $this->url = $arg; 161 161 $this->is_new = true; 162 } 163 162 } 163 164 164 } else if (is_array($arg)){ 165 165 $this->set_values($arg); … … 170 170 } 171 171 } 172 172 173 173 function blcLink($arg = null){ 174 174 $this->__construct($arg); 175 175 } 176 176 177 177 /** 178 178 * blcLink::set_values() … … 184 184 function set_values($arr){ 185 185 $arr = $this->to_native_format($arr); 186 186 187 187 foreach( $arr as $key => $value ){ 188 188 $this->$key = $value; 189 189 } 190 190 } 191 191 192 192 /** 193 193 * Check whether the object represents a valid link … … 198 198 return !empty( $this->url ) && ( !empty($this->link_id) || $this->is_new ); 199 199 } 200 200 201 201 /** 202 202 * Check if the link is working. 203 203 * 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 206 206 */ 207 207 function check( $save_results = true ){ 208 208 if ( !$this->valid() ) return false; 209 209 210 210 $this->last_check_attempt = time(); 211 211 212 212 /* 213 213 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 215 215 running over the execution time limit or causing a fatal error. 216 216 217 217 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). 219 219 */ 220 220 if ( $this->being_checked ) { 221 221 $this->being_checked = false; 222 222 223 223 //Add an explanatory notice to the link's log 224 224 $error_notice = "[" . __("The plugin script was terminated while trying to check the link.", 'broken-link-checker') . "]"; … … 226 226 $this->log = $error_notice . "\r\n" . $this->log; 227 227 } 228 228 229 229 if ( $save_results ){ 230 230 $this->save(); 231 231 } 232 232 233 233 return false; 234 234 } 235 235 236 236 $this->being_checked = true; 237 237 $this->check_count++; 238 238 239 239 if ( $save_results ) { 240 240 241 241 //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 243 243 //(e.g. the server might kill the script for running over the exec. time limit). 244 244 //Note : might be unnecessary. 245 245 $this->save(); 246 246 } 247 247 248 248 $defaults = array( 249 249 'broken' => false, … … 260 260 'status_code' => '', 261 261 ); 262 263 262 263 264 264 $checker = blcCheckerHelper::get_checker_for($this->get_ascii_url()); 265 265 266 266 if ( is_null($checker) ){ 267 267 //Oops, there are no checker implementations that can handle this link. … … 270 270 $this->being_checked = false; 271 271 $this->log = __("The plugin doesn't know how to check this type of link.", 'broken-link-checker'); 272 272 273 273 if ( $save_results ){ 274 274 $this->save(); 275 275 } 276 276 277 277 return true; 278 278 } 279 279 280 280 //Check the link 281 281 $rez = $checker->check($this->get_ascii_url()); … … 296 296 //Update the object's fields with the new results 297 297 $this->set_values($results); 298 298 299 299 //Update timestamps & state-dependent fields 300 300 $this->status_changed($results['broken'], $new_result_hash); 301 301 $this->being_checked = false; 302 303 //Save results to the DB 302 303 //Save results to the DB 304 304 if($save_results){ 305 305 $this->save(); 306 306 } 307 307 308 308 return $this->broken; 309 309 } … … 439 439 return $check_results; 440 440 } 441 441 442 442 /** 443 * A helper method used to update timestamps & other state-dependent fields 443 * A helper method used to update timestamps & other state-dependent fields 444 444 * after the state of the link (broken vs working) has just been determined. 445 445 * … … 462 462 $this->dismissed = false; 463 463 } 464 464 465 465 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 468 468 //the one that caused the user to mark it as a false positive. 469 469 if ( $broken || $this->warning ){ … … 477 477 } 478 478 } else { 479 //The plugin now thinks the link is working, 479 //The plugin now thinks the link is working, 480 480 //so it's no longer a false positive. 481 481 $this->false_positive = false; 482 482 } 483 483 } 484 484 485 485 $this->broken = $broken; 486 486 $this->result_hash = $new_result_hash; 487 487 488 488 //Update timestamps 489 489 $this->last_check = $this->last_check_attempt; … … 497 497 $this->check_count = 0; 498 498 } 499 499 500 500 //Add a line indicating link status to the log 501 501 if ( $this->broken || $this->warning ) { … … 505 505 } 506 506 } 507 507 508 508 /** 509 509 * blcLink::save() … … 521 521 $this->warning = false; 522 522 } 523 523 524 524 //Make a list of fields to be saved and their values in DB format 525 525 $values = array(); … … 528 528 } 529 529 $values = $this->to_db_format($values); 530 530 531 531 if ( $this->is_new ){ 532 533 TransactionManager::getInstance()->commit();534 532 535 533 //BUG: Technically, there should be a 'LOCK TABLES wp_blc_links WRITE' here. In fact, 536 534 //the plugin should probably lock all involved tables whenever it parses something, lest 537 535 //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 539 537 //all of WP freeze while the plugin is working would be a Bad Thing. Food for thought. 540 538 541 539 //Check if there's already a link with this URL present 542 540 $q = $wpdb->prepare( … … 545 543 ); 546 544 $existing_id = $wpdb->get_var($q); 547 545 548 546 if ( !empty($existing_id) ){ 549 547 //Dammit. … … 551 549 $this->is_new = false; 552 550 return true; 553 } 554 551 } 552 555 553 //Insert a new row 556 554 $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)), 559 557 implode(', ', array_values($values)) 560 558 ); … … 563 561 564 562 $rez = $wpdb->query($q) !== false; 565 563 566 564 if ($rez){ 567 565 $this->link_id = $wpdb->insert_id; … … 574 572 //FB::error($wpdb->last_error, "Error adding link {$this->url}"); 575 573 } 576 574 575 TransactionManager::getInstance()->commit(); 576 577 577 return $rez; 578 578 579 579 } else { 580 580 if ($this->isOptionLinkChanged !== true ) { … … 582 582 } 583 583 $this->isOptionLinkChanged = false; 584 //Generate the field = dbvalue expressions 584 //Generate the field = dbvalue expressions 585 585 $set_exprs = array(); 586 586 foreach($values as $name => $value){ … … 588 588 } 589 589 $set_exprs = implode(', ', $set_exprs); 590 590 591 591 //Update an existing DB record 592 592 $q = sprintf( … … 597 597 //FB::log($q, 'Link update query'); 598 598 $blclog->debug(__CLASS__ .':' . __FUNCTION__ . ' Updating a link. SQL query:'. "\n", $q); 599 599 600 600 $rez = $wpdb->query($q) !== false; 601 601 if ( $rez ){ … … 606 606 //FB::error($wpdb->last_error, "Error updating link {$this->url}"); 607 607 } 608 609 return $rez; 610 } 611 } 612 608 609 TransactionManager::getInstance()->commit(); 610 611 return $rez; 612 } 613 } 614 613 615 /** 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. 616 618 * 617 619 * @param array $values … … 620 622 function to_db_format($values){ 621 623 global $wpdb; /** @var wpdb $wpdb */ 622 624 623 625 $dbvalues = array(); 624 626 625 627 foreach($values as $name => $value){ 626 628 //Skip fields that don't exist in the blc_links table. … … 628 630 continue; 629 631 } 630 632 631 633 $format = $this->field_format[$name]; 632 634 633 635 //Convert native values to a format comprehensible to the DB 634 636 switch($format){ 635 637 636 638 case 'datetime' : 637 639 if ( empty($value) ){ … … 642 644 $format = '%s'; 643 645 break; 644 646 645 647 case 'bool': 646 648 if ( $value ){ … … 652 654 break; 653 655 } 654 656 655 657 //Escapize 656 658 $value = $wpdb->prepare($format, $value); 657 659 658 660 $dbvalues[$name] = $value; 659 661 } 660 661 return $dbvalues; 662 } 663 662 663 return $dbvalues; 664 } 665 664 666 /** 665 667 * A helper method for converting values fetched from the database to native datatypes. … … 669 671 */ 670 672 function to_native_format($values){ 671 673 672 674 foreach($values as $name => $value){ 673 675 //Don't process fields that don't exist in the blc_links table. … … 675 677 continue; 676 678 } 677 679 678 680 $format = $this->field_format[$name]; 679 681 680 682 //Convert values in DB format to native datatypes. 681 683 switch($format){ 682 684 683 685 case 'datetime' : 684 686 if ( $value == '0000-00-00 00:00:00' ){ … … 688 690 } 689 691 break; 690 692 691 693 case 'bool': 692 694 $value = (bool)$value; 693 695 break; 694 696 695 697 case '%d': 696 698 $value = intval($value); 697 699 break; 698 700 699 701 case '%f': 700 702 $value = floatval($value); 701 703 break; 702 703 } 704 704 705 } 706 705 707 $values[$name] = $value; 706 708 } 707 709 708 710 return $values; 709 711 } 710 712 711 713 /** 712 714 * blcLink::edit() … … 714 716 * 715 717 * 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 717 719 * 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. 719 721 * 720 722 * @param string $new_url 721 723 * @param string $new_text Optional. 722 * @return array An associative array with these keys : 724 * @return array An associative array with these keys : 723 725 * new_link_id - the database ID of the new link. 724 726 * 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. 726 728 * 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. 728 730 */ 729 731 function edit($new_url, $new_text = null){ … … 734 736 ); 735 737 } 736 738 737 739 //FB::info('Changing link '.$this->link_id .' to URL "'.$new_url.'"'); 738 740 739 741 $instances = $this->get_instances(); 740 742 //Fail if there are no instances … … 753 755 ); 754 756 }; 755 756 //Load or create a link with the URL = $new_url 757 758 //Load or create a link with the URL = $new_url 757 759 $new_link = new blcLink($new_url); 758 760 $was_new = $new_link->is_new; … … 761 763 $new_link->save(); //so that we get a valid link_id 762 764 } 763 765 764 766 //FB::log("Changing link to $new_url"); 765 767 766 768 if ( empty($new_link->link_id) ){ 767 769 //FB::error("Failed to create a new link record"); … … 779 781 ); 780 782 } 781 783 782 784 $cnt_okay = $cnt_error = 0; 783 785 $errors = array(); 784 786 785 787 //Edit each instance. 786 788 //FB::info('Editing ' . count($instances) . ' instances'); … … 798 800 } 799 801 } 800 802 801 803 //If all instances were edited successfully we can delete the old link record. 802 804 //UNLESS this link is equal to the new link (which should never happen, but whatever). … … 804 806 $this->forget( false ); 805 807 } 806 808 807 809 //On the other hand, if no instances could be edited and the $new_link was really new, 808 810 //then delete it. … … 811 813 $new_link = $this; 812 814 } 813 815 814 816 return array( 815 817 'new_link_id' => $new_link->link_id, 816 818 'new_link' => $new_link, 817 819 'cnt_okay' => $cnt_okay, 818 'cnt_error' => $cnt_error, 820 'cnt_error' => $cnt_error, 819 821 'errors' => $errors, 820 ); 821 } 822 822 ); 823 } 824 823 825 /** 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. 825 827 * This method does nothing if the link isn't a redirect. 826 828 * 827 * @see blcLink::edit() 828 * 829 * @return array|WP_Error 830 */ 829 * @see blcLink::edit() 830 * 831 * @return array|WP_Error 832 */ 831 833 function deredirect(){ 832 834 if ( !$this->valid() ){ … … 836 838 ); 837 839 } 838 840 839 841 if ( ($this->redirect_count <= 0) || empty($this->final_url) ){ 840 842 return new WP_Error( … … 850 852 $new_url .= '#' . $anchor; 851 853 } 852 854 853 855 return $this->edit($new_url); 854 856 } … … 857 859 * Unlink all instances and delete the link record. 858 860 * 859 * @return array|WP_Error An associative array with these keys : 861 * @return array|WP_Error An associative array with these keys : 860 862 * cnt_okay - the number of successfully removed instances. 861 863 * cnt_error - the number of instances that couldn't be removed. … … 870 872 ); 871 873 } 872 874 873 875 //FB::info($this, 'Removing link'); 874 876 $instances = $this->get_instances(); 875 877 876 878 //No instances? Just remove the link then. 877 879 if (empty($instances)) { 878 880 //FB::warn("This link has no instances. Deleting the link."); 879 881 $rez = $this->forget( false ) !== false; 880 882 881 883 if ( $rez ){ 882 884 return array( … … 884 886 'cnt_error' => 0, 885 887 'link_deleted' => true, 886 'errors' => array(), 888 'errors' => array(), 887 889 ); 888 890 } else { … … 896 898 __("Couldn't delete the link's database record", 'broken-link-checker') 897 899 ) 898 ), 900 ), 899 901 ); 900 902 } 901 903 } 902 903 904 905 904 906 //FB::info('Unlinking ' . count($instances) . ' instances'); 905 907 906 908 $cnt_okay = $cnt_error = 0; 907 909 $errors = array(); 908 910 909 911 //Unlink each instance. 910 912 foreach ( $instances as $instance ){ 911 $rez = $instance->unlink( $this->url ); 912 913 $rez = $instance->unlink( $this->url ); 914 913 915 if ( is_wp_error($rez) ){ 914 916 $cnt_error++; … … 920 922 } 921 923 } 922 924 923 925 //If all instances were unlinked successfully we can delete the link record. 924 926 if ( ( $cnt_error == 0 ) && ( $cnt_okay > 0 ) ){ 925 927 //FB::log('Instances removed, deleting the link.'); 926 928 $link_deleted = $this->forget() !== false; 927 929 928 930 if ( !$link_deleted ){ 929 931 array_push( 930 $errors, 932 $errors, 931 933 new WP_Error( 932 934 "deletion_failed", … … 935 937 ); 936 938 } 937 939 938 940 } else { 939 941 //FB::error("Something went wrong. Unlinked instances : $cnt_okay, errors : $cnt_error"); 940 942 $link_deleted = false; 941 943 } 942 944 943 945 return array( 944 946 'cnt_okay' => $cnt_okay, … … 946 948 'link_deleted' => $link_deleted, 947 949 'errors' => $errors, 948 ); 950 ); 949 951 } 950 952 … … 958 960 global $wpdb; /** @var wpdb $wpdb */ 959 961 if ( !$this->valid() ) return false; 960 962 961 963 if ( !empty($this->link_id) ){ 962 964 //FB::info($this, 'Deleting link from DB'); 963 965 964 966 if ( $remove_instances ){ 965 967 //Remove instances, if any 966 968 $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}blc_instances WHERE link_id=%d", $this->link_id) ); 967 969 } 968 970 969 971 //Remove the link itself 970 972 $rez = $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}blc_links WHERE link_id=%d", $this->link_id) ); 971 973 $this->link_id = 0; 972 974 973 975 return $rez; 974 976 } else { 975 977 return false; 976 978 } 977 978 } 979 979 980 } 981 980 982 /** 981 983 * Get a list of the link's instances 982 984 * 983 985 * @param bool $ignore_cache Don't use the internally cached instance list. 984 * @param string $purpose 986 * @param string $purpose 985 987 * @return blcLinkInstance[] An array of instance objects or FALSE on failure. 986 988 */ 987 989 function get_instances( $ignore_cache = false, $purpose = '' ){ 988 990 if ( !$this->valid() || empty($this->link_id) ) return false; 989 991 990 992 if ( $ignore_cache || is_null($this->_instances) ){ 991 993 $instances = blc_get_instances( array($this->link_id), $purpose ); … … 994 996 } 995 997 } 996 998 997 999 return $this->_instances; 998 1000 } 999 1001 1000 1002 /** 1001 1003 * Determine the status text and status code corresponding to the current state of this link. 1002 * 1004 * 1003 1005 * @return array Associative array with two keys, 'text' and 'code'. 1004 1006 */ … … 1006 1008 $code = BLC_LINK_STATUS_UNKNOWN; 1007 1009 $text = _x('Unknown', 'link status', 'broken-link-checker'); 1008 1010 1009 1011 //Status text 1010 1012 if ( isset($this->status_text) && !empty($this->status_text) && !empty($this->status_code) ){ 1011 1013 1012 1014 //Lucky, the checker module has already set it for us. 1013 1015 $text = $this->status_text; 1014 1016 $code = $this->status_code; 1015 1017 1016 1018 } else { 1017 1019 1018 1020 if ( $this->broken || $this->warning ){ 1019 1021 $code = BLC_LINK_STATUS_WARNING; 1020 1022 $text = __('Unknown Error', 'broken-link-checker'); 1021 1023 1022 1024 if ( $this->timeout ){ 1023 1025 1024 1026 $text = __('Timeout', 'broken-link-checker'); 1025 1027 $code = BLC_LINK_STATUS_WARNING; 1026 1028 1027 1029 } elseif ( $this->http_code ) { 1028 1030 1029 1031 //Only 404 (Not Found) and 410 (Gone) are treated as broken-for-sure. 1030 1032 if ( in_array($this->http_code, array(404, 410)) ){ … … 1033 1035 $code = BLC_LINK_STATUS_WARNING; 1034 1036 } 1035 1037 1036 1038 if ( array_key_exists(intval($this->http_code), $this->http_status_codes) ){ 1037 1039 $text = $this->http_status_codes[intval($this->http_code)]; 1038 1040 } 1039 1041 } 1040 1042 1041 1043 } else { 1042 1044 1043 1045 if ( !$this->last_check ) { 1044 1046 $text = __('Not checked', 'broken-link-checker'); … … 1051 1053 $code = BLC_LINK_STATUS_OK; 1052 1054 } 1053 1054 } 1055 } 1056 1055 1056 } 1057 } 1058 1057 1059 return compact('text', 'code'); 1058 1060 } 1059 1061 1060 1062 /** 1061 1063 * Get the link URL in ASCII-compatible encoding. 1062 * 1064 * 1063 1065 * @return string 1064 1066 */ … … 1122 1124 WHERE 1123 1125 {$wpdb->prefix}blc_instances.link_id IS NULL"; 1124 1126 1125 1127 if ( $link_id !== null ) { 1126 1128 if ( !is_array($link_id) ){ … … 1129 1131 $q .= " AND {$wpdb->prefix}blc_links.link_id IN (" . implode(', ', $link_id) . ')'; 1130 1132 } 1131 1133 1132 1134 $rez = $wpdb->query( $q ); 1133 1135 $elapsed = microtime(true) - $start; 1134 1136 $blclog->log(sprintf('... %d links deleted in %.3f seconds', $wpdb->rows_affected, $elapsed)); 1135 1136 return $rez !== false; 1137 1138 return $rez !== false; 1137 1139 } 1138 1140 -
broken-link-checker/trunk/includes/transactions-manager.php
r1383258 r2054130 19 19 { 20 20 global $wpdb; 21 global $blclog; 22 $blclog->debug('Starting DB commit.'); 21 23 22 24 $this->start(); … … 24 26 try { 25 27 $wpdb->query('COMMIT'); 28 $blclog->debug('Commit executed.'); 26 29 $this->isTransactionStarted = false; 27 30 } catch (Exception $e) { 28 31 $wpdb->query('ROLLBACK'); 32 $blclog->debug('Commit failed; rollback.'); 29 33 $this->isTransactionStarted = false; 30 34 } -
broken-link-checker/trunk/modules/checkers/http.php
r1706472 r2054130 24 24 /** @var blcTokenBucketList */ 25 25 private $token_bucket_list; 26 26 27 27 function init(){ 28 28 parent::init(); … … 34 34 $conf->get('http_throttle_min_interval', 2) 35 35 ); 36 36 37 37 if ( function_exists('curl_init') || is_callable('curl_init') ) { 38 38 $this->implementation = new blcCurlHttp( 39 $this->module_id, 39 $this->module_id, 40 40 $this->cached_header, 41 41 $this->plugin_conf, … … 50 50 } 51 51 } 52 52 53 53 //If Snoopy is available, it will be used in place of CURL. 54 54 if ( class_exists('Snoopy') ){ 55 55 $this->implementation = new blcSnoopyHttp( 56 $this->module_id, 56 $this->module_id, 57 57 $this->cached_header, 58 58 $this->plugin_conf, … … 62 62 } 63 63 } 64 64 65 65 function can_check($url, $parsed){ 66 66 if ( isset($this->implementation) ){ … … 70 70 } 71 71 } 72 72 73 73 function check($url, $use_get = false){ 74 74 global $blclog; … … 93 93 */ 94 94 class blcHttpCheckerBase extends blcChecker { 95 95 96 96 function clean_url($url){ 97 97 $url = html_entity_decode($url); … … 110 110 ); 111 111 $url = trim($url); 112 112 113 113 return $url; 114 114 } 115 115 116 116 function is_error_code($http_code){ 117 117 /*"Good" response codes are anything in the 2XX range (e.g "200 OK") and redirects - the 3XX range. … … 121 121 return !$good_code; 122 122 } 123 123 124 124 /** 125 125 * This checker only accepts HTTP(s) links. … … 131 131 function can_check($url, $parsed){ 132 132 if ( !isset($parsed['scheme']) ) return false; 133 133 134 134 return in_array( strtolower($parsed['scheme']), array('http', 'https') ); 135 135 } 136 136 137 137 /** 138 138 * Takes an URL and replaces spaces and some other non-alphanumeric characters with their urlencoded equivalents. … … 142 142 */ 143 143 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. 145 145 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]);'), 148 148 $url 149 );150 } 151 149 ); 150 } 151 152 152 } 153 153 154 154 class blcCurlHttp extends blcHttpCheckerBase { 155 155 156 156 var $last_headers = ''; 157 157 158 158 function check($url, $use_get = false){ 159 159 global $blclog; … … 171 171 ); 172 172 $log = ''; 173 173 174 174 //Get the BLC configuration. It's used below to set the right timeout values and such. 175 175 $conf = blc_get_configuration(); 176 176 177 177 //Init curl. 178 178 $ch = curl_init(); … … 180 180 curl_setopt($ch, CURLOPT_URL, $this->urlencodefix($url)); 181 181 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'; 186 185 curl_setopt($ch, CURLOPT_USERAGENT, $ua); 187 186 … … 191 190 $request_headers[] = 'Connection: close'; 192 191 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 194 193 curl_setopt($ch, CURLOPT_REFERER, home_url()); 195 194 196 195 //Redirects don't work when safe mode or open_basedir is enabled. 197 196 if ( !blcUtility::is_safe_mode() && !blcUtility::is_open_basedir() ) { … … 200 199 //Set maximum redirects 201 200 curl_setopt($ch, CURLOPT_MAXREDIRS, 10); 202 201 203 202 //Set the timeout 204 203 curl_setopt($ch, CURLOPT_TIMEOUT, $conf->options['timeout']); 205 204 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 208 207 if (defined('WP_PROXY_HOST')) { 209 208 curl_setopt($ch, CURLOPT_PROXY, WP_PROXY_HOST); 210 209 } 211 if (defined('WP_PROXY_PORT')) { 210 if (defined('WP_PROXY_PORT')) { 212 211 curl_setopt($ch, CURLOPT_PROXYPORT, WP_PROXY_PORT); 213 212 } … … 223 222 curl_setopt($ch, CURLOPT_FAILONERROR, false); 224 223 225 224 226 225 $nobody = !$use_get; //Whether to send a HEAD request (the default) or a GET request 227 226 228 227 $parts = @parse_url($url); 229 228 if( $parts['scheme'] == 'https' ){ 230 229 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); 232 231 //$nobody = false; //Can't use HEAD with HTTPS. 233 232 } 234 233 235 234 if ( $nobody ){ 236 235 //If possible, use HEAD requests for speed. 237 curl_setopt($ch, CURLOPT_NOBODY, true); 236 curl_setopt($ch, CURLOPT_NOBODY, true); 238 237 } else { 239 238 //If we must use GET at least limit the amount of downloaded data. … … 247 246 248 247 //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. 250 249 curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this,'read_header')); 251 250 … … 263 262 $measured_request_duration = microtime_float() - $start_time; 264 263 $blclog->debug(sprintf('HTTP request took %.3f seconds', $measured_request_duration)); 265 264 266 265 $info = curl_getinfo($ch); 267 266 268 267 //Store the results 269 268 $result['http_code'] = intval( $info['http_code'] ); … … 273 272 274 273 //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. 276 275 if( empty($result['request_duration']) ){ 277 276 $result['request_duration'] = $measured_request_duration; 278 277 } 279 278 280 279 //Determine if the link counts as "broken" 281 280 if ( $result['http_code'] == 0 ){ 282 281 $result['broken'] = true; 283 282 284 283 $error_code = curl_errno($ch); 285 284 $log .= sprintf( "%s [Error #%d]\n", curl_error($ch), $error_code ); 286 285 287 286 //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 289 288 //different names or values in PHP. 290 289 switch( $error_code ) { … … 294 293 $result['error_code'] = 'couldnt_resolve_host'; 295 294 break; 296 295 297 296 case 28: //CURLE_OPERATION_TIMEDOUT 298 297 $result['timeout'] = true; 299 298 break; 300 299 301 300 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 304 303 //due to timeouts and those that fail due to other causes. 305 304 if ( $result['request_duration'] >= 0.9*$conf->options['timeout'] ){ … … 311 310 } 312 311 break; 313 312 314 313 default: 315 314 $result['status_code'] = BLC_LINK_STATUS_WARNING; 316 315 $result['status_text'] = __('Unknown Error', 'broken-link-checker'); 317 316 } 318 317 319 318 } else { 320 319 $result['broken'] = $this->is_error_code($result['http_code']); … … 333 332 isset($result['status_text']) ? $result['status_text'] : 'N/A' 334 333 )); 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. 339 338 return $this->check($url, true); 340 339 341 340 //Note : normally a server that doesn't allow HEAD requests on a specific resource *should* 342 341 //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 346 345 //When safe_mode or open_basedir is enabled CURL will be forbidden from following redirects, 347 346 //so redirect_count will be 0 for all URLs. As a workaround, set it to 1 when the HTTP … … 350 349 if ( ($result['redirect_count'] == 0) && ( in_array( $result['http_code'], array(301, 302, 303, 307) ) ) ){ 351 350 $result['redirect_count'] = 1; 352 } 353 351 } 352 354 353 //Build the log from HTTP code and headers. 355 354 $log .= '=== '; … … 379 378 380 379 $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. 384 383 $result['result_hash'] = implode('|', array( 385 384 $result['http_code'], … … 388 387 blcLink::remove_query_string($result['final_url']), 389 388 )); 390 389 391 390 return $result; 392 391 } 393 392 394 393 function read_header(/** @noinspection PhpUnusedParameterInspection */ $ch, $header){ 395 394 $this->last_headers .= $header; 396 395 return strlen($header); 397 396 } 398 397 399 398 } 400 399 401 400 class blcSnoopyHttp extends blcHttpCheckerBase { 402 401 403 402 function check($url){ 404 $url = $this->clean_url($url); 403 $url = $this->clean_url($url); 405 404 //Note : Snoopy doesn't work too well with HTTPS URLs. 406 405 407 406 $result = array( 408 407 'broken' => false, … … 410 409 ); 411 410 $log = ''; 412 413 //Get the timeout setting from the BLC configuration. 411 412 //Get the timeout setting from the BLC configuration. 414 413 $conf = blc_get_configuration(); 415 414 $timeout = $conf->options['timeout']; 416 415 417 416 $start_time = microtime_float(); 418 417 419 418 //Fetch the URL with Snoopy 420 419 $snoopy = new Snoopy; … … 424 423 $snoopy->maxlength = 1024*5; //load up to 5 kilobytes 425 424 $snoopy->fetch( $this->urlencodefix($url) ); 426 425 427 426 $result['request_duration'] = microtime_float() - $start_time; 428 427 429 428 $result['http_code'] = $snoopy->status; //HTTP status code 430 //Snoopy returns -100 on timeout 429 //Snoopy returns -100 on timeout 431 430 if ( $result['http_code'] == -100 ){ 432 431 $result['http_code'] = 0; 433 432 $result['timeout'] = true; 434 433 } 435 434 436 435 //Build the log 437 436 $log .= '=== '; … … 453 452 $log .= implode("", $snoopy->headers)."\n"; //those headers already contain newlines 454 453 455 //Redirected? 454 //Redirected? 456 455 if ( $snoopy->lastredirectaddr ) { 457 456 $result['final_url'] = $snoopy->lastredirectaddr; … … 460 459 $result['final_url'] = $url; 461 460 } 462 461 463 462 //Determine if the link counts as "broken" 464 463 $result['broken'] = $this->is_error_code($result['http_code']) || $result['timeout']; 465 464 466 465 $log .= "<em>(" . __('Using Snoopy', 'broken-link-checker') . ")</em>"; 467 466 $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. 471 470 $result['result_hash'] = implode('|', array( 472 471 $result['http_code'], 473 $result['broken']?'broken':'0', 472 $result['broken']?'broken':'0', 474 473 $result['timeout']?'timeout':'0', 475 474 blcLink::remove_query_string($result['final_url']), 476 475 )); 477 476 478 477 return $result; 479 478 } 480 479 481 480 } -
broken-link-checker/trunk/modules/containers/acf_field.php
r1707025 r2054130 435 435 436 436 //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); 438 438 439 439 //When a post is deleted, also delete the custom field container associated with it. … … 654 654 $selected_fields = array_keys($selected_fields); 655 655 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 )) { 664 687 return; 665 688 } 666 689 667 $container = blcContainerHelper::get_container(array($this->container_type, $post_id));690 $container = blcContainerHelper::get_container(array($this->container_type, intval($post_id))); 668 691 $container->mark_as_unsynched(); 669 692 -
broken-link-checker/trunk/modules/parsers/html_link.php
r1132662 r2054130 28 28 */ 29 29 function parse($content, $base_url = '', $default_link_text = ''){ 30 $content = apply_filters( 'blc-parser-html-link-content', $content ); 31 30 32 //remove all <code></code> blocks first 31 33 $content = preg_replace('/<code[^>]*>.+?<\/code>/si', ' ', $content); -
broken-link-checker/trunk/readme.txt
r1707025 r2054130 1 1 === Broken Link Checker === 2 Contributors: freediver2 Contributors: managewp 3 3 Donate link: 4 4 Tags: links, broken, maintenance, blogroll, custom fields, admin, comments, posts 5 5 Requires at least: 3.2 6 Tested up to: 4.87 Stable tag: 1.11. 56 Tested up to: 5.1 7 Stable tag: 1.11.8 8 8 9 9 This plugin will check your posts, comments and other content for broken links and missing images, and notify you if any are found. … … 40 40 You can also click on the contents of the "Status" or "Link Text" columns to get more info about the status of each link. 41 41 42 **Translations**43 44 * Arabic - Yaser Maadan45 * Belorussian - [M. Comfi](http://www.comfi.com/)46 * Chinese Simplified - Kaijia Feng47 * 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 - mepmepmep71 * 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 77 42 **Other Credits** 78 43 … … 101 66 102 67 == 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 103 74 104 75 = 1.11.5 =
Note: See TracChangeset
for help on using the changeset viewer.