Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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