From 6d55b3153aa698d6d08e0c26c6909295f4c826eb Mon Sep 17 00:00:00 2001
From: rboren
Date: Thu, 5 Feb 2004 20:55:50 +0000
Subject: [PATCH] Clean feed and trackback URLs.
git-svn-id: http://svn.automattic.com/wordpress/trunk@836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/options-permalink.php | 43 +++++++++++++++++++--
wp-atom.php | 10 +++--
wp-blog-header.php | 4 +-
wp-commentsrss2.php | 13 ++++---
wp-includes/functions.php | 7 ++++
wp-includes/template-functions-category.php | 19 ++++++++-
wp-includes/template-functions-comment.php | 13 ++++++-
wp-includes/template-functions-general.php | 26 +++++++++++++
wp-rdf.php | 9 +++--
wp-rss.php | 9 +++--
wp-rss2.php | 9 +++--
wp-trackback.php | 5 +++
12 files changed, 143 insertions(+), 24 deletions(-)
diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php
index 6fa0887c26..bdf5be2057 100644
--- a/wp-admin/options-permalink.php
+++ b/wp-admin/options-permalink.php
@@ -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, '%'));
+RewriteRule ^ [QSA]
+RewriteRule ^ [QSA]
+RewriteRule ^(.*)/$ wp-feed.php?category_name=$1&feed=$2 [QSA]
+RewriteRule ^?(.*) index.php?category_name=$1 [QSA]
+RewriteRule ^ [QSA]
+RewriteRule ^ [QSA]
\ No newline at end of file
+?>
diff --git a/wp-commentsrss2.php b/wp-commentsrss2.php
index 3131a2034e..59866d006c 100644
--- a/wp-commentsrss2.php
+++ b/wp-commentsrss2.php
@@ -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 "";
@@ -26,8 +29,8 @@ foreach ($posts as $post) { start_wp();
if ($i < 1) {
$i++;
?>
-
-
+
+
@@ -40,7 +43,7 @@ foreach ($posts as $post) { start_wp();
2000-01-01T12:00+00:00
get_results("SELECT comment_ID,
comment_author,
comment_author_email,
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 0550fff92f..846ff9420b 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -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$1
\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|\s*?
|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
+ $pee = preg_replace('!\s*(?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*
!', "$1", $pee); // don't pee all over a tag
$pee = preg_replace("|(
|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|]*)>|i', "", $pee);
$pee = str_replace('
', '', $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;
diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php
index 1ef156aff0..d03dea5d79 100644
--- a/wp-includes/template-functions-category.php
+++ b/wp-includes/template-functions-category.php
@@ -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;
}
-?>
\ No newline at end of file
+?>
diff --git a/wp-includes/template-functions-comment.php b/wp-includes/template-functions-comment.php
index 064b6d830f..f62dbcc024 100644
--- a/wp-includes/template-functions-comment.php
+++ b/wp-includes/template-functions-comment.php
@@ -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 = ''.$link_text.'';
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 {
diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php
index eee5c29dc0..ecfbb5bb1c 100644
--- a/wp-includes/template-functions-general.php
+++ b/wp-includes/template-functions-general.php
@@ -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';
diff --git a/wp-rdf.php b/wp-rdf.php
index 89773f532d..d89fde7885 100644
--- a/wp-rdf.php
+++ b/wp-rdf.php
@@ -1,8 +1,11 @@
ID;
+}
if (empty($title) && empty($tb_url) && empty($blog_name)) {
// If it doesn't look like a trackback at all...