コード例 #1
0
 function blc_update_link($params)
 {
     if ($this->_checkBLC()) {
         $link = new blcLink(intval($params['linkID']));
         $rez = $link->edit($params['newLink'], $params['newText']);
         $rez['new_text'] = $params['newText'];
         $rez['old_link_id'] = $params['linkID'];
         $rez['linkType'] = $params['linkType'];
         return $rez;
     } else {
         return array('error' => "Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_update_link');
     }
 }
コード例 #2
0
ファイル: core.php プロジェクト: ManageWP/broken-link-checker
 /**
  * AJAX hook for the inline link editor on Tools -> Broken Links. 
  *
  * @return void
  */
 function ajax_edit()
 {
     if (!current_user_can('edit_others_posts') || !check_ajax_referer('blc_edit', false, false)) {
         die(json_encode(array('error' => __("You're not allowed to do that!", 'broken-link-checker'))));
     }
     if (empty($_POST['link_id']) || empty($_POST['new_url']) || !is_numeric($_POST['link_id'])) {
         die(json_encode(array('error' => __("Error : link_id or new_url not specified", 'broken-link-checker'))));
     }
     //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'])))));
     }
     //Validate the new URL.
     $new_url = stripslashes($_POST['new_url']);
     $parsed = @parse_url($new_url);
     if (!$parsed) {
         die(json_encode(array('error' => __("Oops, the new URL is invalid!", 'broken-link-checker'))));
     }
     if (!current_user_can('unfiltered_html')) {
         //Disallow potentially dangerous URLs like "javascript:...".
         $protocols = wp_allowed_protocols();
         $good_protocol_url = wp_kses_bad_protocol($new_url, $protocols);
         if ($new_url != $good_protocol_url) {
             die(json_encode(array('error' => __("Oops, the new URL is invalid!", 'broken-link-checker'))));
         }
     }
     $new_text = isset($_POST['new_text']) && is_string($_POST['new_text']) ? stripslashes($_POST['new_text']) : null;
     if ($new_text === '') {
         $new_text = null;
     }
     if (!empty($new_text) && !current_user_can('unfiltered_html')) {
         $new_text = stripslashes(wp_filter_post_kses(addslashes($new_text)));
         //wp_filter_post_kses expects slashed data.
     }
     $rez = $link->edit($new_url, $new_text);
     if ($rez === false) {
         die(json_encode(array('error' => __("An unexpected error occurred!", 'broken-link-checker'))));
     } else {
         $new_link = $rez['new_link'];
         /** @var blcLink $new_link */
         $new_status = $new_link->analyse_status();
         $ui_link_text = null;
         if (isset($new_text)) {
             $instances = $new_link->get_instances();
             if (!empty($instances)) {
                 $first_instance = reset($instances);
                 $ui_link_text = $first_instance->ui_get_link_text();
             }
         }
         $response = array('new_link_id' => $rez['new_link_id'], 'cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'status_text' => $new_status['text'], 'status_code' => $new_status['code'], 'http_code' => empty($new_link->http_code) ? '' : $new_link->http_code, 'redirect_count' => $new_link->redirect_count, 'url' => $new_link->url, 'escaped_url' => esc_url_raw($new_link->url), 'final_url' => $new_link->final_url, 'link_text' => isset($new_text) ? $new_text : null, 'ui_link_text' => isset($new_text) ? $ui_link_text : null, 'errors' => array());
         //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()));
         }
         die(json_encode($response));
     }
 }
コード例 #3
0
ファイル: core.php プロジェクト: ahsaeldin/projects
 /**
  * AJAX hook for the inline link editor on Tools -> Broken Links. 
  *
  * @return void
  */
 function ajax_edit()
 {
     if (!current_user_can('edit_others_posts') || !check_ajax_referer('blc_edit', false, false)) {
         die(json_encode(array('error' => __("You're not allowed to do that!", 'broken-link-checker'))));
     }
     if (isset($_GET['link_id']) && !empty($_GET['new_url'])) {
         //Load the link
         $link = new blcLink(intval($_GET['link_id']));
         if (!$link->valid()) {
             die(json_encode(array('error' => sprintf(__("Oops, I can't find the link %d", 'broken-link-checker'), intval($_GET['link_id'])))));
         }
         $new_url = $_GET['new_url'];
         $new_url = stripslashes($new_url);
         $parsed = @parse_url($new_url);
         if (!$parsed) {
             die(json_encode(array('error' => __("Oops, the new URL is invalid!", 'broken-link-checker'))));
         }
         //Try and edit the link
         //FB::log($new_url, "Ajax edit");
         //FB::log($_GET, "Ajax edit");
         $rez = $link->edit($new_url);
         if ($rez === false) {
             die(json_encode(array('error' => __("An unexpected error occured!", 'broken-link-checker'))));
         } else {
             $response = array('new_link_id' => $rez['new_link_id'], 'cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'errors' => array());
             foreach ($rez['errors'] as $error) {
                 /** @var $error WP_Error */
                 array_push($response['errors'], implode(', ', $error->get_error_messages()));
             }
             die(json_encode($response));
         }
     } else {
         die(json_encode(array('error' => __("Error : link_id or new_url not specified", 'broken-link-checker'))));
     }
 }
コード例 #4
0
 function edit_link()
 {
     $information = array();
     if (!current_user_can('edit_others_posts')) {
         $information['error'] = 'NOTALLOW';
         return $information;
     }
     //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;
     }
     //Validate the new URL.
     $new_url = stripslashes($_POST['new_url']);
     $parsed = @parse_url($new_url);
     if (!$parsed) {
         $information['error'] = 'URLINVALID';
         // Oops, the new URL is invalid!
         return $information;
     }
     $new_text = isset($_POST['new_text']) && is_string($_POST['new_text']) ? stripslashes($_POST['new_text']) : null;
     if ($new_text === '') {
         $new_text = null;
     }
     if (!empty($new_text) && !current_user_can('unfiltered_html')) {
         $new_text = stripslashes(wp_filter_post_kses(addslashes($new_text)));
         //wp_filter_post_kses expects slashed data.
     }
     $rez = $link->edit($new_url, $new_text);
     if ($rez === false) {
         $information['error'] = __('An unexpected error occurred!');
         return $information;
     } else {
         $new_link = $rez['new_link'];
         /** @var blcLink $new_link */
         $new_status = $new_link->analyse_status();
         $ui_link_text = null;
         if (isset($new_text)) {
             $instances = $new_link->get_instances();
             if (!empty($instances)) {
                 $first_instance = reset($instances);
                 $ui_link_text = $first_instance->ui_get_link_text();
             }
         }
         $response = array('new_link_id' => $rez['new_link_id'], 'cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'status_text' => $new_status['text'], 'status_code' => $new_status['code'], 'http_code' => empty($new_link->http_code) ? '' : $new_link->http_code, 'url' => $new_link->url, 'link_text' => isset($new_text) ? $new_text : null, 'ui_link_text' => isset($new_text) ? $ui_link_text : null, 'errors' => array());
         //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()));
         }
         return $response;
     }
 }