OSDN Git Service

Now this trunk equal 3.62 without documentation. We need to test for install and...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / xmlrpc / server.php
index ad20026..0266c09 100755 (executable)
@@ -1,75 +1,86 @@
 <?php
-/** 
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
-  * Copyright (C) 2002-2004 The Nucleus Group
-  *
-  * This program is free software; you can redistribute it and/or
-  * modify it under the terms of the GNU General Public License
-  * as published by the Free Software Foundation; either version 2
-  * of the License, or (at your option) any later version.
-  * (see nucleus/documentation/index.html#license for more info)
-  *
-  * $Id: server.php,v 1.1.1.1 2005-02-28 07:15:05 kimitake Exp $
-  *
-  * This script is provides an XML-RPC [1] interface to Nucleus [2].
-  *
-  * At this time, the Blogger API [3], the metaWeblog API [4] and 
-  * parts of the Movable Type API [5] are implemented
-  *
-  * This script uses the the 'XML-RPC for PHP v1.02' implementation [6]
-  * All other code was written by Wouter Demuynck [7]
-  *
-  * [1] http://www.xmlrpc.com/
-  * [2] http://nucleuscms.org/
-  * [3] http://plant.blogger.com/api/
-  * [4] http://www.xmlrpc.com/metaWeblogApi
-  * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html
-  * [6] http://phpxmlrpc.sourceforge.net/
-  * [7] http://demuynck.org/
-  *
-  *
-  * The Blogger API: (more info in the documentation)
-  *
-  *    blogger.newPost 
-  *    blogger.editPost 
-  *    blogger.getUsersBlogs 
-  *    blogger.deletePost
-  *    blogger.getRecentPosts
-  *    blogger.getPost
-  *    blogger.getUserInfo
-  *    blogger.getTemplate
-  *    blogger.setTemplate
-  *
-  *    Note: The getUserInfo response contains an empty 'lastname' and the full name as 
-  *       'firstname'
-  * Note: Blogger API methods only affect the body field of items
-  *
-  * The metaWeblog API (more info in documentation)
-  *
-  * metaWeblog.newPost
-  * metaWeblog.getPost
-  * metaWeblog.editPost
-  * metaWeblog.getCategories
-  * metaWeblog.newMediaObject
-  * metaWeblog.getRecentPosts
-  *
-  * Note: metaWeblog API methods only affect the body and title fields of items. 
-  *       the extended part is left untouched (and empty for new posts)
-  *
-  * The Movable Type API
-  *
-  * mt.supportedMethods
-  */
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2010 The Nucleus Group
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+
+/**
+ * This script is provides an XML-RPC [1] interface to Nucleus [2].
+ *
+ * At this time, the Blogger API [3], the metaWeblog API [4] and
+ * parts of the Movable Type API [5] are implemented
+ *
+ * This script uses the the 'XML-RPC for PHP v1.02' implementation [6]
+ * All other code was written by Wouter Demuynck [7]
+ *
+ * [1] http://www.xmlrpc.com/
+ * [2] http://nucleuscms.org/
+ * [3] http://plant.blogger.com/api/
+ * [4] http://www.xmlrpc.com/metaWeblogApi
+ * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html
+ * [6] http://phpxmlrpc.sourceforge.net/
+ * [7] http://demuynck.org/
+ *
+ *
+ * The Blogger API: (more info in the documentation)
+ *
+ *     blogger.newPost
+ *     blogger.editPost
+ *     blogger.getUsersBlogs
+ *     blogger.deletePost
+ *     blogger.getRecentPosts
+ *     blogger.getPost
+ *     blogger.getUserInfo
+ *     blogger.getTemplate
+ *     blogger.setTemplate
+ *
+ *     Note: The getUserInfo response contains an empty 'lastname' and the full name as
+ *       'firstname'
+ * Note: Blogger API methods only affect the body field of items
+ *
+ * The metaWeblog API (more info in documentation)
+ *
+ * metaWeblog.newPost
+ * metaWeblog.getPost
+ * metaWeblog.editPost
+ * metaWeblog.getCategories
+ * metaWeblog.newMediaObject
+ * metaWeblog.getRecentPosts
+ *
+ * Note: metaWeblog API methods only affect the body and title fields of items.
+ *       the extended part is left untouched (and empty for new posts)
+ *
+ * The Movable Type API
+ *
+ * mt.supportedMethods
+ *
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2010 The Nucleus Group
+ * @version $Id$
+ * @version $NucleusJP: server.php,v 1.8.2.1 2007/09/07 07:12:42 kimitake Exp $
+ */
 $CONF = array();
