コード例 #1
0
ファイル: ajax-actions.php プロジェクト: hughnet/WordPress
/**
 * Ajax handler for internal linking.
 *
 * @since 3.1.0
 */
function wp_ajax_wp_link_ajax()
{
    check_ajax_referer('internal-linking', '_ajax_linking_nonce');
    $args = array();
    if (isset($_POST['search'])) {
        $args['s'] = wp_unslash($_POST['search']);
    }
    $args['pagenum'] = !empty($_POST['page']) ? absint($_POST['page']) : 1;
    require ABSPATH . WPINC . '/class-wp-editor.php';
    $results = _WP_Editors::wp_link_query($args);
    if (!isset($results)) {
        wp_die(0);
    }
    echo wp_json_encode($results);
    echo "\n";
    wp_die();
}
コード例 #2
0
ファイル: ckeditor_class.php プロジェクト: vanlong200880/tmdt
 public function ckeditor_linkbrowser_search()
 {
     check_ajax_referer('internal-linking', '_ajax_linking_nonce');
     $args = array();
     if (isset($_POST['search'])) {
         $args['s'] = stripslashes($_POST['search']);
     }
     $args['pagenum'] = !empty($_POST['page']) ? absint($_POST['page']) : 1;
     $results = _WP_Editors::wp_link_query($args);
     if (!isset($results)) {
         wp_die(0);
     }
     echo json_encode($results);
     echo "\n";
     wp_die();
 }
コード例 #3
0
ファイル: admin-ajax.php プロジェクト: vivekkodira1/wordpress
     if (!current_user_can('edit_theme_options')) {
         die('-1');
     }
     require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     _wp_ajax_menu_quick_search($_REQUEST);
     exit;
     break;
 case 'wp-link-ajax':
     check_ajax_referer('internal-linking', '_ajax_linking_nonce');
     $args = array();
     if (isset($_POST['search'])) {
         $args['s'] = stripslashes($_POST['search']);
     }
     $args['pagenum'] = !empty($_POST['page']) ? absint($_POST['page']) : 1;
     require ABSPATH . WPINC . '/class-wp-editor.php';
     $results = _WP_Editors::wp_link_query($args);
     if (!isset($results)) {
         die('0');
     }
     echo json_encode($results);
     echo "\n";
     exit;
     break;
 case 'menu-locations-save':
     if (!current_user_can('edit_theme_options')) {
         die('-1');
     }
     check_ajax_referer('add-menu_item', 'menu-settings-column-nonce');
     if (!isset($_POST['menu-locations'])) {
         die('0');
     }
 /**
  * Returns search results.
  *
  * Results returned in a format expected by the internal link manager.
  * Doesn't have support for paging.
  *
  * Multiple filters provided for either adding results or short-circuiting
  * the flow at various points.
  *
  * @since 1.1.0
  */
 public static function ajax_get_link_search_results()
 {
     global $wpdb;
     check_ajax_referer('internal-linking', '_ajax_linking_nonce');
     if (isset($_POST['search'])) {
         $results = array();
         $s = stripslashes($_POST['search']);
         $args['s'] = $s;
         $args['page'] = !empty($_POST['page']) ? absint($_POST['page']) : 1;
         $args['per_page'] = 20;
         // Default for usage in filters, otherwise, it shouldn't do anything.
         // Check to see if the request is prepended with a modifier (ex: -wikipedia interrobang, -spotify:artist willie nelson).
         if (0 === mb_strpos($s, '-')) {
             preg_match('/-([^\\s]+)\\s?(.*)?/', $s, $matches);
             $s = trim($matches[2]);
             $args['s'] = $s;
             $args['modifier'] = explode(':', trim($matches[1]));
             $results = (array) apply_filters('better_internal_link_search_modifier-' . $args['modifier'][0], array(), $args);
             if (!empty($results)) {
                 echo json_encode($results);
                 wp_die();
             }
         }
         // Allow plugins to intercept the request and add their own results or short-circuit execution.
         $pre_results = (array) apply_filters('pre_better_internal_link_search_results', array(), $args);
         if (!empty($pre_results)) {
             $results = array_merge($results, $pre_results);
         }
         // Short-circuit if this is a paged request. The first request should have returned all results.
         if (isset($_POST['page']) && $_POST['page'] > 1) {
             wp_die(0);
         }
         // Don't continue if the query length is less than three.
         if (strlen($args['s']) < 3) {
             wp_die(0);
         }
         // @see wp_link_ajax();
         require_once ABSPATH . WPINC . '/class-wp-editor.php';
         $posts = _WP_Editors::wp_link_query($args);
         if ($posts) {
             $future_status_object = get_post_status_object('future');
             $private_status_object = get_post_status_object('private');
             foreach ($posts as $key => $post) {
                 if ('future' == get_post_status($post['ID'])) {
                     $posts[$key]['info'] = $future_status_object->label;
                 } elseif ('private' == get_post_status($post['ID'])) {
                     $posts[$key]['info'] .= ' (' . $private_status_object->label . ')';
                 }
             }
             $results = array_merge($results, $posts);
         }
         if ('yes' === Better_Internal_Link_Search_Settings::get_settings('include_term_results')) {
             // Search for matching term archives.
             $search = '%' . self::esc_like($s) . '%';
             $terms = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name, tt.taxonomy\n\t\t\t\t\tFROM {$wpdb->terms} t\n\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id=tt.term_id\n\t\t\t\t\tWHERE t.name LIKE %s\n\t\t\t\t\tORDER BY name ASC", $search));
             if ($terms) {
                 foreach ($terms as $term) {
                     $taxonomy = get_taxonomy($term->taxonomy);
                     if (isset($taxonomy->query_var)) {
                         $results[] = array('title' => trim(esc_html(strip_tags($term->name))), 'permalink' => get_term_link((int) $term->term_id, $term->taxonomy), 'info' => $taxonomy->labels->singular_name);
                     }
                 }
             }
         }
         // Allow results to be filtered one last time and attempt to sort them.
         if (!empty($results)) {
             self::$s = $s;
             $results = apply_filters('better_internal_link_search_results', $results, $args);
             if (apply_filters('better_internal_link_search_sort_results', true, $results, $args)) {
                 usort($results, array(__CLASS__, 'sort_results'));
             }
         }
         // Add shortcut results.
         $shortcuts = (array) self::get_shortcuts();
         if (!empty($shortcuts)) {
             if (array_key_exists($s, $shortcuts)) {
                 array_unshift($results, $shortcuts[$s]);
             } elseif ('shortcuts' == $s) {
                 $results = array_merge($shortcuts, $results);
             }
         }
     }
     if (!isset($results) || empty($results)) {
         wp_die(0);
     }
     echo json_encode($results);
     echo "\n";
     wp_die();
 }