Ticket #1526: wp-atom-3405.patch
| File wp-atom-3405.patch, 15.4 KB (added by , 20 years ago) |
|---|
-
wp-includes/template-functions-general.php
82 82 case 'wpurl' : 83 83 $output = get_settings('siteurl'); 84 84 break; 85 case 'atom_alternate_url': 86 $output = get_self_link(-1); 87 break; 88 case 'atom_self_url': 89 case 'self' : 90 $output = get_self_link(); 91 break; 85 92 case 'description': 86 93 $output = get_settings('blogdescription'); 87 94 break; -
wp-includes/template-functions-links.php
175 175 } 176 176 } 177 177 178 function get_self_link($omit_feed = 0) { 179 // This function produce the "prettiest" link that returns this resource 180 // Set $omit_feed to: 181 // -1 to force the link to not contain a feed 182 // 0 to leave the feed parameter alone 183 // 1 to force the link to contain a feed 184 185 global $wp_rewrite; 186 // NOTE: This could be refactored into 'get_self_link' and 'get_params_link' 187 // the latter could take an array of arbitrary paramaters (like the one below) 188 $params = array( 189 's' => get_query_var('s'), 190 'pagename' => get_query_var('pagename'), 191 'author_name' => get_query_var('author_name'), 192 'author' => get_query_var('author'), 193 'category_name' => get_query_var('category_name'), 194 'cat' => get_query_var('cat'), 195 'year' => get_query_var('year'), 196 'monthnum' => get_query_var('monthnum'), 197 'day' => get_query_var('day'), 198 'hour' => get_query_var('hour'), 199 'minute' => get_query_var('minute'), 200 'second' => get_query_var('second'), 201 'name' => get_query_var('name'), 202 'p' => get_query_var('p') ); 203 foreach ( $params as $key => $value ) { 204 if ( empty($value) ) 205 unset($params[$key]); 206 else 207 $params[$key] = rawurlencode($value); 208 } 209 // feed is a special case because it can be safely combined with 210 // various permalink types 211 $feed = rawurlencode(get_query_var('feed')); 212 switch ( $omit_feed ) { 213 case 1: 214 if ( empty($feed) ) 215 $feed = 'feed'; 216 break; 217 case -1: 218 $feed = ''; 219 break; 220 case 0: 221 default: 222 // do nothing 223 break; 224 } 225 226 $link = ''; 227 // search, date, category, author 228 if ( $wp_rewrite->using_permalinks() ) { 229 if ( 1 == count($params) ) { 230 if ( ! empty($params['s']) ) { 231 $link = str_replace('%search%', $params['s'], $wp_rewrite->get_search_permastruct()); 232 } else if ( ! empty($params['category_name']) ) { 233 $link = str_replace('%category%', $params['category_name'], $wp_rewrite->get_category_permastruct()); 234 } else if ( ! empty($params['author_name']) ) { 235 $link = str_replace('%author%', $params['author_name'], $wp_rewrite->get_author_permastruct()); 236 } else if ( ! empty($params['pagename']) ) { 237 $link = str_replace('%pagename%', $params['pagename'], $wp_rewrite->get_page_permastruct()); 238 } 239 } else if ( 2 == count($params) ) { 240 if ( ! empty($params['cat']) && ( $params['category_name'] == get_catname($params['cat']) ) ) { 241 $link = str_replace('%category%', $params['category_name'], $wp_rewrite->get_category_permastruct()); 242 } else if ( ! empty($params['author']) && ( $params['author_name'] == get_author_name($params['author']) ) ) { 243 $link = str_replace('%author%', $params['author_name'], $wp_rewrite->get_author_permastruct()); 244 } 245 } else { 246 $is_date = false; 247 // if exactly one date param is not empty 248 if ( ( 1 == count($params) ) && ( ! empty($params['year']) || ! empty($params['monthnum']) || ! empty($params['day']) ) ) { 249 $is_date = true; 250 // if exactly two date params are not empty 251 } else if ( ( 2 == count($params) ) && ( ( ! empty($params['year']) && ! empty($params['monthnum']) ) || ( ! empty($params['monthnum']) && ! empty($params['day']) ) ) ) { 252 $is_date = true; 253 // if all three date params are not empty 254 } else if ( ( 3 == count($params) ) && ( ! empty($params['year']) && ! empty($params['monthnum']) && ! empty($params['day']) ) ) { 255 $is_date = true; 256 } 257 if ( $is_date ) { 258 if( ! empty($params['monthnum']) ) 259 $params['monthnum'] = zeroise($params['monthnum'], 2); 260 261 if( ! empty($params['day']) ) 262 $params['day'] = zeroise($params['day'], 2); 263 264 $link = $wp_rewrite->get_date_permastruct(); 265 $link = str_replace('%year%', $params['year'], $link); 266 $link = str_replace('%monthnum%', $params['monthnum'], $link); 267 $link = str_replace('%day%', $params['day'], $link); 268 $link = preg_replace('#/+#', '/', $link); 269 } else { 270 $struct = get_settings('permalink_structure'); 271 272 // replacements for consistency 273 $struct = str_replace('%post_id%', '%p%', $struct); 274 $struct = str_replace('%postname%', '%name%', $struct); 275 $struct = str_replace('%category%', '%category_name%', $struct); 276 $struct = str_replace('%author%', '%author_name%', $struct); 277 278 // Note: array assignment always copies 279 $params_copy = $params; 280 foreach ( $params_copy as $key => $value ) { 281 if ( false === strpos($struct, "%{$key}%") ) { 282 $struct = str_replace("%{$key}%", $value, $struct); 283 unset($params_copy[$key]); 284 } 285 } 286 // were all the parameters used? 287 if ( empty($params_copy) ) { 288 $link = $struct; 289 $tags = array( 290 'p', 291 'title', 292 'category_name', 293 'author_name', 294 'year', 295 'monthnum', 296 'day', 297 'hour', 298 'minute', 299 'second' ); 300 // were all tags substituted for? 301 foreach ( $tags as $value ) { 302 if ( false !== strpos($struct, "%{$value}%") ) { 303 $link = ''; 304 break; 305 } 306 } 307 } 308 } 309 } 310 311 // handle feed 312 if ( ! empty($feed) ) { 313 if ( 0 == count($params) ) { 314 if ( ( 1 === $feed ) || ( 'feed' == $feed ) ) 315 $feed = ''; 316 $link = str_replace('%feed%', $feed, $wp_rewrite->get_feed_permastruct()); 317 } else if ( '' != $link ) { 318 $link = trailingslashit($link); 319 if ( 1 === $feed ) 320 $link .= 'feed/'; 321 else 322 $link = trailingslashit($link) . "feed/{$feed}/"; 323 } 324 } 325 } 326 327 $home = trailingslashit(get_settings('home')); 328 if ( '' == $link ) { 329 foreach ( $params as $key => $value ) { 330 if ( ! empty($value) ) { 331 $link .= "&{$key}={$value}"; 332 } 333 } 334 if ( ! empty($feed) ) 335 $link .= "&feed={$feed}"; 336 337 if ( empty($link) ) { 338 $link = $home; 339 } else { 340 $link = "{$home}?" . substr($link, 1); 341 } 342 } else { 343 $link = trailingslashit($link); 344 $link = preg_replace('#/+#', '/', $link); 345 if ( $link{0} == '/' ) 346 $link = substr($link, 1); 347 348 $link = $home . $link; 349 } 350 return $link; 351 } 352 178 353 function get_feed_link($feed='rss2') { 179 354 global $wp_rewrite; 180 355 $do_perma = 0; 181 356 $feed_url = get_settings('siteurl'); 182 357 $comment_feed_url = $feed_url; 358 $cat = ''; 359 if ( false !== strpos($feed, '_self') ) { 360 $feed = str_replace('_self', '', $feed); 361 $cat = intval( get_query_var('cat') ); 362 if ( ( $cat == 0 ) || ( strtoupper($cat) == 'ALL' ) ) 363 $cat = ''; 364 } 183 365 184 366 $permalink = $wp_rewrite->get_feed_permastruct(); 185 367 if ( '' != $permalink ) { … … 193 375 194 376 $permalink = str_replace('%feed%', $feed, $permalink); 195 377 $permalink = preg_replace('#/+#', '/', "/$permalink/"); 196 $output = get_settings('home') . $permalink;378 $output = get_settings('home') . $permalink; 197 379 } else { 198 380 if ( false !== strpos($feed, 'comments_') ) 199 381 $feed = str_replace('comments_', 'comments-', $feed); 382 if ( $cat ) 383 $cat = "&cat={$cat}"; 200 384 201 $output = get_settings('home') . "/?feed={$feed} ";385 $output = get_settings('home') . "/?feed={$feed}{$cat}"; 202 386 } 203 387 204 388 return apply_filters('feed_link', $output, $feed); … … 318 502 319 503 $format = str_replace('%link', $link, $format); 320 504 321 echo $format; 505 echo $format; 322 506 } 323 507 324 508 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { … … 333 517 $link = $string . $link . '</a>'; 334 518 $format = str_replace('%link', $link, $format); 335 519 336 echo $format; 520 echo $format; 337 521 } 338 522 339 523 -
wp-includes/feed-functions.php
105 105 $link = get_author_link(0, $author_id, $author_nicename); 106 106 $link = $link . "feed/"; 107 107 } 108 108 109 109 $link = apply_filters('author_feed_link', $link); 110 110 111 111 if ($echo) echo $link; … … 148 148 149 149 $custom_fields = get_post_custom(); 150 150 if( is_array( $custom_fields ) ) { 151 while( list( $key, $val ) = each( $custom_fields ) ) { 151 while( list( $key, $val ) = each( $custom_fields ) ) { 152 152 if( $key == 'enclosure' ) { 153 153 if (is_array($val)) { 154 154 foreach($val as $enc) { … … 161 161 } 162 162 } 163 163 164 165 function atom_enclosure() { 166 global $id, $post; 167 if (!empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password)) return; 168 169 $custom_fields = get_post_custom(); 170 if( is_array( $custom_fields ) ) { 171 while( list( $key, $val ) = each( $custom_fields ) ) { 172 if( $key == 'enclosure' ) { 173 if (is_array($val)) { 174 foreach($val as $enc) { 175 $enclosure = split( "\n", $enc ); 176 print "<link rel=\"enclosure\" href=\"".trim( htmlspecialchars($enclosure[ 0 ]) )."\" length=\"".trim( $enclosure[ 1 ] )."\" type=\"".trim( $enclosure[ 2 ] )."\"/>\n"; 177 } 178 } 179 } 180 } 181 } 182 } 164 183 ?> 184 No newline at end of file -
wp-content/themes/classic/header.php
14 14 15 15 <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" /> 16 16 <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" /> 17 <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />17 <link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php bloginfo('atom_url'); ?>" /> 18 18 19 19 <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> 20 20 <?php wp_get_archives('type=monthly&format=link'); ?> -
wp-content/themes/default/header.php
9 9 <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats --> 10 10 11 11 <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> 12 <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" /> 12 13 <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" /> 13 14 <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> 14 15 -
wp-atom.php
1 1 <?php 2 // Atom 1.0 feed generator for WordPress 3 // Distributed under the terms of the GNU General Public License v2 2 4 3 if (empty($wp)) { 4 require_once('wp-config.php'); 5 wp('feed=atom'); 5 if (empty($feed)) { 6 $blog = 1; 7 $feed = 'atom'; 8 $doing_rss = 1; 9 require('wp-blog-header.php'); 6 10 } 7 11 8 12 header('Content-type: application/atom+xml; charset=' . get_settings('blog_charset'), true); 9 13 $more = 1; 10 11 14 ?> 12 <?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?> 13 <feed version="0.3" 14 xmlns="http://purl.org/atom/ns#" 15 xmlns:dc="http://purl.org/dc/elements/1.1/" 16 xml:lang="<?php echo get_option('rss_language'); ?>" 17 <?php do_action('atom_ns'); ?> 18 > 19 <title><?php bloginfo_rss('name') ?></title> 20 <link rel="alternate" type="text/html" href="<?php bloginfo_rss('home') ?>" /> 21 <tagline><?php bloginfo_rss("description") ?></tagline> 22 <modified><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></modified> 23 <copyright>Copyright <?php echo mysql2date('Y', get_lastpostdate('blog'), 0); ?></copyright> 24 <generator url="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress</generator> 15 <?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'."\n"; ?> 16 <feed xmlns="http://www.w3.org/2005/Atom" 17 xml:lang="<?php echo get_option('rss_language'); ?>" 18 <?php do_action('atom_ns'); ?>> 19 <title><?php bloginfo_rss('name'); ?></title> 20 <subtitle><?php bloginfo_rss('description'); ?></subtitle> 21 <id><?php bloginfo('url'); ?>/</id> 22 <link rel="self" type="application/atom+xml" href="<?php bloginfo_rss('atom_self_url'); ?>"/> 23 <link rel="alternate" type="<?php bloginfo('html_type'); ?>" href="<?php bloginfo_rss('atom_alternate_url'); ?>"/> 24 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated> 25 <rights>Copyright <?php echo mysql2date('Y', get_lastpostdate('blog'), 0); ?></rights> 26 <generator uri="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress</generator> 25 27 <?php do_action('atom_head'); ?> 26 28 <?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?> 27 29 <entry> 28 30 <author> 29 <name><?php the_author() ?></name>31 <name><?php the_author(); ?></name> 30 32 </author> 31 <title type="text/html" mode="escaped"><![CDATA[<?php the_title_rss() ?>]]></title> 32 <link rel="alternate" type="text/html" href="<?php permalink_single_rss() ?>" /> 33 <id><?php the_guid(); ?></id> 34 <modified><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></modified> 35 <issued><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></issued> 36 <?php the_category_rss('rdf') ?> 37 <summary type="text/plain" mode="escaped"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 33 <title type="html"><![CDATA[ <?php the_title_rss(); ?> ]]></title> 34 <link rel="alternate" type="<?php bloginfo('html_type'); ?>" href="<?php permalink_single_rss(); ?>"/> 35 <id><?php permalink_single_rss(); ?></id> 36 <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 37 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z',$post->post_modified_gmt); ?></updated> 38 <?php 39 $categories_path = get_category_link(0); 40 $categories = get_the_category(); 41 foreach ($categories as $cat) { ?> 42 <category scheme="<?php echo $categories_path; ?>" 43 term="<?php $foo = "/" . str_replace('/','\/',$categories_path) . "/"; 44 echo preg_replace($foo,'',get_category_link($cat->cat_ID)); ?>" 45 label="<?php echo $cat->cat_name; ?>"/> 46 <?php } ?> 47 <summary type="html"> 48 <![CDATA[ <?php the_excerpt_rss(); ?> ]]> 49 </summary> 38 50 <?php if ( !get_settings('rss_use_excerpt') ) : ?> 39 <content type="<?php bloginfo('html_type'); ?>" mode="escaped" xml:base="<?php permalink_single_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content> 51 <content type="html"> 52 <![CDATA[ <?php the_content('', 0, '') ?> ]]> 53 </content> 54 <?php atom_enclosure(); ?> 55 <?php do_action('atom_entry'); ?> 40 56 <?php endif; ?> 41 <?php rss_enclosure(); ?>42 <?php do_action('atom_entry'); ?>43 57 </entry> 44 58 <?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?> 45 </feed> 59 </feed> 60 No newline at end of file