-include("../../config.php");   // include Nucleus libs and code
-include($DIR_LIBS . "xmlrpc.inc.php");
-include($DIR_LIBS . "xmlrpcs.inc.php");
+require("../../config.php");   // include Nucleus libs and code
+//include($DIR_LIBS . "xmlrpc.inc.php");
+//include($DIR_LIBS . "xmlrpcs.inc.php");
+include_libs('xmlrpc.inc.php',false,false);
+include_libs('xmlrpcs.inc.php',false,false);
+
+/* define xmlrpc settings */
+$xmlrpc_internalencoding = _CHARSET;
+$xmlrpc_defencoding = 'UTF-8';
 
 /* definition of available methods */
 
 $functionDefs = array();
 
-// load server functions 
+// load server functions
 include('api_blogger.inc.php');
 include('api_metaweblog.inc.php');
 // include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods
@@ -91,13 +102,13 @@ function _addItem($blogid, $username, $password, $title, $body, $more, $publish,
        return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname);
 }
 
-/** 
+/**
   * Adds item to blog, with time of item given
   */
 function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") {
        // 1. login
        $mem = new MEMBER();
-       
+
        if (!$mem->login($username, $password))
                return _error(1,"Could not log in");
 
@@ -111,7 +122,7 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
 
        // 3. calculate missing vars
        $blog = new BLOG($blogid);
-       
+
        // get category id (or id for default category when false category)
        $catid = $blog->getCategoryIdFromName($catname);
 
@@ -121,10 +132,10 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
                $draft = 1;
        if ($closed != 1)
                $closed = 0;
-       
+
        // 4. add to blog
        $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft);
-       
+
        // [TODO] ping weblogs.com ?
 
        return new xmlrpcresp(new xmlrpcval($itemid,"string"));
@@ -135,21 +146,21 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
   */
 function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) {
        global $manager;
-       
+
        // 1. login
        $mem = new MEMBER();
        if (!$mem->login($username, $password))
                return _error(1,"Could not log in");
-       
+
        // 2. check if allowed to add to blog
        if (!$manager->existsItem($itemid,1,1))
                return _error(6,"No such item ($itemid)");
        if (!$mem->canAlterItem($itemid))
                return _error(7,"Not allowed to alter item");
-               
+
        // 3. update item
        ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0);
-       
+
        return new xmlrpcresp(new xmlrpcval(1,"boolean"));
 }
 
