Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 1280 lines (935 sloc) 37.391 kB
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1 <?php
2
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
3 define('XMLRPC_REQUEST', true);
4
5 // Some browser-embedded clients send cookies. We don't want them.
6 $_COOKIE = array();
7
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
8 # fix for mozBlog and other cases where '<?xml' isn't on the very first line
60ccea9 Check if HTTP_RAW_POST_DATA is set to avoid undefined var warning. P…
ryan authored
9 if ( isset($HTTP_RAW_POST_DATA) )
10 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
11
4fe6495 whoops, a dot that was removed yesterday came back when restoring the…
michelvaldrighi authored
12 include('./wp-config.php');
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
13
14 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
15 header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
16
17 ?>
18 <?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?>
19 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
20 <service>
21 <engineName>WordPress</engineName>
22 <engineLink>http://wordpress.org/</engineLink>
23 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
24 <apis>
25 <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
26 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
27 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
28 </apis>
29 </service>
30 </rsd>
31 <?php
32 exit;
33 }
34
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
35 include_once(ABSPATH . WPINC . '/class-IXR.php');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
36
37 // Turn off all warnings and errors.
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
38 // error_reporting(0);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
39
40 $post_default_title = ""; // posts submitted via the xmlrpc interface get that title
41
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big tim…
michelvaldrighi authored
42 $xmlrpc_logging = 0;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
43
44 function logIO($io,$msg) {
45 global $xmlrpc_logging;
46 if ($xmlrpc_logging) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
47 $fp = fopen("../xmlrpc.log","a+");
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
48 $date = gmdate("Y-m-d H:i:s ");
49 $iot = ($io == "I") ? " Input: " : " Output: ";
50 fwrite($fp, "\n\n".$date.$iot.$msg);
51 fclose($fp);
52 }
53 return true;
54 }
55
56 function starify($string) {
57 $i = strlen($string);
58 return str_repeat('*', $i);
59 }
60
85cb306 avoid $HTTP_RAW_POST_DATA notices. props mgeisler and Nazgul. fixes …
markjaquith authored
61 if ( isset($HTTP_RAW_POST_DATA) )
62 logIO("I", $HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
63
9611463 added Emmanuel Frecon's fix to create directories in mw.newMediaObjec…
michelvaldrighi authored
64
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
65 class wp_xmlrpc_server extends IXR_Server {
66
67 function wp_xmlrpc_server() {
68 $this->methods = array(
69 // Blogger API
70 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
71 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
72 'blogger.getPost' => 'this:blogger_getPost',
73 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
74 'blogger.getTemplate' => 'this:blogger_getTemplate',
75 'blogger.setTemplate' => 'this:blogger_setTemplate',
76 'blogger.newPost' => 'this:blogger_newPost',
77 'blogger.editPost' => 'this:blogger_editPost',
78 'blogger.deletePost' => 'this:blogger_deletePost',
79
80 // MetaWeblog API (with MT extensions to structs)
81 'metaWeblog.newPost' => 'this:mw_newPost',
82 'metaWeblog.editPost' => 'this:mw_editPost',
83 'metaWeblog.getPost' => 'this:mw_getPost',
84 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
85 'metaWeblog.getCategories' => 'this:mw_getCategories',
86 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
87
88 // MetaWeblog API aliases for Blogger API
89 // see http://www.xmlrpc.com/stories/storyReader$2460
90 'metaWeblog.deletePost' => 'this:blogger_deletePost',
91 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
92 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
93 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
94
95 // MovableType API
96 'mt.getCategoryList' => 'this:mt_getCategoryList',
97 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
98 'mt.getPostCategories' => 'this:mt_getPostCategories',
99 'mt.setPostCategories' => 'this:mt_setPostCategories',
100 'mt.supportedMethods' => 'this:mt_supportedMethods',
101 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
102 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
103 'mt.publishPost' => 'this:mt_publishPost',
104
105 // PingBack
106 'pingback.ping' => 'this:pingback_ping',
107 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
108
109 'demo.sayHello' => 'this:sayHello',
110 'demo.addTwoNumbers' => 'this:addTwoNumbers'
111 );
087df40 Allow plugins to hook into XML-RPC server.
saxmatt authored
112 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
113 $this->IXR_Server($this->methods);
114 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
115
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
116 function sayHello($args) {
117 return 'Hello!';
118 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
119
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
120 function addTwoNumbers($args) {
121 $number1 = $args[0];
122 $number2 = $args[1];
123 return $number1 + $number2;
124 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
125
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
126 function login_pass_ok($user_login, $user_pass) {
127 if (!user_pass_ok($user_login, $user_pass)) {
128 $this->error = new IXR_Error(403, 'Bad login/pass combination.');
129 return false;
130 }
131 return true;
132 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
133
9c9ba0a Escape XMLRPC args.
ryan authored
134 function escape(&$array) {
135 global $wpdb;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
136
fde479b Cast to array in xmlrpc.php. fixes #3266
markjaquith authored
137 foreach ( (array) $array as $k => $v ) {
9c9ba0a Escape XMLRPC args.
ryan authored
138 if (is_array($v)) {
139 $this->escape($array[$k]);
3882320 Don't escape objects.
ryan authored
140 } else if (is_object($v)) {
141 //skip
9c9ba0a Escape XMLRPC args.
ryan authored
142 } else {
143 $array[$k] = $wpdb->escape($v);
144 }
145 }
146 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
147
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
148 /* Blogger API functions
149 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
150 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
151
152
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
153 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
154 function blogger_getUsersBlogs($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
155
9c9ba0a Escape XMLRPC args.
ryan authored
156 $this->escape($args);
157
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
158 $user_login = $args[1];
159 $user_pass = $args[2];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
160
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
161 if (!$this->login_pass_ok($user_login, $user_pass)) {
162 return $this->error;
163 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
164
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
165 set_current_user(0, $user_login);
166 $is_admin = current_user_can('level_8');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
167
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
168 $struct = array(
169 'isAdmin' => $is_admin,
637cfdc Cleaning up blogfilename.
saxmatt authored
170 'url' => get_settings('home') . '/',
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
171 'blogid' => '1',
172 'blogName' => get_settings('blogname')
173 );
e762c60 Remove debug cruft. fixes #2273
ryan authored
174
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
175 return array($struct);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
176 }
177
178
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
179 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
180 function blogger_getUserInfo($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
181
9c9ba0a Escape XMLRPC args.
ryan authored
182 $this->escape($args);
183
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
184 $user_login = $args[1];
185 $user_pass = $args[2];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
186
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
187 if (!$this->login_pass_ok($user_login, $user_pass)) {
188 return $this->error;
189 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
190
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
191 $user_data = get_userdatabylogin($user_login);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
192
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
193 $struct = array(
1f9a608 User data migration should be complete
matt authored
194 'nickname' => $user_data->nickname,
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
195 'userid' => $user_data->ID,
196 'url' => $user_data->user_url,
197 'email' => $user_data->user_email,
1f9a608 User data migration should be complete
matt authored
198 'lastname' => $user_data->last_name,
199 'firstname' => $user_data->first_name
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
200 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
201
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
202 return $struct;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
203 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
204
205
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
206 /* blogger.getPost ...gets a post */
207 function blogger_getPost($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
208
9c9ba0a Escape XMLRPC args.
ryan authored
209 $this->escape($args);
210
a359d59 Some int casts
ryan authored
211 $post_ID = (int) $args[1];
212 $user_login = $args[2];
213 $user_pass = $args[3];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
214
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
215 if (!$this->login_pass_ok($user_login, $user_pass)) {
216 return $this->error;
217 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
218
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
219 $user_data = get_userdatabylogin($user_login);
220 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
221
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
222 $categories = implode(',', wp_get_post_cats(1, $post_ID));
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
223
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
224 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
225 $content .= '<category>'.$categories.'</category>';
226 $content .= stripslashes($post_data['post_content']);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
227
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
228 $struct = array(
229 'userid' => $post_data['post_author'],
230 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
231 'content' => $content,
232 'postid' => $post_data['ID']
233 );
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
234
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
235 return $struct;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
236 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
237
238
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
239 /* blogger.getRecentPosts ...gets recent posts */
240 function blogger_getRecentPosts($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
241
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
242 global $wpdb;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
243
9c9ba0a Escape XMLRPC args.
ryan authored
244 $this->escape($args);
245
a359d59 Some int casts
ryan authored
246 $blog_ID = (int) $args[1]; /* though we don't use it yet */
247 $user_login = $args[2];
248 $user_pass = $args[3];
249 $num_posts = $args[4];
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
250
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
251 if (!$this->login_pass_ok($user_login, $user_pass)) {
252 return $this->error;
253 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
254
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
255 $posts_list = wp_get_recent_posts($num_posts);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
256
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
257 if (!$posts_list) {
258 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
259 return $this->error;
260 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
261
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
262 foreach ($posts_list as $entry) {
263
264 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
265 $categories = implode(',', wp_get_post_cats(1, $entry['ID']));
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
266
8767434 Fix typo. Bug 540. Patch from Froosh.
rboren authored
267 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
268 $content .= '<category>'.$categories.'</category>';
269 $content .= stripslashes($entry['post_content']);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
270
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
271 $struct[] = array(
272 'userid' => $entry['post_author'],
273 'dateCreated' => new IXR_Date($post_date),
274 'content' => $content,
275 'postid' => $entry['ID'],
276 );
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
277
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
278 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
279
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
280 $recent_posts = array();
281 for ($j=0; $j<count($struct); $j++) {
282 array_push($recent_posts, $struct[$j]);
283 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
284
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
285 return $recent_posts;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
286 }
287
288
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
289 /* blogger.getTemplate returns your blog_filename */
290 function blogger_getTemplate($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
291
9c9ba0a Escape XMLRPC args.
ryan authored
292 $this->escape($args);
293
a359d59 Some int casts
ryan authored
294 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
295 $user_login = $args[2];
296 $user_pass = $args[3];
297 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
298
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
299 if (!$this->login_pass_ok($user_login, $user_pass)) {
300 return $this->error;
301 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
302
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
303 set_current_user(0, $user_login);
304 if ( !current_user_can('edit_themes') ) {
2f6ae33 Cap migration.
ryan authored
305 return new IXR_Error(401, 'Sorry, this user can not edit the template.');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
306 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
307
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
308 /* warning: here we make the assumption that the weblog's URI is on the same server */
637cfdc Cleaning up blogfilename.
saxmatt authored
309 $filename = get_settings('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
310 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
311
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
312 $f = fopen($filename, 'r');
313 $content = fread($f, filesize($filename));
314 fclose($f);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
315
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
316 /* so it is actually editable with a windows/mac client */
317 // 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);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
318
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
319 return $content;
320 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
321
322
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
323 /* blogger.setTemplate updates the content of blog_filename */
324 function blogger_setTemplate($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
325
9c9ba0a Escape XMLRPC args.
ryan authored
326 $this->escape($args);
327
a359d59 Some int casts
ryan authored
328 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
329 $user_login = $args[2];
330 $user_pass = $args[3];
331 $content = $args[4];
332 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
333
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
334 if (!$this->login_pass_ok($user_login, $user_pass)) {
335 return $this->error;
336 }
1387744 added blogger.newPost
michelvaldrighi authored
337
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
338 set_current_user(0, $user_login);
339 if ( !current_user_can('edit_themes') ) {
2f6ae33 Cap migration.
ryan authored
340 return new IXR_Error(401, 'Sorry, this user can not edit the template.');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
341 }
1387744 added blogger.newPost
michelvaldrighi authored
342
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
343 /* warning: here we make the assumption that the weblog's URI is on the same server */
637cfdc Cleaning up blogfilename.
saxmatt authored
344 $filename = get_settings('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
345 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1387744 added blogger.newPost
michelvaldrighi authored
346
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
347 if ($f = fopen($filename, 'w+')) {
348 fwrite($f, $content);
349 fclose($f);
350 } else {
351 return new IXR_Error(500, 'Either the file is not writable, or something wrong happened. The file has not been updated.');
352 }
1387744 added blogger.newPost
michelvaldrighi authored
353
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
354 return true;
355 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
356
357
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
358 /* blogger.newPost ...creates a new post */
359 function blogger_newPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
360
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
361 global $wpdb;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
362
9c9ba0a Escape XMLRPC args.
ryan authored
363 $this->escape($args);
364
a359d59 Some int casts
ryan authored
365 $blog_ID = (int) $args[1]; /* though we don't use it yet */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
366 $user_login = $args[2];
367 $user_pass = $args[3];
368 $content = $args[4];
369 $publish = $args[5];
1387744 added blogger.newPost
michelvaldrighi authored
370
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
371 if (!$this->login_pass_ok($user_login, $user_pass)) {
372 return $this->error;
373 }
c2fd7b8 Capability updates for xmlrpc.
ryan authored
374
375 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
376 $user = set_current_user(0, $user_login);
377 if ( !current_user_can($cap) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
378 return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.');
1387744 added blogger.newPost
michelvaldrighi authored
379
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
380 $post_status = ($publish) ? 'publish' : 'draft';
1387744 added blogger.newPost
michelvaldrighi authored
381
c2fd7b8 Capability updates for xmlrpc.
ryan authored
382 $post_author = $user->ID;
1387744 added blogger.newPost
michelvaldrighi authored
383
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
384 $post_title = xmlrpc_getposttitle($content);
385 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
386 $post_content = xmlrpc_removepostdata($content);
1387744 added blogger.newPost
michelvaldrighi authored
387
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
388 $post_date = current_time('mysql');
389 $post_date_gmt = current_time('mysql', 1);
1387744 added blogger.newPost
michelvaldrighi authored
390
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
391 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
1387744 added blogger.newPost
michelvaldrighi authored
392
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
393 $post_ID = wp_insert_post($post_data);
1387744 added blogger.newPost
michelvaldrighi authored
394
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
395 if (!$post_ID) {
396 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.');
397 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
398
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
399 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
400
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
401 return $post_ID;
1387744 added blogger.newPost
michelvaldrighi authored
402 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
403
404
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
405 /* blogger.editPost ...edits a post */
406 function blogger_editPost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
407
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
408 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
409
9c9ba0a Escape XMLRPC args.
ryan authored
410 $this->escape($args);
411
efd3bae Cast to int.
ryan authored
412 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
413 $user_login = $args[2];
414 $user_pass = $args[3];
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
415 $content = $args[4];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
416 $publish = $args[5];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
417
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
418 if (!$this->login_pass_ok($user_login, $user_pass)) {
419 return $this->error;
420 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
421
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
422 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
423
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
424 if (!$actual_post) {
425 return new IXR_Error(404, 'Sorry, no such post.');
426 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
427
9c9ba0a Escape XMLRPC args.
ryan authored
428 $this->escape($actual_post);
429
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
430 set_current_user(0, $user_login);
431 if ( !current_user_can('edit_post', $post_ID) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
432 return new IXR_Error(401, 'Sorry, you do not have the right to edit this post.');
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
433
d446bf0 escape before extracting. Props Alexander Concha.
markjaquith authored
434 extract($actual_post, EXTR_SKIP);
9c9ba0a Escape XMLRPC args.
ryan authored
435
b5ae536 Check for publish caps when editing via xmlrpc. For 2.0
ryan authored
436 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
437 return new IXR_Error(401, 'Sorry, you do not have the right to publish this post.');
438
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
439 $post_title = xmlrpc_getposttitle($content);
440 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
441 $post_content = xmlrpc_removepostdata($content);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
442
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
443 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
444
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
445 $result = wp_update_post($postdata);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
446
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
447 if (!$result) {
448 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.');
449 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
450
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
451 return true;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
452 }
453
454
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
455 /* blogger.deletePost ...deletes a post */
456 function blogger_deletePost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
457
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
458 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
459
9c9ba0a Escape XMLRPC args.
ryan authored
460 $this->escape($args);
461
a359d59 Some int casts
ryan authored
462 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
463 $user_login = $args[2];
464 $user_pass = $args[3];
465 $publish = $args[4];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
466
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
467 if (!$this->login_pass_ok($user_login, $user_pass)) {
468 return $this->error;
469 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
470
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
471 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
472
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
473 if (!$actual_post) {
474 return new IXR_Error(404, 'Sorry, no such post.');
475 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
476
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
477 set_current_user(0, $user_login);
478 if ( !current_user_can('edit_post', $post_ID) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
479 return new IXR_Error(401, 'Sorry, you do not have the right to delete this post.');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
480
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
481 $result = wp_delete_post($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
482
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
483 if (!$result) {
484 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be deleted.');
485 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
486
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
487 return true;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
488 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
489
490
491
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
492 /* MetaWeblog API functions
493 * specs on wherever Dave Winer wants them to be
494 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big tim…
michelvaldrighi authored
495
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
496 /* metaweblog.newPost creates a post */
497 function mw_newPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
498
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default c…
ryan authored
499 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
500
9c9ba0a Escape XMLRPC args.
ryan authored
501 $this->escape($args);
502
a359d59 Some int casts
ryan authored
503 $blog_ID = (int) $args[0]; // we will support this in the near future
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
504 $user_login = $args[1];
505 $user_pass = $args[2];
506 $content_struct = $args[3];
507 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
508
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
509 if (!$this->login_pass_ok($user_login, $user_pass)) {
510 return $this->error;
511 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
512
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
513 $user = set_current_user(0, $user_login);
514 if ( !current_user_can('publish_posts') )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
515 return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
516
c2fd7b8 Capability updates for xmlrpc.
ryan authored
517 $post_author = $user->ID;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
518
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
519 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
520 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
521 $post_status = $publish ? 'publish' : 'draft';
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
522
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
523 $post_excerpt = $content_struct['mt_excerpt'];
524 $post_more = $content_struct['mt_text_more'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
525
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
526 $comment_status = (empty($content_struct['mt_allow_comments'])) ?
527 get_settings('default_comment_status')
528 : $content_struct['mt_allow_comments'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
529
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
530 $ping_status = (empty($content_struct['mt_allow_pings'])) ?
531 get_settings('default_ping_status')
532 : $content_struct['mt_allow_pings'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
533
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
534 if ($post_more) {
535 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
536 }
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
537
ef81217 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
538 $to_ping = $content_struct['mt_tb_ping_urls'];
539 if ( is_array($to_ping) )
540 $to_ping = implode(' ', $to_ping);
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
541
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
542 // Do some timestamp voodoo
543 $dateCreatedd = $content_struct['dateCreated'];
9367489 dateCreated typos
michelvaldrighi authored
544 if (!empty($dateCreatedd)) {
06d0270 I was stupidly parsing dateCreated even when it was empty -- hence th…
michelvaldrighi authored
545 $dateCreated = $dateCreatedd->getIso();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
546 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
547 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
548 } else {
549 $post_date = current_time('mysql');
550 $post_date_gmt = current_time('mysql', 1);
551 }
552
553 $catnames = $content_struct['categories'];
83e6c81 s/logio/logIO/. Remove logio calls from the one function in function…
rboren authored
554 logIO('O', 'Post cats: ' . printr($catnames,true));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
555 $post_category = array();
556
6ff9558 Make sure category list is actually a list. http://mosquito.wordpres…
ryan authored
557 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
558 foreach ($catnames as $cat) {
559 $post_category[] = get_cat_ID($cat);
560 }
54766ea XMLRPC category fixes
ryan authored
561 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
562
563 // We've got all the data -- post it:
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
564 $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');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
565
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
566 $post_ID = wp_insert_post($postdata);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
567
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
568 if (!$post_ID) {
569 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.');
570 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
571
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
572 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
573
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
574 return strval($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
575 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
576
577
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
578 /* metaweblog.editPost ...edits a post */
579 function mw_editPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
580
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default c…
ryan authored
581 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
582
9c9ba0a Escape XMLRPC args.
ryan authored
583 $this->escape($args);
584
efd3bae Cast to int.
ryan authored
585 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
586 $user_login = $args[1];
587 $user_pass = $args[2];
588 $content_struct = $args[3];
589 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
590
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
591 if (!$this->login_pass_ok($user_login, $user_pass)) {
592 return $this->error;
593 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
594
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
595 set_current_user(0, $user_login);
596 if ( !current_user_can('edit_post', $post_ID) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
597 return new IXR_Error(401, 'Sorry, you can not edit this post.');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
598
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
599 $postdata = wp_get_single_post($post_ID, ARRAY_A);
9c9ba0a Escape XMLRPC args.
ryan authored
600 $this->escape($postdata);
d446bf0 escape before extracting. Props Alexander Concha.
markjaquith authored
601 extract($postdata, EXTR_SKIP);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
602
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
603 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
604 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
605 $catnames = $content_struct['categories'];
bdfab81 Default category and pingback check fixes.
ryan authored
606
607 $post_category = array();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
608
6ff9558 Make sure category list is actually a list. http://mosquito.wordpres…
ryan authored
609 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
610 foreach ($catnames as $cat) {
611 $post_category[] = get_cat_ID($cat);
612 }
54766ea XMLRPC category fixes
ryan authored
613 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
614
615 $post_excerpt = $content_struct['mt_excerpt'];
616 $post_more = $content_struct['mt_text_more'];
617 $post_status = $publish ? 'publish' : 'draft';
618
b5ae536 Check for publish caps when editing via xmlrpc. For 2.0
ryan authored
619
620 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
621 return new IXR_Error(401, 'Sorry, you do not have the right to publish this post.');
622
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
623 if ($post_more) {
624 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
625 }
626
ef81217 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
627 $to_ping = $content_struct['mt_tb_ping_urls'];
628 if ( is_array($to_ping) )
629 $to_ping = implode(' ', $to_ping);
630
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
631 $comment_status = (empty($content_struct['mt_allow_comments'])) ?
632 get_settings('default_comment_status')
633 : $content_struct['mt_allow_comments'];
634
635 $ping_status = (empty($content_struct['mt_allow_pings'])) ?
636 get_settings('default_ping_status')
637 : $content_struct['mt_allow_pings'];
638
639 // Do some timestamp voodoo
9367489 dateCreated typos
michelvaldrighi authored
640 $dateCreatedd = $content_struct['dateCreated'];
641 if (!empty($dateCreatedd)) {
06d0270 I was stupidly parsing dateCreated even when it was empty -- hence th…
michelvaldrighi authored
642 $dateCreated = $dateCreatedd->getIso();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
643 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
644 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
645 } else {
646 $post_date = $postdata['post_date'];
647 $post_date_gmt = $postdata['post_date_gmt'];
648 }
649
650 // We've got all the data -- post it:
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
651 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
652
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
653 $result = wp_update_post($newpost);
654 if (!$result) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
655 return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.');
656 }
657
658 logIO('O',"(MW) Edited ! ID: $post_ID");
659
660 return true;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
661 }
662
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
663
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
664 /* metaweblog.getPost ...returns a post */
665 function mw_getPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
666
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
667 global $wpdb;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
668
9c9ba0a Escape XMLRPC args.
ryan authored
669 $this->escape($args);
670
a359d59 Some int casts
ryan authored
671 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
672 $user_login = $args[1];
673 $user_pass = $args[2];
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
674
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
675 if (!$this->login_pass_ok($user_login, $user_pass)) {
676 return $this->error;
677 }
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
678
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
679 $postdata = wp_get_single_post($post_ID, ARRAY_A);
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
680
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
681 if ($postdata['post_date'] != '') {
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
682
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
683 $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
684
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
685 $categories = array();
686 $catids = wp_get_post_cats('', $post_ID);
687 foreach($catids as $catid) {
688 $categories[] = get_cat_name($catid);
689 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
690
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
691 $post = get_extended($postdata['post_content']);
692 $link = post_permalink($postdata['ID']);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
693
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
694 $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
695 $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
696
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
697 $resp = array(
698 'dateCreated' => new IXR_Date($post_date),
699 'userid' => $postdata['post_author'],
700 'postid' => $postdata['ID'],
701 'description' => $post['main'],
702 'title' => $postdata['post_title'],
703 'link' => $link,
704 'permaLink' => $link,
705 // commented out because no other tool seems to use this
706 // 'content' => $entry['post_content'],
707 'categories' => $categories,
708 'mt_excerpt' => $postdata['post_excerpt'],
709 'mt_text_more' => $post['extended'],
710 'mt_allow_comments' => $allow_comments,
711 'mt_allow_pings' => $allow_pings
712 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
713
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
714 return $resp;
715 } else {
716 return new IXR_Error(404, 'Sorry, no such post.');
717 }
718 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
719
720
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
721 /* metaweblog.getRecentPosts ...returns recent posts */
722 function mw_getRecentPosts($args) {
723
9c9ba0a Escape XMLRPC args.
ryan authored
724 $this->escape($args);
725
a359d59 Some int casts
ryan authored
726 $blog_ID = (int) $args[0];
727 $user_login = $args[1];
728 $user_pass = $args[2];
729 $num_posts = (int) $args[3];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
730
731 if (!$this->login_pass_ok($user_login, $user_pass)) {
732 return $this->error;
733 }
734
735 $posts_list = wp_get_recent_posts($num_posts);
736
737 if (!$posts_list) {
738 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
739 return $this->error;
740 }
741
742 foreach ($posts_list as $entry) {
743
744 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
745 $categories = array();
746 $catids = wp_get_post_cats('', $entry['ID']);
747 foreach($catids as $catid) {
748 $categories[] = get_cat_name($catid);
749 }
750
751 $post = get_extended($entry['post_content']);
752 $link = post_permalink($entry['ID']);
753
754 $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
755 $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
756
757 $struct[] = array(
758 'dateCreated' => new IXR_Date($post_date),
759 'userid' => $entry['post_author'],
760 'postid' => $entry['ID'],
761 'description' => $post['main'],
762 'title' => $entry['post_title'],
763 'link' => $link,
764 'permaLink' => $link,
765 // commented out because no other tool seems to use this
766 // 'content' => $entry['post_content'],
767 'categories' => $categories,
768 'mt_excerpt' => $entry['post_excerpt'],
769 'mt_text_more' => $post['extended'],
770 'mt_allow_comments' => $allow_comments,
771 'mt_allow_pings' => $allow_pings
772 );
773
774 }
775
776 $recent_posts = array();
777 for ($j=0; $j<count($struct); $j++) {
778 array_push($recent_posts, $struct[$j]);
779 }
780
781 return $recent_posts;
782 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
783
784
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
785 /* metaweblog.getCategories ...returns the list of categories on a given weblog */
786 function mw_getCategories($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
787
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
788 global $wpdb;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
789
9c9ba0a Escape XMLRPC args.
ryan authored
790 $this->escape($args);
791
a359d59 Some int casts
ryan authored
792 $blog_ID = (int) $args[0];
793 $user_login = $args[1];
794 $user_pass = $args[2];
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
795
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
796 if (!$this->login_pass_ok($user_login, $user_pass)) {
797 return $this->error;
798 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
799
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
800 $categories_struct = array();
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
801
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
802 // FIXME: can we avoid using direct SQL there?
803 if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) {
804 foreach ($cats as $cat) {
805 $struct['categoryId'] = $cat['cat_ID'];
806 $struct['description'] = $cat['cat_name'];
807 $struct['categoryName'] = $cat['cat_name'];
0be171b fix parse error
michelvaldrighi authored
808 $struct['htmlUrl'] = wp_specialchars(get_category_link($cat['cat_ID']));
c3e1d51 Axing htmlspecialchars because it double-encodes-encodes. Better erro…
saxmatt authored
809 $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name']));
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
810
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
811 $categories_struct[] = $struct;
812 }
813 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
814
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
815 return $categories_struct;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit…
michelvaldrighi authored
816 }
817
17d6d76 added mw.newMediaObject (not tested yet), fixed local/gmt dates confu…
michelvaldrighi authored
818
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
819 /* metaweblog.newMediaObject uploads a file, following your settings */
820 function mw_newMediaObject($args) {
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
821 // adapted from a patch by Johann Richard
822 // http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
823
c267240 Don't escape image bits.
ryan authored
824 global $wpdb;
bdfab81 Default category and pingback check fixes.
ryan authored
825
a359d59 Some int casts
ryan authored
826 $blog_ID = (int) $args[0];
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
827 $user_login = $wpdb->escape($args[1]);
c267240 Don't escape image bits.
ryan authored
828 $user_pass = $wpdb->escape($args[2]);
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
829 $data = $args[3];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
830
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
831 $name = $data['name'];
832 $type = $data['type'];
833 $bits = $data['bits'];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
834
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
835 logIO('O', '(MW) Received '.strlen($bits).' bytes');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
836
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
837 if ( !$this->login_pass_ok($user_login, $user_pass) )
838 return $this->error;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
839
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
840 set_current_user(0, $user_login);
841 if ( !current_user_can('upload_files') ) {
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
842 logIO('O', '(MW) User does not have upload_files capability');
843 $this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
844 return $this->error;
845 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
846
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
847 $upload = wp_upload_bits($name, $type, $bits);
6d40d77 More wp_upload_bits() fixes.
ryan authored
848 if ( ! empty($upload['error']) ) {
30a8b61 Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
ryan authored
849 logIO('O', '(MW) Could not write file '.$name);
850 return new IXR_Error(500, 'Could not write file '.$name);
851 }
852
853 return array('url' => $upload['url']);
17d6d76 added mw.newMediaObject (not tested yet), fixed local/gmt dates confu…
michelvaldrighi authored
854 }
855
89e0409 various fixes, and started MT API support
michelvaldrighi authored
856
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
857 /* MovableType API functions
858 * specs on http://www.movabletype.org/docs/mtmanual_programmatic.html
859 */
89e0409 various fixes, and started MT API support
michelvaldrighi authored
860
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
861 /* mt.getRecentPostTitles ...returns recent posts' titles */
862 function mt_getRecentPostTitles($args) {
89e0409 various fixes, and started MT API support
michelvaldrighi authored
863
9c9ba0a Escape XMLRPC args.
ryan authored
864 $this->escape($args);
865
a359d59 Some int casts
ryan authored
866 $blog_ID = (int) $args[0];
867 $user_login = $args[1];
868 $user_pass = $args[2];
869 $num_posts = (int) $args[3];
89e0409 various fixes, and started MT API support
michelvaldrighi authored
870
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
871 if (!$this->login_pass_ok($user_login, $user_pass)) {
872 return $this->error;
873 }
89e0409 various fixes, and started MT API support
michelvaldrighi authored
874
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
875 $posts_list = wp_get_recent_posts($num_posts);
89e0409 various fixes, and started MT API support
michelvaldrighi authored
876
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
877 if (!$posts_list) {
878 $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
879 return $this->error;
880 }
89e0409 various fixes, and started MT API support
michelvaldrighi authored
881
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
882 foreach ($posts_list as $entry) {
883
884 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
89e0409 various fixes, and started MT API support
michelvaldrighi authored
885
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
886 $struct[] = array(
887 'dateCreated' => new IXR_Date($post_date),
888 'userid' => $entry['post_author'],
889 'postid' => $entry['ID'],
890 'title' => $entry['post_title'],
891 );
89e0409 various fixes, and started MT API support
michelvaldrighi authored
892
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
893 }
89e0409 various fixes, and started MT API support
michelvaldrighi authored
894
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
895 $recent_posts = array();
896 for ($j=0; $j<count($struct); $j++) {
897 array_push($recent_posts, $struct[$j]);
898 }
899
900 return $recent_posts;
89e0409 various fixes, and started MT API support
michelvaldrighi authored
901 }
902
903
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
904 /* mt.getCategoryList ...returns the list of categories on a given weblog */
905 function mt_getCategoryList($args) {
89e0409 various fixes, and started MT API support
michelvaldrighi authored
906
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
907 global $wpdb;
89e0409 various fixes, and started MT API support
michelvaldrighi authored
908
9c9ba0a Escape XMLRPC args.
ryan authored
909 $this->escape($args);
910
a359d59 Some int casts
ryan authored
911 $blog_ID = (int) $args[0];
912 $user_login = $args[1];
913 $user_pass = $args[2];
89e0409 various fixes, and started MT API support
michelvaldrighi authored
914
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
915 if (!$this->login_pass_ok($user_login, $user_pass)) {
916 return $this->error;
917 }
89e0409 various fixes, and started MT API support
michelvaldrighi authored
918
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
919 $categories_struct = array();
89e0409 various fixes, and started MT API support
michelvaldrighi authored
920
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
921 // FIXME: can we avoid using direct SQL there?
922 if ($cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_A)) {
923 foreach ($cats as $cat) {
924 $struct['categoryId'] = $cat['cat_ID'];
925 $struct['categoryName'] = $cat['cat_name'];
89e0409 various fixes, and started MT API support
michelvaldrighi authored
926
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
927 $categories_struct[] = $struct;
928 }
929 }
89e0409 various fixes, and started MT API support
michelvaldrighi authored
930
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
931 return $categories_struct;
89e0409 various fixes, and started MT API support
michelvaldrighi authored
932 }
933
093993d added pingback (now with accurate fault codes and more easily readabl…
michelvaldrighi authored
934
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
935 /* mt.getPostCategories ...returns a post's categories */
936 function mt_getPostCategories($args) {
937
9c9ba0a Escape XMLRPC args.
ryan authored
938 $this->escape($args);
939
a359d59 Some int casts
ryan authored
940 $post_ID = (int) $args[0];
941 $user_login = $args[1];
942 $user_pass = $args[2];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
943
944 if (!$this->login_pass_ok($user_login, $user_pass)) {
945 return $this->error;
946 }
947
948 $categories = array();
949 $catids = wp_get_post_cats('', intval($post_ID));
950 // first listed category will be the primary category
951 $isPrimary = true;
952 foreach($catids as $catid) {
953 $categories[] = array(
954 'categoryName' => get_cat_name($catid),
955 'categoryId' => $catid,
956 'isPrimary' => $isPrimary
957 );
958 $isPrimary = false;
959 }
960
961 return $categories;
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
962 }
963
964
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
965 /* mt.setPostCategories ...sets a post's categories */
966 function mt_setPostCategories($args) {
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
967
9c9ba0a Escape XMLRPC args.
ryan authored
968 $this->escape($args);
969
a359d59 Some int casts
ryan authored
970 $post_ID = (int) $args[0];
971 $user_login = $args[1];
972 $user_pass = $args[2];
973 $categories = $args[3];
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
974
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
975 if (!$this->login_pass_ok($user_login, $user_pass)) {
976 return $this->error;
977 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
978
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
979 set_current_user(0, $user_login);
980 if ( !current_user_can('edit_post', $post_ID) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
981 return new IXR_Error(401, 'Sorry, you can not edit this post.');
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
982
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
983 foreach($categories as $cat) {
984 $catids[] = $cat['categoryId'];
985 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
986
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
987 wp_set_post_cats('', $post_ID, $catids);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
988
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
989 return true;
990 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
991
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
992
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
993 /* mt.supportedMethods ...returns an array of methods supported by this server */
994 function mt_supportedMethods($args) {
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
995
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
996 $supported_methods = array();
997 foreach($this->methods as $key=>$value) {
998 $supported_methods[] = $key;
999 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1000
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1001 return $supported_methods;
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1002 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1003
1004
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1005 /* mt.supportedTextFilters ...returns an empty array because we don't
1006 support per-post text filters yet */
1007 function mt_supportedTextFilters($args) {
1008 return array();
1009 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1010
1011
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1012 /* mt.getTrackbackPings ...returns trackbacks sent to a given post */
1013 function mt_getTrackbackPings($args) {
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1014
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1015 global $wpdb;
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1016
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1017 $post_ID = intval($args);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1018
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1019 $actual_post = wp_get_single_post($post_ID, ARRAY_A);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1020
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1021 if (!$actual_post) {
1022 return new IXR_Error(404, 'Sorry, no such post.');
1023 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1024
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1025 $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID");
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1026
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1027 if (!$comments) {
1028 return array();
1029 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1030
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1031 $trackback_pings = array();
1032 foreach($comments as $comment) {
6584b20 Some cleanup patches from Scott: http://www.coffee2code.com/archives/…
saxmatt authored
1033 if ( 'trackback' == $comment->comment_type ) {
1034 $content = $comment->comment_content;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1035 $title = substr($content, 8, (strpos($content, '</strong>') - 8));
1036 $trackback_pings[] = array(
1037 'pingTitle' => $title,
1038 'pingURL' => $comment->comment_author_url,
1039 'pingIP' => $comment->comment_author_IP
1040 );
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1041 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1042 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1043
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1044 return $trackback_pings;
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1045 }
1046
1047
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1048 /* mt.publishPost ...sets a post's publish status to 'publish' */
1049 function mt_publishPost($args) {
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1050
9c9ba0a Escape XMLRPC args.
ryan authored
1051 $this->escape($args);
1052
a359d59 Some int casts
ryan authored
1053 $post_ID = (int) $args[0];
1054 $user_login = $args[1];
1055 $user_pass = $args[2];
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1056
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1057 if (!$this->login_pass_ok($user_login, $user_pass)) {
1058 return $this->error;
1059 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1060
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
1061 set_current_user(0, $user_login);
1062 if ( !current_user_can('edit_post', $post_ID) )
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1063 return new IXR_Error(401, 'Sorry, you can not edit this post.');
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1064
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1065 $postdata = wp_get_single_post($post_ID,ARRAY_A);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1066
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1067 $postdata['post_status'] = 'publish';
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1068
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1069 // retain old cats
1070 $cats = wp_get_post_cats('',$post_ID);
1071 $postdata['post_category'] = $cats;
9c9ba0a Escape XMLRPC args.
ryan authored
1072 $this->escape($postdata);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1073
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1074 $result = wp_update_post($postdata);
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1075
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1076 return $result;
1077 }
83d9723 now with complete MT API support -- TEST TEST TEST THIS (here it work…
michelvaldrighi authored
1078
093993d added pingback (now with accurate fault codes and more easily readabl…
michelvaldrighi authored
1079
1080
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1081 /* PingBack functions
1082 * specs on www.hixie.ch/specs/pingback/pingback
1083 */
093993d added pingback (now with accurate fault codes and more easily readabl…
michelvaldrighi authored
1084
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1085 /* pingback.ping gets a pingback and registers it */
1086 function pingback_ping($args) {
1087 global $wpdb, $wp_version;
093993d added pingback (now with accurate fault codes and more easily readabl…
michelvaldrighi authored
1088
9c9ba0a Escape XMLRPC args.
ryan authored
1089 $this->escape($args);
1090
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1091 $pagelinkedfrom = $args[0];
1092 $pagelinkedto = $args[1];
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1093
a7322e8