2010-11-18 08:59:05 +01:00
< ? php
/**
* Internal linking functions .
*
2010-12-30 22:58:44 +01:00
* @ package WordPress
2010-11-18 08:59:05 +01:00
* @ subpackage Administration
* @ since 3.1 . 0
*/
/**
* Performs post queries for internal linking .
*
* @ since 3.1 . 0
*
* @ param array $args Optional . Accepts 'pagenum' and 's' ( search ) arguments .
* @ return array Results .
*/
function wp_link_query ( $args = array () ) {
2011-06-10 19:02:03 +02:00
$pts = get_post_types ( array ( 'public' => true ), 'objects' );
2010-11-18 08:59:05 +01:00
$pt_names = array_keys ( $pts );
$query = array (
'post_type' => $pt_names ,
'suppress_filters' => true ,
'update_post_term_cache' => false ,
'update_post_meta_cache' => false ,
'post_status' => 'publish' ,
'order' => 'DESC' ,
'orderby' => 'post_date' ,
'posts_per_page' => 20 ,
);
$args [ 'pagenum' ] = isset ( $args [ 'pagenum' ] ) ? absint ( $args [ 'pagenum' ] ) : 1 ;
if ( isset ( $args [ 's' ] ) )
$query [ 's' ] = $args [ 's' ];
$query [ 'offset' ] = $args [ 'pagenum' ] > 1 ? $query [ 'posts_per_page' ] * ( $args [ 'pagenum' ] - 1 ) : 0 ;
// Do main query.
$get_posts = new WP_Query ;
$posts = $get_posts -> query ( $query );
// Check if any posts were found.
if ( ! $get_posts -> post_count )
return false ;
// Build results.
$results = array ();
foreach ( $posts as $post ) {
if ( 'post' == $post -> post_type )
$info = mysql2date ( __ ( 'Y/m/d' ), $post -> post_date );
else
$info = $pts [ $post -> post_type ] -> labels -> singular_name ;
$results [] = array (
'ID' => $post -> ID ,
2010-12-08 01:22:43 +01:00
'title' => trim ( esc_html ( strip_tags ( get_the_title ( $post ) ) ) ),
2010-11-18 08:59:05 +01:00
'permalink' => get_permalink ( $post -> ID ),
'info' => $info ,
);
}
return $results ;
}
/**
* Dialog for internal linking .
*
* @ since 3.1 . 0
*/
function wp_link_dialog () {
?>
2010-11-24 07:44:46 +01:00
< form id = " wp-link " tabindex = " -1 " >
2011-01-11 21:03:50 +01:00
< ? php wp_nonce_field ( 'internal-linking' , '_ajax_linking_nonce' , false ); ?>
2010-11-18 08:59:05 +01:00
< div id = " link-selector " >
< div id = " link-options " >
2010-12-21 16:04:59 +01:00
< p class = " howto " >< ? php _e ( 'Enter the destination URL' ); ?> </p>
2010-11-18 08:59:05 +01:00
< div >
2011-06-09 00:39:08 +02:00
< label >< span >< ? php _e ( 'URL' ); ?> </span><input id="url-field" type="text" tabindex="10" name="href" /></label>
2010-11-18 08:59:05 +01:00
</ div >
< div >
2011-06-09 00:39:08 +02:00
< label >< span >< ? php _e ( 'Title' ); ?> </span><input id="link-title-field" type="text" tabindex="20" name="linktitle" /></label>
2010-11-18 08:59:05 +01:00
</ div >
< div class = " link-target " >
2011-06-09 00:39:08 +02:00
< label >< input type = " checkbox " id = " link-target-checkbox " tabindex = " 30 " /> < ? php _e ( 'Open link in a new window/tab' ); ?> </label>
2010-11-18 08:59:05 +01:00
</ div >
</ div >
2010-12-15 03:36:24 +01:00
< ? php $show_internal = '1' == get_user_setting ( 'wplink' , '0' ); ?>
2010-12-23 15:44:51 +01:00
< p class = " howto toggle-arrow <?php if ( $show_internal ) echo 'toggle-arrow-active'; ?> " id = " internal-toggle " >< ? php _e ( 'Or link to existing content' ); ?> </p>
2010-12-15 03:36:24 +01:00
< div id = " search-panel " < ? php if ( ! $show_internal ) echo ' style="display:none"' ; ?> >
2010-11-18 08:59:05 +01:00
< div class = " link-search-wrapper " >
2011-06-09 00:39:08 +02:00
< label >
2010-11-18 08:59:05 +01:00
< span >< ? php _e ( 'Search' ); ?> </span>
2010-11-24 07:44:46 +01:00
< input type = " text " id = " search-field " class = " link-search-field " tabindex = " 60 " autocomplete = " off " />
2010-11-18 08:59:05 +01:00
< img class = " waiting " src = " <?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?> " alt = " " />
</ label >
</ div >
< div id = " search-results " class = " query-results " >
2010-11-19 06:31:07 +01:00
< ul ></ ul >
2010-11-18 08:59:05 +01:00
< div class = " river-waiting " >
< img class = " waiting " src = " <?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?> " alt = " " />
</ div >
</ div >
< div id = " most-recent-results " class = " query-results " >
2010-11-19 06:31:07 +01:00
< div class = " query-notice " >< em >< ? php _e ( 'No search term specified. Showing recent items.' ); ?> </em></div>
< ul ></ ul >
2010-11-18 08:59:05 +01:00
< div class = " river-waiting " >
< img class = " waiting " src = " <?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?> " alt = " " />
</ div >
</ div >
</ div >
</ div >
< div class = " submitbox " >
< div id = " wp-link-cancel " >
< a class = " submitdelete deletion " href = " # " >< ? php _e ( 'Cancel' ); ?> </a>
</ div >
< div id = " wp-link-update " >
2010-11-24 07:44:46 +01:00
< ? php submit_button ( __ ( 'Update' ), 'primary' , 'wp-link-submit' , false , array ( 'tabindex' => 100 )); ?>
2010-11-18 08:59:05 +01:00
</ div >
</ div >
2010-11-24 07:44:46 +01:00
</ form >
2010-12-13 22:21:50 +01:00
< ? php
2010-11-18 08:59:05 +01:00
}
2011-06-09 00:39:08 +02:00
?>