2004-01-27 09:58:01 +00:00
|
|
|
<?php
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* WordPress Link Template Functions
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Template
|
|
|
|
*/
|
2004-01-27 09:58:01 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.2.0
|
|
|
|
* @uses apply_filters()
|
|
|
|
*/
|
2004-04-21 04:12:55 +00:00
|
|
|
function the_permalink() {
|
2005-01-14 23:43:20 +00:00
|
|
|
echo apply_filters('the_permalink', get_permalink());
|
2004-05-18 08:36:53 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 07:07:12 +00:00
|
|
|
/**
|
2008-10-13 22:00:07 +00:00
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
2007-02-15 07:07:12 +00:00
|
|
|
* Conditionally adds a trailing slash if the permalink structure
|
|
|
|
* has a trailing slash, strips the trailing slash if not
|
2008-10-13 22:00:07 +00:00
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.2.0
|
|
|
|
* @uses $wp_rewrite
|
|
|
|
*
|
2008-10-18 20:46:30 +00:00
|
|
|
* @param $string String a URL with or without a trailing slash
|
|
|
|
* @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter
|
2007-02-15 07:07:12 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2007-03-10 06:18:43 +00:00
|
|
|
function user_trailingslashit($string, $type_of_url = '') {
|
2007-02-15 07:07:12 +00:00
|
|
|
global $wp_rewrite;
|
|
|
|
if ( $wp_rewrite->use_trailing_slashes )
|
|
|
|
$string = trailingslashit($string);
|
|
|
|
else
|
2007-03-10 06:25:33 +00:00
|
|
|
$string = untrailingslashit($string);
|
2007-03-10 06:18:43 +00:00
|
|
|
|
|
|
|
// Note that $type_of_url can be one of following:
|
|
|
|
// single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
|
|
|
|
$string = apply_filters('user_trailingslashit', $string, $type_of_url);
|
2007-02-15 07:07:12 +00:00
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
* @param unknown_type $mode
|
|
|
|
*/
|
2004-01-27 09:58:01 +00:00
|
|
|
function permalink_anchor($mode = 'id') {
|
2005-10-17 23:41:28 +00:00
|
|
|
global $post;
|
|
|
|
switch ( strtolower($mode) ) {
|
|
|
|
case 'title':
|
2008-01-04 19:36:34 +00:00
|
|
|
$title = sanitize_title($post->post_title) . '-' . $post->ID;
|
2005-10-17 23:41:28 +00:00
|
|
|
echo '<a id="'.$title.'"></a>';
|
|
|
|
break;
|
|
|
|
case 'id':
|
|
|
|
default:
|
|
|
|
echo '<a id="post-' . $post->ID . '"></a>';
|
|
|
|
break;
|
|
|
|
}
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-01-17 16:51:32 +00:00
|
|
|
function get_permalink($id = 0, $leavename=false) {
|
2004-09-05 02:41:01 +00:00
|
|
|
$rewritecode = array(
|
|
|
|
'%year%',
|
|
|
|
'%monthnum%',
|
|
|
|
'%day%',
|
|
|
|
'%hour%',
|
|
|
|
'%minute%',
|
|
|
|
'%second%',
|
2008-01-17 16:51:32 +00:00
|
|
|
$leavename? '' : '%postname%',
|
2004-09-05 02:41:01 +00:00
|
|
|
'%post_id%',
|
|
|
|
'%category%',
|
|
|
|
'%author%',
|
2008-01-17 16:51:32 +00:00
|
|
|
$leavename? '' : '%pagename%',
|
2004-09-05 02:41:01 +00:00
|
|
|
);
|
2004-08-10 05:35:59 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
$post = &get_post($id);
|
2007-08-28 18:58:54 +00:00
|
|
|
|
|
|
|
if ( empty($post->ID) ) return FALSE;
|
|
|
|
|
2006-02-09 10:03:48 +00:00
|
|
|
if ( $post->post_type == 'page' )
|
2008-02-21 20:19:34 +00:00
|
|
|
return get_page_link($post->ID, $leavename);
|
2006-02-09 10:03:48 +00:00
|
|
|
elseif ($post->post_type == 'attachment')
|
2005-11-15 22:55:24 +00:00
|
|
|
return get_attachment_link($post->ID);
|
2004-11-12 23:08:51 +00:00
|
|
|
|
2006-08-30 21:46:31 +00:00
|
|
|
$permalink = get_option('permalink_structure');
|
2004-08-10 05:35:59 +00:00
|
|
|
|
2007-06-15 22:11:01 +00:00
|
|
|
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
|
2005-03-27 20:45:01 +00:00
|
|
|
$unixtime = strtotime($post->post_date);
|
2004-06-04 02:36:46 +00:00
|
|
|
|
2005-02-16 15:49:02 +00:00
|
|
|
$category = '';
|
2007-12-04 00:40:00 +00:00
|
|
|
if ( strpos($permalink, '%category%') !== false ) {
|
2005-03-27 20:45:01 +00:00
|
|
|
$cats = get_the_category($post->ID);
|
2007-05-29 04:54:45 +00:00
|
|
|
if ( $cats )
|
|
|
|
usort($cats, '_usort_terms_by_ID'); // order by ID
|
2007-05-28 18:47:08 +00:00
|
|
|
$category = $cats[0]->slug;
|
|
|
|
if ( $parent=$cats[0]->parent )
|
2005-10-17 23:41:28 +00:00
|
|
|
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
|
2005-01-25 05:01:54 +00:00
|
|
|
|
2008-04-08 01:55:04 +00:00
|
|
|
// show default category in permalinks, without
|
|
|
|
// having to assign it explicitly
|
|
|
|
if ( empty($category) ) {
|
|
|
|
$default_category = get_category( get_option( 'default_category' ) );
|
2008-08-09 05:36:14 +00:00
|
|
|
$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
|
2008-04-08 01:55:04 +00:00
|
|
|
}
|
2008-03-10 07:15:01 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 00:40:00 +00:00
|
|
|
$author = '';
|
|
|
|
if ( strpos($permalink, '%author%') !== false ) {
|
|
|
|
$authordata = get_userdata($post->post_author);
|
|
|
|
$author = $authordata->user_nicename;
|
|
|
|
}
|
|
|
|
|
2006-02-17 01:04:20 +00:00
|
|
|
$date = explode(" ",date('Y m d H i s', $unixtime));
|
2006-11-19 07:56:05 +00:00
|
|
|
$rewritereplace =
|
2004-09-05 02:41:01 +00:00
|
|
|
array(
|
2006-02-17 01:04:20 +00:00
|
|
|
$date[0],
|
|
|
|
$date[1],
|
|
|
|
$date[2],
|
|
|
|
$date[3],
|
|
|
|
$date[4],
|
|
|
|
$date[5],
|
2005-03-27 20:45:01 +00:00
|
|
|
$post->post_name,
|
|
|
|
$post->ID,
|
2004-09-05 02:41:01 +00:00
|
|
|
$category,
|
|
|
|
$author,
|
2005-03-27 20:45:01 +00:00
|
|
|
$post->post_name,
|
2004-09-05 02:41:01 +00:00
|
|
|
);
|
2007-03-10 06:18:43 +00:00
|
|
|
$permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
|
|
|
|
$permalink = user_trailingslashit($permalink, 'single');
|
2008-07-29 19:52:44 +00:00
|
|
|
return apply_filters('post_link', $permalink, $post, $leavename);
|
2004-09-05 02:41:01 +00:00
|
|
|
} else { // if they're not using the fancy permalink option
|
2006-08-30 21:46:31 +00:00
|
|
|
$permalink = get_option('home') . '/?p=' . $post->ID;
|
2008-07-29 19:52:44 +00:00
|
|
|
return apply_filters('post_link', $permalink, $post, $leavename);
|
2004-09-05 02:41:01 +00:00
|
|
|
}
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve permalink from post ID.
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $post_id
|
|
|
|
* @param unknown_type $deprecated
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-04-24 23:21:56 +00:00
|
|
|
function post_permalink($post_id = 0, $deprecated = '') {
|
2006-06-07 23:17:59 +00:00
|
|
|
return get_permalink($post_id);
|
|
|
|
}
|
|
|
|
|
2006-11-17 20:00:11 +00:00
|
|
|
// Respects page_on_front. Use this one.
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-02-21 20:19:34 +00:00
|
|
|
function get_page_link($id = false, $leavename = false) {
|
2006-11-17 20:00:11 +00:00
|
|
|
global $post;
|
|
|
|
|
2007-03-22 01:04:19 +00:00
|
|
|
$id = (int) $id;
|
2006-11-17 20:00:11 +00:00
|
|
|
if ( !$id )
|
2007-03-23 00:59:21 +00:00
|
|
|
$id = (int) $post->ID;
|
2006-11-17 20:00:11 +00:00
|
|
|
|
|
|
|
if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
|
|
|
|
$link = get_option('home');
|
|
|
|
else
|
2008-02-21 20:19:34 +00:00
|
|
|
$link = _get_page_link( $id , $leavename );
|
2006-11-17 20:00:11 +00:00
|
|
|
|
|
|
|
return apply_filters('page_link', $link, $id);
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* Ignores page_on_front. Internal use only.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access private
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-02-21 20:19:34 +00:00
|
|
|
function _get_page_link( $id = false, $leavename = false ) {
|
2004-12-03 02:38:11 +00:00
|
|
|
global $post, $wp_rewrite;
|
2004-10-06 02:18:37 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$id )
|
2007-03-23 00:59:21 +00:00
|
|
|
$id = (int) $post->ID;
|
2008-02-06 18:11:49 +00:00
|
|
|
else
|
|
|
|
$post = &get_post($id);
|
2004-10-06 02:18:37 +00:00
|
|
|
|
2005-01-26 22:46:40 +00:00
|
|
|
$pagestruct = $wp_rewrite->get_page_permastruct();
|
2004-10-06 02:18:37 +00:00
|
|
|
|
2008-01-10 20:51:07 +00:00
|
|
|
if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
|
2004-10-06 02:18:37 +00:00
|
|
|
$link = get_page_uri($id);
|
2008-02-21 20:19:34 +00:00
|
|
|
$link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
|
2007-02-15 07:07:12 +00:00
|
|
|
$link = get_option('home') . "/$link";
|
2007-03-10 06:18:43 +00:00
|
|
|
$link = user_trailingslashit($link, 'page');
|
2004-10-06 02:18:37 +00:00
|
|
|
} else {
|
2006-08-30 21:46:31 +00:00
|
|
|
$link = get_option('home') . "/?page_id=$id";
|
2004-10-06 02:18:37 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 20:00:11 +00:00
|
|
|
return apply_filters( '_get_page_link', $link, $id );
|
2004-10-06 02:18:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-11-15 22:55:24 +00:00
|
|
|
function get_attachment_link($id = false) {
|
2005-10-20 20:48:32 +00:00
|
|
|
global $post, $wp_rewrite;
|
|
|
|
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if (! $id) {
|
2007-03-23 00:59:21 +00:00
|
|
|
$id = (int) $post->ID;
|
2005-10-20 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$object = get_post($id);
|
2006-12-12 22:50:54 +00:00
|
|
|
if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
|
2005-10-20 20:48:32 +00:00
|
|
|
$parent = get_post($object->post_parent);
|
2006-11-17 20:00:11 +00:00
|
|
|
if ( 'page' == $parent->post_type )
|
|
|
|
$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
|
|
|
|
else
|
|
|
|
$parentlink = get_permalink( $object->post_parent );
|
2008-04-02 16:18:11 +00:00
|
|
|
if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
|
2008-03-21 03:08:22 +00:00
|
|
|
$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
|
|
|
|
else
|
|
|
|
$name = $object->post_name;
|
2007-03-07 05:29:15 +00:00
|
|
|
if (strpos($parentlink, '?') === false)
|
2008-05-19 18:51:28 +00:00
|
|
|
$link = user_trailingslashit( trailingslashit($parentlink) . $name );
|
2005-10-20 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $link ) {
|
2007-03-07 03:05:41 +00:00
|
|
|
$link = get_bloginfo('url') . "/?attachment_id=$id";
|
2005-10-20 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 22:55:24 +00:00
|
|
|
return apply_filters('attachment_link', $link, $id);
|
2005-10-20 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $year
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2004-11-19 20:54:16 +00:00
|
|
|
function get_year_link($year) {
|
2005-02-07 07:37:53 +00:00
|
|
|
global $wp_rewrite;
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$year )
|
2006-08-30 21:46:31 +00:00
|
|
|
$year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
$yearlink = $wp_rewrite->get_year_permastruct();
|
|
|
|
if ( !empty($yearlink) ) {
|
|
|
|
$yearlink = str_replace('%year%', $year, $yearlink);
|
2007-03-10 06:18:43 +00:00
|
|
|
return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
|
2005-10-17 23:41:28 +00:00
|
|
|
} else {
|
2006-08-30 21:46:31 +00:00
|
|
|
return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-11-19 20:54:16 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $year
|
|
|
|
* @param unknown_type $month
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2004-01-27 09:58:01 +00:00
|
|
|
function get_month_link($year, $month) {
|
2005-10-17 23:41:28 +00:00
|
|
|
global $wp_rewrite;
|
|
|
|
if ( !$year )
|
2006-08-30 21:46:31 +00:00
|
|
|
$year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$month )
|
2006-08-30 21:46:31 +00:00
|
|
|
$month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
$monthlink = $wp_rewrite->get_month_permastruct();
|
|
|
|
if ( !empty($monthlink) ) {
|
|
|
|
$monthlink = str_replace('%year%', $year, $monthlink);
|
|
|
|
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
|
2007-03-10 06:18:43 +00:00
|
|
|
return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
|
2005-10-17 23:41:28 +00:00
|
|
|
} else {
|
2006-08-30 21:46:31 +00:00
|
|
|
return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $year
|
|
|
|
* @param unknown_type $month
|
|
|
|
* @param unknown_type $day
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2004-01-27 09:58:01 +00:00
|
|
|
function get_day_link($year, $month, $day) {
|
2005-10-17 23:41:28 +00:00
|
|
|
global $wp_rewrite;
|
|
|
|
if ( !$year )
|
2006-08-30 21:46:31 +00:00
|
|
|
$year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$month )
|
2006-08-30 21:46:31 +00:00
|
|
|
$month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$day )
|
2006-08-30 21:46:31 +00:00
|
|
|
$day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
|
2005-10-17 23:41:28 +00:00
|
|
|
|
|
|
|
$daylink = $wp_rewrite->get_day_permastruct();
|
|
|
|
if ( !empty($daylink) ) {
|
|
|
|
$daylink = str_replace('%year%', $year, $daylink);
|
|
|
|
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
|
|
|
|
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
|
2007-03-10 06:18:43 +00:00
|
|
|
return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
|
2005-10-17 23:41:28 +00:00
|
|
|
} else {
|
2006-08-30 21:46:31 +00:00
|
|
|
return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-06-02 07:14:03 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $feed
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-06 19:58:15 +00:00
|
|
|
function get_feed_link($feed = '') {
|
2004-12-03 02:38:11 +00:00
|
|
|
global $wp_rewrite;
|
2004-06-02 07:14:03 +00:00
|
|
|
|
2005-01-26 22:46:40 +00:00
|
|
|
$permalink = $wp_rewrite->get_feed_permastruct();
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( '' != $permalink ) {
|
2005-01-26 22:46:40 +00:00
|
|
|
if ( false !== strpos($feed, 'comments_') ) {
|
|
|
|
$feed = str_replace('comments_', '', $feed);
|
|
|
|
$permalink = $wp_rewrite->get_comment_feed_permastruct();
|
|
|
|
}
|
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
if ( get_default_feed() == $feed )
|
2005-01-26 22:46:40 +00:00
|
|
|
$feed = '';
|
|
|
|
|
|
|
|
$permalink = str_replace('%feed%', $feed, $permalink);
|
2007-02-15 07:07:12 +00:00
|
|
|
$permalink = preg_replace('#/+#', '/', "/$permalink");
|
2007-03-10 06:18:43 +00:00
|
|
|
$output = get_option('home') . user_trailingslashit($permalink, 'feed');
|
2005-01-26 22:46:40 +00:00
|
|
|
} else {
|
2007-12-06 19:58:15 +00:00
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
2005-01-26 22:46:40 +00:00
|
|
|
if ( false !== strpos($feed, 'comments_') )
|
2005-02-26 06:12:16 +00:00
|
|
|
$feed = str_replace('comments_', 'comments-', $feed);
|
2005-01-26 22:46:40 +00:00
|
|
|
|
2006-08-30 21:46:31 +00:00
|
|
|
$output = get_option('home') . "/?feed={$feed}";
|
2005-01-26 22:46:40 +00:00
|
|
|
}
|
2004-06-02 07:14:03 +00:00
|
|
|
|
2005-02-06 03:40:08 +00:00
|
|
|
return apply_filters('feed_link', $output, $feed);
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.2.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $post_id
|
|
|
|
* @param unknown_type $feed
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-06 19:58:15 +00:00
|
|
|
function get_post_comments_feed_link($post_id = '', $feed = '') {
|
2007-02-23 08:31:07 +00:00
|
|
|
global $id;
|
|
|
|
|
|
|
|
if ( empty($post_id) )
|
2007-03-23 00:59:21 +00:00
|
|
|
$post_id = (int) $id;
|
2007-02-23 08:31:07 +00:00
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
2007-02-23 08:31:07 +00:00
|
|
|
if ( '' != get_option('permalink_structure') ) {
|
2007-08-22 22:42:57 +00:00
|
|
|
$url = trailingslashit( get_permalink($post_id) ) . 'feed';
|
2007-12-06 19:58:15 +00:00
|
|
|
if ( $feed != get_default_feed() )
|
2007-02-23 08:31:07 +00:00
|
|
|
$url .= "/$feed";
|
2007-03-10 06:18:43 +00:00
|
|
|
$url = user_trailingslashit($url, 'single_feed');
|
2007-02-23 08:31:07 +00:00
|
|
|
} else {
|
2007-08-22 22:42:57 +00:00
|
|
|
$type = get_post_field('post_type', $post_id);
|
|
|
|
if ( 'page' == $type )
|
|
|
|
$url = get_option('home') . "/?feed=$feed&page_id=$post_id";
|
|
|
|
else
|
|
|
|
$url = get_option('home') . "/?feed=$feed&p=$post_id";
|
2007-02-23 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 15:24:54 +00:00
|
|
|
return apply_filters('post_comments_feed_link', $url);
|
2007-02-23 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Display the comment feed link for a post.
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* Prints out the comment feed link for a post. Link text is placed in the
|
|
|
|
* anchor. If no link text is specified, default text is used. If no post ID is
|
|
|
|
* specified, the current post is used.
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.5.0
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
2008-10-18 20:46:30 +00:00
|
|
|
* @param string $link_text Descriptive text.
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param int $post_id Optional post ID. Default to current post.
|
2008-10-18 20:46:30 +00:00
|
|
|
* @param string $feed Optional. Feed format.
|
|
|
|
* @return string Link to the comment feed for the current post.
|
2007-12-06 19:58:15 +00:00
|
|
|
*/
|
|
|
|
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
|
|
|
|
$url = get_post_comments_feed_link($post_id, $feed);
|
|
|
|
if ( empty($link_text) )
|
|
|
|
$link_text = __('Comments Feed');
|
|
|
|
|
|
|
|
echo "<a href='$url'>$link_text</a>";
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the feed link for a given author.
|
2008-08-22 02:21:37 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* Returns a link to the feed for all posts by a given author. A specific feed
|
|
|
|
* can be requested or left blank to get the default feed.
|
2008-08-22 02:21:37 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.5.0
|
2008-08-22 02:21:37 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param int $author_id ID of an author.
|
|
|
|
* @param string $feed Feed type.
|
|
|
|
* @return string Link to the feed for the author specified by $author_id.
|
2008-08-22 02:21:37 +00:00
|
|
|
*/
|
2007-12-06 19:58:15 +00:00
|
|
|
function get_author_feed_link( $author_id, $feed = '' ) {
|
|
|
|
$author_id = (int) $author_id;
|
|
|
|
$permalink_structure = get_option('permalink_structure');
|
|
|
|
|
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
|
|
|
if ( '' == $permalink_structure ) {
|
2008-08-22 02:21:37 +00:00
|
|
|
$link = get_option('home') . "?feed=$feed&author=" . $author_id;
|
2007-12-06 19:58:15 +00:00
|
|
|
} else {
|
2008-01-04 19:36:34 +00:00
|
|
|
$link = get_author_posts_url($author_id);
|
2008-08-22 02:21:37 +00:00
|
|
|
if ( $feed == get_default_feed() )
|
|
|
|
$feed_link = 'feed';
|
|
|
|
else
|
|
|
|
$feed_link = "feed/$feed";
|
|
|
|
|
|
|
|
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
|
2007-12-06 19:58:15 +00:00
|
|
|
}
|
|
|
|
|
2008-08-22 02:21:37 +00:00
|
|
|
$link = apply_filters('author_feed_link', $link, $feed);
|
2007-12-06 19:58:15 +00:00
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the feed link for a category.
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* Returns a link to the feed for all post in a given category. A specific feed
|
|
|
|
* can be requested or left blank to get the default feed.
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.5.0
|
2007-12-06 19:58:15 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param int $cat_id ID of a category.
|
|
|
|
* @param string $feed Feed type.
|
|
|
|
* @return string Link to the feed for the category specified by $cat_id.
|
2007-12-06 19:58:15 +00:00
|
|
|
*/
|
|
|
|
function get_category_feed_link($cat_id, $feed = '') {
|
|
|
|
$cat_id = (int) $cat_id;
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
$category = get_category($cat_id);
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
if ( empty($category) || is_wp_error($category) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
|
|
|
$permalink_structure = get_option('permalink_structure');
|
|
|
|
|
|
|
|
if ( '' == $permalink_structure ) {
|
|
|
|
$link = get_option('home') . "?feed=$feed&cat=" . $cat_id;
|
|
|
|
} else {
|
|
|
|
$link = get_category_link($cat_id);
|
|
|
|
if( $feed == get_default_feed() )
|
|
|
|
$feed_link = 'feed';
|
|
|
|
else
|
|
|
|
$feed_link = "feed/$feed";
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = apply_filters('category_feed_link', $link, $feed);
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-06 19:58:15 +00:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $tag_id
|
|
|
|
* @param unknown_type $feed
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-06 19:58:15 +00:00
|
|
|
function get_tag_feed_link($tag_id, $feed = '') {
|
|
|
|
$tag_id = (int) $tag_id;
|
|
|
|
|
|
|
|
$tag = get_tag($tag_id);
|
|
|
|
|
|
|
|
if ( empty($tag) || is_wp_error($tag) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$permalink_structure = get_option('permalink_structure');
|
|
|
|
|
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
|
|
|
if ( '' == $permalink_structure ) {
|
|
|
|
$link = get_option('home') . "?feed=$feed&tag=" . $tag->slug;
|
|
|
|
} else {
|
|
|
|
$link = get_tag_link($tag->term_id);
|
|
|
|
if ( $feed == get_default_feed() )
|
|
|
|
$feed_link = 'feed';
|
|
|
|
else
|
|
|
|
$feed_link = "feed/$feed";
|
2008-05-27 17:56:46 +00:00
|
|
|
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
|
2007-12-06 19:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$link = apply_filters('tag_feed_link', $link, $feed);
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $search_query
|
|
|
|
* @param unknown_type $feed
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-19 18:05:21 +00:00
|
|
|
function get_search_feed_link($search_query = '', $feed = '') {
|
|
|
|
if ( empty($search_query) )
|
|
|
|
$search = attribute_escape(get_search_query());
|
|
|
|
else
|
|
|
|
$search = attribute_escape(stripslashes($search_query));
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
$link = get_option('home') . "?s=$search&feed=$feed";
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
$link = apply_filters('search_feed_link', $link);
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $search_query
|
|
|
|
* @param unknown_type $feed
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-19 18:05:21 +00:00
|
|
|
function get_search_comments_feed_link($search_query = '', $feed = '') {
|
|
|
|
if ( empty($search_query) )
|
|
|
|
$search = attribute_escape(get_search_query());
|
|
|
|
else
|
|
|
|
$search = attribute_escape(stripslashes($search_query));
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
$link = get_option('home') . "?s=$search&feed=comments-$feed";
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
$link = apply_filters('search_feed_link', $link);
|
2008-02-05 06:47:27 +00:00
|
|
|
|
2007-12-19 18:05:21 +00:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-04-18 23:38:21 +00:00
|
|
|
function get_edit_post_link( $id = 0, $context = 'display' ) {
|
2008-03-12 05:50:07 +00:00
|
|
|
if ( !$post = &get_post( $id ) )
|
|
|
|
return;
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2008-04-18 23:38:21 +00:00
|
|
|
if ( 'display' == $context )
|
|
|
|
$action = 'action=edit&';
|
|
|
|
else
|
|
|
|
$action = 'action=edit&';
|
|
|
|
|
2008-03-12 05:50:07 +00:00
|
|
|
switch ( $post->post_type ) :
|
|
|
|
case 'page' :
|
2007-04-24 23:21:56 +00:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
2006-02-22 19:17:28 +00:00
|
|
|
return;
|
|
|
|
$file = 'page';
|
2008-03-12 05:50:07 +00:00
|
|
|
$var = 'post';
|
|
|
|
break;
|
|
|
|
case 'attachment' :
|
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
|
|
return;
|
|
|
|
$file = 'media';
|
|
|
|
$var = 'attachment_id';
|
|
|
|
break;
|
2008-04-18 23:38:21 +00:00
|
|
|
case 'revision' :
|
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
|
|
return;
|
|
|
|
$file = 'revision';
|
|
|
|
$var = 'revision';
|
|
|
|
$action = '';
|
|
|
|
break;
|
2008-03-12 05:50:07 +00:00
|
|
|
default :
|
2007-04-24 23:21:56 +00:00
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
2006-02-22 19:17:28 +00:00
|
|
|
return;
|
2005-12-13 19:19:56 +00:00
|
|
|
$file = 'post';
|
2008-03-12 05:50:07 +00:00
|
|
|
$var = 'post';
|
|
|
|
break;
|
|
|
|
endswitch;
|
2008-08-09 05:36:14 +00:00
|
|
|
|
2008-07-28 23:39:15 +00:00
|
|
|
return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $before
|
|
|
|
* @param unknown_type $after
|
|
|
|
*/
|
2007-04-24 23:21:56 +00:00
|
|
|
function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
|
|
|
|
global $post;
|
2007-04-27 03:51:36 +00:00
|
|
|
|
2008-03-11 21:08:09 +00:00
|
|
|
if ( $post->post_type == 'page' ) {
|
2007-04-27 03:51:36 +00:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-24 23:21:56 +00:00
|
|
|
$link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . __( 'Edit post' ) . '">' . $link . '</a>';
|
|
|
|
echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
|
|
|
|
}
|
2007-04-17 23:00:35 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $comment_id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-04-24 23:21:56 +00:00
|
|
|
function get_edit_comment_link( $comment_id = 0 ) {
|
|
|
|
$comment = &get_comment( $comment_id );
|
|
|
|
$post = &get_post( $comment->comment_post_ID );
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2008-03-11 21:08:09 +00:00
|
|
|
if ( $post->post_type == 'page' ) {
|
2007-04-24 23:21:56 +00:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
2006-02-22 19:17:28 +00:00
|
|
|
return;
|
2007-04-28 16:45:47 +00:00
|
|
|
} else {
|
2007-04-24 23:21:56 +00:00
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
2006-02-22 19:17:28 +00:00
|
|
|
return;
|
2007-04-28 16:45:47 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 04:46:59 +00:00
|
|
|
$location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID;
|
2007-04-24 23:21:56 +00:00
|
|
|
return apply_filters( 'get_edit_comment_link', $location );
|
|
|
|
}
|
2004-01-27 09:58:01 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $before
|
|
|
|
* @param unknown_type $after
|
|
|
|
*/
|
2008-09-11 19:25:50 +00:00
|
|
|
function edit_comment_link( $link = 'Edit This', $before = '', $after = '', $echo = true ) {
|
2007-04-27 03:51:36 +00:00
|
|
|
global $comment, $post;
|
|
|
|
|
2007-04-28 16:45:47 +00:00
|
|
|
if ( $post->post_type == 'attachment' ) {
|
|
|
|
} elseif ( $post->post_type == 'page' ) {
|
2007-04-27 03:51:36 +00:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
|
|
|
return;
|
2007-04-28 16:45:47 +00:00
|
|
|
} else {
|
2007-04-27 03:51:36 +00:00
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
|
|
return;
|
2007-04-28 16:45:47 +00:00
|
|
|
}
|
2007-04-27 03:51:36 +00:00
|
|
|
|
2007-04-24 23:21:56 +00:00
|
|
|
$link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
|
2008-09-11 19:25:50 +00:00
|
|
|
$link = $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
|
|
|
|
if ( $echo )
|
|
|
|
echo $link;
|
|
|
|
else
|
|
|
|
return $link;
|
2004-01-27 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-08-27 22:04:12 +00:00
|
|
|
function get_edit_bookmark_link( $link = 0 ) {
|
|
|
|
$link = &get_bookmark( $link );
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_links') )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$location = admin_url('link.php?action=edit&link_id=') . $link->link_id;
|
|
|
|
return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $before
|
|
|
|
* @param unknown_type $after
|
|
|
|
* @param unknown_type $bookmark
|
|
|
|
*/
|
2008-08-27 22:04:12 +00:00
|
|
|
function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
|
|
|
|
$bookmark = get_bookmark($bookmark);
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_links') )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( empty($link) )
|
|
|
|
$link = __('Edit This');
|
|
|
|
|
|
|
|
$link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
|
|
|
|
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
|
|
|
|
}
|
|
|
|
|
2004-06-02 07:44:43 +00:00
|
|
|
// Navigation links
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2004-08-24 01:35:57 +00:00
|
|
|
function get_previous_post($in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 09:25:45 +00:00
|
|
|
return get_adjacent_post($in_same_cat, $excluded_categories);
|
2004-08-24 01:35:57 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2004-08-24 01:35:57 +00:00
|
|
|
function get_next_post($in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 09:25:45 +00:00
|
|
|
return get_adjacent_post($in_same_cat, $excluded_categories, false);
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
* @param unknown_type $previous
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-12-05 09:25:45 +00:00
|
|
|
function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
|
2005-04-18 21:47:35 +00:00
|
|
|
global $post, $wpdb;
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2007-09-20 18:25:14 +00:00
|
|
|
if( empty($post) || !is_single() || is_attachment() )
|
2005-04-18 21:47:35 +00:00
|
|
|
return null;
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2005-04-18 21:47:35 +00:00
|
|
|
$current_post_date = $post->post_date;
|
2006-02-12 07:53:23 +00:00
|
|
|
|
2005-04-18 21:47:35 +00:00
|
|
|
$join = '';
|
2008-02-02 18:42:09 +00:00
|
|
|
$posts_in_ex_cats_sql = '';
|
2007-12-05 09:25:45 +00:00
|
|
|
if ( $in_same_cat || !empty($excluded_categories) ) {
|
|
|
|
$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
|
|
|
|
|
|
|
|
if ( $in_same_cat ) {
|
|
|
|
$cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
|
2008-09-15 11:08:47 +00:00
|
|
|
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
|
2005-04-18 21:47:35 +00:00
|
|
|
}
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2007-12-05 09:25:45 +00:00
|
|
|
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
|
|
|
|
if ( !empty($excluded_categories) ) {
|
|
|
|
$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
|
|
|
|
if ( !empty($cat_array) ) {
|
|
|
|
$excluded_categories = array_diff($excluded_categories, $cat_array);
|
|
|
|
$posts_in_ex_cats_sql = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($excluded_categories) ) {
|
2008-04-14 17:56:58 +00:00
|
|
|
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
|
2007-12-05 09:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-18 21:47:35 +00:00
|
|
|
}
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2007-12-05 09:25:45 +00:00
|
|
|
$adjacent = $previous ? 'previous' : 'next';
|
|
|
|
$op = $previous ? '<' : '>';
|
|
|
|
$order = $previous ? 'DESC' : 'ASC';
|
2007-01-11 04:30:44 +00:00
|
|
|
|
2007-12-05 09:25:45 +00:00
|
|
|
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
|
|
|
|
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
|
|
|
|
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2007-12-05 09:25:45 +00:00
|
|
|
return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
|
|
|
|
}
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $format
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
*/
|
2005-10-17 23:41:28 +00:00
|
|
|
function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 09:25:45 +00:00
|
|
|
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
|
2004-08-24 01:35:57 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $format
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
*/
|
2004-08-24 01:35:57 +00:00
|
|
|
function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 09:25:45 +00:00
|
|
|
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $format
|
|
|
|
* @param unknown_type $link
|
|
|
|
* @param unknown_type $in_same_cat
|
|
|
|
* @param unknown_type $excluded_categories
|
|
|
|
* @param unknown_type $previous
|
|
|
|
*/
|
2007-12-05 09:25:45 +00:00
|
|
|
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
|
|
|
|
if ( $previous && is_attachment() )
|
|
|
|
$post = & get_post($GLOBALS['post']->post_parent);
|
|
|
|
else
|
|
|
|
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$post )
|
|
|
|
return;
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2007-09-11 20:05:52 +00:00
|
|
|
$title = $post->post_title;
|
|
|
|
|
|
|
|
if ( empty($post->post_title) )
|
2007-12-05 09:25:45 +00:00
|
|
|
$title = $previous ? __('Previous Post') : __('Next Post');
|
2007-09-11 20:05:52 +00:00
|
|
|
|
|
|
|
$title = apply_filters('the_title', $title, $post);
|
2008-09-15 23:48:24 +00:00
|
|
|
$date = mysql2date(get_option('date_format'), $post->post_date);
|
|
|
|
|
2007-12-05 09:25:45 +00:00
|
|
|
$string = '<a href="'.get_permalink($post).'">';
|
2005-10-17 23:41:28 +00:00
|
|
|
$link = str_replace('%title', $title, $link);
|
2008-09-15 23:48:24 +00:00
|
|
|
$link = str_replace('%date', $date, $link);
|
2005-10-17 23:41:28 +00:00
|
|
|
$link = $string . $link . '</a>';
|
2007-12-05 09:25:45 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
$format = str_replace('%link', $link, $format);
|
2004-08-24 01:35:57 +00:00
|
|
|
|
2008-06-16 22:27:07 +00:00
|
|
|
$adjacent = $previous ? 'previous' : 'next';
|
|
|
|
echo apply_filters( "{$adjacent}_post_link", $format, $link );
|
2004-08-24 01:35:57 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
|
|
|
* @param unknown_type $pagenum
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-03-28 02:34:16 +00:00
|
|
|
function get_pagenum_link($pagenum = 1) {
|
2004-12-03 02:38:11 +00:00
|
|
|
global $wp_rewrite;
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-12 00:17:34 +00:00
|
|
|
$pagenum = (int) $pagenum;
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-12 00:17:34 +00:00
|
|
|
$request = remove_query_arg( 'paged' );
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2006-08-30 21:46:31 +00:00
|
|
|
$home_root = parse_url(get_option('home'));
|
2008-01-10 20:51:07 +00:00
|
|
|
$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
|
2007-05-12 00:17:34 +00:00
|
|
|
$home_root = preg_quote( trailingslashit( $home_root ), '|' );
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-16 02:47:24 +00:00
|
|
|
$request = preg_replace('|^'. $home_root . '|', '', $request);
|
|
|
|
$request = preg_replace('|^/+|', '', $request);
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-28 18:34:06 +00:00
|
|
|
if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
|
2007-05-12 00:17:34 +00:00
|
|
|
$base = trailingslashit( get_bloginfo( 'home' ) );
|
2007-05-28 18:34:06 +00:00
|
|
|
|
2007-05-12 00:17:34 +00:00
|
|
|
if ( $pagenum > 1 ) {
|
2007-05-16 02:47:24 +00:00
|
|
|
$result = add_query_arg( 'paged', $pagenum, $base . $request );
|
2007-05-12 00:17:34 +00:00
|
|
|
} else {
|
|
|
|
$result = $base . $request;
|
|
|
|
}
|
2005-03-28 02:34:16 +00:00
|
|
|
} else {
|
2007-05-12 00:17:34 +00:00
|
|
|
$qs_regex = '|\?.*?$|';
|
|
|
|
preg_match( $qs_regex, $request, $qs_match );
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2008-02-02 18:42:09 +00:00
|
|
|
if ( !empty( $qs_match[0] ) ) {
|
2007-05-12 00:17:34 +00:00
|
|
|
$query_string = $qs_match[0];
|
|
|
|
$request = preg_replace( $qs_regex, '', $request );
|
2005-03-28 02:34:16 +00:00
|
|
|
} else {
|
2007-05-12 00:17:34 +00:00
|
|
|
$query_string = '';
|
2005-03-28 02:34:16 +00:00
|
|
|
}
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-12-19 19:27:14 +00:00
|
|
|
$request = preg_replace( '|page/\d+/?$|', '', $request);
|
2007-09-20 20:56:22 +00:00
|
|
|
$request = preg_replace( '|^index\.php|', '', $request);
|
|
|
|
$request = ltrim($request, '/');
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-16 02:47:24 +00:00
|
|
|
$base = trailingslashit( get_bloginfo( 'url' ) );
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-09-22 06:07:03 +00:00
|
|
|
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
|
2007-05-12 00:17:34 +00:00
|
|
|
$base .= 'index.php/';
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-16 02:47:24 +00:00
|
|
|
if ( $pagenum > 1 ) {
|
|
|
|
$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
|
|
|
|
}
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2007-05-12 00:17:34 +00:00
|
|
|
$result = $base . $request . $query_string;
|
2005-03-28 02:34:16 +00:00
|
|
|
}
|
2007-06-14 02:25:30 +00:00
|
|
|
|
2008-02-25 18:40:46 +00:00
|
|
|
$result = apply_filters('get_pagenum_link', $result);
|
|
|
|
|
2007-05-12 00:17:34 +00:00
|
|
|
return $result;
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
* Backported from 2.1.3 to 2.0.10.
|
|
|
|
*
|
|
|
|
* @since 2.0.10
|
|
|
|
*
|
|
|
|
* @param unknown_type $max_page
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-03-16 08:04:24 +00:00
|
|
|
function get_next_posts_page_link($max_page = 0) {
|
2007-12-06 19:49:33 +00:00
|
|
|
global $paged;
|
2005-10-17 23:41:28 +00:00
|
|
|
|
|
|
|
if ( !is_single() ) {
|
|
|
|
if ( !$paged )
|
|
|
|
$paged = 1;
|
|
|
|
$nextpage = intval($paged) + 1;
|
|
|
|
if ( !$max_page || $max_page >= $nextpage )
|
2007-03-16 08:04:24 +00:00
|
|
|
return get_pagenum_link($nextpage);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
* @param unknown_type $max_page
|
|
|
|
*/
|
2007-03-16 08:04:24 +00:00
|
|
|
function next_posts($max_page = 0) {
|
2007-03-17 08:46:59 +00:00
|
|
|
echo clean_url(get_next_posts_page_link($max_page));
|
2007-03-16 08:04:24 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
* @param unknown_type $label
|
|
|
|
* @param unknown_type $max_page
|
|
|
|
*/
|
2004-06-02 07:44:43 +00:00
|
|
|
function next_posts_link($label='Next Page »', $max_page=0) {
|
2007-12-06 19:49:33 +00:00
|
|
|
global $paged, $wp_query;
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !$max_page ) {
|
2006-11-08 21:22:35 +00:00
|
|
|
$max_page = $wp_query->max_num_pages;
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
|
|
|
if ( !$paged )
|
|
|
|
$paged = 1;
|
|
|
|
$nextpage = intval($paged) + 1;
|
|
|
|
if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) {
|
|
|
|
echo '<a href="';
|
|
|
|
next_posts($max_page);
|
2008-07-30 07:01:03 +00:00
|
|
|
$attr = apply_filters( 'next_posts_link_attributes', '' );
|
|
|
|
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 2.0.10 Backported
|
|
|
|
* @since 2.1.3
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2007-03-16 08:04:24 +00:00
|
|
|
function get_previous_posts_page_link() {
|
2007-12-06 19:49:33 +00:00
|
|
|
global $paged;
|
2004-06-02 07:44:43 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( !is_single() ) {
|
|
|
|
$nextpage = intval($paged) - 1;
|
|
|
|
if ( $nextpage < 1 )
|
|
|
|
$nextpage = 1;
|
2007-03-16 08:04:24 +00:00
|
|
|
return get_pagenum_link($nextpage);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
*/
|
2007-03-16 08:04:24 +00:00
|
|
|
function previous_posts() {
|
2007-03-17 08:46:59 +00:00
|
|
|
echo clean_url(get_previous_posts_page_link());
|
2007-03-16 08:04:24 +00:00
|
|
|
}
|
2005-10-17 23:41:28 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
* @param unknown_type $label
|
|
|
|
*/
|
2004-06-02 07:44:43 +00:00
|
|
|
function previous_posts_link($label='« Previous Page') {
|
2005-10-17 23:41:28 +00:00
|
|
|
global $paged;
|
|
|
|
if ( (!is_single()) && ($paged > 1) ) {
|
|
|
|
echo '<a href="';
|
|
|
|
previous_posts();
|
2008-07-30 07:01:03 +00:00
|
|
|
$attr = apply_filters( 'previous_posts_link_attributes', '' );
|
|
|
|
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
*
|
|
|
|
* @param unknown_type $sep
|
|
|
|
* @param unknown_type $prelabel
|
|
|
|
* @param unknown_type $nxtlabel
|
|
|
|
*/
|
2004-06-02 07:44:43 +00:00
|
|
|
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
|
2006-11-08 21:22:35 +00:00
|
|
|
global $wp_query;
|
|
|
|
if ( !is_singular() ) {
|
|
|
|
$max_num_pages = $wp_query->max_num_pages;
|
2006-03-20 19:43:57 +00:00
|
|
|
$paged = get_query_var('paged');
|
2006-11-19 07:56:05 +00:00
|
|
|
|
2006-03-20 19:43:57 +00:00
|
|
|
//only have sep if there's both prev and next results
|
|
|
|
if ($paged < 2 || $paged >= $max_num_pages) {
|
|
|
|
$sep = '';
|
2004-10-12 13:04:35 +00:00
|
|
|
}
|
2004-08-16 22:50:06 +00:00
|
|
|
|
2005-10-17 23:41:28 +00:00
|
|
|
if ( $max_num_pages > 1 ) {
|
|
|
|
previous_posts_link($prelabel);
|
|
|
|
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
|
2006-03-20 19:43:57 +00:00
|
|
|
next_posts_link($nxtlabel);
|
2005-10-17 23:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-02 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-23 21:11:27 +00:00
|
|
|
function get_comments_pagenum_link($pagenum = 1) {
|
|
|
|
global $wp_rewrite;
|
|
|
|
|
|
|
|
$pagenum = (int) $pagenum;
|
|
|
|
|
|
|
|
$request = remove_query_arg( 'cpage' );
|
|
|
|
|
|
|
|
$home_root = parse_url(get_option('home'));
|
|
|
|
$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
|
|
|
|
$home_root = preg_quote( trailingslashit( $home_root ), '|' );
|
|
|
|
|
|
|
|
$request = preg_replace('|^'. $home_root . '|', '', $request);
|
|
|
|
$request = preg_replace('|^/+|', '', $request);
|
|
|
|
|
|
|
|
$base = trailingslashit( get_bloginfo( 'home' ) );
|
|
|
|
|
|
|
|
if ( $pagenum > 1 ) {
|
|
|
|
$result = add_query_arg( 'cpage', $pagenum, $base . $request );
|
|
|
|
} else {
|
|
|
|
$result = $base . $request;
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:41:51 +00:00
|
|
|
$result .= '#comments';
|
|
|
|
|
2008-09-23 21:11:27 +00:00
|
|
|
$result = apply_filters('get_comments_pagenum_link', $result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function next_comments_link($label='', $max_page = 0) {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
if ( !is_singular() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$page = get_query_var('cpage');
|
|
|
|
|
|
|
|
if ( !$page )
|
|
|
|
$page = 1;
|
|
|
|
|
|
|
|
$nextpage = intval($page) + 1;
|
|
|
|
|
|
|
|
if ( empty($max_page) )
|
|
|
|
$max_page = $wp_query->max_num_comment_pages;
|
|
|
|
|
|
|
|
if ( $nextpage > $max_page )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( empty($label) )
|
|
|
|
$label = __('» Newer Comments');
|
|
|
|
|
|
|
|
echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
|
|
|
|
$attr = apply_filters( 'next_comments_link_attributes', '' );
|
|
|
|
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
function previous_comments_link($label='') {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
if ( !is_singular() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$page = get_query_var('cpage');
|
|
|
|
|
2008-10-07 22:41:51 +00:00
|
|
|
if ( !$page )
|
|
|
|
$page = 1;
|
|
|
|
|
2008-09-23 21:11:27 +00:00
|
|
|
if ( $page <= 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$nextpage = intval($page) - 1;
|
|
|
|
|
|
|
|
if ( empty($label) )
|
|
|
|
$label = __('« Older Comments');
|
|
|
|
|
|
|
|
echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
|
|
|
|
$attr = apply_filters( 'previous_comments_link_attributes', '' );
|
|
|
|
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:41:51 +00:00
|
|
|
/** Create pagination links for the comments on the current post
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @see paginate_links
|
|
|
|
* @since 2.7
|
|
|
|
*
|
|
|
|
* @param string|array $args Optional args. See paginate_links.
|
|
|
|
* @return string Markup for pagination links
|
|
|
|
*/
|
|
|
|
function paginate_comments_links($args = array()) {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
if ( !is_singular() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$page = get_query_var('cpage');
|
|
|
|
if ( !$page )
|
|
|
|
$page = 1;
|
|
|
|
$max_page = $wp_query->max_num_comment_pages;
|
|
|
|
$defaults = array(
|
|
|
|
'base' => add_query_arg( 'cpage', '%#%' ),
|
|
|
|
'format' => '',
|
|
|
|
'total' => $max_page,
|
|
|
|
'current' => $page,
|
|
|
|
'echo' => true,
|
|
|
|
'add_fragment' => '#comments'
|
|
|
|
);
|
|
|
|
$args = wp_parse_args( $args, $defaults );
|
|
|
|
$page_links = paginate_links( $args );
|
|
|
|
|
|
|
|
if ( $args['echo'] )
|
|
|
|
echo $page_links;
|
|
|
|
else
|
|
|
|
return $page_links;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* {@internal Missing Long Description}}
|
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-05-12 19:08:39 +00:00
|
|
|
function get_shortcut_link() {
|
|
|
|
$link = "javascript:
|
2008-07-13 04:57:01 +00:00
|
|
|
var d=document,
|
|
|
|
w=window,
|
|
|
|
e=w.getSelection,
|
|
|
|
k=d.getSelection,
|
|
|
|
x=d.selection,
|
|
|
|
s=(e?e():(k)?k():(x?x.createRange().text:0)),
|
|
|
|
f='" . admin_url('press-this.php') . "',
|
|
|
|
l=d.location,
|
|
|
|
e=encodeURIComponent,
|
|
|
|
g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';
|
2008-05-13 16:02:12 +00:00
|
|
|
function a(){
|
|
|
|
if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=700,height=500')){
|
|
|
|
l.href=g;
|
|
|
|
}
|
2008-07-10 16:54:32 +00:00
|
|
|
}";
|
|
|
|
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)
|
|
|
|
$link .= 'setTimeout(a,0);';
|
|
|
|
else
|
|
|
|
$link .= 'a();';
|
|
|
|
|
|
|
|
$link .= "void(0);";
|
2008-05-13 16:02:12 +00:00
|
|
|
|
|
|
|
$link = str_replace(array("\r", "\n", "\t"), '', $link);
|
2008-05-12 19:08:39 +00:00
|
|
|
|
|
|
|
return apply_filters('shortcut_link', $link);
|
|
|
|
}
|
2008-05-27 17:46:01 +00:00
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the site url.
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* Returns the 'site_url' option with the appropriate protocol, 'https' if
|
|
|
|
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
|
|
|
|
* overridden.
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.6.0
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param string $path Optional. Path relative to the site url.
|
|
|
|
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
|
|
|
|
* @return string Site url link with optional path appended.
|
2008-07-14 23:39:11 +00:00
|
|
|
*/
|
2008-05-27 17:46:01 +00:00
|
|
|
function site_url($path = '', $scheme = null) {
|
|
|
|
// should the list of allowed schemes be maintained elsewhere?
|
2008-08-19 19:41:11 +00:00
|
|
|
$orig_scheme = $scheme;
|
2008-06-06 07:39:11 +00:00
|
|
|
if ( !in_array($scheme, array('http', 'https')) ) {
|
2008-06-26 16:40:04 +00:00
|
|
|
if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
|
|
|
|
$scheme = 'https';
|
|
|
|
elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
|
2008-06-11 17:25:55 +00:00
|
|
|
$scheme = 'https';
|
|
|
|
elseif ( ('admin' == $scheme) && force_ssl_admin() )
|
2008-06-06 07:39:11 +00:00
|
|
|
$scheme = 'https';
|
|
|
|
else
|
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
|
|
|
}
|
2008-05-27 17:46:01 +00:00
|
|
|
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
2008-08-19 19:41:11 +00:00
|
|
|
return apply_filters('site_url', $url, $path, $orig_scheme);
|
2008-05-27 17:46:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the url to the admin area.
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.6.0
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
|
|
|
* @param string $path Optional path relative to the admin url
|
|
|
|
* @return string Admin url link with optional path appended
|
|
|
|
*/
|
2008-05-27 17:46:01 +00:00
|
|
|
function admin_url($path = '') {
|
2008-06-11 17:25:55 +00:00
|
|
|
$url = site_url('wp-admin/', 'admin');
|
2008-05-27 17:46:01 +00:00
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= ltrim($path, '/');
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the url to the includes directory.
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.6.0
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param string $path Optional. Path relative to the includes url.
|
|
|
|
* @return string Includes url link with optional path appended.
|
2008-07-14 23:39:11 +00:00
|
|
|
*/
|
2008-05-27 17:46:01 +00:00
|
|
|
function includes_url($path = '') {
|
|
|
|
$url = site_url() . '/' . WPINC . '/';
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= ltrim($path, '/');
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the url to the content directory.
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.6.0
|
2008-07-14 23:39:11 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param string $path Optional. Path relative to the content url.
|
|
|
|
* @return string Content url link with optional path appended.
|
2008-07-14 23:39:11 +00:00
|
|
|
*/
|
2008-07-09 17:24:36 +00:00
|
|
|
function content_url($path = '') {
|
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
|
|
|
$url = WP_CONTENT_URL;
|
|
|
|
if ( 0 === strpos($url, 'http') ) {
|
|
|
|
if ( is_ssl() )
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", $url );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-10-13 22:00:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the url to the plugins directory.
|
2008-07-15 00:10:07 +00:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 22:00:07 +00:00
|
|
|
* @since 2.6.0
|
2008-07-15 00:10:07 +00:00
|
|
|
*
|
2008-10-13 22:00:07 +00:00
|
|
|
* @param string $path Optional. Path relative to the plugins url.
|
|
|
|
* @return string Plugins url link with optional path appended.
|
2008-07-15 00:10:07 +00:00
|
|
|
*/
|
|
|
|
function plugins_url($path = '') {
|
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
|
|
|
$url = WP_PLUGIN_URL;
|
|
|
|
if ( 0 === strpos($url, 'http') ) {
|
|
|
|
if ( is_ssl() )
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", $url );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2005-10-20 20:48:32 +00:00
|
|
|
?>
|