NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/xmlrpc.php

Go to the documentation of this file.
00001 <?php
00002 
00003         if (!defined( "PLOG_CLASS_PATH" )) {
00004         define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
00005     }
00006 
00007 
00008     // include required classes, dont know what, but it works for me :-)
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     // init database
00025     $_db = new Db;
00026     $adodb = $_db->getDb();
00027 
00028     // config object
00029     $config =& Config::getConfig();
00030 
00031     // users object
00032     $users = new Users;
00033 
00034     // articles object
00035     $articles = new Articles;
00036 
00037     // category object
00038     $category = new ArticleCategories;
00039     
00040     // blog object
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]; // true post&publish | false post only
00054         /*
00055          int postid
00056         */
00057 
00058         // -mhe todo security
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             // Get the default category
00076             $cats = $category->getBlogCategories($blogid);
00077             foreach($cats as $cat)
00078             {
00079                 $idCategory = $cat->_id;
00080                 // Stop here, we have a category
00081                 break;
00082             }
00083 
00084             // fake topic
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, // text
00096                 $idCategory, // catid
00097                 $erg->_id, // userid
00098                 $blogid, // blogid
00099                 $status,
00100                 0, // numread
00101                 Array( "comments_enabled" => true ) // enable comments
00102             );
00103             
00104             $article->setDate(date("YmdHis"));
00105 
00106                         // Get the plugin manager
00107                         $plugMgr =& PluginManager::getPluginManager();
00108                         $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00109                         $plugMgr->setUserInfo( $erg );
00110                         $plugMgr->loadPlugins();
00111                         // Send the PRE_POST_POST_ADD message
00112                         $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));            
00113 
00114             $postid = $articles->addArticle($article);
00115             
00116             if ($postid != 0) {
00117                                 // The post was successful
00118                                 // Send the EVENT_POST_POST_ADD messages to the plugins
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]; // true post&publish | false post only
00140         /*
00141          int postid
00142         */
00143 
00144         // -mhe todo security
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             // Get the default category
00162             //$cats = $category->getBlogCategories($blogid);
00163             //foreach($cats as $cat)
00164             //{
00165             //    $idCategory = $cat->_id;
00166             //    // Stop here, we have a category
00167             //    break;
00168             //}
00169             
00170             $title = $content["title"];
00171             $body = $content["description"];
00172             $catList = $content["categories"];
00173             $categoryName = NULL;
00174 
00175             //
00176             // :KLUDGE:
00177             // not exactly the smartest and fastest bit of code ever but it seems to work :-)
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                 // if no category, let's pick a random one
00195                 $blogCategory = array_pop( $cats );
00196                 $categories[] = $blogCategory->getId();
00197             }
00198             
00199             $article = new Article(
00200                 $title,
00201                 $body, // text
00202                 $categories, // catid
00203                 $erg->_id, // userid
00204                 $blogid, // blogid
00205                 $status,
00206                 0, // numread
00207                 Array( "comments_enabled" => true ) // enable comments
00208             );
00209 
00210            $dateCreated = $content['dateCreated'];
00211            
00212            // there must be a bug in the xmlrpc library, we're getting an object in $dateCreated
00213            // that does not have a type or anyhting, but it still is an object... kinda weird. Anyway,
00214            // clients like ecto do not allow to change the time an article is posted so this is not 
00215            // too annoying, *yet*
00216             if (!empty($dateCreated))
00217             {
00218                // Convert the UTC time to local time, since articleDate is in local time
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                         // Get the plugin manager
00231                         $plugMgr =& PluginManager::getPluginManager();
00232                         $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00233                         $plugMgr->setUserInfo( $erg );
00234                         $plugMgr->loadPlugins();
00235                         // Send the PRE_POST_POST_ADD message
00236                         $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));            
00237             
00238             $postid = $articles->addArticle($article);
00239             if ($postid != 0)
00240             {
00241                         // The post was successful
00242                         
00243                         // Send the EVENT_POST_POST_ADD messages to the plugins
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          "description" =>
00266          "htmlUrl" =>
00267          "rssUrl" =>
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                 // We can't use $cat->_url becuase it is not set, so 
00286                 // we have to do this in long way
00287                 $blogInfo = $blogsG->getBlogInfo( $blogid );
00288                 $url = $blogInfo->getBlogRequestGenerator();
00289                 // disable the generation of xhtml content or else the IXR_XMLRPC library will
00290                 // escape things twice!
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             "userid" =>
00315             "dateCreated" =>
00316             "content" =>
00317             "postid" =>
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             // Get the unix time stamp 
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             "userid" =>
00350             "dateCreated" =>
00351             "content" =>
00352             "postid" =>
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             // Get the unix time stamp 
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             boolean, true or false
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             // fake topic
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                         // Get the plugin manager
00432                         $plugMgr =& PluginManager::getPluginManager();
00433                         $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
00434                         $plugMgr->setUserInfo( $erg );
00435                         $plugMgr->loadPlugins();
00436                         // Send the EVENT_PRE_POST_UPDATE message
00437                         $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article ));            
00438 
00439             $articles->updateArticle($article);
00440 
00441             // Send the EVENT_POST_POST_UPDATE messages to the plugins
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             boolean, true or false
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             // :KLUDGE:
00486             // not exactly the smartest and fastest bit of code ever but it seems to work :-)
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                 // if no category, let's pick a random one
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                         // Get the plugin manager
00515                         $plugMgr =& PluginManager::getPluginManager();
00516                         $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $blogid ) );
00517                         $plugMgr->setUserInfo( $erg );
00518                         $plugMgr->loadPlugins();
00519                         // Send the EVENT_PRE_POST_UPDATE message
00520                         $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article ));            
00521 
00522             $articles->updateArticle($article);
00523             
00524             // Send the EVENT_POST_POST_UPDATE messages to the plugins
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         // -mhe todo
00547         $erg = $users->getUserInfo($username,$password);
00548         if ($erg != false)
00549         {
00550 
00551             $article = $articles->getUserArticle($postid, $erg->_id);
00552             
00553                         // Get the plugin manager
00554                         $plugMgr =& PluginManager::getPluginManager();
00555                         $plugMgr->setBlogInfo( $blogsG->getBlogInfo( $article->getBlog() ) );
00556                         $plugMgr->setUserInfo( $erg );
00557                         $plugMgr->loadPlugins();
00558                         // Send the EVENT_PRE_POST_DELETE message
00559                         $plugMgr->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$article ));            
00560 
00561             $articles->deleteArticle(
00562                 $postid,
00563                 $erg->_id, // userid
00564                 $article->getBlog()
00565             );
00566             
00567             // Send the EVENT_POST_POST_DELETE messages to the plugins
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             "userid" =>
00584             "dateCreated" =>
00585             "content" =>
00586             "postid" =>
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                 // Get the unix time stamp 
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             "userid" =>
00632             "dateCreated" =>
00633             "content" =>
00634             "postid" =>
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,  // date
00648                 $number, // number of articles
00649                 -1  // category id
00650             );
00651 
00652             foreach($list as $item)
00653             {
00654                 $dateObject = $item->getDateObject();
00655                 include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
00656                 // Get the unix time stamp 
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             "userid" =>
00693             "dateCreated" =>
00694             "content" =>
00695             "postid" =>
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             // Save this file to the tmp directory
00706             
00707             // Create a temp file
00708             // Get the temp directory
00712                         $config =& Config::getConfig();
00713                         $tmp_dir = $config->getTempFolder();
00714             
00715             // Remove all characters that would need to be urlencoded
00716             // This may not be necessary, but this was causing problems when given file
00717             // names with spaces in it.
00718             $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
00719             // Make the tmp name
00720             $tempFile = $tmp_dir . '/' . $tempFile;
00721 
00722             // Open the file
00723             if (!$handle = fopen( $tempFile, "wb" ) ) {
00724                 return new IXR_Error(-1, 'Could not open file');
00725             }    
00726             
00727             // It appears that the data has already been decoded, no need to call base64_decode
00728             $decodedBits = $file['bits'];
00729             // Write the data to the file
00730             if ( fwrite( $handle, $decodedBits ) === false ) {
00731                 return new IXR_Error(-1, 'Could not write to file');
00732             }
00733 
00734             // Close the file
00735             fclose($handle);
00736             
00737             // let the gallery library do its work...
00738                 $resources = new GalleryResources();
00739 
00740             // Get the first album for this blog
00741             $albums = new GalleryAlbums();
00742             // get the list of albums for this blog
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             // Add the resource to the first album
00749             $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(),
00750                                                      basename($file['name']), $tempFile );
00751             // Get the resource from the id
00752             $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() );
00753             // Now we need to get the url for the resource
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         "nickname" =>
00773         "firstname" =>
00774         "lastname" =>
00775         "email" =>
00776         "userid" =>
00777         "url" =>
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             "blogName" =>
00811             "url" =>
00812             "blogid" =>
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         // xmlrpc_api disabled, no methods configured
00863         $xmlrpc = new IXR_Server(
00864             array (
00865             )
00866         );
00867     
00868     }
00869 ?>