@@ -163,20 +174,20 @@ function _getUsersBlogs($username, $password) {
                return _error(1,"Could not log in");
 
        // 2. Get list of blogs
-       
+
        $structarray = array();
        $query =  "SELECT bnumber, bname, burl"
-               . ' FROM '.sql_table('blog').', '.sql_table('team')
-               . " WHERE tblog=bnumber and tmember=" . $mem->getID()
-               . " ORDER BY bname";
+                       . ' FROM '.sql_table('blog').', '.sql_table('team')
+                       . " WHERE tblog=bnumber and tmember=" . $mem->getID()
+                       . " ORDER BY bname";
        $r = sql_query($query);
-       
-       while ($obj = mysql_fetch_object($r)) {
+
+       while ($obj = sql_fetch_object($r)) {
                if ($obj->burl)
                        $blogurl = $obj->burl;
                else
                        $blogurl = 'http://';
-       
+
                $newstruct = new xmlrpcval(array(
                        "url" => new xmlrpcval($blogurl,"string"),
                        "blogid" => new xmlrpcval($obj->bnumber,"string"),
@@ -184,7 +195,7 @@ function _getUsersBlogs($username, $password) {
                ),'struct');
                array_push($structarray, $newstruct);
        }
-       
+
        return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
 }
 
@@ -197,7 +208,7 @@ function _getUserInfo($username, $password) {
 
        // 3. return the info
        // Structure returned has nickname, userid, url, email, lastname, firstname
-       
+
        $newstruct = new xmlrpcval(array(
                "nickname" => new xmlrpcval($mem->getDisplayName(),"string"),
                "userid" => new xmlrpcval($mem->getID(),"string"),
@@ -206,9 +217,9 @@ function _getUserInfo($username, $password) {
                "lastname" => new xmlrpcval("","string"),
                "firstname" => new xmlrpcval($mem->getRealName(),"string")
        ),'struct');
-       
+
        return new xmlrpcresp($newstruct);
-       
+
 
 }
 
@@ -223,16 +234,16 @@ function _deleteItem($itemid, $username, $password) {
        if (!$mem->login($username, $password))
                return _error(1,"Could not log in");
 
-       // 2. check if allowed 
+       // 2. check if allowed
        if (!$manager->existsItem($itemid,1,1))
                return _error(6,"No such item ($itemid)");
        $blogid = getBlogIDFromItemID($itemid);
        if (!$mem->teamRights($blogid))
                return _error(3,"Not a team member");
-               
+
        // delete the item
-       ITEM::delete($itemid);  
-       
+       ITEM::delete($itemid);
+
        return new xmlrpcresp(new xmlrpcval(1,"boolean"));
 }
 
@@ -244,18 +255,18 @@ function _getSkinPart($blogid, $username, $password, $type) {
        $mem = new MEMBER();
        if (!$mem->login($username, $password))
                return _error(1,"Could not log in");
-               
+
        // 2. check if allowed
        if (!BLOG::existsID($blogid))
                return _error(2,"No such blog ($blogid)");
        if (!$mem->teamRights($blogid))
                return _error(3,"Not a team member");
-       
+
        // 3. return skin part
        $blog = new BLOG($blogid);
        $skin = new SKIN($blog->getDefaultSkin());
        return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string"));
-       
+
 }
 
 function _setSkinPart($blogid, $username, $password, $content, $type) {
@@ -263,25 +274,25 @@ function _setSkinPart($blogid, $username, $password, $content, $type) {
        $mem = new MEMBER();
        if (!$mem->login($username, $password))
                return _error(1,"Could not log in");
-               
+
        // 2. check if allowed
        if (!BLOG::existsID($blogid))
                return _error(2,"No such blog ($blogid)");
        if (!$mem->teamRights($blogid))
                return _error(3,"Not a team member");
-               
+
        // 3. update skin part
        $blog = new BLOG($blogid);
        $skin = new SKIN($blog->getDefaultSkin());
        $skin->update($type, $content);
-       
+
        return new xmlrpcresp(new xmlrpcval(1,'boolean'));
 }
 
 /**
   * Some convenience methods
   */
-  
+
 function _getScalar($m, $idx) {
        $v = $m->getParam($idx);
        return $v->scalarval();
@@ -289,11 +300,14 @@ function _getScalar($m, $idx) {
 
 function _getStructVal($struct, $key) {
        $t = $struct->structmem($key);
-       return $t->scalarval();
+       if (!$t) 
+               return '';      // no such struct value
+       else
+               return $t->scalarval();
 }
 
 function _getArrayVal($a, $idx) {
-       $t = $a->arraymem(0);
+       $t = $a->arraymem($idx);
        return $t->scalarval();
 }