webmaster@1
|
1 <?php |
webmaster@9
|
2 // $Id: blogapi.module,v 1.115.2.3 2008/08/13 23:59:13 drumm Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * @file |
webmaster@1
|
6 * Enable users to post using applications that support XML-RPC blog APIs. |
webmaster@1
|
7 */ |
webmaster@1
|
8 |
webmaster@1
|
9 /** |
webmaster@1
|
10 * Implementation of hook_help(). |
webmaster@1
|
11 */ |
webmaster@1
|
12 function blogapi_help($path, $arg) { |
webmaster@1
|
13 switch ($path) { |
webmaster@1
|
14 case 'admin/help#blogapi': |
webmaster@1
|
15 $output = '<p>'. t("The Blog API module allows your site's users to access and post to their blogs from external blogging clients. External blogging clients are available for a wide range of desktop operating systems, and generally provide a feature-rich graphical environment for creating and editing posts.") .'</p>'; |
webmaster@1
|
16 $output .= '<p>'. t('<a href="@ecto-link">Ecto</a>, a blogging client available for both Mac OS X and Microsoft Windows, can be used with Blog API. Blog API also supports <a href="@blogger-api">Blogger API</a>, <a href="@metaweblog-api">MetaWeblog API</a>, and most of the <a href="@movabletype-api">Movable Type API</a>. Blogging clients and other services (e.g. <a href="@flickr">Flickr\'s</a> "post to blog") that support these APIs may also be compatible.', array('@ecto-link' => url('http://infinite-sushi.com/software/ecto/'), '@blogger-api' => url('http://www.blogger.com/developers/api/1_docs/'), '@metaweblog-api' => url('http://www.xmlrpc.com/metaWeblogApi'), '@movabletype-api' => url('http://www.movabletype.org/docs/mtmanual_programmatic.html'), '@flickr' => url('http://www.flickr.com'))) .'</p>'; |
webmaster@1
|
17 $output .= '<p>'. t('Select the content types available to external clients on the <a href="@blogapi-settings">Blog API settings page</a>. If supported and available, each content type will be displayed as a separate "blog" by the external client.', array('@blogapi-settings' => url('admin/settings/blogapi'))) .'</p>'; |
webmaster@1
|
18 $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@blogapi">Blog API module</a>.', array('@blogapi' => url('http://drupal.org/handbook/modules/blogapi/'))) .'</p>'; |
webmaster@1
|
19 return $output; |
webmaster@1
|
20 } |
webmaster@1
|
21 } |
webmaster@1
|
22 |
webmaster@1
|
23 /** |
webmaster@1
|
24 * Implementation of hook_perm(). |
webmaster@1
|
25 */ |
webmaster@1
|
26 function blogapi_perm() { |
webmaster@1
|
27 return array('administer content with blog api'); |
webmaster@1
|
28 } |
webmaster@1
|
29 |
webmaster@1
|
30 /** |
webmaster@1
|
31 * Implementation of hook_xmlrpc(). |
webmaster@1
|
32 */ |
webmaster@1
|
33 function blogapi_xmlrpc() { |
webmaster@1
|
34 return array( |
webmaster@1
|
35 array( |
webmaster@1
|
36 'blogger.getUsersBlogs', |
webmaster@1
|
37 'blogapi_blogger_get_users_blogs', |
webmaster@1
|
38 array('array', 'string', 'string', 'string'), |
webmaster@1
|
39 t('Returns a list of blogs to which an author has posting privileges.')), |
webmaster@1
|
40 array( |
webmaster@1
|
41 'blogger.getUserInfo', |
webmaster@1
|
42 'blogapi_blogger_get_user_info', |
webmaster@1
|
43 array('struct', 'string', 'string', 'string'), |
webmaster@1
|
44 t('Returns information about an author in the system.')), |
webmaster@1
|
45 array( |
webmaster@1
|
46 'blogger.newPost', |
webmaster@1
|
47 'blogapi_blogger_new_post', |
webmaster@1
|
48 array('string', 'string', 'string', 'string', 'string', 'string', 'boolean'), |
webmaster@1
|
49 t('Creates a new post, and optionally publishes it.')), |
webmaster@1
|
50 array( |
webmaster@1
|
51 'blogger.editPost', |
webmaster@1
|
52 'blogapi_blogger_edit_post', |
webmaster@1
|
53 array('boolean', 'string', 'string', 'string', 'string', 'string', 'boolean'), |
webmaster@1
|
54 t('Updates the information about an existing post.')), |
webmaster@1
|
55 array( |
webmaster@1
|
56 'blogger.getPost', |
webmaster@1
|
57 'blogapi_blogger_get_post', |
webmaster@1
|
58 array('struct', 'string', 'string', 'string', 'string'), |
webmaster@1
|
59 t('Returns information about a specific post.')), |
webmaster@1
|
60 array( |
webmaster@1
|
61 'blogger.deletePost', |
webmaster@1
|
62 'blogapi_blogger_delete_post', |
webmaster@1
|
63 array('boolean', 'string', 'string', 'string', 'string', 'boolean'), |
webmaster@1
|
64 t('Deletes a post.')), |
webmaster@1
|
65 array( |
webmaster@1
|
66 'blogger.getRecentPosts', |
webmaster@1
|
67 'blogapi_blogger_get_recent_posts', |
webmaster@1
|
68 array('array', 'string', 'string', 'string', 'string', 'int'), |
webmaster@1
|
69 t('Returns a list of the most recent posts in the system.')), |
webmaster@1
|
70 array( |
webmaster@1
|
71 'metaWeblog.newPost', |
webmaster@1
|
72 'blogapi_metaweblog_new_post', |
webmaster@1
|
73 array('string', 'string', 'string', 'string', 'struct', 'boolean'), |
webmaster@1
|
74 t('Creates a new post, and optionally publishes it.')), |
webmaster@1
|
75 array( |
webmaster@1
|
76 'metaWeblog.editPost', |
webmaster@1
|
77 'blogapi_metaweblog_edit_post', |
webmaster@1
|
78 array('boolean', 'string', 'string', 'string', 'struct', 'boolean'), |
webmaster@1
|
79 t('Updates information about an existing post.')), |
webmaster@1
|
80 array( |
webmaster@1
|
81 'metaWeblog.getPost', |
webmaster@1
|
82 'blogapi_metaweblog_get_post', |
webmaster@1
|
83 array('struct', 'string', 'string', 'string'), |
webmaster@1
|
84 t('Returns information about a specific post.')), |
webmaster@1
|
85 array( |
webmaster@1
|
86 'metaWeblog.newMediaObject', |
webmaster@1
|
87 'blogapi_metaweblog_new_media_object', |
webmaster@1
|
88 array('string', 'string', 'string', 'string', 'struct'), |
webmaster@1
|
89 t('Uploads a file to your webserver.')), |
webmaster@1
|
90 array( |
webmaster@1
|
91 'metaWeblog.getCategories', |
webmaster@1
|
92 'blogapi_metaweblog_get_category_list', |
webmaster@1
|
93 array('struct', 'string', 'string', 'string'), |
webmaster@1
|
94 t('Returns a list of all categories to which the post is assigned.')), |
webmaster@1
|
95 array( |
webmaster@1
|
96 'metaWeblog.getRecentPosts', |
webmaster@1
|
97 'blogapi_metaweblog_get_recent_posts', |
webmaster@1
|
98 array('array', 'string', 'string', 'string', 'int'), |
webmaster@1
|
99 t('Returns a list of the most recent posts in the system.')), |
webmaster@1
|
100 array( |
webmaster@1
|
101 'mt.getRecentPostTitles', |
webmaster@1
|
102 'blogapi_mt_get_recent_post_titles', |
webmaster@1
|
103 array('array', 'string', 'string', 'string', 'int'), |
webmaster@1
|
104 t('Returns a bandwidth-friendly list of the most recent posts in the system.')), |
webmaster@1
|
105 array( |
webmaster@1
|
106 'mt.getCategoryList', |
webmaster@1
|
107 'blogapi_mt_get_category_list', |
webmaster@1
|
108 array('array', 'string', 'string', 'string'), |
webmaster@1
|
109 t('Returns a list of all categories defined in the blog.')), |
webmaster@1
|
110 array( |
webmaster@1
|
111 'mt.getPostCategories', |
webmaster@1
|
112 'blogapi_mt_get_post_categories', |
webmaster@1
|
113 array('array', 'string', 'string', 'string'), |
webmaster@1
|
114 t('Returns a list of all categories to which the post is assigned.')), |
webmaster@1
|
115 array( |
webmaster@1
|
116 'mt.setPostCategories', |
webmaster@1
|
117 'blogapi_mt_set_post_categories', |
webmaster@1
|
118 array('boolean', 'string', 'string', 'string', 'array'), |
webmaster@1
|
119 t('Sets the categories for a post.')), |
webmaster@1
|
120 array( |
webmaster@1
|
121 'mt.supportedMethods', |
webmaster@1
|
122 'xmlrpc_server_list_methods', |
webmaster@1
|
123 array('array'), |
webmaster@1
|
124 t('Retrieve information about the XML-RPC methods supported by the server.')), |
webmaster@1
|
125 array( |
webmaster@1
|
126 'mt.supportedTextFilters', |
webmaster@1
|
127 'blogapi_mt_supported_text_filters', |
webmaster@1
|
128 array('array'), |
webmaster@1
|
129 t('Retrieve information about the text formatting plugins supported by the server.')), |
webmaster@1
|
130 array( |
webmaster@1
|
131 'mt.publishPost', |
webmaster@9
|
132 'blogapi_mt_publish_post', |
webmaster@1
|
133 array('boolean', 'string', 'string', 'string'), |
webmaster@1
|
134 t('Publish (rebuild) all of the static files related to an entry from your blog. Equivalent to saving an entry in the system (but without the ping).'))); |
webmaster@1
|
135 } |
webmaster@1
|
136 |
webmaster@1
|
137 /** |
webmaster@1
|
138 * Blogging API callback. Finds the URL of a user's blog. |
webmaster@1
|
139 */ |
webmaster@1
|
140 |
webmaster@1
|
141 function blogapi_blogger_get_users_blogs($appid, $username, $password) { |
webmaster@1
|
142 |
webmaster@1
|
143 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
144 if ($user->uid) { |
webmaster@1
|
145 $types = _blogapi_get_node_types(); |
webmaster@1
|
146 $structs = array(); |
webmaster@1
|
147 foreach ($types as $type) { |
webmaster@1
|
148 $structs[] = array('url' => url('blog/'. $user->uid, array('absolute' => TRUE)), 'blogid' => $type, 'blogName' => $user->name .": ". $type); |
webmaster@1
|
149 } |
webmaster@1
|
150 return $structs; |
webmaster@1
|
151 } |
webmaster@1
|
152 else { |
webmaster@1
|
153 return blogapi_error($user); |
webmaster@1
|
154 } |
webmaster@1
|
155 } |
webmaster@1
|
156 |
webmaster@1
|
157 /** |
webmaster@1
|
158 * Blogging API callback. Returns profile information about a user. |
webmaster@1
|
159 */ |
webmaster@1
|
160 function blogapi_blogger_get_user_info($appkey, $username, $password) { |
webmaster@1
|
161 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
162 |
webmaster@1
|
163 if ($user->uid) { |
webmaster@1
|
164 $name = explode(' ', $user->realname ? $user->realname : $user->name, 2); |
webmaster@1
|
165 return array( |
webmaster@1
|
166 'userid' => $user->uid, |
webmaster@1
|
167 'lastname' => $name[1], |
webmaster@1
|
168 'firstname' => $name[0], |
webmaster@1
|
169 'nickname' => $user->name, |
webmaster@1
|
170 'email' => $user->mail, |
webmaster@1
|
171 'url' => url('blog/'. $user->uid, array('absolute' => TRUE))); |
webmaster@1
|
172 } |
webmaster@1
|
173 else { |
webmaster@1
|
174 return blogapi_error($user); |
webmaster@1
|
175 } |
webmaster@1
|
176 } |
webmaster@1
|
177 |
webmaster@1
|
178 /** |
webmaster@1
|
179 * Blogging API callback. Inserts a new blog post as a node. |
webmaster@1
|
180 */ |
webmaster@1
|
181 function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish) { |
webmaster@1
|
182 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
183 if (!$user->uid) { |
webmaster@1
|
184 return blogapi_error($user); |
webmaster@1
|
185 } |
webmaster@1
|
186 |
webmaster@1
|
187 if (($error = _blogapi_validate_blogid($blogid)) !== TRUE) { |
webmaster@1
|
188 // Return an error if not configured type. |
webmaster@1
|
189 return $error; |
webmaster@1
|
190 } |
webmaster@1
|
191 |
webmaster@1
|
192 $edit = array(); |
webmaster@1
|
193 $edit['type'] = $blogid; |
webmaster@1
|
194 // get the node type defaults |
webmaster@1
|
195 $node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote')); |
webmaster@1
|
196 $edit['uid'] = $user->uid; |
webmaster@1
|
197 $edit['name'] = $user->name; |
webmaster@1
|
198 $edit['promote'] = in_array('promote', $node_type_default); |
webmaster@1
|
199 $edit['comment'] = variable_get('comment_'. $edit['type'], 2); |
webmaster@1
|
200 $edit['revision'] = in_array('revision', $node_type_default); |
webmaster@1
|
201 $edit['format'] = FILTER_FORMAT_DEFAULT; |
webmaster@1
|
202 $edit['status'] = $publish; |
webmaster@1
|
203 |
webmaster@1
|
204 // check for bloggerAPI vs. metaWeblogAPI |
webmaster@1
|
205 if (is_array($content)) { |
webmaster@1
|
206 $edit['title'] = $content['title']; |
webmaster@1
|
207 $edit['body'] = $content['description']; |
webmaster@1
|
208 _blogapi_mt_extra($edit, $content); |
webmaster@1
|
209 } |
webmaster@1
|
210 else { |
webmaster@1
|
211 $edit['title'] = blogapi_blogger_title($content); |
webmaster@1
|
212 $edit['body'] = $content; |
webmaster@1
|
213 } |
webmaster@1
|
214 |
webmaster@1
|
215 if (!node_access('create', $edit['type'])) { |
webmaster@1
|
216 return blogapi_error(t('You do not have permission to create this type of post.')); |
webmaster@1
|
217 } |
webmaster@1
|
218 |
webmaster@1
|
219 if (user_access('administer nodes') && !isset($edit['date'])) { |
webmaster@1
|
220 $edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O'); |
webmaster@1
|
221 } |
webmaster@1
|
222 |
webmaster@1
|
223 node_invoke_nodeapi($edit, 'blogapi new'); |
webmaster@1
|
224 |
webmaster@1
|
225 node_validate($edit); |
webmaster@1
|
226 if ($errors = form_get_errors()) { |
webmaster@1
|
227 return blogapi_error(implode("\n", $errors)); |
webmaster@1
|
228 } |
webmaster@1
|
229 |
webmaster@1
|
230 $node = node_submit($edit); |
webmaster@1
|
231 node_save($node); |
webmaster@1
|
232 if ($node->nid) { |
webmaster@1
|
233 watchdog('content', '@type: added %title using blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); |
webmaster@1
|
234 // blogger.newPost returns a string so we cast the nid to a string by putting it in double quotes: |
webmaster@1
|
235 return "$node->nid"; |
webmaster@1
|
236 } |
webmaster@1
|
237 |
webmaster@1
|
238 return blogapi_error(t('Error storing post.')); |
webmaster@1
|
239 } |
webmaster@1
|
240 |
webmaster@1
|
241 /** |
webmaster@1
|
242 * Blogging API callback. Modifies the specified blog node. |
webmaster@1
|
243 */ |
webmaster@1
|
244 function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $content, $publish) { |
webmaster@1
|
245 |
webmaster@1
|
246 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
247 |
webmaster@1
|
248 if (!$user->uid) { |
webmaster@1
|
249 return blogapi_error($user); |
webmaster@1
|
250 } |
webmaster@1
|
251 |
webmaster@1
|
252 $node = node_load($postid); |
webmaster@1
|
253 if (!$node) { |
webmaster@1
|
254 return blogapi_error(t('n/a')); |
webmaster@1
|
255 } |
webmaster@1
|
256 // Let the teaser be re-generated. |
webmaster@1
|
257 unset($node->teaser); |
webmaster@1
|
258 |
webmaster@1
|
259 if (!node_access('update', $node)) { |
webmaster@1
|
260 return blogapi_error(t('You do not have permission to update this post.')); |
webmaster@1
|
261 } |
webmaster@1
|
262 |
webmaster@1
|
263 $node->status = $publish; |
webmaster@1
|
264 |
webmaster@1
|
265 // check for bloggerAPI vs. metaWeblogAPI |
webmaster@1
|
266 if (is_array($content)) { |
webmaster@1
|
267 $node->title = $content['title']; |
webmaster@1
|
268 $node->body = $content['description']; |
webmaster@1
|
269 _blogapi_mt_extra($node, $content); |
webmaster@1
|
270 } |
webmaster@1
|
271 else { |
webmaster@1
|
272 $node->title = blogapi_blogger_title($content); |
webmaster@1
|
273 $node->body = $content; |
webmaster@1
|
274 } |
webmaster@1
|
275 |
webmaster@1
|
276 node_invoke_nodeapi($node, 'blogapi edit'); |
webmaster@1
|
277 |
webmaster@1
|
278 node_validate($node); |
webmaster@1
|
279 if ($errors = form_get_errors()) { |
webmaster@1
|
280 return blogapi_error(implode("\n", $errors)); |
webmaster@1
|
281 } |
webmaster@1
|
282 |
webmaster@1
|
283 if (user_access('administer nodes') && !isset($edit['date'])) { |
webmaster@1
|
284 $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); |
webmaster@1
|
285 } |
webmaster@1
|
286 $node = node_submit($node); |
webmaster@1
|
287 node_save($node); |
webmaster@1
|
288 if ($node->nid) { |
webmaster@1
|
289 watchdog('content', '@type: updated %title using Blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); |
webmaster@1
|
290 return TRUE; |
webmaster@1
|
291 } |
webmaster@1
|
292 |
webmaster@1
|
293 return blogapi_error(t('Error storing post.')); |
webmaster@1
|
294 } |
webmaster@1
|
295 |
webmaster@1
|
296 /** |
webmaster@1
|
297 * Blogging API callback. Returns a specified blog node. |
webmaster@1
|
298 */ |
webmaster@1
|
299 function blogapi_blogger_get_post($appkey, $postid, $username, $password) { |
webmaster@1
|
300 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
301 if (!$user->uid) { |
webmaster@1
|
302 return blogapi_error($user); |
webmaster@1
|
303 } |
webmaster@1
|
304 |
webmaster@1
|
305 $node = node_load($postid); |
webmaster@1
|
306 |
webmaster@1
|
307 return _blogapi_get_post($node, TRUE); |
webmaster@1
|
308 } |
webmaster@1
|
309 |
webmaster@1
|
310 /** |
webmaster@1
|
311 * Blogging API callback. Removes the specified blog node. |
webmaster@1
|
312 */ |
webmaster@1
|
313 function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $publish) { |
webmaster@1
|
314 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
315 if (!$user->uid) { |
webmaster@1
|
316 return blogapi_error($user); |
webmaster@1
|
317 } |
webmaster@1
|
318 |
webmaster@1
|
319 node_delete($postid); |
webmaster@1
|
320 return TRUE; |
webmaster@1
|
321 } |
webmaster@1
|
322 |
webmaster@1
|
323 /** |
webmaster@1
|
324 * Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE |
webmaster@1
|
325 * <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles"> |
webmaster@1
|
326 * returns a bandwidth-friendly list</a>. |
webmaster@1
|
327 */ |
webmaster@1
|
328 function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password, $number_of_posts, $bodies = TRUE) { |
webmaster@1
|
329 // Remove unused appkey (from bloggerAPI). |
webmaster@1
|
330 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
331 if (!$user->uid) { |
webmaster@1
|
332 return blogapi_error($user); |
webmaster@1
|
333 } |
webmaster@1
|
334 |
webmaster@1
|
335 if (($error = _blogapi_validate_blogid($blogid)) !== TRUE) { |
webmaster@1
|
336 // Return an error if not configured type. |
webmaster@1
|
337 return $error; |
webmaster@1
|
338 } |
webmaster@1
|
339 |
webmaster@1
|
340 if ($bodies) { |
webmaster@1
|
341 $result = db_query_range("SELECT n.nid, n.title, r.body, r.format, n.comment, n.created, u.name FROM {node} n, {node_revisions} r, {users} u WHERE n.uid = u.uid AND n.vid = r.vid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $blogid, $user->uid, 0, $number_of_posts); |
webmaster@1
|
342 } |
webmaster@1
|
343 else { |
webmaster@1
|
344 $result = db_query_range("SELECT n.nid, n.title, n.created, u.name FROM {node} n, {users} u WHERE n.uid = u.uid AND n.type = '%s' AND n.uid = %d ORDER BY n.created DESC", $blogid, $user->uid, 0, $number_of_posts); |
webmaster@1
|
345 } |
webmaster@1
|
346 $blogs = array(); |
webmaster@1
|
347 while ($blog = db_fetch_object($result)) { |
webmaster@1
|
348 $blogs[] = _blogapi_get_post($blog, $bodies); |
webmaster@1
|
349 } |
webmaster@1
|
350 return $blogs; |
webmaster@1
|
351 } |
webmaster@1
|
352 |
webmaster@1
|
353 function blogapi_metaweblog_new_post($blogid, $username, $password, $content, $publish) { |
webmaster@1
|
354 return blogapi_blogger_new_post('0123456789ABCDEF', $blogid, $username, $password, $content, $publish); |
webmaster@1
|
355 } |
webmaster@1
|
356 |
webmaster@1
|
357 function blogapi_metaweblog_edit_post($postid, $username, $password, $content, $publish) { |
webmaster@1
|
358 return blogapi_blogger_edit_post('0123456789ABCDEF', $postid, $username, $password, $content, $publish); |
webmaster@1
|
359 } |
webmaster@1
|
360 |
webmaster@1
|
361 function blogapi_metaweblog_get_post($postid, $username, $password) { |
webmaster@1
|
362 return blogapi_blogger_get_post('01234567890ABCDEF', $postid, $username, $password); |
webmaster@1
|
363 } |
webmaster@1
|
364 |
webmaster@1
|
365 /** |
webmaster@1
|
366 * Blogging API callback. Inserts a file into Drupal. |
webmaster@1
|
367 */ |
webmaster@1
|
368 function blogapi_metaweblog_new_media_object($blogid, $username, $password, $file) { |
webmaster@1
|
369 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
370 if (!$user->uid) { |
webmaster@1
|
371 return blogapi_error($user); |
webmaster@1
|
372 } |
webmaster@1
|
373 |
webmaster@9
|
374 $usersize = 0; |
webmaster@9
|
375 $uploadsize = 0; |
webmaster@9
|
376 |
webmaster@9
|
377 $roles = array_intersect(user_roles(FALSE, 'administer content with blog api'), $user->roles); |
webmaster@9
|
378 |
webmaster@9
|
379 foreach ($roles as $rid => $name) { |
webmaster@9
|
380 $extensions .= ' '. strtolower(variable_get("blogapi_extensions_$rid", variable_get('blogapi_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'))); |
webmaster@9
|
381 $usersize= max($usersize, variable_get("blogapi_usersize_$rid", variable_get('blogapi_usersize_default', 1)) * 1024 * 1024); |
webmaster@9
|
382 $uploadsize = max($uploadsize, variable_get("blogapi_uploadsize_$rid", variable_get('blogapi_uploadsize_default', 1)) * 1024 * 1024); |
webmaster@9
|
383 } |
webmaster@9
|
384 |
webmaster@9
|
385 $filesize = strlen($file['bits']); |
webmaster@9
|
386 |
webmaster@9
|
387 if ($filesize > $uploadsize) { |
webmaster@9
|
388 return blogapi_error(t('It is not possible to upload the file, because it exceeded the maximum filesize of @maxsize.', array('@maxsize' => format_size($uploadsize)))); |
webmaster@9
|
389 } |
webmaster@9
|
390 |
webmaster@9
|
391 if (_blogapi_space_used($user->uid) + $filesize > $usersize) { |
webmaster@9
|
392 return blogapi_error(t('The file can not be attached to this post, because the disk quota of @quota has been reached.', array('@quota' => format_size($usersize)))); |
webmaster@9
|
393 } |
webmaster@9
|
394 |
webmaster@9
|
395 // Only allow files with whitelisted extensions and convert remaining dots to |
webmaster@9
|
396 // underscores to prevent attacks via non-terminal executable extensions with |
webmaster@9
|
397 // files such as exploit.php.jpg. |
webmaster@9
|
398 |
webmaster@9
|
399 $whitelist = array_unique(explode(' ', trim($extensions))); |
webmaster@9
|
400 |
webmaster@1
|
401 $name = basename($file['name']); |
webmaster@9
|
402 |
webmaster@9
|
403 if ($extension_position = strrpos($name, '.')) { |
webmaster@9
|
404 $filename = drupal_substr($name, 0, $extension_position); |
webmaster@9
|
405 $final_extension = drupal_substr($name, $extension_position + 1); |
webmaster@9
|
406 |
webmaster@9
|
407 if (!in_array(strtolower($final_extension), $whitelist)) { |
webmaster@9
|
408 return blogapi_error(t('It is not possible to upload the file, because it is only possible to upload files with the following extensions: @extensions', array('@extensions' => implode(' ', $whitelist)))); |
webmaster@9
|
409 } |
webmaster@9
|
410 |
webmaster@9
|
411 $filename = str_replace('.', '_', $filename); |
webmaster@9
|
412 $filename .= '.'. $final_extension; |
webmaster@9
|
413 } |
webmaster@9
|
414 |
webmaster@1
|
415 $data = $file['bits']; |
webmaster@1
|
416 |
webmaster@1
|
417 if (!$data) { |
webmaster@1
|
418 return blogapi_error(t('No file sent.')); |
webmaster@1
|
419 } |
webmaster@1
|
420 |
webmaster@9
|
421 if (!$file = file_save_data($data, $filename)) { |
webmaster@1
|
422 return blogapi_error(t('Error storing file.')); |
webmaster@1
|
423 } |
webmaster@1
|
424 |
webmaster@9
|
425 $row = new stdClass(); |
webmaster@9
|
426 $row->uid = $user->uid; |
webmaster@9
|
427 $row->filepath = $file; |
webmaster@9
|
428 $row->filesize = $filesize; |
webmaster@9
|
429 |
webmaster@9
|
430 drupal_write_record('blogapi_files', $row); |
webmaster@9
|
431 |
webmaster@1
|
432 // Return the successful result. |
webmaster@1
|
433 return array('url' => file_create_url($file), 'struct'); |
webmaster@1
|
434 } |
webmaster@1
|
435 /** |
webmaster@1
|
436 * Blogging API callback. Returns a list of the taxonomy terms that can be |
webmaster@1
|
437 * associated with a blog node. |
webmaster@1
|
438 */ |
webmaster@1
|
439 function blogapi_metaweblog_get_category_list($blogid, $username, $password) { |
webmaster@1
|
440 if (($error = _blogapi_validate_blogid($blogid)) !== TRUE) { |
webmaster@1
|
441 // Return an error if not configured type. |
webmaster@1
|
442 return $error; |
webmaster@1
|
443 } |
webmaster@1
|
444 |
webmaster@1
|
445 $vocabularies = module_invoke('taxonomy', 'get_vocabularies', $blogid, 'vid'); |
webmaster@1
|
446 $categories = array(); |
webmaster@1
|
447 if ($vocabularies) { |
webmaster@1
|
448 foreach ($vocabularies as $vocabulary) { |
webmaster@1
|
449 $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, -1); |
webmaster@1
|
450 foreach ($terms as $term) { |
webmaster@1
|
451 $term_name = $term->name; |
webmaster@1
|
452 foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) { |
webmaster@1
|
453 $term_name = $parent->name .'/'. $term_name; |
webmaster@1
|
454 } |
webmaster@1
|
455 $categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid); |
webmaster@1
|
456 } |
webmaster@1
|
457 } |
webmaster@1
|
458 } |
webmaster@1
|
459 return $categories; |
webmaster@1
|
460 } |
webmaster@1
|
461 |
webmaster@1
|
462 function blogapi_metaweblog_get_recent_posts($blogid, $username, $password, $number_of_posts) { |
webmaster@1
|
463 return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, TRUE); |
webmaster@1
|
464 } |
webmaster@1
|
465 |
webmaster@1
|
466 function blogapi_mt_get_recent_post_titles($blogid, $username, $password, $number_of_posts) { |
webmaster@1
|
467 return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, FALSE); |
webmaster@1
|
468 } |
webmaster@1
|
469 |
webmaster@1
|
470 function blogapi_mt_get_category_list($blogid, $username, $password) { |
webmaster@1
|
471 return blogapi_metaweblog_get_category_list($blogid, $username, $password); |
webmaster@1
|
472 } |
webmaster@1
|
473 |
webmaster@1
|
474 /** |
webmaster@1
|
475 * Blogging API callback. Returns a list of the taxonomy terms that are |
webmaster@1
|
476 * assigned to a particular node. |
webmaster@1
|
477 */ |
webmaster@1
|
478 function blogapi_mt_get_post_categories($postid, $username, $password) { |
webmaster@1
|
479 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
480 if (!$user->uid) { |
webmaster@1
|
481 return blogapi_error($user); |
webmaster@1
|
482 } |
webmaster@1
|
483 |
webmaster@1
|
484 $node = node_load($postid); |
webmaster@1
|
485 $terms = module_invoke('taxonomy', 'node_get_terms', $node, 'tid'); |
webmaster@1
|
486 $categories = array(); |
webmaster@1
|
487 foreach ($terms as $term) { |
webmaster@1
|
488 $term_name = $term->name; |
webmaster@1
|
489 foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) { |
webmaster@1
|
490 $term_name = $parent->name .'/'. $term_name; |
webmaster@1
|
491 } |
webmaster@1
|
492 $categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid, 'isPrimary' => TRUE); |
webmaster@1
|
493 } |
webmaster@1
|
494 |
webmaster@1
|
495 return $categories; |
webmaster@1
|
496 } |
webmaster@1
|
497 |
webmaster@1
|
498 /** |
webmaster@1
|
499 * Blogging API callback. Assigns taxonomy terms to a particular node. |
webmaster@1
|
500 */ |
webmaster@1
|
501 function blogapi_mt_set_post_categories($postid, $username, $password, $categories) { |
webmaster@1
|
502 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
503 if (!$user->uid) { |
webmaster@1
|
504 return blogapi_error($user); |
webmaster@1
|
505 } |
webmaster@1
|
506 |
webmaster@1
|
507 $node = node_load($postid); |
webmaster@1
|
508 $node->taxonomy = array(); |
webmaster@1
|
509 foreach ($categories as $category) { |
webmaster@1
|
510 $node->taxonomy[] = $category['categoryId']; |
webmaster@1
|
511 } |
webmaster@1
|
512 node_save($node); |
webmaster@1
|
513 return TRUE; |
webmaster@1
|
514 } |
webmaster@1
|
515 |
webmaster@1
|
516 /** |
webmaster@1
|
517 * Blogging API callback. Sends a list of available input formats. |
webmaster@1
|
518 */ |
webmaster@1
|
519 function blogapi_mt_supported_text_filters() { |
webmaster@1
|
520 // NOTE: we're only using anonymous' formats because the MT spec |
webmaster@1
|
521 // does not allow for per-user formats. |
webmaster@1
|
522 $formats = filter_formats(); |
webmaster@1
|
523 |
webmaster@1
|
524 $filters = array(); |
webmaster@1
|
525 foreach ($formats as $format) { |
webmaster@1
|
526 $filter['key'] = $format->format; |
webmaster@1
|
527 $filter['label'] = $format->name; |
webmaster@1
|
528 $filters[] = $filter; |
webmaster@1
|
529 } |
webmaster@1
|
530 |
webmaster@1
|
531 return $filters; |
webmaster@1
|
532 } |
webmaster@1
|
533 |
webmaster@1
|
534 /** |
webmaster@1
|
535 * Blogging API callback. Publishes the given node |
webmaster@1
|
536 */ |
webmaster@9
|
537 function blogapi_mt_publish_post($postid, $username, $password) { |
webmaster@1
|
538 $user = blogapi_validate_user($username, $password); |
webmaster@1
|
539 if (!$user->uid) { |
webmaster@1
|
540 return blogapi_error($user); |
webmaster@1
|
541 } |
webmaster@1
|
542 $node = node_load($postid); |
webmaster@1
|
543 if (!$node) { |
webmaster@1
|
544 return blogapi_error(t('Invalid post.')); |
webmaster@1
|
545 } |
webmaster@1
|
546 |
webmaster@1
|
547 $node->status = 1; |
webmaster@1
|
548 if (!node_access('update', $node)) { |
webmaster@1
|
549 return blogapi_error(t('You do not have permission to update this post.')); |
webmaster@1
|
550 } |
webmaster@1
|
551 |
webmaster@1
|
552 node_save($node); |
webmaster@1
|
553 |
webmaster@1
|
554 return TRUE; |
webmaster@1
|
555 } |
webmaster@1
|
556 |
webmaster@1
|
557 /** |
webmaster@1
|
558 * Prepare an error message for returning to the XMLRPC caller. |
webmaster@1
|
559 */ |
webmaster@1
|
560 function blogapi_error($message) { |
webmaster@1
|
561 static $xmlrpcusererr; |
webmaster@1
|
562 if (!is_array($message)) { |
webmaster@1
|
563 $message = array($message); |
webmaster@1
|
564 } |
webmaster@1
|
565 |
webmaster@1
|
566 $message = implode(' ', $message); |
webmaster@1
|
567 |
webmaster@1
|
568 return xmlrpc_error($xmlrpcusererr + 1, strip_tags($message)); |
webmaster@1
|
569 } |
webmaster@1
|
570 |
webmaster@1
|
571 /** |
webmaster@1
|
572 * Ensure that the given user has permission to edit a blog. |
webmaster@1
|
573 */ |
webmaster@1
|
574 function blogapi_validate_user($username, $password) { |
webmaster@1
|
575 global $user; |
webmaster@1
|
576 |
webmaster@1
|
577 $user = user_authenticate(array('name' => $username, 'pass' => $password)); |
webmaster@1
|
578 |
webmaster@1
|
579 if ($user->uid) { |
webmaster@1
|
580 if (user_access('administer content with blog api', $user)) { |
webmaster@1
|
581 return $user; |
webmaster@1
|
582 } |
webmaster@1
|
583 else { |
webmaster@1
|
584 return t('You do not have permission to edit this blog.'); |
webmaster@1
|
585 } |
webmaster@1
|
586 } |
webmaster@1
|
587 else { |
webmaster@1
|
588 return t('Wrong username or password.'); |
webmaster@1
|
589 } |
webmaster@1
|
590 } |
webmaster@1
|
591 |
webmaster@1
|
592 /** |
webmaster@1
|
593 * For the blogger API, extract the node title from the contents field. |
webmaster@1
|
594 */ |
webmaster@1
|
595 function blogapi_blogger_title(&$contents) { |
webmaster@1
|
596 if (eregi('<title>([^<]*)</title>', $contents, $title)) { |
webmaster@1
|
597 $title = strip_tags($title[0]); |
webmaster@1
|
598 $contents = ereg_replace('<title>[^<]*</title>', '', $contents); |
webmaster@1
|
599 } |
webmaster@1
|
600 else { |
webmaster@1
|
601 list($title, $contents) = explode("\n", $contents, 2); |
webmaster@1
|
602 } |
webmaster@1
|
603 return $title; |
webmaster@1
|
604 } |
webmaster@1
|
605 |
webmaster@1
|
606 function blogapi_admin_settings() { |
webmaster@1
|
607 $node_types = array_map('check_plain', node_get_types('names')); |
webmaster@1
|
608 $defaults = isset($node_types['blog']) ? array('blog' => 1) : array(); |
webmaster@1
|
609 $form['blogapi_node_types'] = array( |
webmaster@1
|
610 '#type' => 'checkboxes', |
webmaster@1
|
611 '#title' => t('Enable for external blogging clients'), |
webmaster@1
|
612 '#required' => TRUE, |
webmaster@1
|
613 '#default_value' => variable_get('blogapi_node_types', $defaults), |
webmaster@1
|
614 '#options' => $node_types, |
webmaster@1
|
615 '#description' => t('Select the content types available to external blogging clients via Blog API. If supported, each enabled content type will be displayed as a separate "blog" by the external client.') |
webmaster@1
|
616 ); |
webmaster@1
|
617 |
webmaster@9
|
618 $blogapi_extensions_default = variable_get('blogapi_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'); |
webmaster@9
|
619 $blogapi_uploadsize_default = variable_get('blogapi_uploadsize_default', 1); |
webmaster@9
|
620 $blogapi_usersize_default = variable_get('blogapi_usersize_default', 1); |
webmaster@9
|
621 |
webmaster@9
|
622 $form['settings_general'] = array( |
webmaster@9
|
623 '#type' => 'fieldset', |
webmaster@9
|
624 '#title' => t('File settings'), |
webmaster@9
|
625 '#collapsible' => TRUE, |
webmaster@9
|
626 ); |
webmaster@9
|
627 |
webmaster@9
|
628 $form['settings_general']['blogapi_extensions_default'] = array( |
webmaster@9
|
629 '#type' => 'textfield', |
webmaster@9
|
630 '#title' => t('Default permitted file extensions'), |
webmaster@9
|
631 '#default_value' => $blogapi_extensions_default, |
webmaster@9
|
632 '#maxlength' => 255, |
webmaster@9
|
633 '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'), |
webmaster@9
|
634 ); |
webmaster@9
|
635 |
webmaster@9
|
636 $form['settings_general']['blogapi_uploadsize_default'] = array( |
webmaster@9
|
637 '#type' => 'textfield', |
webmaster@9
|
638 '#title' => t('Default maximum file size per upload'), |
webmaster@9
|
639 '#default_value' => $blogapi_uploadsize_default, |
webmaster@9
|
640 '#size' => 5, |
webmaster@9
|
641 '#maxlength' => 5, |
webmaster@9
|
642 '#description' => t('The default maximum file size a user can upload.'), |
webmaster@9
|
643 '#field_suffix' => t('MB') |
webmaster@9
|
644 ); |
webmaster@9
|
645 |
webmaster@9
|
646 $form['settings_general']['blogapi_usersize_default'] = array( |
webmaster@9
|
647 '#type' => 'textfield', |
webmaster@9
|
648 '#title' => t('Default total file size per user'), |
webmaster@9
|
649 '#default_value' => $blogapi_usersize_default, |
webmaster@9
|
650 '#size' => 5, |
webmaster@9
|
651 '#maxlength' => 5, |
webmaster@9
|
652 '#description' => t('The default maximum size of all files a user can have on the site.'), |
webmaster@9
|
653 '#field_suffix' => t('MB') |
webmaster@9
|
654 ); |
webmaster@9
|
655 |
webmaster@9
|
656 $form['settings_general']['upload_max_size'] = array('#value' => '<p>'. t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))).'</p>'); |
webmaster@9
|
657 |
webmaster@9
|
658 $roles = user_roles(0, 'administer content with blog api'); |
webmaster@9
|
659 $form['roles'] = array('#type' => 'value', '#value' => $roles); |
webmaster@9
|
660 |
webmaster@9
|
661 foreach ($roles as $rid => $role) { |
webmaster@9
|
662 $form['settings_role_'. $rid] = array( |
webmaster@9
|
663 '#type' => 'fieldset', |
webmaster@9
|
664 '#title' => t('Settings for @role', array('@role' => $role)), |
webmaster@9
|
665 '#collapsible' => TRUE, |
webmaster@9
|
666 '#collapsed' => TRUE, |
webmaster@9
|
667 ); |
webmaster@9
|
668 $form['settings_role_'. $rid]['blogapi_extensions_'. $rid] = array( |
webmaster@9
|
669 '#type' => 'textfield', |
webmaster@9
|
670 '#title' => t('Permitted file extensions'), |
webmaster@9
|
671 '#default_value' => variable_get('blogapi_extensions_'. $rid, $blogapi_extensions_default), |
webmaster@9
|
672 '#maxlength' => 255, |
webmaster@9
|
673 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'), |
webmaster@9
|
674 ); |
webmaster@9
|
675 $form['settings_role_'. $rid]['blogapi_uploadsize_'. $rid] = array( |
webmaster@9
|
676 '#type' => 'textfield', |
webmaster@9
|
677 '#title' => t('Maximum file size per upload'), |
webmaster@9
|
678 '#default_value' => variable_get('blogapi_uploadsize_'. $rid, $blogapi_uploadsize_default), |
webmaster@9
|
679 '#size' => 5, |
webmaster@9
|
680 '#maxlength' => 5, |
webmaster@9
|
681 '#description' => t('The maximum size of a file a user can upload (in megabytes).'), |
webmaster@9
|
682 ); |
webmaster@9
|
683 $form['settings_role_'. $rid]['blogapi_usersize_'. $rid] = array( |
webmaster@9
|
684 '#type' => 'textfield', |
webmaster@9
|
685 '#title' => t('Total file size per user'), |
webmaster@9
|
686 '#default_value' => variable_get('blogapi_usersize_'. $rid, $blogapi_usersize_default), |
webmaster@9
|
687 '#size' => 5, |
webmaster@9
|
688 '#maxlength' => 5, |
webmaster@9
|
689 '#description' => t('The maximum size of all files a user can have on the site (in megabytes).'), |
webmaster@9
|
690 ); |
webmaster@9
|
691 } |
webmaster@9
|
692 |
webmaster@1
|
693 return system_settings_form($form); |
webmaster@1
|
694 } |
webmaster@1
|
695 |
webmaster@1
|
696 function blogapi_menu() { |
webmaster@1
|
697 $items['blogapi/rsd'] = array( |
webmaster@1
|
698 'title' => 'RSD', |
webmaster@1
|
699 'page callback' => 'blogapi_rsd', |
webmaster@1
|
700 'access arguments' => array('access content'), |
webmaster@1
|
701 'type' => MENU_CALLBACK, |
webmaster@1
|
702 ); |
webmaster@1
|
703 $items['admin/settings/blogapi'] = array( |
webmaster@1
|
704 'title' => 'Blog API', |
webmaster@1
|
705 'description' => 'Configure the content types available to external blogging clients.', |
webmaster@1
|
706 'page callback' => 'drupal_get_form', |
webmaster@1
|
707 'page arguments' => array('blogapi_admin_settings'), |
webmaster@1
|
708 'access arguments' => array('administer site configuration'), |
webmaster@1
|
709 'type' => MENU_NORMAL_ITEM, |
webmaster@1
|
710 ); |
webmaster@1
|
711 |
webmaster@1
|
712 return $items; |
webmaster@1
|
713 } |
webmaster@1
|
714 |
webmaster@1
|
715 function blogapi_init() { |
webmaster@1
|
716 if (drupal_is_front_page()) { |
webmaster@1
|
717 drupal_add_link(array('rel' => 'EditURI', |
webmaster@1
|
718 'type' => 'application/rsd+xml', |
webmaster@1
|
719 'title' => t('RSD'), |
webmaster@1
|
720 'href' => url('blogapi/rsd', array('absolute' => TRUE)))); |
webmaster@1
|
721 } |
webmaster@1
|
722 } |
webmaster@1
|
723 |
webmaster@1
|
724 function blogapi_rsd() { |
webmaster@1
|
725 global $base_url; |
webmaster@1
|
726 |
webmaster@1
|
727 $xmlrpc = $base_url .'/xmlrpc.php'; |
webmaster@1
|
728 $base = url('', array('absolute' => TRUE)); |
webmaster@1
|
729 $blogid = 1; # until we figure out how to handle multiple bloggers |
webmaster@1
|
730 |
webmaster@1
|
731 drupal_set_header('Content-Type: application/rsd+xml; charset=utf-8'); |
webmaster@1
|
732 print <<<__RSD__ |
webmaster@1
|
733 <?xml version="1.0"?> |
webmaster@1
|
734 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> |
webmaster@1
|
735 <service> |
webmaster@1
|
736 <engineName>Drupal</engineName> |
webmaster@1
|
737 <engineLink>http://drupal.org/</engineLink> |
webmaster@1
|
738 <homePageLink>$base</homePageLink> |
webmaster@1
|
739 <apis> |
webmaster@1
|
740 <api name="MetaWeblog" preferred="false" apiLink="$xmlrpc" blogID="$blogid" /> |
webmaster@1
|
741 <api name="Blogger" preferred="false" apiLink="$xmlrpc" blogID="$blogid" /> |
webmaster@1
|
742 <api name="MovableType" preferred="true" apiLink="$xmlrpc" blogID="$blogid" /> |
webmaster@1
|
743 </apis> |
webmaster@1
|
744 </service> |
webmaster@1
|
745 </rsd> |
webmaster@1
|
746 __RSD__; |
webmaster@1
|
747 } |
webmaster@1
|
748 |
webmaster@1
|
749 /** |
webmaster@1
|
750 * Handles extra information sent by clients according to MovableType's spec. |
webmaster@1
|
751 */ |
webmaster@1
|
752 function _blogapi_mt_extra(&$node, $struct) { |
webmaster@1
|
753 if (is_array($node)) { |
webmaster@1
|
754 $was_array = TRUE; |
webmaster@1
|
755 $node = (object)$node; |
webmaster@1
|
756 } |
webmaster@1
|
757 |
webmaster@1
|
758 // mt_allow_comments |
webmaster@1
|
759 if (array_key_exists('mt_allow_comments', $struct)) { |
webmaster@1
|
760 switch ($struct['mt_allow_comments']) { |
webmaster@1
|
761 case 0: |
webmaster@1
|
762 $node->comment = COMMENT_NODE_DISABLED; |
webmaster@1
|
763 break; |
webmaster@1
|
764 case 1: |
webmaster@1
|
765 $node->comment = COMMENT_NODE_READ_WRITE; |
webmaster@1
|
766 break; |
webmaster@1
|
767 case 2: |
webmaster@1
|
768 $node->comment = COMMENT_NODE_READ_ONLY; |
webmaster@1
|
769 break; |
webmaster@1
|
770 } |
webmaster@1
|
771 } |
webmaster@1
|
772 |
webmaster@1
|
773 // merge the 3 body sections (description, mt_excerpt, mt_text_more) into |
webmaster@1
|
774 // one body |
webmaster@1
|
775 if ($struct['mt_excerpt']) { |
webmaster@1
|
776 $node->body = $struct['mt_excerpt'] .'<!--break-->'. $node->body; |
webmaster@1
|
777 } |
webmaster@1
|
778 if ($struct['mt_text_more']) { |
webmaster@1
|
779 $node->body = $node->body .'<!--extended-->'. $struct['mt_text_more']; |
webmaster@1
|
780 } |
webmaster@1
|
781 |
webmaster@1
|
782 // mt_convert_breaks |
webmaster@1
|
783 if ($struct['mt_convert_breaks']) { |
webmaster@1
|
784 $node->format = $struct['mt_convert_breaks']; |
webmaster@1
|
785 } |
webmaster@1
|
786 |
webmaster@1
|
787 // dateCreated |
webmaster@1
|
788 if ($struct['dateCreated']) { |
webmaster@1
|
789 $node->date = format_date(mktime($struct['dateCreated']->hour, $struct['dateCreated']->minute, $struct['dateCreated']->second, $struct['dateCreated']->month, $struct['dateCreated']->day, $struct['dateCreated']->year), 'custom', 'Y-m-d H:i:s O'); |
webmaster@1
|
790 } |
webmaster@1
|
791 |
webmaster@1
|
792 if ($was_array) { |
webmaster@1
|
793 $node = (array)$node; |
webmaster@1
|
794 } |
webmaster@1
|
795 } |
webmaster@1
|
796 |
webmaster@1
|
797 function _blogapi_get_post($node, $bodies = TRUE) { |
webmaster@1
|
798 $xmlrpcval = array( |
webmaster@1
|
799 'userid' => $node->name, |
webmaster@1
|
800 'dateCreated' => xmlrpc_date($node->created), |
webmaster@1
|
801 'title' => $node->title, |
webmaster@1
|
802 'postid' => $node->nid, |
webmaster@1
|
803 'link' => url('node/'. $node->nid, array('absolute' => TRUE)), |
webmaster@1
|
804 'permaLink' => url('node/'. $node->nid, array('absolute' => TRUE)), |
webmaster@1
|
805 ); |
webmaster@1
|
806 if ($bodies) { |
webmaster@1
|
807 if ($node->comment == 1) { |
webmaster@1
|
808 $comment = 2; |
webmaster@1
|
809 } |
webmaster@1
|
810 else if ($node->comment == 2) { |
webmaster@1
|
811 $comment = 1; |
webmaster@1
|
812 } |
webmaster@1
|
813 $xmlrpcval['content'] = "<title>$node->title</title>$node->body"; |
webmaster@1
|
814 $xmlrpcval['description'] = $node->body; |
webmaster@1
|
815 // Add MT specific fields |
webmaster@1
|
816 $xmlrpcval['mt_allow_comments'] = (int) $comment; |
webmaster@1
|
817 $xmlrpcval['mt_convert_breaks'] = $node->format; |
webmaster@1
|
818 } |
webmaster@1
|
819 |
webmaster@1
|
820 return $xmlrpcval; |
webmaster@1
|
821 } |
webmaster@1
|
822 |
webmaster@1
|
823 /** |
webmaster@1
|
824 * Validate blog ID, which maps to a content type in Drupal. |
webmaster@1
|
825 * |
webmaster@1
|
826 * Only content types configured to work with Blog API are supported. |
webmaster@1
|
827 * |
webmaster@1
|
828 * @return |
webmaster@1
|
829 * TRUE if the content type is supported and the user has permission |
webmaster@1
|
830 * to post, or a blogapi_error() XML construct otherwise. |
webmaster@1
|
831 */ |
webmaster@1
|
832 function _blogapi_validate_blogid($blogid) { |
webmaster@1
|
833 $types = _blogapi_get_node_types(); |
webmaster@1
|
834 if (in_array($blogid, $types, TRUE)) { |
webmaster@1
|
835 return TRUE; |
webmaster@1
|
836 } |
webmaster@1
|
837 return blogapi_error(t("Blog API module is not configured to support the %type content type, or you don't have sufficient permissions to post this type of content.", array('%type' => $blogid))); |
webmaster@1
|
838 } |
webmaster@1
|
839 |
webmaster@1
|
840 function _blogapi_get_node_types() { |
webmaster@1
|
841 $available_types = array_keys(array_filter(variable_get('blogapi_node_types', array('blog' => 1)))); |
webmaster@1
|
842 $types = array(); |
webmaster@1
|
843 foreach (node_get_types() as $type => $name) { |
webmaster@1
|
844 if (node_access('create', $type) && in_array($type, $available_types)) { |
webmaster@1
|
845 $types[] = $type; |
webmaster@1
|
846 } |
webmaster@1
|
847 } |
webmaster@1
|
848 |
webmaster@1
|
849 return $types; |
webmaster@1
|
850 } |
webmaster@9
|
851 |
webmaster@9
|
852 function _blogapi_space_used($uid) { |
webmaster@9
|
853 return db_result(db_query('SELECT SUM(filesize) FROM {blogapi_files} f WHERE f.uid = %d', $uid)); |
webmaster@9
|
854 } |