server.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00012 
00068 $CONF = array();
00069 require("../../config.php");    // include Nucleus libs and code
00070 include($DIR_LIBS . "xmlrpc.inc.php");
00071 include($DIR_LIBS . "xmlrpcs.inc.php");
00072 
00073 /* define xmlrpc settings */
00074 $xmlrpc_internalencoding = _CHARSET;
00075 $xmlrpc_defencoding = 'UTF-8';
00076 
00077 /* definition of available methods */
00078 
00079 $functionDefs = array();
00080 
00081 // load server functions
00082 include('api_blogger.inc.php');
00083 include('api_metaweblog.inc.php');
00084 // include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods
00085 include('api_mt.inc.php');
00086 
00087 
00088 // create server
00089 $s = new xmlrpc_server( $functionDefs );
00090 
00091 
00092 /* ------------------------------ private functions ---------------------------------- */
00093 
00097 function _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $catname = "") {
00098         $blog = new BLOG($blogid);
00099         $timestamp = $blog->getCorrectTime();
00100         return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname);
00101 }
00102 
00106 function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") {
00107         // 1. login
00108         $mem = new MEMBER();
00109 
00110         if (!$mem->login($username, $password))
00111                 return _error(1,"Could not log in");
00112 
00113         // 2. check if allowed to add to blog
00114         if (!BLOG::existsID($blogid))
00115                 return _error(2,"No such blog ($blogid)");
00116         if (!$mem->teamRights($blogid))
00117                 return _error(3,"Not a team member");
00118         if (!trim($body))
00119                 return _error(4,"Cannot add empty items!");
00120 
00121         // 3. calculate missing vars
00122         $blog = new BLOG($blogid);
00123 
00124         // get category id (or id for default category when false category)
00125         $catid = $blog->getCategoryIdFromName($catname);
00126 
00127         if ($publish == 1)
00128                 $draft = 0;
00129         else
00130                 $draft = 1;
00131         if ($closed != 1)
00132                 $closed = 0;
00133 
00134         // 4. add to blog
00135         $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft);
00136 
00137         // [TODO] ping weblogs.com ?
00138 
00139         return new xmlrpcresp(new xmlrpcval($itemid,"string"));
00140 }
00141 
00145 function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) {
00146         global $manager;
00147 
00148         // 1. login
00149         $mem = new MEMBER();
00150         if (!$mem->login($username, $password))
00151                 return _error(1,"Could not log in");
00152 
00153         // 2. check if allowed to add to blog
00154         if (!$manager->existsItem($itemid,1,1))
00155                 return _error(6,"No such item ($itemid)");
00156         if (!$mem->canAlterItem($itemid))
00157                 return _error(7,"Not allowed to alter item");
00158 
00159         // 3. update item
00160         ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0);
00161 
00162         return new xmlrpcresp(new xmlrpcval(1,"boolean"));
00163 }
00164 
00168 function _getUsersBlogs($username, $password) {
00169         // 1. Try to login
00170         $mem = new MEMBER();
00171         if (!$mem->login($username, $password))
00172                 return _error(1,"Could not log in");
00173 
00174         // 2. Get list of blogs
00175 
00176         $structarray = array();
00177         $query =  "SELECT bnumber, bname, burl"
00178                         . ' FROM '.sql_table('blog').', '.sql_table('team')
00179                         . " WHERE tblog=bnumber and tmember=" . $mem->getID()
00180                         . " ORDER BY bname";
00181         $r = sql_query($query);
00182 
00183         while ($obj = mysql_fetch_object($r)) {
00184                 if ($obj->burl)
00185                         $blogurl = $obj->burl;
00186                 else
00187                         $blogurl = 'http://';
00188 
00189                 $newstruct = new xmlrpcval(array(
00190                         "url" => new xmlrpcval($blogurl,"string"),
00191                         "blogid" => new xmlrpcval($obj->bnumber,"string"),
00192                         "blogName" => new xmlrpcval($obj->bname,"string")
00193                 ),'struct');
00194                 array_push($structarray, $newstruct);
00195         }
00196 
00197         return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
00198 }
00199 
00200 
00201 function _getUserInfo($username, $password) {
00202         // 1. login
00203         $mem = new MEMBER();
00204         if (!$mem->login($username, $password))
00205                 return _error(1,"Could not log in");
00206 
00207         // 3. return the info
00208         // Structure returned has nickname, userid, url, email, lastname, firstname
00209 
00210         $newstruct = new xmlrpcval(array(
00211                 "nickname" => new xmlrpcval($mem->getDisplayName(),"string"),
00212                 "userid" => new xmlrpcval($mem->getID(),"string"),
00213                 "url" => new xmlrpcval($mem->getURL(),"string"),
00214                 "email" => new xmlrpcval($mem->getEmail(),"string"),
00215                 "lastname" => new xmlrpcval("","string"),
00216                 "firstname" => new xmlrpcval($mem->getRealName(),"string")
00217         ),'struct');
00218 
00219         return new xmlrpcresp($newstruct);
00220 
00221 
00222 }
00223 
00227 function _deleteItem($itemid, $username, $password) {
00228         global $manager;
00229 
00230         // 1. login
00231         $mem = new MEMBER();
00232         if (!$mem->login($username, $password))
00233                 return _error(1,"Could not log in");
00234 
00235         // 2. check if allowed
00236         if (!$manager->existsItem($itemid,1,1))
00237                 return _error(6,"No such item ($itemid)");
00238         $blogid = getBlogIDFromItemID($itemid);
00239         if (!$mem->teamRights($blogid))
00240                 return _error(3,"Not a team member");
00241 
00242         // delete the item
00243         ITEM::delete($itemid);
00244 
00245         return new xmlrpcresp(new xmlrpcval(1,"boolean"));
00246 }
00247 
00251 function _getSkinPart($blogid, $username, $password, $type) {
00252         // 1. login
00253         $mem = new MEMBER();
00254         if (!$mem->login($username, $password))
00255                 return _error(1,"Could not log in");
00256 
00257         // 2. check if allowed
00258         if (!BLOG::existsID($blogid))
00259                 return _error(2,"No such blog ($blogid)");
00260         if (!$mem->teamRights($blogid))
00261                 return _error(3,"Not a team member");
00262 
00263         // 3. return skin part
00264         $blog = new BLOG($blogid);
00265         $skin = new SKIN($blog->getDefaultSkin());
00266         return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string"));
00267 
00268 }
00269 
00270 function _setSkinPart($blogid, $username, $password, $content, $type) {
00271         // 1. login
00272         $mem = new MEMBER();
00273         if (!$mem->login($username, $password))
00274                 return _error(1,"Could not log in");
00275 
00276         // 2. check if allowed
00277         if (!BLOG::existsID($blogid))
00278                 return _error(2,"No such blog ($blogid)");
00279         if (!$mem->teamRights($blogid))
00280                 return _error(3,"Not a team member");
00281 
00282         // 3. update skin part
00283         $blog = new BLOG($blogid);
00284         $skin = new SKIN($blog->getDefaultSkin());
00285         $skin->update($type, $content);
00286 
00287         return new xmlrpcresp(new xmlrpcval(1,'boolean'));
00288 }
00289 
00294 function _getScalar($m, $idx) {
00295         $v = $m->getParam($idx);
00296         return $v->scalarval();
00297 }
00298 
00299 function _getStructVal($struct, $key) {
00300         $t = $struct->structmem($key);
00301         if (!$t) 
00302                 return '';      // no such struct value
00303         else
00304                 return $t->scalarval();
00305 }
00306 
00307 function _getArrayVal($a, $idx) {
00308         $t = $a->arraymem($idx);
00309         return $t->scalarval();
00310 }
00311 
00316 function _error($err, $msg) {
00317         global $xmlrpcerruser;
00318         return new xmlrpcresp(0, $xmlrpcerruser + $err, $msg);
00319 }
00320 ?>



Generated on Wed Jun 25 17:25:59 2008 by  doxygen 1.5.5