Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1288 lines (943 sloc) 37.157 kb
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
1 <?php
2
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
3 define('XMLRPC_REQUEST', true);
4
5 // Some browser-embedded clients send cookies. We don't want them.
6 $_COOKIE = array();
7
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
8 # fix for mozBlog and other cases where '<?xml' isn't on the very first line
9 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
10
4fe64950 » michelvaldrighi
2004-09-18 whoops, a dot that was removed yesterday came back when restoring the…
11 include('./wp-config.php');
af8c37fd » matt
2005-11-07 Add RSD support. See http://archipelago.phrasewise.com/rsd
12
13 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
14 header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
15
16 ?>
17 <?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?>
18 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
19 <service>
20 <engineName>WordPress</engineName>
21 <engineLink>http://wordpress.org/</engineLink>
22 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
23 <apis>
24 <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
25 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
26 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
27 </apis>
28 </service>
29 </rsd>
30 <?php
31 exit;
32 }
33
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
34 include_once(ABSPATH . WPINC . '/class-IXR.php');
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
35
36 // Turn off all warnings and errors.
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
37 // error_reporting(0);
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
38
39 $post_default_title = ""; // posts submitted via the xmlrpc interface get that title
40
80b3445c » michelvaldrighi
2004-09-14 fixed comment_status screwup, removed debug stuff, screwed up big tim…
41 $xmlrpc_logging = 0;
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
42
43 function logIO($io,$msg) {
44 global $xmlrpc_logging;
45 if ($xmlrpc_logging) {
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
46 $fp = fopen("../xmlrpc.log","a+");
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
47 $date = gmdate("Y-m-d H:i:s ");
48 $iot = ($io == "I") ? " Input: " : " Output: ";
49 fwrite($fp, "\n\n".$date.$iot.$msg);
50 fclose($fp);
51 }
52 return true;
53 }
54
55 function starify($string) {
56 $i = strlen($string);
57 return str_repeat('*', $i);
58 }
59
60 logIO("I", $HTTP_RAW_POST_DATA);
61
96114636 » michelvaldrighi
2004-09-01 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
62
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
63 function mkdir_p($target) {
64 // from php.net/mkdir user contributed notes
65 if (file_exists($target)) {
66 if (!is_dir($target)) {
67 return false;
68 } else {
69 return true;
70 }
96114636 » michelvaldrighi
2004-09-01 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
71 }
72
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
73 // Attempting to create the directory may clutter up our display.
74 if (@mkdir($target)) {
75 return true;
96114636 » michelvaldrighi
2004-09-01 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
76 }
77
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
78 // If the above failed, attempt to create the parent node, then try again.
79 if (mkdir_p(dirname($target))) {
80 return mkdir_p($target);
96114636 » michelvaldrighi
2004-09-01 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
81 }
82
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
83 return false;
96114636 » michelvaldrighi
2004-09-01 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
84 }
85
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
86
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
87 class wp_xmlrpc_server extends IXR_Server {
88
89 function wp_xmlrpc_server() {
90 $this->methods = array(
91 // Blogger API
92 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
93 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
94 'blogger.getPost' => 'this:blogger_getPost',
95 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
96 'blogger.getTemplate' => 'this:blogger_getTemplate',
97 'blogger.setTemplate' => 'this:blogger_setTemplate',
98 'blogger.newPost' => 'this:blogger_newPost',
99 'blogger.editPost' => 'this:blogger_editPost',
100 'blogger.deletePost' => 'this:blogger_deletePost',
101
102 // MetaWeblog API (with MT extensions to structs)
103 'metaWeblog.newPost' => 'this:mw_newPost',
104 'metaWeblog.editPost' => 'this:mw_editPost',
105 'metaWeblog.getPost' => 'this:mw_getPost',
106 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
107 'metaWeblog.getCategories' => 'this:mw_getCategories',
108 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
109
110 // MetaWeblog API aliases for Blogger API
111 // see http://www.xmlrpc.com/stories/storyReader$2460
112 'metaWeblog.deletePost' => 'this:blogger_deletePost',
113 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
114 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
115 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
116
117 // MovableType API
118 'mt.getCategoryList' => 'this:mt_getCategoryList',
119 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
120 'mt.getPostCategories' => 'this:mt_getPostCategories',
121 'mt.setPostCategories' => 'this:mt_setPostCategories',
122 'mt.supportedMethods' => 'this:mt_supportedMethods',
123 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
124 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
125 'mt.publishPost' => 'this:mt_publishPost',
126
127 // PingBack
128 'pingback.ping' => 'this:pingback_ping',
129 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
130
131 'demo.sayHello' => 'this:sayHello',
132 'demo.addTwoNumbers' => 'this:addTwoNumbers'
133 );
087df40d » saxmatt
2005-01-06 Allow plugins to hook into XML-RPC server.
134 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
135 $this->IXR_Server($this->methods);
136 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
137
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
138 function sayHello($args) {
139 return 'Hello!';
140 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
141
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
142 function addTwoNumbers($args) {
143 $number1 = $args[0];
144 $number2 = $args[1];
145 return $number1 + $number2;
146 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
147
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
148 function login_pass_ok($user_login, $user_pass) {
149 if (!user_pass_ok($user_login, $user_pass)) {
150 $this->error = new IXR_Error(403, 'Bad login/pass combination.');
151 return false;
152 }
153 return true;
154 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
155
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
156 function escape(&$array) {
157 global $wpdb;
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
158
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
159 foreach ($array as $k => $v) {
160 if (is_array($v)) {
161 $this->escape($array[$k]);
3882320f » ryan
2005-06-29 Don't escape objects.
162 } else if (is_object($v)) {
163 //skip
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
164 } else {
165 $array[$k] = $wpdb->escape($v);
166 }
167 }
168 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
169
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
170 /* Blogger API functions
171 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
172 */
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
173
174
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
175 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
176 function blogger_getUsersBlogs($args) {
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
177
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
178 $this->escape($args);
179
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
180 $user_login = $args[1];
181 $user_pass = $args[2];
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
182
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
183 if (!$this->login_pass_ok($user_login, $user_pass)) {
184 return $this->error;
185 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
186
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
187 set_current_user(0, $user_login);
188 $is_admin = current_user_can('level_8');
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
189
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
190 $struct = array(
191 'isAdmin' => $is_admin,
637cfdc7 » saxmatt
2004-12-24 Cleaning up blogfilename.
192 'url' => get_settings('home') . '/',
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
193 'blogid' => '1',
194 'blogName' => get_settings('blogname')
195 );
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
196 error_log(print_r($struct,1), 3, '/tmp/xmlrpc');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
197 return array($struct);
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
198 }
199
200
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
201 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
202 function blogger_getUserInfo($args) {
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
203
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
204 $this->escape($args);
205
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
206 $user_login = $args[1];
207 $user_pass = $args[2];
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
208
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
209 if (!$this->login_pass_ok($user_login, $user_pass)) {
210 return $this->error;
211 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
212
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
213 $user_data = get_userdatabylogin($user_login);
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
214
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
215 $struct = array(
1f9a608b » matt
2005-06-13 User data migration should be complete
216 'nickname' => $user_data->nickname,
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
217 'userid' => $user_data->ID,
218 'url' => $user_data->user_url,
219 'email' => $user_data->user_email,
1f9a608b » matt
2005-06-13 User data migration should be complete
220 'lastname' => $user_data->last_name,
221 'firstname' => $user_data->first_name
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
222 );
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
223
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
224 return $struct;
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
225 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
226
227
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
228 /* blogger.getPost ...gets a post */
229 function blogger_getPost($args) {
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
230
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
231 $this->escape($args);
232
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
233 $post_ID = $args[1];
234 $user_login = $args[2];
235 $user_pass = $args[3];
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
236
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
237 if (!$this->login_pass_ok($user_login, $user_pass)) {
238 return $this->error;
239 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
240
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
241 $user_data = get_userdatabylogin($user_login);
242 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
243
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
244 $categories = implode(',', wp_get_post_cats(1, $post_ID));
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
245
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
246 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
247 $content .= '<category>'.$categories.'</category>';
248 $content .= stripslashes($post_data['post_content']);
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
249
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
250 $struct = array(
251 'userid' => $post_data['post_author'],
252 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
253 'content' => $content,
254 'postid' => $post_data['ID']
255 );
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
256
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
257 return $struct;
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
258 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
259
260
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
261 /* blogger.getRecentPosts ...gets recent posts */
262 function blogger_getRecentPosts($args) {
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
263
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
264 global $wpdb;
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
265
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
266 $this->escape($args);
267
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
268 $blog_ID = $args[1]; /* though we don't use it yet */
269 $user_login = $args[2];
270 $user_pass = $args[3];
271 $num_posts = $args[4];
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
272
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
273 if (!$this->login_pass_ok($user_login, $user_pass)) {
274 return $this->error;
275 }
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
276
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
277 $posts_list = wp_get_recent_posts($num_posts);
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
278
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
279 if (!$posts_list) {
280 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
281 return $this->error;
282 }
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
283
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
284 foreach ($posts_list as $entry) {
285
286 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
287 $categories = implode(',', wp_get_post_cats(1, $entry['ID']));
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
288
8767434e » rboren
2004-12-13 Fix typo. Bug 540. Patch from Froosh.
289 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
290 $content .= '<category>'.$categories.'</category>';
291 $content .= stripslashes($entry['post_content']);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
292
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
293 $struct[] = array(
294 'userid' => $entry['post_author'],
295 'dateCreated' => new IXR_Date($post_date),
296 'content' => $content,
297 'postid' => $entry['ID'],
298 );
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
299
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
300 }
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
301
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
302 $recent_posts = array();
303 for ($j=0; $j<count($struct); $j++) {
304 array_push($recent_posts, $struct[$j]);
305 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
306
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
307 return $recent_posts;
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
308 }
309
310
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
311 /* blogger.getTemplate returns your blog_filename */
312 function blogger_getTemplate($args) {
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
313
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
314 $this->escape($args);
315
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
316 $blog_ID = $args[1];
317 $user_login = $args[2];
318 $user_pass = $args[3];
319 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
320
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
321 if (!$this->login_pass_ok($user_login, $user_pass)) {
322 return $this->error;
323 }
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
324
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
325 set_current_user(0, $user_login);
326 if ( !current_user_can('edit_themes') ) {
2f6ae330 » ryan
2005-07-15 Cap migration.
327 return new IXR_Error(401, 'Sorry, this user can not edit the template.');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
328 }
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
329
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
330 /* warning: here we make the assumption that the weblog's URI is on the same server */
637cfdc7 » saxmatt
2004-12-24 Cleaning up blogfilename.
331 $filename = get_settings('home') . '/';
41775561 » matt
2005-11-11 Add HTTPS support, fixes #1372
332 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
333
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
334 $f = fopen($filename, 'r');
335 $content = fread($f, filesize($filename));
336 fclose($f);
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
337
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
338 /* so it is actually editable with a windows/mac client */
339 // 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);
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
340
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
341 return $content;
342 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
343
344
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
345 /* blogger.setTemplate updates the content of blog_filename */
346 function blogger_setTemplate($args) {
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
347
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
348 $this->escape($args);
349
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
350 $blog_ID = $args[1];
351 $user_login = $args[2];
352 $user_pass = $args[3];
353 $content = $args[4];
354 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841e » michelvaldrighi
2004-05-23 added blogger.getTemplate and blogger.setTemplate
355
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
356 if (!$this->login_pass_ok($user_login, $user_pass)) {
357 return $this->error;
358 }
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
359
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
360 set_current_user(0, $user_login);
361 if ( !current_user_can('edit_themes') ) {
2f6ae330 » ryan
2005-07-15 Cap migration.
362 return new IXR_Error(401, 'Sorry, this user can not edit the template.');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
363 }
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
364
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
365 /* warning: here we make the assumption that the weblog's URI is on the same server */
637cfdc7 » saxmatt
2004-12-24 Cleaning up blogfilename.
366 $filename = get_settings('home') . '/';
41775561 » matt
2005-11-11 Add HTTPS support, fixes #1372
367 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
368
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
369 if ($f = fopen($filename, 'w+')) {
370 fwrite($f, $content);
371 fclose($f);
372 } else {
373 return new IXR_Error(500, 'Either the file is not writable, or something wrong happened. The file has not been updated.');
374 }
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
375
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
376 return true;
377 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
378
379
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
380 /* blogger.newPost ...creates a new post */
381 function blogger_newPost($args) {
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
382
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
383 global $wpdb;
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
384
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
385 $this->escape($args);
386
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
387 $blog_ID = $args[1]; /* though we don't use it yet */
388 $user_login = $args[2];
389 $user_pass = $args[3];
390 $content = $args[4];
391 $publish = $args[5];
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
392
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
393 if (!$this->login_pass_ok($user_login, $user_pass)) {
394 return $this->error;
395 }
c2fd7b83 » ryan
2005-09-07 Capability updates for xmlrpc.
396
397 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
398 $user = set_current_user(0, $user_login);
399 if ( !current_user_can($cap) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
400 return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.');
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
401
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
402 $post_status = ($publish) ? 'publish' : 'draft';
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
403
c2fd7b83 » ryan
2005-09-07 Capability updates for xmlrpc.
404 $post_author = $user->ID;
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
405
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
406 $post_title = xmlrpc_getposttitle($content);
407 $post_category = xmlrpc_getpostcategory($content);
183593f3 » ryan
2005-10-20 Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
408 $post_content = xmlrpc_removepostdata($content);
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
409
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
410 $post_date = current_time('mysql');
411 $post_date_gmt = current_time('mysql', 1);
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
412
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
413 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
414
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
415 $post_ID = wp_insert_post($post_data);
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
416
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
417 if (!$post_ID) {
418 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.');
419 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
420
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
421 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
422
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
423 return $post_ID;
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
424 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
425
426
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
427 /* blogger.editPost ...edits a post */
428 function blogger_editPost($args) {
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
429
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
430 global $wpdb;
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
431
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
432 $this->escape($args);
433
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
434 $post_ID = $args[1];
435 $user_login = $args[2];
436 $user_pass = $args[3];
183593f3 » ryan
2005-10-20 Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
437 $content = $args[4];
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
438 $publish = $args[5];
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
439
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
440 if (!$this->login_pass_ok($user_login, $user_pass)) {
441 return $this->error;
442 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
443
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
444 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
445
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
446 if (!$actual_post) {
447 return new IXR_Error(404, 'Sorry, no such post.');
448 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
449
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
450 $this->escape($actual_post);
451
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
452 set_current_user(0, $user_login);
453 if ( !current_user_can('edit_post', $post_ID) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
454 return new IXR_Error(401, 'Sorry, you do not have the right to edit this post.');
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
455
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
456 extract($actual_post);
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
457
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
458 $post_title = xmlrpc_getposttitle($content);
459 $post_category = xmlrpc_getpostcategory($content);
183593f3 » ryan
2005-10-20 Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
460 $post_content = xmlrpc_removepostdata($content);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
461
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
462 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
463
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
464 $result = wp_update_post($postdata);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
465
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
466 if (!$result) {
467 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.');
468 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
469
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
470 return true;
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
471 }
472
473
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
474 /* blogger.deletePost ...deletes a post */
475 function blogger_deletePost($args) {
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
476
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
477 global $wpdb;
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
478
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
479 $this->escape($args);
480
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
481 $post_ID = $args[1];
482 $user_login = $args[2];
483 $user_pass = $args[3];
484 $publish = $args[4];
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
485
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
486 if (!$this->login_pass_ok($user_login, $user_pass)) {
487 return $this->error;
488 }
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
489
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
490 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f7 » michelvaldrighi
2004-08-25 added blogger.editPost and blogger.deletePost, time to move on to met…
491
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
492 if (!$actual_post) {
493 return new IXR_Error(404, 'Sorry, no such post.');
494 }
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
495
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
496 set_current_user(0, $user_login);
497 if ( !current_user_can('edit_post', $post_ID) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
498 return new IXR_Error(401, 'Sorry, you do not have the right to delete this post.');
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
499
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
500 $result = wp_delete_post($post_ID);
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
501
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
502 if (!$result) {
503 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be deleted.');
504 }
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
505
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
506 return true;
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
507 }
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
508
509
510
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
511 /* MetaWeblog API functions
512 * specs on wherever Dave Winer wants them to be
513 */
80b3445c » michelvaldrighi
2004-09-14 fixed comment_status screwup, removed debug stuff, screwed up big tim…
514
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
515 /* metaweblog.newPost creates a post */
516 function mw_newPost($args) {
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
517
d1ea1c93 » ryan
2005-06-18 Use instead of hardcoding 1. Do we really need a separate default cat…
518 global $wpdb, $post_default_category;
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
519
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
520 $this->escape($args);
521
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
522 $blog_ID = $args[0]; // we will support this in the near future
523 $user_login = $args[1];
524 $user_pass = $args[2];
525 $content_struct = $args[3];
526 $publish = $args[4];
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
527
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
528 if (!$this->login_pass_ok($user_login, $user_pass)) {
529 return $this->error;
530 }
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
531
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
532 $user = set_current_user(0, $user_login);
533 if ( !current_user_can('publish_posts') )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
534 return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.');
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
535
c2fd7b83 » ryan
2005-09-07 Capability updates for xmlrpc.
536 $post_author = $user->ID;
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
537
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
538 $post_title = $content_struct['title'];
99df7e3a » saxmatt
2005-01-06 Cleaning up filters and format-to-post
539 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
540 $post_status = $publish ? 'publish' : 'draft';
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
541
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
542 $post_excerpt = $content_struct['mt_excerpt'];
543 $post_more = $content_struct['mt_text_more'];
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
544
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
545 $comment_status = (empty($content_struct['mt_allow_comments'])) ?
546 get_settings('default_comment_status')
547 : $content_struct['mt_allow_comments'];
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
548
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
549 $ping_status = (empty($content_struct['mt_allow_pings'])) ?
550 get_settings('default_ping_status')
551 : $content_struct['mt_allow_pings'];
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
552
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
553 if ($post_more) {
554 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
555 }
de05283f » ryan
2005-06-19 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
556
557 $to_ping = $content_struct['mt_tb_ping_urls'];
558
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
559 // Do some timestamp voodoo
560 $dateCreatedd = $content_struct['dateCreated'];
93674897 » michelvaldrighi
2004-09-22 dateCreated typos
561 if (!empty($dateCreatedd)) {
06d02709 » michelvaldrighi
2004-09-18 I was stupidly parsing dateCreated even when it was empty -- hence th…
562 $dateCreated = $dateCreatedd->getIso();
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
563 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
564 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
565 } else {
566 $post_date = current_time('mysql');
567 $post_date_gmt = current_time('mysql', 1);
568 }
569
570 $catnames = $content_struct['categories'];
83e6c81f » rboren
2004-12-08 s/logio/logIO/. Remove logio calls from the one function in functions…
571 logIO('O', 'Post cats: ' . printr($catnames,true));
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
572 $post_category = array();
573
6ff95582 » ryan
2005-03-02 Make sure category list is actually a list. http://mosquito.wordpress…
574 if (is_array($catnames)) {
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
575 foreach ($catnames as $cat) {
576 $post_category[] = get_cat_ID($cat);
577 }
54766ead » ryan
2005-07-03 XMLRPC category fixes
578 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
579
580 // We've got all the data -- post it:
de05283f » ryan
2005-06-19 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
581 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping');
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
582
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
583 $post_ID = wp_insert_post($postdata);
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
584
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
585 if (!$post_ID) {
586 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.');
587 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
588
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
589 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
590
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
591 return strval($post_ID);
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
592 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
593
594
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
595 /* metaweblog.editPost ...edits a post */
596 function mw_editPost($args) {
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
597
d1ea1c93 » ryan
2005-06-18 Use instead of hardcoding 1. Do we really need a separate default cat…
598 global $wpdb, $post_default_category;
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
599
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
600 $this->escape($args);
601
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
602 $post_ID = $args[0];
603 $user_login = $args[1];
604 $user_pass = $args[2];
605 $content_struct = $args[3];
606 $publish = $args[4];
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
607
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
608 if (!$this->login_pass_ok($user_login, $user_pass)) {
609 return $this->error;
610 }
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
611
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
612 set_current_user(0, $user_login);
613 if ( !current_user_can('edit_post', $post_ID) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
614 return new IXR_Error(401, 'Sorry, you can not edit this post.');
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
615
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
616 $postdata = wp_get_single_post($post_ID, ARRAY_A);
617 extract($postdata);
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
618 $this->escape($postdata);
13004042 » michelvaldrighi
2004-08-25 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
619
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
620 $post_title = $content_struct['title'];
99df7e3a » saxmatt
2005-01-06 Cleaning up filters and format-to-post
621 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
622 $catnames = $content_struct['categories'];
bdfab81f » ryan
2005-06-30 Default category and pingback check fixes.
623
624 $post_category = array();
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
625
6ff95582 » ryan
2005-03-02 Make sure category list is actually a list. http://mosquito.wordpress…
626 if (is_array($catnames)) {
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
627 foreach ($catnames as $cat) {
628 $post_category[] = get_cat_ID($cat);
629 }
54766ead » ryan
2005-07-03 XMLRPC category fixes
630 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
631
632 $post_excerpt = $content_struct['mt_excerpt'];
633 $post_more = $content_struct['mt_text_more'];
634 $post_status = $publish ? 'publish' : 'draft';
635
636 if ($post_more) {
637 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
638 }
639
de05283f » ryan
2005-06-19 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
640 $to_ping = $content_struct['mt_tb_ping_urls'];
641
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
642 $comment_status = (empty($content_struct['mt_allow_comments'])) ?
643 get_settings('default_comment_status')
644 : $content_struct['mt_allow_comments'];
645
646 $ping_status = (empty($content_struct['mt_allow_pings'])) ?
647 get_settings('default_ping_status')
648 : $content_struct['mt_allow_pings'];
649
650 // Do some timestamp voodoo
93674897 » michelvaldrighi
2004-09-22 dateCreated typos
651 $dateCreatedd = $content_struct['dateCreated'];
652 if (!empty($dateCreatedd)) {
06d02709 » michelvaldrighi
2004-09-18 I was stupidly parsing dateCreated even when it was empty -- hence th…
653 $dateCreated = $dateCreatedd->getIso();
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
654 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
655 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
656 } else {
657 $post_date = $postdata['post_date'];
658 $post_date_gmt = $postdata['post_date_gmt'];
659 }
660
661 // We've got all the data -- post it:
de05283f » ryan
2005-06-19 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
662 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
663
de05283f » ryan
2005-06-19 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
664 $result = wp_update_post($newpost);
665 if (!$result) {
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
666 return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.');
667 }
668
669 logIO('O',"(MW) Edited ! ID: $post_ID");
670
671 return true;
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
672 }
673
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
674
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
675 /* metaweblog.getPost ...returns a post */
676 function mw_getPost($args) {
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
677
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
678 global $wpdb;
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
679
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
680 $this->escape($args);
681
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
682 $post_ID = $args[0];
683 $user_login = $args[1];
684 $user_pass = $args[2];
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
685
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
686 if (!$this->login_pass_ok($user_login, $user_pass)) {
687 return $this->error;
688 }
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
689
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
690 $postdata = wp_get_single_post($post_ID, ARRAY_A);
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
691
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
692 if ($postdata['post_date'] != '') {
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
693
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
694 $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
695
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
696 $categories = array();
697 $catids = wp_get_post_cats('', $post_ID);
698 foreach($catids as $catid) {
699 $categories[] = get_cat_name($catid);
700 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
701
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
702 $post = get_extended($postdata['post_content']);
703 $link = post_permalink($postdata['ID']);
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
704
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
705 $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
706 $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
707
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
708 $resp = array(
709 'dateCreated' => new IXR_Date($post_date),
710 'userid' => $postdata['post_author'],
711 'postid' => $postdata['ID'],
712 'description' => $post['main'],
713 'title' => $postdata['post_title'],
714 'link' => $link,
715 'permaLink' => $link,
716 // commented out because no other tool seems to use this
717 // 'content' => $entry['post_content'],
718 'categories' => $categories,
719 'mt_excerpt' => $postdata['post_excerpt'],
720 'mt_text_more' => $post['extended'],
721 'mt_allow_comments' => $allow_comments,
722 'mt_allow_pings' => $allow_pings
723 );
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
724
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
725 return $resp;
726 } else {
727 return new IXR_Error(404, 'Sorry, no such post.');
728 }
729 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
730
731
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
732 /* metaweblog.getRecentPosts ...returns recent posts */
733 function mw_getRecentPosts($args) {
734
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
735 $this->escape($args);
736
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
737 $blog_ID = $args[0];
738 $user_login = $args[1];
739 $user_pass = $args[2];
740 $num_posts = $args[3];
741
742 if (!$this->login_pass_ok($user_login, $user_pass)) {
743 return $this->error;
744 }
745
746 $posts_list = wp_get_recent_posts($num_posts);
747
748 if (!$posts_list) {
749 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
750 return $this->error;
751 }
752
753 foreach ($posts_list as $entry) {
754
755 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
756 $categories = array();
757 $catids = wp_get_post_cats('', $entry['ID']);
758 foreach($catids as $catid) {
759 $categories[] = get_cat_name($catid);
760 }
761
762 $post = get_extended($entry['post_content']);
763 $link = post_permalink($entry['ID']);
764
765 $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
766 $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
767
768 $struct[] = array(
769 'dateCreated' => new IXR_Date($post_date),
770 'userid' => $entry['post_author'],
771 'postid' => $entry['ID'],
772 'description' => $post['main'],
773 'title' => $entry['post_title'],
774 'link' => $link,
775 'permaLink' => $link,
776 // commented out because no other tool seems to use this
777 // 'content' => $entry['post_content'],
778 'categories' => $categories,
779 'mt_excerpt' => $entry['post_excerpt'],
780 'mt_text_more' => $post['extended'],
781 'mt_allow_comments' => $allow_comments,
782 'mt_allow_pings' => $allow_pings
783 );
784
785 }
786
787 $recent_posts = array();
788 for ($j=0; $j<count($struct); $j++) {
789 array_push($recent_posts, $struct[$j]);
790 }
791
792 return $recent_posts;
793 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
794
795
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
796 /* metaweblog.getCategories ...returns the list of categories on a given weblog */
797 function mw_getCategories($args) {
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
798
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
799 global $wpdb;
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
800
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
801 $this->escape($args);
802
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
803 $blog_ID = $args[0];
804 $user_login = $args[1];
805 $user_pass = $args[2];
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
806
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
807 if (!$this->login_pass_ok($user_login, $user_pass)) {
808 return $this->error;
809 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
810
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
811 $categories_struct = array();
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
812
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
813 // FIXME: can we avoid using direct SQL there?
814 if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) {
815 foreach ($cats as $cat) {
816 $struct['categoryId'] = $cat['cat_ID'];
817 $struct['description'] = $cat['cat_name'];
818 $struct['categoryName'] = $cat['cat_name'];
0be171b0 » michelvaldrighi
2005-02-15 fix parse error
819 $struct['htmlUrl'] = wp_specialchars(get_category_link($cat['cat_ID']));
c3e1d51c » saxmatt
2004-12-12 Axing htmlspecialchars because it double-encodes-encodes. Better erro…
820 $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name']));
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
821
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
822 $categories_struct[] = $struct;
823 }
824 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
825
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
826 return $categories_struct;
b763f6ca » michelvaldrighi
2004-08-26 added mw.getRecentPosts, mw.getCategories, refactored the living shit…
827 }
828
17d6d76c » michelvaldrighi
2004-08-27 added mw.newMediaObject (not tested yet), fixed local/gmt dates confu…
829
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
830 /* metaweblog.newMediaObject uploads a file, following your settings */
831 function mw_newMediaObject($args) {
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
832 // adapted from a patch by Johann Richard
833 // http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
834
c2672406 » ryan
2005-06-30 Don't escape image bits.
835 global $wpdb;
bdfab81f » ryan
2005-06-30 Default category and pingback check fixes.
836
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
837 $blog_ID = $wpdb->escape($args[0]);
838 $user_login = $wpdb->escape($args[1]);
c2672406 » ryan
2005-06-30 Don't escape image bits.
839 $user_pass = $wpdb->escape($args[2]);
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
840 $data = $args[3];
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
841
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
842 $name = $data['name'];
843 $type = $data['type'];
844 $bits = $data['bits'];
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
845
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
846 logIO('O', '(MW) Received '.strlen($bits).' bytes');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
847
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
848 if ( !$this->login_pass_ok($user_login, $user_pass) )
849 return $this->error;
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
850
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
851 set_current_user(0, $user_login);
852 if ( !current_user_can('upload_files') ) {
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
853 logIO('O', '(MW) User does not have upload_files capability');
854 $this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
855 return $this->error;
856 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
857
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
858 $upload = wp_upload_bits($name, $type, $bits);
6d40d776 » ryan
2005-12-29 More wp_upload_bits() fixes.
859 if ( ! empty($upload['error']) ) {
30a8b614 » ryan
2005-12-01 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
860 logIO('O', '(MW) Could not write file '.$name);
861 return new IXR_Error(500, 'Could not write file '.$name);
862 }
863
864 return array('url' => $upload['url']);
17d6d76c » michelvaldrighi
2004-08-27 added mw.newMediaObject (not tested yet), fixed local/gmt dates confu…
865 }
866
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
867
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
868 /* MovableType API functions
869 * specs on http://www.movabletype.org/docs/mtmanual_programmatic.html
870 */
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
871
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
872 /* mt.getRecentPostTitles ...returns recent posts' titles */
873 function mt_getRecentPostTitles($args) {
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
874
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
875 $this->escape($args);
876
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
877 $blog_ID = $args[0];
878 $user_login = $args[1];
879 $user_pass = $args[2];
880 $num_posts = $args[3];
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
881
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
882 if (!$this->login_pass_ok($user_login, $user_pass)) {
883 return $this->error;
884 }
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
885
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
886 $posts_list = wp_get_recent_posts($num_posts);
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
887
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
888 if (!$posts_list) {
889 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
890 return $this->error;
891 }
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
892
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
893 foreach ($posts_list as $entry) {
894
895 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
896
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
897 $struct[] = array(
898 'dateCreated' => new IXR_Date($post_date),
899 'userid' => $entry['post_author'],
900 'postid' => $entry['ID'],
901 'title' => $entry['post_title'],
902 );
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
903
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
904 }
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
905
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
906 $recent_posts = array();
907 for ($j=0; $j<count($struct); $j++) {
908 array_push($recent_posts, $struct[$j]);
909 }
910
911 return $recent_posts;
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
912 }
913
914
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
915 /* mt.getCategoryList ...returns the list of categories on a given weblog */
916 function mt_getCategoryList($args) {
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
917
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
918 global $wpdb;
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
919
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
920 $this->escape($args);
921
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
922 $blog_ID = $args[0];
923 $user_login = $args[1];
924 $user_pass = $args[2];
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
925
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
926 if (!$this->login_pass_ok($user_login, $user_pass)) {
927 return $this->error;
928 }
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
929
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
930 $categories_struct = array();
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
931
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
932 // FIXME: can we avoid using direct SQL there?
933 if ($cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_A)) {
934 foreach ($cats as $cat) {
935 $struct['categoryId'] = $cat['cat_ID'];
936 $struct['categoryName'] = $cat['cat_name'];
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
937
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
938 $categories_struct[] = $struct;
939 }
940 }
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
941
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
942 return $categories_struct;
89e04090 » michelvaldrighi
2004-09-14 various fixes, and started MT API support
943 }
944
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
945
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
946 /* mt.getPostCategories ...returns a post's categories */
947 function mt_getPostCategories($args) {
948
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
949 $this->escape($args);
950
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
951 $post_ID = $args[0];
952 $user_login = $args[1];
953 $user_pass = $args[2];
954
955 if (!$this->login_pass_ok($user_login, $user_pass)) {
956 return $this->error;
957 }
958
959 $categories = array();
960 $catids = wp_get_post_cats('', intval($post_ID));
961 // first listed category will be the primary category
962 $isPrimary = true;
963 foreach($catids as $catid) {
964 $categories[] = array(
965 'categoryName' => get_cat_name($catid),
966 'categoryId' => $catid,
967 'isPrimary' => $isPrimary
968 );
969 $isPrimary = false;
970 }
971
972 return $categories;
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
973 }
974
975
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
976 /* mt.setPostCategories ...sets a post's categories */
977 function mt_setPostCategories($args) {
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
978
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
979 $this->escape($args);
980
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
981 $post_ID = $args[0];
982 $user_login = $args[1];
983 $user_pass = $args[2];
984 $categories = $args[3];
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
985
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
986 if (!$this->login_pass_ok($user_login, $user_pass)) {
987 return $this->error;
988 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
989
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
990 set_current_user(0, $user_login);
991 if ( !current_user_can('edit_post', $post_ID) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
992 return new IXR_Error(401, 'Sorry, you can not edit this post.');
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
993
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
994 foreach($categories as $cat) {
995 $catids[] = $cat['categoryId'];
996 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
997
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
998 wp_set_post_cats('', $post_ID, $catids);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
999
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1000 return true;
1001 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1002
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1003
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1004 /* mt.supportedMethods ...returns an array of methods supported by this server */
1005 function mt_supportedMethods($args) {
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1006
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1007 $supported_methods = array();
1008 foreach($this->methods as $key=>$value) {
1009 $supported_methods[] = $key;
1010 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1011
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1012 return $supported_methods;
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1013 }
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1014
1015
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1016 /* mt.supportedTextFilters ...returns an empty array because we don't
1017 support per-post text filters yet */
1018 function mt_supportedTextFilters($args) {
1019 return array();
1020 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1021
1022
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1023 /* mt.getTrackbackPings ...returns trackbacks sent to a given post */
1024 function mt_getTrackbackPings($args) {
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1025
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1026 global $wpdb;
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1027
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1028 $post_ID = intval($args);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1029
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1030 $actual_post = wp_get_single_post($post_ID, ARRAY_A);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1031
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1032 if (!$actual_post) {
1033 return new IXR_Error(404, 'Sorry, no such post.');
1034 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1035
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1036 $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID");
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1037
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1038 if (!$comments) {
1039 return array();
1040 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1041
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1042 $trackback_pings = array();
1043 foreach($comments as $comment) {
6584b204 » saxmatt
2005-01-06 Some cleanup patches from Scott: http://www.coffee2code.com/archives/…
1044 if ( 'trackback' == $comment->comment_type ) {
1045 $content = $comment->comment_content;
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1046 $title = substr($content, 8, (strpos($content, '</strong>') - 8));
1047 $trackback_pings[] = array(
1048 'pingTitle' => $title,
1049 'pingURL' => $comment->comment_author_url,
1050 'pingIP' => $comment->comment_author_IP
1051 );
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1052 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1053 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1054
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1055 return $trackback_pings;
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1056 }
1057
1058
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1059 /* mt.publishPost ...sets a post's publish status to 'publish' */
1060 function mt_publishPost($args) {
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1061
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
1062 $this->escape($args);
1063
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1064 $post_ID = $args[0];
1065 $user_login = $args[1];
1066 $user_pass = $args[2];
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1067
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1068 if (!$this->login_pass_ok($user_login, $user_pass)) {
1069 return $this->error;
1070 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1071
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
1072 set_current_user(0, $user_login);
1073 if ( !current_user_can('edit_post', $post_ID) )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1074 return new IXR_Error(401, 'Sorry, you can not edit this post.');
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1075
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1076 $postdata = wp_get_single_post($post_ID,ARRAY_A);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1077
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1078 $postdata['post_status'] = 'publish';
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1079
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1080 // retain old cats
1081 $cats = wp_get_post_cats('',$post_ID);
1082 $postdata['post_category'] = $cats;
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
1083 $this->escape($postdata);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1084
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1085 $result = wp_update_post($postdata);
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1086
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1087 return $result;
1088 }
83d97232 » michelvaldrighi
2004-09-16 now with complete MT API support -- TEST TEST TEST THIS (here it work…
1089
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1090
1091
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1092 /* PingBack functions
1093 * specs on www.hixie.ch/specs/pingback/pingback
1094 */
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1095
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1096 /* pingback.ping gets a pingback and registers it */
1097 function pingback_ping($args) {
1098 global $wpdb, $wp_version;
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1099
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
1100 $this->escape($args);
1101
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1102 $pagelinkedfrom = $args[0];
1103 $pagelinkedto = $args[1];
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1104
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1105 $title = '';
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1106
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1107 $pagelinkedfrom = str_replace('&amp;', '&', $pagelinkedfrom);
1108 $pagelinkedto = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedto);
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1109
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1110 $error_code = -1;
7c7e0fb3 » michelvaldrighi
2004-09-17 moved wp-admin/xmlrpc.php to the root dir
1111
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1112 // Check if the page linked to is in our site
41775561 » matt
2005-11-11 Add HTTPS support, fixes #1372
1113 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_settings('home')));
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1114 if( !$pos1 )
1115 return new IXR_Error(0, 'Is there no link to us?');
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1116
1117 // let's find which post is linked to
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1118 // FIXME: does url_to_postid() cover all these cases already?
1119 // if so, then let's use it and drop the old code.
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1120 $urltest = parse_url($pagelinkedto);
1121 if ($post_ID = url_to_postid($pagelinkedto)) {
1122 $way = 'url_to_postid()';
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1123 } elseif (preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) {
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1124 // the path defines the post_ID (archives/p/XXXX)
1125 $blah = explode('/', $match[0]);
1126 $post_ID = $blah[1];
1127 $way = 'from the path';
1128 } elseif (preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) {
1129 // the querystring defines the post_ID (?p=XXXX)
1130 $blah = explode('=', $match[0]);
1131 $post_ID = $blah[1];
1132 $way = 'from the querystring';
1133 } elseif (isset($urltest['fragment'])) {
1134 // an #anchor is there, it's either...
1135 if (intval($urltest['fragment'])) {
1136 // ...an integer #XXXX (simpliest case)
1137 $post_ID = $urltest['fragment'];
1138 $way = 'from the fragment (numeric)';
1139 } elseif (preg_match('/post-[0-9]+/',$urltest['fragment'])) {
1140 // ...a post id in the form 'post-###'
1141 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
1142 $way = 'from the fragment (post-###)';
1143 } elseif (is_string($urltest['fragment'])) {
1144 // ...or a string #title, a little more complicated
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1145 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1146 $sql = "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE '$title'";
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1147 if (! ($post_ID = $wpdb->get_var($sql)) ) {
1148 // returning unknown error '0' is better than die()ing
1149 return new IXR_Error(0, '');
1150 }
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1151 $way = 'from the fragment (title)';
1152 }
1153 } else {
1154 // TODO: Attempt to extract a post ID from the given URL
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1155 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1156 }
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1157 $post_ID = (int) $post_ID;
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1158
1159
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1160 logIO("O","(PB) URI='$pagelinkedto' ID='$post_ID' Found='$way'");
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1161
bdfab81f » ryan
2005-06-30 Default category and pingback check fixes.
1162 $post = get_post($post_ID);
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1163
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1164 if ( !$post ) // Post_ID not found
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1165 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
1166
e445ffe7 » ryan
2005-11-05 Don't self ping. Props Mark Jaquith fixes #993
1167 if ( $post_ID == url_to_postid($pagelinkedfrom) )
1168 return new IXR_Error(0, 'The source URI and the target URI cannot both point to the same resource.');
1169
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1170 // Check if pings are on
1171 if ( 'closed' == $post->ping_status )
1172 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1173
1174 // Let's check that the remote site didn't already pingback this entry
06bacff6 » saxmatt
2004-12-12 Check for dupe trackbacks as well.
1175 $result = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_ID' AND comment_author_url = '$pagelinkedfrom'");
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1176
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1177 if ( $wpdb->num_rows ) // We already have a Pingback from this URL
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1178 return new IXR_Error(48, 'The pingback has already been registered.');
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1179
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1180 // very stupid, but gives time to the 'from' server to publish !
1181 sleep(1);
093993d9 » michelvaldrighi
2004-09-16 added pingback (now with accurate fault codes and more easily readabl…
1182
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1183 // Let's check the remote site
95883b92 » matt
2005-05-03 Use CURL if available, possible fix for http://mosquito.wordpress.org…
1184 $linea = wp_remote_fopen( $pagelinkedfrom );
1185 if ( !$linea )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1186 return new IXR_Error(16, 'The source URI does not exist.');
fcb0c547 » michelvaldrighi
2004-09-16 added pingback.extensions.getPingbacks
1187
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1188 // Work around bug in strip_tags():
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1189 $linea = str_replace('<!DOC', '<DOC', $linea);
1190 $linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces
1191 $linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea );
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1192
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1193 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
1194 $title = $matchtitle[1];
1195 if ( empty( $title ) )
1196 return new IXR_Error(32, 'We cannot find a title on that page.');
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1197
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1198 $linea = strip_tags( $linea, '<a>' ); // just keep the tag we need
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1199
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1200 $p = explode( "\n\n", $linea );
1201
1202 $sem_regexp_pb = "/(\\/|\\\|\*|\?|\+|\.|\^|\\$|\(|\)|\[|\]|\||\{|\})/";
1203 $sem_regexp_fix = "\\\\$1";
1204 $link = preg_replace( $sem_regexp_pb, $sem_regexp_fix, $pagelinkedfrom );
1205
1206 $finished = false;
1207 foreach ( $p as $para ) {
1208 if ( $finished )
1209 continue;
1210 if ( strstr( $para, $pagelinkedto ) ) {
1211 $context = preg_replace( "/.*<a[^>]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para );
1212 $excerpt = strip_tags( $para );
1213 $excerpt = trim( $excerpt );
1214 $use = preg_quote( $context );
1215 $excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt);
1216 $finished = true;
1217 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1218 }
1219
0e15d15f » matt
2005-08-03 Fixes #1541
1220 if ( empty($context) ) // URL pattern not found
1221 return new IXR_Error(17, 'The source URI does not contain a link to the target URI, and so cannot be used as a source.');
1222
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1223 $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedfrom);
c65f0168 » matt
2005-06-04 Better pingback extraction, fixes #1268
1224
1225 $context = '[...] ' . wp_specialchars( $excerpt ) . ' [...]';
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1226 $original_pagelinkedfrom = $pagelinkedfrom;
91efba11 » ryan
2005-07-05 Use wpdb->escape instead of addslashes to prepare DB bound data.
1227 $pagelinkedfrom = $wpdb->escape( $pagelinkedfrom );
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1228 $original_title = $title;
1229
75caf097 » michelvaldrighi
2004-09-22 make pingback.ping use wp_new_comment
1230 $comment_post_ID = $post_ID;
1231 $comment_author = $title;
1232 $comment_author_url = $pagelinkedfrom;
1233 $comment_content = $context;
1234 $comment_type = 'pingback';
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1235
75caf097 » michelvaldrighi
2004-09-22 make pingback.ping use wp_new_comment
1236 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_content', 'comment_type');
1237
171c6175 » michelvaldrighi
2004-09-27 ok, I can't believe I forgot to add that in
1238 wp_new_comment($commentdata);
65bbec71 » saxmatt
2004-12-16 Comments refactoring and cleanup
1239 do_action('pingback_post', $wpdb->insert_id);
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1240
1241 return "Pingback from $pagelinkedfrom to $pagelinkedto registered. Keep the web talking! :-)";
1242 }
1243
1244
1245 /* pingback.extensions.getPingbacks returns an array of URLs
1246 that pingbacked the given URL
1247 specs on http://www.aquarionics.com/misc/archives/blogite/0198.html */
1248 function pingback_extensions_getPingbacks($args) {
1249
1250 global $wpdb;
1251
9c9ba0ae » ryan
2005-06-28 Escape XMLRPC args.
1252 $this->escape($args);
1253
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1254 $url = $args;
1255
1256 $post_ID = url_to_postid($url);
1257 if (!$post_ID) {
1258 // We aren't sure that the resource is available and/or pingback enabled
1259 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
1260 }
1261
1262 $actual_post = wp_get_single_post($post_ID, ARRAY_A);
1263
1264 if (!$actual_post) {
1265 // No such post = resource not found
1266 return new IXR_Error(32, 'The specified target URI does not exist.');
1267 }
1268
1269 $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID");
1270
1271 if (!$comments) {
1272 return array();
1273 }
1274
1275 $pingbacks = array();
1276 foreach($comments as $comment) {
6584b204 » saxmatt
2005-01-06 Some cleanup patches from Scott: http://www.coffee2code.com/archives/…
1277 if ( 'pingback' == $comment->comment_type )
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1278 $pingbacks[] = $comment->comment_author_url;
fcb0c547 » michelvaldrighi
2004-09-16 added pingback.extensions.getPingbacks
1279 }
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1280
1281 return $pingbacks;
fcb0c547 » michelvaldrighi
2004-09-16 added pingback.extensions.getPingbacks
1282 }
1387744b » michelvaldrighi
2004-05-23 added blogger.newPost
1283 }
e61a7ce5 » michelvaldrighi
2004-05-23 work in progress: replacement for xmlrpc.php, using IXR
1284
a7322e87 » michelvaldrighi
2004-09-17 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
1285
1286 $wp_xmlrpc_server = new wp_xmlrpc_server();
1287
cb093369 » ryan
2006-01-13 Make the xmlrpc user the current user. fixes #2273
1288 ?>
Something went wrong with that request. Please try again.