File indexing completed on 2024-12-22 05:33:23
0001 <?php 0002 0003 include_once("gfx3/lib.php"); 0004 0005 /** 0006 * OCS Lib 0007 * 0008 * @author Frank Karlitschek 0009 * @copyright 2010 Frank Karlitschek karlitschek@kde.org 0010 * 0011 * This library is free software; you can redistribute it and/or 0012 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 0013 * License as published by the Free Software Foundation; either 0014 * version 3 of the License, or any later version. 0015 * 0016 * This library is distributed in the hope that it will be useful, 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0019 * GNU AFFERO GENERAL PUBLIC LICENSE for more details. 0020 * 0021 * You should have received a copy of the GNU Lesser General Public 0022 * License along with this library. If not, see <http://www.gnu.org/licenses/> 0023 * 0024 0025 0026 Documentation: 0027 This libary is an example implementation of the Open Collaboration Services Specification you find here: 0028 http://www.freedesktop.org/wiki/Specifications/open-collaboration-services 0029 0030 This libary is using PHP 5.x and MySQL 5.x 0031 The OCS Libary is just an example implementation you can use as a reference or inspiration. 0032 It will probalby not run on your server unmodified because your datasources are different. But you should 0033 get an impression how the REST interface works and how you can make your data available in an OCS compatible way 0034 0035 You need a database table to track the API traffic. 0036 The table should look like this: 0037 0038 CREATE TABLE IF NOT EXISTS `apitraffic` ( 0039 `ip` bigint(20) NOT NULL, 0040 `count` int(11) NOT NULL, 0041 PRIMARY KEY (`ip`) 0042 ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 0043 0044 You have to force apache to parse this file even it it doesn´t end with .php 0045 0046 This version use apache .htaccess. 0047 Make sure your webserver can use .htaccess file and mod_rewrite is installed and available fr this site. 0048 0049 0050 */ 0051 0052 /** 0053 * Class to handle open collaboration services API requests 0054 * 0055 */ 0056 class H01_OCS { 0057 0058 /** 0059 * define some configuration variables 0060 **/ 0061 public $whitelist; 0062 public $maxpersonsearchpage; 0063 public $maxrequests; // per 15min from one IP 0064 public $maxrequestsauthenticated; 0065 0066 public function __construct(){ 0067 $this->whitelist = EConfig::$data["whitelist"]; 0068 $this->maxpersonsearchpage = 200; 0069 $this->maxrequests = 1000; // per 15min from one IP 0070 $this->maxrequestsauthenticated = 2000; 0071 OCSUser::load(); 0072 } 0073 0074 /** 0075 * reads input date from get/post/cookies and converts the date to a special data-type 0076 * 0077 * @param variable $key 0078 * @param variable-type $type Supported variable types are: raw, text, int, float, array 0079 * @param priority $getpriority 0080 * @param default $default 0081 * @return data 0082 */ 0083 public function readdata($key,$type='raw',$getpriority=false,$default='') { 0084 if($getpriority) { 0085 if(isset($_GET[$key])) { 0086 $data=$_GET[$key]; 0087 } elseif(isset($_POST[$key])) { 0088 $data=$_POST[$key]; 0089 } else { 0090 if($default=='') { 0091 if(($type=='int') or ($type=='float')) $data=0; else $data=''; 0092 } else { 0093 $data=$default; 0094 } 0095 } 0096 } else { 0097 if(isset($_POST[$key])) { 0098 $data=$_POST[$key]; 0099 } elseif(isset($_GET[$key])) { 0100 $data=$_GET[$key]; 0101 } elseif(isset($_COOKIE[$key])) { 0102 $data=$_COOKIE[$key]; 0103 } else { 0104 if($default=='') { 0105 if(($type=='int') or ($type=='float')) $data=0; else $data=''; 0106 } else { 0107 $data=$default; 0108 } 0109 } 0110 } 0111 0112 if($type=='raw') return($data); 0113 elseif($type=='text') return(addslashes(strip_tags($data))); 0114 elseif($type=='int') { $data = (int) $data; return($data); } 0115 elseif($type=='float') { $data = (float) $data; return($data); } 0116 elseif($type=='array') { $data = $data; return($data); } 0117 else { H01_UTIL::exception('readdata: internal error:'.$type); return(false); } 0118 } 0119 0120 0121 /** 0122 main function to handle the REST request 0123 **/ 0124 public function handle() { 0125 0126 // overwrite the 404 error page returncode 0127 header("HTTP/1.0 200 OK"); 0128 0129 0130 if($_SERVER['REQUEST_METHOD'] == 'GET') { 0131 $method='get'; 0132 }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { 0133 $method='put'; 0134 parse_str(file_get_contents("php://input"),$put_vars); 0135 }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { 0136 $method='post'; 0137 }else{ 0138 echo('internal server error: method not supported'); 0139 exit(); 0140 } 0141 0142 // preprocess url 0143 $url=$_SERVER['PHP_SELF']; 0144 $url = str_replace("server.php", "v1", $url); 0145 0146 if(substr($url,(strlen($url)-1))<>'/') $url.='/'; 0147 $ex=explode('/',$url); 0148 0149 // eventhandler 0150 if(count($ex)==2){ 0151 H01_GUI::showtemplate('apidoc'); 0152 0153 0154 // CONFIG 0155 // apiconfig - GET - CONFIG 0156 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='config') and (count($ex)==4)){ 0157 $format=$this->readdata('format','text'); 0158 $this->apiconfig($format); 0159 0160 0161 // personsearch - GET - PERSON/DATA parameter als url parameter 0162 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0163 $format=$this->readdata('format','text'); 0164 $username=$this->readdata('name','text'); 0165 $country=$this->readdata('country','text'); 0166 $city=$this->readdata('city','text'); 0167 $description=$this->readdata('description','text'); 0168 $pc=$this->readdata('pc','text'); 0169 $software=$this->readdata('software','text'); 0170 $longitude=$this->readdata('longitude','float'); 0171 $latitude=$this->readdata('latitude','float'); 0172 $distance=$this->readdata('distance','float'); 0173 0174 $attributeapp=$this->readdata('attributeapp','text'); 0175 $attributekey=$this->readdata('attributekey','text'); 0176 $attributevalue=$this->readdata('attributevalue','text'); 0177 0178 $page=$this->readdata('page','int'); 0179 $pagesize=$this->readdata('pagesize','int'); 0180 if($pagesize<1 or $pagesize>100) $pagesize=10; 0181 $this->personsearch($format,$username,$country,$city,$description,$pc,$software,$longitude,$latitude,$distance,$attributeapp,$attributekey,$attributevalue,$page,$pagesize); 0182 0183 // personget - GET - PERSON/DATA/frank 0184 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0185 $format=$this->readdata('format','text'); 0186 $username=addslashes($ex[4]); 0187 $this->personget($format,$username); 0188 0189 // personaccountbalance - GET - PERSON/BALANCE 0190 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='balance') and (count($ex)==5)){ 0191 $format=$this->readdata('format','text'); 0192 $this->persongetbalance($format); 0193 0194 // personget - GET - PERSON/SELF 0195 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='self') and (count($ex)==5)){ 0196 $format=$this->readdata('format','text'); 0197 $this->personget($format); 0198 0199 // personedit - POST - PERSON/SELF 0200 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='self') and (count($ex)==5)){ 0201 $format=$this->readdata('format','text'); 0202 $longitude=$this->readdata('longitude','float'); 0203 $latitude=$this->readdata('latitude','float'); 0204 $country=$this->readdata('country','text'); 0205 $city=$this->readdata('city','text'); 0206 $this->personedit($format,$longitude,$latitude,$country,$city); 0207 0208 // personcheck - POST - PERSON/CHECK 0209 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='check') and (count($ex)==5)){ 0210 $format=$this->readdata('format','text'); 0211 $login=$this->readdata('login','text'); 0212 $passwd=$this->readdata('password','text'); 0213 $this->personcheck($format,$login,$passwd); 0214 0215 // personadd - POST - PERSON/ADD 0216 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0217 $format=$this->readdata('format','text'); 0218 $login=$this->readdata('login','text'); 0219 $passwd=$this->readdata('password','text'); 0220 $firstname=$this->readdata('firstname','text'); 0221 $lastname=$this->readdata('lastname','text'); 0222 $email=$this->readdata('email','text'); 0223 $this->personadd($format,$login,$passwd,$firstname,$lastname,$email); 0224 0225 // persongetea - GET - PERSON/ATTRIBUTES/frank/parley/key 0226 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==8)){ 0227 $format=$this->readdata('format','text'); 0228 $username= addslashes($ex[4]); 0229 $app= addslashes($ex[5]); 0230 $key= addslashes($ex[6]); 0231 $this->personattributeget($format,$username,$app,$key); 0232 0233 // persongetea - GET - PERSON/ATTRIBUTES/frank/parley 0234 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==7)){ 0235 $format=$this->readdata('format','text'); 0236 $username= addslashes($ex[4]); 0237 $app= addslashes($ex[5]); 0238 $key= ''; 0239 $this->personattributeget($format,$username,$app,$key); 0240 0241 // persongetea - GET - PERSON/ATTRIBUTES/frank 0242 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==6)){ 0243 $format=$this->readdata('format','text'); 0244 $username= addslashes($ex[4]); 0245 $app= ''; 0246 $key= ''; 0247 $this->personattributeget($format,$username,$app,$key); 0248 0249 // persondeleteea - POST - PERSON/DELETEATTRIBUTE/app/key 0250 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='deleteattribute') and (count($ex)==7)){ 0251 $format=$this->readdata('format','text'); 0252 $app= addslashes($ex[4]); 0253 $key= addslashes($ex[5]); 0254 $this->personattributedelete($format,$app,$key); 0255 0256 // personsetea - POST - PERSON/SETATTRIBUTE/app/key 0257 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='setattribute') and (count($ex)==7)){ 0258 $format=$this->readdata('format','text'); 0259 $app= addslashes($ex[4]); 0260 $key= addslashes($ex[5]); 0261 $value=$this->readdata('value','text'); 0262 $this->personattributeset($format,$app,$key,$value); 0263 0264 0265 0266 // FAN 0267 //fanget - GET - FAN/DATA/"contentid" - page,pagesize als url parameter, 0268 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0269 $format=$this->readdata('format','text'); 0270 $content=addslashes($ex[4]); 0271 $page=$this->readdata('page','int'); 0272 $pagesize=$this->readdata('pagesize','int'); 0273 if($pagesize<1 or $pagesize>100) $pagesize=10; 0274 $this->fanget($format,$content,$page,$pagesize); 0275 0276 //isfan - GET - FAN/STATUS/"contentid" 0277 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='status') and (count($ex)==6)){ 0278 $format=$this->readdata('format','text'); 0279 $content=addslashes($ex[4]); 0280 $this->isfan($format,$content); 0281 0282 //addfan - POST - FAN/ADD/"contentid" 0283 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='add') and (count($ex)==6)){ 0284 $format=$this->readdata('format','text'); 0285 $content=addslashes($ex[4]); 0286 $this->addfan($format,$content); 0287 0288 //removefan - POST - FAN/REMOVE/"contentid" 0289 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='remove') and (count($ex)==6)){ 0290 $format=$this->readdata('format','text'); 0291 $content=addslashes($ex[4]); 0292 $this->removefan($format,$content); 0293 0294 0295 0296 // FRIEND 0297 //friendget - GET - FRIEND/DATA/"personid" - page,pagesize als url parameter, 0298 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0299 $format=$this->readdata('format','text'); 0300 $username=addslashes($ex[4]); 0301 $page=$this->readdata('page','int'); 0302 $pagesize=$this->readdata('pagesize','int'); 0303 if($pagesize<1 or $pagesize>100) $pagesize=10; 0304 $this->friendget($format,$username,$page,$pagesize); 0305 0306 //friendinvite - POST - FRIEND/INVITE/"username"/ message als url parameter 0307 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='invite') and (count($ex)==6)){ 0308 $format=$this->readdata('format','text'); 0309 $username=addslashes($ex[4]); 0310 $message=$this->readdata('message','text'); 0311 $this->friendinvite($format,$username,$message); 0312 0313 //friendapprove - POST - FRIEND/APPROVE/"username"/ 0314 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='approve') and (count($ex)==6)){ 0315 $format=$this->readdata('format','text'); 0316 $username=addslashes($ex[4]); 0317 $this->friendapprove($format,$username); 0318 0319 //frienddecline - POST - FRIEND/DECLINE/"username"/ 0320 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='decline') and (count($ex)==6)){ 0321 $format=$this->readdata('format','text'); 0322 $username=addslashes($ex[4]); 0323 $this->frienddecline($format,$username); 0324 0325 //friendcancel - POST - FRIEND/CANCEL/"username"/ 0326 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='cancel') and (count($ex)==6)){ 0327 $format=$this->readdata('format','text'); 0328 $username=addslashes($ex[4]); 0329 $this->friendcancel($format,$username); 0330 0331 //friendcancelinvitation - POST - FRIEND/CANCEL/"username"/ 0332 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='cancelinvitation') and (count($ex)==6)){ 0333 $format=$this->readdata('format','text'); 0334 $username=addslashes($ex[4]); 0335 $this->friendcancelinvitation($format,$username); 0336 0337 //friendsentinvitations - GET - FRIEND/SENTINVITATIONS/ 0338 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='sentinvitations') and (count($ex)==5)){ 0339 $format=$this->readdata('format','text'); 0340 $page=$this->readdata('page','int'); 0341 $pagesize=$this->readdata('pagesize','int'); 0342 if($pagesize<1 or $pagesize>100) $pagesize=10; 0343 $this->friendsentinvitations($format,$page,$pagesize); 0344 0345 //friendreceivedinvitations - GET - FRIEND/RECEIVEDINVITATIONS/ 0346 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='receivedinvitations') and (count($ex)==5)){ 0347 $format=$this->readdata('format','text'); 0348 $page=$this->readdata('page','int'); 0349 $pagesize=$this->readdata('pagesize','int'); 0350 if($pagesize<1 or $pagesize>100) $pagesize=10; 0351 $this->friendreceivedinvitations($format,$page,$pagesize); 0352 0353 0354 // MESSAGE 0355 //messagefolders - GET - MESSAGE/ 0356 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==4)){ 0357 $format=$this->readdata('format','text'); 0358 $this->messagefolders($format); 0359 0360 //messagelist - GET - MESSAGE/"folderid"/ page,pagesize als url parameter 0361 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==5)){ 0362 $format=$this->readdata('format','text'); 0363 $folder= (int) addslashes($ex[3]); 0364 $filter=$this->readdata('status','text'); 0365 $page=$this->readdata('page','int'); 0366 $pagesize=$this->readdata('pagesize','int'); 0367 if($pagesize<1 or $pagesize>100) $pagesize=10; 0368 $this->messagelist($format,$folder,$page,$pagesize,$filter); 0369 0370 // messagesend - POST - MESSAGE/"folderid" 0371 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (strtolower($ex[3])=='2') and (count($ex)==5)){ 0372 $format=$this->readdata('format','text'); 0373 $touser=$this->readdata('to','text'); 0374 $subject=$this->readdata('subject','text'); 0375 $message=$this->readdata('message','text'); 0376 $this->messagesend($format,$touser,$subject,$message); 0377 0378 // messageget - GET - MESSAGE/"folderid"/"messageid" 0379 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==6)){ 0380 $format=$this->readdata('format','text'); 0381 $folder= (int) addslashes($ex[3]); 0382 $message= (int) addslashes($ex[4]); 0383 $this->messageget($format,$folder,$message); 0384 0385 0386 // ACTIVITY 0387 // activityget - GET ACTIVITY page,pagesize als urlparameter 0388 }elseif(($method=='get') and (strtolower($ex[1])=='v1')and (strtolower($ex[2])=='activity') and (count($ex)==4)){ 0389 $format=$this->readdata('format','text'); 0390 $page=$this->readdata('page','int'); 0391 $pagesize=$this->readdata('pagesize','int'); 0392 if($pagesize<1 or $pagesize>100) $pagesize=10; 0393 $this->activityget($format,$page,$pagesize); 0394 0395 // activityput - POST ACTIVITY 0396 }elseif(($method=='post') and (strtolower($ex[1])=='v1')and (strtolower($ex[2])=='activity') and (count($ex)==4)){ 0397 $format=$this->readdata('format','text'); 0398 $message=$this->readdata('message','text'); 0399 $this->activityput($format,$message); 0400 0401 0402 // CONTENT 0403 // contentcategories - GET - CONTENT/CATEGORIES 0404 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='categories') and (count($ex)==5)){ 0405 $format=$this->readdata('format','text'); 0406 $this->contentcategories($format); 0407 0408 // contentlicense - GET - CONTENT/LICENSES 0409 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='licenses') and (count($ex)==5)){ 0410 $format=$this->readdata('format','text'); 0411 $this->contentlicenses($format); 0412 0413 // contentdistributions - GET - CONTENT/DISTRIBUTIONS 0414 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='distributions') and (count($ex)==5)){ 0415 $format=$this->readdata('format','text'); 0416 $this->contentdistributions($format); 0417 0418 // contentdependencies - GET - CONTENT/DISTRIBUTIONS 0419 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='dependencies') and (count($ex)==5)){ 0420 $format=$this->readdata('format','text'); 0421 $this->contentdependencies($format); 0422 0423 // contenthomepage - GET - CONTENT/HOMPAGES 0424 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='homepages') and (count($ex)==5)){ 0425 $format=$this->readdata('format','text'); 0426 $this->contenthomepages($format); 0427 0428 0429 // contentlist - GET - CONTENT/DATA - category,search,sort,page,pagesize 0430 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0431 $format=$this->readdata('format','text'); 0432 $contents=$this->readdata('categories','text'); 0433 $searchstr=$this->readdata('search','text'); 0434 $searchuser=$this->readdata('user','text'); 0435 $external=$this->readdata('external','text'); 0436 $distribution=$this->readdata('distribution','text'); 0437 $license=$this->readdata('license','text'); 0438 $sortmode=$this->readdata('sortmode','text'); 0439 $page=$this->readdata('page','int'); 0440 $pagesize=$this->readdata('pagesize','int'); 0441 if($pagesize<1 or $pagesize>100) $pagesize=10; 0442 $this->contentlist($format,$contents,$searchstr,$searchuser,$external,$distribution,$license,$sortmode,$page,$pagesize); 0443 0444 // contentget - GET - CONTENT/DATA/"id" 0445 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0446 $format=$this->readdata('format','text'); 0447 $id= addslashes($ex[4]); 0448 $this->contentget($format,$id); 0449 0450 // contentdownload - GET - CONTENT/DOWNLOAD/"id"/"item" 0451 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='download') and (count($ex)==7)){ 0452 $format=$this->readdata('format','text'); 0453 $id= addslashes($ex[4]); 0454 $item= addslashes($ex[5]); 0455 $this->contentdownload($format,$id,$item); 0456 0457 // getrecommendations - GET - CONTENT/RECOMMENDATIONS/"id" 0458 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='recommendations') and (count($ex)==6)){ 0459 $format=$this->readdata('format','text'); 0460 $id= addslashes($ex[4]); 0461 $page=$this->readdata('page','int'); 0462 $pagesize=$this->readdata('pagesize','int'); 0463 $this->contentrecommendations($id,$format,$page,$pagesize); 0464 0465 0466 // contentvote - POST - CONTENT/VOTE/"id" - good/bad als url parameter 0467 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='vote') and (count($ex)==6)){ 0468 $format=$this->readdata('format','text'); 0469 $id= addslashes($ex[4]); 0470 $vote=$this->readdata('vote','text'); 0471 $this->contentvote($format,$id,$vote); 0472 0473 // contentpreviewdelete - POST - CONTENT/DELETEPREVIEW/"contentid"/"previewid" 0474 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='deletepreview') and (count($ex)==7)){ 0475 $format=$this->readdata('format','text'); 0476 $contentid= addslashes($ex[4]); 0477 $previewid= addslashes($ex[5]); 0478 $this->contentpreviewdelete($format,$contentid,$previewid); 0479 0480 // contentpreviewupload - POST - CONTENT/UPLOADPREVIEW/"contentid"/"previewid" 0481 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='uploadpreview') and (count($ex)==7)){ 0482 $format=$this->readdata('format','text'); 0483 $contentid= addslashes($ex[4]); 0484 $previewid= addslashes($ex[5]); 0485 $this->contentpreviewupload($format,$contentid,$previewid); 0486 0487 // contentdownloaddelete - POST - CONTENT/DELETEDOWNLOAD/"contentid" 0488 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='deletedownload') and (count($ex)==6)){ 0489 $format=$this->readdata('format','text'); 0490 $contentid= addslashes($ex[4]); 0491 $this->contentdownloaddelete($format,$contentid); 0492 0493 // contentdownloadupload - POST - CONTENT/UPLOADDOWNLOAD/"contentid" 0494 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='uploaddownload') and (count($ex)==6)){ 0495 $format=$this->readdata('format','text'); 0496 $contentid= addslashes($ex[4]); 0497 $this->contentdownloadupload($format,$contentid); 0498 0499 // contentadd - POST - CONTENT/ADD 0500 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0501 $format=$this->readdata('format','text'); 0502 $this->contentadd($format); 0503 0504 // contentedit - POST - CONTENT/EDIT/"contentid" 0505 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='edit') and (count($ex)==6)){ 0506 $format=$this->readdata('format','text'); 0507 $contentid = addslashes($ex[4]); 0508 $this->contentedit($format,$contentid); 0509 0510 // contentdelete - POST - CONTENT/DELETE/"contentid" 0511 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='delete') and (count($ex)==6)){ 0512 $format=$this->readdata('format','text'); 0513 $contentid= addslashes($ex[4]); 0514 $this->contentdelete($format,$contentid); 0515 0516 0517 0518 // KNOWLEDGEBASE 0519 0520 // knowledgebaseget - GET - KNOWLEDGEBASE/DATA/"id" 0521 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='knowledgebase') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0522 $format=$this->readdata('format','text'); 0523 $id= addslashes($ex[4]); 0524 $this->knowledgebaseget($format,$id); 0525 0526 // knowledgebaselist - GET - KNOWLEDGEBASE/DATA - category,search,sort,page,pagesize 0527 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='knowledgebase') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0528 $format=$this->readdata('format','text'); 0529 $contents=$this->readdata('content','text'); 0530 $searchstr=$this->readdata('search','text'); 0531 $sortmode=$this->readdata('sortmode','text'); 0532 $page=$this->readdata('page','int'); 0533 $pagesize=$this->readdata('pagesize','int'); 0534 if($pagesize<1 or $pagesize>100) $pagesize=10; 0535 $this->knowledgebaselist($format,$contents,$searchstr,$sortmode,$page,$pagesize); 0536 0537 0538 // EVENT 0539 0540 // eventget - GET - EVENT/DATA/"id" 0541 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0542 $format=$this->readdata('format','text'); 0543 $id= addslashes($ex[4]); 0544 $this->eventget($format,$id); 0545 0546 // eventlist - GET - EVENT/DATA - type,country,startat,search,sort,page,pagesize 0547 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0548 $format=$this->readdata('format','text'); 0549 $type=$this->readdata('type','int'); 0550 $country=$this->readdata('country','text'); 0551 $startat=$this->readdata('startat','text'); 0552 $searchstr=$this->readdata('search','text'); 0553 $sortmode=$this->readdata('sortmode','text'); 0554 $page=$this->readdata('page','int'); 0555 $pagesize=$this->readdata('pagesize','int'); 0556 if($pagesize<1 or $pagesize>100) $pagesize=10; 0557 $this->eventlist($format,$type,$country,$startat,$searchstr,$sortmode,$page,$pagesize); 0558 0559 0560 // eventadd - POST - EVENT/ADD 0561 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0562 $format=$this->readdata('format','text'); 0563 $this->eventadd($format); 0564 0565 // eventedit - POST - EVENT/EDIT/"eventid" 0566 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='edit') and (count($ex)==6)){ 0567 $format=$this->readdata('format','text'); 0568 $eventid= addslashes($ex[4]); 0569 $this->eventedit($format,$eventid); 0570 0571 // eventdelete - POST - EVENT/DELETE/"eventid" 0572 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='delete') and (count($ex)==6)){ 0573 $format=$this->readdata('format','text'); 0574 $eventid= addslashes($ex[4]); 0575 $this->eventdelete($format,$eventid); 0576 0577 0578 // COMMENTS 0579 0580 // commentsget - GET - COMMENTS/GET 0581 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='data') and (count($ex)==8)){ 0582 $type= addslashes($ex[4]); 0583 $content= addslashes($ex[5]); 0584 $content2= addslashes($ex[6]); 0585 $format=$this->readdata('format','text'); 0586 $page=$this->readdata('page','int'); 0587 $pagesize=$this->readdata('pagesize','int'); 0588 if($pagesize<1 or $pagesize>2000) $pagesize=10; 0589 $this->commentsget($format,$type,$content,$content2,$page,$pagesize); 0590 0591 // commentsadd - POST - COMMENTS/ADD 0592 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0593 $format=$this->readdata('format','text'); 0594 $type=$this->readdata('type','int'); 0595 $content=$this->readdata('content','int'); 0596 $content2=$this->readdata('content2','int'); 0597 $parent=$this->readdata('parent','int'); 0598 $subject=$this->readdata('subject','text'); 0599 $message=$this->readdata('message','text'); 0600 $this->commentsadd($format,$type,$content,$content2,$parent,$subject,$message); 0601 0602 // commentvote - GET - COMMENTS/vote 0603 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='vote') and (count($ex)==6)){ 0604 $id = addslashes($ex[4]); 0605 $score = $this->readdata('vote','int'); 0606 $format=$this->readdata('format','text'); 0607 $this->commentvote($format,$id,$score); 0608 0609 0610 // FORUM 0611 0612 }elseif(strtolower($ex[1])=='v1' and strtolower($ex[2])=='forum'){ 0613 $functioncall=strtolower($ex[3]); 0614 $subcall=strtolower($ex[4]); 0615 $argumentcount=count($ex); 0616 // list - GET - FORUM/LIST 0617 if($method=='get' and $functioncall=='list' and $argumentcount==4){ 0618 $format=$this->readdata('format','text'); 0619 $page=$this->readdata('page','int'); 0620 $pagesize=$this->readdata('pagesize','int'); 0621 // TOPIC section 0622 }elseif($functioncall=='topic'){ 0623 // list - GET - FORUM/TOPIC/LIST 0624 if($method=='get' and $subcall=='list' and $argumentcount==10){ 0625 $format=$this->readdata('format','text'); 0626 $forum=$this->readdata('forum','int'); 0627 $search=$this->readdata('search','text'); 0628 $description=$this->readdata('description','text'); 0629 $sortmode=$this->readdata('sortmode','text'); 0630 $page=$this->readdata('page','int'); 0631 $pagesize=$this->readdata('pagesize','int'); 0632 // add - POST - FORUM/TOPIC/ADD 0633 }elseif($method=='post' and $subcall=='add' and $argumentcount==5){ 0634 $format=$this->readdata('format','text'); 0635 $subject=$this->readdata('subject','text'); 0636 $content=$this->readdata('content','text'); 0637 $forum=$this->readdata('forum','int'); 0638 } 0639 } 0640 0641 // BUILDSERVICE 0642 0643 0644 }elseif(strtolower($ex[1])=='v1' and strtolower($ex[2])=='buildservice' and count($ex)>4){ 0645 $functioncall=strtolower($ex[4]); 0646 $argumentcount=count($ex); 0647 // PROJECT section 0648 if(strtolower($ex[3]=='project')){ 0649 // create - POST - PROJECT/CREATE 0650 if($method=='post' and $functioncall=='create' and $argumentcount==6){ 0651 $format=$this->readdata('format','text'); 0652 $name=$this->readdata('name','text'); 0653 $version=$this->readdata('version','text'); 0654 $license=$this->readdata('license','text'); 0655 $url=$this->readdata('url','text'); 0656 $developers=$this->readdata('developers','text'); 0657 $summary=$this->readdata('summary','text'); 0658 $description=$this->readdata('description','text'); 0659 $requirements=$this->readdata('requirements','text'); 0660 $specfile=$this->readdata('specfile','text'); 0661 0662 $this->buildserviceprojectcreate($format,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 0663 // get - GET - PROJECT/GET/"project" 0664 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0665 $format=$this->readdata('format','text'); 0666 $projectID=$ex[5]; 0667 0668 $this->buildserviceprojectget($format,$projectID); 0669 // delete - POST - PROJECT/DELETE/"project" 0670 }elseif($method=='post' and $functioncall=='delete' and $argumentcount==7){ 0671 $format=$this->readdata('format','text'); 0672 $projectID=$ex[5]; 0673 0674 $this->buildserviceprojectdelete($format,$projectID); 0675 // edit - POST - ROJECT/EDIT/"project" 0676 }elseif($method=='post' and $functioncall=='edit' and $argumentcount==7){ 0677 $format=$this->readdata('format','text'); 0678 $projectID=$ex[5]; 0679 $name=$this->readdata('name','text'); 0680 $version=$this->readdata('version','text'); 0681 $license=$this->readdata('license','text'); 0682 $url=$this->readdata('url','text'); 0683 $developers=$this->readdata('developers','text'); 0684 $summary=$this->readdata('summary','text'); 0685 $description=$this->readdata('description','text'); 0686 $requirements=$this->readdata('requirements','text'); 0687 $specfile=$this->readdata('specfile','text'); 0688 $this->buildserviceprojectedit($format,$projectID,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 0689 // listall - GET - PROJECT/LIST 0690 }elseif($method=='get' and $functioncall=='list' and $argumentcount==6){ 0691 $format=$this->readdata('format','text'); 0692 $page=$this->readdata('page','int'); 0693 $pagesize=$this->readdata('pagesize','int'); 0694 $this->buildserviceprojectlist($format,$page,$pagesize); 0695 // generatespecfile - GET - PROJECT/UPLOADSOURCE 0696 }elseif($method=='post' and $functioncall=='uploadsource' and $argumentcount==7){ 0697 $format=$this->readdata('format','text'); 0698 $projectID=$ex[5]; 0699 $this->buildserviceprojectuploadsource($format,$projectID); 0700 }else{ 0701 $this->reportapisyntaxerror('buildservice/project'); 0702 } 0703 // REMOTEACCOUNTS section 0704 }elseif(strtolower($ex[3])=='remoteaccounts'){ 0705 if($method=='get' and $functioncall=='list' and $argumentcount==6){ 0706 $format=$this->readdata('format','text'); 0707 $page=$this->readdata('page','int'); 0708 $pagesize=$this->readdata('pagesize','int'); 0709 $this->buildserviceremoteaccountslist($format,$page,$pagesize); 0710 }elseif($method=='post' and $functioncall=='add' and $argumentcount==6){ 0711 $format=$this->readdata('format','text'); 0712 $type=$this->readdata('type','int'); 0713 $typeid=$this->readdata('typeid','text'); 0714 $data=$this->readdata('data','text'); 0715 $login=$this->readdata('login','text'); 0716 $password=$this->readdata('password','text'); 0717 $this->buildserviceremoteaccountsadd($format,$type,$typeid,$data,$login,$password); 0718 }elseif($method=='post' and $functioncall=='edit' and $argumentcount==7){ 0719 $format=$this->readdata('format','text'); 0720 $id=$ex[5]; 0721 $data=$this->readdata('data','text'); 0722 $login=$this->readdata('login','text'); 0723 $password=$this->readdata('password','text'); 0724 $this->buildserviceremoteaccountsedit($format,$id,$login,$password,$data); 0725 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0726 $format=$this->readdata('format','text'); 0727 $id=$ex[5]; 0728 $this->buildserviceremoteaccountsget($format,$id); 0729 }elseif($method=='post' and $functioncall=='remove' and $argumentcount==7){ 0730 $format=$this->readdata('format','text'); 0731 $id=$ex[5]; 0732 $this->buildserviceremoteaccountsremove($format,$id); 0733 }else{ 0734 $this->reportapisyntaxerror('buildservice/remoteaccounts'); 0735 } 0736 // BUILDSERVICES section 0737 }elseif(strtolower($ex[3]=='buildservices')){ 0738 if($method=='get' and $functioncall=='list' and $argumentcount==6){ 0739 $format=$this->readdata('format','text'); 0740 $page=$this->readdata('page','int'); 0741 $pagesize=$this->readdata('pagesize','int'); 0742 $this->buildservicebuildserviceslist($format,$page,$pagesize); 0743 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0744 $format=$this->readdata('format','text'); 0745 $buildserviceID=$ex[5]; 0746 $this->buildservicebuildservicesget($format,$buildserviceID); 0747 }else{ 0748 $this->reportapisyntaxerror('buildservice/buildservices'); 0749 } 0750 // JOBS section 0751 }elseif(strtolower($ex[3]=='jobs')){ 0752 // getbuildcapabilities - GET - JOBS/GETBUILDCAPABILITIES 0753 if($method=='get' and $functioncall=='list' and $argumentcount==7){ 0754 $format=$this->readdata('format','text'); 0755 $projectID=$ex[5]; 0756 $page=$this->readdata('page','int'); 0757 $pagesize=$this->readdata('pagesize','int'); 0758 $this->buildservicejobslist($format,$projectID,$page,$pagesize); 0759 // create - POST - JOBS/CREATE/"project"/"buildsevice"/"target" 0760 }elseif($method=='post' and $functioncall=='create' and $argumentcount==9){ 0761 $format=$this->readdata('format','text'); 0762 $projectID=$ex[5]; 0763 $buildserviceID=$ex[6]; 0764 $target=$ex[7]; 0765 $this->buildservicejobscreate($format,$projectID,$buildserviceID,$target); 0766 // cancel - POST - JOBS/CANCEL/"buildjob" 0767 }elseif($method=='post' and $functioncall=='cancel' and $argumentcount==7){ 0768 $format=$this->readdata('format','text'); 0769 $buildjobID=$ex[5]; 0770 $this->buildservicejobscancel($format,$buildjobID); 0771 // get - GET - JOBS/GET/"buildjob" 0772 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0773 $format=$this->readdata('format','text'); 0774 $buildjobID=$ex[5]; 0775 $this->buildservicejobsget($format,$buildjobID); 0776 // getoutput - GET - JOBS/GETOUTPOT/"buildjob" 0777 }elseif($method=='get' and $functioncall=='getoutput' and $argumentcount==7){ 0778 $format=$this->readdata('format','text'); 0779 $buildjobID=$ex[5]; 0780 $this->buildservicejobsgetoutput($format,$buildjobID); 0781 }else{ 0782 $this->reportapisyntaxerror('buildservice/jobs'); 0783 } 0784 // PUBLISHING section 0785 }elseif(strtolower($ex[3]=='publishing')){ 0786 // getpublishingcapabilities - GET - PUBLISHING/GETPUBLISHINGCAPABILITIES 0787 if($method=='get' and $functioncall=='getpublishingcapabilities' and $argumentcount==6){ 0788 $format=$this->readdata('format','text'); 0789 $page=$this->readdata('page','int'); 0790 $pagesize=$this->readdata('pagesize','int'); 0791 $this->buildservicepublishinggetpublishingcapabilities($format,$page,$pagesize); 0792 // getpublisher - GET - PUBLISHING/GETPUBLISHER 0793 }elseif($method=='get' and $functioncall=='getpublisher' and $argumentcount==7){ 0794 $format=$this->readdata('format','text'); 0795 $publisherID=$ex[5]; 0796 $this->buildservicepublishinggetpublisher($format,$publisherID); 0797 // publishtargetresult - POST - PUBLISHING/PUBLISHTARGETRESULT/"buildjob"/"publisher" 0798 }elseif($method=='post' and $functioncall=='publishtargetresult' and $argumentcount==8){ 0799 $format=$this->readdata('format','text'); 0800 $buildjobID=$ex[5]; 0801 $publisherID=$ex[6]; 0802 $this->buildservicepublishingpublishtargetresult($format,$buildjobID,$publisherID); 0803 // savefields - POST - PUBLISHING/SAVEFIELDS/"project" 0804 }elseif($method=='post' and $functioncall=='savefields' and $argumentcount==7){ 0805 $format=$this->readdata('format','text'); 0806 $projectID=$ex[5]; 0807 $fields=$this->readdata('fields','array'); 0808 $this->buildservicepublishingsavefields($format,$projectID,$fields); 0809 // getfields - GET - PUBLISHING/GETFIELDS/"project" 0810 }elseif($method=='get' and $functioncall=='getfields' and $argumentcount==7){ 0811 $format=$this->readdata('format','text'); 0812 $projectID=$ex[5]; 0813 $this->buildservicepublishinggetfields($format,$projectID); 0814 }else{ 0815 $this->reportapisyntaxerror('buildservice/publishing'); 0816 } 0817 }else{ 0818 $this->reportapisyntaxerror('buildservice'); 0819 } 0820 0821 0822 }else{ 0823 $format=$this->readdata('format','text'); 0824 $txt='please check the syntax. api specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services'."\n"; 0825 $txt.=$this->getdebugoutput(); 0826 echo($this->generatexml($format,'failed',999,$txt)); 0827 } 0828 exit(); 0829 } 0830 0831 /** 0832 * Use this function to inform the user that there is a syntax error in the API call. The function 0833 * will inform the user which module the error occured in. 0834 * @param apimodule The name of the module the error occured in 0835 */ 0836 private function reportapisyntaxerror($apimodule){ 0837 $format=$this->readdata('format','text'); 0838 $txt='please check the syntax of the module '.$apimodule.'. api specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services'."\n"; 0839 $txt.=$this->getdebugoutput(); 0840 echo($this->generatexml($format,'failed',999,$txt)); 0841 } 0842 0843 /** 0844 * generated some debug information to make it easier to find faild API calls 0845 * @return debug data string 0846 */ 0847 private function getdebugoutput() { 0848 $txt=''; 0849 $txt.="debug output:\n"; 0850 if(isset($_SERVER['REQUEST_METHOD'])) $txt.='http request method: '.$_SERVER['REQUEST_METHOD']."\n"; 0851 if(isset($_SERVER['REQUEST_URI'])) $txt.='http request uri: '.$_SERVER['REQUEST_URI']."\n"; 0852 if(isset($_GET)) foreach($_GET as $key=>$value) $txt.='get parameter: '.$key.'->'.$value."\n"; 0853 if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n"; 0854 return($txt); 0855 } 0856 0857 /** 0858 * checks if the user is authenticated 0859 * checks the IP whitlist, apikeys and login/password combination 0860 * if $forceuser is true and the authentication failed it returns an 401 http response. 0861 * if $forceuser is false and authentification fails it returns an empty username string 0862 * @param bool $forceuser 0863 * @return username string 0864 */ 0865 private function checkpassword($forceuser=true) { 0866 //valid user account ? 0867 if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser=''; 0868 if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw=''; 0869 0870 //this small (and dirty) hack checks if the client who requested the page is konqueror 0871 //which is also Qt itself 0872 //TODO: maybe fix this thing? 0873 if(isset($_SERVER['HTTP_USER_AGENT'])){ 0874 $iskonqueror = stristr($_SERVER['HTTP_USER_AGENT'],"Konqueror"); 0875 } else { 0876 $iskonqueror = false; 0877 } 0878 0879 if(empty($authuser)) { 0880 if($forceuser){ 0881 if(!$iskonqueror){ 0882 header("WWW-Authenticate: Basic realm=\"Private Area\""); 0883 header('HTTP/1.0 401 Unauthorized'); 0884 exit; 0885 } else { 0886 $txt=$this->generatexml('','failed',999,'needs authentication'); 0887 echo($txt); 0888 exit; 0889 } 0890 }else{ 0891 $identifieduser=''; 0892 } 0893 }else{ 0894 /* 0895 $user=H01_USER::finduserbyapikey($authuser,CONFIG_USERDB); 0896 if($user==false) { 0897 */ 0898 $user=OCSUser::checklogin($authuser,$authpw); 0899 if($user==false) { 0900 if($forceuser){ 0901 if(!$iskonqueror){ 0902 header("WWW-Authenticate: Basic realm=\"Private Area\""); 0903 header('HTTP/1.0 401 Unauthorized'); 0904 exit; 0905 } else { 0906 $txt=$this->generatexml('','failed',999,'needs authentication'); 0907 echo($txt); 0908 exit; 0909 } 0910 }else{ 0911 $identifieduser=''; 0912 } 0913 }else{ 0914 $identifieduser=$user; 0915 } 0916 /* 0917 }else{ 0918 $identifieduser=$user; 0919 }*/ 0920 } 0921 return $identifieduser; 0922 } 0923 0924 0925 /** 0926 * cleans up the api traffic limit database table. 0927 * this function should be call by a cronjob every 15 minutes 0928 */ 0929 public function cleanuptrafficlimit() { 0930 EDatabase::q('truncate ocs_apitraffic'); 0931 } 0932 0933 0934 0935 /** 0936 * check if the current user is allowed to do one more API call or if the traffic limit is exceeded. 0937 * @param string $user 0938 */ 0939 private function checktrafficlimit($user) { 0940 /* 0941 $ip = $_SERVER['REMOTE_ADDR']; 0942 if(!isset(EConfig::$data["whitelist"][$ip])){ 0943 // BACKUP: 0944 // $result = $db->insert('apitraffic','into apitraffic (ip,count) values ('.ip2long($_SERVER['REMOTE_ADDR']).',1) on duplicate key update count=count+1'); 0945 EDatabase::q('insert into ocs_apitraffic (ip,count) values ('.ip2long($_SERVER['REMOTE_ADDR']).',1) on duplicate key update count=count+1'); 0946 0947 $result = EDatabase::q('select * from ocs_apitraffic where ip="'.ip2long($_SERVER['REMOTE_ADDR']).'"'); 0948 $numrows = EDatabase::num_rows($result); 0949 $DBcount = EDatabase::fetch_assoc($result); 0950 0951 if($numrows==0) return(true); 0952 if($user=='') $max=$this->maxrequests; else $max=$this->maxrequestsauthenticated; 0953 0954 if($DBcount['count']>$max) { 0955 $format=$this->readdata('format','text'); 0956 echo($this->generatexml($format,'failed',200,'too many API requests in the last 15 minutes from your IP address. please try again later.')); 0957 exit(); 0958 } 0959 return(true); 0960 } else { 0961 return(true); 0962 } 0963 */ 0964 return true; 0965 0966 } 0967 0968 0969 0970 /** 0971 * generates the xml or json response for the API call from an multidimenional data array. 0972 * @param string $format 0973 * @param string $status 0974 * @param string $statuscode 0975 * @param string $message 0976 * @param array $data 0977 * @param string $tag 0978 * @param string $tagattribute 0979 * @param int $dimension 0980 * @param int $itemscount 0981 * @param int $itemsperpage 0982 * @return string xml/json 0983 */ 0984 private function generatexml($format,$status,$statuscode,$message,$data=array(),$tag='',$tagattribute='',$dimension=-1,$itemscount='',$itemsperpage='') { 0985 if($format=='json') { 0986 0987 $json=array(); 0988 $json['status']=$status; 0989 $json['statuscode']=$statuscode; 0990 $json['message']=$message; 0991 $json['totalitems']=$itemscount; 0992 $json['itemsperpage']=$itemsperpage; 0993 $json['data']=$data; 0994 return(json_encode($json)); 0995 0996 0997 }else{ 0998 $txt=''; 0999 $writer = xmlwriter_open_memory(); 1000 xmlwriter_set_indent( $writer, 2 ); 1001 xmlwriter_start_document($writer ); 1002 xmlwriter_start_element($writer,'ocs'); 1003 xmlwriter_start_element($writer,'meta'); 1004 xmlwriter_write_element($writer,'status',$status); 1005 xmlwriter_write_element($writer,'statuscode',$statuscode); 1006 xmlwriter_write_element($writer,'message',$message); 1007 if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount); 1008 if(!empty($itemsperpage)) xmlwriter_write_element($writer,'itemsperpage',$itemsperpage); 1009 xmlwriter_end_element($writer); 1010 //echo($dimension); 1011 if($dimension=='0') { 1012 // 0 dimensions 1013 xmlwriter_write_element($writer,'data',$data); 1014 1015 }elseif($dimension=='1') { 1016 xmlwriter_start_element($writer,'data'); 1017 foreach($data as $key=>$entry) { 1018 xmlwriter_write_element($writer,$key,$entry); 1019 } 1020 xmlwriter_end_element($writer); 1021 1022 }elseif($dimension=='2') { 1023 xmlwriter_start_element($writer,'data'); 1024 foreach($data as $entry) { 1025 xmlwriter_start_element($writer,$tag); 1026 if(!empty($tagattribute)) { 1027 xmlwriter_write_attribute($writer,'details',$tagattribute); 1028 } 1029 foreach($entry as $key=>$value) { 1030 if(is_array($value)){ 1031 foreach($value as $k=>$v) { 1032 xmlwriter_write_element($writer,$k,$v); 1033 } 1034 } else { 1035 xmlwriter_write_element($writer,$key,$value); 1036 } 1037 } 1038 xmlwriter_end_element($writer); 1039 } 1040 xmlwriter_end_element($writer); 1041 1042 }elseif($dimension=='3') { 1043 xmlwriter_start_element($writer,'data'); 1044 foreach($data as $entrykey=>$entry) { 1045 xmlwriter_start_element($writer,$tag); 1046 if(!empty($tagattribute)) { 1047 xmlwriter_write_attribute($writer,'details',$tagattribute); 1048 } 1049 foreach($entry as $key=>$value) { 1050 if(is_array($value)){ 1051 xmlwriter_start_element($writer,$entrykey); 1052 foreach($value as $k=>$v) { 1053 xmlwriter_write_element($writer,$k,$v); 1054 } 1055 xmlwriter_end_element($writer); 1056 } else { 1057 xmlwriter_write_element($writer,$key,$value); 1058 } 1059 } 1060 xmlwriter_end_element($writer); 1061 } 1062 xmlwriter_end_element($writer); 1063 }elseif($dimension=='dynamic') { 1064 xmlwriter_start_element($writer,'data'); 1065 // $this->toxml($writer,$data,'comment'); 1066 if(is_array($data)) $this->toxml($writer,$data,$tag); 1067 xmlwriter_end_element($writer); 1068 } 1069 1070 xmlwriter_end_element($writer); 1071 1072 xmlwriter_end_document( $writer ); 1073 $txt.=xmlwriter_output_memory( $writer ); 1074 unset($writer); 1075 return($txt); 1076 } 1077 } 1078 1079 /** 1080 * Take an array of any size, and make it into xml 1081 * @param xmlwriter An xmlwriter instance 1082 * @param array The array which is to be transformed 1083 * @param mixed Either a string, or an array of elements defining element names for each level in the XML hierarchy 1084 * In the case of multiple lists of differently titled items at the same level, adding an array inside the array will allow for this to be constructed. 1085 * @param int Internal use (the index of the child item in question - corresponds to the index in the second level array above) 1086 */ 1087 public function toxml($writer,$data,$node,$childindex=0) { 1088 $nodename=$node; 1089 if(is_array($node)){ 1090 $nodename=array_shift($node); 1091 } 1092 1093 $childcount=-1; 1094 foreach($data as $key => $value) { 1095 $childcount++; 1096 if (is_numeric($key)) { 1097 if(is_array($nodename)) { 1098 $key = $nodename[$childindex]; 1099 } else { 1100 $key = $nodename; 1101 } 1102 } 1103 if (is_array($value)){ 1104 xmlwriter_start_element($writer,$key); 1105 $this->toxml($writer,$value,$node,$childcount); 1106 xmlwriter_end_element($writer); 1107 }else{ 1108 xmlwriter_write_element($writer,$key,$value); 1109 } 1110 } 1111 if(is_array($node)) { 1112 array_unshift($node,$nodename); 1113 } 1114 } 1115 1116 1117 1118 1119 /** 1120 * return the config data of this server 1121 * @param string $format 1122 * @return string xml/json 1123 */ 1124 private function apiconfig($format) { 1125 $user=$this->checkpassword(false); 1126 $this->checktrafficlimit($user); 1127 1128 $xml['version']=EConfig::$data["ocsserver"]["version"];; 1129 $xml['website']=EConfig::$data["ocsserver"]["website"]; 1130 $xml['host']=EConfig::$data["ocsserver"]["host"];; 1131 $xml['contact']=EConfig::$data["ocsserver"]["contact"];; 1132 $xml['ssl']=EConfig::$data["ocsserver"]["ssl"];; 1133 echo($this->generatexml($format,'ok',100,'',$xml,'config','',1)); 1134 } 1135 1136 1137 1138 1139 // PERSON API ############################################# 1140 1141 /** 1142 * search and return a list of persons corresponding to different optional search parameters 1143 * @param string $format 1144 * @param string $username 1145 * @param string $country 1146 * @param string $city 1147 * @param string $description 1148 * @param string $pc 1149 * @param string $software 1150 * @param string $longitude 1151 * @param string $latitude 1152 * @param string $distance 1153 * @param string $attributeapp 1154 * @param string $attributekey 1155 * @param string $attributevalue 1156 * @param string $page 1157 * @param string $pagesize 1158 * @return string xml/json 1159 */ 1160 private function personsearch($format,$username,$country,$city,$description,$pc,$software,$longitude,$latitude,$distance,$attributeapp,$attributekey,$attributevalue,$page,$pagesize) { 1161 $user=$this->checkpassword(false); 1162 $this->checktrafficlimit($user); 1163 1164 $pl = new OCSPersonLister; 1165 $xml = $pl->ocs_person_search($username,$page,$pagesize); 1166 $plcount = count($xml); 1167 1168 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','summary',2,$plcount,$pagesize); 1169 1170 echo($txt); 1171 1172 } 1173 1174 /** 1175 * edit my own useraccount 1176 * @param string $format 1177 * @param string $country 1178 * @param string $city 1179 * @param float $longitude 1180 * @param float $latitude 1181 * @return string xml/json 1182 */ 1183 private function personedit($format,$longitude,$latitude,$country,$city) { 1184 $user=$this->checkpassword(); 1185 $this->checktrafficlimit($user); 1186 1187 if($latitude<>0 or $longitude<>0 or !empty($city) or !empty($country)){ 1188 H01_USER::edit($user,CONFIG_USERDB,$latitude,$longitude,$city,$country); 1189 1190 // cleanup the caches for this user. 1191 H01_CACHEADMIN::cleancache('userdetail',array($user)); 1192 H01_CACHEADMIN::cleancache('avatar',array($user)); 1193 H01_CACHEADMIN::cleancache('apipersonget',array($user)); 1194 H01_CACHEADMIN::cleancache('apipersonsearch',array()); 1195 echo($this->generatexml($format,'ok',100,'')); 1196 }else{ 1197 echo($this->generatexml($format,'failed',101,'no parameters to update found')); 1198 } 1199 } 1200 1201 1202 /** 1203 * register new user 1204 * @param string $format 1205 * @param string $login 1206 * @param string $passwd 1207 * @param string $firstname 1208 * @param string $lastname 1209 * @param string $email 1210 * @return string xml/json 1211 */ 1212 private function personadd($format,$login,$passwd,$firstname,$lastname,$email) { 1213 $user=$this->checkpassword(false); 1214 $this->checktrafficlimit($user); 1215 1216 if($login<>'' and $passwd<>'' and $firstname<>'' and $lastname<>'' and $email<>''){ 1217 if(OCSUser::isvalidpassword($passwd)){ 1218 if(OCSUser::isloginname($login)){ 1219 if(!OCSUser::exists($login)){ 1220 if(OCSUser::countusersbyemail($email)==0) { 1221 if(OCSUser::isvalidemail($email)) { 1222 OCSUser::register($login,$passwd,$firstname,$lastname,$email); 1223 echo($this->generatexml($format,'ok',100,'')); 1224 }else{ 1225 echo($this->generatexml($format,'failed',106,'email already taken')); 1226 } 1227 }else{ 1228 echo($this->generatexml($format,'failed',105,'email invalid')); 1229 } 1230 }else{ 1231 echo($this->generatexml($format,'failed',104,'login already exists')); 1232 } 1233 }else{ 1234 echo($this->generatexml($format,'failed',103,'please specify a valid login')); 1235 } 1236 }else{ 1237 echo($this->generatexml($format,'failed',102,'please specify a valid password')); 1238 } 1239 }else{ 1240 echo($this->generatexml($format,'failed',101,'please specify all mandatory fields')); 1241 } 1242 } 1243 1244 /** 1245 * TODO: fix personcheck 1246 * check if the provided login/apikey/password is valid 1247 * @param string $format 1248 * @param string $login 1249 * @param string $passwd 1250 * @return string xml/json 1251 */ 1252 private function personcheck($format,$login,$passwd) { 1253 $user=$this->checkpassword(false); 1254 $this->checktrafficlimit($user); 1255 1256 1257 if($login<>''){ 1258 $reallogin=OCSUser::checklogin($login,$passwd); // $login,CONFIG_USERDB,$passwd,PERM_Login 1259 if($reallogin<>false){ 1260 $xml['person']['personid']=$reallogin; 1261 echo($this->generatexml($format,'ok',100,'',$xml,'person','check',2)); 1262 }else{ 1263 /* 1264 * TODO: uncomment and implement login by API key 1265 $user=H01_USER::finduserbyapikey($login,CONFIG_USERDB); 1266 if($user==false) { 1267 */ 1268 echo($this->generatexml($format,'failed',102,'login not valid')); 1269 /* 1270 }else{ 1271 $xml['person']['personid']=$user; 1272 echo($this->generatexml($format,'ok',100,'',$xml,'person','check',2)); 1273 1274 } 1275 */ 1276 } 1277 }else{ 1278 echo($this->generatexml($format,'failed',101,'please specify all mandatory fields')); 1279 } 1280 } 1281 1282 1283 1284 /** 1285 * get detailed information about a person 1286 * @param string $format 1287 * @param string $username 1288 * @return string xml/json 1289 */ 1290 private function personget($format,$username='') { 1291 if(empty($username)) { 1292 $user=$this->checkpassword(); 1293 }else{ 1294 $user=$this->checkpassword(false); 1295 } 1296 $this->checktrafficlimit($user); 1297 if(empty($username)) $username=$user; 1298 1299 $DBuser = OCSUser::get_user_info($username); 1300 1301 if(is_null($DBuser)){ 1302 $txt=$this->generatexml($format,'failed',101,'person not found'); 1303 echo($txt); 1304 }else if (empty($user)) { 1305 }else{ 1306 $xml=array(); 1307 $xml[0]['personid']=$DBuser['login']; 1308 $xml[0]['firstname']=$DBuser['firstname']; 1309 $xml[0]['lastname']=$DBuser['lastname']; 1310 $xml[0]['email']=$DBuser['email']; 1311 //$xml[0]['description']=H01_UTIL::bbcode2html($DBuser['description']); 1312 1313 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','full',2); 1314 //$txt=$this->generatexml($format,'failed',102,'data is private'); 1315 echo($txt); 1316 } 1317 1318 } 1319 1320 1321 /** 1322 * get my own balance 1323 * @param string $format 1324 * @return string xml/json 1325 */ 1326 private function persongetbalance($format) { 1327 $user=$this->checkpassword(); 1328 $this->checktrafficlimit($user); 1329 1330 $balance=H01_PAYMENT::getbalance($user,CONFIG_USERDB); 1331 1332 $xml=array(); 1333 $xml[0]['currency']='USD'; 1334 $xml[0]['balance']=number_format(($balance/100),2); 1335 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','balance',2); 1336 echo($txt); 1337 } 1338 1339 1340 /** 1341 * get attributes from a specific person/app/key 1342 * @param string $format 1343 * @param string $username 1344 * @param string $app 1345 * @param string $key 1346 * @return string xml/json 1347 */ 1348 private function personattributeget($format,$username,$app,$key) { 1349 $user=$this->checkpassword(); 1350 $this->checktrafficlimit($user); 1351 1352 $xml=H01_USER::getattributes($username,CONFIG_USERDB,$app,$key); 1353 $xml2=array(); 1354 $xml2['attribute']=$xml; 1355 $txt=$this->generatexml($format,'ok',100,'',$xml2,'person','attributes',3,count($xml)); 1356 echo($txt); 1357 1358 } 1359 1360 /** 1361 * set a attribute 1362 * @param string $format 1363 * @param string $app 1364 * @param string $key 1365 * @param string $value 1366 * @return string xml/json 1367 */ 1368 private function personattributeset($format,$app,$key,$value) { 1369 $user=$this->checkpassword(); 1370 $this->checktrafficlimit($user); 1371 1372 $xml=H01_USER::setattribute($user,CONFIG_USERDB,$app,$key,$value); 1373 $txt=$this->generatexml($format,'ok',100,''); 1374 echo($txt); 1375 1376 } 1377 1378 1379 /** 1380 * delete a attribute 1381 * @param string $format 1382 * @param string $app 1383 * @param string $key 1384 * @return string xml/json 1385 */ 1386 private function personattributedelete($format,$app,$key) { 1387 $user=$this->checkpassword(); 1388 $this->checktrafficlimit($user); 1389 1390 $xml=H01_USER::deleteattribute($user,CONFIG_USERDB,$app,$key); 1391 $txt=$this->generatexml($format,'ok',100,''); 1392 echo($txt); 1393 1394 } 1395 1396 1397 // FAN API ############################################# 1398 1399 /** 1400 * get the fans of a specific content 1401 * @param string $format 1402 * @param string $content 1403 * @param string $page 1404 * @param string $pagesize 1405 * @return string xml/json 1406 */ 1407 private function fanget($format,$content,$page,$pagesize) { 1408 $user=$this->checkpassword(true); 1409 $this->checktrafficlimit($user); 1410 $content=strip_tags(addslashes($content)); 1411 $page = intval($page); 1412 1413 $fan = new OCSFanLister; 1414 $xml = $fan->ocs_fan_list($content,$page,$pagesize); 1415 $fancount = count($xml); 1416 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','fans',2,$fancount,$pagesize); 1417 1418 echo $txt; 1419 } 1420 1421 1422 /** 1423 * add a fans to a specific content 1424 * @param string $format 1425 * @param string $content 1426 * @return string xml/json 1427 */ 1428 private function addfan($format,$content) { 1429 $contentid = intval($content); 1430 $user=$this->checkpassword(true); 1431 $this->checktrafficlimit($user); 1432 1433 $fan = new OCSFan; 1434 if(!$fan->isfan($content)){ 1435 $fan->add($contentid); 1436 } 1437 1438 $txt=$this->generatexml($format,'ok',100,''); 1439 echo($txt); 1440 } 1441 1442 1443 /** 1444 * remove a fans from a specific content 1445 * @param string $format 1446 * @param string $content 1447 * @return string xml/json 1448 */ 1449 private function removefan($format,$content) { 1450 $contentid = intval($content); 1451 $user=$this->checkpassword(true); 1452 $this->checktrafficlimit($user); 1453 1454 $fan = new OCSFan; 1455 if($fan->isfan($content)){ 1456 $fan->remove($contentid); 1457 } 1458 1459 $txt=$this->generatexml($format,'ok',100,''); 1460 echo($txt); 1461 } 1462 1463 1464 /** 1465 * check if the user is a fan of a content 1466 * @param string $format 1467 * @param string $content 1468 * @return string xml/json 1469 */ 1470 private function isfan($format,$content) { 1471 $contentid = intval($content); 1472 $user=$this->checkpassword(true); 1473 $this->checktrafficlimit($user); 1474 $fan = new OCSFan; 1475 if($fan->isfan($contentid)){ 1476 $xml['status']='fan'; 1477 $txt=$this->generatexml($format,'ok',100,'',$xml,'','',1); 1478 }else{ 1479 $xml['status']='notfan'; 1480 $txt=$this->generatexml($format,'ok',100,'',$xml,'','',1); 1481 } 1482 echo($txt); 1483 } 1484 1485 1486 1487 1488 1489 // FRIEND API ############################################# 1490 1491 /** 1492 * get the list of sent invitations 1493 * @param string $format 1494 * @param string $page 1495 * @param string $pagesize 1496 * @return string xml/json 1497 */ 1498 private function friendsentinvitations($format,$page,$pagesize) { 1499 $user=$this->checkpassword(); 1500 $this->checktrafficlimit($user); 1501 1502 $friend = new OCSFriendsLister; 1503 $xml = $friend->ocs_sentinvitations($page,$pagesize); 1504 $friendcount = count($xml); 1505 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1506 1507 echo $txt; 1508 } 1509 1510 /** 1511 * get the list of received invitations 1512 * @param string $format 1513 * @param string $page 1514 * @param string $pagesize 1515 * @return string xml/json 1516 */ 1517 private function friendreceivedinvitations($format,$page,$pagesize) { 1518 $user=$this->checkpassword(); 1519 $this->checktrafficlimit($user); 1520 1521 $friend = new OCSFriendsLister; 1522 $xml = $friend->ocs_receivedinvitations($page,$pagesize); 1523 $friendcount = count($xml); 1524 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1525 1526 echo $txt; 1527 } 1528 1529 1530 1531 /** 1532 * get the list of friends from a person 1533 * @param string $format 1534 * @param string $fromuser user which called the query 1535 * @param string $page 1536 * @param string $pagesize 1537 * @return string xml/json 1538 */ 1539 private function friendget($format,$fromuser,$page,$pagesize) { //example params: (,snizzo,0,10); 1540 $user=$this->checkpassword(); 1541 $this->checktrafficlimit($user); 1542 1543 $fromuser=strip_tags(addslashes($fromuser)); 1544 1545 /* 1546 $cache = new H01_CACHE('apifriends',array($fromuser,CONFIG_USERDB,$page,$pagesize,$format)); 1547 if ($cache->exist()) { 1548 $cache->get(); 1549 unset($cache); 1550 } else { 1551 1552 $DBuser=H01_USER::getuser($fromuser,CONFIG_USERDB); 1553 if(isset($DBuser['login'])) { 1554 if($DBuser['privacyrelations']==0) { 1555 $visible=true; 1556 }elseif($DBuser['privacyrelations']==1){ 1557 if($user<>'') $visible=true; else $visible=false; 1558 }elseif($DBuser['privacyrelations']==2){ 1559 if(($fromuser==$user) or (H01_RELATION::isrelation(1,$fromuser,CONFIG_USERDB,$user))) $visible=true; else $visible=false; 1560 }elseif($DBuser['privacyrelations']==3){ 1561 if($fromuser==$user) $visible=true; else $visible=false; 1562 } 1563 1564 if($visible){ 1565 $countapprovedrelations=H01_RELATION::countapprovedrelations(1,$fromuser,CONFIG_USERDB); 1566 $relations=H01_RELATION::getapprovedrelations(1,$fromuser,CONFIG_USERDB,$start,$count,true); 1567 $itemscount=count($relations); 1568 $xml=array(); 1569 for ($i=0; $i < $itemscount;$i++) { 1570 $xml[$i]['personid']=$relations[$i]['user']; 1571 $xml[$i]['firstname']=$relations[$i]['firstname']; 1572 $xml[$i]['lastname']=$relations[$i]['lastname']; 1573 1574 1575 if (file_exists(CONFIG_DOCUMENT_ROOT.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.jpg')) { $pic='http://'.CONFIG_WEBSITEHOST.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.jpg'; $found=true; } 1576 elseif (file_exists(CONFIG_DOCUMENT_ROOT.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.png')) { $pic='http://'.CONFIG_WEBSITEHOST.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.png'; $found=true; } 1577 elseif (file_exists(CONFIG_DOCUMENT_ROOT.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.gif')) { $pic='http://'.CONFIG_WEBSITEHOST.'/CONTENT/user-pics/'.CONFIG_USERDB.'/'.$relations[$i]['user'].'.gif'; $found=true; } 1578 else { $pic=HOST.'/usermanager/nopic.png'; $found=false ;} 1579 $xml[$i]['avatarpic']=$pic; 1580 $xml[$i]['avatarpicfound']=$found; 1581 } 1582 $txt=$this->generatexml($format,'ok',100,'',$xml,'user','id',2,$countapprovedrelations,$pagesize); 1583 }else{ 1584 $txt=$this->generatexml($format,'failed',101,'data is private'); 1585 } 1586 }else{ 1587 $txt=$this->generatexml($format,'failed',102,'user not found'); 1588 } 1589 1590 $cache->put($txt); 1591 unset($cache); 1592 echo($txt); 1593 } 1594 */ 1595 $fan = new OCSFriendsLister; 1596 $xml = $fan->ocs_friend_list($fromuser,$page,$pagesize); 1597 $friendcount = count($xml); 1598 $txt=$this->generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1599 1600 echo $txt; 1601 } 1602 1603 1604 1605 1606 /** 1607 * invite a person as a friend 1608 * @param string $format 1609 * @param string $inviteuser 1610 * @param string $message 1611 * @return string xml/json 1612 */ 1613 private function friendinvite($format,$inviteuser,$message) { 1614 $user=$this->checkpassword(); 1615 $this->checktrafficlimit($user); 1616 $inviteuser = strip_tags(addslashes($inviteuser)); 1617 $message = strip_tags(addslashes($message)); 1618 1619 if($user<>'' and $inviteuser<>'' and $inviteuser<>false) { 1620 if($user<>$inviteuser) { 1621 if($message<>'') { 1622 OCSFriend::send_invitation($inviteuser, $message); 1623 echo($this->generatexml($format,'ok',100,'')); 1624 } else { 1625 echo($this->generatexml($format,'failed',101,'message must not be empty')); 1626 } 1627 }else{ 1628 echo($this->generatexml($format,'failed',102,'you can\´t invite yourself')); 1629 } 1630 } else { 1631 echo($this->generatexml($format,'failed',103,'user not found')); 1632 } 1633 1634 } 1635 1636 /** 1637 * approve a friendsship invitation 1638 * @param string $format 1639 * @param string $inviteuser 1640 * @return string xml/json 1641 */ 1642 private function friendapprove($format,$inviteuser) { 1643 $user=$this->checkpassword(); 1644 $this->checktrafficlimit($user); 1645 $inviteuser = strip_tags(addslashes($inviteuser)); 1646 1647 if($user<>'' and $inviteuser<>'') { 1648 OCSFriend::approve_invitation($inviteuser); 1649 echo($this->generatexml($format,'ok',100,'')); 1650 } else { 1651 echo($this->generatexml($format,'failed',101,'user not found')); 1652 } 1653 1654 } 1655 1656 1657 /** 1658 * decline a friendsship invitation 1659 * @param string $format 1660 * @param string $inviteuser 1661 * @return string xml/json 1662 */ 1663 private function frienddecline($format,$inviteuser) { 1664 $user=$this->checkpassword(); 1665 $this->checktrafficlimit($user); 1666 $inviteuser = strip_tags(addslashes($inviteuser)); 1667 1668 if($user<>'' and $inviteuser<>'') { 1669 OCSFriend::decline_invitation($inviteuser); 1670 echo($this->generatexml($format,'ok',100,'')); 1671 } else { 1672 echo($this->generatexml($format,'failed',101,'user not found')); 1673 } 1674 1675 } 1676 1677 1678 /** 1679 * cancel a friendsship 1680 * @param string $format 1681 * @param string $inviteuser 1682 * @return string xml/json 1683 */ 1684 private function friendcancel($format,$inviteuser) { 1685 $user=$this->checkpassword(); 1686 $this->checktrafficlimit($user); 1687 $inviteuser = strip_tags(addslashes($inviteuser)); 1688 1689 if($user<>'' and $inviteuser<>'') { 1690 OCSFriend::cancel_friendship($inviteuser); 1691 echo($this->generatexml($format,'ok',100,'')); 1692 } else { 1693 echo($this->generatexml($format,'failed',101,'user not found')); 1694 } 1695 1696 } 1697 1698 1699 /** 1700 * cancel a friendsship invitation 1701 * @param string $format 1702 * @param string $inviteuser 1703 * @return string xml/json 1704 */ 1705 private function friendcancelrequest($format,$inviteuser) { 1706 $user=$this->checkpassword(); 1707 $this->checktrafficlimit($user); 1708 $inviteuser = strip_tags(addslashes($inviteuser)); 1709 1710 if($user<>'' and $inviteuser<>'') { 1711 H01_RELATION::deleterelationrequest(1,$user,$inviteuser,CONFIG_USERDB); 1712 echo($this->generatexml($format,'ok',100,'')); 1713 } else { 1714 echo($this->generatexml($format,'failed',101,'user not found')); 1715 } 1716 1717 } 1718 1719 1720 1721 1722 1723 1724 // MESSAGE API ############################################# 1725 1726 /** 1727 * get the list of available message foldersn 1728 * @param string $format 1729 * @return string xml/json 1730 */ 1731 private function messagefolders($format) { 1732 $user=$this->checkpassword(); 1733 $this->checktrafficlimit($user); 1734 if(!empty($user)) { 1735 $cache = new H01_CACHE('apimessagefolder',array($user,CONFIG_USERDB,$format)); 1736 if ($cache->exist()) { 1737 $cache->get(); 1738 unset($cache); 1739 } else { 1740 1741 $i=0; 1742 foreach(H01_MESSAGE::$FOLDERS[1] as $key=>$value) { 1743 $i++; 1744 $xml[$i]['id']=$key; 1745 $xml[$i]['name']=$value; 1746 $count=H01_MESSAGE::countmessages($user,CONFIG_USERDB,$key); 1747 $xml[$i]['messagecount']=$count; 1748 if($key==0) $xml[$i]['type']='inbox'; 1749 elseif($key==1) $xml[$i]['type']='send'; 1750 elseif($key==2) $xml[$i]['type']='trash'; 1751 else $xml[$i]['type']=''; 1752 } 1753 $txt=$this->generatexml($format,'ok',100,'',$xml,'folder','',2,count(H01_MESSAGE::$FOLDERS[1])); 1754 1755 $cache->put($txt); 1756 unset($cache); 1757 echo($txt); 1758 } 1759 1760 }else{ 1761 $txt=$this->generatexml($format,'failed',101,'user not found'); 1762 echo($txt); 1763 } 1764 1765 } 1766 1767 1768 /** 1769 * get a list of messages 1770 * @param string $format 1771 * @param string $folder 1772 * @param string $page 1773 * @param string $pagesize 1774 * @param string $filter 1775 * @return string xml/json 1776 */ 1777 private function messagelist($format,$folder,$page,$pagesize,$filter) { 1778 $user=$this->checkpassword(); 1779 $this->checktrafficlimit($user); 1780 1781 $cache = new H01_CACHE('apimessagelist',array($user,CONFIG_USERDB,$folder,$filter,$page,$pagesize,$format)); 1782 if ($cache->exist()) { 1783 $cache->get(); 1784 unset($cache); 1785 } else { 1786 $messages=H01_MESSAGE::getlist($user,CONFIG_USERDB,$folder,$page,$pagesize,$filter); 1787 $messagescount=$messages['count']; 1788 unset($messages['count']); 1789 $itemscount=count($messages); 1790 $xml=array(); 1791 for ($i=0; $i < $itemscount;$i++) { 1792 $xml[$i]['id']=$messages[$i]['id']; 1793 $xml[$i]['messagefrom']=$messages[$i]['messagefrom']; 1794 $xml[$i]['firstname']=$messages[$i]['firstname']; 1795 $xml[$i]['lastname']=$messages[$i]['lastname']; 1796 $xml[$i]['profilepage']='http://'.CONFIG_WEBSITEHOST.'/usermanager/search.php?username='.urlencode($messages[$i]['messagefrom']); 1797 $xml[$i]['messageto']=$messages[$i]['messageto']; 1798 $xml[$i]['senddate']=date('c',$messages[$i]['senddate']); 1799 $xml[$i]['status']=$messages[$i]['status']; 1800 $xml[$i]['statustext']=strip_tags(H01_MESSAGE::$STATUS[1][$messages[$i]['status']]); 1801 $xml[$i]['subject']=$messages[$i]['subject']; 1802 $xml[$i]['body']=$messages[$i]['body']; 1803 // $xml[$i]['folder']=$messages[$i]['folder']; 1804 } 1805 1806 $txt=$this->generatexml($format,'ok',100,'',$xml,'message','full',2,$messagescount,$pagesize); 1807 1808 $cache->put($txt); 1809 unset($cache); 1810 echo($txt); 1811 } 1812 } 1813 1814 /** 1815 * get one specific message 1816 * @param string $format 1817 * @param string $folder 1818 * @param string $message 1819 * @return string xml/json 1820 */ 1821 private function messageget($format,$folder,$message) { 1822 $user=$this->checkpassword(); 1823 $this->checktrafficlimit($user); 1824 1825 $cache = new H01_CACHE('apimessageget',array($user,CONFIG_USERDB,$folder,$message,$format)); 1826 if ($cache->exist()) { 1827 $cache->get(); 1828 unset($cache); 1829 } else { 1830 1831 H01_MESSAGE::setstatus($message,$user,CONFIG_USERDB,1); 1832 $message=H01_MESSAGE::get($user,CONFIG_USERDB,$folder,$message); 1833 if(count($message)>0) { 1834 $xml['id']=$message['id']; 1835 $xml['messagefrom']=$message['messagefrom']; 1836 $xml['firstname']=$message['firstname']; 1837 $xml['lastname']=$message['lastname']; 1838 $xml['profilepage']='http://'.CONFIG_WEBSITEHOST.'/usermanager/search.php?username='.urlencode($message['messagefrom']); 1839 $xml['messageto']=$message['messageto']; 1840 $xml['senddate']=date('c',$message['senddate']); 1841 $xml['status']=$message['status']; 1842 $xml['statustext']=strip_tags(H01_MESSAGE::$STATUS[1][$message['status']]); 1843 $xml['subject']=$message['subject']; 1844 $xml['body']=$message['body']; 1845 $xml2[1]=$xml; 1846 $txt=$this->generatexml($format,'ok',100,'',$xml2,'message','full',2); 1847 }else{ 1848 $txt=$this->generatexml($format,'failed',101,'message not found'); 1849 } 1850 1851 $cache->put($txt); 1852 unset($cache); 1853 echo($txt); 1854 } 1855 } 1856 1857 1858 1859 /** 1860 * send a message 1861 * @param string $format 1862 * @param string $touser 1863 * @param string $subject 1864 * @param string $message 1865 * @return string xml/json 1866 */ 1867 private function messagesend($format,$touser,$subject,$message) { 1868 $user=$this->checkpassword(); 1869 $this->checktrafficlimit($user); 1870 1871 if($touser<>$user) { 1872 if(!empty($subject) and !empty($message)) { 1873 if(!empty($user) and H01_USER::exist($touser,CONFIG_USERDB,true)) { 1874 H01_MESSAGE::send($user,CONFIG_USERDB,$touser,$subject,$message); 1875 echo($this->generatexml($format,'ok',100,'')); 1876 }else{ 1877 echo($this->generatexml($format,'failed',101,'user not found')); 1878 } 1879 }else{ 1880 echo($this->generatexml($format,'failed',102,'subject or message not found')); 1881 } 1882 }else{ 1883 echo($this->generatexml($format,'failed',103,'you can\´t send a message to yourself')); 1884 } 1885 } 1886 1887 1888 // ACTIVITY API ############################################# 1889 1890 /** 1891 * get my activities 1892 * @param string $format 1893 * @param string $page 1894 * @param string $pagesize 1895 * @return string xml/json 1896 */ 1897 private function activityget($format,$page,$pagesize) { 1898 1899 $user=$this->checkpassword(); 1900 $this->checktrafficlimit($user); 1901 1902 $al = new OCSActivityLister(); 1903 $log=$al->ocs_activity_list($user,$page,$pagesize); 1904 $itemscount=count($log); 1905 $xml=array(); 1906 for ($i=0; $i < $itemscount;$i++) { 1907 $xml[$i]['id']=$log[$i]['id']; 1908 $xml[$i]['personid']=$log[$i]['personid']; 1909 $xml[$i]['firstname']=$log[$i]['firstname']; 1910 $xml[$i]['lastname']=$log[$i]['lastname']; 1911 $xml[$i]['profilepage']=''; 1912 $xml[$i]['avatarpic']=''; 1913 $xml[$i]['timestamp']=date('c',$log[$i]['timestamp']); 1914 $xml[$i]['type']=$log[$i]['type']; 1915 $xml[$i]['message']=strip_tags($log[$i]['message']); 1916 $xml[$i]['link']=''; 1917 } 1918 1919 $txt=$this->generatexml($format,'ok',100,'',$xml,'activity','full',2,count($xml),$pagesize); 1920 1921 echo($txt); 1922 1923 } 1924 1925 /** 1926 * submit a activity 1927 * @param string $format 1928 * @param string $message 1929 * @return string xml/json 1930 */ 1931 private function activityput($format,$message) { 1932 $user=$this->checkpassword(); 1933 $this->checktrafficlimit($user); 1934 1935 if($user<>'') { 1936 if(trim($message)<>'') { 1937 OCSActivity::add(OCSUser::id(), 1, $message); 1938 echo($this->generatexml($format,'ok',100,'')); 1939 } else { 1940 echo($this->generatexml($format,'failed',101,'empty message')); 1941 } 1942 } else { 1943 echo($this->generatexml($format,'failed',102,'user not found')); 1944 } 1945 1946 } 1947 1948 1949 // CONTENT API ############################################# 1950 1951 /** 1952 * get a specific content 1953 * @param string $format 1954 * @param string $content 1955 * @return string xml/json 1956 */ 1957 private function contentget($format,$content) { 1958 1959 $user=$this->checkpassword(false); 1960 $this->checktrafficlimit($user); 1961 1962 $content=addslashes($content); 1963 1964 // fetch data 1965 $con = new OCSContent(); 1966 1967 // check data 1968 if (!$con->load($content)) { 1969 $txt=$this->generatexml($format,'failed',101,'content not found'); 1970 } else { 1971 $xml['id']=$con->id; 1972 $xml['name']=$con->name; 1973 $xml['version']=$con->version; 1974 $xml['typeid']=$con->type; 1975 //$xml['typename']=$WEBSITECONTENT[$con['type']]; 1976 //$xml['language']=H01_CONTENT::$LANGUAGES[$con['language']]; 1977 $xml['personid']=$con->owner; 1978 //$xml['profilepage']='http://opendesktop.org/usermanager/search.php?username='.urlencode($con['user']); 1979 //$xml['created']=date('c',$con['created']); 1980 //$xml['changed']=date('c',$con['changed']); 1981 //$xml['downloads']=$con['downloads']; 1982 $xml['score'] = $con->score; 1983 $xml['description'] = $con->description; 1984 $xml['summary'] = $con->summary; 1985 //$xml['feedbackurl'] = $con['feedbackurl']; 1986 $xml['changelog'] = $con->changelog; 1987 $xml['license'] = $con->license; 1988 $xml['personid'] = $con->personid; 1989 $xml['preview1'] = $con->preview1; 1990 $xml['preview2'] = $con->preview2; 1991 $xml['preview3'] = $con->preview3; 1992 /*$xml['homepage'] = $con['homepage1']; 1993 if($con['homepagetype1']<>0) $xml['homepagetype']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype1']]; else $xml['homepagetype']=''; 1994 $xml['homepage2']=$con['homepage2']; 1995 if($con['homepagetype2']<>0) $xml['homepagetype2']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype2']]; else $xml['homepagetype2']=''; 1996 $xml['homepage3']=$con['homepage3']; 1997 if($con['homepagetype3']<>0) $xml['homepagetype3']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype3']]; else $xml['homepagetype3']=''; 1998 $xml['homepage4']=$con['homepage4']; 1999 if($con['homepagetype4']<>0) $xml['homepagetype4']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype4']]; else $xml['homepagetype4']=''; 2000 $xml['homepage5']=$con['homepage5']; 2001 if($con['homepagetype5']<>0) $xml['homepagetype5']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype5']]; else $xml['homepagetype5']=''; 2002 $xml['homepage6']=$con['homepage6']; 2003 if($con['homepagetype6']<>0) $xml['homepagetype6']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype6']]; else $xml['homepagetype6']=''; 2004 $xml['homepage7']=$con['homepage7']; 2005 if($con['homepagetype7']<>0) $xml['homepagetype7']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype7']]; else $xml['homepagetype7']=''; 2006 $xml['homepage8']=$con['homepage8']; 2007 if($con['homepagetype8']<>0) $xml['homepagetype8']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype8']]; else $xml['homepagetype8']=''; 2008 $xml['homepage9']=$con['homepage9']; 2009 if($con['homepagetype9']<>0) $xml['homepagetype9']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype9']]; else $xml['homepagetype9']=''; 2010 $xml['homepage10']=$con['homepage10']; 2011 if($con['homepagetype10']<>0) $xml['homepagetype10']=H01_CONTENT::$LINK_CATEGORY[$con['homepagetype10']]; else $xml['homepagetype10']=''; 2012 */ 2013 2014 //$xml['licensetype']=$con->license; 2015 /*if (($con['licensetype']<>0) and ($con['licensetype']<>1000)) { 2016 if(isset($contentlicense[$con['licensetype']])) $xml['license']=$contentlicense[$con['licensetype']]; 2017 } else { 2018 if (!empty($con['license'])) $xml['license']=nl2br(htmlspecialchars($con['license'])); 2019 } 2020 $xml['license'] = $con->license; 2021 2022 if(!empty($con['donation'])) $xml['donationpage']='http://'.CONFIG_WEBSITEHOST.'/content/donate.php?content='.$con['id']; else $xml['donationpage']=''; 2023 $xml['comments']=$con['commentscount']; 2024 $xml['commentspage']='http://'.CONFIG_WEBSITEHOST.'/content/show.php?content='.$con['id']; 2025 $xml['fans']=$con['fancount']; 2026 $xml['fanspage']='http://'.CONFIG_WEBSITEHOST.'/content/show.php?action=fan&content='.$con['id']; 2027 $xml['knowledgebaseentries']=$con['knowledgebasecount']; 2028 $xml['knowledgebasepage']='http://'.CONFIG_WEBSITEHOST.'/content/show.php?action=knowledgebase&content='.$con['id']; 2029 2030 if ($con['depend']<>0) $xml['depend']=$DEPENDTYPES[$con['depend']]; else $xml['depend']=''; 2031 2032 // preview 2033 if (!empty($con['preview1'])) $pic1=$con['id'].'-1.'.$con['preview1']; else $pic1=''; 2034 if (!empty($con['preview2'])) $pic2=$con['id'].'-2.'.$con['preview2']; else $pic2=''; 2035 if (!empty($con['preview3'])) $pic3=$con['id'].'-3.'.$con['preview3']; else $pic3=''; 2036 if (!empty($con['preview1'])) $picsmall1='m'.$con['id'].'-1.png'; else $picsmall1=''; 2037 if (!empty($con['preview2'])) $picsmall2='m'.$con['id'].'-2.png'; else $picsmall2=''; 2038 if (!empty($con['preview3'])) $picsmall3='m'.$con['id'].'-3.png'; else $picsmall3=''; 2039 2040 2041 if(!empty($pic1)) $xml['preview1']='http://'.CONFIG_WEBSITEHOST.'/content/preview.php?preview=1&id='.$con['id'].'&file1='.$pic1.'&file2='.$pic2.'&file3='.$pic3.'&name='.urlencode($con['name']); else $xml['preview1']=''; 2042 if(!empty($pic2)) $xml['preview2']='http://'.CONFIG_WEBSITEHOST.'/content/preview.php?preview=2&id='.$con['id'].'&file1='.$pic1.'&file2='.$pic2.'&file3='.$pic3.'&name='.urlencode($con['name']); else $xml['preview2']=''; 2043 if(!empty($pic3)) $xml['preview3']='http://'.CONFIG_WEBSITEHOST.'/content/preview.php?preview=3&id='.$con['id'].'&file1='.$pic1.'&file2='.$pic2.'&file3='.$pic3.'&name='.urlencode($con['name']); else $xml['preview3']=''; 2044 if(!empty($pic1)) $xml['previewpic1']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-pre1/'.$pic1; else $xml['previewpic1']=''; 2045 if(!empty($pic2)) $xml['previewpic2']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-pre2/'.$pic2; else $xml['previewpic2']=''; 2046 if(!empty($pic3)) $xml['previewpic3']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-pre3/'.$pic3; else $xml['previewpic3']=''; 2047 if(!empty($picsmall1)) $xml['smallpreviewpic1']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-m1/'.$picsmall1; else $xml['picsmall1']=''; 2048 if(!empty($picsmall2)) $xml['smallpreviewpic2']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-m2/'.$picsmall2; else $xml['picsmall2']=''; 2049 if(!empty($picsmall3)) $xml['smallpreviewpic3']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/content-m3/'.$picsmall3; else $xml['picsmall3']=''; 2050 $xml['detailpage']='http://'.CONFIG_WEBSITEHOST.'/content/show.php?content='.$con['id']; 2051 */ 2052 // download 2053 if (!empty($con->downloadname1) or !empty($con->downloadlink1)) { 2054 /* 2055 if($con['downloadfiletype1']<>0) { 2056 $typetmp=$DISTRIBUTIONSTYPES[$con['downloadfiletype1']].' '; 2057 } else { 2058 $typetmp=''; 2059 } 2060 $xml['downloadtype1']=$typetmp; 2061 if($con['downloadbuy1']==1) { 2062 $xml['downloadprice1']=$con['downloadbuyprice1']; 2063 $xml['downloadlink1']='http://'.CONFIG_WEBSITEHOST.'/content/buy.php?content='.$con['id'].'&id=1'; 2064 }else{ 2065 $xml['downloadprice1']='0'; 2066 $xml['downloadlink1']='http://'.CONFIG_WEBSITEHOST.'/content/download.php?content='.$con['id'].'&id=1'; 2067 } 2068 */ 2069 $xml['downloadname1'] = $con->downloadname1; 2070 $xml['downloadlink1'] = $con->downloadlink1; 2071 /* 2072 if(!empty($con['downloadgpgfingerprint1'])) $xml['downloadgpgfingerprint1']=$con['downloadgpgfingerprint1']; else $xml['downloadgpgfingerprint1']=''; 2073 if(!empty($con['downloadgpgsignature1'])) $xml['downloadgpgsignature1']=$con['downloadgpgsignature1']; else $xml['downloadgpgsignature1']=''; 2074 if(!empty($con['downloadpackagename1'])) $xml['downloadpackagename1']=$con['downloadpackagename1']; else $xml['downloadpackagename1']=''; 2075 if(!empty($con['downloadrepository1'])) $xml['downloadrepository1']=$con['downloadrepository1']; else $xml['downloadrepository1']=''; 2076 2077 if(($con['downloadtyp1']=='0') and (!empty($con['download1']))) $xml['downloadsize1']=ceil(@filesize(CONFIG_DOCUMENT_ROOT.'/CONTENT/content-files/'.$con['download1'])/1024); else $xml['downloadsize1']=''; 2078 */ 2079 } else { 2080 $xml['downloadname1']=''; 2081 $xml['downloadlink1']=''; 2082 } 2083 2084 /* 2085 for ($i=2; $i <= 12;$i++) { 2086 if (!empty($con['downloadname'.$i]) and !empty($con['downloadlink'.$i]) ) { 2087 if($con['downloadfiletype'.$i]<>0) { 2088 $typetmp=$DISTRIBUTIONSTYPES[$con['downloadfiletype'.$i]].' '; 2089 } else { 2090 $typetmp=''; 2091 } 2092 $xml['downloadtype'.$i]=$typetmp; 2093 2094 if($con['downloadbuy'.$i]==1) { 2095 $xml['downloadprice'.$i]=$con['downloadbuyprice'.$i]; 2096 $xml['downloadlink'.$i]='http://'.CONFIG_WEBSITEHOST.'/content/buy.php?content='.$con['id'].'&id='.$i; 2097 }else{ 2098 $xml['downloadprice'.$i]='0'; 2099 $xml['downloadlink'.$i]='http://'.CONFIG_WEBSITEHOST.'/content/download.php?content='.$con['id'].'&id='.$i; 2100 } 2101 if(!empty($con['downloadname'.$i])) $xml['downloadname'.$i]=$con['downloadname'.$i]; else $xml['downloadname'.$i]=''; 2102 if(!empty($con['downloadgpgfingerprint'.$i])) $xml['downloadgpgfingerprint'.$i]=$con['downloadgpgfingerprint'.$i]; else $xml['downloadgpgfingerprint'.$i]=''; 2103 if(!empty($con['downloadgpgsignature'.$i])) $xml['downloadgpgsignature'.$i]=$con['downloadgpgsignature'.$i]; else $xml['downloadgpgsignature'.$i]=''; 2104 if(!empty($con['downloadpackagename'.$i])) $xml['downloadpackagename'.$i]=$con['downloadpackagename'.$i]; else $xml['downloadpackagename'.$i]=''; 2105 if(!empty($con['downloadrepository'.$i])) $xml['downloadrepository'.$i]=$con['downloadrepository'.$i]; else $xml['downloadrepository'.$i]=''; 2106 } 2107 } 2108 */ 2109 $xml2[0]=$xml; 2110 $txt=$this->generatexml($format,'ok',100,'',$xml2,'content','full',2); 2111 echo($txt); 2112 2113 } 2114 2115 } 2116 2117 2118 2119 /** 2120 * get the download link for a content 2121 * @param string $format 2122 * @param string $content 2123 * @param string $item 2124 * @return string xml/json 2125 */ 2126 private function contentdownload($format,$content,$item) { 2127 $user=$this->checkpassword(false); 2128 $this->checktrafficlimit($user); 2129 2130 $content = (int) $content; 2131 $item = (int) $item; 2132 2133 // item range 2134 if($item<1 or $item>12) { 2135 $txt=$this->generatexml($format,'failed',103,'item not found'); 2136 } else { 2137 2138 // fetch data 2139 $con = new OCSContent(); 2140 2141 // check data 2142 if (!$con->load($content)) { 2143 $txt=$this->generatexml($format,'failed',101,'content not found'); 2144 } else { 2145 //download link 2146 $link = $con->downloadlink1; 2147 //mimetype 2148 $headers = get_headers($link); 2149 $mimetype = $headers[3]; 2150 2151 if (!empty($con->downloadname1) or !empty($con->downloadlink1)) { 2152 $xml['downloadlink']=$link; 2153 $xml['mimetype']=$mimetype; 2154 $xml2[0]=$xml; 2155 $txt=$this->generatexml($format,'ok',100,'',$xml2,'content','download',2); 2156 } else { 2157 $txt=$this->generatexml($format,'failed',103,'content item not found'); 2158 } 2159 2160 } 2161 2162 if(isset($txt) and $txt<>'') { 2163 echo($txt); 2164 } 2165 } 2166 } 2167 2168 2169 2170 2171 2172 /** 2173 * get a list of contents 2174 * @param string $format 2175 * @param string $contents 2176 * @param string $searchstr 2177 * @param string $searchuser 2178 * @param string $sortmode 2179 * @param string $page 2180 * @param string $pagesize 2181 * @return string xml/json 2182 */ 2183 private function contentlist($format,$contents,$searchstr,$searchuser,$external,$distribution,$license,$sortmode,$page,$pagesize) { 2184 $user=$this->checkpassword(false); 2185 $this->checktrafficlimit($user); 2186 2187 $conl = new OCSContentLister("ocs_content"); 2188 $xml = $conl->ocs_content_list($searchstr,$sortmode,$page,$pagesize); 2189 $totalitems = count($xml); 2190 /* 2191 * test page: http://localhost/v1/content/data?search=lolol 2192 */ 2193 2194 if(empty($xml)){ 2195 $txt=$this->generatexml($format,'ok',100,''); 2196 } else { 2197 $txt=$this->generatexml($format,'ok',100,'',$xml,'content','summary',2,$totalitems,$pagesize); 2198 } 2199 2200 echo($txt); 2201 2202 } 2203 2204 2205 2206 2207 /** 2208 * get a list of recommendations for a content 2209 * @param string $format 2210 * @param string $contents 2211 * @param string $searchstr 2212 * @param string $searchuser 2213 * @param string $sortmode 2214 * @param string $page 2215 * @param string $pagesize 2216 * @return string xml/json 2217 */ 2218 private function contentrecommendations($format,$contentid,$page,$pagesize) { 2219 2220 $user=$this->checkpassword(false); 2221 $this->checktrafficlimit($user); 2222 2223 2224 $cache = new H01_CACHE('apicontentrecommendations',array($_SESSION['website'],$_SESSION['lang'],$contentid,$format)); 2225 if ($cache->exist()) { 2226 $cache->get(); 2227 unset($cache); 2228 } else { 2229 2230 $xml=H01_CONTENT::getrecommendations($contentid,$page,$pagesize); 2231 $totalitems=$xml['totalitems']; 2232 unset($xml['totalitems']); 2233 2234 $txt=$this->generatexml($format,'ok',100,'',$xml,'content','basic',2,$totalitems,$pagesize); 2235 2236 $cache->put($txt); 2237 unset($cache); 2238 echo($txt); 2239 } 2240 2241 } 2242 2243 2244 2245 2246 2247 2248 /** 2249 * get a list of contents categories 2250 * @param string $format 2251 * @return string xml/json 2252 */ 2253 private function contentcategories($format) { 2254 $user=$this->checkpassword(false); 2255 $this->checktrafficlimit($user); 2256 2257 $i=0; 2258 foreach(EConfig::$data["ocs_categories"] as $key=>$value) { 2259 $i++; 2260 $xml[$i]['id']=$key; 2261 $xml[$i]['name']=$value; 2262 } 2263 $txt=$this->generatexml($format,'ok',100,'',$xml,'category','',2,count(EConfig::$data["ocs_categories"])); 2264 2265 echo($txt); 2266 } 2267 2268 /** 2269 * get a list of contents licenses 2270 * @param string $format 2271 * @return string xml/json 2272 */ 2273 private function contentlicenses($format) { 2274 $contentlicense = EConfig::$data["licenses"]; 2275 $contentlicenselink = EConfig::$data["licenseslink"]; 2276 2277 $user=$this->checkpassword(false); 2278 $this->checktrafficlimit($user); 2279 2280 $i=0; 2281 foreach($contentlicense as $key=>$value) { 2282 $i++; 2283 $xml[$i]['id']=$key; 2284 $xml[$i]['name']=$value; 2285 $xml[$i]['link']=$contentlicenselink[$key]; 2286 } 2287 $txt=$this->generatexml($format,'ok',100,'',$xml,'license','',2,count($contentlicense)); 2288 2289 echo($txt); 2290 } 2291 2292 /** 2293 * get a list of contents distributions 2294 * @param string $format 2295 * @return string xml/json 2296 */ 2297 private function contentdistributions($format) { 2298 global $DISTRIBUTIONSTYPES; 2299 2300 $user=$this->checkpassword(false); 2301 $this->checktrafficlimit($user); 2302 2303 $i=0; 2304 foreach($DISTRIBUTIONSTYPES as $key=>$value) { 2305 $i++; 2306 $xml[$i]['id']=$key; 2307 $xml[$i]['name']=$value; 2308 } 2309 $txt=$this->generatexml($format,'ok',100,'',$xml,'distribution','',2,count($DISTRIBUTIONSTYPES)); 2310 2311 echo($txt); 2312 } 2313 2314 2315 /** 2316 * get a list of contents homepages 2317 * @param string $format 2318 * @return string xml/json 2319 */ 2320 private function contenthomepages($format) { 2321 $user=$this->checkpassword(false); 2322 $this->checktrafficlimit($user); 2323 2324 $i=0; 2325 foreach(H01_CONTENT::$LINK_CATEGORY as $key=>$value) { 2326 $i++; 2327 $xml[$i]['id']=$key; 2328 $xml[$i]['name']=$value; 2329 } 2330 $txt=$this->generatexml($format,'ok',100,'',$xml,'homepagetypes','',2,count(H01_CONTENT::$LINK_CATEGORY)); 2331 2332 echo($txt); 2333 } 2334 2335 2336 /** 2337 * get a list of contents dependencies 2338 * @param string $format 2339 * @return string xml/json 2340 */ 2341 private function contentdependencies($format) { 2342 global $DEPENDTYPES; 2343 2344 $user=$this->checkpassword(false); 2345 $this->checktrafficlimit($user); 2346 2347 $i=0; 2348 foreach($DEPENDTYPES as $key=>$value) { 2349 $i++; 2350 $xml[$i]['id']=$key; 2351 $xml[$i]['name']=$value; 2352 } 2353 $txt=$this->generatexml($format,'ok',100,'',$xml,'dependtypes','',2,count($DEPENDTYPES)); 2354 2355 echo($txt); 2356 } 2357 2358 2359 2360 /** 2361 * vote for a content 2362 * @param string $format 2363 * @param string $content 2364 * @param string $vote 2365 * @return string xml/json 2366 */ 2367 private function contentvote($format,$content,$vote) { 2368 2369 $user=$this->checkpassword(true); 2370 $this->checktrafficlimit($user); 2371 2372 $con = new OCSContent(); 2373 2374 // fetch data 2375 $content=addslashes($content); 2376 $vote=addslashes($vote); 2377 2378 // check data 2379 if (!$con->load($content)) { 2380 $txt=$this->generatexml($format,'failed',101,'content not found'); 2381 } else { 2382 if($user<>'') $con->set_score($vote); 2383 $txt=$this->generatexml($format,'ok',100,''); 2384 } 2385 echo($txt); 2386 } 2387 2388 2389 /** 2390 * delete a preview picture of a content 2391 * @param string $format 2392 * @param string $contentid 2393 * @param string $previewid 2394 * @return string xml/json 2395 */ 2396 private function contentpreviewdelete($format,$contentid,$previewid) { 2397 $user=$this->checkpassword(true); 2398 $this->checktrafficlimit($user); 2399 $content=addslashes($contentid); 2400 $preview=addslashes($previewid); 2401 2402 // fetch data 2403 $con = new OCSContent(); 2404 2405 if($con->load($content)){ 2406 if($con->is_preview_available($previewid)){ 2407 if($con->is_owned(OCSUser::id())) { 2408 2409 $con->previewdelete($content,$preview); 2410 2411 $txt=$this->generatexml($format,'ok',100,''); 2412 } else { 2413 $txt=$this->generatexml($format,'failed',101,'no permission to change content'); 2414 } 2415 } else { 2416 $txt=$this->generatexml($format,'failed',102,'preview not found'); 2417 } 2418 } 2419 echo($txt); 2420 } 2421 2422 /** 2423 * upload a preview picture of a content 2424 * @param string $format 2425 * @param string $contentid 2426 * @param string $previewid 2427 * @return string xml/json 2428 */ 2429 private function contentpreviewupload($format,$contentid,$previewid) { 2430 $user=$this->checkpassword(true); 2431 $this->checktrafficlimit($user); 2432 $content=addslashes($contentid); 2433 $preview=addslashes($previewid); 2434 2435 // fetch data 2436 $con = new OCSContent(); 2437 2438 if(($preview==1) or ($preview==2) or ($preview==3)) { 2439 2440 if($con->load($content) and $con->is_owned(OCSUser::id())) { 2441 2442 if(isset($_FILES['localfile']['name']) and isset($_FILES['localfile']['name']) and ($_FILES['localfile']['name']<>'' and $_FILES['localfile']['name']<>'none' and $_FILES['localfile']['tmp_name']<>'' and $_FILES['localfile']['tmp_name']<>'none')) { 2443 if($con->previewadd($content,'localfile',$preview)){ 2444 $txt=$this->generatexml($format,'ok',100,''); 2445 } else { 2446 ELog::error("previewadd crashed lol!"); 2447 } 2448 } else { 2449 $txt=$this->generatexml($format,'failed',101,'localfile not found'); 2450 } 2451 } else { 2452 $txt=$this->generatexml($format,'failed',102,'no permission to change content'); 2453 } 2454 } else { 2455 $txt=$this->generatexml($format,'failed',103,'preview must be 1, 2 or 3'); 2456 } 2457 echo($txt); 2458 } 2459 2460 2461 2462 /** 2463 * delete the downloadfile from a content 2464 * @param string $format 2465 * @param string $contentid 2466 * @return string xml/json 2467 */ 2468 private function contentdownloaddelete($format,$contentid) { 2469 $user=$this->checkpassword(true); 2470 $this->checktrafficlimit($user); 2471 $content=addslashes($contentid); 2472 2473 // fetch data 2474 $con = new OCSContent(); 2475 2476 if($con->load($content) and $con->is_owned(OCSUser::id())) { 2477 2478 $con->downloaddelete(); 2479 $txt=$this->generatexml($format,'ok',100,''); 2480 } else { 2481 $txt=$this->generatexml($format,'failed',101,'no permission to change content'); 2482 } 2483 2484 echo($txt); 2485 2486 } 2487 2488 /** 2489 * upload the downloadfile for a content 2490 * @param string $format 2491 * @param string $contentid 2492 * @return string xml/json 2493 */ 2494 private function contentdownloadupload($format,$contentid) { 2495 2496 $user=$this->checkpassword(true); 2497 $this->checktrafficlimit($user); 2498 $content=addslashes($contentid); 2499 2500 // fetch data 2501 $con = new OCSContent(); 2502 2503 if($con->load($content) and $con->is_owned(OCSUser::id())) { 2504 2505 if(isset($_FILES['localfile']['name']) and isset($_FILES['localfile']['name']) and ($_FILES['localfile']['name']<>'' and $_FILES['localfile']['name']<>'none' and $_FILES['localfile']['tmp_name']<>'' and $_FILES['localfile']['tmp_name']<>'none')) { 2506 if($con->downloadadd($content,'localfile')){ 2507 $txt=$this->generatexml($format,'ok',100,''); 2508 }else{ 2509 $txt=$this->generatexml($format,'failed',101,$error); 2510 } 2511 } else { 2512 $txt=$this->generatexml($format,'failed',102,'localfile not found'); 2513 } 2514 } else { 2515 $txt=$this->generatexml($format,'failed',103,'no permission to change content'); 2516 } 2517 2518 echo($txt); 2519 2520 } 2521 2522 2523 2524 2525 /** 2526 * add a new content 2527 * @param string $format 2528 * @return string xml/json 2529 */ 2530 private function contentadd($format) { 2531 $user=$this->checkpassword(true); 2532 $this->checktrafficlimit($user); 2533 2534 $categories = EConfig::$data["ocs_categories"]; 2535 $numcats = count($categories); 2536 2537 if(OCSUser::is_logged()) { 2538 2539 $data=array(); 2540 $data['name']=$this->readdata('name','text'); 2541 $data['type']=$this->readdata('type','int'); 2542 2543 if($this->readdata('downloadname1','text')<>'') $data['downloadname1']=$this->readdata('downloadname1','text') ; 2544 if($this->readdata('downloadlink1','text')<>'') $data['downloadlink1']=$this->readdata('downloadlink1','text'); 2545 if($this->readdata('description','text')<>'') { $data['description']=$this->readdata('description','text'); } else { $data['description']='...'; } 2546 if($this->readdata('summary','text')<>'') { $data['summary']=$this->readdata('summary','text'); } else { $data['summary']='...'; } 2547 if($this->readdata('version','text')<>'') { $data['version']=$this->readdata('version','text'); } else { $data['version']='...'; } 2548 if($this->readdata('changelog','text')<>'') { $data['changelog']=$this->readdata('changelog','text'); } else { $data['changelog']='...'; } 2549 //if($this->readdata('personid','text')<>'') $data['personid']=$this->readdata('personid','text'); 2550 if($this->readdata('license','int') >=0 or $this->readdata('license','int')<5) $data['license']=$this->readdata('license','int'); 2551 2552 $data['preview1'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 2553 $data['preview2'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 2554 $data['preview3'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 2555 $data['personid'] = $user; 2556 2557 if( ($data['name']<>'') or ($data['type']<0) or ($data['type']>$numcats) ) { 2558 $content = new OCSContent(); 2559 $content->set_owner(OCSUser::id()); 2560 $content->set_data($data); 2561 $content->save(); 2562 2563 $xml = array(); 2564 $xml[0]['id'] = $content->id(); 2565 $txt = $this->generatexml($format,'ok',100,'',$xml,'content','',2); 2566 }else{ 2567 $txt = $this->generatexml($format,'failed',101,'please specify all mandatory fields'); 2568 } 2569 }else{ 2570 $txt=$this->generatexml($format,'failed',102,'no permission to change content'); 2571 } 2572 2573 echo($txt); 2574 2575 } 2576 2577 2578 2579 /** 2580 * edit a content entry 2581 * @param string $format 2582 * @param string $contentid 2583 * @return string xml/json 2584 */ 2585 private function contentedit($format,$contentid) { 2586 2587 $user=$this->checkpassword(true); 2588 $this->checktrafficlimit($user); 2589 $content=addslashes($contentid); 2590 2591 $categories = EConfig::$data["ocs_categories"]; 2592 $numcats = count($categories); 2593 2594 // fetch data 2595 $con = new OCSContent(); 2596 if($con->load($content) and OCSUser::is_logged() and OCSUser::id() == $con->owner) { 2597 2598 $data=array(); 2599 if($this->readdata('name','text')<>'') $data['name'] = $this->readdata('name','text'); 2600 if($this->readdata('type','text')<>'') $data['type'] = $this->readdata('type','text'); else $data['type'] = $con->type; 2601 2602 if($this->readdata('downloadname1','text')<>$con->downloadname1) $data['downloadname1'] = $this->readdata('downloadname1','text'); 2603 if($this->readdata('downloadlink1','text')<>$con->downloadlink1) $data['downloadlink1'] = $this->readdata('downloadlink1','text'); 2604 if($this->readdata('description','text')<>'') { $data['description']=$this->readdata('description','text'); } else { $data['description']='...'; } 2605 if($this->readdata('summary','text')<>'') { $data['summary']=$this->readdata('summary','text'); } else { $data['summary']='...'; } 2606 if($this->readdata('version','text')<>'') { $data['version']=$this->readdata('version','text'); } else { $data['version']='...'; } 2607 if($this->readdata('changelog','text')<>'') { $data['changelog']=$this->readdata('changelog','text'); } else { $data['changelog']='...'; } 2608 if($this->readdata('license','int') >=0 or $this->readdata('license','int')<5) $data['license']=$this->readdata('license','int'); 2609 2610 if( ($data['name']<>'') or ($data['type']<0) or ($data['type']>$numcats) ) { 2611 $con->update(array("name","type","downloadname1","downloadlink1","description","summary","version","changelog","license")); 2612 2613 $xml = array(); 2614 $txt = $this->generatexml($format,'ok',100,'',$xml,'content'); 2615 }else{ 2616 $txt = $this->generatexml($format,'failed',101,'please specify all mandatory fields'); 2617 } 2618 }else{ 2619 $txt=$this->generatexml($format,'failed',102,'no permission to change content'); 2620 } 2621 $con->updated(); 2622 2623 echo($txt); 2624 2625 } 2626 2627 2628 2629 /** 2630 * delete a content 2631 * @param string $format 2632 * @param string $contentid 2633 * @return string xml/json 2634 */ 2635 private function contentdelete($format,$contentid) { 2636 2637 $user=$this->checkpassword(true); 2638 $this->checktrafficlimit($user); 2639 $content=addslashes($contentid); 2640 2641 // fetch data 2642 $con = new OCSContent(); 2643 if(!$con->load($content)){ 2644 $txt=$this->generatexml($format,'failed',101,'no permission to change content'); 2645 } else { 2646 if(!$con->is_owned(OCSUser::id())){ 2647 $txt=$this->generatexml($format,'failed',101,'no permission to change content'); 2648 } else { 2649 $con->delete(); 2650 $txt=$this->generatexml($format,'ok',100,''); 2651 } 2652 } 2653 2654 echo($txt); 2655 } 2656 2657 2658 //KNOWLEDGEBASE API ############################################# 2659 2660 /** 2661 * get a specific knowledgebase entry 2662 * @param string $format 2663 * @param string $kbid 2664 * @return string xml/json 2665 */ 2666 private function knowledgebaseget($format,$kbid) { 2667 $user=$this->checkpassword(); 2668 $this->checktrafficlimit($user); 2669 $kbid=addslashes($kbid); 2670 2671 $cache = new H01_CACHE('apiknowledgebaseget',array($_SESSION['website'],$_SESSION['lang'],$kbid,$format)); 2672 if ($cache->exist()) { 2673 $cache->get(); 2674 unset($cache); 2675 } else { 2676 2677 // fetch data 2678 $con=H01_KNOWLEDGEBASE::getentry($kbid); 2679 2680 // check data 2681 if (($con['id'])==0) { 2682 $txt=$this->generatexml($format,'failed',101,'entry not found'); 2683 } else { 2684 2685 if(trim($con['answer'])=='') $status=1; else $status=2; 2686 $xml['id']=$con['id']; 2687 $xml['status']=H01_KNOWLEDGEBASE::$STATUS[1][$status]; 2688 $xml['contentid']=$con['contentid']; 2689 $xml['category']=H01_KNOWLEDGEBASE::$TYPE[1][1][$con['type']]; 2690 $xml['user']=$con['user']; 2691 $xml['changed']=date('c',$con['changed']); 2692 $xml['name']=$con['name']; 2693 $xml['description']=$con['description']; 2694 $xml['answeruser']=$con['user2']; 2695 $xml['answer']=$con['answer']; 2696 $xml['comments']=$con['commentscount']; 2697 $xml['detailpage']='http://'.CONFIG_WEBSITEHOST.'/content/show.php?action=knowledgebase&content='.$con['contentid'].'&kbid='.$con['id']; 2698 2699 // preview 2700 if (!empty($con['pic1'])) $pic1=$con['pic1']; else $pic1=''; 2701 if (!empty($con['pic2'])) $pic2=$con['pic2']; else $pic2=''; 2702 if (!empty($con['pic3'])) $pic3=$con['pic3']; else $pic3=''; 2703 2704 2705 if(!empty($pic1)) $xml['previewpic1']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-pics1/'.$pic1; 2706 if(!empty($pic1)) $xml['smallpreviewpic1']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-m1/'.$pic1; 2707 2708 if(!empty($pic2)) $xml['previewpic2']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-pics2/'.$pic2; 2709 if(!empty($pic2)) $xml['smallpreviewpic2']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-m2/'.$pic2; 2710 2711 if(!empty($pic3)) $xml['previewpic3']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-pics3/'.$pic3; 2712 if(!empty($pic3)) $xml['smallpreviewpic3']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-m3/'.$pic3; 2713 2714 if(!empty($pic4)) $xml['previewpic4']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-pics4/'.$pic4; 2715 if(!empty($pic4)) $xml['smallpreviewpic4']='http://'.CONFIG_WEBSITEHOST.'/CONTENT/knowledgebase-m4/'.$pic4; 2716 2717 $xml2[0]=$xml; 2718 $txt=$this->generatexml($format,'ok',100,'',$xml2,'knowledgebase','',2); 2719 2720 } 2721 2722 $cache->put($txt); 2723 unset($cache); 2724 echo($txt); 2725 } 2726 } 2727 2728 2729 /** 2730 * get a list of knowledgebase entries 2731 * @param string $format 2732 * @param string $contents 2733 * @param string $searchstr 2734 * @param string $sortmode 2735 * @param string $page 2736 * @param string $pagesize 2737 * @return string xml/json 2738 */ 2739 private function knowledgebaselist($format,$contents,$searchstr,$sortmode,$page,$pagesize) { 2740 $user=$this->checkpassword(); 2741 $this->checktrafficlimit($user); 2742 2743 $cache = new H01_CACHE('apiknowledgebaselist',array($_SESSION['website'],$_SESSION['lang'],$format,$contents.$searchstr.$sortmode.$page.$pagesize)); 2744 if ($cache->exist()) { 2745 $cache->get(); 2746 unset($cache); 2747 } else { 2748 2749 $xml=H01_KNOWLEDGEBASE::search($contents,$searchstr,$sortmode,$page,$pagesize); 2750 $totalitems=$xml['totalitems']; 2751 unset($xml['totalitems']); 2752 2753 $txt=$this->generatexml($format,'ok',100,'',$xml,'content','detail',2,$totalitems,$pagesize); 2754 2755 $cache->put($txt); 2756 unset($cache); 2757 echo($txt); 2758 } 2759 2760 } 2761 2762 2763 2764 // EVENT API ############################################# 2765 2766 /** 2767 * get a specific event 2768 * @param string $format 2769 * @param string $evid 2770 * @return string xml/json 2771 */ 2772 private function eventget($format,$evid) { 2773 2774 $user=$this->checkpassword(); 2775 $this->checktrafficlimit($user); 2776 $evid=addslashes($evid); 2777 2778 $cache = new H01_CACHE('apieventget',array($_SESSION['website'],$_SESSION['lang'],$evid,$format)); 2779 if ($cache->exist()) { 2780 $cache->get(); 2781 unset($cache); 2782 } else { 2783 2784 // fetch data 2785 $con=H01_EVENT::get($evid,0); 2786 2787 // check data 2788 if (($con['id'])==0) { 2789 $txt=$this->generatexml($format,'failed',100,'entry not found'); 2790 } else { 2791 2792 $xml['id']=$con['id']; 2793 $xml['name']=$con['name']; 2794 $xml['description']=$con['description']; 2795 $xml['category']=H01_EVENT::$CATEGORIES[0][1][$con['category']]; 2796 $xml['startdate']=date('c',$con['startdate']); 2797 $xml['enddate']=date('c',$con['enddate']); 2798 $xml['user']=$con['user']; 2799 $xml['organizer']=$con['organizer']; 2800 $xml['location']=$con['location']; 2801 $xml['city']=$con['city']; 2802 $xml['country']=H01_USER::$COUNTRIES[$con['country']]; 2803 $xml['longitude']=$con['longitude']; 2804 $xml['latitude']=$con['latitude']; 2805 $xml['homepage']=$con['homepage']; 2806 $xml['tel']=$con['tel']; 2807 $xml['fax']=$con['fax']; 2808 $xml['email']=$con['email']; 2809 $xml['changed']=date('c',$con['changed']); 2810 $xml['comments']=$con['comments']; 2811 $xml['participants']=$con['participants']; 2812 $xml['detailpage']='http://'.CONFIG_WEBSITEHOST.'/events/?id='.$con['id']; 2813 2814 $photourl='/CONTENT/event-badge/0/'.$con['id'].'.'; 2815 if (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'gif')) $xml['badge']='http://'.CONFIG_WEBSITEHOST.$photourl.'gif'; 2816 elseif (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'png')) $xml['badge']='http://'.CONFIG_WEBSITEHOST.$photourl.'png'; 2817 elseif (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'jpg')) $xml['badge']='http://'.CONFIG_WEBSITEHOST.$photourl.'jpg'; 2818 else $xml['badge']=''; 2819 2820 2821 $photourl='/CONTENT/event-image/0/'.$con['id'].'.'; 2822 if (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'gif')) $xml['image']='http://'.CONFIG_WEBSITEHOST.$photourl.'gif'; 2823 elseif (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'png')) $xml['image']='http://'.CONFIG_WEBSITEHOST.$photourl.'png'; 2824 elseif (file_exists(CONFIG_DOCUMENT_ROOT.$photourl.'jpg')) $xml['image']='http://'.CONFIG_WEBSITEHOST.$photourl.'jpg'; 2825 else $xml['image']=''; 2826 2827 2828 $xml2[0]=$xml; 2829 $txt=$this->generatexml($format,'ok',100,'',$xml2,'event','',2); 2830 2831 } 2832 2833 $cache->put($txt); 2834 unset($cache); 2835 echo($txt); 2836 } 2837 } 2838 2839 2840 /** 2841 * get a list of events 2842 * @param string $format 2843 * @param string $type 2844 * @param string $country 2845 * @param string $startat 2846 * @param string $searchstr 2847 * @param string $sortmode 2848 * @param string $page 2849 * @param string $pagesize 2850 * @return string xml/json 2851 */ 2852 private function eventlist($format,$type,$country,$startat,$searchstr,$sortmode,$page,$pagesize) { 2853 $user=$this->checkpassword(); 2854 $this->checktrafficlimit($user); 2855 2856 $cache = new H01_CACHE('apieventlist',array($_SESSION['website'],$_SESSION['lang'],$format,$type.$country.$startat.$searchstr.$sortmode.$page.$pagesize)); 2857 if ($cache->exist()) { 2858 $cache->get(); 2859 unset($cache); 2860 } else { 2861 2862 $xml=H01_EVENT::search($type,$country,$startat,$searchstr,$sortmode,$page,$pagesize); 2863 $totalitems=$xml['totalitems']; 2864 unset($xml['totalitems']); 2865 2866 $txt=$this->generatexml($format,'ok',100,'',$xml,'event','detail',2,$totalitems,$pagesize); 2867 2868 $cache->put($txt); 2869 unset($cache); 2870 echo($txt); 2871 } 2872 2873 } 2874 2875 2876 /** 2877 * add a new event 2878 * @param string $format 2879 * @return string xml/json 2880 */ 2881 private function eventadd($format) { 2882 2883 $user=$this->checkpassword(); 2884 $this->checktrafficlimit($user); 2885 2886 $name=$this->readdata('name','text'); 2887 $category=$this->readdata('category','int'); 2888 2889 if($this->readdata('description','text')<>'') $description=$this->readdata('description','text'); else $description=''; 2890 if($this->readdata('startdate','text')<>'') $startdate=strtotime($this->readdata('startdate','raw')); else $startdate=0; 2891 if($this->readdata('enddate','text')<>'') $enddate=strtotime($this->readdata('enddate','raw')); else $enddate=0; 2892 2893 if($this->readdata('organizer','text')<>'') $organizer=$this->readdata('organizer','text'); else $organizer=''; 2894 if($this->readdata('location','text')<>'') $location=$this->readdata('location','text'); else $location=''; 2895 if($this->readdata('city','text')<>'') $city=$this->readdata('city','text'); else $city=''; 2896 if($this->readdata('country','text')<>'') $country=$this->readdata('country','text'); else $country=''; 2897 $co=array_search(strtoupper($country),H01_USER::$COUNTRIESISO); 2898 2899 if($this->readdata('longitude','float')<>'') $longitude=$this->readdata('longitude','float'); else $longitude=''; 2900 if($this->readdata('latitude','float')<>'') $latitude=$this->readdata('latitude','float'); else $latitude=''; 2901 2902 if($this->readdata('homepage','text')<>'') $homepage=$this->readdata('homepage','text'); else $homepage=''; 2903 if($this->readdata('tel','text')<>'') $tel=$this->readdata('tel','text'); else $tel=''; 2904 if($this->readdata('fax','text')<>'') $fax=$this->readdata('fax','text'); else $fax=''; 2905 if($this->readdata('email','text')<>'') $email=$this->readdata('email','text'); else $email=''; 2906 2907 if($user<>'') { 2908 if(($name<>'' and $category<>0)) { 2909 $id=H01_EVENT::create(CONFIG_EVENTDB,$name,$description,$category,$startdate,$enddate,$user,CONFIG_USERDB,$organizer,$location,$city,$co,$longitude,$latitude,$homepage,$tel,$fax,$email); 2910 $xml=array(); 2911 $xml[0]['id']=$id; 2912 $txt=$this->generatexml($format,'ok',100,'',$xml,'event','',2); 2913 }else{ 2914 $txt=$this->generatexml($format,'failed',101,'please specify all mandatory fields'); 2915 } 2916 }else{ 2917 $txt=$this->generatexml($format,'failed',102,'no permission to add event'); 2918 } 2919 2920 echo($txt); 2921 2922 } 2923 2924 2925 /** 2926 * delete a event 2927 * @param string $format 2928 * @param string $eventid 2929 * @return string xml/json 2930 */ 2931 private function eventdelete($format,$eventid) { 2932 $user=$this->checkpassword(); 2933 $this->checktrafficlimit($user); 2934 $event=addslashes($eventid); 2935 2936 // fetch data 2937 $con=H01_EVENT::get($event,CONFIG_EVENTDB); 2938 if(isset($con['user'])) { 2939 2940 if((($con['user']==$user) and ($con['userdb']==CONFIG_USERDB) ) or (H01_AUTH::checkuser(PERM_Event_Admin,$user,CONFIG_USERDB))) { 2941 H01_EVENT::del($event,$user); 2942 $txt=$this->generatexml($format,'ok',100,''); 2943 }else{ 2944 $txt=$this->generatexml($format,'failed',101,'no permission to change event'); 2945 } 2946 }else{ 2947 $txt=$this->generatexml($format,'failed',101,'ano permission to change event'); 2948 } 2949 2950 echo($txt); 2951 2952 } 2953 2954 2955 /** 2956 * edit a event 2957 * @param string $format 2958 * @param string $eventid 2959 * @return string xml/json 2960 */ 2961 private function eventedit($format,$eventid) { 2962 $user=$this->checkpassword(); 2963 $this->checktrafficlimit($user); 2964 $event=addslashes($eventid); 2965 2966 // fetch data 2967 $DBevent=H01_EVENT::get($event,CONFIG_EVENTDB); 2968 if(isset($DBevent['user'])) { 2969 2970 if((($DBevent['user']==$user) and ($DBevent['userdb']==CONFIG_USERDB) ) or (H01_AUTH::checkuser(PERM_Event_Admin,$user,CONFIG_USERDB))) { 2971 2972 if(isset($_POST['name'])) $name=$this->readdata('name','text'); else $name=$DBevent['name']; 2973 if(isset($_POST['category'])) $category=$this->readdata('category','int'); else $category=$DBevent['category']; 2974 2975 if(isset($_POST['description'])) $description=$this->readdata('description','text'); else $description=$DBevent['description']; 2976 if(isset($_POST['startdate'])) $startdate=strtotime($this->readdata('startdate','raw')); else $startdate=$DBevent['startdate']; 2977 if(isset($_POST['enddate'])) $enddate=strtotime($this->readdata('enddate','raw')); else $enddate=$DBevent['enddate']; 2978 if(isset($_POST['organizer'])) $organizer=$this->readdata('organizer','text'); else $organizer=$DBevent['organizer']; 2979 if(isset($_POST['location'])) $location=$this->readdata('location','text'); else $location=$DBevent['location']; 2980 if(isset($_POST['city'])) $city=$this->readdata('city','text'); else $city=$DBevent['city']; 2981 if(isset($_POST['country'])) { 2982 $country=$this->readdata('country','text'); 2983 $country=array_search(strtoupper($country),H01_USER::$COUNTRIESISO); 2984 }else { 2985 $country=$DBevent['country']; 2986 } 2987 if(isset($_POST['longitude'])) $longitude=$this->readdata('longitude','float'); else $longitude=$DBevent['longitude']; 2988 if(isset($_POST['latitude'])) $latitude=$this->readdata('latitude','float'); else $latitude=$DBevent['latitude']; 2989 if(isset($_POST['homepage'])) $homepage=$this->readdata('homepage','text'); else $homepage=$DBevent['homepage']; 2990 if(isset($_POST['tel'])) $tel=$this->readdata('tel','text'); else $tel=$DBevent['tel']; 2991 if(isset($_POST['fax'])) $fax=$this->readdata('fax','text'); else $fax=$DBevent['fax']; 2992 if(isset($_POST['email'])) $email=$this->readdata('email','text'); else $email=$DBevent['email']; 2993 2994 if(($name<>'') and ($category<>0)) { 2995 2996 H01_EVENT::edit($event,CONFIG_EVENTDB,$name,$description,$category,$startdate,$enddate,$user,CONFIG_USERDB,$organizer,$location,$city,$country,$longitude,$latitude,$homepage,$tel,$fax,$email); 2997 $txt=$this->generatexml($format,'ok',100,''); 2998 }else{ 2999 $txt=$this->generatexml($format,'failed',101,'please specify all mandatory fields'); 3000 } 3001 }else{ 3002 $txt=$this->generatexml($format,'failed',102,'no permission to change event'); 3003 } 3004 }else{ 3005 $txt=$this->generatexml($format,'failed',102,'event not found'); 3006 } 3007 3008 echo($txt); 3009 } 3010 3011 3012 3013 // COMMENTS API ############################################# 3014 3015 /** 3016 * add a comment 3017 * @param string $format 3018 * @param string $content 3019 * @param string $parent 3020 * @param string $subject 3021 * @param string $message 3022 * @return string xml/json 3023 */ 3024 private function commentsadd($format,$type,$content,$content2,$parent,$subject,$message) { 3025 $user = $this->checkpassword(true); 3026 $this->checktrafficlimit($user); 3027 $data['parent'] = strip_tags(addslashes($parent)); 3028 $data['subject'] = strip_tags(addslashes($subject)); 3029 $data['message'] = strip_tags(addslashes($message)); 3030 $data['content'] = strip_tags(addslashes($content)); 3031 $data['content2'] = strip_tags(addslashes($content2)); 3032 $data['type'] = strip_tags(addslashes($type)); 3033 $data['owner'] = OCSUser::id(); 3034 3035 //types 3036 // just 1 is accepted 3037 // 1 - content 3038 3039 //setting content type as default 3040 if(!in_array($data['type'],array(1,4,7,8))) $data['type']=1; 3041 3042 if($user<>'') { 3043 if($data['message']<>'' and $data['subject']<>'') { 3044 if($data['content']<>0) { 3045 $comment = new OCSComment(); //creating new object 3046 $comment->set_data($data); //loading new data for comment 3047 $comment->save_to_db(); 3048 $id = $comment->id(); 3049 $xml[0]['id'] = $id; 3050 echo($this->generatexml($format,'ok',100,'',$xml,'comment','',2)); 3051 } else { 3052 echo($this->generatexml($format,'failed',101,'content must not be empty')); 3053 } 3054 } else { 3055 echo($this->generatexml($format,'failed',102,'message or subject must not be empty')); 3056 } 3057 } else { 3058 echo($this->generatexml($format,'failed',103,'no permission to add a comment')); 3059 } 3060 3061 } 3062 3063 3064 3065 private function commentsget($format,$type,$content,$content2,$page,$pagesize) { 3066 $user=$this->checkpassword(false); 3067 $this->checktrafficlimit($user); 3068 $type = strip_tags(addslashes($type)); 3069 $content = strip_tags(addslashes($content)); 3070 $content2 = strip_tags(addslashes($content2)); 3071 $page = strip_tags(addslashes($page)); 3072 $pagesize = strip_tags(addslashes($pagesize)); 3073 3074 //types 3075 // 1 - content 3076 // 4 - forum 3077 // 7 - knowledgebase 3078 // 8 - event 3079 3080 if(!in_array($type,array(1,4,7,8))) $type=1; 3081 3082 $coml = new OCSCommentLister(); 3083 $comments = $coml->ocs_comment_list($type,$content,$content2,$page,$pagesize); 3084 $totalitems = count($comments); 3085 //$txt=$this->generatexml($format,'ok',100,'',$comments,'event','detail',2,$totalitems,$pagesize); 3086 3087 $txt=$this->generatexml($format,'ok',100,'',$comments,'comment','','dynamic',$totalitems,$pagesize); 3088 echo($txt); 3089 3090 3091 } 3092 3093 3094 /** 3095 * vote for a comment 3096 * @param string $format 3097 * @param string $id 3098 * @param string $score 3099 * @return string xml/json 3100 */ 3101 private function commentvote($format,$id,$score) { 3102 $user=$this->checkpassword(true); 3103 $this->checktrafficlimit($user); 3104 3105 $comment = new OCSComment(); 3106 if($comment->load($id)){ 3107 3108 $comment->set_score($score); 3109 $txt=$this->generatexml($format,'ok',100,''); 3110 echo($txt); 3111 } else { 3112 $txt=$this->generatexml($format,'failed',101,'comment not found'); 3113 } 3114 } 3115 3116 3117 // FORUM 3118 3119 /** 3120 * Get a list of forums 3121 * @param string $format 3122 * @param int $page The list page. You can control the size of a page with the pagesize argument. The first page is 0, the second is 1. 3123 * @param int $pagesize The amount of entries per page. 3124 * @return string xml/json 3125 */ 3126 private function forumlist($format,$page,$pagesize){ 3127 $user=$this->checkpassword(); 3128 $this->checktrafficlimit($user); 3129 3130 // Call forum implementation here 3131 $txt=$this->generatexml($format,'ok',100,''); 3132 echo($txt); 3133 } 3134 3135 /** 3136 * Gets a list of a specific set of topics. 3137 * @param string $format 3138 * @param string $forum Id of the forum you are requesting a list of. Not required if a search term is provided. 3139 * @param string $search a keyword you want find in the name. 3140 * @param string $description the description or comment of a topic. Not required if a forum id is provided. 3141 * @param string $sortmode The sortmode of the list. Possible values are: "new" - newest first or "alpha" - alphabetical 3142 * @param int $page The list page. You can control the size of a page with the pagesize argument. The first page is 0, the second is 1. 3143 * @param int $pagesize The amount of entries per page. 3144 * @return string xml/json 3145 */ 3146 private function forumtopiclist($format,$forum,$search,$description,$sortmode,$page,$pagesize){ 3147 $user=$this->checkpassword(); 3148 $this->checktrafficlimit($user); 3149 3150 // Call forum implementation here 3151 $txt=$this->generatexml($format,'ok',100,''); 3152 echo($txt); 3153 } 3154 3155 /** 3156 * Add a new topic to a forum. Only authenticated users are allowed to access this method. 3157 * Authentication is done by sending a Basic HTTP Authorisation header. All arguments are 3158 * mandatory. 3159 * @param string $format 3160 * @param string $subject Subject of the new topic 3161 * @param string $content Content of the first post of the new topic 3162 * @param string $forum id of the forum entry to be added to if available 3163 * @return string xml/json 3164 */ 3165 private function forumtopicadd($format,$subject,$content,$forum){ 3166 $user=$this->checkpassword(); 3167 $this->checktrafficlimit($user); 3168 3169 // Call forum implementation here 3170 $txt=$this->generatexml($format,'ok',100,''); 3171 echo($txt); 3172 } 3173 3174 // BUILDSERVICE 3175 3176 /** 3177 * Create a new project in the build service 3178 * @param string $format 3179 * @param string $name 3180 * @param string $version 3181 * @param string $license 3182 * @param string $url 3183 * @param array $developers 3184 * @param string $summary 3185 * @param string $description 3186 * @param string $requirements 3187 * @param string $specfile 3188 * @return string xml/json 3189 */ 3190 private function buildserviceprojectcreate($format,$name='',$version='',$license='',$url='',$developers='',$summary='',$description='',$requirements='',$specfile=''){ 3191 $user=$this->checkpassword(true); 3192 $this->checktrafficlimit($user); 3193 3194 if(strlen($name)<1){ 3195 echo($this->generatexml($format,'failed',101,'required argument missing: name')); 3196 return; 3197 } 3198 3199 $data=H01_BUILDSERVICE::projectcreate($user,CONFIG_USERDB,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 3200 $txt=""; 3201 if($data!=NULL) { 3202 $txt=$this->generatexml($format,'ok',100,'',$data,'buildservice','','dynamic'); 3203 // This looks a bit odd - but errors are also cached, and as such we got to expire the error 3204 // page for attempting to fetch a wrongly IDd project 3205 H01_CACHEADMIN::cleancache('apibuildserviceprojectget',$_SESSION['website'],$_SESSION['lang'],$format,$user.'#'.$data['projectid']); 3206 H01_CACHEADMIN::cleancache('apibuildserviceprojectlist',$_SESSION['website'],$_SESSION['lang'],$format,$user); 3207 } else 3208 $txt=$this->generatexml($format,'failed',101,''); 3209 echo($txt); 3210 } 3211 3212 /** 3213 * Get the data for a project in the build service 3214 * @param string $format 3215 * @param int $projectID 3216 * @return string xml/json 3217 */ 3218 private function buildserviceprojectget($format,$projectID){ 3219 $user=$this->checkpassword(true); 3220 $this->checktrafficlimit($user); 3221 3222 $cache = new H01_CACHE('apibuildserviceprojectget',array($_SESSION['website'],$_SESSION['lang'],$format,$user.'#'.$projectID)); 3223 if ($cache->exist()) { 3224 $cache->get(); 3225 unset($cache); 3226 } else { 3227 $txt=""; 3228 $data=H01_BUILDSERVICE::projectget($user,CONFIG_USERDB,$projectID); 3229 3230 if(count($data["project"])>0) 3231 $txt=$this->generatexml($format,'ok',100,'',$data,'buildservice','','dynamic'); 3232 else { 3233 if(is_numeric($projectID)) 3234 $txt=$this->generatexml($format,'failed',101,'no such project'); 3235 else 3236 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3237 } 3238 $cache->put($txt); 3239 unset($cache); 3240 echo($txt); 3241 } 3242 } 3243 3244 /** 3245 * Delete a project in the build service 3246 * @param string $format 3247 * @param int $projectID 3248 * @return string xml/json 3249 */ 3250 private function buildserviceprojectdelete($format,$projectID){ 3251 $user=$this->checkpassword(true); 3252 $this->checktrafficlimit($user); 3253 3254 $data=H01_BUILDSERVICE::projectdelete($user,CONFIG_USERDB,$projectID); 3255 3256 $txt=""; 3257 if($data==true) { 3258 $txt=$this->generatexml($format,'ok',100,''); 3259 H01_CACHEADMIN::cleancache('apibuildserviceprojectget',$_SESSION['website'],$_SESSION['lang'],$format,$user.'#'.$projectID); 3260 H01_CACHEADMIN::cleancache('apibuildserviceprojectlist',$_SESSION['website'],$_SESSION['lang'],$format,$user); 3261 } else { 3262 if(is_numeric($projectID)) 3263 $txt=$this->generatexml($format,'failed',101,'no such project'); 3264 else 3265 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3266 } 3267 3268 echo($txt); 3269 } 3270 3271 /** 3272 * Change the details of a project in the build service 3273 * @param string $format 3274 * @param int @projectID 3275 * @param string $name 3276 * @param string $version 3277 * @param string $license 3278 * @param string $url 3279 * @param array $developers 3280 * @param string $summary 3281 * @param string $description 3282 * @param string $requirements 3283 * @param string $specfile 3284 * @return string xml/json 3285 */ 3286 private function buildserviceprojectedit($format,$projectID,$name="",$version="",$license="",$url="",$developers='',$summary="",$description="",$requirements="",$specfile=""){ 3287 $user=$this->checkpassword(true); 3288 $this->checktrafficlimit($user); 3289 3290 // This looks slightly odd - we do this because the function in the buildservice module requires 3291 // a 0 here if you do not intend to clear the field - it checks the data type to be a real int. 3292 if(!array_key_exists("specfile",$_POST)) 3293 $specfile=0; 3294 3295 $data=H01_BUILDSERVICE::projectedit($user,CONFIG_USERDB,$projectID,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 3296 $txt=""; 3297 if($data===true) { 3298 $txt=$this->generatexml($format,'ok',100,''); 3299 H01_CACHEADMIN::cleancache('apibuildserviceprojectget',$_SESSION['website'],$_SESSION['lang'],$format,$user.'#'.$projectID); 3300 H01_CACHEADMIN::cleancache('apibuildserviceprojectlist',$_SESSION['website'],$_SESSION['lang'],$format,$user); 3301 } else { 3302 if(is_numeric($projectID)) 3303 $txt=$this->generatexml($format,'failed',101,'no such project'); 3304 else 3305 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3306 } 3307 3308 echo($txt); 3309 } 3310 3311 /** 3312 * List all the projects in the build service owned by the authorized user 3313 * @param string $format 3314 * @param int $page 3315 * @param int $pagesize 3316 * @return string xml/json 3317 */ 3318 private function buildserviceprojectlist($format,$page,$pagesize){ 3319 $user=$this->checkpassword(true); 3320 $this->checktrafficlimit($user); 3321 3322 $cache = new H01_CACHE('apibuildserviceprojectlist',array($_SESSION['website'],$_SESSION['lang'],$format,$user)); 3323 if ($cache->exist()) { 3324 $cache->get(); 3325 unset($cache); 3326 } else { 3327 $data=H01_BUILDSERVICE::projectlist($user,CONFIG_USERDB); 3328 $txt=$this->generatexml($format,'ok',100,'',$data,'project','','dynamic'); 3329 3330 $cache->put($txt); 3331 unset($cache); 3332 echo($txt); 3333 } 3334 } 3335 3336 /** 3337 * Upload a new source bundle (a compressed file in .zip, .tar.gz or .tar.bz2 format) containing 3338 * the source code of the project 3339 * @param string $format 3340 * @param int $projectID 3341 * @return string xml/json 3342 */ 3343 private function buildserviceprojectuploadsource($format,$projectID){ 3344 $user=$this->checkpassword(true); 3345 $this->checktrafficlimit($user); 3346 3347 if(!is_numeric($projectID)){ 3348 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3349 }else{ 3350 $error=H01_BUILDSERVICE::projectuploadsource($user,CONFIG_USERDB,$projectID); 3351 3352 if($error==''){ 3353 $txt=$this->generatexml($format,'ok',100,''); 3354 }else{ 3355 $txt=$this->generatexml($format,'failed',103,$error); 3356 } 3357 3358 } 3359 3360 3361 echo($txt); 3362 } 3363 3364 // REMOTEACCOUNTS section 3365 3366 /** 3367 * List all accounts for the currently authorised user 3368 * @param string $format 3369 * @return string xml/json 3370 */ 3371 private function buildserviceremoteaccountslist($format,$page,$pagesize) { 3372 $user=$this->checkpassword(true); 3373 $this->checktrafficlimit($user); 3374 3375 $data=H01_BUILDSERVICE::remoteaccountslist($user,CONFIG_USERDB); 3376 $txt=$this->generatexml($format,'ok',100,'',$data,'remoteaccount','','dynamic'); 3377 echo($txt); 3378 } 3379 3380 /** 3381 * Add a remote account entry for the currently authorised user 3382 * @param string $format 3383 * @param int $type The type of account (1 == build service, 2 == publisher) 3384 * @param string $typeid The ID of the service the account pertains to 3385 * @param string $data The data to enter into the data section (any arbitrary string data) 3386 * @param string $login The user's login on the remote service 3387 * @param string $password The user's password on the remote service 3388 * @return string xml/json 3389 */ 3390 private function buildserviceremoteaccountsadd($format,$type,$typeid,$data,$login,$password) { 3391 $user=$this->checkpassword(true); 3392 $this->checktrafficlimit($user); 3393 3394 $txt=''; 3395 $data=H01_BUILDSERVICE::remoteaccountsadd($user,CONFIG_USERDB,$type,$typeid,$data,$login,$password); 3396 if(array_key_exists('remoteaccountid',$data)) { 3397 $txt=$this->generatexml($format,'ok',100,''); 3398 } else { 3399 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3400 } 3401 3402 echo($txt); 3403 } 3404 3405 /** 3406 * Edit the specified remote account entry 3407 * @param string $format 3408 * @param int $id The ID of the remote account to edit 3409 * @param string $data The data to enter into the data section (any arbitrary string data) 3410 * @param string $login The user's login on the remote service 3411 * @param string $password The user's password on the remote service 3412 * @return string xml/json 3413 */ 3414 private function buildserviceremoteaccountsedit($format,$id,$login,$password,$data) { 3415 $user=$this->checkpassword(true); 3416 $this->checktrafficlimit($user); 3417 3418 $txt=''; 3419 $data=H01_BUILDSERVICE::remoteaccountsedit($user,CONFIG_USERDB,$id,$login,$password,$data); 3420 if($data) { 3421 $txt=$this->generatexml($format,'ok',100,''); 3422 } else { 3423 $txt=$this->generatexml($format,'failed',101,'no such remote account'); 3424 } 3425 3426 echo($txt); 3427 } 3428 3429 /** 3430 * Fetch all known information about a specified remote account 3431 * @param string $format 3432 * @param int $id The ID of the remote account to get 3433 * @return string xml/json 3434 */ 3435 private function buildserviceremoteaccountsget($format,$id) { 3436 $user=$this->checkpassword(true); 3437 $this->checktrafficlimit($user); 3438 3439 $txt=''; 3440 $data=H01_BUILDSERVICE::remoteaccountsget($user,CONFIG_USERDB,$id); 3441 if(!array_key_exists('code',$data)) { 3442 $txt=$this->generatexml($format,'ok',100,'',$data,'remoteaccount','','dynamic'); 3443 } else { 3444 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3445 } 3446 3447 echo($txt); 3448 } 3449 3450 /** 3451 * Delete the specified remote account entry 3452 * @param string $format 3453 * @param int $id The ID of the remote account to remove 3454 * @return string xml/json 3455 */ 3456 private function buildserviceremoteaccountsremove($format,$id) { 3457 $user=$this->checkpassword(true); 3458 $this->checktrafficlimit($user); 3459 3460 $txt=''; 3461 $data=H01_BUILDSERVICE::remoteaccountsremove($user,CONFIG_USERDB,$id); 3462 if(!is_array($data)) { 3463 $txt=$this->generatexml($format,'ok',100,''); 3464 } else { 3465 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3466 } 3467 3468 echo($txt); 3469 } 3470 3471 // BUILDSERVICES section 3472 3473 /** 3474 * get build service listing 3475 * @param string $format 3476 * @return string xml/json 3477 */ 3478 private function buildservicebuildserviceslist($format,$page,$pagesize) { 3479 $user=$this->checkpassword(false); 3480 $this->checktrafficlimit($user); 3481 3482 $data=H01_BUILDSERVICE::buildserviceslist($user,CONFIG_USERDB); 3483 $txt=$this->generatexml($format,'ok',100,'',$data,array('','buildservice','','target'),'','dynamic'); 3484 echo($txt); 3485 } 3486 3487 /** 3488 * get build service data 3489 * @param string $format 3490 * @param string $buildserviceID 3491 * @return string xml/json 3492 */ 3493 private function buildservicebuildservicesget($format,$buildserviceID) { 3494 $user=$this->checkpassword(false); 3495 $this->checktrafficlimit($user); 3496 3497 $data=H01_BUILDSERVICE::buildservicesget($user,CONFIG_USERDB,$buildserviceID); 3498 if(is_array($data['buildservice']) && count($data['buildservice'])>0) { 3499 $txt=$this->generatexml($format,'ok',100,'',$data,array('buildservice','','target'),'','dynamic'); 3500 } else { 3501 if(is_numeric($buildserviceID)) { 3502 $txt=$this->generatexml($format,'failed',101,'no such build service'); 3503 } else { 3504 $txt=$this->generatexml($format,'failed',101,'no such build service - the build service ID should be an integer'); 3505 } 3506 } 3507 echo($txt); 3508 } 3509 3510 // JOBS section 3511 3512 /** 3513 * Get a list of jobs pertaining to one project on the build service 3514 * @param string $format 3515 * @param int $projectID 3516 * @param int $page 3517 * @param int $pagesize 3518 * @return string xml/json 3519 */ 3520 private function buildservicejobslist($format,$projectID,$page,$pagesize){ 3521 $user=$this->checkpassword(true); 3522 $this->checktrafficlimit($user); 3523 3524 $data=H01_BUILDSERVICE::jobslist($user,CONFIG_USERDB,$projectID); 3525 if(!array_key_exists('code',$data)) { 3526 $txt=$this->generatexml($format,'ok',100,'',$data,'buildjob','','dynamic'); 3527 } else { 3528 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3529 } 3530 3531 echo($txt); 3532 } 3533 3534 /** 3535 * Create a new build job for a specified project, on a specified build service, with a specified 3536 * target 3537 * @param string $format 3538 * @param int $projectID 3539 * @param int $buildserviceID 3540 * @param string $target 3541 * @return string xml/json 3542 */ 3543 private function buildservicejobscreate($format,$projectID,$buildserviceID,$target){ 3544 $user=$this->checkpassword(true); 3545 $this->checktrafficlimit($user); 3546 3547 $data=H01_BUILDSERVICE::jobscreate($projectID,$buildserviceID,$target,$user,CONFIG_USERDB); 3548 $txt=""; 3549 if(array_key_exists('buildjobid',$data) && $data['buildjobid']!=NULL) 3550 $txt=$this->generatexml($format,'ok',100,'',$data,'buildservice','','dynamic'); 3551 else{ 3552 if(is_array($data) and array_key_exists('code',$data)){ 3553 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3554 }else 3555 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3556 } 3557 3558 echo($txt); 3559 } 3560 3561 /** 3562 * Cancel a specified build job 3563 * @param string $format 3564 * @param int $buildjobID 3565 * @return string xml/json 3566 */ 3567 private function buildservicejobscancel($format,$buildjobID){ 3568 $user=$this->checkpassword(true); 3569 $this->checktrafficlimit($user); 3570 3571 $data=H01_BUILDSERVICE::jobscancel($buildjobID,$user,CONFIG_USERDB); 3572 $txt=""; 3573 if($data===true) 3574 $txt=$this->generatexml($format,'ok',100,''); 3575 else{ 3576 if(is_numeric($buildjobID)) 3577 $txt=$this->generatexml($format,'failed',101,'no such build job'); 3578 else 3579 $txt=$this->generatexml($format,'failed',102,'build job id should be an integer'); 3580 } 3581 3582 echo($txt); 3583 } 3584 3585 /** 3586 * Get information about a specified build job 3587 * @param string $format 3588 * @param int $buildjobID 3589 * @return string xml/json 3590 */ 3591 private function buildservicejobsget($format,$buildjobID){ 3592 $user=$this->checkpassword(true); 3593 $this->checktrafficlimit($user); 3594 3595 $data=H01_BUILDSERVICE::jobsget($buildjobID,$user,CONFIG_USERDB); 3596 $txt=""; 3597 if(count($data["buildjob"])>0) 3598 $txt=$this->generatexml($format,'ok',100,'',$data,'buildservice','','dynamic'); 3599 else{ 3600 if(is_numeric($buildjobID)) 3601 $txt=$this->generatexml($format,'failed',101,'no such build job'); 3602 else 3603 $txt=$this->generatexml($format,'failed',102,'build job id should be an integer'); 3604 } 3605 3606 echo($txt); 3607 } 3608 3609 /** 3610 * Get the command output from a specified build job 3611 * @param string $format 3612 * @param int $buildjobID 3613 * @return string xml/json 3614 */ 3615 private function buildservicejobsgetoutput($format,$buildjobID){ 3616 $user=$this->checkpassword(true); 3617 $this->checktrafficlimit($user); 3618 3619 $data=H01_BUILDSERVICE::jobsgetoutput($buildjobID,$user,CONFIG_USERDB); 3620 $txt=""; 3621 if($data["output"]!==NULL) 3622 $txt=$this->generatexml($format,'ok',100,'',$data,'buildservice','','dynamic'); 3623 else{ 3624 if(is_numeric($buildjobID)) 3625 $txt=$this->generatexml($format,'failed',101,'no such build job'); 3626 else 3627 $txt=$this->generatexml($format,'failed',102,'build job id should be an integer'); 3628 } 3629 3630 echo($txt); 3631 } 3632 3633 // Publishing 3634 3635 /** 3636 * Get a list of supported publishers, optionally for the currently authorised user 3637 * @param string $format 3638 * @param int $page 3639 * @param int $pagesize 3640 * @return string xml/json 3641 */ 3642 private function buildservicepublishinggetpublishingcapabilities($format,$page,$pagesize){ 3643 $user=$this->checkpassword(false); 3644 $this->checktrafficlimit($user); 3645 3646 $data=H01_BUILDSERVICE::publishinggetpublishingcapabilities($user,CONFIG_USERDB); 3647 $txt=""; 3648 if(count($data["publishers"])>0){ 3649 $txt=$this->generatexml($format,'ok',100,'',$data,array('','publisher','',array(3=>'field',4=>'target'),'','option'),'','dynamic'); 3650 }else{ 3651 if($user=='') 3652 $txt=$this->generatexml($format,'failed',101,'no such user'); 3653 else 3654 $txt=$this->generatexml($format,'failed',102,'user has not registered with any publishers'); 3655 } 3656 3657 echo($txt); 3658 } 3659 3660 /** 3661 * Get information on a specified publisher 3662 * @param string $format 3663 * @param int $publisherID 3664 * @return string xml/json 3665 */ 3666 private function buildservicepublishinggetpublisher($format,$publisherID){ 3667 $user=$this->checkpassword(false); 3668 $this->checktrafficlimit($user); 3669 3670 $data=H01_BUILDSERVICE::publishinggetpublisher($publisherID); 3671 $txt=""; 3672 if(count($data["publisher"])>0) 3673 $txt=$this->generatexml($format,'ok',100,'',$data,array('','',array(3=>'field',4=>'target'),'','option'),'','dynamic'); 3674 else{ 3675 if(is_numeric($publisherID)) 3676 $txt=$this->generatexml($format,'failed',101,'no such publisher'); 3677 else 3678 $txt=$this->generatexml($format,'failed',102,'publisher id should be an integer'); 3679 } 3680 3681 echo($txt); 3682 } 3683 3684 /** 3685 * Publish the result of a bulid job on some specified project to a publisher 3686 * @param string $format 3687 * @param int $buildjobID 3688 * @param int $publisherID 3689 * @return string xml/json 3690 */ 3691 private function buildservicepublishingpublishtargetresult($format,$buildjobID,$publisherID){ 3692 $user=$this->checkpassword(true); 3693 $this->checktrafficlimit($user); 3694 3695 $data=H01_BUILDSERVICE::publishingpublishtargetresult($buildjobID,$publisherID,$user,CONFIG_USERDB); 3696 $txt=""; 3697 if($data===true) 3698 $txt=$this->generatexml($format,'ok',100,''); 3699 else { 3700 if(is_array($data)) { 3701 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3702 } else if(is_numeric($buildjobID)) { 3703 if(is_numeric($publisherID)) { 3704 $txt=$this->generatexml($format,'failed',108,'publishing failed'); 3705 } else { 3706 $txt=$this->generatexml($format,'failed',107,'publisher id should be an integer'); 3707 } 3708 } else { 3709 $txt=$this->generatexml($format,'failed',105,'build job id should be an integer'); 3710 } 3711 } 3712 3713 echo($txt); 3714 } 3715 3716 /** 3717 * Save some field data (as connected to publishing the project) into that project 3718 * @param string $format 3719 * @param int $projectID 3720 * @param array $fields A bunch of field data, in the form 3721 * array( array("name"=>value,"fieldtype"=>value,"data"=>value), array(...)) 3722 * @return string xml/json 3723 */ 3724 private function buildservicepublishingsavefields($format,$projectID,$fields){ 3725 $user=$this->checkpassword(true); 3726 $this->checktrafficlimit($user); 3727 3728 $data=H01_BUILDSERVICE::publishingsavefields($projectID,$fields,$user,CONFIG_USERDB); 3729 $txt=""; 3730 if($data===true) 3731 $txt=$this->generatexml($format,'ok',100,''); 3732 else { 3733 if(is_numeric($projectID)) 3734 $txt=$this->generatexml($format,'failed',101,'no such project'); 3735 else 3736 $txt=$this->generatexml($format,'failed',102,'project id should be an integer'); 3737 } 3738 3739 echo($txt); 3740 } 3741 3742 /** 3743 * Get all the saved fields for some specified project 3744 * @param string $format 3745 * @param int $projectID 3746 * @return string xml/json 3747 */ 3748 private function buildservicepublishinggetfields($format,$projectID){ 3749 $user=$this->checkpassword(true); 3750 $this->checktrafficlimit($user); 3751 3752 $data=H01_BUILDSERVICE::publishinggetfields($projectID,$user,CONFIG_USERDB); 3753 $txt=""; 3754 if(!array_key_exists('code',$data)) 3755 $txt=$this->generatexml($format,'ok',100,'',$data,'field','','dynamic'); 3756 else { 3757 $txt=$this->generatexml($format,'failed',$data['code'],$data['message']); 3758 } 3759 3760 echo($txt); 3761 } 3762 } 3763 // Little hack to get kdevelop to pick up the functions... 3764 //include_once("../buildservice/lib_buildservice.php"); 3765 3766 ?>