Skip to content

HTTPS clone URL

Subversion checkout URL

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