Clean feed and trackback URLs.

git-svn-id: http://svn.automattic.com/wordpress/trunk@836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-02-05 20:55:50 +00:00
parent cab7113ff9
commit 6d55b3153a
12 changed files with 143 additions and 24 deletions

View File

@ -129,18 +129,50 @@ $match = preg_replace('|/[?]|', '', $match, 1);
$match = str_replace($rewritecode, $rewritereplace, $match);
$match = preg_replace('|[?]|', '', $match, 1);
$feedmatch = str_replace('?/?', '/', $match);
$trackbackmatch = $feedmatch;
preg_match_all('/%.+?%/', $permalink_structure, $tokens);
$query = 'index.php?';
$feedquery = 'wp-feed.php?';
$trackbackquery = 'wp-trackback.php?';
for ($i = 0; $i < count($tokens[0]); ++$i) {
if (0 < $i) $query .= '&';
$query .= str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . '$'. ($i + 1);
if (0 < $i) {
$query .= '&';
$feedquery .= '&';
$trackbackquery .= '&';
}
$query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . '$'. ($i + 1);
$query .= $query_token;
$feedquery .= $query_token;
$trackbackquery .= $query_token;
}
++$i;
// Add post paged stuff
$match .= '([0-9]+)?/?';
$query .= "&page=$$i";
// Add post feed stuff
$feedregex = '(feed|rdf|rss|rss2|atom)/?';
$feedmatch .= $feedregex;
$feedquery .= "&feed=$$i";
// Add post trackback stuff
$trackbackregex = 'trackback/?';
$trackbackmatch .= $trackbackregex;
// Site feed
$sitefeedmatch = 'feed/?([0-9a-z-]+)?/?$';
$sitefeedquery = $site_root . 'wp-feed.php?feed=$1';
// Site comment feed
$sitecommentfeedmatch = 'comments/feed/?([0-9a-z-]+)?/?$';
$sitecommentfeedquery = $site_root . 'wp-feed.php?feed=$1&withcomments=1';
// Code for nice categories, currently not very flexible
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
$catmatch = $front . 'category/';
@ -151,7 +183,12 @@ $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
<textarea rows="5" style="width: 100%;">RewriteEngine On
RewriteBase <?php echo $site_root; ?>
RewriteRule ^<?php echo $match; echo '$ ' . $site_root . $query ?> [QSA]
RewriteRule ^<?php echo $catmatch; ?>?(.*) <?php echo $site_root; ?>index.php?category_name=$1 [QSA]</textarea>
RewriteRule ^<?php echo $feedmatch; echo '$ ' . $site_root . $feedquery ?> [QSA]
RewriteRule ^<?php echo $trackbackmatch; echo '$ ' . $site_root . $trackbackquery ?> [QSA]
RewriteRule ^<?php echo $catmatch; ?>(.*)/<?php echo $feedregex ?>$ <?php echo $site_root; ?>wp-feed.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^<?php echo $catmatch; ?>?(.*) <?php echo $site_root; ?>index.php?category_name=$1 [QSA]
RewriteRule ^<?php echo $sitefeedmatch; ?> <?php echo $sitefeedquery ?> [QSA]
RewriteRule ^<?php echo $sitecommentfeedmatch; ?> <?php echo $sitecommentfeedquery ?> [QSA]</textarea>
</form>
</div>
<?php

View File

@ -1,8 +1,12 @@
<?php
$blog = 1;
$doing_rss = 1;
if (! $feed) {
$blog = 1;
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: application/atom+xml', true);
require('wp-blog-header.php');
if (!isset($rss_language)) { $rss_language = 'en'; }
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }

View File

@ -10,7 +10,7 @@ if (!file_exists($curpath . '/wp-config.php'))
require($curpath.'/wp-config.php');
$wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'name', 'category_name');
$wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'name', 'category_name', 'feed');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
@ -388,4 +388,4 @@ if ($posts) {
}
}
} // end if posts.
?>
?>

View File

