Ticket #4887: wp-app.php.patch
File wp-app.php.patch, 13.7 KB (added by , 17 years ago) |
---|
-
wp-app.php
13 13 require_once(ABSPATH . WPINC . '/post-template.php'); 14 14 require_once(ABSPATH . WPINC . '/atomlib.php'); 15 15 16 // Attempt to automatically detect whether to use querystring 17 // or PATH_INFO, based on our environment: 18 $use_querystring = $wp_version == 'MU' ? 1 : 0; 16 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] ); 19 17 20 // If using querystring, we need to put the path together manually:21 if ($use_querystring) {22 $GLOBALS['use_querystring'] = $use_querystring;23 $action = $_GET['action'];24 $eid = (int) $_GET['eid'];25 26 $_SERVER['PATH_INFO'] = $action;27 28 if ($eid) {29 $_SERVER['PATH_INFO'] .= "/$eid";30 }31 } else {32 $_SERVER['PATH_INFO'] = str_replace( '.*/wp-app.php', '', $_SERVER['REQUEST_URI'] );33 }34 35 18 $app_logging = 0; 36 19 37 20 // TODO: Should be an option somewhere … … 142 125 143 126 // redirect to /service in case no path is found. 144 127 if(strlen($path) == 0 || $path == '/') { 145 128 $this->redirect($this->get_service_url()); 146 129 } 147 130 148 131 // dispatch … … 150 133 if(preg_match($regex, $path, $matches)) { 151 134 if(isset($funcs[$method])) { 152 135 153 154 155 156 157 158 159 160 161 136 // authenticate regardless of the operation and set the current 137 // user. each handler will decide if auth is required or not. 138 $this->authenticate(); 139 $u = wp_get_current_user(); 140 if(!isset($u) || $u->ID == 0) { 141 if ($always_authenticate) { 142 $this->auth_required('Credentials required.'); 143 } 144 } 162 145 163 164 165 146 array_shift($matches); 147 call_user_func_array(array(&$this,$funcs[$method]), $matches); 148 exit(); 166 149 } else { 167 168 150 // only allow what we have handlers for... 151 $this->not_allowed(array_keys($funcs)); 169 152 } 170 153 } 171 154 } … … 245 228 array_push($catnames, $cat["term"]); 246 229 247 230 $wp_cats = get_categories(array('hide_empty' => false)); 248 log_app('CATEGORIES :', print_r($wp_cats,true));249 231 250 232 $post_category = array(); 251 233 … … 352 334 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt'); 353 335 $this->escape($postdata); 354 336 355 log_app('UPDATING ENTRY WITH:', print_r($postdata,true));356 357 337 $result = wp_update_post($postdata); 358 338 359 339 if (!$result) { … … 606 586 } 607 587 608 588 function get_entries_url($page = NULL) { 609 global $use_querystring;610 589 if($GLOBALS['post_type'] == 'attachment') { 611 590 $path = $this->MEDIA_PATH; 612 591 } else { 613 592 $path = $this->ENTRIES_PATH; 614 593 } 615 $url = get_bloginfo('url') . '/' . $this->script_name; 616 if ($use_querystring) { 617 $url .= '?action=/' . $path; 618 if(isset($page) && is_int($page)) { 619 $url .= "&eid=$page"; 620 } 621 } else { 622 $url .= '/' . $path; 623 if(isset($page) && is_int($page)) { 624 $url .= "/$page"; 625 } 594 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $path; 595 if(isset($page) && is_int($page)) { 596 $url .= "/$page"; 626 597 } 627 598 return $url; 628 599 } … … 633 604 } 634 605 635 606 function get_categories_url($page = NULL) { 636 global $use_querystring; 637 $url = get_bloginfo('url') . '/' . $this->script_name; 638 if ($use_querystring) { 639 $url .= '?action=/' . $this->CATEGORIES_PATH; 640 } else { 641 $url .= '/' . $this->CATEGORIES_PATH; 642 } 643 return $url; 607 return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->CATEGORIES_PATH; 644 608 } 645 609 646 610 function the_categories_url() { … … 649 613 } 650 614 651 615 function get_attachments_url($page = NULL) { 652 global $use_querystring; 653 $url = get_bloginfo('url') . '/' . $this->script_name; 654 if ($use_querystring) { 655 $url .= '?action=/' . $this->MEDIA_PATH; 656 if(isset($page) && is_int($page)) { 657 $url .= "&eid=$page"; 658 } 659 } else { 660 $url .= '/' . $this->MEDIA_PATH; 661 if(isset($page) && is_int($page)) { 662 $url .= "/$page"; 663 } 616 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_PATH; 617 if(isset($page) && is_int($page)) { 618 $url .= "/$page"; 664 619 } 665 620 return $url; 666 621 } … … 671 626 } 672 627 673 628 function get_service_url() { 674 global $use_querystring; 675 $url = get_bloginfo('url') . '/' . $this->script_name; 676 if ($use_querystring) { 677 $url .= '?action=/' . $this->SERVICE_PATH; 678 } else { 679 $url .= '/' . $this->SERVICE_PATH; 680 } 681 return $url; 629 return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->SERVICE_PATH; 682 630 } 683 631 684 632 function get_entry_url($postID = NULL) { 685 global $use_querystring;686 633 if(!isset($postID)) { 687 634 global $post; 688 635 $postID = (int) $GLOBALS['post']->ID; 689 636 } 690 637 691 if ($use_querystring) { 692 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "&eid=$postID"; 693 } else { 694 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; 695 } 638 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; 696 639 697 640 log_app('function',"get_entry_url() = $url"); 698 641 return $url; … … 704 647 } 705 648 706 649 function get_media_url($postID = NULL) { 707 global $use_querystring;708 650 if(!isset($postID)) { 709 651 global $post; 710 652 $postID = (int) $GLOBALS['post']->ID; 711 653 } 712 654 713 if ($use_querystring) { 714 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."/file&eid=$postID"; 715 } else { 716 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID"; 717 } 655 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID"; 718 656 719 657 log_app('function',"get_media_url() = $url"); 720 658 return $url; … … 767 705 768 706 $count = get_option('posts_per_rss'); 769 707 770 wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($ page-1));708 wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) )); 771 709 772 710 $post = $GLOBALS['post']; 773 711 $posts = $GLOBALS['posts']; … … 783 721 $next_page = (($page + 1) > $last_page) ? NULL : $page + 1; 784 722 $prev_page = ($page - 1) < 1 ? NULL : $page - 1; 785 723 $last_page = ((int)$last_page == 1 || (int)$last_page == 0) ? NULL : (int) $last_page; 724 $self_page = $page > 1 ? $page : NULL; 786 725 ?><feed xmlns="<?php echo $this->ATOM_NS ?>" xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>"> 787 726 <id><?php $this->the_entries_url() ?></id> 788 727 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated> … … 796 735 <link rel="next" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url($next_page) ?>" /> 797 736 <?php endif; ?> 798 737 <link rel="last" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url($last_page) ?>" /> 799 <link rel="self" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url( ) ?>" />738 <link rel="self" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url($self_page) ?>" /> 800 739 <rights type="text">Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></rights> 801 740 <generator uri="http://wordpress.com/" version="1.0.5-dc">WordPress.com Atom API</generator> 802 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 803 $post = $GLOBALS['post']; 804 ?> 805 <entry> 806 <id><?php the_guid($post->ID); ?></id> 807 <title type="text"><![CDATA[<?php the_title_rss() ?>]]></title> 808 <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> 809 <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 810 <app:edited><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></app:edited> 811 <app:control> 812 <app:draft><?php echo ($GLOBALS['post']->post_status == 'draft' ? 'yes' : 'no') ?></app:draft> 813 </app:control> 814 <author> 815 <name><?php the_author()?></name> 816 <email><?php the_author_email()?></email> 817 <?php if (get_the_author_url() && get_the_author_url() != 'http://') { ?> 818 <uri><?php the_author_url()?></uri> 819 <?php } ?> 820 </author> 821 <?php if($GLOBALS['post']->post_type == 'attachment') { ?> 822 <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> 823 <content type="<?php echo $GLOBALS['post']->post_mime_type ?>" src="<?php the_guid(); ?>"/> 824 <?php } else { ?> 825 <link href="<?php the_permalink_rss() ?>" /> 826 <?php if ( strlen( $GLOBALS['post']->post_content ) ) : ?> 827 <content type="html"><![CDATA[<?php echo get_the_content('', 0, '') ?>]]></content> 828 <?php endif; ?> 829 <?php } ?> 830 <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 831 <?php foreach(get_the_category() as $category) { ?> 832 <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->cat_name?>" /> 833 <?php } ?> 834 <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 835 </entry> 836 <?php 837 endwhile; 838 endif; 741 <?php if ( have_posts() ) { 742 while ( have_posts() ) { 743 the_post(); 744 $this->echo_entry(); 745 } 746 } 839 747 ?></feed> 840 748 <?php 841 749 $feed = ob_get_contents(); … … 856 764 break; 857 765 } 858 766 query_posts($varname . '=' . $postID); 859 if ( have_posts() ) : while ( have_posts() ) : the_post(); 860 $post = $GLOBALS['post']; 861 ?> 862 <?php log_app('$post',print_r($GLOBALS['post'],true)); ?> 767 if ( have_posts() ) { 768 while ( have_posts() ) { 769 the_post(); 770 $this->echo_entry(); 771 log_app('$post',print_r($GLOBALS['post'],true)); 772 $entry = ob_get_contents(); 773 break; 774 } 775 } 776 ob_end_clean(); 777 778 log_app('get_entry returning:',$entry); 779 return $entry; 780 } 781 782 function echo_entry() { ?> 863 783 <entry xmlns="<?php echo $this->ATOM_NS ?>" 864 784 xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>"> 865 <id><?php the_guid($ post->ID); ?></id>866 <title type="text"><![CDATA[<?php the_title_rss() ?>]]></title>867 785 <id><?php the_guid($GLOBALS['post']->ID); ?></id> 786 <?php list($content_type, $content) = $this->prep_content(get_the_title()); ?> 787 <title type="<?php echo $content_type ?>"><?php echo $content ?></title> 868 788 <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> 869 789 <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 870 790 <app:edited><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></app:edited> … … 874 794 <author> 875 795 <name><?php the_author()?></name> 876 796 <email><?php the_author_email()?></email> 877 797 <?php if (get_the_author_url() && get_the_author_url() != 'http://') { ?> 878 798 <uri><?php the_author_url()?></uri> 879 799 <?php } ?> 880 800 </author> 881 801 <?php if($GLOBALS['post']->post_type == 'attachment') { ?> 882 802 <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> 883 803 <content type="<?php echo $GLOBALS['post']->post_mime_type ?>" src="<?php the_guid(); ?>"/> 884 804 <?php } else { ?> 885 805 <link href="<?php the_permalink_rss() ?>" /> 886 <?php if ( strlen( $GLOBALS['post']->post_content ) ) : ?> 887 <content type="<?php echo $GLOBALS['post']->post_mime_tpye ?>"><![CDATA[<?php echo get_the_content('', 0, '') ?>]]></content> 888 <?php endif; ?> 806 <?php if ( strlen( $GLOBALS['post']->post_content ) ) : 807 list($content_type, $content) = $this->prep_content(get_the_content()); ?> 808 <content type="<?php echo $content_type ?>"><?php echo $content ?></content> 809 <?php endif; ?> 889 810 <?php } ?> 890 811 <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 891 812 <?php foreach(get_the_category() as $category) { ?> 892 813 <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->cat_name?>" /> 893 814 <?php } ?> 894 <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 895 </entry> 896 <?php 897 $entry = ob_get_contents(); 898 break; 899 endwhile; 900 endif; 901 ob_end_clean(); 815 <?php list($content_type, $content) = $this->prep_content(get_the_excerpt()); ?> 816 <summary type="<?php echo $content_type ?>"><?php echo $content ?></summary> 817 </entry> 818 <?php } 902 819 903 log_app('get_entry returning:',$entry); 904 return $entry; 820 function prep_content($data) { 821 if (strpos($data, '<') === false && strpos($data, '&') === false) { 822 return array('text', $data); 823 } 824 825 $parser = xml_parser_create(); 826 xml_parse($parser, '<div>' . $data . '</div>', true); 827 $code = xml_get_error_code($parser); 828 xml_parser_free($parser); 829 830 if (!$code) { 831 $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; 832 return array('xhtml', $data); 833 } 834 835 if (strpos($data, ']]>') == false) { 836 return array('html', "<![CDATA[$data]]>"); 837 } else { 838 return array('html', htmlspecialchars($data)); 839 } 905 840 } 906 841 907 842 function ok() { … … 997 932 } 998 933 999 934 function created($post_ID, $content, $post_type = 'post') { 1000 global $use_querystring;1001 935 log_app('created()::$post_ID',"$post_ID, $post_type"); 1002 936 $edit = $this->get_entry_url($post_ID); 1003 937 switch($post_type) { … … 1005 939 $ctloc = $this->get_entry_url($post_ID); 1006 940 break; 1007 941 case 'attachment': 1008 if ($use_querystring) { 1009 $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments&eid=$post_ID"; 1010 } else { 1011 $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; 1012 } 942 $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; 1013 943 break; 1014 944 } 1015 945 header("Content-Type: $this->ATOM_CONTENT_TYPE");