private function blc_set_dismiss_status($dismiss, $params)
 {
     if ($this->_checkBLC()) {
         $link = new blcLink(intval($params['linkID']));
         if (!$link->valid()) {
             return "Oops, I can't find the link " . intval($params['linkID']);
         }
         $link->dismissed = $dismiss;
         if ($link->save()) {
             $rez = array('old_link_id' => $params['linkID'], 'linkType' => $params['linkType'], 'dismissvalue_set' => 1);
         } else {
             $rez = array('error' => 'Action couldn\'t be completed', 'error_code' => 'blc_plugin_action_couldnt_completed_blc_set_dismiss_status');
         }
         return $rez;
     } else {
         return array('error' => "Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_set_dismiss_status');
     }
 }
 /**
  * AJAX hook for the "Recheck" action.
  */
 public function ajax_recheck()
 {
     if (!current_user_can('edit_others_posts') || !check_ajax_referer('blc_recheck', false, false)) {
         die(json_encode(array('error' => __("You're not allowed to do that!", 'broken-link-checker'))));
     }
     if (!isset($_POST['link_id']) || !is_numeric($_POST['link_id'])) {
         die(json_encode(array('error' => __("Error : link_id not specified", 'broken-link-checker'))));
     }
     $id = intval($_POST['link_id']);
     $link = new blcLink($id);
     if (!$link->valid()) {
         die(json_encode(array('error' => sprintf(__("Oops, I can't find the link %d", 'broken-link-checker'), $id))));
     }
     //In case the immediate check fails, this will ensure the link is checked during the next work() run.
     $link->last_check_attempt = 0;
     $link->isOptionLinkChanged = true;
     $link->save();
     //Check the link and save the results.
     $link->check(true);
     $status = $link->analyse_status();
     $response = array('status_text' => $status['text'], 'status_code' => $status['code'], 'http_code' => empty($link->http_code) ? '' : $link->http_code, 'redirect_count' => $link->redirect_count, 'final_url' => $link->final_url);
     die(json_encode($response));
 }
Exemple #3
0
 /**
  * AJAX hook for the "Unlink" action links in Tools -> Broken Links. 
  * Removes the specified link from all posts and other supported items.
  *
  * @return void
  */
 function ajax_unlink()
 {
     if (!current_user_can('edit_others_posts') || !check_ajax_referer('blc_unlink', false, false)) {
         die(json_encode(array('error' => __("You're not allowed to do that!", 'broken-link-checker'))));
     }
     if (isset($_POST['link_id'])) {
         //Load the link
         $link = new blcLink(intval($_POST['link_id']));
         if (!$link->valid()) {
             die(json_encode(array('error' => sprintf(__("Oops, I can't find the link %d", 'broken-link-checker'), intval($_POST['link_id'])))));
         }
         //Try and unlink it
         $rez = $link->unlink();
         if ($rez === false) {
             die(json_encode(array('error' => __("An unexpected error occured!", 'broken-link-checker'))));
         } else {
             $response = array('cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'errors' => array());
             foreach ($rez['errors'] as $error) {
                 /** @var WP_Error $error */
                 array_push($response['errors'], implode(', ', $error->get_error_messages()));
             }
             die(json_encode($response));
         }
     } else {
         die(json_encode(array('error' => __("Error : link_id not specified", 'broken-link-checker'))));
     }
 }
 private function discard()
 {
     $information = array();
     if (!current_user_can('edit_others_posts')) {
         $information['error'] = 'NOTALLOW';
         return $information;
     }
     if (isset($_POST['link_id'])) {
         //Load the link
         $link = new blcLink(intval($_POST['link_id']));
         if (!$link->valid()) {
             $information['error'] = 'NOTFOUNDLINK';
             // Oops, I can't find the link
             return $information;
         }
         //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.");
         //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
         }
     } else {
         $information['error'] = __("Error : link_id not specified");
     }
     return $information;
 }