Changeset 1565
- Timestamp:
- 08/26/2004 03:42:43 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xmlrpc.php
r1563 r1565 6 6 include('../wp-config.php'); 7 7 include_once(ABSPATH . WPINC . '/class-IXR.php'); 8 include_once(ABSPATH . WPINC . '/functions-post.php'); 8 9 9 10 // Turn off all warnings and errors. … … 13 14 $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category 14 15 15 $xmlrpc_logging = 0;16 $xmlrpc_logging = 1; 16 17 17 18 function logIO($io,$msg) { … … 34 35 logIO("I", $HTTP_RAW_POST_DATA); 35 36 36 37 function printr ( $var, $do_not_echo = false ) 38 { 39 ob_start(); 40 print_r($var); 41 $code = htmlentities(ob_get_contents()); 42 ob_clean(); 43 if ( !$do_not_echo ) 44 { 45 echo "<pre>$code</pre>"; 46 } 47 return $code; 48 } 37 49 38 50 class wp_xmlrpc_server extends IXR_Server { … … 53 65 'metaWeblog.editPost' => 'this:mw_editPost', 54 66 'metaWeblog.getPost' => 'this:mw_getPost', 67 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', 68 'metaWeblog.getCategories' => 'this:mw_getCategories', 55 69 56 70 'demo.sayHello' => 'this:sayHello', … … 71 85 function login_pass_ok($user_login, $user_pass) { 72 86 if (!user_pass_ok($user_login, $user_pass)) { 73 $this->error = new IXR_Error(403, 'Bad login/pass combination.' );87 $this->error = new IXR_Error(403, 'Bad login/pass combination.'.$user_login); 74 88 return false; 75 89 } … … 146 160 147 161 $user_data = get_userdatabylogin($user_login); 148 $post_data = get_postdata($post_ID); 149 150 $post_date = mysql2date('Ymd\TH:i:s', $post_data['Date']); 162 $post_data = wp_get_single_post($post_ID, ARRAY_A); 151 163 152 164 $categories = implode(',', wp_get_post_cats(1, $post_ID)); 153 165 154 $content = '<title>'.stripslashes($post_data[' Title']).'</title>';166 $content = '<title>'.stripslashes($post_data['post_title']).'</title>'; 155 167 $content .= '<category>'.$categories.'</category>'; 156 $content .= stripslashes($post_data[' Content']);168 $content .= stripslashes($post_data['post_content']); 157 169 158 170 $struct = array( 159 'userid' => $post_data[' Author_ID'],160 'dateCreate ed' => mysql2date('Ymd\TH:i:s', $post_data['Date']),171 'userid' => $post_data['post_author'], 172 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s\Z', $post_data['post_date_gmt'])), 161 173 'content' => $content, 162 174 'postid' => $post_data['ID'] … … 177 189 $num_posts = $args[4]; 178 190 179 if ($num_posts > 0) { 180 $limit = " LIMIT $num_posts"; 181 } else { 182 $limit = ''; 183 } 184 185 if (!$this->login_pass_ok($user_login, $user_pass)) { 186 return $this->error; 187 } 188 189 $sql = "SELECT * FROM $wpdb->posts ORDER BY post_date DESC".$limit; 190 $result = $wpdb->get_results($sql); 191 192 if (!$result) { 191 if (!$this->login_pass_ok($user_login, $user_pass)) { 192 return $this->error; 193 } 194 195 $posts_list = wp_get_recent_posts($num_posts); 196 197 if (!$posts_list) { 193 198 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 194 199 return $this->error; 195 200 } 196 201 197 $i = 0; 198 foreach ($result as $row) { 199 $post_data = array( 200 'ID' => $row->ID, 201 'Author_ID' => $row->post_author, 202 'Date' => $row->post_date, 203 'Content' => $row->post_content, 204 'Title' => $row->post_title, 205 'Category' => $row->post_category 202 foreach ($posts_list as $entry) { 203 204 $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']); 205 $categories = implode(',', wp_get_post_cats(1, $entry['ID'])); 206 207 $content = '<title>'.stripslashes($entry['post_itle']).'</title>'; 208 $content .= '<category>'.$categories.'</category>'; 209 $content .= stripslashes($entry['post_content']); 210 211 $struct[] = array( 212 'userid' => $entry['post_author'], 213 'dateCreated' => new IXR_Date($post_date), 214 'content' => $content, 215 'postid' => $entry['ID'], 206 216 ); 207 217 208 $categories = implode(',', wp_get_post_cats(1, $post_data['ID']));209 $post_date = mysql2date("Ymd\TH:i:s", $post_data['Date']);210 211 $content = '<title>'.stripslashes($post_data['Title']).'</title>';212 $content .= '<category>'.$categories.'</category>';213 $content .= stripslashes($post_data['Content']);214 215 $author_data = get_userdata($post_data['Author_ID']);216 217 switch($author_data['user_idmode']) {218 case 'nickname':219 $author_name = $author_data['user_nickname'];220 case 'login':221 $author_name = $author_data['user_login'];222 break;223 case 'firstname':224 $author_name = $author_data['user_firstname'];225 break;226 case 'lastname':227 $author_name = $author_data['user_lastname'];228 break;229 case 'namefl':230 $author_name = $author_data['user_firstname']." ".$author_data['user_lastname'];231 break;232 case 'namelf':233 $author_name = $author_data['user_lastname']." ".$author_data['user_firstname'];234 break;235 default:236 $author_name = $author_data['user_nickname'];237 break;238 }239 240 $struct[$i] = array(241 'authorName' => $author_name,242 'userid' => $post_data['Author_ID'],243 'dateCreated' => $post_date,244 'content' => $content,245 'postid' => $post_data['ID'],246 'category' => $categories247 );248 249 $i++;250 218 } 251 219 … … 286 254 287 255 /* so it is actually editable with a windows/mac client */ 288 $content = str_replace("\n", "\r\n", $content);256 // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content); 289 257 290 258 return $content; … … 511 479 $catnames = $content_struct['categories']; 512 480 // FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true)); 481 //logio('O', 'Post cats: ' . printr($catnames,true)); 513 482 $post_category = array(); 514 483 … … 627 596 628 597 $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']); 629 598 599 $categories = array(); 630 600 $catids = wp_get_post_cats('', $post_ID); 631 601 foreach($catids as $catid) { 632 $catname = get_cat_name($catid); 633 $catnameenc = new xmlrpcval($catname); 634 $catlist[] = $catnameenc; 602 $categories[] = get_cat_name($catid); 635 603 } 604 636 605 $post = get_extended($postdata['post_content']); 606 $link = post_permalink($entry['ID']); 607 637 608 $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0; 638 609 $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; 639 610 640 611 $resp = array( 641 'link' => post_permalink($post_ID),612 'link' => $link, 642 613 'title' => $postdata['post_title'], 643 614 'description' => $post['main'], … … 646 617 'postid' => $postdata['ID'], 647 618 'content' => $postdata['post_content'], 648 'permalink' => post_permalink($post_ID),649 'categories' => $cat list,619 'permalink' => $link, 620 'categories' => $categories, 650 621 'mt_excerpt' => $postdata['post_excerpt'], 651 622 'mt_allow_comments' => $allow_comments, … … 659 630 } 660 631 } 661 632 633 634 /* metaweblog.getRecentPosts ...returns recent posts */ 635 function mw_getRecentPosts($args) { 636 637 $blog_ID = $args[0]; 638 $user_login = $args[1]; 639 $user_pass = $args[2]; 640 $num_posts = $args[4]; 641 642 if (!$this->login_pass_ok($user_login, $user_pass)) { 643 return $this->error; 644 } 645 646 $posts_list = wp_get_recent_posts($num_posts); 647 648 if (!$posts_list) { 649 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 650 return $this->error; 651 } 652 653 foreach ($posts_list as $entry) { 654 655 $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']); 656 $categories = array(); 657 $catids = wp_get_post_cats('', $entry['ID']); 658 foreach($catids as $catid) { 659 $categories[] = get_cat_name($catid); 660 } 661 662 $post = get_extended($entry['post_content']); 663 $link = post_permalink($entry['ID']); 664 665 $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0; 666 $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0; 667 668 $struct[] = array( 669 'link' => $link, 670 'title' => $entry['post_title'], 671 'description' => $post['main'], 672 'dateCreated' => new IXR_Date($post_date), 673 'userid' => $entry['post_author'], 674 'postid' => $entry['ID'], 675 'content' => $entry['post_content'], 676 'permalink' => $link, 677 'categories' => $categories, 678 'mt_excerpt' => $entry['post_excerpt'], 679 'mt_allow_comments' => $allow_comments, 680 'mt_allow_pings' => $allow_pings, 681 'mt_text_more' => $post['extended'] 682 ); 683 684 } 685 686 $recent_posts = array(); 687 for ($j=0; $j<count($struct); $j++) { 688 array_push($recent_posts, $struct[$j]); 689 } 690 691 return $recent_posts; 692 } 693 694 695 /* metaweblog.getCategories ...returns the list of categories on a given weblog */ 696 function mw_getCategories($args) { 697 698 global $wpdb; 699 700 $blog_ID = $args[0]; 701 $user_login = $args[1]; 702 $user_pass = $args[2]; 703 704 if (!$this->login_pass_ok($user_login, $user_pass)) { 705 return $this->error; 706 } 707 708 $categories_struct = array(); 709 710 // FIXME: can we avoid using direct SQL there? 711 if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) { 712 foreach ($cats as $cat) { 713 $struct['categoryId'] = $cat['cat_ID']; 714 $struct['description'] = $cat['cat_name']; 715 $struct['categoryName'] = $cat['cat_name']; 716 $struct['htmlUrl'] = htmlspecialchars(get_category_link(false, $cat['cat_ID'], $cat['cat_name'])); 717 $struct['rssUrl'] = htmlspecialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name'])); 718 719 $categories_struct[] = $struct; 720 } 721 } 722 723 return $categories_struct; 724 } 725 662 726 } 663 727
Note: See TracChangeset
for help on using the changeset viewer.