-<?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
- */
-$CONF = array();
-include("../../config.php"); // include Nucleus libs and code
-include($DIR_LIBS . "xmlrpc.inc.php");
-include($DIR_LIBS . "xmlrpcs.inc.php");
-
-/* definition of available methods */
-
-$functionDefs = array();
-
-// 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
-include('api_mt.inc.php');
-
-
-// create server
-$s = new xmlrpc_server( $functionDefs );
-
-
-/* ------------------------------ private functions ---------------------------------- */
-
-/**
- * Adds an item to the given blog. Username and password are required to login
- */
-function _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $catname = "") {
- $blog = new BLOG($blogid);
- $timestamp = $blog->getCorrectTime();
- 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");
-
- // 2. check if allowed to add to blog
- if (!BLOG::existsID($blogid))
- return _error(2,"No such blog ($blogid)");
- if (!$mem->teamRights($blogid))
- return _error(3,"Not a team member");
- if (!trim($body))
- return _error(4,"Cannot add empty items!");
-
- // 3. calculate missing vars
- $blog = new BLOG($blogid);
-
- // get category id (or id for default category when false category)
- $catid = $blog->getCategoryIdFromName($catname);
-
- if ($publish == 1)
- $draft = 0;
- else
- $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"));
-}
-
-/**
- * Updates an item. Username and password are required to login
- */
-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"));
-}
-
-/**
- * Gives the list of blogs to which the user with given name and password has access
- */
-function _getUsersBlogs($username, $password) {
- // 1. Try to login
- $mem = new MEMBER();
- if (!$mem->login($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";
- $r = sql_query($query);
-
- while ($obj = mysql_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"),
- "blogName" => new xmlrpcval($obj->bname,"string")
- ),'struct');
- array_push($structarray, $newstruct);
- }
-
- return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
-}
-
-
-function _getUserInfo($username, $password) {
- // 1. login
- $mem = new MEMBER();
- if (!$mem->login($username, $password))
- return _error(1,"Could not log in");
-
- // 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"),
- "url" => new xmlrpcval($mem->getURL(),"string"),
- "email" => new xmlrpcval($mem->getEmail(),"string"),
- "lastname" => new xmlrpcval("","string"),
- "firstname" => new xmlrpcval($mem->getRealName(),"string")
- ),'struct');
-
- return new xmlrpcresp($newstruct);
-
-
-}
-
-/**
- * deletes an item
- */
-function _deleteItem($itemid, $username, $password) {
- global $manager;
-
- // 1. login
- $mem = new MEMBER();
- if (!$mem->login($username, $password))
- return _error(1,"Could not log in");
-
- // 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);
-
- return new xmlrpcresp(new xmlrpcval(1,"boolean"));
-}
-
-/**
- * Returns a template
- */
-function _getSkinPart($blogid, $username, $password, $type) {
- // 1. login
- $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) {
- // 1. login
- $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();
-}
-
-function _getStructVal($struct, $key) {
- $t = $struct->structmem($key);
- return $t->scalarval();
-}
-
-function _getArrayVal($a, $idx) {
- $t = $a->arraymem(0);
- return $t->scalarval();
-}
-
-/**
- * Returns an XML-RPC error response
- * $err is the error number (>0, will be added to $xmlrpcerruser)
- */
-function _error($err, $msg) {
- global $xmlrpcerruser;
- return new xmlrpcresp(0, $xmlrpcerruser + $err, $msg);
-}
+<?php\r
+/** \r
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
+ * Copyright (C) 2002-2004 The Nucleus Group\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * (see nucleus/documentation/index.html#license for more info)\r
+ *\r
+ * This script is provides an XML-RPC [1] interface to Nucleus [2].\r
+ *\r
+ * At this time, the Blogger API [3], the metaWeblog API [4] and \r
+ * parts of the Movable Type API [5] are implemented\r
+ *\r
+ * This script uses the the 'XML-RPC for PHP v1.02' implementation [6]\r
+ * All other code was written by Wouter Demuynck [7]\r
+ *\r
+ * [1] http://www.xmlrpc.com/\r
+ * [2] http://nucleuscms.org/\r
+ * [3] http://plant.blogger.com/api/\r
+ * [4] http://www.xmlrpc.com/metaWeblogApi\r
+ * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html\r
+ * [6] http://phpxmlrpc.sourceforge.net/\r
+ * [7] http://demuynck.org/\r
+ *\r
+ *\r
+ * The Blogger API: (more info in the documentation)\r
+ *\r
+ * blogger.newPost \r
+ * blogger.editPost \r
+ * blogger.getUsersBlogs \r
+ * blogger.deletePost\r
+ * blogger.getRecentPosts\r
+ * blogger.getPost\r
+ * blogger.getUserInfo\r
+ * blogger.getTemplate\r
+ * blogger.setTemplate\r
+ *\r
+ * Note: The getUserInfo response contains an empty 'lastname' and the full name as \r
+ * 'firstname'\r
+ * Note: Blogger API methods only affect the body field of items\r
+ *\r
+ * The metaWeblog API (more info in documentation)\r
+ *\r
+ * metaWeblog.newPost\r
+ * metaWeblog.getPost\r
+ * metaWeblog.editPost\r
+ * metaWeblog.getCategories\r
+ * metaWeblog.newMediaObject\r
+ * metaWeblog.getRecentPosts\r
+ *\r
+ * Note: metaWeblog API methods only affect the body and title fields of items. \r
+ * the extended part is left untouched (and empty for new posts)\r
+ *\r
+ * The Movable Type API\r
+ *\r
+ * mt.supportedMethods\r
+ */\r
+$CONF = array();\r
+include("../../config.php"); // include Nucleus libs and code\r
+include($DIR_LIBS . "xmlrpc.inc.php");\r
+include($DIR_LIBS . "xmlrpcs.inc.php");\r
+\r
+/* definition of available methods */\r
+\r
+$functionDefs = array();\r
+\r
+// load server functions \r
+include('api_blogger.inc.php');\r
+include('api_metaweblog.inc.php');\r
+// include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods\r
+include('api_mt.inc.php');\r
+\r
+\r
+// create server\r
+$s = new xmlrpc_server( $functionDefs );\r
+\r
+\r
+/* ------------------------------ private functions ---------------------------------- */\r
+\r
+/**\r
+ * Adds an item to the given blog. Username and password are required to login\r
+ */\r
+function _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $catname = "") {\r
+ $blog = new BLOG($blogid);\r
+ $timestamp = $blog->getCorrectTime();\r
+ return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname);\r
+}\r
+\r
+/** \r
+ * Adds item to blog, with time of item given\r
+ */\r
+function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") {\r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ \r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+\r
+ // 2. check if allowed to add to blog\r
+ if (!BLOG::existsID($blogid))\r
+ return _error(2,"No such blog ($blogid)");\r
+ if (!$mem->teamRights($blogid))\r
+ return _error(3,"Not a team member");\r
+ if (!trim($body))\r
+ return _error(4,"Cannot add empty items!");\r
+\r
+ // 3. calculate missing vars\r
+ $blog = new BLOG($blogid);\r
+ \r
+ // get category id (or id for default category when false category)\r
+ $catid = $blog->getCategoryIdFromName($catname);\r
+\r
+ if ($publish == 1)\r
+ $draft = 0;\r
+ else\r
+ $draft = 1;\r
+ if ($closed != 1)\r
+ $closed = 0;\r
+ \r
+ // 4. add to blog\r
+ $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft);\r
+ \r
+ // [TODO] ping weblogs.com ?\r
+\r
+ return new xmlrpcresp(new xmlrpcval($itemid,"string"));\r
+}\r
+\r
+/**\r
+ * Updates an item. Username and password are required to login\r
+ */\r
+function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) {\r
+ global $manager;\r
+ \r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+ \r
+ // 2. check if allowed to add to blog\r
+ if (!$manager->existsItem($itemid,1,1))\r
+ return _error(6,"No such item ($itemid)");\r
+ if (!$mem->canAlterItem($itemid))\r
+ return _error(7,"Not allowed to alter item");\r
+ \r
+ // 3. update item\r
+ ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0);\r
+ \r
+ return new xmlrpcresp(new xmlrpcval(1,"boolean"));\r
+}\r
+\r
+/**\r
+ * Gives the list of blogs to which the user with given name and password has access\r
+ */\r
+function _getUsersBlogs($username, $password) {\r
+ // 1. Try to login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+\r
+ // 2. Get list of blogs\r
+ \r
+ $structarray = array();\r
+ $query = "SELECT bnumber, bname, burl"\r
+ . ' FROM '.sql_table('blog').', '.sql_table('team')\r
+ . " WHERE tblog=bnumber and tmember=" . $mem->getID()\r
+ . " ORDER BY bname";\r
+ $r = sql_query($query);\r
+ \r
+ while ($obj = mysql_fetch_object($r)) {\r
+ if ($obj->burl)\r
+ $blogurl = $obj->burl;\r
+ else\r
+ $blogurl = 'http://';\r
+ \r
+ $newstruct = new xmlrpcval(array(\r
+ "url" => new xmlrpcval($blogurl,"string"),\r
+ "blogid" => new xmlrpcval($obj->bnumber,"string"),\r
+ "blogName" => new xmlrpcval($obj->bname,"string")\r
+ ),'struct');\r
+ array_push($structarray, $newstruct);\r
+ }\r
+ \r
+ return new xmlrpcresp(new xmlrpcval( $structarray , "array"));\r
+}\r
+\r
+\r
+function _getUserInfo($username, $password) {\r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+\r
+ // 3. return the info\r
+ // Structure returned has nickname, userid, url, email, lastname, firstname\r
+ \r
+ $newstruct = new xmlrpcval(array(\r
+ "nickname" => new xmlrpcval($mem->getDisplayName(),"string"),\r
+ "userid" => new xmlrpcval($mem->getID(),"string"),\r
+ "url" => new xmlrpcval($mem->getURL(),"string"),\r
+ "email" => new xmlrpcval($mem->getEmail(),"string"),\r
+ "lastname" => new xmlrpcval("","string"),\r
+ "firstname" => new xmlrpcval($mem->getRealName(),"string")\r
+ ),'struct');\r
+ \r
+ return new xmlrpcresp($newstruct);\r
+ \r
+\r
+}\r
+\r
+/**\r
+ * deletes an item\r
+ */\r
+function _deleteItem($itemid, $username, $password) {\r
+ global $manager;\r
+\r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+\r
+ // 2. check if allowed \r
+ if (!$manager->existsItem($itemid,1,1))\r
+ return _error(6,"No such item ($itemid)");\r
+ $blogid = getBlogIDFromItemID($itemid);\r
+ if (!$mem->teamRights($blogid))\r
+ return _error(3,"Not a team member");\r
+ \r
+ // delete the item\r
+ ITEM::delete($itemid); \r
+ \r
+ return new xmlrpcresp(new xmlrpcval(1,"boolean"));\r
+}\r
+\r
+/**\r
+ * Returns a template\r
+ */\r
+function _getSkinPart($blogid, $username, $password, $type) {\r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+ \r
+ // 2. check if allowed\r
+ if (!BLOG::existsID($blogid))\r
+ return _error(2,"No such blog ($blogid)");\r
+ if (!$mem->teamRights($blogid))\r
+ return _error(3,"Not a team member");\r
+ \r
+ // 3. return skin part\r
+ $blog = new BLOG($blogid);\r
+ $skin = new SKIN($blog->getDefaultSkin());\r
+ return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string"));\r
+ \r
+}\r
+\r
+function _setSkinPart($blogid, $username, $password, $content, $type) {\r
+ // 1. login\r
+ $mem = new MEMBER();\r
+ if (!$mem->login($username, $password))\r
+ return _error(1,"Could not log in");\r
+ \r
+ // 2. check if allowed\r
+ if (!BLOG::existsID($blogid))\r
+ return _error(2,"No such blog ($blogid)");\r
+ if (!$mem->teamRights($blogid))\r
+ return _error(3,"Not a team member");\r
+ \r
+ // 3. update skin part\r
+ $blog = new BLOG($blogid);\r
+ $skin = new SKIN($blog->getDefaultSkin());\r
+ $skin->update($type, $content);\r
+ \r
+ return new xmlrpcresp(new xmlrpcval(1,'boolean'));\r
+}\r
+\r
+/**\r
+ * Some convenience methods\r
+ */\r
+ \r
+function _getScalar($m, $idx) {\r
+ $v = $m->getParam($idx);\r
+ return $v->scalarval();\r
+}\r
+\r
+function _getStructVal($struct, $key) {\r
+ $t = $struct->structmem($key);\r
+ return $t->scalarval();\r
+}\r
+\r
+function _getArrayVal($a, $idx) {\r
+ $t = $a->arraymem(0);\r
+ return $t->scalarval();\r
+}\r
+\r
+/**\r
+ * Returns an XML-RPC error response\r
+ * $err is the error number (>0, will be added to $xmlrpcerruser)\r
+ */\r
+function _error($err, $msg) {\r
+ global $xmlrpcerruser;\r
+ return new xmlrpcresp(0, $xmlrpcerruser + $err, $msg);\r
+}\r
?>
\ No newline at end of file