Ticket #1526: wp-atom-3762.patch
File wp-atom-3762.patch, 15.0 KB (added by , 17 years ago) |
---|
-
wp-includes/template-functions-general.php
80 80 case 'wpurl' : 81 81 $output = get_settings('siteurl'); 82 82 break; 83 case 'atom_alternate_url': 84 $output = get_self_link(-1); 85 break; 86 case 'atom_self_url': 87 case 'self' : 88 $output = get_self_link(); 89 break; 83 90 case 'description': 84 91 $output = get_settings('blogdescription'); 85 92 break; -
wp-includes/template-functions-links.php
176 176 } 177 177 } 178 178 179 function get_self_link($omit_feed = 0) { 180 // This function produce the "prettiest" link that returns this resource 181 // Set $omit_feed to: 182 // -1 to force the link to not contain a feed 183 // 0 to leave the feed parameter alone 184 // 1 to force the link to contain a feed 185 186 global $wp_rewrite; 187 // NOTE: This could be refactored into 'get_self_link' and 'get_params_link' 188 // the latter could take an array of arbitrary paramaters (like the one below) 189 $params = array( 190 's' => get_query_var('s'), 191 'pagename' => get_query_var('pagename'), 192 'author_name' => get_query_var('author_name'), 193 'author' => get_query_var('author'), 194 'category_name' => get_query_var('category_name'), 195 'cat' => get_query_var('cat'), 196 'year' => get_query_var('year'), 197 'monthnum' => get_query_var('monthnum'), 198 'day' => get_query_var('day'), 199 'hour' => get_query_var('hour'), 200 'minute' => get_query_var('minute'), 201 'second' => get_query_var('second'), 202 'name' => get_query_var('name'), 203 'p' => get_query_var('p') ); 204 foreach ( $params as $key => $value ) { 205 if ( empty($value) ) 206 unset($params[$key]); 207 else 208 $params[$key] = rawurlencode($value); 209 } 210 // feed is a special case because it can be safely combined with 211 // various permalink types 212 $feed = rawurlencode(get_query_var('feed')); 213 switch ( $omit_feed ) { 214 case 1: 215 if ( empty($feed) ) 216 $feed = 'feed'; 217 break; 218 case -1: 219 $feed = ''; 220 break; 221 case 0: 222 default: 223 // do nothing 224 break; 225 } 226 227 $link = ''; 228 // search, date, category, author 229 if ( $wp_rewrite->using_permalinks() ) { 230 if ( ( 1 == count($params) ) && ! empty($params['s']) ) { 231 $link = str_replace('%search%', $params['s'], $wp_rewrite->get_search_permastruct()); 232 } else if ( 2 == count($params) ) { 233 if ( ! empty($params['cat']) && ( $params['category_name'] == get_catname($params['cat']) ) ) { 234 $link = str_replace('%category%', $params['category_name'], $wp_rewrite->get_category_permastruct()); 235 } else if ( ! empty($params['author']) ) { 236 $authordata = get_userdata($params['author']); 237 $author_login = $authordata->user_login; 238 if ( $params['author_name'] == $author_login ) { 239 $link = str_replace('%author%', $params['author_name'], $wp_rewrite->get_author_permastruct()); 240 } 241 } else if ( ! empty($params['pagename']) && ( $params['pagename'] == $params['name'] ) ) { 242 $link = str_replace('%pagename%', $params['pagename'], $wp_rewrite->get_page_permastruct()); 243 } 244 } 245 if ( '' == $link ){ 246 $is_date = false; 247 $struct = $wp_rewrite->get_date_permastruct(); 248 249 // Note: there are only three possiblities, per WP_Reewrite 250 $endian = array(); 251 $year_pos = strpos($struct, '%year%'); 252 $monthnum_pos = strpos($struct, '%monthnum%'); 253 $day_pos = strpos($struct, '%day%'); 254 if ( $year_pos < $monthnum_pos ) { 255 if ( $monthnum_pos < $day_pos ) { 256 $endian = array('year', 'monthnum', 'day'); 257 } 258 } else { 259 if ( $monthnum_pos < $day_pos ) { 260 $endian = array('monthnum', 'day', 'year'); 261 } else { 262 $endian = array('day', 'monthnum', 'year'); 263 } 264 } 265 266 $off = 0; 267 if ( false !== strpos($struct, '%postid%') ) { 268 $off = 1; 269 $is_date = empty($params['p']); 270 } else { 271 $is_date = true; 272 } 273 274 $max = count($params) - $off - 1; 275 if ( $is_date && ( $max < 3 ) ) { 276 $is_date = true; 277 for ( $i = 0; $i < count($params); $i++ ) { 278 if ( empty($params[$endian[$i]]) ) { 279 $is_date = false; 280 break; 281 } 282 } 283 } 284 285 if ( $is_date ) { 286 if( ! empty($params['monthnum']) ) 287 $params['monthnum'] = zeroise($params['monthnum'], 2); 288 289 if( ! empty($params['day']) ) 290 $params['day'] = zeroise($params['day'], 2); 291 292 $link = $struct; 293 $link = str_replace('%post_id%', $params['p'], $struct); 294 $link = str_replace('%year%', $params['year'], $link); 295 $link = str_replace('%monthnum%', $params['monthnum'], $link); 296 $link = str_replace('%day%', $params['day'], $link); 297 $link = preg_replace('#/+#', '/', $link); 298 } else { 299 $struct = get_settings('permalink_structure'); 300 301 // replacements for consistency 302 $struct = str_replace('%post_id%', '%p%', $struct); 303 $struct = str_replace('%postname%', '%name%', $struct); 304 $struct = str_replace('%category%', '%category_name%', $struct); 305 $struct = str_replace('%author%', '%author_name%', $struct); 306 307 // Note: array assignment always copies 308 $params_copy = $params; 309 foreach ( $params_copy as $key => $value ) { 310 if ( false === strpos($struct, "%{$key}%") ) { 311 $struct = str_replace("%{$key}%", $value, $struct); 312 unset($params_copy[$key]); 313 } 314 } 315 // were all the parameters used? 316 if ( empty($params_copy) ) { 317 $link = $struct; 318 $tags = array( 319 'p', 320 'title', 321 'category_name', 322 'author_name', 323 'year', 324 'monthnum', 325 'day', 326 'hour', 327 'minute', 328 'second' ); 329 // were all tags substituted for? 330 foreach ( $tags as $value ) { 331 if ( false !== strpos($struct, "%{$value}%") ) { 332 $link = ''; 333 break; 334 } 335 } 336 } 337 } 338 } 339 340 // handle feed 341 if ( ! empty($feed) ) { 342 if ( 0 == count($params) ) { 343 if ( ( 1 === $feed ) || ( 'feed' == $feed ) ) 344 $feed = ''; 345 $link = str_replace('%feed%', $feed, $wp_rewrite->get_feed_permastruct()); 346 } else if ( '' != $link ) { 347 $link = trailingslashit($link); 348 if ( 1 === $feed ) 349 $link .= 'feed/'; 350 else 351 $link = trailingslashit($link) . "feed/{$feed}/"; 352 } 353 } 354 } 355 356 $home = trailingslashit(get_settings('home')); 357 if ( '' == $link ) { 358 foreach ( $params as $key => $value ) { 359 if ( ! empty($value) ) { 360 $link .= "&{$key}={$value}"; 361 } 362 } 363 if ( ! empty($feed) ) 364 $link .= "&feed={$feed}"; 365 366 if ( empty($link) ) { 367 $link = $home; 368 } else { 369 $link = "{$home}?" . substr($link, 1); 370 } 371 } else { 372 $link = trailingslashit($link); 373 $link = preg_replace('#/+#', '/', $link); 374 if ( $link{0} == '/' ) 375 $link = substr($link, 1); 376 377 $link = $home . $link; 378 } 379 return $link; 380 } 381 179 382 function get_feed_link($feed='rss2') { 180 383 global $wp_rewrite; 181 384 $do_perma = 0; … … 194 397 195 398 $permalink = str_replace('%feed%', $feed, $permalink); 196 399 $permalink = preg_replace('#/+#', '/', "/$permalink/"); 197 $output = 400 $output = get_settings('home') . $permalink; 198 401 } else { 199 402 if ( false !== strpos($feed, 'comments_') ) 200 403 $feed = str_replace('comments_', 'comments-', $feed); … … 326 529 327 530 $format = str_replace('%link', $link, $format); 328 531 329 echo $format; 532 echo $format; 330 533 } 331 534 332 535 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { … … 341 544 $link = $string . $link . '</a>'; 342 545 $format = str_replace('%link', $link, $format); 343 546 344 echo $format; 547 echo $format; 345 548 } 346 549 347 550 function get_pagenum_link($pagenum = 1) { -
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_rss('atom_self_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 59 </feed>