【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-api.php,希望本篇文章对您学习有所帮助。
<?php
/*
* $Id: api.php,v 1.2 2004/02/06 07:57:14 f-bomb Exp $
*
* api.php
* Implements the Blogger and metaWeblog APIs for MyPHPBlog
* Created by Dougal Campbell <dougal@gunters.org>, <emc3@users.sf.net>
* http://dougal.gunters.org/
*
* License: GPL
*
* NOTES:
* Info about the Blogger API:
* http://plant.blogger.com/api/
*
* More info (bloggerDev mailing list):
* http://groups.yahoo.com/group/bloggerDev
*
* Info about the metaWeblog API:
* http://www.xmlrpc.com/discuss/msgReader$2198?mode=topic
*
* The Blogger API doesn't support titles on posts. This module follows
* the convention of using '<title>foo</title>' at the beginning of a
* post to denote the title. Some clients (e.g., w.bloggar version 3)
* support this automagically.
*
* MyPHPBlog doesn't currently have a way to store a unique URL
* for each blogid. Because of this, the getUsersBlogs method
* will use the global $blogurl for all blogs. This will affect
* you if you have multiple blogs, each with a unique URL. In the
* future, we might want to add a URL field to the blog_list table.
*
* Blogger uses unique post ids, across multiple blogs. MyPHPBlog
* post ids are only unique within their blog (there is an argument
* to be made here that MyPHPBlog's design is stronger, in that
* respect). Because of that, this module internally combines
* the blogid and postid (separated by a colon). This shouldn't
* affect anything visibly, but I wanted to note it here so that
* others will understand what's going on in the relevant functions.
*
* The API functions related to templates have no comparable functions
* in MyPHPBlog. Unimplemented functions will be intercepted by this
* module, however, and will return an appropriate error message.
*
* $Log: api.php,v $
* Revision 1.2 2004/02/06 07:57:14 f-bomb
* changes for 0.9beta
*
* Revision 1.6 2003/10/09 06:47:07 f-bomb
* added pingback functionality
*
* Revision 1.5 2003/08/06 06:05:04 jbuberel
* Big schema creation and related overhaul, plus updates to the install and upgrade procedures.
*
* Known remaining bug: Template previewing is broken.
*
* Other bugs to be discovered.
*
* Revision 1.4 2003/03/13 17:33:07 emc3
* Updated for 0.8
*
* Revision 1.3 2002/10/24 14:04:54 emc3
* Declared $title and $blogurl as globals so that the weblogs.com ping function would work correctly
*
* Revision 1.2 2002/10/24 13:58:54 emc3
* Declared $use_
weblog_rpc as a global so that the weblogs.com ping function would work correctly
*
* Revision 1.1 2002/09/27 14:07:48 emc3
* New file for Blogger and metaWeblog APIs
*
*
*/
// Pull in the My
PHPBlog lib for some useful globals and functions
include_once('lib.php');
// Pull in the XML-RPC libraries from Useful, Inc.
// http://usefulinc.com/
include_once('xmlrpc.inc');
include_once('xmlrpcs.inc');
include_once('class.BlogInfo.php');
include_once('class.BlogEntry.php');
include_once('class.BlogUser.php');
/***********************************
*
* Define API and helper functions
*
***********************************/
// First, the Blogger API stuff:
function newPost ($params) { // ($appkey, $blogid, $user, $pass, $content, $publish)
global $xmlrpcerruser;
// PHP makes us do this decode in multiple steps, with
// temp variables... It can't do something like:
// $foo = $params->getParam(0)->scalarval()
$xappkey = $params->getParam(0);
$xblogid = $params->getParam(1);
$xuser = $params->getParam(2);
$xpass = $params->getParam(3);
$xcontent = $params->getParam(4);
$xpublish = $params->getParam(5);
$appkey = $xappkey->scalarval();
$blogid = $xblogid->scalarval();
$user = $xuser->scalarval();
$pass = $xpass->scalarval();
$content = $xcontent->scalarval();
$publish = $xpublish->scalarval();
// Check login
$login = mpb_get_userid($user,$pass);
$uid = $login['uid'];
// uid of -1 means user/pass didn't jive
if ($uid != -1) {
// Do some stuff
if (!mpb_user_blog_check($uid,$blogid)) {
$err = "User " . $user . " does not have access to blogid " . $blogid;
}
} else {
// Bad login
$err = $login['err'];
}
if ($err) {
// this is an error condition
return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
$err);
} else {
// Build response packet.
// MyPHPBlog's organization is different from Blogger. We
// have to play a few tricks with postid, because it is
// not unique throughout the system, but instead is only
// unique to a particular blogid. We separate the blogid
// and postid with a colon, and pass that value to th