| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.32 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 4 * Copyright (C) 2002-2007 The Nucleus Group 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * (see nucleus/documentation/index.html#license for more info) 11 */ 12 13 /** 14 * This script is provides an XML-RPC [1] interface to Nucleus [2]. 15 * 16 * At this time, the Blogger API [3], the metaWeblog API [4] and 17 * parts of the Movable Type API [5] are implemented 18 * 19 * This script uses the the 'XML-RPC for PHP v1.02' implementation [6] 20 * All other code was written by Wouter Demuynck [7] 21 * 22 * [1] http://www.xmlrpc.com/ 23 * [2] http://nucleuscms.org/ 24 * [3] http://plant.blogger.com/api/ 25 * [4] http://www.xmlrpc.com/metaWeblogApi 26 * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html 27 * [6] http://phpxmlrpc.sourceforge.net/ 28 * [7] http://demuynck.org/ 29 * 30 * 31 * The Blogger API: (more info in the documentation) 32 * 33 * blogger.newPost 34 * blogger.editPost 35 * blogger.getUsersBlogs 36 * blogger.deletePost 37 * blogger.getRecentPosts 38 * blogger.getPost 39 * blogger.getUserInfo 40 * blogger.getTemplate 41 * blogger.setTemplate 42 * 43 * Note: The getUserInfo response contains an empty 'lastname' and the full name as 44 * 'firstname' 45 * Note: Blogger API methods only affect the body field of items 46 * 47 * The metaWeblog API (more info in documentation) 48 * 49 * metaWeblog.newPost 50 * metaWeblog.getPost 51 * metaWeblog.editPost 52 * metaWeblog.getCategories 53 * metaWeblog.newMediaObject 54 * metaWeblog.getRecentPosts 55 * 56 * Note: metaWeblog API methods only affect the body and title fields of items. 57 * the extended part is left untouched (and empty for new posts) 58 * 59 * The Movable Type API 60 * 61 * mt.supportedMethods 62 * 63 * @license http://nucleuscms.org/license.txt GNU General Public License 64 * @copyright Copyright (C) 2002-2007 The Nucleus Group 65 * @version $Id: server.php 1201 2007-09-07 07:12:21Z kimitake $ 66 */ 67 $CONF = array(); 68 require ("../../config.php"); // include Nucleus libs and code 69 include($DIR_LIBS . "xmlrpc.inc.php"); 70 include($DIR_LIBS . "xmlrpcs.inc.php"); 71 72 /* define xmlrpc settings */ 73 $xmlrpc_internalencoding = _CHARSET; 74 $xmlrpc_defencoding = 'UTF-8'; 75 76 /* definition of available methods */ 77 78 $functionDefs = array(); 79 80 // load server functions 81 include ('api_blogger.inc.php'); 82 include ('api_metaweblog.inc.php'); 83 // include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods 84 include ('api_mt.inc.php'); 85 86 87 // create server 88 $s = new xmlrpc_server( $functionDefs ); 89 90 91 /* ------------------------------ private functions ---------------------------------- */ 92 93 /** 94 * Adds an item to the given blog. Username and password are required to login 95 */ 96 function _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $catname = "") { 97 $blog = new BLOG($blogid); 98 $timestamp = $blog->getCorrectTime(); 99 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname); 100 } 101 102 /** 103 * Adds item to blog, with time of item given 104 */ 105 function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") { 106 // 1. login 107 $mem = new MEMBER(); 108 109 if (!$mem->login($username, $password)) 110 return _error(1,"Could not log in"); 111 112 // 2. check if allowed to add to blog 113 if (!BLOG::existsID($blogid)) 114 return _error(2,"No such blog ($blogid)"); 115 if (!$mem->teamRights($blogid)) 116 return _error(3,"Not a team member"); 117 if (!trim($body)) 118 return _error(4,"Cannot add empty items!"); 119 120 // 3. calculate missing vars 121 $blog = new BLOG($blogid); 122 123 // get category id (or id for default category when false category) 124 $catid = $blog->getCategoryIdFromName($catname); 125 126 if ($publish == 1) 127 $draft = 0; 128 else 129 $draft = 1; 130 if ($closed != 1) 131 $closed = 0; 132 133 // 4. add to blog 134 $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft); 135 136 // [TODO] ping weblogs.com ? 137 138 return new xmlrpcresp(new xmlrpcval($itemid,"string")); 139 } 140 141 /** 142 * Updates an item. Username and password are required to login 143 */ 144 function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) { 145 global $manager; 146 147 // 1. login 148 $mem = new MEMBER(); 149 if (!$mem->login($username, $password)) 150 return _error(1,"Could not log in"); 151 152 // 2. check if allowed to add to blog 153 if (!$manager->existsItem($itemid,1,1)) 154 return _error(6,"No such item ($itemid)"); 155 if (!$mem->canAlterItem($itemid)) 156 return _error(7,"Not allowed to alter item"); 157 158 // 3. update item 159 ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0); 160 161 return new xmlrpcresp(new xmlrpcval(1,"boolean")); 162 } 163 164 /** 165 * Gives the list of blogs to which the user with given name and password has access 166 */ 167 function _getUsersBlogs($username, $password) { 168 // 1. Try to login 169 $mem = new MEMBER(); 170 if (!$mem->login($username, $password)) 171 return _error(1,"Could not log in"); 172 173 // 2. Get list of blogs 174 175 $structarray = array(); 176 $query = "SELECT bnumber, bname, burl" 177 . ' FROM '.sql_table('blog').', '.sql_table('team') 178 . " WHERE tblog=bnumber and tmember=" . $mem->getID() 179 . " ORDER BY bname"; 180 $r = sql_query($query); 181 182 while ($obj = mysql_fetch_object($r)) { 183 if ($obj->burl) 184 $blogurl = $obj->burl; 185 else 186 $blogurl = 'http://'; 187 188 $newstruct = new xmlrpcval(array( 189 "url" => new xmlrpcval($blogurl,"string"), 190 "blogid" => new xmlrpcval($obj->bnumber,"string"), 191 "blogName" => new xmlrpcval($obj->bname,"string") 192 ),'struct'); 193 array_push($structarray, $newstruct); 194 } 195 196 return new xmlrpcresp(new xmlrpcval( $structarray , "array")); 197 } 198 199 200 function _getUserInfo($username, $password) { 201 // 1. login 202 $mem = new MEMBER(); 203 if (!$mem->login($username, $password)) 204 return _error(1,"Could not log in"); 205 206 // 3. return the info 207 // Structure returned has nickname, userid, url, email, lastname, firstname 208 209 $newstruct = new xmlrpcval(array( 210 "nickname" => new xmlrpcval($mem->getDisplayName(),"string"), 211 "userid" => new xmlrpcval($mem->getID(),"string"), 212 "url" => new xmlrpcval($mem->getURL(),"string"), 213 "email" => new xmlrpcval($mem->getEmail(),"string"), 214 "lastname" => new xmlrpcval("","string"), 215 "firstname" => new xmlrpcval($mem->getRealName(),"string") 216 ),'struct'); 217 218 return new xmlrpcresp($newstruct); 219 220 221 } 222 223 /** 224 * deletes an item 225 */ 226 function _deleteItem($itemid, $username, $password) { 227 global $manager; 228 229 // 1. login 230 $mem = new MEMBER(); 231 if (!$mem->login($username, $password)) 232 return _error(1,"Could not log in"); 233 234 // 2. check if allowed 235 if (!$manager->existsItem($itemid,1,1)) 236 return _error(6,"No such item ($itemid)"); 237 $blogid = getBlogIDFromItemID($itemid); 238 if (!$mem->teamRights($blogid)) 239 return _error(3,"Not a team member"); 240 241 // delete the item 242 ITEM::delete($itemid); 243 244 return new xmlrpcresp(new xmlrpcval(1,"boolean")); 245 } 246 247 /** 248 * Returns a template 249 */ 250 function _getSkinPart($blogid, $username, $password, $type) { 251 // 1. login 252 $mem = new MEMBER(); 253 if (!$mem->login($username, $password)) 254 return _error(1,"Could not log in"); 255 256 // 2. check if allowed 257 if (!BLOG::existsID($blogid)) 258 return _error(2,"No such blog ($blogid)"); 259 if (!$mem->teamRights($blogid)) 260 return _error(3,"Not a team member"); 261 262 // 3. return skin part 263 $blog = new BLOG($blogid); 264 $skin = new SKIN($blog->getDefaultSkin()); 265 return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string")); 266 267 } 268 269 function _setSkinPart($blogid, $username, $password, $content, $type) { 270 // 1. login 271 $mem = new MEMBER(); 272 if (!$mem->login($username, $password)) 273 return _error(1,"Could not log in"); 274 275 // 2. check if allowed 276 if (!BLOG::existsID($blogid)) 277 return _error(2,"No such blog ($blogid)"); 278 if (!$mem->teamRights($blogid)) 279 return _error(3,"Not a team member"); 280 281 // 3. update skin part 282 $blog = new BLOG($blogid); 283 $skin = new SKIN($blog->getDefaultSkin()); 284 $skin->update($type, $content); 285 286 return new xmlrpcresp(new xmlrpcval(1,'boolean')); 287 } 288 289 /** 290 * Some convenience methods 291 */ 292 293 function _getScalar($m, $idx) { 294 $v = $m->getParam($idx); 295 return $v->scalarval(); 296 } 297 298 function _getStructVal($struct, $key) { 299 $t = $struct->structmem($key); 300 if (!$t) 301 return ''; // no such struct value 302 else 303 return $t->scalarval(); 304 } 305 306 function _getArrayVal($a, $idx) { 307 $t = $a->arraymem($idx); 308 return $t->scalarval(); 309 } 310 311 /** 312 * Returns an XML-RPC error response 313 * $err is the error number (>0, will be added to $xmlrpcerruser) 314 */ 315 function _error($err, $msg) { 316 global $xmlrpcerruser; 317 return new xmlrpcresp(0, $xmlrpcerruser + $err, $msg); 318 } 319 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Feb 12 15:34:36 2008 | Cross-referenced by PHPXref 0.7 |