[ Index ] |
|
Code source de Drupal 5.3 |
1 <?php 2 // $Id: blogapi.module,v 1.100.2.2 2007/07/26 19:16:45 drumm Exp $ 3 4 /** 5 * @file 6 * Enable users to post using applications that support XML-RPC blog APIs. 7 */ 8 9 /** 10 * Implementation of hook_help(). 11 */ 12 function blogapi_help($section) { 13 switch ($section) { 14 case 'admin/help#blogapi': 15 $output = '<p>'. t('The blog API module enables a post to be posted to a site via external GUI applications. Many users prefer to use external tools to improve their ability to read and post responses in a customized way. The blog api provides users the freedom to use the blogging tools they want but still have the blogging server of choice.') .'</p>'; 16 $output .= '<p>'. t('When this module is enabled and configured you can use programs like <a href="@external-http-ecto-kung-foo-tv">Ecto</a> to create and publish posts from your desktop. Blog API module supports several XML-RPC based blogging APIs such as the <a href="@-">Blogger API</a>, <a href="@external-http-www-xmlrpc-com-metaWeblogApi">MetaWeblog API</a>, and most of the <a href="@external-http-www-movabletype-org-docs-mtmanual_programmatic-html">Movable Type API</a>. Any desktop blogging tools or other services (e.g. <a href="@external-http-www-flickr-com">Flickr\'s</a> "post to blog") that support these APIs should work with this site.', array('@external-http-ecto-kung-foo-tv' => 'http://ecto.kung-foo.tv/', '@-' => url('http://www.blogger.com/developers/api/1_docs/'), '@external-http-www-xmlrpc-com-metaWeblogApi' => 'http://www.xmlrpc.com/metaWeblogApi', '@external-http-www-movabletype-org-docs-mtmanual_programmatic-html' => 'http://www.movabletype.org/docs/mtmanual_programmatic.html', '@external-http-www-flickr-com' => 'http://www.flickr.com')) .'</p>'; 17 $output .= '<p>'. t('This module also allows site administrators to configure which content types can be posted via the external applications. So, for instance, users can post forum topics as well as blog posts. Where supported, the external applications will display each content type as a separate "blog".') .'</p>'; 18 $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@blogapi">BlogApi page</a>.', array('@blogapi' => 'http://drupal.org/handbook/modules/blogapi/')) .'</p>'; 19 return $output; 20 } 21 } 22 23 /** 24 * Implementation of hook_xmlrpc(). 25 */ 26 function blogapi_xmlrpc() { 27 return array( 28 array( 29 'blogger.getUsersBlogs', 30 'blogapi_blogger_get_users_blogs', 31 array('array', 'string', 'string', 'string'), 32 t('Returns a list of weblogs to which an author has posting privileges.')), 33 array( 34 'blogger.getUserInfo', 35 'blogapi_blogger_get_user_info', 36 array('struct', 'string', 'string', 'string'), 37 t('Returns information about an author in the system.')), 38 array( 39 'blogger.newPost', 40 'blogapi_blogger_new_post', 41 array('string', 'string', 'string', 'string', 'string', 'string', 'boolean'), 42 t('Creates a new post, and optionally publishes it.')), 43 array( 44 'blogger.editPost', 45 'blogapi_blogger_edit_post', 46 array('boolean', 'string', 'string', 'string', 'string', 'string', 'boolean'), 47 t('Updates the information about an existing post.')), 48 array( 49 'blogger.getPost', 50 'blogapi_blogger_get_post', 51 array('struct', 'string', 'string', 'string', 'string'), 52 t('Returns information about a specific post.')), 53 array( 54 'blogger.deletePost', 55 'blogapi_blogger_delete_post', 56 array('boolean', 'string', 'string', 'string', 'string', 'boolean'), 57 t('Deletes a post.')), 58 array( 59 'blogger.getRecentPosts', 60 'blogapi_blogger_get_recent_posts', 61 array('array', 'string', 'string', 'string', 'string', 'int'), 62 t('Returns a list of the most recent posts in the system.')), 63 array( 64 'metaWeblog.newPost', 65 'blogapi_metaweblog_new_post', 66 array('string', 'string', 'string', 'string', 'struct', 'boolean'), 67 t('Creates a new post, and optionally publishes it.')), 68 array( 69 'metaWeblog.editPost', 70 'blogapi_metaweblog_edit_post', 71 array('boolean', 'string', 'string', 'string', 'struct', 'boolean'), 72 t('Updates information about an existing post.')), 73 array( 74 'metaWeblog.getPost', 75 'blogapi_metaweblog_get_post', 76 array('struct', 'string', 'string', 'string'), 77 t('Returns information about a specific post.')), 78 array( 79 'metaWeblog.newMediaObject', 80 'blogapi_metaweblog_new_media_object', 81 array('string', 'string', 'string', 'string', 'struct'), 82 t('Uploads a file to your webserver.')), 83 array( 84 'metaWeblog.getCategories', 85 'blogapi_metaweblog_get_category_list', 86 array('struct', 'string', 'string', 'string'), 87 t('Returns a list of all categories to which the post is assigned.')), 88 array( 89 'metaWeblog.getRecentPosts', 90 'blogapi_metaweblog_get_recent_posts', 91 array('array', 'string', 'string', 'string', 'int'), 92 t('Returns a list of the most recent posts in the system.')), 93 array( 94 'mt.getRecentPostTitles', 95 'blogapi_mt_get_recent_post_titles', 96 array('array', 'string', 'string', 'string', 'int'), 97 t('Returns a bandwidth-friendly list of the most recent posts in the system.')), 98 array( 99 'mt.getCategoryList', 100 'blogapi_mt_get_category_list', 101 array('array', 'string', 'string', 'string'), 102 t('Returns a list of all categories defined in the weblog.')), 103 array( 104 'mt.getPostCategories', 105 'blogapi_mt_get_post_categories', 106 array('array', 'string', 'string', 'string'), 107 t('Returns a list of all categories to which the post is assigned.')), 108 array( 109 'mt.setPostCategories', 110 'blogapi_mt_set_post_categories', 111 array('boolean', 'string', 'string', 'string', 'array'), 112 t('Sets the categories for a post.')), 113 array( 114 'mt.supportedMethods', 115 'xmlrpc_server_list_methods', 116 array('array'), 117 t('Retrieve information about the XML-RPC methods supported by the server.')), 118 array( 119 'mt.supportedTextFilters', 120 'blogapi_mt_supported_text_filters', 121 array('array'), 122 t('Retrieve information about the text formatting plugins supported by the server.')), 123 array( 124 'mt.publishPost', 125 'blogap_mti_publish_post', 126 array('boolean', 'string', 'string', 'string'), 127 t('Publish (rebuild) all of the static files related to an entry from your weblog. Equivalent to saving an entry in the system (but without the ping).'))); 128 } 129 130 /** 131 * Blogging API callback. Finds the URL of a user's blog. 132 */ 133 134 function blogapi_blogger_get_users_blogs($appid, $username, $password) { 135 136 $user = blogapi_validate_user($username, $password); 137 if ($user->uid) { 138 $types = _blogapi_get_node_types(); 139 $structs = array(); 140 foreach ($types as $type) { 141 $structs[] = array('url' => url('blog/'. $user->uid, NULL, NULL, TRUE), 'blogid' => $type, 'blogName' => $user->name .": ". $type); 142 } 143 return $structs; 144 } 145 else { 146 return blogapi_error($user); 147 } 148 } 149 150 /** 151 * Blogging API callback. Returns profile information about a user. 152 */ 153 function blogapi_blogger_get_user_info($appkey, $username, $password) { 154 $user = blogapi_validate_user($username, $password); 155 156 if ($user->uid) { 157 $name = explode(' ', $user->realname ? $user->realname : $user->name, 2); 158 return array( 159 'userid' => $user->uid, 160 'lastname' => $name[1], 161 'firstname' => $name[0], 162 'nickname' => $user->name, 163 'email' => $user->mail, 164 'url' => url('blog/'. $user->uid, NULL, NULL, TRUE)); 165 } 166 else { 167 return blogapi_error($user); 168 } 169 } 170 171 /** 172 * Blogging API callback. Inserts a new blog post as a node. 173 */ 174 function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish) { 175 $user = blogapi_validate_user($username, $password); 176 if (!$user->uid) { 177 return blogapi_error($user); 178 } 179 180 $edit = array(); 181 $edit['type'] = _blogapi_blogid($blogid); 182 // get the node type defaults 183 $node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote')); 184 $edit['uid'] = $user->uid; 185 $edit['name'] = $user->name; 186 $edit['promote'] = in_array('promote', $node_type_default); 187 $edit['comment'] = variable_get('comment_'. $edit['type'], 2); 188 $edit['revision'] = in_array('revision', $node_type_default); 189 $edit['format'] = FILTER_FORMAT_DEFAULT; 190 $edit['status'] = $publish; 191 192 // check for bloggerAPI vs. metaWeblogAPI 193 if (is_array($content)) { 194 $edit['title'] = $content['title']; 195 $edit['body'] = $content['description']; 196 _blogapi_mt_extra($edit, $content); 197 } 198 else { 199 $edit['title'] = blogapi_blogger_title($content); 200 $edit['body'] = $content; 201 } 202 203 if (!node_access('create', $edit['type'])) { 204 return blogapi_error(t('You do not have permission to create the type of post you wanted to create.')); 205 } 206 207 if (user_access('administer nodes') && !isset($edit['date'])) { 208 $edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O'); 209 } 210 211 node_invoke_nodeapi($edit, 'blogapi new'); 212 213 node_validate($edit); 214 if ($errors = form_get_errors()) { 215 return blogapi_error(implode("\n", $errors)); 216 } 217 218 $node = node_submit($edit); 219 node_save($node); 220 if ($node->nid) { 221 watchdog('content', t('@type: added %title using blog API.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); 222 // blogger.newPost returns a string so we cast the nid to a string by putting it in double quotes: 223 return "$node->nid"; 224 } 225 226 return blogapi_error(t('Error storing post.')); 227 } 228 229 /** 230 * Blogging API callback. Modifies the specified blog node. 231 */ 232 function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $content, $publish) { 233 234 $user = blogapi_validate_user($username, $password); 235 236 if (!$user->uid) { 237 return blogapi_error($user); 238 } 239 240 $node = node_load($postid); 241 if (!$node) { 242 return blogapi_error(t('n/a')); 243 } 244 // Let the teaser be re-generated. 245 unset($node->teaser); 246 247 if (!node_access('update', $node)) { 248 return blogapi_error(t('You do not have permission to update this post.')); 249 } 250 251 $node->status = $publish; 252 253 // check for bloggerAPI vs. metaWeblogAPI 254 if (is_array($content)) { 255 $node->title = $content['title']; 256 $node->body = $content['description']; 257 _blogapi_mt_extra($node, $content); 258 } 259 else { 260 $node->title = blogapi_blogger_title($content); 261 $node->body = $content; 262 } 263 264 node_invoke_nodeapi($node, 'blogapi edit'); 265 266 node_validate($node); 267 if ($errors = form_get_errors()) { 268 return blogapi_error(implode("\n", $errors)); 269 } 270 271 if (user_access('administer nodes') && !isset($edit['date'])) { 272 $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); 273 } 274 $node = node_submit($node); 275 node_save($node); 276 if ($node->nid) { 277 watchdog('content', t('@type: updated %title using blog API.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); 278 return TRUE; 279 } 280 281 return blogapi_error(t('Error storing post.')); 282 } 283 284 /** 285 * Blogging API callback. Returns a specified blog node. 286 */ 287 function blogapi_blogger_get_post($appkey, $postid, $username, $password) { 288 $user = blogapi_validate_user($username, $password); 289 if (!$user->uid) { 290 return blogapi_error($user); 291 } 292 293 $node = node_load($postid); 294 295 return _blogapi_get_post($node, TRUE); 296 } 297 298 /** 299 * Blogging API callback. Removes the specified blog node. 300 */ 301 function blogapi_blogger_delete_post($appkey, $postid, $username, $password, $publish) { 302 $user = blogapi_validate_user($username, $password); 303 if (!$user->uid) { 304 return blogapi_error($user); 305 } 306 307 node_delete($postid); 308 return TRUE; 309 } 310 311 /** 312 * Blogging API callback. Returns the latest few postings in a user's blog. $bodies TRUE 313 * <a href="http://movabletype.org/docs/mtmanual_programmatic.html#item_mt%2EgetRecentPostTitles"> 314 * returns a bandwidth-friendly list</a>. 315 */ 316 function blogapi_blogger_get_recent_posts($appkey, $blogid, $username, $password, $number_of_posts, $bodies = TRUE) { 317 // Remove unused appkey (from bloggerAPI). 318 $user = blogapi_validate_user($username, $password); 319 if (!$user->uid) { 320 return blogapi_error($user); 321 } 322 323 $type = _blogapi_blogid($blogid); 324 if ($bodies) { 325 $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", $type, $user->uid, 0, $number_of_posts); 326 } 327 else { 328 $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", $type, $user->uid, 0, $number_of_posts); 329 } 330 $blogs = array(); 331 while ($blog = db_fetch_object($result)) { 332 $blogs[] = _blogapi_get_post($blog, $bodies); 333 } 334 return $blogs; 335 } 336 337 function blogapi_metaweblog_new_post($blogid, $username, $password, $content, $publish) { 338 return blogapi_blogger_new_post('0123456789ABCDEF', $blogid, $username, $password, $content, $publish); 339 } 340 341 function blogapi_metaweblog_edit_post($postid, $username, $password, $content, $publish) { 342 return blogapi_blogger_edit_post('0123456789ABCDEF', $postid, $username, $password, $content, $publish); 343 } 344 345 function blogapi_metaweblog_get_post($postid, $username, $password) { 346 return blogapi_blogger_get_post('01234567890ABCDEF', $postid, $username, $password); 347 } 348 349 /** 350 * Blogging API callback. Inserts a file into Drupal. 351 */ 352 function blogapi_metaweblog_new_media_object($blogid, $username, $password, $file) { 353 $user = blogapi_validate_user($username, $password); 354 if (!$user->uid) { 355 return blogapi_error($user); 356 } 357 358 $name = basename($file['name']); 359 $data = $file['bits']; 360 361 if (!$data) { 362 return blogapi_error(t('No file sent.')); 363 } 364 365 if (!$file = file_save_data($data, $name)) { 366 return blogapi_error(t('Error storing file.')); 367 } 368 369 // Return the successful result. 370 return array('url' => file_create_url($file), 'struct'); 371 } 372 /** 373 * Blogging API callback. Returns a list of the taxonomy terms that can be 374 * associated with a blog node. 375 */ 376 function blogapi_metaweblog_get_category_list($blogid, $username, $password) { 377 $type = _blogapi_blogid($blogid); 378 $vocabularies = module_invoke('taxonomy', 'get_vocabularies', $type, 'vid'); 379 $categories = array(); 380 if ($vocabularies) { 381 foreach ($vocabularies as $vocabulary) { 382 $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, -1); 383 foreach ($terms as $term) { 384 $term_name = $term->name; 385 foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) { 386 $term_name = $parent->name .'/'. $term_name; 387 } 388 $categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid); 389 } 390 } 391 } 392 return $categories; 393 } 394 395 function blogapi_metaweblog_get_recent_posts($blogid, $username, $password, $number_of_posts) { 396 return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, TRUE); 397 } 398 399 // see above 400 function blogapi_mt_get_recent_post_titles($blogid, $username, $password, $number_of_posts) { 401 return blogapi_blogger_get_recent_posts('0123456789ABCDEF', $blogid, $username, $password, $number_of_posts, FALSE); 402 } 403 404 /* **** */ 405 function blogapi_mt_get_category_list($blogid, $username, $password) { 406 return blogapi_metaweblog_get_category_list($blogid, $username, $password); 407 } 408 409 /** 410 * Blogging API callback. Returns a list of the taxonomy terms that are 411 * assigned to a particular node. 412 */ 413 function blogapi_mt_get_post_categories($postid, $username, $password) { 414 $user = blogapi_validate_user($username, $password); 415 if (!$user->uid) { 416 return blogapi_error($user); 417 } 418 419 $terms = module_invoke('taxonomy', 'node_get_terms', $postid, 'tid'); 420 $categories = array(); 421 foreach ($terms as $term) { 422 $term_name = $term->name; 423 foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) { 424 $term_name = $parent->name .'/'. $term_name; 425 } 426 $categories[] = array('categoryName' => $term_name, 'categoryId' => $term->tid, 'isPrimary' => TRUE); 427 } 428 return $categories; 429 } 430 431 /** 432 * Blogging API callback. Assigns taxonomy terms to a particular node. 433 */ 434 function blogapi_mt_set_post_categories($postid, $username, $password, $categories) { 435 $user = blogapi_validate_user($username, $password); 436 if (!$user->uid) { 437 return blogapi_error($user); 438 } 439 440 $node = node_load($postid); 441 $node->taxonomy = array(); 442 foreach ($categories as $category) { 443 $node->taxonomy[] = $category['categoryId']; 444 } 445 node_save($node); 446 return TRUE; 447 } 448 449 /** 450 * Blogging API callback. Sends a list of available input formats. 451 */ 452 function blogapi_mt_supported_text_filters() { 453 // NOTE: we're only using anonymous' formats because the MT spec 454 // does not allow for per-user formats. 455 $formats = filter_formats(); 456 457 $filters = array(); 458 foreach ($formats as $format) { 459 $filter['key'] = $format->format; 460 $filter['label'] = $format->name; 461 $filters[] = $filter; 462 } 463 464 return $filters; 465 } 466 467 /** 468 * Blogging API callback. Publishes the given node 469 */ 470 function blogap_mti_publish_post($postid, $username, $password) { 471 $user = blogapi_validate_user($username, $password); 472 if (!$user->uid) { 473 return blogapi_error($user); 474 } 475 $node = node_load($postid); 476 if (!$node) { 477 return blogapi_error(t('Invalid post.')); 478 } 479 480 $node->status = 1; 481 if (!node_access('update', $node)) { 482 return blogapi_error(t('You do not have permission to update this post.')); 483 } 484 485 node_save($node); 486 487 return TRUE; 488 } 489 490 /** 491 * Prepare an error message for returning to the XMLRPC caller. 492 */ 493 function blogapi_error($message) { 494 static $xmlrpcusererr; 495 if (!is_array($message)) { 496 $message = array($message); 497 } 498 499 $message = implode(' ', $message); 500 501 return xmlrpc_error($xmlrpcusererr + 1, strip_tags($message)); 502 } 503 504 /** 505 * Ensure that the given user has permission to edit a blog. 506 */ 507 function blogapi_validate_user($username, $password) { 508 global $user; 509 510 $user = user_authenticate($username, $password); 511 512 if ($user->uid) { 513 if (user_access('edit own blog', $user)) { 514 return $user; 515 } 516 else { 517 return t("You either tried to edit somebody else's blog or you don't have permission to edit your own blog."); 518 } 519 } 520 else { 521 return t('Wrong username or password.'); 522 } 523 } 524 525 /** 526 * For the blogger API, extract the node title from the contents field. 527 */ 528 function blogapi_blogger_title(&$contents) { 529 if (eregi('<title>([^<]*)</title>', $contents, $title)) { 530 $title = strip_tags($title[0]); 531 $contents = ereg_replace('<title>[^<]*</title>', '', $contents); 532 } 533 else { 534 list($title, $contents) = explode("\n", $contents, 2); 535 } 536 return $title; 537 } 538 539 function blogapi_admin_settings() { 540 $node_types = array_map('check_plain', node_get_types('names')); 541 $defaults = isset($node_types['blog']) ? array('blog' => 1) : array(); 542 $form['blogapi_node_types'] = array( 543 '#type' => 'checkboxes', 544 '#title' => t('Blog types'), 545 '#required' => TRUE, 546 '#default_value' => variable_get('blogapi_node_types', $defaults), 547 '#options' => $node_types, 548 '#description' => t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).') 549 ); 550 551 return system_settings_form($form); 552 } 553 554 function blogapi_menu($may_cache) { 555 $items = array(); 556 557 if (drupal_is_front_page()) { 558 drupal_add_link(array('rel' => 'EditURI', 559 'type' => 'application/rsd+xml', 560 'title' => t('RSD'), 561 'href' => url('blogapi/rsd', NULL, NULL, TRUE))); 562 } 563 564 if ($may_cache) { 565 $items[] = array( 566 'path' => 'blogapi', 567 'title' => t('RSD'), 568 'callback' => 'blogapi_blogapi', 569 'access' => user_access('access content'), 570 'type' => MENU_CALLBACK); 571 $items[] = array( 572 'path' => 'admin/settings/blogapi', 573 'title' => t('Blog APIs'), 574 'description' => t('Configure which content types and engines external blog clients can use.'), 575 'callback' => 'drupal_get_form', 576 'callback arguments' => array('blogapi_admin_settings'), 577 'access' => user_access('administer site configuration'), 578 'type' => MENU_NORMAL_ITEM 579 ); 580 } 581 582 return $items; 583 } 584 585 function blogapi_blogapi() { 586 switch (arg(1)) { 587 case 'rsd': 588 blogapi_rsd(); 589 break; 590 default: 591 drupal_not_found(); 592 break; 593 } 594 } 595 596 function blogapi_rsd() { 597 global $base_url; 598 599 $xmlrpc = $base_url .'/'. 'xmlrpc.php'; 600 $base = url('', NULL, NULL, TRUE); 601 $blogid = 1; # until we figure out how to handle multiple bloggers 602 603 drupal_set_header('Content-Type: application/rsd+xml; charset=utf-8'); 604 print <<<__RSD__ 605 <?xml version="1.0"?> 606 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> 607 <service> 608 <engineName>Drupal</engineName> 609 <engineLink>http://drupal.org/</engineLink> 610 <homePageLink>$base</homePageLink> 611 <apis> 612 <api name="MetaWeblog" preferred="false" apiLink="$xmlrpc" blogID="$blogid" /> 613 <api name="Blogger" preferred="false" apiLink="$xmlrpc" blogID="$blogid" /> 614 <api name="MovableType" preferred="true" apiLink="$xmlrpc" blogID="$blogid" /> 615 </apis> 616 </service> 617 </rsd> 618 __RSD__; 619 } 620 621 /** 622 * Handles extra information sent by clients according to MovableType's spec. 623 */ 624 function _blogapi_mt_extra(&$node, $struct) { 625 if (is_array($node)) { 626 $was_array = TRUE; 627 $node = (object)$node; 628 } 629 630 // mt_allow_comments 631 if (array_key_exists('mt_allow_comments', $struct)) { 632 switch ($struct['mt_allow_comments']) { 633 case 0: 634 $node->comment = COMMENT_NODE_DISABLED; 635 break; 636 case 1: 637 $node->comment = COMMENT_NODE_READ_WRITE; 638 break; 639 case 2: 640 $node->comment = COMMENT_NODE_READ_ONLY; 641 break; 642 } 643 } 644 645 // merge the 3 body sections (description, mt_excerpt, mt_text_more) into 646 // one body 647 if ($struct['mt_excerpt']) { 648 $node->body = $struct['mt_excerpt'] .'<!--break-->'.$node->body; 649 } 650 if ($struct['mt_text_more']) { 651 $node->body = $node->body .'<!--extended-->'. $struct['mt_text_more']; 652 } 653 654 // mt_convert_breaks 655 if ($struct['mt_convert_breaks']) { 656 $node->format = $struct['mt_convert_breaks']; 657 } 658 659 // dateCreated 660 if ($struct['dateCreated']) { 661 $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'); 662 } 663 664 if ($was_array) { 665 $node = (array)$node; 666 } 667 } 668 669 function _blogapi_get_post($node, $bodies = TRUE) { 670 $xmlrpcval = array( 671 'userid' => $node->name, 672 'dateCreated' => xmlrpc_date($node->created), 673 'title' => $node->title, 674 'postid' => $node->nid, 675 'link' => url('node/'.$node->nid, NULL, NULL, TRUE), 676 'permaLink' => url('node/'.$node->nid, NULL, NULL, TRUE), 677 ); 678 if ($bodies) { 679 if ($node->comment == 1) { 680 $comment = 2; 681 } 682 else if ($node->comment == 2) { 683 $comment = 1; 684 } 685 $xmlrpcval['content'] = "<title>$node->title</title>$node->body"; 686 $xmlrpcval['description'] = $node->body; 687 // Add MT specific fields 688 $xmlrpcval['mt_allow_comments'] = (int) $comment; 689 $xmlrpcval['mt_convert_breaks'] = $node->format; 690 } 691 692 return $xmlrpcval; 693 } 694 695 function _blogapi_blogid($id) { 696 if (is_numeric($id)) { 697 return 'blog'; 698 } 699 else { 700 return $id; 701 } 702 } 703 704 function _blogapi_get_node_types() { 705 $available_types = array_keys(array_filter(variable_get('blogapi_node_types', array('blog' => 1)))); 706 $types = array(); 707 foreach (node_get_types() as $type => $name) { 708 if (node_access('create', $type) && in_array($type, $available_types)) { 709 $types[] = $type; 710 } 711 } 712 713 return $types; 714 } 715
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 16:20:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |