00001 <?php
00002
00003 if (!defined( "PLOG_CLASS_PATH" )) {
00004 define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
00005 }
00006
00007
00008
00009 include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" );
00011 include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/dao/users.class.php");
00014 include_once( PLOG_CLASS_PATH."class/dao/article.class.php");
00015 include_once( PLOG_CLASS_PATH."class/dao/articles.class.php");
00016 include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php");
00017 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00018 include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00019 include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
00020 include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00021 include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00022
00023
00024
00025 $_db = new Db;
00026 $adodb = $_db->getDb();
00027
00028
00029 $config =& Config::getConfig();
00030
00031
00032 $users = new Users;
00033
00034
00035 $articles = new Articles;
00036
00037
00038 $category = new ArticleCategories;
00039
00040
00041 $blogsG = new Blogs;
00042
00043
00044
00045 function newPost($args)
00046 {
00047 global $users, $articles, $blogsG;
00048 $appkey = $args[0];
00049 $blogid = $args[1];
00050 $username = $args[2];
00051 $password = $args[3];
00052 $content = $args[4];
00053 $publish = $args[5];
00054
00055
00056
00057
00058
00059
00060 $erg = $users->getUserInfo(
00061 $username,
00062 $password
00063 );
00064
00065 if ($erg != false)
00066 {
00067 if ($publish)
00068 {
00069 $status = POST_STATUS_PUBLISHED;
00070 } else
00071 {
00072 $status = POST_STATUS_DRAFT;
00073 }
00074
00075
00076 $cats = $category->getBlogCategories($blogid);
00077 foreach($cats as $cat)
00078 {
00079 $idCategory = $cat->_id;
00080
00081 break;
00082 }
00083
00084
00085 $dummy = explode("\n", $content);
00086 $title = $dummy[0];
00087 unset($dummy[0]);
00088 $content = implode("\n", $dummy);
00089 unset($dummy);
00090
00091
00092
00093 $article = new Article(
00094 $title,
00095 $content,
00096 $idCategory,
00097 $erg->_id,
00098 $blogid,
00099 $status,
00100 0,
00101 Array( "comments_enabled" => true )
00102 );
00103
00104 $article->setDate(date("YmdHis"));
00105
00106
00107 $plugMgr =& PluginManager::getPluginManager();
00108 $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00109 $plugMgr->setUserInfo( $erg );
00110 $plugMgr->loadPlugins();
00111
00112 $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
00113
00114 $postid = $articles->addArticle($article);
00115
00116 if ($postid != 0) {
00117
00118
00119 $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
00120 CacheControl::resetBlogCache( $blogid );
00121 return sprintf( "%d", $postid );
00122 }
00123 else {
00124 return new IXR_Error(-1, 'Internal error occured creating your post!');
00125 }
00126 }
00127 else {
00128 return new IXR_Error(-1, 'You did not provide the correct password');
00129 }
00130 }
00131
00132 function metaWeblogNewPost($args)
00133 {
00134 global $users, $articles, $category, $blogsG;
00135 $blogid = $args[0];
00136 $username = $args[1];
00137 $password = $args[2];
00138 $content = $args[3];
00139 $publish = $args[4];
00140
00141
00142
00143
00144
00145
00146 $erg = $users->getUserInfo(
00147 $username,
00148 $password
00149 );
00150
00151 if ($erg != false)
00152 {
00153 if ($publish)
00154 {
00155 $status = POST_STATUS_PUBLISHED;
00156 } else
00157 {
00158 $status = POST_STATUS_DRAFT;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 $title = $content["title"];
00171 $body = $content["description"];
00172 $catList = $content["categories"];
00173 $categoryName = NULL;
00174
00175
00176
00177
00178
00179 $categories = Array();
00180 $cats = $category->getBlogCategories($blogid);
00181 if ( $catList != NULL )
00182 {
00183 foreach( $catList as $categoryName ) {
00184 foreach( $cats as $blogCategory ) {
00185 $categoryName = trim($categoryName);
00186 if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
00187 {
00188 $categories[] = $blogCategory->getId();
00189 }
00190 }
00191 }
00192 }
00193 else {
00194
00195 $blogCategory = array_pop( $cats );
00196 $categories[] = $blogCategory->getId();
00197 }
00198
00199 $article = new Article(
00200 $title,
00201 $body,
00202 $categories,
00203 $erg->_id,
00204 $blogid,
00205 $status,
00206 0,
00207 Array( "comments_enabled" => true )
00208 );
00209
00210 $dateCreated = $content['dateCreated'];
00211
00212
00213
00214
00215
00216 if (!empty($dateCreated))
00217 {
00218
00219 $ar = localtime ( $dateCreated->getTimestamp() );
00220 $ar[5] += 1900; $ar[4]++;
00221 $localTimeStamp = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] );
00222 $articleDate = date("YmdHis", $localTimeStamp);
00223 } else
00224 {
00225 $articleDate = date("YmdHis");
00226 }
00227
00228 $article->setDate($articleDate);
00229
00230
00231 $plugMgr =& PluginManager::getPluginManager();
00232 $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00233 $plugMgr->setUserInfo( $erg );
00234 $plugMgr->loadPlugins();
00235
00236 $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
00237
00238 $postid = $articles->addArticle($article);
00239 if ($postid != 0)
00240 {
00241
00242
00243
00244 $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
00245
00246 CacheControl::resetBlogCache( $blogid );
00247 return sprintf( "%d", $postid );
00248 } else
00249 {
00250 return new IXR_Error(-1, 'Internal error occured creating your post!');
00251 }
00252 } else
00253 {
00254 return new IXR_Error(-1, 'You did not provide the correct password');
00255 }
00256 }
00257
00258 function metaWeblogGetCategories($args)
00259 {
00260 global $users, $category, $blogsG;
00261 $blogid = $args[0];
00262 $username = $args[1];
00263 $password = $args[2];
00264
00265
00266
00267
00268
00269
00270
00271 $erg = $users->getUserInfo(
00272 $username,
00273 $password
00274 );
00275
00276 if ($erg != false)
00277 {
00278 $cats = $category->getBlogCategories($blogid);
00279 $ret = array();
00280 foreach($cats as $cat)
00281 {
00282 $dummy = array();
00283 $dummy["description"] = $cat->_name;
00284
00285
00286
00287 $blogInfo = $blogsG->getBlogInfo( $blogid );
00288 $url = $blogInfo->getBlogRequestGenerator();
00289
00290
00291 $url->setXHTML( false );
00292
00293 $dummy["htmlUrl"] = $url->categoryLink( $cat );
00294 $dummy["rssUrl"] = "http://";
00295 $ret[$cat->_name] = $dummy;
00296 }
00297 return $ret;
00298 } else
00299 {
00300 return new IXR_Error(-1, 'You did not provide the correct password');
00301 }
00302 }
00303
00304
00305 function getPost($args)
00306 {
00307 global $users, $articles;
00308 $appkey = $args[0];
00309 $postid = $args[1];
00310 $username = $args[2];
00311 $password = $args[3];
00312
00313
00314
00315
00316
00317
00318
00319
00320 $erg = $users->getUserInfo($username,$password);
00321 if ($erg != false)
00322 {
00323 $item = $articles->getUserArticle($postid, $erg->_id);
00324 $dateObject = $item->getDateObject();
00325 include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
00326
00327 $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
00328
00329 $dummy = array();
00330 $dummy["userid"] = $item->_userInfo->_id;
00331 $dummy["dateCreated"] = new IXR_Date($time);
00332 $dummy["content"] = $item->_topic . "\r\n" . $item->_text . " ";
00333 $dummy["postid"] = $item->_id;
00334 return $dummy;
00335 } else
00336 {
00337 return new IXR_Error(-1, 'You did not provide the correct password');
00338 }
00339 }
00340
00341 function metaWeblogGetPost($args)
00342 {
00343 global $users, $articles;
00344 $postid = $args[0];
00345 $username = $args[1];
00346 $password = $args[2];
00347
00348
00349
00350
00351
00352
00353
00354
00355 $erg = $users->getUserInfo($username,$password);
00356 if ($erg != false)
00357 {
00358 $item = $articles->getUserArticle($postid, $erg->_id);
00359 $dateObject = $item->getDateObject();
00360 include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
00361
00362 $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
00363
00364 $articleCat = $item->getCategory();
00365
00366 $blogId = $item->getBlog();
00367 $blogs = new Blogs();
00368 $blogInfo = $blogs->getBlogInfo( $blogId );
00369 $url = $blogInfo->getBlogRequestGenerator();
00370
00371 $dummy = array();
00372 $dummy["userid"] = $item->_userInfo->_id;
00373 $dummy["dateCreated"] = new IXR_Date($time);
00374 $dummy["title"] = $item->_topic;
00375 $dummy["description"] = $item->_text;
00376 $dummy["postid"] = $item->_id;
00377
00378 $dummy["link"] = $url->postLink( $item );
00379 $dummy["permaLink"] = $url->postPermalink( $item );
00380
00381 $catArray = array();
00382 foreach( $item->getCategories() as $category ) {
00383 $catArray[] = $category->getName();
00384 }
00385 $dummy["categories"] = $catArray;
00386 return $dummy;
00387 } else
00388 {
00389 return new IXR_Error(-1, 'You did not provide the correct password');
00390 }
00391 }
00392
00393 function editPost($args)
00394 {
00395 global $users, $articles, $blogsG;
00396
00397 $appkey = $args[0];
00398 $postid = $args[1];
00399 $username = $args[2];
00400 $password = $args[3];
00401 $content = $args[4];
00402 $publish = $args[5];
00403
00404
00405
00406
00407
00408 $erg = $users->getUserInfo($username,$password);
00409 if ($erg != false)
00410 {
00411 if ($publish)
00412 {
00413 $status = POST_STATUS_PUBLISHED;
00414 } else
00415 {
00416 $status = POST_STATUS_DRAFT;
00417 }
00418
00419
00420 $dummy = explode("\n", $content);
00421 $title = $dummy[0];
00422 unset($dummy[0]);
00423 $content = implode("\n", $dummy);
00424 unset($dummy);
00425
00426 $article = $articles->getUserArticle($postid);
00427 $article->setText($content);
00428 $article->setTopic($title);
00429 $article->setStatus($status);
00430
00431
00432 $plugMgr =& PluginManager::getPluginManager();
00433 $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
00434 $plugMgr->setUserInfo( $erg );
00435 $plugMgr->loadPlugins();
00436
00437 $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article ));
00438
00439 $articles->updateArticle($article);
00440
00441
00442 $plugMgr->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$article ));
00443
00444 CacheControl::resetBlogCache( $blogid );
00445
00446 return true;
00447 } else
00448 {
00449 return new IXR_Error(-1, 'You did not provide the correct password');
00450 }
00451 }
00452
00453 function metaWeblogEditPost($args)
00454 {
00455 global $users, $articles, $category, $blogsG;
00456
00457 $postid = $args[0];
00458 $username = $args[1];
00459 $password = $args[2];
00460 $content = $args[3];
00461 $publish = $args[4];
00462
00463
00464
00465
00466
00467 $erg = $users->getUserInfo($username,$password);
00468 if ($erg != false)
00469 {
00470 if ($publish)
00471 {
00472 $status = POST_STATUS_PUBLISHED;
00473 } else
00474 {
00475 $status = POST_STATUS_DRAFT;
00476 }
00477
00478 $title = $content["title"];
00479 $body = $content["description"];
00480
00481 $article = $articles->getUserArticle($postid);
00482
00483 $catList = $content["categories"];
00484
00485
00486
00487
00488 $categories = Array();
00489 $blogid = $article->getBlog();
00490 $cats = $category->getBlogCategories($blogid);
00491 if ( $catList != NULL )
00492 {
00493 foreach( $catList as $categoryName ) {
00494 foreach( $cats as $blogCategory ) {
00495 $categoryName = trim($categoryName);
00496 if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
00497 {
00498 $categories[] = $blogCategory->getId();
00499 }
00500 }
00501 }
00502 }
00503 else {
00504
00505 $blogCategory = array_pop( $cats );
00506 $categories[] = $blogCategory->getId();
00507 }
00508
00509 $article->setText($body);
00510 $article->setTopic($title);
00511 $article->setStatus($status);
00512 $article->setCategoryIds( $categories );
00513
00514
00515 $plugMgr =& PluginManager::getPluginManager();
00516 $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00517 $plugMgr->setUserInfo( $erg );
00518 $plugMgr->loadPlugins();
00519
00520 $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article ));
00521
00522 $articles->updateArticle($article);
00523
00524
00525 $plugMgr->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$article ));
00526
00527 CacheControl::resetBlogCache( $blogid );
00528
00529 return true;
00530 } else
00531 {
00532 return new IXR_Error(-1, 'You did not provide the correct password');
00533 }
00534 }
00535
00536 function deletePost($args)
00537 {
00538 global $users, $articles, $blogsG;
00539
00540 $appkey = $args[0];
00541 $postid = $args[1];
00542 $username = $args[2];
00543 $password = $args[3];
00544 $publish = $args[4];
00545
00546
00547 $erg = $users->getUserInfo($username,$password);
00548 if ($erg != false)
00549 {
00550
00551 $article = $articles->getUserArticle($postid, $erg->_id);
00552
00553
00554 $plugMgr =& PluginManager::getPluginManager();
00555 $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
00556 $plugMgr->setUserInfo( $erg );
00557 $plugMgr->loadPlugins();
00558
00559 $plugMgr->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$article ));
00560
00561 $articles->deleteArticle(
00562 $postid,
00563 $erg->_id,
00564 $article->getBlog()
00565 );
00566
00567
00568 $plugMgr->notifyEvent( EVENT_POST_POST_DELETE, Array( "article" => &$article ));
00569
00570 CacheControl::resetBlogCache( $blogid );
00571
00572 return true;
00573 } else
00574 {
00575 return new IXR_Error(-1, 'You did not provide the correct password');
00576 }
00577 }
00578
00579 function getRecentPosts($args)
00580 {
00581 global $users, $articles;
00582
00583
00584
00585
00586
00587
00588 $appkey = $args[0];
00589 $blogid = $args[1];
00590 $username = $args[2];
00591 $password = $args[3];
00592 $number = $args[4];
00593
00594 $erg = $users->getUserInfo($username,$password);
00595 if ($erg != false)
00596 {
00597 $ret = array();
00598 $list = $articles->getBlogArticles(
00599 $blogid,
00600 -1,
00601 $number,
00602 -1
00603 );
00604
00605 foreach($list as $item)
00606 {
00607 $dateObject = $item->getDateObject();
00608 include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
00609
00610 $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
00611
00612 $dummy = array();
00613 $dummy["userid"] = $item->_userInfo->_id;
00614 $dummy["dateCreated"] = new IXR_Date($time);
00615 $dummy["content"] = $item->_topic . "\r\n" . $item->_text . " ";
00616 $dummy["postid"] = $item->_id;
00617
00618 $ret[] = $dummy;
00619 }
00620 return $ret;
00621 } else
00622 {
00623 return new IXR_Error(-1, 'You did not provide the correct password');
00624 }
00625 }
00626
00627 function metaWeblogGetRecentPosts($args)
00628 {
00629 global $users, $articles;
00630
00631
00632
00633
00634
00635
00636 $blogid = $args[0];
00637 $username = $args[1];
00638 $password = $args[2];
00639 $number = $args[3];
00640
00641 $erg = $users->getUserInfo($username,$password);
00642 if ($erg != false)
00643 {
00644 $ret = array();
00645 $list = $articles->getBlogArticles(
00646 $blogid,
00647 -1,
00648 $number,
00649 -1
00650 );
00651
00652 foreach($list as $item)
00653 {
00654 $dateObject = $item->getDateObject();
00655 include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
00656
00657 $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
00658
00659 $articleCat = $item->getCategory();
00660
00661 $dummy = array();
00662 $dummy["userid"] = $item->_userInfo->_id;
00663 $dummy["dateCreated"] = new IXR_Date($time);
00664 $dummy["title"] = $item->_topic;
00665 $dummy["description"] = $item->_text;
00666 $dummy["postid"] = $item->_id;
00667
00668 $blogId = $item->getBlog();
00669 $blogs = new Blogs();
00670 $blogInfo = $blogs->getBlogInfo( $blogId );
00671 $url = $blogInfo->getBlogRequestGenerator();
00672 $dummy["link"] = $url->postLink( $item );
00673 $dummy["permaLink"] = $url->postPermalink( $item );
00674
00675 $catArray = array();
00676 $catArray[] = $articleCat->getName();
00677 $dummy["categories"] = $catArray;
00678
00679 $ret[] = $dummy;
00680 }
00681 return $ret;
00682 } else
00683 {
00684 return new IXR_Error(-1, 'You did not provide the correct password');
00685 }
00686 }
00687
00688 function metaWeblogNewMediaObject($args)
00689 {
00690 global $users, $articles, $blogsG;
00691
00692
00693
00694
00695
00696
00697 $blogid = $args[0];
00698 $username = $args[1];
00699 $password = $args[2];
00700 $file = $args[3];
00701
00702 $erg = $users->getUserInfo($username,$password);
00703 if ($erg != false)
00704 {
00705
00706
00707
00708
00712 $config =& Config::getConfig();
00713 $tmp_dir = $config->getTempFolder();
00714
00715
00716
00717
00718 $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
00719
00720 $tempFile = $tmp_dir . '/' . $tempFile;
00721
00722
00723 if (!$handle = fopen( $tempFile, "wb" ) ) {
00724 return new IXR_Error(-1, 'Could not open file');
00725 }
00726
00727
00728 $decodedBits = $file['bits'];
00729
00730 if ( fwrite( $handle, $decodedBits ) === false ) {
00731 return new IXR_Error(-1, 'Could not write to file');
00732 }
00733
00734
00735 fclose($handle);
00736
00737
00738 $resources = new GalleryResources();
00739
00740
00741 $albums = new GalleryAlbums();
00742
00743 $albumArray = $albums->getUserAlbums( $blogid );
00744 if ( $albumArray == NULL || count( $albumArray ) == 0 ) {
00745 return new IXR_Error(-1, 'Could not find album');
00746 }
00747
00748
00749 $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(),
00750 basename($file['name']), $tempFile );
00751
00752 $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() );
00753
00754 $blogInfo = $blogsG->getBlogInfo( $blogid );
00755 $url = $blogInfo->getBlogRequestGenerator();
00756
00757 $ret = $url->resourceDownloadLink( $resource );
00758
00759 return $ret;
00760 } else
00761 {
00762 return new IXR_Error(-1, 'You did not provide the correct password');
00763 }
00764 }
00765
00766 function getUserInfo($args)
00767 {
00768 $appkeyp = $args[0];
00769 $username = $args[1];
00770 $password = $args[2];
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 $users = new Users();
00781
00782 $erg = $users->getUserInfo(
00783 $username,
00784 $password
00785 );
00786
00787 if ($erg != false)
00788 {
00789 $ret = array();
00790 $ret["nickname"] = $erg["_username"];
00791 $ret["firstname"] = $erg["_username"];
00792 $ret["lastname"] = "";
00793 $ret["email"] = $erg["_email"];
00794 $ret["userid"] = $erg["_id"];
00795 $ret["url"] = "";
00796 return $ret;
00797 } else
00798 {
00799 return new IXR_Error(-1, 'You did not provide the correct password');
00800 }
00801 }
00802
00803 function getUsersBlogs($args)
00804 {
00805 global $users, $category;
00806 $appkey = $args[0];
00807 $username = $args[1];
00808 $password = $args[2];
00809
00810
00811
00812
00813
00814
00815 $erg = $users->getUserInfo(
00816 $username,
00817 $password
00818 );
00819
00820 if ($erg != false)
00821 {
00822 $blogs = $users->getUsersBlogs($erg->_id);
00823 $ret = array();
00824 foreach($blogs as $blog)
00825 {
00826 $dummy = array();
00827 $dummy["blogid"] = $blog->_id;
00828 $dummy["blogName"] = $blog->_blog;
00829 $url = $blog->getBlogRequestGenerator();
00830 $dummy["url"] = $url->blogLink();
00831 $ret[] = $dummy;
00832 }
00833 return $ret;
00834 } else
00835 {
00836 return new IXR_Error(-1, 'You did not provide the correct password');
00837 }
00838 }
00839
00840 if ($config->getValue("xmlrpc_api_enabled"))
00841 {
00842 $xmlrpc = new IXR_Server(
00843 array (
00844 "blogger.newPost" => "newPost",
00845 "blogger.getUserInfo" => "getUserInfo",
00846 "blogger.getPost" => "getPost",
00847 "blogger.editPost" => "editPost",
00848 "blogger.deletePost" => "deletePost",
00849 "blogger.getRecentPosts" => "getRecentPosts",
00850 "blogger.getUserInfo" => "getUserInfo",
00851 "blogger.getUsersBlogs" => "getUsersBlogs",
00852 "metaWeblog.newPost" => "metaWeblogNewPost",
00853 "metaWeblog.editPost" => "metaWeblogEditPost",
00854 "metaWeblog.getPost" => "metaWeblogGetPost",
00855 "metaWeblog.getRecentPosts" => "metaWeblogGetRecentPosts",
00856 "metaWeblog.getCategories" => "metaWeblogGetCategories",
00857 "metaWeblog.newMediaObject" => "metaWeblogNewMediaObject"
00858 )
00859 );
00860 } else
00861 {
00862
00863 $xmlrpc = new IXR_Server(
00864 array (
00865 )
00866 );
00867
00868 }
00869 ?>