@ -5,9 +5,12 @@
/* These first lines are the first part of a WordPress template.
In every template you do, you got to copy them before the CafeLog 'loop' */
$blog=1; // enter your blog's ID
if (! $feed) {
$blog=1; // enter your blog's ID
require('wp-blog-header.php');
}
header('Content-type: text/xml');
require('wp-blog-header.php');
if (!isset($rss_language)) { $rss_language = 'en'; }
echo "<?xml version=\"1.0\"?".">";
@ -26,8 +29,8 @@ foreach ($posts as $post) { start_wp();
if ($i < 1) {
$i++;
?>
<title><?php if (isset($_REQUEST["p"])) { echo "Comments on: "; the_title_rss(); } else { bloginfo_rss("name"); echo " Comments"; } ?></title>
<link><?php isset($_REQUEST["p"]) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
<title><?php if (isset($_REQUEST["p"]) || isset($_REQUEST["name"])) { echo "Comments on: "; the_title_rss(); } else { bloginfo_rss("name"); echo " Comments"; } ?></title>
<link><?php (isset($_REQUEST["p"]) || isset($_REQUEST["name"])) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
<description><?php bloginfo_rss("description") ?></description>
<dc:language><?php echo $rss_language ?></dc:language>
<dc:creator><?php echo antispambot($admin_email) ?></dc:creator>
@ -40,7 +43,7 @@ foreach ($posts as $post) { start_wp();
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
<?php
if (isset($_REQUEST["p"])) {
if (isset($_REQUEST["p"]) || isset($_REQUEST["name"])) {
$comments = $wpdb->get_results("SELECT comment_ID,
comment_author,
comment_author_email,

View File

@ -73,6 +73,7 @@ function wpautop($pee, $br = 1) {
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace('!<p>\s*(</?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
@ -146,6 +147,12 @@ function backslashit($string) {
return $string;
}
function trailingslashit($string) {
if ( '/' != substr($string, -1)) {
$string .= '/';
}
return $string;
}
function mysql2date($dateformatstring, $mysqlstring, $use_b2configmonthsdays = 1) {
global $month, $weekday;

View File

@ -36,6 +36,23 @@ function get_category_link($echo = false, $category_id, $category_nicename) {
return $link;
}
function get_category_rss_link($echo = false, $category_id, $category_nicename) {
global $querystring_start, $querystring_equal, $siteurl;
$cat_ID = $category_id;
$permalink_structure = get_settings('permalink_structure');
if ('' == $permalink_structure) {
$file = "$siteurl/wp-rss2.php";
$link = $file . $querystring_start . 'cat' . $querystring_equal . $category_id;
} else {
$link = get_category_link(0, $category_id, $category_nicename);
$link = $link . "/feed/";
}
if ($echo) echo $link;
return $link;
}
function the_category($seperator = '', $parents='') {
$categories = get_the_category();
if ('' == $seperator) {
@ -318,4 +335,4 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
}
echo $thelist;
}
?>
?>

View File

@ -209,7 +209,13 @@ function comment_time($d='') {
function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') {
global $id;
global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
$url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
if ('' != get_settings('permalink_structure')) {
$url = trailingslashit(get_permalink()) . 'rss2/';
} else {
$url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
}
$url = '<a href="'.$url.'">'.$link_text.'</a>';
echo $url;
}
@ -252,6 +258,11 @@ function permalink_comments_rss() {
function trackback_url($display = true) {
global $siteurl, $id;
$tb_url = $siteurl.'/wp-trackback.php/'.$id;
if ('' != get_settings('permalink_structure')) {
$tb_url = get_permalink() . 'trackback/';
}
if ($display) {
echo $tb_url;
} else {

View File

@ -23,6 +23,17 @@ function bloginfo_unicode($show='') {
function get_bloginfo($show='') {
global $siteurl, $blogfilename, $blogname, $blogdescription, $siteurl, $admin_email;
$do_perma = 0;
$feed_url = $siteurl;
$comment_feed_url = $siteurl;
if ('' != get_settings('permalink_structure')) {
$do_perma = 1;
$feed_url = $siteurl . '/feed';
$comment_feed_url = $siteurl . '/comments/feed';
}
switch($show) {
case "url":
$output = $siteurl."/".$blogfilename;
@ -32,18 +43,33 @@ function get_bloginfo($show='') {
break;
case "rdf_url":
$output = $siteurl.'/wp-rdf.php';
if ($do_perma) {
$output = $feed_url . '/rdf/';
}
break;
case "rss_url":
$output = $siteurl.'/wp-rss.php';
if ($do_perma) {
$output = $feed_url . '/rss/';
}
break;
case "rss2_url":
$output = $siteurl.'/wp-rss2.php';
if ($do_perma) {
$output = $feed_url . '/rss2/';
}
break;
case "atom_url":
$output = $siteurl.'/wp-atom.php';
if ($do_perma) {
$output = $feed_url . '/atom/';
}
break;
case "comments_rss2_url":
$output = $siteurl.'/wp-commentsrss2.php';
if ($do_perma) {
$output = $comment_feed_url . '/rss2/';
}
break;
case "pingback_url":
$output = $siteurl.'/xmlrpc.php';

View File

@ -1,8 +1,11 @@
<?php /* RDF 1.0 generator, original version by garym@teledyn.com */
$blog = 1; // enter your blog's ID
$doing_rss = 1;
if (! $feed) {
$blog = 1; // enter your blog's ID
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: text/xml', true);
require('wp-blog-header.php');
/* This doesn't take into account edits
// Get the time of the most recent article

View File

@ -1,9 +1,12 @@
<?php /* These first lines are the first part of a CafeLog template.
In every template you do, you got to copy them before the CafeLog 'loop' */
$blog = 1; // enter your blog's ID
$doing_rss = 1;
if (! $feed) {
$blog = 1; // enter your blog's ID
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: text/xml', true);
require('wp-blog-header.php');
/* This doesn't take into account edits
// Get the time of the most recent article

View File

@ -1,8 +1,11 @@
<?php
$blog = 1;
$doing_rss = 1;
if (! $feed) {
$blog = 1;
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: text/xml', true);
require('wp-blog-header.php');
/* This doesn't take into account edits
// Get the time of the most recent article

View File

@ -10,6 +10,11 @@ $title = $HTTP_POST_VARS['title'];
$excerpt = $HTTP_POST_VARS['excerpt'];
$blog_name = $HTTP_POST_VARS['blog_name'];
require('wp-blog-header.php');
if ( (($p != '') && ($p != 'all')) || ($name != '') ) {
$tb_id = $posts[0]->ID;
}
if (empty($title) && empty($tb_url) && empty($blog_name)) {
// If it doesn't look like a trackback at all...