Skip to content

HTTPS clone URL

Subversion checkout URL

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