2004-01-27 04:58:01 -05:00
|
|
|
<?php
|
|
|
|
|
2004-04-21 00:12:55 -04:00
|
|
|
function the_permalink() {
|
|
|
|
echo get_permalink();
|
|
|
|
}
|
|
|
|
|
2004-05-18 04:36:53 -04:00
|
|
|
function permalink_link() { // For backwards compatibility
|
|
|
|
echo get_permalink();
|
|
|
|
}
|
|
|
|
|
2004-01-27 04:58:01 -05:00
|
|
|
function permalink_anchor($mode = 'id') {
|
|
|
|
global $id, $post;
|
|
|
|
switch(strtolower($mode)) {
|
|
|
|
case 'title':
|
|
|
|
$title = sanitize_title($post->post_title) . '-' . $id;
|
|
|
|
echo '<a id="'.$title.'"></a>';
|
|
|
|
break;
|
|
|
|
case 'id':
|
|
|
|
default:
|
|
|
|
echo '<a id="post-'.$id.'"></a>';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function permalink_single_rss($file = '') {
|
|
|
|
echo get_permalink();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_permalink($id=false) {
|
2004-05-24 04:22:18 -04:00
|
|
|
global $post, $wpdb;
|
2004-02-26 11:15:48 -05:00
|
|
|
global $querystring_start, $querystring_equal;
|
2004-01-27 04:58:01 -05:00
|
|
|
|
|
|
|
$rewritecode = array(
|
|
|
|
'%year%',
|
|
|
|
'%monthnum%',
|
|
|
|
'%day%',
|
2004-05-05 03:34:41 -04:00
|
|
|
'%hour%',
|
|
|
|
'%minute%',
|
|
|
|
'%second%',
|
2004-01-27 04:58:01 -05:00
|
|
|
'%postname%',
|
|
|
|
'%post_id%'
|
|
|
|
);
|
|
|
|
if (!$id) {
|
|
|
|
if ('' != get_settings('permalink_structure')) {
|
2004-03-24 21:04:15 -05:00
|
|
|
$unixtime = strtotime($post->post_date);
|
2004-01-27 04:58:01 -05:00
|
|
|
$rewritereplace = array(
|
|
|
|
date('Y', $unixtime),
|
|
|
|
date('m', $unixtime),
|
|
|
|
date('d', $unixtime),
|
2004-05-05 03:34:41 -04:00
|
|
|
date('H', $unixtime),
|
|
|
|
date('i', $unixtime),
|
|
|
|
date('s', $unixtime),
|
2004-01-27 04:58:01 -05:00
|
|
|
$post->post_name,
|
|
|
|
$post->ID
|
|
|
|
);
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
|
2004-01-27 04:58:01 -05:00
|
|
|
} else { // if they're not using the fancy permalink option
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$post->ID;
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
} else { // if an ID is given
|
2004-05-24 04:22:18 -04:00
|
|
|
$idpost = $wpdb->get_row("SELECT post_date, post_name FROM $wpdb->posts WHERE ID = $id");
|
2004-01-27 04:58:01 -05:00
|
|
|
if ('' != get_settings('permalink_structure')) {
|
2004-03-24 21:04:15 -05:00
|
|
|
$unixtime = strtotime($idpost->post_date);
|
2004-01-27 04:58:01 -05:00
|
|
|
$rewritereplace = array(
|
|
|
|
date('Y', $unixtime),
|
|
|
|
date('m', $unixtime),
|
|
|
|
date('d', $unixtime),
|
2004-05-05 03:34:41 -04:00
|
|
|
date('H', $unixtime),
|
|
|
|
date('i', $unixtime),
|
|
|
|
date('s', $unixtime),
|
2004-01-27 04:58:01 -05:00
|
|
|
$idpost->post_name,
|
|
|
|
$id
|
|
|
|
);
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
|
2004-01-27 04:58:01 -05:00
|
|
|
} else {
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$id;
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_month_link($year, $month) {
|
2004-02-26 11:15:48 -05:00
|
|
|
global $querystring_start, $querystring_equal;
|
2004-04-24 17:52:24 -04:00
|
|
|
if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
|
|
|
|
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
|
2004-01-27 04:58:01 -05:00
|
|
|
if ('' != get_settings('permalink_structure')) {
|
2004-05-31 13:22:25 -04:00
|
|
|
$permalink = get_settings('permalink_structure');
|
|
|
|
|
|
|
|
// If the permalink structure does not contain year and month, make
|
|
|
|
// one that does.
|
|
|
|
if (! (strstr($permalink, '%year') && strstr($permalink, '%monthnum')) ) {
|
|
|
|
$front = substr($permalink, 0, strpos($permalink, '%'));
|
|
|
|
$permalink = $front . '%year%/%monthnum%/';
|
|
|
|
}
|
|
|
|
|
|
|
|
$off = strpos($permalink, '%monthnum%');
|
2004-01-27 04:58:01 -05:00
|
|
|
$offset = $off + 11;
|
2004-05-31 13:22:25 -04:00
|
|
|
$monthlink = substr($permalink, 0, $offset);
|
2004-01-27 04:58:01 -05:00
|
|
|
if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1);
|
|
|
|
$monthlink = str_replace('%year%', $year, $monthlink);
|
|
|
|
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
|
|
|
|
$monthlink = str_replace('%post_id%', '', $monthlink);
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . $monthlink;
|
2004-01-27 04:58:01 -05:00
|
|
|
} else {
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2);
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_day_link($year, $month, $day) {
|
2004-02-26 11:15:48 -05:00
|
|
|
global $querystring_start, $querystring_equal;
|
2004-04-24 17:52:24 -04:00
|
|
|
if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
|
|
|
|
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
|
|
|
|
if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
|
2004-01-27 04:58:01 -05:00
|
|
|
if ('' != get_settings('permalink_structure')) {
|
2004-05-31 13:22:25 -04:00
|
|
|
$permalink = get_settings('permalink_structure');
|
|
|
|
|
|
|
|
// If the permalink structure does not contain year, month, and day,
|
|
|
|
// make one that does.
|
|
|
|
if (! (strstr($permalink, '%year') && strstr($permalink, '%monthnum')) ) {
|
|
|
|
$front = substr($permalink, 0, strpos($permalink, '%'));
|
|
|
|
$permalink = $front . '%year%/%monthnum%/%day%/';
|
|
|
|
}
|
|
|
|
|
|
|
|
$off = strpos($permalink, '%day%');
|
2004-01-27 04:58:01 -05:00
|
|
|
$offset = $off + 6;
|
2004-05-31 13:22:25 -04:00
|
|
|
$daylink = substr($permalink, 0, $offset);
|
2004-01-27 04:58:01 -05:00
|
|
|
if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
|
|
|
|
$daylink = str_replace('%year%', $year, $daylink);
|
|
|
|
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
|
|
|
|
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
|
|
|
|
$daylink = str_replace('%post_id%', '', $daylink);
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') . $daylink;
|
2004-01-27 04:58:01 -05:00
|
|
|
} else {
|
2004-04-28 03:27:03 -04:00
|
|
|
return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2);
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
2004-06-02 03:14:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_feed_link($feed='rss2') {
|
|
|
|
$do_perma = 0;
|
|
|
|
$feed_url = get_settings('siteurl');
|
|
|
|
$comment_feed_url = $feed_url;
|
|
|
|
|
|
|
|
$permalink = get_settings('permalink_structure');
|
|
|
|
if ('' != $permalink) {
|
|
|
|
$do_perma = 1;
|
|
|
|
$feed_url = get_settings('home');
|
|
|
|
$index = get_settings('blogfilename');
|
|
|
|
$prefix = '';
|
|
|
|
if (preg_match('#^/*' . $index . '#', $permalink)) {
|
|
|
|
$feed_url .= '/' . $index;
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment_feed_url = $feed_url;
|
|
|
|
$feed_url .= '/feed';
|
|
|
|
$comment_feed_url .= '/comments/feed';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($feed) {
|
|
|
|
case 'rdf':
|
|
|
|
$output = $feed_url .'/wp-rdf.php';
|
|
|
|
if ($do_perma) {
|
|
|
|
$output = $feed_url . '/rdf/';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'rss':
|
|
|
|
$output = $feed_url . '/wp-rss.php';
|
|
|
|
if ($do_perma) {
|
|
|
|
$output = $feed_url . '/rss/';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'atom':
|
|
|
|
$output = $feed_url .'/wp-atom.php';
|
|
|
|
if ($do_perma) {
|
|
|
|
$output = $feed_url . '/atom/';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'comments_rss2':
|
|
|
|
$output = $feed_url .'/wp-commentsrss2.php';
|
|
|
|
if ($do_perma) {
|
|
|
|
$output = $comment_feed_url . '/rss2/';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'rss2':
|
|
|
|
default:
|
|
|
|
$output = $feed_url .'/wp-rss2.php';
|
|
|
|
if ($do_perma) {
|
|
|
|
$output = $feed_url . '/rss2/';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function edit_post_link($link = 'Edit This', $before = '', $after = '') {
|
2004-02-26 11:15:48 -05:00
|
|
|
global $user_level, $post;
|
2004-01-27 04:58:01 -05:00
|
|
|
|
|
|
|
get_currentuserinfo();
|
|
|
|
|
|
|
|
if ($user_level > 0) {
|
|
|
|
$authordata = get_userdata($post->post_author);
|
|
|
|
if ($user_level < $authordata->user_level) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-26 11:15:48 -05:00
|
|
|
$location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&post=$post->ID";
|
2004-02-19 20:53:41 -05:00
|
|
|
echo "$before <a href=\"$location\">$link</a> $after";
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
|
2004-02-26 11:15:48 -05:00
|
|
|
global $user_level, $post, $comment;
|
2004-01-27 04:58:01 -05:00
|
|
|
|
|
|
|
get_currentuserinfo();
|
|
|
|
|
|
|
|
if ($user_level > 0) {
|
|
|
|
$authordata = get_userdata($post->post_author);
|
|
|
|
if ($user_level < $authordata->user_level) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-26 11:15:48 -05:00
|
|
|
$location = get_settings('siteurl') . "/wp-admin/post.php?action=editcomment&comment=$comment->comment_ID";
|
2004-05-09 01:47:02 -04:00
|
|
|
echo "$before <a href='$location'>$link</a> $after";
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|