mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-01 03:58:07 +08:00
Fixed: CodeFactor issues
This commit is contained in:
parent
fc55fcb6d5
commit
69bf22c065
1 changed files with 67 additions and 77 deletions
|
@ -1,15 +1,12 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
* Plugin-Name: Broken Link Checker
|
||||
* Plugin URI: https://wordpress.org/plugins/broken-link-checker/
|
||||
* Author: Janis Elsts, Vladimir Prelovac
|
||||
*
|
||||
* The code is used for the MainWP Broken Links Checker Extension
|
||||
* Extension URL: https://mainwp.com/extension/broken-links-checker/
|
||||
* The code is used for the MainWP Broken Links Checker Extension (Retired Extension)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -18,7 +15,7 @@ class MainWP_Child_Links_Checker {
|
|||
public static $instance = null;
|
||||
public $is_plugin_installed = false;
|
||||
|
||||
static function Instance() {
|
||||
public static function Instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new MainWP_Child_Links_Checker();
|
||||
}
|
||||
|
@ -48,7 +45,6 @@ class MainWP_Child_Links_Checker {
|
|||
blc_init();
|
||||
|
||||
MainWP_Helper::update_option( 'mainwp_linkschecker_ext_enabled', 'Y', 'yes' );
|
||||
// need this try()
|
||||
try {
|
||||
if ( isset( $_POST['mwp_action'] ) ) {
|
||||
switch ( $_POST['mwp_action'] ) {
|
||||
|
@ -113,7 +109,7 @@ class MainWP_Child_Links_Checker {
|
|||
blc_cleanup_links();
|
||||
}
|
||||
|
||||
function save_settings() {
|
||||
public function save_settings() {
|
||||
$information = array();
|
||||
$check_threshold = intval( $_POST['check_threshold'] );
|
||||
if ( $check_threshold > 0 ) {
|
||||
|
@ -125,7 +121,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
function force_recheck() {
|
||||
public function force_recheck() {
|
||||
$this->initiate_recheck();
|
||||
$information = array();
|
||||
$information['result'] = 'SUCCESS';
|
||||
|
@ -133,14 +129,14 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
function initiate_recheck() {
|
||||
public function initiate_recheck() {
|
||||
global $wpdb;
|
||||
/** @var wpdb $wpdb */
|
||||
|
||||
// Delete all discovered instances
|
||||
// Delete all discovered instances.
|
||||
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
|
||||
|
||||
// Delete all discovered links
|
||||
// Delete all discovered links.
|
||||
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
|
||||
|
||||
// Mark all posts, custom fields and bookmarks for processing.
|
||||
|
@ -158,18 +154,18 @@ class MainWP_Child_Links_Checker {
|
|||
}
|
||||
blc_init();
|
||||
|
||||
// Get the container type matching the type of the deleted post
|
||||
// Get the container type matching the type of the deleted post.
|
||||
$post = get_post( $post_id );
|
||||
if ( ! $post ) {
|
||||
return;
|
||||
}
|
||||
// Get the associated container object
|
||||
// Get the associated container object.
|
||||
$post_container = blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
|
||||
|
||||
if ( $post_container ) {
|
||||
// Delete it
|
||||
// Delete it.
|
||||
$post_container->delete();
|
||||
// Clean up any dangling links
|
||||
// Clean up any dangling links.
|
||||
blc_cleanup_links();
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +182,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $plugins;
|
||||
}
|
||||
|
||||
function update_footer( $text ) {
|
||||
public function update_footer( $text ) {
|
||||
?>
|
||||
<script>
|
||||
jQuery( document ).ready( function () {
|
||||
|
@ -199,7 +195,7 @@ class MainWP_Child_Links_Checker {
|
|||
}
|
||||
|
||||
|
||||
function set_showhide() {
|
||||
public function set_showhide() {
|
||||
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
||||
MainWP_Helper::update_option( 'mainwp_linkschecker_hide_plugin', $hide );
|
||||
$information['result'] = 'SUCCESS';
|
||||
|
@ -207,20 +203,19 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
// ok
|
||||
public function syncOthersData( $information, $data = array() ) {
|
||||
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
|
||||
try {
|
||||
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
// ok!
|
||||
}
|
||||
}
|
||||
return $information;
|
||||
}
|
||||
|
||||
|
||||
function get_sync_data( $strategy = '' ) {
|
||||
public function get_sync_data( $strategy = '' ) {
|
||||
$information = array();
|
||||
$data = $this->get_count_links();
|
||||
if ( is_array( $data ) ) {
|
||||
|
@ -229,7 +224,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
function get_links_data() {
|
||||
public function get_links_data() {
|
||||
|
||||
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
||||
return;
|
||||
|
@ -291,7 +286,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
function get_count_links() {
|
||||
public function get_count_links() {
|
||||
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -320,7 +315,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $data;
|
||||
}
|
||||
|
||||
function links_checker_data( $params ) {
|
||||
public function links_checker_data( $params ) {
|
||||
|
||||
MainWP_Helper::check_functions( 'blc_get_links' );
|
||||
MainWP_Helper::check_classes_exists( 'blcLink' );
|
||||
|
@ -345,7 +340,6 @@ class MainWP_Child_Links_Checker {
|
|||
'last_success',
|
||||
'may_recheck',
|
||||
'false_positive',
|
||||
// 'result_hash',
|
||||
'dismissed',
|
||||
'status_text',
|
||||
'status_code',
|
||||
|
@ -374,7 +368,7 @@ class MainWP_Child_Links_Checker {
|
|||
|
||||
$days_broken = 0;
|
||||
if ( $link->broken ) {
|
||||
// Add a highlight to broken links that appear to be permanently broken
|
||||
// Add a highlight to broken links that appear to be permanently broken.
|
||||
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
|
||||
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
|
||||
$extra_info['permanently_broken'] = 1;
|
||||
|
@ -401,9 +395,7 @@ class MainWP_Child_Links_Checker {
|
|||
$extra_info['count_instance'] = count( $instances );
|
||||
$container = $first_instance->get_container();
|
||||
|
||||
/** @var blcContainer $container */
|
||||
|
||||
if ( ! empty( $container ) /* && ($container instanceof blcAnyPostContainer) */ ) {
|
||||
if ( ! empty( $container ) ) {
|
||||
if ( true === MainWP_Helper::check_properties( $first_instance, array( 'container_field' ), true ) ) {
|
||||
if ( true === MainWP_Helper::check_properties( $container, array( 'container_type', 'container_id' ), true ) ) {
|
||||
$extra_info['container_type'] = $container->container_type;
|
||||
|
@ -444,7 +436,7 @@ class MainWP_Child_Links_Checker {
|
|||
$new_link->link_text = '';
|
||||
$extra_info['count_instance'] = 0;
|
||||
}
|
||||
$new_link->extra_info = base64_encode(serialize($extra_info));
|
||||
$new_link->extra_info = base64_encode( serialize( $extra_info ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
$new_link->synced = 1;
|
||||
$return[] = $new_link;
|
||||
}
|
||||
|
@ -455,17 +447,17 @@ class MainWP_Child_Links_Checker {
|
|||
return $return;
|
||||
}
|
||||
|
||||
function edit_link() {
|
||||
public function edit_link() {
|
||||
$information = array();
|
||||
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
||||
$information['error'] = 'NOTALLOW';
|
||||
|
||||
return $information;
|
||||
}
|
||||
// Load the link
|
||||
// Load the link.
|
||||
$link = new blcLink( intval( $_POST['link_id'] ) );
|
||||
if ( ! $link->valid() ) {
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
||||
return $information;
|
||||
}
|
||||
|
||||
|
@ -515,10 +507,9 @@ class MainWP_Child_Links_Checker {
|
|||
'ui_link_text' => isset( $new_text ) ? $ui_link_text : null,
|
||||
'errors' => array(),
|
||||
);
|
||||
// url, status text, status code, link text, editable link text
|
||||
// url, status text, status code, link text, editable link text.
|
||||
|
||||
foreach ( $rez['errors'] as $error ) {
|
||||
/** @var $error WP_Error */
|
||||
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
|
||||
}
|
||||
|
||||
|
@ -526,7 +517,7 @@ class MainWP_Child_Links_Checker {
|
|||
}
|
||||
}
|
||||
|
||||
function unlink() {
|
||||
public function unlink() {
|
||||
$information = array();
|
||||
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
||||
$information['error'] = 'NOTALLOW';
|
||||
|
@ -535,15 +526,15 @@ class MainWP_Child_Links_Checker {
|
|||
}
|
||||
|
||||
if ( isset( $_POST['link_id'] ) ) {
|
||||
// Load the link
|
||||
// Load the link.
|
||||
$link = new blcLink( intval( $_POST['link_id'] ) );
|
||||
|
||||
if ( ! $link->valid() ) {
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
||||
return $information;
|
||||
}
|
||||
|
||||
// Try and unlink it
|
||||
// Try and unlink it.
|
||||
$rez = $link->unlink();
|
||||
|
||||
if ( false === $rez ) {
|
||||
|
@ -580,21 +571,21 @@ class MainWP_Child_Links_Checker {
|
|||
}
|
||||
|
||||
if ( isset( $_POST['link_id'] ) ) {
|
||||
// Load the link
|
||||
// Load the link.
|
||||
$link = new blcLink( intval( $_POST['link_id'] ) );
|
||||
|
||||
if ( ! $link->valid() ) {
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
||||
return $information;
|
||||
}
|
||||
|
||||
$link->dismissed = $dismiss;
|
||||
|
||||
// Save the changes
|
||||
// Save the changes.
|
||||
if ( $link->save() ) {
|
||||
$information = 'OK';
|
||||
} else {
|
||||
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link
|
||||
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link.
|
||||
}
|
||||
|
||||
return $information;
|
||||
|
@ -613,26 +604,26 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
if ( isset( $_POST['link_id'] ) ) {
|
||||
// Load the link
|
||||
// Load the link.
|
||||
$link = new blcLink( intval( $_POST['link_id'] ) );
|
||||
|
||||
if ( ! $link->valid() ) {
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
||||
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
||||
return $information;
|
||||
}
|
||||
|
||||
// Make it appear "not broken"
|
||||
// Make it appear "not broken".
|
||||
$link->broken = false;
|
||||
$link->false_positive = true;
|
||||
$link->last_check_attempt = time();
|
||||
$link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' );
|
||||
|
||||
// Save the changes
|
||||
// Save the changes.
|
||||
if ( $link->save() ) {
|
||||
$information['status'] = 'OK';
|
||||
$information['last_check_attempt'] = $link->last_check_attempt;
|
||||
} else {
|
||||
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link
|
||||
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link.
|
||||
}
|
||||
} else {
|
||||
$information['error'] = __( 'Error: link_id is not specified.', 'mainwp-child' );
|
||||
|
@ -641,7 +632,7 @@ class MainWP_Child_Links_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
function ui_get_source( $container, $container_field = '' ) {
|
||||
public function ui_get_source( $container, $container_field = '' ) {
|
||||
if ( 'comment' === $container->container_type ) {
|
||||
return $this->ui_get_source_comment( $container, $container_field );
|
||||
} elseif ( $container instanceof blcAnyPostContainer ) {
|
||||
|
@ -651,7 +642,7 @@ class MainWP_Child_Links_Checker {
|
|||
return array();
|
||||
}
|
||||
|
||||
function ui_get_source_comment( $container, $container_field = '' ) {
|
||||
public function ui_get_source_comment( $container, $container_field = '' ) {
|
||||
// Display a comment icon.
|
||||
if ( 'comment_author_url' === $container_field ) {
|
||||
$image = 'font-awesome/font-awesome-user.png';
|
||||
|
@ -665,7 +656,7 @@ class MainWP_Child_Links_Checker {
|
|||
|
||||
$comment = $container->get_wrapped_object();
|
||||
|
||||
// Display a small text sample from the comment
|
||||
// Display a small text sample from the comment.
|
||||
$text_sample = strip_tags( $comment->comment_content );
|
||||
$text_sample = blcUtility::truncate( $text_sample, 65 );
|
||||
|
||||
|
@ -681,7 +672,7 @@ class MainWP_Child_Links_Checker {
|
|||
);
|
||||
}
|
||||
|
||||
function ui_get_source_post( $container, $container_field = '' ) {
|
||||
public function ui_get_source_post( $container, $container_field = '' ) {
|
||||
return array(
|
||||
'post_title' => get_the_title( $container->container_id ),
|
||||
'post_status' => get_post_status( $container->container_id ),
|
||||
|
@ -689,4 +680,3 @@ class MainWP_Child_Links_Checker {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue