]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/internal-linking.php
Wordpress 3.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / internal-linking.php
1 <?php
2 /**
3  * Internal linking functions.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 3.1.0
8  */
9
10 /**
11  * Performs post queries for internal linking.
12  *
13  * @since 3.1.0
14  *
15  * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
16  * @return array Results.
17  */
18 function wp_link_query( $args = array() ) {
19         $pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
20         $pt_names = array_keys( $pts );
21
22         $query = array(
23                 'post_type' => $pt_names,
24                 'suppress_filters' => true,
25                 'update_post_term_cache' => false,
26                 'update_post_meta_cache' => false,
27                 'post_status' => 'publish',
28                 'order' => 'DESC',
29                 'orderby' => 'post_date',
30                 'posts_per_page' => 20,
31         );
32
33         $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
34
35         if ( isset( $args['s'] ) )
36                 $query['s'] = $args['s'];
37
38         $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
39
40         // Do main query.
41         $get_posts = new WP_Query;
42         $posts = $get_posts->query( $query );
43         // Check if any posts were found.
44         if ( ! $get_posts->post_count )
45                 return false;
46
47         // Build results.
48         $results = array();
49         foreach ( $posts as $post ) {
50                 if ( 'post' == $post->post_type )
51                         $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
52                 else
53                         $info = $pts[ $post->post_type ]->labels->singular_name;
54
55                 $results[] = array(
56                         'ID' => $post->ID,
57                         'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
58                         'permalink' => get_permalink( $post->ID ),
59                         'info' => $info,
60                 );
61         }
62
63         return $results;
64 }
65
66 /**
67  * Dialog for internal linking.
68  *
69  * @since 3.1.0
70  */
71 function wp_link_dialog() {
72 ?>
73 <form id="wp-link" tabindex="-1">
74 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
75 <div id="link-selector">
76         <div id="link-options">
77                 <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
78                 <div>
79                         <label for="url-field"><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" tabindex="10" autocomplete="off" /></label>
80                 </div>
81                 <div>
82                         <label for="link-title-field"><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" tabindex="20" autocomplete="off" /></label>
83                 </div>
84                 <div class="link-target">
85                         <label for="link-target-checkbox"><input type="checkbox" id="link-target-checkbox" tabindex="30" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
86                 </div>
87         </div>
88         <?php $show_internal = '1' == get_user_setting( 'wplink', '0' ); ?>
89         <p class="howto toggle-arrow <?php if ( $show_internal ) echo 'toggle-arrow-active'; ?>" id="internal-toggle"><?php _e( 'Or link to existing content' ); ?></p>
90         <div id="search-panel"<?php if ( ! $show_internal ) echo ' style="display:none"'; ?>>
91                 <div class="link-search-wrapper">
92                         <label for="search-field">
93                                 <span><?php _e( 'Search' ); ?></span>
94                                 <input type="text" id="search-field" class="link-search-field" tabindex="60" autocomplete="off" />
95                                 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
96                         </label>
97                 </div>
98                 <div id="search-results" class="query-results">
99                         <ul></ul>
100                         <div class="river-waiting">
101                                 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
102                         </div>
103                 </div>
104                 <div id="most-recent-results" class="query-results">
105                         <div class="query-notice"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></div>
106                         <ul></ul>
107                         <div class="river-waiting">
108                                 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
109                         </div>
110                 </div>
111         </div>
112 </div>
113 <div class="submitbox">
114         <div id="wp-link-cancel">
115                 <a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
116         </div>
117         <div id="wp-link-update">
118                 <?php submit_button( __('Update'), 'primary', 'wp-link-submit', false, array('tabindex' => 100)); ?>
119         </div>
120 </div>
121 </form>
122 <?php
123 }
124 ?>