📄 xmlrpcserver.class.php
字号:
return new IXR_Error(-1, 'You did not provide the correct password'); } } function metaWeblogNewMediaObject($args) { $users = new Users(); $articles = new Articles(); $blogsG = new Blogs(); $blogid = $args[0]; $username = $args[1]; $password = $args[2]; $file = $args[3]; $userInfo = $users->getUserInfo( $username, $password ); if( $userInfo ) { // check if the blog id is valid $blogInfo = $blogsG->getBlogInfo( $blogid ); if( !$blogInfo ) { return new IXR_Error(-1, 'The blog is not valid' ); } // and now check if the user has enough access to upload resources if( !$this->userHasPermission( $userInfo, $blogInfo, "add_resource" )) { return new IXR_Error(-1, 'This user does not have enough permissions' ); } // Save this file to the tmp directory // Create a temp file // Get the temp directory /**if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) { $tmp_dir = dirname(tempnam('/tmp', '')); }*/ $config =& Config::getConfig(); $tmp_dir = $config->getTempFolder(); // Remove all characters that would need to be urlencoded // This may not be necessary, but this was causing problems when given file // names with spaces in it. $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name'])); // Make the tmp name $tempFile = $tmp_dir . '/' . $tempFile; // Open the file if (!$handle = fopen( $tempFile, "wb" ) ) { return new IXR_Error(-1, 'Could not open file'); } // It appears that the data has already been decoded, no need to call base64_decode $decodedBits = $file['bits']; // Write the data to the file if ( fwrite( $handle, $decodedBits ) === false ) { return new IXR_Error(-1, 'Could not write to file'); } // Close the file fclose($handle); // let the gallery library do its work... $resources = new GalleryResources(); // Get the first album for this blog $albums = new GalleryAlbums(); // get the list of albums for this blog $albumArray = $albums->getUserAlbums( $blogid ); if ( $albumArray == NULL || count( $albumArray ) == 0 ) { return new IXR_Error(-1, 'Could not find album'); } // Add the resource to the first album $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(), basename($file['name']), $tempFile ); // Get the resource from the id $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() ); // Now we need to get the url for the resource $url = $blogInfo->getBlogRequestGenerator(); $responseStruct = array(); $responseStruct['url'] = $url->resourceDownloadLink( $resource ); $this->setResponseCharset( $blogInfo ); return $responseStruct; } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } function getUserInfo($args) { $appkeyp = $args[0]; $username = $args[1]; $password = $args[2]; $users = new Users(); $userInfo = $users->getUserInfo( $username, $password ); if ($userInfo) { $ret = array(); $ret["nickname"] = $userInfo->getUsername(); $ret["firstname"] = $userInfo->getUsername(); $ret["lastname"] = ""; $ret["email"] = $userInfo->getEmail(); $ret["userid"] = $userInfo->getId(); $ret["url"] = ""; // set the response encoding according to one of the blogs owned by this user $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE ); if( count($userBlogs) > 0 ) { $blogInfo = array_pop( $userBlogs ); $this->setResponseCharset( $blogInfo ); } return $ret; } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } function getUsersBlogs($args) { $users = new Users(); $category = new ArticleCategories(); $appkey = $args[0]; $username = $args[1]; $password = $args[2]; /* "blogName" => "url" => "blogid" => */ $userInfo = $users->getUserInfo( $username, $password ); if ($userInfo) { $blogs = $users->getUsersBlogs($userInfo->getId(), BLOG_STATUS_ACTIVE ); $ret = array(); foreach($blogs as $blog) { $dummy = array(); $dummy["blogid"] = $blog->_id; $dummy["blogName"] = $blog->_blog; $url = $blog->getBlogRequestGenerator(); $dummy["url"] = $url->blogLink(); $ret[] = $dummy; } // set the encoding as long as we've got at least one blog if( count( $blogs ) > 0 ) { $blogInfo = $blogs[0]; $this->setResponseCharset( $blogInfo ); } return $ret; } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } function mtSupportedTextFilters($args) { $ret = array(); return $ret; } function mtGetPostCategories($args) { $users = new Users(); $articles = new Articles(); $postid = $args[0]; $username = $args[1]; $password = $args[2]; $userInfo = $users->getUserInfo( $username, $password ); if( $userInfo ) { include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); $item = $articles->getBlogArticle($postid, -1, // blogId true, // includeHiddenFields -1, // date -1, // categoryId $userInfo->getId()); // check if the article is valid if( !$item ) { return( new IXR_Error(-1, 'The article is not valid' )); } // and permissions $blogInfo = $item->getBlogInfo(); if( !$this->userHasPermission( $userInfo, $blogInfo, "view_posts" )) { return new IXR_Error(-1, 'This user does not have enough permissions' ); } $catArray = array(); foreach( $item->getCategories() as $category ) { $dummy = array(); $dummy["categoryId"] = $category->getId(); $dummy["categoryName"] = $category->getName(); $catArray[] = $dummy; } $this->setResponseCharset( $blogInfo ); return $catArray; } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } function mtSetPostCategories($args) { $users = new Users(); $articles = new Articles(); $postid = $args[0]; $username = $args[1]; $password = $args[2]; $categories = $args[3]; $userInfo = $users->getUserInfo( $username, $password ); if( $userInfo ) { include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); $article = $articles->getBlogArticle($postid, -1, // blogId true, // includeHiddenFields -1, // date -1, // categoryId $userInfo->getId()); // check that the article is valid if( !$article ) { return( new IXR_Error(-1, 'The article is not correct' )); } // check the permissions $blogId = $article->getBlog(); $blogInfo = $article->getBlogInfo(); if( !$this->userHasPermission( $userInfo, $blogInfo, "update_post" )) { return new IXR_Error(-1, 'This user does not have enough permissions' ); } $articleCategories = new ArticleCategories(); $catArray = Array(); if ( $categories != NULL ) { foreach( $categories as $category ) { // Get the category object for the category $catArray[] = $category["categoryId"]; } } $article->setCategoryIds($catArray); // Get the plugin manager $plugMgr =& PluginManager::getPluginManager(); $plugMgr->setBlogInfo( $blogInfo ); $plugMgr->setUserInfo( $userInfo ); $plugMgr->loadPlugins(); // Send the EVENT_PRE_POST_UPDATE message $plugMgr->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$article )); $articles->updateArticle($article); // Send the EVENT_POST_POST_UPDATE messages to the plugins $plugMgr->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$article )); CacheControl::resetBlogCache( $blogId ); $this->setResponseCharset( $blogInfo ); return true; } else { return new IXR_Error(-1, 'You did not provide the correct password'); } } /** * Extra helper method to check permissions * * @param user A UserInfo object * @param blog A BlogInfo object * @param permName Name of the permission * @param mode Either BLOG_PERMISSION or ADMIN_PERMISSION, depending on whether * we're checking the user's permissions in this blog or an admin permission */ function userHasPermission( $userInfo, $blogInfo, $permName, $mode = BLOG_PERMISSION ) { // check for the permission, whether the user is the blog owner or // whether the user is a site administrator $hasPermission = false; if( $mode == BLOG_PERMISSION ) { $hasPermission = ( $userInfo->hasPermissionByName( $permName, $blogInfo->getId()) || $blogInfo->getOwnerId() == $userInfo->getId() || $userInfo->hasPermissionByName( "edit_blog_admin_mode", 0 ) ); } else { $hasPermission = ( $userInfo->hasPermissionByName( $permName, 0 )); } return( $hasPermission ); } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -