Make WordPress Core


Ignore:
Timestamp:
11/18/2010 06:22:13 AM (11 years ago)
Author:
nacin
Message:

Ludicrous speed for internal linking. First pass. props koopersmith, see #11420.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/wp-mce-link.php

    r16407 r16457  
    11<?php
     2// args expects optionally 'pagenum' and 's'
     3function wp_link_query( $args = array() ) {
     4    $pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
     5    $pt_names = array_keys( $pts );
    26
    3 require_once '../../../wp-load.php';
    4 include './wp-mce-link-includes.php';
     7    $query = array(
     8        'post_type' => $pt_names,
     9        'suppress_filters' => true,
     10        'update_post_term_cache' => false,
     11        'update_post_meta_cache' => false,
     12        'post_status' => 'publish',
     13        'order' => 'DESC',
     14        'orderby' => 'post_date',
     15        'posts_per_page' => 20,
     16    );
    517
    6 header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
     18    $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
     19
     20    if ( isset( $args['s'] ) )
     21        $query['s'] = $args['s'];
     22
     23    $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
     24
     25    // Do main query.
     26    $get_posts = new WP_Query;
     27    $posts = $get_posts->query( $query );
     28    // Check if any posts were found.
     29    if ( ! $get_posts->post_count )
     30        return false;
     31
     32    // Build results.
     33    $results = array();
     34    foreach ( $posts as $post ) {
     35        if ( 'post' == $post->post_type )
     36            $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
     37        else
     38            $info = $pts[ $post->post_type ]->labels->singular_name;
     39
     40        $results[] = array(
     41            'ID' => $post->ID,
     42            'title' => esc_html( strip_tags($post->post_title) ),
     43            'permalink' => get_permalink( $post->ID ),
     44            'info' => $info,
     45        );
     46    }
     47
     48    return $results;
     49}
     50
     51function wp_link_ajax( $request ) {
     52    // Searches have a title term.
     53    if ( isset( $request['title'] ) )
     54        $args['s'] = stripslashes( $request['title'] );
     55    $args['pagenum'] = ! empty( $request['page'] ) ? absint( $request['page'] ) : 1;
     56
     57    $results = wp_link_query( $args );
     58
     59    if ( ! isset( $results ) )
     60        die( '0' );
     61
     62    echo json_encode( $results );
     63    echo "\n";
     64}
     65
     66function wp_link_dialog() {
    767?>
    8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    9 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    10 <head>
    11 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_bloginfo('charset'); ?>" />
    12 <title><?php _e( 'Insert/edit link' ); ?></title>
    13 <script type="text/javascript">
    14 //<![CDATA[
    15 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>',
    16     wpLinkL10n = {
    17         untitled : '<?php _e('Untitled'); ?>',
    18         noMatchesFound : '<?php _e( 'No matches found.' ); ?>'
    19     };
    20 //]]>
    21 </script>
    22 <script type="text/javascript" src="tiny_mce_popup.js?ver=3223"></script>
    23 <?php
    24 wp_print_scripts( array( 'jquery', 'jquery-ui-widget' ) );
    25 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
    26 $src = "plugins/wplink/js/wplink$suffix.js?ver=20101116b";
    27 ?>
    28 <script type="text/javascript" src="<?php echo $src; ?>"></script>
    29 <?php
    30 wp_admin_css( 'global', true );
    31 wp_admin_css( 'wp-admin', true );
    32 register_admin_color_schemes();
    33 wp_admin_css( 'colors', true );
    34 ?>
    35 <style>
    36 html {
    37     background: #f1f1f1;
    38 }
    39 a:link, a:visited {
    40     color: #21759b;
    41 }
    42 p.howto {
    43     margin: 3px;
    44 }
    45 #link-options {
    46     padding: 10px 0 14px;
    47     border-bottom: 1px solid #dfdfdf;
    48     margin: 0 6px 14px;
    49 }
    50 label input[type="text"] {
    51     width: 360px;
    52     margin-top: 5px;
    53 }
    54 label span {
    55     display: inline-block;
    56     width: 80px;
    57     text-align: right;
    58     padding-right: 5px;
    59 }
    60 .link-search-wrapper {
    61     margin: 5px 5px 9px;
    62     display: block;
    63     overflow: hidden;
    64 }
    65 .link-search-wrapper span {
    66     float: left;
    67     margin-top: 6px;
    68 }
    69 .link-search-wrapper input[type="text"] {
    70     float: left;
    71     width: 220px;
    72 }
    73 .link-search-wrapper img.waiting {
    74     margin: 8px 1px 0 4px;
    75     float: left;
    76     display: none;
    77 }
    78 #open-in-new-tab {
    79     display: inline-block;
    80     padding: 3px 0 0;
    81     margin: 0 0 0 87px;
    82 }
    83 #open-in-new-tab span {
    84     width: auto;
    85     margin-left: 6px;
    86     font-size: 11px;
    87 }
    88 .query-results {
    89     border: 1px #dfdfdf solid;
    90     margin: 0 5px 5px;
    91     background: #fff;
    92     height: 185px;
    93     overflow: auto;
    94 }
    95 .query-results li {
    96     margin-bottom: 0;
    97     border-bottom: 1px solid #f1f1f1;
    98     color: #555;
    99     padding: 4px 6px;
    100     cursor: pointer;
    101 }
    102 .query-results li:hover {
    103     background: #eaf2fa;
    104     color: #333;
    105 }
    106 .query-results li.unselectable:hover {
    107     background: #fff;
    108     cursor: auto;
    109     color: #555;
    110 }
    111 .query-results li.unselectable {
    112     border-bottom: 1px solid #dfdfdf;
    113 }
    114 .query-results li.selected {
    115     background: #f1f1f1;
    116     color: #333;
    117 }
    118 .query-results li.selected .item-title {
    119     font-weight: bold;
    120 }
    121 .item-info {
    122     text-transform: uppercase;
    123     color: #aaa;
    124     font-size: 11px;
    125     float: right;
    126 }
    127 #search-results {
    128     display: none;
    129 }
    130 .river-waiting {
    131     display: none;
    132     padding: 10px 0;
    133 }
    134 .river-waiting img.waiting {
    135     margin: 0 auto;
    136     display: block;
    137 }
    138 .submitbox {
    139     padding: 5px 5px 0;
    140     font-size: 11px;
    141     overflow: auto;
    142     height: 29px;
    143 }
    144 #wp-cancel {
    145     line-height: 25px;
    146     float: left;
    147 }
    148 #wp-update {
    149     line-height: 23px;
    150     float: right;
    151 }
    152 #wp-update a {
    153     display: inline-block;
    154 }
    155 </style>
    156 </head>
    157 <body id="post-body">
     68<div id="wp-link">
    15869<div id="link-selector">
    15970    <div id="link-options">
     
    205116</div>
    206117<div class="submitbox">
    207     <div id="wp-cancel">
     118    <div id="wp-link-cancel">
    208119        <a class="submitdelete deletion"><?php _e( 'Cancel' ); ?></a>
    209120    </div>
    210     <div id="wp-update">
     121    <div id="wp-link-update">
    211122        <a class="button-primary"><?php _e( 'Update' ); ?></a>
    212123    </div>
    213124</div>
    214 </body>
    215 </html>
     125</div>
     126<?php } ?>
Note: See TracChangeset for help on using the changeset viewer.