📄 xmlrpcserver.class.php
字号:
<?php lt_include( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" ); lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/users.class.php"); lt_include( PLOG_CLASS_PATH."class/dao/article.class.php"); lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php"); lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php"); lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" ); lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" ); lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" ); if( !defined( "ADMIN_PERMISSION" )) define( "ADMIN_PERMISSION", 1 ); if( !defined( "BLOG_PERMISSION" )) define( "BLOG_PERMISSION", 2 ); class XmlRpcServer extends IXR_Server { function XmlRpcServer() { $config =& Config::getConfig(); if ($config->getValue("xmlrpc_api_enabled")) { $this->IXR_Server( array ( "blogger.newPost" => "this:newPost", "blogger.getPost" => "this:getPost", "blogger.editPost" => "this:editPost", "blogger.deletePost" => "this:deletePost", "blogger.getRecentPosts" => "this:getRecentPosts", "blogger.getUserInfo" => "this:getUserInfo", "blogger.getUsersBlogs" => "this:getUsersBlogs", "metaWeblog.newPost" => "this:metaWeblogNewPost", "metaWeblog.editPost" => "this:metaWeblogEditPost", "metaWeblog.getPost" => "this:metaWeblogGetPost", "metaWeblog.getRecentPosts" => "this:metaWeblogGetRecentPosts", "metaWeblog.getCategories" => "this:metaWeblogGetCategories", "metaWeblog.newMediaObject" => "this:metaWeblogNewMediaObject", "metaWeblog.getUsersBlogs" => "this:getUsersBlogs", "mt.getCategoryList" => "this:mtGetCategoryList", "mt.supportedTextFilters" => "this:mtSupportedTextFilters", "mt.getPostCategories" => "this:mtGetPostCategories", "mt.setPostCategories" => "this:mtSetPostCategories" )); } else { // xmlrpc_api disabled, no methods configured $this->IXR_Server( Array ()); } } function newPost( $args ) { $users = new Users(); $articles = new Articles(); $category = new ArticleCategories(); $blogsG = new Blogs(); $appkey = $args[0]; $blogid = $args[1]; $username = $args[2]; $password = $args[3]; $content = $args[4]; $publish = $args[5]; // true post&publish | false post only /* int postid */ // -mhe todo security $userInfo = $users->getUserInfo( $username, $password ); if ($userInfo) { $blogInfo = $blogsG->getBlogInfo( $blogid ); if( !$blogInfo ) { return new IXR_Error(-1, 'Error loading blog' ); } // check this user's permissions before proceeding if( !$this->userHasPermission( $userInfo, $blogInfo, "add_post" )) { return new IXR_Error(-1, 'This user does not have enough permissions' ); } if ($publish) { $status = POST_STATUS_PUBLISHED; } else { $status = POST_STATUS_DRAFT; } // Get the default category $cats = $category->getBlogCategories($blogid); // some protection again blogs without categories if( !$cats ) { return new IXR_Error(-1, 'This blog does not have categories!'); } foreach($cats as $cat) { $idCategory = $cat->getId(); // Stop here, we have a category break; } // ecto sends the topic as <title>blah blah</title>rest of the body if( preg_match( "/<title>(.*)<\/title>(.*)/i", $content, $matches )) { $title = $matches[1]; $content = $matches[2]; } else { $dummy = explode("\n", $content); if( count( $dummy ) == 1 ) { $title = substr( $content, 0, 60 ); } else { $title = $dummy[0]; unset($dummy[0]); $content = implode("\n", $dummy); unset($dummy); } } $article = new Article( $title, $content, // text Array( $idCategory ), // catid $userInfo->getId(), // userid $blogid, // blogid $status, 0, // numread Array( "comments_enabled" => true ) // enable comments ); $article->setDate(date("YmdHis")); // Get the plugin manager $plugMgr =& PluginManager::getPluginManager(); $plugMgr->setBlogInfo( $blogInfo); $plugMgr->setUserInfo( $userInfo ); $plugMgr->loadPlugins(); // Send the PRE_POST_POST_ADD message $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article )); $postid = $articles->addArticle($article); if ($postid != 0) { // The post was successful // Send the EVENT_POST_POST_ADD messages to the plugins $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article )); CacheControl::resetBlogCache( $blogid ); $blogSettings = $blogInfo->getSettings(); // Add article notifcations if this is specified by the default setting. if ($blogSettings->getValue( "default_send_notification" )) { require_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" ); $artNotifications = new ArticleNotifications(); $artNotifications->addNotification( $postid, $blogid, $userInfo->getId()); } $this->setResponseCharset( $blogInfo ); return sprintf( "%d", $postid ); } else { return new IXR_Error(-1, 'Internal error occured creating your post!'); } } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } function metaWeblogNewPost($args) { $users = new Users(); $articles = new Articles(); $category = new ArticleCategories(); $blogsG = new Blogs(); $blogid = $args[0]; $username = $args[1]; $password = $args[2]; $content = $args[3]; $publish = $args[4]; // true post&publish | false post only /* int postid */ $userInfo = $users->getUserInfo( $username, $password); if( $userInfo ) { if ($publish) { $status = POST_STATUS_PUBLISHED; } else { $status = POST_STATUS_DRAFT; } $blogInfo = $blogsG->getBlogInfo( $blogid ); if( !$this->userHasPermission( $userInfo, $blogInfo, "add_post" )) { return new IXR_Error(-1, 'This user does not have enough permissions' ); } $title = $content["title"]; // Check to see if the MovableType extnensions have been added $mt_excerpt = ""; $mt_text_more = ""; $mt_allow_comments = ""; if( isset( $content["mt_excerpt"] )) $mt_excerpt = $content["mt_excerpt"]; if( isset( $content["mt_text_more"] )) $mt_text_more = $content["mt_text_more"]; if( isset( $content["mt_allow_comments"] )) $mt_allow_comments = $content["mt_allow_comments"]; if ( $mt_text_more != NULL && trim($mt_text_more != "")) { $body = $content["description"] . POST_EXTENDED_TEXT_MODIFIER . $mt_text_more; } else { $body = $content["description"]; } $catList = NULL; if( isset( $content["categories"] )) $catList = $content["categories"]; $categoryName = NULL; // // :KLUDGE: // not exactly the smartest and fastest bit of code ever but it seems to work :-) // $categories = Array(); $cats = $category->getBlogCategories($blogid); // some protection again blogs without categories if( !$cats ) { return new IXR_Error(-1, 'This blog does not have categories!'); } if ( $catList != NULL ) { foreach( $catList as $categoryName ) { foreach( $cats as $blogCategory ) { $categoryName = trim($categoryName); if ( strcmp( $categoryName, $blogCategory->getName()) == 0 ) { $categories[] = $blogCategory->getId(); } } } } else { // if no category, let's pick a random one $blogCategory = array_pop( $cats ); $categories[] = $blogCategory->getId(); } $userInfo = $users->getUserInfoFromUsername( $username ); // Initially assume that comments are enabled $enableComments = true; // Was a setting specified in the MovableType fields? if ($mt_allow_comments != NULL) { $enableComments = $mt_allow_comments; } $article = new Article( $title, $body, // text $categories, // catid $userInfo->getId(), // userid $blogid, // blogid $status, 0, // numread Array( "comments_enabled" => $enableComments ) ); $dateCreated = NULL; if( isset( $content['dateCreated'] )) $dateCreated = $content['dateCreated']; // there must be a bug in the xmlrpc library, we're getting an object in $dateCreated // that does not have a type or anyhting, but it still is an object... kinda weird. Anyway, // clients like ecto do not allow to change the time an article is posted so this is not // too annoying, *yet* if (!empty($dateCreated)) { // Convert the UTC time to local time, since articleDate is in local time $ar = localtime ( $dateCreated->getTimestamp() ); $ar[5] += 1900; $ar[4]++; $localTimeStamp = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] ); $articleDate = date("YmdHis", $localTimeStamp); } else { $articleDate = date("YmdHis"); } $article->setDate($articleDate); // Get the plugin manager $plugMgr =& PluginManager::getPluginManager(); $plugMgr->setBlogInfo( $blogInfo ); $plugMgr->setUserInfo( $userInfo ); $plugMgr->loadPlugins(); // Send the PRE_POST_POST_ADD message $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article )); $postid = $articles->addArticle($article); if ($postid != 0) { // The post was successful // Send the EVENT_POST_POST_ADD messages to the plugins $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article )); CacheControl::resetBlogCache( $blogid );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -