Ticket #9510: 9510-v3.patch
| File 9510-v3.patch, 17.4 KB (added by peaceablewhale, 4 years ago) |
|---|
-
feed-atom.php
13 13 xmlns="http://www.w3.org/2005/Atom" 14 14 xmlns:thr="http://purl.org/syndication/thread/1.0" 15 15 xml:lang="<?php echo get_option('rss_language'); ?>" 16 xml:base="<?php bloginfo_rss(' home') ?>/wp-atom.php"16 xml:base="<?php bloginfo_rss('url') ?>/wp-atom.php" 17 17 <?php do_action('atom_ns'); ?> 18 18 > 19 19 <title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title> 20 <subtitle type="text"><?php bloginfo_rss("description") ?></subtitle> 21 20 <?php atom_header(); the_generator('atom'); do_action('atom_head'); ?> 22 21 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated> 23 <?php the_generator( 'atom' ); ?>24 25 <link rel="alternate" type="text/html" href="<?php bloginfo_rss('home') ?>" />26 <id><?php bloginfo('atom_url'); ?></id>27 <link rel="self" type="application/atom+xml" href="<?php self_link(); ?>" />28 29 <?php do_action('atom_head'); ?>30 22 <?php while (have_posts()) : the_post(); ?> 31 23 <entry> 32 24 <author> … … 52 44 <thr:total><?php echo get_comments_number()?></thr:total> 53 45 </entry> 54 46 <?php endwhile ; ?> 55 </feed> 47 </feed> 48 No newline at end of file -
feed.php
559 559 560 560 return $feed; 561 561 } 562 563 function echo_atom_feed_id($feed_id) { 564 echo "<id>$feed_id</id>\n"; 565 } 566 function echo_atom_feed_subtitle($feed_subtitle) { 567 if(!empty($feed_subtitle)) { 568 echo '<subtitle type="text">'.$feed_subtitle.'</subtitle>'."\n"; 569 } 570 } 571 function echo_atom_feed_links($self_link,$alternate_link,$replies_link) { 572 echo '<link rel="self" type="application/atom+xml" href="'.$self_link.'" />'."\n".'<link rel="alternate" type="'.get_option('html_type').'" href="'.$alternate_link.'" />'."\n".'<link rel="replies" type="application/atom+xml" href="'.$replies_link.'" />'."\n"; 573 } 574 function atom_header() { 575 $feed_type="atom"; 576 if(is_category()) { 577 $cat_id=get_query_object_id(); 578 echo_atom_feed_id(get_category_feed_link($cat_id,$feed_type,true)); 579 echo_atom_feed_links(get_category_feed_link($cat_id,$feed_type),get_category_link($cat_id),get_category_comments_feed_link($cat_id,$feed_type)); 580 } 581 elseif(is_tag()) { 582 $tag_atom_id=get_query_object_id(); 583 echo_atom_feed_id(get_tag_feed_link($tag_id,$feed_type,true)); 584 echo_atom_feed_links(get_tag_feed_link($tag_id,$feed_type),get_tag_link($tag_id),get_tag_comments_feed_link($tag_id,$feed_type)); 585 } 586 elseif(is_author()) { 587 $author_id=get_query_object_id(); 588 echo_atom_feed_id(get_author_feed_link($author_id,$feed_type,true)); 589 echo_atom_feed_links(get_author_feed_link($author_id,$feed_type),get_author_posts_url($author_id),get_author_comments_feed_link($author_id,$feed_type)); 590 } 591 elseif(is_date()) { 592 $year=$month=$day=$hour=$minute=$second=$canonical_feed_link=$alternate_link=$comments_feed_link=null; 593 $year_string=get_query_var('year'); 594 $month_string=get_query_var('monthnum'); 595 $day_string=get_query_var('day'); 596 $hour_string=get_query_var('hour'); 597 $minute_string=get_query_var('minute'); 598 $second_string=get_query_var('second'); 599 $m=get_query_var('m'); 600 $week=get_query_var('w'); 601 if(!empty($week)) { 602 if(!empty($year_string)) { 603 $year=$year_string; 604 } 605 elseif(!empty($m)&&strlen($m)>=4) { 606 $year=substr($m,0,4); 607 } 608 $canonical_feed_link=get_week_feed_link($year,$week,$feed_type); 609 $alternate_link=get_week_link($year,$week); 610 $comments_feed_link=get_week_comments_feed_link($year,$week,$feed_type); 611 } 612 elseif(empty($m)) { 613 if(!empty($year_string)) { 614 $year=$year_string; 615 } 616 if(!empty($month_string)) { 617 $month=$month_string; 618 } 619 if(!empty($day_string)) { 620 $day=$day_string; 621 } 622 if(!empty($hour_string)) { 623 $hour=$hour_string; 624 } 625 if(!empty($minute_string)) { 626 $minute=$minute_string; 627 } 628 if(!empty($second_string)) { 629 $second=$second_string; 630 } 631 } 632 else { 633 $m_length=strlen($m); 634 switch($m_length) { 635 case 14: 636 $second=substr($m,12,2); 637 case 12: 638 $minute=substr($m,10,2); 639 case 10: 640 $hour=substr($m,8,2); 641 case 8: 642 $day=substr($m,6,2); 643 case 6: 644 $month=substr($m,4,2); 645 case 4: 646 $year=substr($m,0,4); 647 break; 648 default: 649 return false; 650 } 651 } 652 if($canonical_feed_link===null) { 653 $canonical_feed_link=get_archive_feed_link($year,$month,$day,$hour,$minute,$second,$feed_type); 654 } 655 if($alternate_link===null) { 656 $alternate_link=get_archive_link($year,$month,$day,$hour,$minute,$second); 657 } 658 if($comments_feed_link===null) { 659 $comments_feed_link=get_archive_comments_feed_link($year,$month,$day,$hour,$minute,$second,$feed_type); 660 } 661 echo_atom_feed_id($canonical_feed_link); 662 echo_atom_feed_links($canonical_feed_link,$alternate_link,$comments_feed_link); 663 } 664 else if(is_search()) { 665 $search_query=get_search_query(); 666 $canonical_feed_link=get_search_feed_link($search_query,$feed_type); 667 echo_atom_feed_id($canonical_feed_link); 668 echo_atom_feed_links($canonical_feed_link,get_search_link($search_query),get_search_comments_feed_link($search_query,$feed_type)); 669 } 670 else { 671 echo_atom_feed_subtitle(get_bloginfo_rss("description")); 672 echo_atom_feed_id(get_feed_link('atom',true)); 673 echo_atom_feed_links(get_bloginfo('atom_url'),trailingslashit(get_bloginfo_rss('url')),get_bloginfo_rss('comments_atom_url')); 674 } 675 } -
link-template.php
359 359 * @param string $feed Optional, defaults to default feed. Feed type. 360 360 * @return string 361 361 */ 362 function get_feed_link($feed = '' ) {362 function get_feed_link($feed = '', $return_canonical_form = false) { 363 363 global $wp_rewrite; 364 364 365 365 $permalink = $wp_rewrite->get_feed_permastruct(); 366 if ( '' != $permalink ) { 366 if ($return_canonical_form==true||empty($permalink)) { 367 if ( empty($feed) ) 368 $feed = get_default_feed(); 369 370 if ( false !== strpos($feed, 'comments_') ) 371 $feed = str_replace('comments_', 'comments-', $feed); 372 373 $output = trailingslashit(get_option('home')) . "?feed={$feed}"; 374 } 375 else { 367 376 if ( false !== strpos($feed, 'comments_') ) { 368 377 $feed = str_replace('comments_', '', $feed); 369 378 $permalink = $wp_rewrite->get_comment_feed_permastruct(); … … 375 384 $permalink = str_replace('%feed%', $feed, $permalink); 376 385 $permalink = preg_replace('#/+#', '/', "/$permalink"); 377 386 $output = get_option('home') . user_trailingslashit($permalink, 'feed'); 378 } else {379 if ( empty($feed) )380 $feed = get_default_feed();381 382 if ( false !== strpos($feed, 'comments_') )383 $feed = str_replace('comments_', 'comments-', $feed);384 385 $output = trailingslashit(get_option('home')) . "?feed={$feed}";386 387 } 387 388 388 389 return apply_filters('feed_link', $output, $feed); 389 390 } 390 391 … … 397 398 * @param string $feed Optional. Feed type. 398 399 * @return string 399 400 */ 400 function get_post_comments_feed_link($post_id = '', $feed = '' ) {401 function get_post_comments_feed_link($post_id = '', $feed = '', $return_canonical_form = false) { 401 402 global $id; 402 403 403 404 if ( empty($post_id) ) … … 406 407 if ( empty($feed) ) 407 408 $feed = get_default_feed(); 408 409 409 if ( '' != get_option('permalink_structure') ) { 410 $url = trailingslashit( get_permalink($post_id) ) . 'feed'; 411 if ( $feed != get_default_feed() ) 412 $url .= "/$feed"; 413 $url = user_trailingslashit($url, 'single_feed'); 414 } else { 410 if ($return_canonical_form==true||empty($permalink)) { 415 411 $type = get_post_field('post_type', $post_id); 416 412 if ( 'page' == $type ) 417 413 $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id"; 418 414 else 419 415 $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id"; 420 416 } 421 417 else { 418 $url = trailingslashit( get_permalink($post_id) ) . 'feed'; 419 if ( $feed != get_default_feed() ) 420 $url .= "/$feed"; 421 $url = user_trailingslashit($url, 'single_feed'); 422 } 423 422 424 return apply_filters('post_comments_feed_link', $url); 423 425 } 424 426 … … 438 440 * @param string $feed Optional. Feed format. 439 441 * @return string Link to the comment feed for the current post. 440 442 */ 441 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {442 $url = get_post_comments_feed_link($post_id, $feed );443 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '', $return_canonical_form = false) { 444 $url = get_post_comments_feed_link($post_id, $feed, $return_canonical_form); 443 445 if ( empty($link_text) ) 444 446 $link_text = __('Comments Feed'); 445 447 … … 460 462 * @param string $feed Optional. Feed type. 461 463 * @return string Link to the feed for the author specified by $author_id. 462 464 */ 463 function get_author_feed_link( $author_id, $feed = '' ) {465 function get_author_feed_link( $author_id, $feed = '', $return_canonical_form = false) { 464 466 $author_id = (int) $author_id; 465 467 $permalink_structure = get_option('permalink_structure'); 466 468 467 469 if ( empty($feed) ) 468 470 $feed = get_default_feed(); 469 471 470 if ( '' == $permalink_structure) {472 if ($return_canonical_form==true||empty($permalink_structure)) { 471 473 $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id; 472 } else { 474 } 475 else { 473 476 $link = get_author_posts_url($author_id); 474 477 if ( $feed == get_default_feed() ) 475 478 $feed_link = 'feed'; … … 484 487 return $link; 485 488 } 486 489 490 function get_author_comments_feed_link($author_id, $feed = '', $return_canonical_form = false) { 491 $author_id = (int) $author_id; 492 $permalink_structure = get_option('permalink_structure'); 493 494 if ( empty($feed) ) 495 $feed = get_default_feed(); 496 497 if ($return_canonical_form==true||empty($permalink_structure)) { 498 $link = trailingslashit(get_option('home')) . "?feed=comments-$feed&author=" . $author_id; 499 } 500 else { 501 $link = get_author_posts_url($author_id); 502 if ( $feed == get_default_feed() ) 503 $feed_link = 'comments/feed'; 504 else 505 $feed_link = "comments/feed/$feed"; 506 507 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); 508 } 509 510 $link = apply_filters('author_comments_feed_link', $link, $feed); 511 512 return $link; 513 } 514 487 515 /** 488 516 * Retrieve the feed link for a category. 489 517 * … … 498 526 * @param string $feed Optional. Feed type. 499 527 * @return string Link to the feed for the category specified by $cat_id. 500 528 */ 501 function get_category_feed_link($cat_id, $feed = '' ) {529 function get_category_feed_link($cat_id, $feed = '', $return_canonical_form = false) { 502 530 $cat_id = (int) $cat_id; 503 531 504 532 $category = get_category($cat_id); … … 511 539 512 540 $permalink_structure = get_option('permalink_structure'); 513 541 514 if ( '' == $permalink_structure) {542 if ($return_canonical_form==true||empty($permalink_structure)) { 515 543 $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id; 516 } else { 544 } 545 else { 517 546 $link = get_category_link($cat_id); 518 547 if( $feed == get_default_feed() ) 519 548 $feed_link = 'feed'; … … 528 557 return $link; 529 558 } 530 559 560 function get_category_comments_feed_link($cat_id, $feed = '', $return_canonical_form = false) { 561 $cat_id = (int) $cat_id; 562 563 $category = get_category($cat_id); 564 565 if ( empty($category) || is_wp_error($category) ) 566 return false; 567 568 if ( empty($feed) ) 569 $feed = get_default_feed(); 570 571 $permalink_structure = get_option('permalink_structure'); 572 573 if ($return_canonical_form==true||empty($permalink_structure)) { 574 $link = trailingslashit(get_option('home')) . "?feed=comments-$feed&cat=" . $cat_id; 575 } 576 else { 577 $link = get_category_link($cat_id); 578 if( $feed == get_default_feed() ) 579 $feed_link = 'comments/feed'; 580 else 581 $feed_link = "comments/feed/$feed"; 582 583 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); 584 } 585 586 $link = apply_filters('category_comments_feed_link', $link, $feed); 587 588 return $link; 589 } 590 531 591 /** 532 592 * Retrieve permalink for feed of tag. 533 593 * … … 537 597 * @param string $feed Optional. Feed type. 538 598 * @return string 539 599 */ 540 function get_tag_feed_link($tag_id, $feed = '' ) {600 function get_tag_feed_link($tag_id, $feed = '', $return_canonical_form = false) { 541 601 $tag_id = (int) $tag_id; 542 602 543 603 $tag = get_tag($tag_id); … … 550 610 if ( empty($feed) ) 551 611 $feed = get_default_feed(); 552 612 553 if ( '' == $permalink_structure) {613 if ($return_canonical_form==true||empty($permalink_structure)) { 554 614 $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug; 555 } else { 615 } 616 else { 556 617 $link = get_tag_link($tag->term_id); 557 618 if ( $feed == get_default_feed() ) 558 619 $feed_link = 'feed'; … … 566 627 return $link; 567 628 } 568 629 630 function get_tag_comments_feed_link($tag_id, $feed = '', $return_canonical_form = false) { 631 $tag_id = (int) $tag_id; 632 633 $tag = get_tag($tag_id); 634 635 if ( empty($tag) || is_wp_error($tag) ) 636 return false; 637 638 $permalink_structure = get_option('permalink_structure'); 639 640 if ( empty($feed) ) 641 $feed = get_default_feed(); 642 643 if ($return_canonical_form==true||empty($permalink_structure)) { 644 $link = trailingslashit(get_option('home')) . "?feed=comments-$feed&tag=" . $tag->slug; 645 } 646 else { 647 $link = get_tag_link($tag->term_id); 648 if ( $feed == get_default_feed() ) 649 $feed_link = 'comments/feed'; 650 else 651 $feed_link = "comments/feed/$feed"; 652 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); 653 } 654 655 $link = apply_filters('tag_comments_feed_link', $link, $feed); 656 657 return $link; 658 } 659 569 660 /** 570 661 * Retrieve edit tag link. 571 662 * … … 608 699 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; 609 700 } 610 701 702 function get_search_link($search_query) { 703 if (empty($search_query)) { 704 $search=attribute_escape(get_search_query()); 705 } 706 else { 707 $search=attribute_escape(stripslashes($search_query)); 708 } 709 $link=trailingslashit(get_option('home'))."?s=$search"; 710 $link=apply_filters('search_link',$link); 711 return $link; 712 } 713 611 714 /** 612 715 * Retrieve the permalink for the feed of the search results. 613 716 * … … 658 761 return $link; 659 762 } 660 763 764 function _archive_array_to_link($array) { 765 $link=$array[0]; 766 $array_length=count($array); 767 if($array_length>1) { 768 $link.="?$array[1]"; 769 if($array_length>2) { 770 for($i=2;$i<$array_length;$i++) { 771 $link.="&$array[$i]"; 772 } 773 } 774 } 775 return $link; 776 } 777 function get_archive_link($year,$month=null,$day=null,$hour=null,$minute=null,$second=null,$return_array=false) { 778 $array=array(trailingslashit(get_option('home'))); 779 if($year!==null) { 780 $year=(int)$year; 781 if($year<=0) { 782 return false; 783 } 784 $array[]="year=$year"; 785 } 786 if($month!==null) { 787 $month=(int)$month; 788 if($month<1||$month>12) { 789 return false; 790 } 791 $array[]="monthnum=$month"; 792 } 793 if($day!==null) { 794 $day=(int)$day; 795 if($day<1||$day>31) { 796 return false; 797 } 798 $array[]="day=$day"; 799 } 800 if($hour!==null) { 801 $hour=(int)$hour; 802 if($hour<0||$hour>23) { 803 return false; 804 } 805 $array[]="hour=$hour"; 806 } 807 if($minute!==null) { 808 $minute=(int)$minute; 809 if($minute<0||$minute>60) { 810 return false; 811 } 812 $array[]="minute=$minute"; 813 } 814 if($second!==null) { 815 $second=(int)$second; 816 if($second<0||$second>60) { 817 return false; 818 } 819 $array[]="second=$second"; 820 } 821 if($return_array==true) { 822 return $array; 823 } 824 else { 825 return apply_filters('archive_link',_archive_array_to_link($array)); 826 } 827 } 828 function get_archive_feed_link($year,$month=null,$day=null,$hour=null,$minute=null,$second=null,$feed='') { 829 $array=get_archive_link($year,$month,$day,$hour,$minute,$second,true); 830 if($array===false) { 831 return false; 832 } 833 if(empty($feed)) { 834 $feed=get_default_feed(); 835 } 836 $array[]="feed=$feed"; 837 return apply_filters('archive_feed_link',_archive_array_to_link($array),$feed); 838 } 839 function get_archive_comments_feed_link($year,$month=null,$day=null,$hour=null,$minute=null,$second=null,$feed='') { 840 $array=get_archive_link($year,$month,$day,$hour,$minute,$second,true); 841 if($array===false) { 842 return false; 843 } 844 if(empty($feed)) { 845 $feed=get_default_feed(); 846 } 847 $array[]="feed=comments-$feed"; 848 return apply_filters('archive_comments_feed_link',_archive_array_to_link($array),$feed); 849 } 850 function get_week_link($year,$week,$return_array=false) { 851 $array=get_archive_link($year,null,null,null,null,null,true); 852 $week=(int)$week; 853 if($array===false||$week<0||$week>53) { 854 return false; 855 } 856 $array[]="w=$week"; 857 if($return_array==true) { 858 return $array; 859 } 860 else { 861 return apply_filters('week_link',_archive_array_to_link($array)); 862 } 863 } 864 function get_week_feed_link($year,$week,$feed='') { 865 $array=get_week_link($year,$week,true); 866 if($array===false) { 867 return false; 868 } 869 if(empty($feed)) { 870 $feed=get_default_feed(); 871 } 872 $array[]="feed=$feed"; 873 return apply_filters('week_feed_link',_archive_array_to_link($array),$feed); 874 } 875 function get_week_comments_feed_link($year,$week,$feed='') { 876 $array=get_week_link($year,$week,true); 877 if($array===false) { 878 return false; 879 } 880 if(empty($feed)) { 881 $feed=get_default_feed(); 882 } 883 $array[]="feed=comments-$feed"; 884 return apply_filters('week_comments_feed_link',_archive_array_to_link($array),$feed); 885 } 886 661 887 /** 662 888 * Retrieve edit posts link for post. 663 889 * -
query.php
11 11 * @subpackage Query 12 12 */ 13 13 14 function get_query_object_id() { 15 global $wp_query; 16 return $wp_query->get_queried_object_id(); 17 } 18 14 19 /** 15 20 * Retrieve variable in the WP_Query class. 16 21 *
