File indexing completed on 2025-01-12 05:18:40
0001 <?php 0002 /* 0003 * on this file gfx inclusion is useless as gfx is already running 0004 */ 0005 0006 class V1Controller extends EController 0007 { 0008 public function readdata($key,$type='raw',$getpriority=false,$default='') { 0009 if($getpriority) { 0010 if(isset($_GET[$key])) { 0011 $data=$_GET[$key]; 0012 } elseif(isset($_POST[$key])) { 0013 $data=$_POST[$key]; 0014 } else { 0015 if($default=='') { 0016 if(($type=='int') or ($type=='float')) $data=0; else $data=''; 0017 } else { 0018 $data=$default; 0019 } 0020 } 0021 } else { 0022 if(isset($_POST[$key])) { 0023 $data=$_POST[$key]; 0024 } elseif(isset($_GET[$key])) { 0025 $data=$_GET[$key]; 0026 } elseif(isset($_COOKIE[$key])) { 0027 $data=$_COOKIE[$key]; 0028 } else { 0029 if($default=='') { 0030 if(($type=='int') or ($type=='float')) $data=0; else $data=''; 0031 } else { 0032 $data=$default; 0033 } 0034 } 0035 } 0036 0037 if($type=='raw') return($data); 0038 elseif($type=='text') return(addslashes(strip_tags($data))); 0039 elseif($type=='int') { $data = (int) $data; return($data); } 0040 elseif($type=='float') { $data = (float) $data; return($data); } 0041 elseif($type=='array') { $data = $data; return($data); } 0042 else { H01_UTIL::exception('readdata: internal error:'.$type); return(false); } 0043 } 0044 0045 public function handle() { 0046 /* 0047 // overwrite the 404 error page returncode 0048 header("HTTP/1.0 200 OK"); 0049 */ 0050 if($_SERVER['REQUEST_METHOD'] == 'GET') { 0051 $method='get'; 0052 }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { 0053 $method='put'; 0054 parse_str(file_get_contents("php://input"),$put_vars); 0055 }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { 0056 $method='post'; 0057 }else{ 0058 echo('internal server error: method not supported'); 0059 exit(); 0060 } 0061 0062 0063 // preprocess url 0064 $url= ERewriter::oldurl(); 0065 0066 //erasing get params 0067 $url = explode('?',$url)[0]; 0068 0069 if(substr($url,(strlen($url)-1))<>'/') $url.='/'; 0070 //$ex=str_replace('?', '/?', $url, $uno); 0071 $ex=explode('/',$url); 0072 0073 //var_dump($ex); 0074 0075 // eventhandler 0076 if(count($ex)==2){ 0077 H01_GUI::showtemplate('apidoc'); 0078 0079 0080 // CONFIG 0081 // apiconfig - GET - CONFIG 0082 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='config') and (count($ex)==4)){ 0083 $format=$this->readdata('format','text'); 0084 $this->config($format); 0085 0086 0087 // personsearch - GET - PERSON/DATA parameter als url parameter 0088 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0089 $format=$this->readdata('format','text'); 0090 $username=$this->readdata('name','text'); 0091 $country=$this->readdata('country','text'); 0092 $city=$this->readdata('city','text'); 0093 $description=$this->readdata('description','text'); 0094 $pc=$this->readdata('pc','text'); 0095 $software=$this->readdata('software','text'); 0096 $longitude=$this->readdata('longitude','float'); 0097 $latitude=$this->readdata('latitude','float'); 0098 $distance=$this->readdata('distance','float'); 0099 0100 $attributeapp=$this->readdata('attributeapp','text'); 0101 $attributekey=$this->readdata('attributekey','text'); 0102 $attributevalue=$this->readdata('attributevalue','text'); 0103 0104 $page=$this->readdata('page','int'); 0105 $pagesize=$this->readdata('pagesize','int'); 0106 if($pagesize<1 or $pagesize>100) $pagesize=10; 0107 $this->personsearch($format,$username,$country,$city,$description,$pc,$software,$longitude,$latitude,$distance,$attributeapp,$attributekey,$attributevalue,$page,$pagesize); 0108 0109 // personget - GET - PERSON/DATA/frank 0110 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0111 $format=$this->readdata('format','text'); 0112 $username=addslashes($ex[4]); 0113 $this->personget($format,$username); 0114 0115 // personaccountbalance - GET - PERSON/BALANCE 0116 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='balance') and (count($ex)==5)){ 0117 $format=$this->readdata('format','text'); 0118 $this->persongetbalance($format); 0119 0120 // personget - GET - PERSON/SELF 0121 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='self') and (count($ex)==5)){ 0122 $format=$this->readdata('format','text'); 0123 $this->personget($format); 0124 0125 // personedit - POST - PERSON/EDIT 0126 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='self') and (count($ex)==5)){ 0127 $format=$this->readdata('format','text'); 0128 $longitude=$this->readdata('longitude','float'); 0129 $latitude=$this->readdata('latitude','float'); 0130 $country=$this->readdata('country','text'); 0131 $city=$this->readdata('city','text'); 0132 $this->personedit($format,$longitude,$latitude,$country,$city); 0133 0134 // personcheck - POST - PERSON/CHECK 0135 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='check') and (count($ex)==5)){ 0136 $format=$this->readdata('format','text'); 0137 $login=$this->readdata('login','text'); 0138 $passwd=$this->readdata('password','text'); 0139 $this->personcheck($format,$login,$passwd); 0140 0141 // personadd - POST - PERSON/ADD 0142 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0143 $format=$this->readdata('format','text'); 0144 $login=$this->readdata('login','text'); 0145 $passwd=$this->readdata('password','text'); 0146 $firstname=$this->readdata('firstname','text'); 0147 $lastname=$this->readdata('lastname','text'); 0148 $email=$this->readdata('email','text'); 0149 $this->personadd($format,$login,$passwd,$firstname,$lastname,$email); 0150 0151 // persongetea - GET - PERSON/ATTRIBUTES/frank/parley/key 0152 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==8)){ 0153 $format=$this->readdata('format','text'); 0154 $username= addslashes($ex[4]); 0155 $app= addslashes($ex[5]); 0156 $key= addslashes($ex[6]); 0157 $this->personattributeget($format,$username,$app,$key); 0158 0159 // persongetea - GET - PERSON/ATTRIBUTES/frank/parley 0160 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==7)){ 0161 $format=$this->readdata('format','text'); 0162 $username= addslashes($ex[4]); 0163 $app= addslashes($ex[5]); 0164 $key= ''; 0165 $this->personattributeget($format,$username,$app,$key); 0166 0167 // persongetea - GET - PERSON/ATTRIBUTES/frank 0168 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='attributes') and (count($ex)==6)){ 0169 $format=$this->readdata('format','text'); 0170 $username= addslashes($ex[4]); 0171 $app= ''; 0172 $key= ''; 0173 $this->personattributeget($format,$username,$app,$key); 0174 0175 // persondeleteea - POST - PERSON/DELETEATTRIBUTE/app/key 0176 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='deleteattribute') and (count($ex)==7)){ 0177 $format=$this->readdata('format','text'); 0178 $app= addslashes($ex[4]); 0179 $key= addslashes($ex[5]); 0180 $this->personattributedelete($format,$app,$key); 0181 0182 // personsetea - POST - PERSON/SETATTRIBUTE/app/key 0183 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='person') and (strtolower($ex[3])=='setattribute') and (count($ex)==7)){ 0184 $format=$this->readdata('format','text'); 0185 $app= addslashes($ex[4]); 0186 $key= addslashes($ex[5]); 0187 $value=$this->readdata('value','text'); 0188 $this->personattributeset($format,$app,$key,$value); 0189 0190 0191 0192 // FAN 0193 //fanget - GET - FAN/DATA/"contentid" - page,pagesize als url parameter, 0194 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0195 $format=$this->readdata('format','text'); 0196 $content=addslashes($ex[4]); 0197 $page=$this->readdata('page','int'); 0198 $pagesize=$this->readdata('pagesize','int'); 0199 if($pagesize<1 or $pagesize>100) $pagesize=10; 0200 $this->fanget($format,$content,$page,$pagesize); 0201 0202 //isfan - GET - FAN/STATUS/"contentid" 0203 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='status') and (count($ex)==6)){ 0204 $format=$this->readdata('format','text'); 0205 $content=addslashes($ex[4]); 0206 $this->isfan($format,$content); 0207 0208 //addfan - POST - FAN/ADD/"contentid" 0209 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='add') and (count($ex)==6)){ 0210 $format=$this->readdata('format','text'); 0211 $content=addslashes($ex[4]); 0212 $this->addfan($format,$content); 0213 0214 //removefan - POST - FAN/REMOVE/"contentid" 0215 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='fan') and (strtolower($ex[3])=='remove') and (count($ex)==6)){ 0216 $format=$this->readdata('format','text'); 0217 $content=addslashes($ex[4]); 0218 $this->removefan($format,$content); 0219 0220 0221 0222 // FRIEND 0223 //friendget - GET - FRIEND/DATA/"personid" - page,pagesize als url parameter, 0224 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0225 $format=$this->readdata('format','text'); 0226 $username=addslashes($ex[4]); 0227 $page=$this->readdata('page','int'); 0228 $pagesize=$this->readdata('pagesize','int'); 0229 if($pagesize<1 or $pagesize>100) $pagesize=10; 0230 $this->friendget($format,$username,$page,$pagesize); 0231 0232 //friendinvite - POST - FRIEND/INVITE/"username"/ message als url parameter 0233 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='invite') and (count($ex)==6)){ 0234 $format=$this->readdata('format','text'); 0235 $username=addslashes($ex[4]); 0236 $message=$this->readdata('message','text'); 0237 $this->friendinvite($format,$username,$message); 0238 0239 //friendapprove - POST - FRIEND/APPROVE/"username"/ 0240 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='approve') and (count($ex)==6)){ 0241 $format=$this->readdata('format','text'); 0242 $username=addslashes($ex[4]); 0243 $this->friendapprove($format,$username); 0244 0245 //frienddecline - POST - FRIEND/DECLINE/"username"/ 0246 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='decline') and (count($ex)==6)){ 0247 $format=$this->readdata('format','text'); 0248 $username=addslashes($ex[4]); 0249 $this->frienddecline($format,$username); 0250 0251 //friendcancel - POST - FRIEND/CANCEL/"username"/ 0252 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='cancel') and (count($ex)==6)){ 0253 $format=$this->readdata('format','text'); 0254 $username=addslashes($ex[4]); 0255 $this->friendcancel($format,$username); 0256 0257 //friendcancelinvitation - POST - FRIEND/CANCEL/"username"/ 0258 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='cancelinvitation') and (count($ex)==6)){ 0259 $format=$this->readdata('format','text'); 0260 $username=addslashes($ex[4]); 0261 $this->friendcancelinvitation($format,$username); 0262 0263 //friendsentinvitations - GET - FRIEND/SENTINVITATIONS/ 0264 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='sentinvitations') and (count($ex)==5)){ 0265 $format=$this->readdata('format','text'); 0266 $page=$this->readdata('page','int'); 0267 $pagesize=$this->readdata('pagesize','int'); 0268 if($pagesize<1 or $pagesize>100) $pagesize=10; 0269 $this->friendsentinvitations($format,$page,$pagesize); 0270 0271 //friendreceivedinvitations - GET - FRIEND/RECEIVEDINVITATIONS/ 0272 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='friend') and (strtolower($ex[3])=='receivedinvitations') and (count($ex)==5)){ 0273 $format=$this->readdata('format','text'); 0274 $page=$this->readdata('page','int'); 0275 $pagesize=$this->readdata('pagesize','int'); 0276 if($pagesize<1 or $pagesize>100) $pagesize=10; 0277 $this->friendreceivedinvitations($format,$page,$pagesize); 0278 0279 0280 // MESSAGE 0281 //messagefolders - GET - MESSAGE/ 0282 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==4)){ 0283 $format=$this->readdata('format','text'); 0284 $this->messagefolders($format); 0285 0286 //messagelist - GET - MESSAGE/"folderid"/ page,pagesize als url parameter 0287 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==5)){ 0288 $format=$this->readdata('format','text'); 0289 $folder= (int) addslashes($ex[3]); 0290 $filter=$this->readdata('status','text'); 0291 $page=$this->readdata('page','int'); 0292 $pagesize=$this->readdata('pagesize','int'); 0293 if($pagesize<1 or $pagesize>100) $pagesize=10; 0294 $this->messagelist($format,$folder,$page,$pagesize,$filter); 0295 0296 // messagesend - POST - MESSAGE/"folderid" 0297 }elseif(($method=='post') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (strtolower($ex[3])=='2') and (count($ex)==5)){ 0298 $format=$this->readdata('format','text'); 0299 $touser=$this->readdata('to','text'); 0300 $subject=$this->readdata('subject','text'); 0301 $message=$this->readdata('message','text'); 0302 $this->messagesend($format,$touser,$subject,$message); 0303 0304 // messageget - GET - MESSAGE/"folderid"/"messageid" 0305 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='message') and (count($ex)==6)){ 0306 $format=$this->readdata('format','text'); 0307 $folder= (int) addslashes($ex[3]); 0308 $message= (int) addslashes($ex[4]); 0309 $this->messageget($format,$folder,$message); 0310 0311 0312 // ACTIVITY 0313 // activityget - GET ACTIVITY page,pagesize als urlparameter 0314 }elseif(($method=='get') and (strtolower($ex[1])=='v1')and (strtolower($ex[2])=='activity') and (count($ex)==4)){ 0315 $format=$this->readdata('format','text'); 0316 $page=$this->readdata('page','int'); 0317 $pagesize=$this->readdata('pagesize','int'); 0318 if($pagesize<1 or $pagesize>100) $pagesize=10; 0319 $this->activityget($format,$page,$pagesize); 0320 0321 // activityput - POST ACTIVITY 0322 }elseif(($method=='post') and (strtolower($ex[1])=='v1')and (strtolower($ex[2])=='activity') and (count($ex)==4)){ 0323 $format=$this->readdata('format','text'); 0324 $message=$this->readdata('message','text'); 0325 $this->activityput($format,$message); 0326 0327 0328 // CONTENT 0329 // contentcategories - GET - CONTENT/CATEGORIES 0330 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='categories') and (count($ex)==5)){ 0331 $format=$this->readdata('format','text'); 0332 $this->contentcategories($format); 0333 0334 // contentlicense - GET - CONTENT/LICENSES 0335 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='licenses') and (count($ex)==5)){ 0336 $format=$this->readdata('format','text'); 0337 $this->contentlicenses($format); 0338 0339 // contentdistributions - GET - CONTENT/DISTRIBUTIONS 0340 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='distributions') and (count($ex)==5)){ 0341 $format=$this->readdata('format','text'); 0342 $this->contentdistributions($format); 0343 0344 // contentdependencies - GET - CONTENT/DISTRIBUTIONS 0345 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='dependencies') and (count($ex)==5)){ 0346 $format=$this->readdata('format','text'); 0347 $this->contentdependencies($format); 0348 0349 // contenthomepage - GET - CONTENT/HOMPAGES 0350 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='homepages') and (count($ex)==5)){ 0351 $format=$this->readdata('format','text'); 0352 $this->contenthomepages($format); 0353 0354 0355 // contentlist - GET - CONTENT/DATA - category,search,sort,page,pagesize 0356 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0357 $format=$this->readdata('format','text'); 0358 $contents=$this->readdata('categories','text'); 0359 $searchstr=$this->readdata('search','text'); 0360 $searchuser=$this->readdata('user','text'); 0361 $external=$this->readdata('external','text'); 0362 $distribution=$this->readdata('distribution','text'); 0363 $license=$this->readdata('license','text'); 0364 $sortmode=$this->readdata('sortmode','text'); 0365 $page=$this->readdata('page','int'); 0366 $pagesize=$this->readdata('pagesize','int'); 0367 if($pagesize<1 or $pagesize>100) $pagesize=10; 0368 $this->contentlist($format,$contents,$searchstr,$searchuser,$external,$distribution,$license,$sortmode,$page,$pagesize); 0369 0370 // contentget - GET - CONTENT/DATA/"id" 0371 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0372 $format=$this->readdata('format','text'); 0373 $id= addslashes($ex[4]); 0374 $this->contentget($format,$id); 0375 0376 // contentdownload - GET - CONTENT/DOWNLOAD/"id"/"item" 0377 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='download') and (count($ex)==7)){ 0378 $format=$this->readdata('format','text'); 0379 $id= addslashes($ex[4]); 0380 $item= addslashes($ex[5]); 0381 $this->contentdownload($format,$id,$item); 0382 0383 // getrecommendations - GET - CONTENT/RECOMMENDATIONS/"id" 0384 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='recommendations') and (count($ex)==6)){ 0385 $format=$this->readdata('format','text'); 0386 $id= addslashes($ex[4]); 0387 $page=$this->readdata('page','int'); 0388 $pagesize=$this->readdata('pagesize','int'); 0389 $this->contentrecommendations($id,$format,$page,$pagesize); 0390 0391 0392 // contentvote - POST - CONTENT/VOTE/"id" - good/bad als url parameter 0393 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='vote') and (count($ex)==6)){ 0394 $format=$this->readdata('format','text'); 0395 $id= addslashes($ex[4]); 0396 $vote=$this->readdata('vote','text'); 0397 $this->contentvote($format,$id,$vote); 0398 0399 // contentpreviewdelete - POST - CONTENT/DELETEPREVIEW/"contentid"/"previewid" 0400 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='deletepreview') and (count($ex)==7)){ 0401 $format=$this->readdata('format','text'); 0402 $contentid= addslashes($ex[4]); 0403 $previewid= addslashes($ex[5]); 0404 $this->contentpreviewdelete($format,$contentid,$previewid); 0405 0406 // contentpreviewupload - POST - CONTENT/UPLOADPREVIEW/"contentid"/"previewid" 0407 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='uploadpreview') and (count($ex)==7)){ 0408 $format=$this->readdata('format','text'); 0409 $contentid= addslashes($ex[4]); 0410 $previewid= addslashes($ex[5]); 0411 $this->contentpreviewupload($format,$contentid,$previewid); 0412 0413 // contentdownloaddelete - POST - CONTENT/DELETEDOWNLOAD/"contentid" 0414 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='deletedownload') and (count($ex)==6)){ 0415 $format=$this->readdata('format','text'); 0416 $contentid= addslashes($ex[4]); 0417 $this->contentdownloaddelete($format,$contentid); 0418 0419 // contentdownloadupload - POST - CONTENT/UPLOADDOWNLOAD/"contentid" 0420 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='uploaddownload') and (count($ex)==6)){ 0421 $format=$this->readdata('format','text'); 0422 $contentid= addslashes($ex[4]); 0423 $this->contentdownloadupload($format,$contentid); 0424 0425 // contentadd - POST - CONTENT/ADD 0426 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0427 $format=$this->readdata('format','text'); 0428 $this->contentadd($format); 0429 0430 // contentedit - POST - CONTENT/EDIT/"contentid" 0431 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='edit') and (count($ex)==6)){ 0432 $format=$this->readdata('format','text'); 0433 $contentid = addslashes($ex[4]); 0434 $this->contentedit($format,$contentid); 0435 0436 // contentdelete - POST - CONTENT/DELETE/"contentid" 0437 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='content') and (strtolower($ex[3])=='delete') and (count($ex)==6)){ 0438 $format=$this->readdata('format','text'); 0439 $contentid= addslashes($ex[4]); 0440 $this->contentdelete($format,$contentid); 0441 0442 0443 0444 // KNOWLEDGEBASE 0445 0446 // knowledgebaseget - GET - KNOWLEDGEBASE/DATA/"id" 0447 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='knowledgebase') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0448 $format=$this->readdata('format','text'); 0449 $id= addslashes($ex[4]); 0450 $this->knowledgebaseget($format,$id); 0451 0452 // knowledgebaselist - GET - KNOWLEDGEBASE/DATA - category,search,sort,page,pagesize 0453 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='knowledgebase') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0454 $format=$this->readdata('format','text'); 0455 $contents=$this->readdata('content','text'); 0456 $searchstr=$this->readdata('search','text'); 0457 $sortmode=$this->readdata('sortmode','text'); 0458 $page=$this->readdata('page','int'); 0459 $pagesize=$this->readdata('pagesize','int'); 0460 if($pagesize<1 or $pagesize>100) $pagesize=10; 0461 $this->knowledgebaselist($format,$contents,$searchstr,$sortmode,$page,$pagesize); 0462 0463 0464 // EVENT 0465 0466 // eventget - GET - EVENT/DATA/"id" 0467 }elseif(($method=='get') and (strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='data') and (count($ex)==6)){ 0468 $format=$this->readdata('format','text'); 0469 $id= addslashes($ex[4]); 0470 $this->eventget($format,$id); 0471 0472 // eventlist - GET - EVENT/DATA - type,country,startat,search,sort,page,pagesize 0473 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='data') and (count($ex)==5)){ 0474 $format=$this->readdata('format','text'); 0475 $type=$this->readdata('type','int'); 0476 $country=$this->readdata('country','text'); 0477 $startat=$this->readdata('startat','text'); 0478 $searchstr=$this->readdata('search','text'); 0479 $sortmode=$this->readdata('sortmode','text'); 0480 $page=$this->readdata('page','int'); 0481 $pagesize=$this->readdata('pagesize','int'); 0482 if($pagesize<1 or $pagesize>100) $pagesize=10; 0483 $this->eventlist($format,$type,$country,$startat,$searchstr,$sortmode,$page,$pagesize); 0484 0485 0486 // eventadd - POST - EVENT/ADD 0487 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0488 $format=$this->readdata('format','text'); 0489 $this->eventadd($format); 0490 0491 // eventedit - POST - EVENT/EDIT/"eventid" 0492 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='edit') and (count($ex)==6)){ 0493 $format=$this->readdata('format','text'); 0494 $eventid= addslashes($ex[4]); 0495 $this->eventedit($format,$eventid); 0496 0497 // eventdelete - POST - EVENT/DELETE/"eventid" 0498 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='event') and (strtolower($ex[3])=='delete') and (count($ex)==6)){ 0499 $format=$this->readdata('format','text'); 0500 $eventid= addslashes($ex[4]); 0501 $this->eventdelete($format,$eventid); 0502 0503 0504 // COMMENTS 0505 0506 // commentsget - GET - COMMENTS/GET 0507 }elseif((($method=='get') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='data') and (count($ex)==8)){ 0508 $type= addslashes($ex[4]); 0509 $content= addslashes($ex[5]); 0510 $content2= addslashes($ex[6]); 0511 $format=$this->readdata('format','text'); 0512 $page=$this->readdata('page','int'); 0513 $pagesize=$this->readdata('pagesize','int'); 0514 if($pagesize<1 or $pagesize>2000) $pagesize=10; 0515 $this->commentsget($format,$type,$content,$content2,$page,$pagesize); 0516 0517 // commentsadd - POST - COMMENTS/ADD 0518 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='add') and (count($ex)==5)){ 0519 $format=$this->readdata('format','text'); 0520 $type=$this->readdata('type','int'); 0521 $content=$this->readdata('content','int'); 0522 $content2=$this->readdata('content2','int'); 0523 $parent=$this->readdata('parent','int'); 0524 $subject=$this->readdata('subject','text'); 0525 $message=$this->readdata('message','text'); 0526 $this->commentsadd($format,$type,$content,$content2,$parent,$subject,$message); 0527 0528 // commentvote - GET - COMMENTS/vote 0529 }elseif((($method=='post') and strtolower($ex[1])=='v1') and (strtolower($ex[2])=='comments') and (strtolower($ex[3])=='vote') and (count($ex)==6)){ 0530 $id = addslashes($ex[4]); 0531 $score = $this->readdata('vote','int'); 0532 $format=$this->readdata('format','text'); 0533 $this->commentvote($format,$id,$score); 0534 0535 0536 // FORUM 0537 0538 }elseif(strtolower($ex[1])=='v1' and strtolower($ex[2])=='forum'){ 0539 $functioncall=strtolower($ex[3]); 0540 $subcall=strtolower($ex[4]); 0541 $argumentcount=count($ex); 0542 // list - GET - FORUM/LIST 0543 if($method=='get' and $functioncall=='list' and $argumentcount==4){ 0544 $format=$this->readdata('format','text'); 0545 $page=$this->readdata('page','int'); 0546 $pagesize=$this->readdata('pagesize','int'); 0547 // TOPIC section 0548 }elseif($functioncall=='topic'){ 0549 // list - GET - FORUM/TOPIC/LIST 0550 if($method=='get' and $subcall=='list' and $argumentcount==10){ 0551 $format=$this->readdata('format','text'); 0552 $forum=$this->readdata('forum','int'); 0553 $search=$this->readdata('search','text'); 0554 $description=$this->readdata('description','text'); 0555 $sortmode=$this->readdata('sortmode','text'); 0556 $page=$this->readdata('page','int'); 0557 $pagesize=$this->readdata('pagesize','int'); 0558 // add - POST - FORUM/TOPIC/ADD 0559 }elseif($method=='post' and $subcall=='add' and $argumentcount==5){ 0560 $format=$this->readdata('format','text'); 0561 $subject=$this->readdata('subject','text'); 0562 $content=$this->readdata('content','text'); 0563 $forum=$this->readdata('forum','int'); 0564 } 0565 } 0566 0567 // BUILDSERVICE 0568 0569 0570 }elseif(strtolower($ex[1])=='v1' and strtolower($ex[2])=='buildservice' and count($ex)>4){ 0571 $functioncall=strtolower($ex[4]); 0572 $argumentcount=count($ex); 0573 // PROJECT section 0574 if(strtolower($ex[3]=='project')){ 0575 // create - POST - PROJECT/CREATE 0576 if($method=='post' and $functioncall=='create' and $argumentcount==6){ 0577 $format=$this->readdata('format','text'); 0578 $name=$this->readdata('name','text'); 0579 $version=$this->readdata('version','text'); 0580 $license=$this->readdata('license','text'); 0581 $url=$this->readdata('url','text'); 0582 $developers=$this->readdata('developers','text'); 0583 $summary=$this->readdata('summary','text'); 0584 $description=$this->readdata('description','text'); 0585 $requirements=$this->readdata('requirements','text'); 0586 $specfile=$this->readdata('specfile','text'); 0587 0588 $this->buildserviceprojectcreate($format,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 0589 // get - GET - PROJECT/GET/"project" 0590 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0591 $format=$this->readdata('format','text'); 0592 $projectID=$ex[5]; 0593 0594 $this->buildserviceprojectget($format,$projectID); 0595 // delete - POST - PROJECT/DELETE/"project" 0596 }elseif($method=='post' and $functioncall=='delete' and $argumentcount==7){ 0597 $format=$this->readdata('format','text'); 0598 $projectID=$ex[5]; 0599 0600 $this->buildserviceprojectdelete($format,$projectID); 0601 // edit - POST - ROJECT/EDIT/"project" 0602 }elseif($method=='post' and $functioncall=='edit' and $argumentcount==7){ 0603 $format=$this->readdata('format','text'); 0604 $projectID=$ex[5]; 0605 $name=$this->readdata('name','text'); 0606 $version=$this->readdata('version','text'); 0607 $license=$this->readdata('license','text'); 0608 $url=$this->readdata('url','text'); 0609 $developers=$this->readdata('developers','text'); 0610 $summary=$this->readdata('summary','text'); 0611 $description=$this->readdata('description','text'); 0612 $requirements=$this->readdata('requirements','text'); 0613 $specfile=$this->readdata('specfile','text'); 0614 $this->buildserviceprojectedit($format,$projectID,$name,$version,$license,$url,$developers,$summary,$description,$requirements,$specfile); 0615 // listall - GET - PROJECT/LIST 0616 }elseif($method=='get' and $functioncall=='list' and $argumentcount==6){ 0617 $format=$this->readdata('format','text'); 0618 $page=$this->readdata('page','int'); 0619 $pagesize=$this->readdata('pagesize','int'); 0620 $this->buildserviceprojectlist($format,$page,$pagesize); 0621 // generatespecfile - GET - PROJECT/UPLOADSOURCE 0622 }elseif($method=='post' and $functioncall=='uploadsource' and $argumentcount==7){ 0623 $format=$this->readdata('format','text'); 0624 $projectID=$ex[5]; 0625 $this->buildserviceprojectuploadsource($format,$projectID); 0626 }else{ 0627 $this->reportapisyntaxerror('buildservice/project'); 0628 } 0629 // REMOTEACCOUNTS section 0630 }elseif(strtolower($ex[3])=='remoteaccounts'){ 0631 if($method=='get' and $functioncall=='list' and $argumentcount==6){ 0632 $format=$this->readdata('format','text'); 0633 $page=$this->readdata('page','int'); 0634 $pagesize=$this->readdata('pagesize','int'); 0635 $this->buildserviceremoteaccountslist($format,$page,$pagesize); 0636 }elseif($method=='post' and $functioncall=='add' and $argumentcount==6){ 0637 $format=$this->readdata('format','text'); 0638 $type=$this->readdata('type','int'); 0639 $typeid=$this->readdata('typeid','text'); 0640 $data=$this->readdata('data','text'); 0641 $login=$this->readdata('login','text'); 0642 $password=$this->readdata('password','text'); 0643 $this->buildserviceremoteaccountsadd($format,$type,$typeid,$data,$login,$password); 0644 }elseif($method=='post' and $functioncall=='edit' and $argumentcount==7){ 0645 $format=$this->readdata('format','text'); 0646 $id=$ex[5]; 0647 $data=$this->readdata('data','text'); 0648 $login=$this->readdata('login','text'); 0649 $password=$this->readdata('password','text'); 0650 $this->buildserviceremoteaccountsedit($format,$id,$login,$password,$data); 0651 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0652 $format=$this->readdata('format','text'); 0653 $id=$ex[5]; 0654 $this->buildserviceremoteaccountsget($format,$id); 0655 }elseif($method=='post' and $functioncall=='remove' and $argumentcount==7){ 0656 $format=$this->readdata('format','text'); 0657 $id=$ex[5]; 0658 $this->buildserviceremoteaccountsremove($format,$id); 0659 }else{ 0660 $this->reportapisyntaxerror('buildservice/remoteaccounts'); 0661 } 0662 // BUILDSERVICES section 0663 }elseif(strtolower($ex[3]=='buildservices')){ 0664 if($method=='get' and $functioncall=='list' and $argumentcount==6){ 0665 $format=$this->readdata('format','text'); 0666 $page=$this->readdata('page','int'); 0667 $pagesize=$this->readdata('pagesize','int'); 0668 $this->buildservicebuildserviceslist($format,$page,$pagesize); 0669 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0670 $format=$this->readdata('format','text'); 0671 $buildserviceID=$ex[5]; 0672 $this->buildservicebuildservicesget($format,$buildserviceID); 0673 }else{ 0674 $this->reportapisyntaxerror('buildservice/buildservices'); 0675 } 0676 // JOBS section 0677 }elseif(strtolower($ex[3]=='jobs')){ 0678 // getbuildcapabilities - GET - JOBS/GETBUILDCAPABILITIES 0679 if($method=='get' and $functioncall=='list' and $argumentcount==7){ 0680 $format=$this->readdata('format','text'); 0681 $projectID=$ex[5]; 0682 $page=$this->readdata('page','int'); 0683 $pagesize=$this->readdata('pagesize','int'); 0684 $this->buildservicejobslist($format,$projectID,$page,$pagesize); 0685 // create - POST - JOBS/CREATE/"project"/"buildsevice"/"target" 0686 }elseif($method=='post' and $functioncall=='create' and $argumentcount==9){ 0687 $format=$this->readdata('format','text'); 0688 $projectID=$ex[5]; 0689 $buildserviceID=$ex[6]; 0690 $target=$ex[7]; 0691 $this->buildservicejobscreate($format,$projectID,$buildserviceID,$target); 0692 // cancel - POST - JOBS/CANCEL/"buildjob" 0693 }elseif($method=='post' and $functioncall=='cancel' and $argumentcount==7){ 0694 $format=$this->readdata('format','text'); 0695 $buildjobID=$ex[5]; 0696 $this->buildservicejobscancel($format,$buildjobID); 0697 // get - GET - JOBS/GET/"buildjob" 0698 }elseif($method=='get' and $functioncall=='get' and $argumentcount==7){ 0699 $format=$this->readdata('format','text'); 0700 $buildjobID=$ex[5]; 0701 $this->buildservicejobsget($format,$buildjobID); 0702 // getoutput - GET - JOBS/GETOUTPOT/"buildjob" 0703 }elseif($method=='get' and $functioncall=='getoutput' and $argumentcount==7){ 0704 $format=$this->readdata('format','text'); 0705 $buildjobID=$ex[5]; 0706 $this->buildservicejobsgetoutput($format,$buildjobID); 0707 }else{ 0708 $this->reportapisyntaxerror('buildservice/jobs'); 0709 } 0710 // PUBLISHING section 0711 }elseif(strtolower($ex[3]=='publishing')){ 0712 // getpublishingcapabilities - GET - PUBLISHING/GETPUBLISHINGCAPABILITIES 0713 if($method=='get' and $functioncall=='getpublishingcapabilities' and $argumentcount==6){ 0714 $format=$this->readdata('format','text'); 0715 $page=$this->readdata('page','int'); 0716 $pagesize=$this->readdata('pagesize','int'); 0717 $this->buildservicepublishinggetpublishingcapabilities($format,$page,$pagesize); 0718 // getpublisher - GET - PUBLISHING/GETPUBLISHER 0719 }elseif($method=='get' and $functioncall=='getpublisher' and $argumentcount==7){ 0720 $format=$this->readdata('format','text'); 0721 $publisherID=$ex[5]; 0722 $this->buildservicepublishinggetpublisher($format,$publisherID); 0723 // publishtargetresult - POST - PUBLISHING/PUBLISHTARGETRESULT/"buildjob"/"publisher" 0724 }elseif($method=='post' and $functioncall=='publishtargetresult' and $argumentcount==8){ 0725 $format=$this->readdata('format','text'); 0726 $buildjobID=$ex[5]; 0727 $publisherID=$ex[6]; 0728 $this->buildservicepublishingpublishtargetresult($format,$buildjobID,$publisherID); 0729 // savefields - POST - PUBLISHING/SAVEFIELDS/"project" 0730 }elseif($method=='post' and $functioncall=='savefields' and $argumentcount==7){ 0731 $format=$this->readdata('format','text'); 0732 $projectID=$ex[5]; 0733 $fields=$this->readdata('fields','array'); 0734 $this->buildservicepublishingsavefields($format,$projectID,$fields); 0735 // getfields - GET - PUBLISHING/GETFIELDS/"project" 0736 }elseif($method=='get' and $functioncall=='getfields' and $argumentcount==7){ 0737 $format=$this->readdata('format','text'); 0738 $projectID=$ex[5]; 0739 $this->buildservicepublishinggetfields($format,$projectID); 0740 }else{ 0741 $this->reportapisyntaxerror('buildservice/publishing'); 0742 } 0743 }else{ 0744 $this->reportapisyntaxerror('buildservice'); 0745 } 0746 0747 0748 }else{ 0749 $format=$this->readdata('format','text'); 0750 $txt='please check the syntax. api specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services'."\n"; 0751 $txt.=$this->getdebugoutput(); 0752 echo(OCSXML::generatexml($format,'failed',999,$txt)); 0753 } 0754 exit(); 0755 } 0756 0757 private function _checkpassword($forceuser=true) { 0758 //valid user account ? 0759 if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser=''; 0760 if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw=''; 0761 0762 //this small (and dirty) hack checks if the client who requested the page is konqueror 0763 //which is also Qt itself 0764 //TODO: maybe fix this thing? 0765 if(isset($_SERVER['HTTP_USER_AGENT'])){ 0766 $iskonqueror = stristr($_SERVER['HTTP_USER_AGENT'],"Konqueror"); 0767 } else { 0768 $iskonqueror = false; 0769 } 0770 0771 if(empty($authuser)) { 0772 if($forceuser){ 0773 if(!$iskonqueror){ 0774 header("WWW-Authenticate: Basic realm=\"Private Area\""); 0775 header('HTTP/1.0 401 Unauthorized'); 0776 exit; 0777 } else { 0778 $txt=OCSXML::generatexml('','failed',999,'needs authentication'); 0779 echo($txt); 0780 exit; 0781 } 0782 }else{ 0783 $identifieduser=''; 0784 } 0785 }else{ 0786 /* 0787 $user=H01_USER::finduserbyapikey($authuser,CONFIG_USERDB); 0788 if($user==false) { 0789 */ 0790 $user=OCSUser::server_checklogin($authuser,$authpw); 0791 if($user==false) { 0792 if($forceuser){ 0793 if(!$iskonqueror){ 0794 header("WWW-Authenticate: Basic realm=\"Private Area\""); 0795 header('HTTP/1.0 401 Unauthorized'); 0796 exit; 0797 } else { 0798 $txt=OCSXML::generatexml('','failed',999,'needs authentication'); 0799 echo($txt); 0800 exit; 0801 } 0802 }else{ 0803 $identifieduser=''; 0804 } 0805 }else{ 0806 $identifieduser=$user; 0807 } 0808 /* 0809 }else{ 0810 $identifieduser=$user; 0811 }*/ 0812 } 0813 return $identifieduser; 0814 } 0815 0816 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// 0817 ///////// OTHER COMPONENTS /////////// 0818 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// 0819 0820 public function index() 0821 { 0822 $v1_config_url = EPageProperties::get_current_website_url()."/v1/config"; 0823 0824 echo "Hello! This webserver runs an Open Collaboration Services server.<br>"; 0825 echo "Check <a href=\"$v1_config_url\">$v1_config_url</a> for configuring your OCS client."; 0826 } 0827 0828 public function config() 0829 { 0830 $xml['version']=EConfig::$data["ocsserver"]["version"]; 0831 $xml['website']=EConfig::$data["ocsserver"]["website"]; 0832 $xml['host']=EConfig::$data["ocsserver"]["host"]; 0833 $xml['contact']=EConfig::$data["ocsserver"]["contact"]; 0834 if(EConfig::$data["ocsserver"]["ssl"]=='yes'){ $xml['ssl']='true'; } else { $xml['ssl']='false'; } 0835 echo(OCSXML::generatexml('xml','ok',100,'',$xml,'config','',1)); 0836 } 0837 0838 private function getdebugoutput() { 0839 $txt=''; 0840 $txt.="debug output:\n"; 0841 if(isset($_SERVER['REQUEST_METHOD'])) $txt.='http request method: '.$_SERVER['REQUEST_METHOD']."\n"; 0842 if(isset($_SERVER['REQUEST_URI'])) $txt.='http request uri: '.$_SERVER['REQUEST_URI']."\n"; 0843 if(isset($_GET)) foreach($_GET as $key=>$value) $txt.='get parameter: '.$key.'->'.$value."\n"; 0844 if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n"; 0845 return($txt); 0846 } 0847 0848 public function personcheck($format, $login, $password){ 0849 //$user=$this->_checkpassword(false); 0850 ////$this->checktrafficlimit($user); 0851 //OCSUser::server_load(); 0852 0853 if($login<>''){ 0854 $reallogin=OCSUser::server_checklogin($login,$password); // $login,CONFIG_USERDB,$passwd,PERM_Login 0855 if($reallogin<>false){ 0856 $xml['person']['personid']=$reallogin; 0857 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'ok',100,'',$xml,'person','check',2)); 0858 }else{ 0859 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',102,'login not valid')); 0860 } 0861 }else{ 0862 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',101,'please specify all mandatory fields')); 0863 } 0864 } 0865 0866 public function personadd($format,$login,$passwd,$firstname,$lastname,$email) 0867 { 0868 if($login<>'' and $passwd<>'' and $firstname<>'' and $lastname<>'' and $email<>''){ 0869 if(OCSUser::isvalidpassword($passwd)){ 0870 if(OCSUser::isloginname($login)){ 0871 if(!OCSUser::server_exists($login)){ 0872 if(OCSUser::server_countusersbyemail($email)==0) { 0873 if(OCSUser::isvalidemail($email)) { 0874 OCSUser::server_register($login,$passwd,$firstname,$lastname,$email); 0875 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'ok',100,'')); 0876 }else{ 0877 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',106,'email already taken')); 0878 } 0879 }else{ 0880 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',105,'email invalid')); 0881 } 0882 }else{ 0883 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',104,'login already exists')); 0884 } 0885 }else{ 0886 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',103,'please specify a valid login')); 0887 } 0888 }else{ 0889 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',102,'please specify a valid password')); 0890 } 0891 }else{ 0892 echo(OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',101,'please specify all mandatory fields')); 0893 } 0894 } 0895 0896 public function personget($format,$username="") 0897 { 0898 if(empty($username)){ 0899 $user=$this->_checkpassword(); 0900 0901 $username=$user; 0902 0903 $DBuser = OCSUser::server_get_user_info($username); 0904 0905 if($DBuser==false){ 0906 $txt=OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'failed',101,'person not found'); 0907 echo($txt); 0908 }else{ 0909 if(isset($DBuser[0]) and is_array($DBuser[0])){ 0910 $DBuser = $DBuser[0]; 0911 } 0912 $xml=array(); 0913 $xml[0]['personid']=$DBuser['login']; 0914 $xml[0]['firstname']=$DBuser['firstname']; 0915 $xml[0]['lastname']=$DBuser['lastname']; 0916 $xml[0]['email']=$DBuser['email']; 0917 0918 //ELog::pd($xml); 0919 //$xml[0]['description']=H01_UTIL::bbcode2html($DBuser['description']); 0920 0921 $txt=OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'ok',100,'',$xml,'person','full',2); 0922 //$txt=OCSXML::generatexml($format,'failed',102,'data is private'); 0923 echo($txt); 0924 } 0925 } else { 0926 $this->personsearch($format, $username, '','','','','','','','','','','','',''); 0927 } 0928 } 0929 0930 public function personsearch($format,$username,$country,$city,$description,$pc,$software,$longitude,$latitude,$distance,$attributeapp,$attributekey,$attributevalue,$page,$pagesize) 0931 { 0932 $pl = new OCSPersonLister; 0933 $xml = $pl->ocs_person_search($username,$page,$pagesize); 0934 0935 for($i=0;$i<count($xml);$i++){ 0936 $xml[$i]['personid'] = $xml[$i]['login']; 0937 //unset($xml[$i]['login']); 0938 } 0939 0940 $plcount = count($xml); 0941 0942 $txt=OCSXML::generatexml(EConfig::$data["ocsserver"]["format"],'ok',100,'',$xml,'person','summary',2,$plcount,$pagesize); 0943 0944 echo($txt); 0945 } 0946 0947 ////////////////////////////////////// CONTENT API ///////////////////////////////////////// 0948 /** 0949 * get a specific content 0950 * @param string $format 0951 * @param string $content 0952 * @return string xml/json 0953 */ 0954 public function contentget($format,$content) { 0955 0956 $user=$this->_checkpassword(false); 0957 //$this->checktrafficlimit($user); 0958 0959 $content=addslashes($content); 0960 0961 // fetch data 0962 $con = new OCSContent(); 0963 0964 // check data 0965 if (!$con->load($content)) { 0966 $txt=OCSXML::generatexml($format,'failed',101,'content not found'); 0967 } else { 0968 $xml['id']=$con->id; 0969 $xml['name']=$con->name; 0970 $xml['version']=$con->version; 0971 $xml['typeid']=$con->type; 0972 //$xml['typename']=$WEBSITECONTENT[$con['type']]; 0973 //$xml['language']=H01_CONTENT::$LANGUAGES[$con['language']]; 0974 $xml['personid']=$con->owner; 0975 //$xml['profilepage']='http://opendesktop.org/usermanager/search.php?username='.urlencode($con['user']); 0976 //$xml['created']=date('c',$con['created']); 0977 //$xml['changed']=date('c',$con['changed']); 0978 //$xml['downloads']=$con['downloads']; 0979 $xml['score'] = $con->score; 0980 $xml['description'] = $con->description; 0981 $xml['summary'] = $con->summary; 0982 //$xml['feedbackurl'] = $con['feedbackurl']; 0983 $xml['changelog'] = $con->changelog; 0984 $xml['license'] = $con->license; 0985 $xml['personid'] = $con->personid; 0986 $xml['preview1'] = $con->preview1; 0987 $xml['preview2'] = $con->preview2; 0988 $xml['preview3'] = $con->preview3; 0989 0990 // download 0991 if (!empty($con->downloadname1) or !empty($con->downloadlink1)) { 0992 $xml['downloadname1'] = $con->downloadname1; 0993 $xml['downloadlink1'] = $con->downloadlink1; 0994 } else { 0995 $xml['downloadname1']=''; 0996 $xml['downloadlink1']=''; 0997 } 0998 0999 $xml2[0]=$xml; 1000 $txt=OCSXML::generatexml($format,'ok',100,'',$xml2,'content','full',2); 1001 echo($txt); 1002 1003 } 1004 } 1005 1006 public function contentdownload($format,$content,$item) { 1007 $user=$this->_checkpassword(false); 1008 //$this->checktrafficlimit($user); 1009 1010 $content = (int) $content; 1011 $item = (int) $item; 1012 1013 // item range 1014 if($item<1 or $item>12) { 1015 $txt=OCSXML::generatexml($format,'failed',103,'item not found'); 1016 } else { 1017 1018 // fetch data 1019 $con = new OCSContent(); 1020 1021 // check data 1022 if (!$con->load($content)) { 1023 $txt=OCSXML::generatexml($format,'failed',101,'content not found'); 1024 } else { 1025 //download link 1026 $link = $con->downloadlink1; 1027 //if url is nonexistent or broken we just set mimetype to unknown 1028 //mimetype 1029 if(file_exists($link)){ 1030 $headers = get_headers($link); 1031 $mimetype = $headers[3]; 1032 } else { 1033 $mimetype = "application/unknown"; 1034 } 1035 1036 if (!empty($con->downloadname1) or !empty($con->downloadlink1)) { 1037 $xml['downloadlink']=$link; 1038 $xml['mimetype']=$mimetype; 1039 $xml2[0]=$xml; 1040 $txt=OCSXML::generatexml($format,'ok',100,'',$xml2,'content','download',2); 1041 } else { 1042 $txt=OCSXML::generatexml($format,'failed',103,'content item not found'); 1043 } 1044 } 1045 1046 if(isset($txt) and $txt<>'') { 1047 echo($txt); 1048 } 1049 } 1050 } 1051 1052 /** 1053 * get a list of contents 1054 * @param string $format 1055 * @param string $contents 1056 * @param string $searchstr 1057 * @param string $searchuser 1058 * @param string $sortmode 1059 * @param string $page 1060 * @param string $pagesize 1061 * @return string xml/json 1062 */ 1063 public function contentlist($format,$contents,$searchstr,$searchuser,$external,$distribution,$license,$sortmode,$page,$pagesize) { 1064 $user=$this->_checkpassword(false); 1065 //$this->checktrafficlimit($user); 1066 1067 $conl = new OCSContentLister("ocs_content"); 1068 $xml = $conl->ocs_content_list($searchstr,$sortmode,$page,$pagesize,$searchuser,$contents); 1069 $totalitems = $conl->get_totalitems(); 1070 /* 1071 * test page: http://localhost/v1/content/data?search=lolol 1072 */ 1073 1074 if(empty($xml)){ 1075 $txt=OCSXML::generatexml($format,'ok',100,''); 1076 } else { 1077 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'content','summary',2,$totalitems,$pagesize); 1078 } 1079 1080 echo($txt); 1081 } 1082 1083 /** 1084 * get a list of contents categories 1085 * @param string $format 1086 * @return string xml/json 1087 */ 1088 public function contentcategories($format) { 1089 $user=$this->_checkpassword(false); 1090 //$this->checktrafficlimit($user); 1091 1092 $i=0; 1093 foreach(EConfig::$data["ocs_categories"] as $key=>$value) { 1094 $i++; 1095 $xml[$i]['id']=$key; 1096 $xml[$i]['name']=$value; 1097 } 1098 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'category','',2,count(EConfig::$data["ocs_categories"])); 1099 1100 echo($txt); 1101 } 1102 1103 /** 1104 * get a list of contents licenses 1105 * @param string $format 1106 * @return string xml/json 1107 */ 1108 private function contentlicenses($format) { 1109 $contentlicense = EConfig::$data["licenses"]; 1110 $contentlicenselink = EConfig::$data["licenseslink"]; 1111 1112 $user=$this->_checkpassword(false); 1113 //$this->checktrafficlimit($user); 1114 1115 $i=0; 1116 foreach($contentlicense as $key=>$value) { 1117 $i++; 1118 $xml[$i]['id']=$key; 1119 $xml[$i]['name']=$value; 1120 $xml[$i]['link']=$contentlicenselink[$key]; 1121 } 1122 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'license','',2,count($contentlicense)); 1123 1124 echo($txt); 1125 } 1126 1127 /** 1128 * vote for a content 1129 * @param string $format 1130 * @param string $content 1131 * @param string $vote 1132 * @return string xml/json 1133 */ 1134 private function contentvote($format,$content,$vote) { 1135 1136 $user=$this->_checkpassword(true); 1137 //$this->checktrafficlimit($user); 1138 1139 $con = new OCSContent(); 1140 1141 // fetch data 1142 $content=addslashes($content); 1143 $vote=addslashes($vote); 1144 1145 // check data 1146 if (!$con->load($content)) { 1147 $txt=OCSXML::generatexml($format,'failed',101,'content not found'); 1148 } else { 1149 if($user<>'') $con->set_score($vote); 1150 $txt=OCSXML::generatexml($format,'ok',100,''); 1151 } 1152 echo($txt); 1153 } 1154 1155 1156 /** 1157 * delete a preview picture of a content 1158 * @param string $format 1159 * @param string $contentid 1160 * @param string $previewid 1161 * @return string xml/json 1162 */ 1163 private function contentpreviewdelete($format,$contentid,$previewid) { 1164 $user=$this->_checkpassword(true); 1165 //$this->checktrafficlimit($user); 1166 $content=addslashes($contentid); 1167 $preview=addslashes($previewid); 1168 1169 // fetch data 1170 $con = new OCSContent(); 1171 1172 if($con->load($content)){ 1173 if($con->is_preview_available($previewid)){ 1174 if($con->is_owned(OCSUser::id())) { 1175 1176 $con->previewdelete($content,$preview); 1177 1178 $txt=OCSXML::generatexml($format,'ok',100,''); 1179 } else { 1180 $txt=OCSXML::generatexml($format,'failed',101,'no permission to change content'); 1181 } 1182 } else { 1183 $txt=OCSXML::generatexml($format,'failed',102,'preview not found'); 1184 } 1185 } 1186 echo($txt); 1187 } 1188 1189 /** 1190 * upload a preview picture of a content 1191 * @param string $format 1192 * @param string $contentid 1193 * @param string $previewid 1194 * @return string xml/json 1195 */ 1196 private function contentpreviewupload($format,$contentid,$previewid) { 1197 $user=$this->_checkpassword(true); 1198 //$this->checktrafficlimit($user); 1199 $content=addslashes($contentid); 1200 $preview=addslashes($previewid); 1201 1202 // fetch data 1203 $con = new OCSContent(); 1204 1205 if(($preview==1) or ($preview==2) or ($preview==3)) { 1206 1207 if($con->load($content) and $con->is_owned(OCSUser::id())) { 1208 1209 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')) { 1210 if($con->previewadd($content,'localfile',$preview)){ 1211 $txt=OCSXML::generatexml($format,'ok',100,''); 1212 } else { 1213 ELog::error("previewadd crashed lol!"); 1214 } 1215 } else { 1216 $txt=OCSXML::generatexml($format,'failed',101,'localfile not found'); 1217 } 1218 } else { 1219 $txt=OCSXML::generatexml($format,'failed',102,'no permission to change content'); 1220 } 1221 } else { 1222 $txt=OCSXML::generatexml($format,'failed',103,'preview must be 1, 2 or 3'); 1223 } 1224 echo($txt); 1225 } 1226 1227 1228 1229 /** 1230 * delete the downloadfile from a content 1231 * @param string $format 1232 * @param string $contentid 1233 * @return string xml/json 1234 */ 1235 private function contentdownloaddelete($format,$contentid) { 1236 $user=$this->_checkpassword(true); 1237 //$this->checktrafficlimit($user); 1238 $content=addslashes($contentid); 1239 1240 // fetch data 1241 $con = new OCSContent(); 1242 1243 if($con->load($content) and $con->is_owned(OCSUser::id())) { 1244 1245 $con->downloaddelete(); 1246 $txt=OCSXML::generatexml($format,'ok',100,''); 1247 } else { 1248 $txt=OCSXML::generatexml($format,'failed',101,'no permission to change content'); 1249 } 1250 1251 echo($txt); 1252 1253 } 1254 1255 /** 1256 * upload the downloadfile for a content 1257 * @param string $format 1258 * @param string $contentid 1259 * @return string xml/json 1260 */ 1261 private function contentdownloadupload($format,$contentid) { 1262 1263 $user=$this->_checkpassword(true); 1264 //$this->checktrafficlimit($user); 1265 $content=addslashes($contentid); 1266 1267 // fetch data 1268 $con = new OCSContent(); 1269 1270 if($con->load($content) and $con->is_owned(OCSUser::id())) { 1271 1272 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')) { 1273 if($con->downloadadd($content,'localfile')){ 1274 $txt=OCSXML::generatexml($format,'ok',100,''); 1275 }else{ 1276 $txt=OCSXML::generatexml($format,'failed',101,$error); 1277 } 1278 } else { 1279 $txt=OCSXML::generatexml($format,'failed',102,'localfile not found'); 1280 } 1281 } else { 1282 $txt=OCSXML::generatexml($format,'failed',103,'no permission to change content'); 1283 } 1284 1285 echo($txt); 1286 1287 } 1288 1289 /** 1290 * add a new content 1291 * @param string $format 1292 * @return string xml/json 1293 */ 1294 private function contentadd($format) { 1295 $user=$this->_checkpassword(true); 1296 //$this->checktrafficlimit($user); 1297 1298 $categories = EConfig::$data["ocs_categories"]; 1299 $numcats = count($categories); 1300 1301 if(OCSUser::is_logged()) { 1302 1303 $data=array(); 1304 $data['name']=$this->readdata('name','text'); 1305 $data['type']=$this->readdata('type','int'); 1306 1307 if($this->readdata('downloadname1','text')<>'') $data['downloadname1']=$this->readdata('downloadname1','text') ; 1308 if($this->readdata('downloadlink1','text')<>'') $data['downloadlink1']=$this->readdata('downloadlink1','text'); 1309 if($this->readdata('description','text')<>'') { $data['description']=$this->readdata('description','text'); } else { $data['description']='...'; } 1310 if($this->readdata('summary','text')<>'') { $data['summary']=$this->readdata('summary','text'); } else { $data['summary']='...'; } 1311 if($this->readdata('version','text')<>'') { $data['version']=$this->readdata('version','text'); } else { $data['version']='...'; } 1312 if($this->readdata('changelog','text')<>'') { $data['changelog']=$this->readdata('changelog','text'); } else { $data['changelog']='...'; } 1313 //if($this->readdata('personid','text')<>'') $data['personid']=$this->readdata('personid','text'); 1314 if($this->readdata('license','int') >=0 or $this->readdata('license','int')<5) $data['license']=$this->readdata('license','int'); 1315 1316 /* 1317 $data['preview1'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 1318 $data['preview2'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 1319 $data['preview3'] = "http://".EConfig::$data["ocs"]["host"]."/template/img/screenshot-unavailable.png"; 1320 */ 1321 $data['preview1'] = ""; 1322 $data['preview2'] = ""; 1323 $data['preview3'] = ""; 1324 $data['personid'] = $user; 1325 1326 if( ($data['name']<>'') or ($data['type']<0) or ($data['type']>$numcats) ) { 1327 $content = new OCSContent(); 1328 $content->set_owner(OCSUser::id()); 1329 $content->set_data($data); 1330 $content->save(); 1331 1332 $xml = array(); 1333 $xml[0]['id'] = $content->id(); 1334 $txt = OCSXML::generatexml($format,'ok',100,'',$xml,'content','',2); 1335 }else{ 1336 $txt = OCSXML::generatexml($format,'failed',101,'please specify all mandatory fields'); 1337 } 1338 }else{ 1339 $txt=OCSXML::generatexml($format,'failed',102,'no permission to change content'); 1340 } 1341 1342 echo($txt); 1343 1344 } 1345 1346 /** 1347 * edit a content entry 1348 * @param string $format 1349 * @param string $contentid 1350 * @return string xml/json 1351 */ 1352 private function contentedit($format,$contentid) { 1353 1354 $user=$this->_checkpassword(true); 1355 //$this->checktrafficlimit($user); 1356 $content=addslashes($contentid); 1357 1358 $categories = EConfig::$data["ocs_categories"]; 1359 $numcats = count($categories); 1360 1361 // fetch data 1362 $con = new OCSContent(); 1363 if($con->load($content) and OCSUser::is_logged() and OCSUser::id() == $con->owner) { 1364 1365 $data=array(); 1366 if($this->readdata('name','text')<>'') $data['name'] = $this->readdata('name','text'); 1367 if($this->readdata('type','text')<>'') $data['type'] = $this->readdata('type','text'); else $data['type'] = $con->type; 1368 1369 if($this->readdata('downloadname1','text')<>$con->downloadname1) $data['downloadname1'] = $this->readdata('downloadname1','text'); 1370 if($this->readdata('downloadlink1','text')<>$con->downloadlink1) $data['downloadlink1'] = $this->readdata('downloadlink1','text'); 1371 if($this->readdata('description','text')<>'') { $data['description']=$this->readdata('description','text'); } else { $data['description']='...'; } 1372 if($this->readdata('summary','text')<>'') { $data['summary']=$this->readdata('summary','text'); } else { $data['summary']='...'; } 1373 if($this->readdata('version','text')<>'') { $data['version']=$this->readdata('version','text'); } else { $data['version']='...'; } 1374 if($this->readdata('changelog','text')<>'') { $data['changelog']=$this->readdata('changelog','text'); } else { $data['changelog']='...'; } 1375 if($this->readdata('license','int') >=0 or $this->readdata('license','int')<5) $data['license']=$this->readdata('license','int'); 1376 1377 if( ($data['name']<>'') or ($data['type']<0) or ($data['type']>$numcats) ) { 1378 $con->update(array("name","type","downloadname1","downloadlink1","description","summary","version","changelog","license")); 1379 1380 $xml = array(); 1381 $txt = OCSXML::generatexml($format,'ok',100,'',$xml,'content'); 1382 }else{ 1383 $txt = OCSXML::generatexml($format,'failed',101,'please specify all mandatory fields'); 1384 } 1385 }else{ 1386 $txt=OCSXML::generatexml($format,'failed',102,'no permission to change content'); 1387 } 1388 $con->updated(); 1389 1390 echo($txt); 1391 1392 } 1393 1394 /** 1395 * delete a content 1396 * @param string $format 1397 * @param string $contentid 1398 * @return string xml/json 1399 */ 1400 private function contentdelete($format,$contentid) { 1401 1402 $user=$this->_checkpassword(true); 1403 //$this->checktrafficlimit($user); 1404 $content=addslashes($contentid); 1405 1406 // fetch data 1407 $con = new OCSContent(); 1408 if(!$con->load($content)){ 1409 $txt=OCSXML::generatexml($format,'failed',101,'no permission to change content'); 1410 } else { 1411 if(!$con->is_owned(OCSUser::id())){ 1412 $txt=OCSXML::generatexml($format,'failed',101,'no permission to change content'); 1413 } else { 1414 $con->delete(); 1415 $txt=OCSXML::generatexml($format,'ok',100,''); 1416 } 1417 } 1418 1419 echo($txt); 1420 } 1421 1422 // ACTIVITY API ############################################# 1423 1424 /** 1425 * get my activities 1426 * @param string $format 1427 * @param string $page 1428 * @param string $pagesize 1429 * @return string xml/json 1430 */ 1431 private function activityget($format,$page,$pagesize) { 1432 1433 $user=$this->_checkpassword(); 1434 //$this->checktrafficlimit($user); 1435 1436 $al = new OCSActivityLister(); 1437 $log=$al->ocs_activity_list($user,$page,$pagesize); 1438 $itemscount=count($log); 1439 $xml=array(); 1440 for ($i=0; $i < $itemscount;$i++) { 1441 $xml[$i]['id']=$log[$i]['id']; 1442 $xml[$i]['personid']=$log[$i]['personid']; 1443 $xml[$i]['firstname']=$log[$i]['firstname']; 1444 $xml[$i]['lastname']=$log[$i]['lastname']; 1445 $xml[$i]['profilepage']=''; 1446 $xml[$i]['avatarpic']=''; 1447 $xml[$i]['timestamp']=date('c',$log[$i]['timestamp']); 1448 $xml[$i]['type']=$log[$i]['type']; 1449 $xml[$i]['message']=strip_tags($log[$i]['message']); 1450 $xml[$i]['link']=''; 1451 } 1452 1453 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'activity','full',2,count($xml),$pagesize); 1454 1455 echo($txt); 1456 1457 } 1458 1459 /** 1460 * submit a activity 1461 * @param string $format 1462 * @param string $message 1463 * @return string xml/json 1464 */ 1465 private function activityput($format,$message) { 1466 $user=$this->_checkpassword(); 1467 //$this->checktrafficlimit($user); 1468 1469 if($user<>'') { 1470 if(trim($message)<>'') { 1471 OCSActivity::add(OCSUser::id(), 1, $message); 1472 echo(OCSXML::generatexml($format,'ok',100,'')); 1473 } else { 1474 echo(OCSXML::generatexml($format,'failed',101,'empty message')); 1475 } 1476 } else { 1477 echo(OCSXML::generatexml($format,'failed',102,'user not found')); 1478 } 1479 1480 } 1481 1482 // FAN API ############################################# 1483 1484 /** 1485 * get the fans of a specific content 1486 * @param string $format 1487 * @param string $content 1488 * @param string $page 1489 * @param string $pagesize 1490 * @return string xml/json 1491 */ 1492 private function fanget($format,$content,$page,$pagesize) { 1493 $user=$this->_checkpassword(true); 1494 //$this->checktrafficlimit($user); 1495 $content=strip_tags(addslashes($content)); 1496 $page = intval($page); 1497 1498 $fan = new OCSFanLister; 1499 $xml = $fan->ocs_fan_list($content,$page,$pagesize); 1500 $fancount = count($xml); 1501 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'person','fans',2,$fancount,$pagesize); 1502 1503 echo $txt; 1504 } 1505 1506 1507 /** 1508 * add a fans to a specific content 1509 * @param string $format 1510 * @param string $content 1511 * @return string xml/json 1512 */ 1513 private function addfan($format,$content) { 1514 $contentid = intval($content); 1515 $user=$this->_checkpassword(true); 1516 //$this->checktrafficlimit($user); 1517 1518 $fan = new OCSFan; 1519 if(!$fan->isfan($content)){ 1520 $fan->add($contentid); 1521 } 1522 1523 $txt=OCSXML::generatexml($format,'ok',100,''); 1524 echo($txt); 1525 } 1526 1527 1528 /** 1529 * remove a fans from a specific content 1530 * @param string $format 1531 * @param string $content 1532 * @return string xml/json 1533 */ 1534 private function removefan($format,$content) { 1535 $contentid = intval($content); 1536 $user=$this->_checkpassword(true); 1537 //$this->checktrafficlimit($user); 1538 1539 $fan = new OCSFan; 1540 if($fan->isfan($content)){ 1541 $fan->remove($contentid); 1542 } 1543 1544 $txt=OCSXML::generatexml($format,'ok',100,''); 1545 echo($txt); 1546 } 1547 1548 1549 /** 1550 * check if the user is a fan of a content 1551 * @param string $format 1552 * @param string $content 1553 * @return string xml/json 1554 */ 1555 private function isfan($format,$content) { 1556 $contentid = intval($content); 1557 $user=$this->_checkpassword(true); 1558 //$this->checktrafficlimit($user); 1559 $fan = new OCSFan; 1560 if($fan->isfan($contentid)){ 1561 $xml['status']='fan'; 1562 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'','',1); 1563 }else{ 1564 $xml['status']='notfan'; 1565 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'','',1); 1566 } 1567 echo($txt); 1568 } 1569 1570 // COMMENTS API ############################################# TODO: tests 1571 1572 /** 1573 * add a comment 1574 * @param string $format 1575 * @param string $content 1576 * @param string $parent 1577 * @param string $subject 1578 * @param string $message 1579 * @return string xml/json 1580 */ 1581 private function commentsadd($format,$type,$content,$content2,$parent,$subject,$message) { 1582 $user = $this->_checkpassword(true); 1583 //$this->checktrafficlimit($user); 1584 $data['parent'] = strip_tags(addslashes($parent)); 1585 $data['subject'] = strip_tags(addslashes($subject)); 1586 $data['message'] = strip_tags(addslashes($message)); 1587 $data['content'] = strip_tags(addslashes($content)); 1588 $data['content2'] = strip_tags(addslashes($content2)); 1589 $data['type'] = strip_tags(addslashes($type)); 1590 $data['owner'] = OCSUser::id(); 1591 1592 //types 1593 // just 1 is accepted 1594 // 1 - content 1595 1596 //setting content type as default 1597 if(!in_array($data['type'],array(1,4,7,8))) $data['type']=1; 1598 1599 if($user<>'') { 1600 if($data['message']<>'' and $data['subject']<>'') { 1601 if($data['content']<>0) { 1602 $comment = new OCSComment(); //creating new object 1603 $comment->set_data($data); //loading new data for comment 1604 $comment->save_to_db(); 1605 $id = $comment->id(); 1606 $xml[0]['id'] = $id; 1607 echo(OCSXML::generatexml($format,'ok',100,'',$xml,'comment','',2)); 1608 } else { 1609 echo(OCSXML::generatexml($format,'failed',101,'content must not be empty')); 1610 } 1611 } else { 1612 echo(OCSXML::generatexml($format,'failed',102,'message or subject must not be empty')); 1613 } 1614 } else { 1615 echo(OCSXML::generatexml($format,'failed',103,'no permission to add a comment')); 1616 } 1617 1618 } 1619 1620 1621 1622 private function commentsget($format,$type,$content,$content2,$page,$pagesize) { 1623 $user=$this->_checkpassword(false); 1624 //$this->checktrafficlimit($user); 1625 $type = strip_tags(addslashes($type)); 1626 $content = strip_tags(addslashes($content)); 1627 $content2 = strip_tags(addslashes($content2)); 1628 $page = strip_tags(addslashes($page)); 1629 $pagesize = strip_tags(addslashes($pagesize)); 1630 1631 //types 1632 // 1 - content 1633 // 4 - forum 1634 // 7 - knowledgebase 1635 // 8 - event 1636 1637 if(!in_array($type,array(1,4,7,8))) $type=1; 1638 1639 $coml = new OCSCommentLister(); 1640 $comments = $coml->ocs_comment_list($type,$content,$content2,$page,$pagesize); 1641 $totalitems = count($comments); 1642 //$txt=$this->generatexml($format,'ok',100,'',$comments,'event','detail',2,$totalitems,$pagesize); 1643 1644 $txt=OCSXML::generatexml($format,'ok',100,'',$comments,'comment','','dynamic',$totalitems,$pagesize); 1645 echo($txt); 1646 1647 1648 } 1649 1650 1651 /** 1652 * vote for a comment TODO: IMPLEMENT THIS ONE 1653 * @param string $format 1654 * @param string $id 1655 * @param string $score 1656 * @return string xml/json 1657 */ 1658 private function commentvote($format,$id,$score) { 1659 $user=$this->_checkpassword(true); 1660 //$this->checktrafficlimit($user); 1661 1662 $comment = new OCSComment(); 1663 if($comment->load($id)){ 1664 1665 $comment->set_score($score); 1666 $txt=$this->generatexml($format,'ok',100,''); 1667 echo($txt); 1668 } else { 1669 $txt=$this->generatexml($format,'failed',101,'comment not found'); 1670 } 1671 } 1672 1673 // FRIEND API ############################################# 1674 1675 /** 1676 * get the list of sent invitations 1677 * @param string $format 1678 * @param string $page 1679 * @param string $pagesize 1680 * @return string xml/json 1681 */ 1682 private function friendsentinvitations($format,$page,$pagesize) { 1683 $user=$this->_checkpassword(); 1684 //$this->checktrafficlimit($user); 1685 1686 $friend = new OCSFriendsLister; 1687 $xml = $friend->ocs_sentinvitations($page,$pagesize); 1688 $friendcount = count($xml); 1689 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1690 1691 echo $txt; 1692 } 1693 1694 /** 1695 * get the list of received invitations 1696 * @param string $format 1697 * @param string $page 1698 * @param string $pagesize 1699 * @return string xml/json 1700 */ 1701 private function friendreceivedinvitations($format,$page,$pagesize) { 1702 $user=$this->_checkpassword(); 1703 //$this->checktrafficlimit($user); 1704 1705 $friend = new OCSFriendsLister; 1706 $xml = $friend->ocs_receivedinvitations($page,$pagesize); 1707 $friendcount = count($xml); 1708 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1709 1710 echo $txt; 1711 } 1712 1713 /** 1714 * get the list of friends from a person 1715 * @param string $format 1716 * @param string $fromuser user which called the query 1717 * @param string $page 1718 * @param string $pagesize 1719 * @return string xml/json 1720 */ 1721 private function friendget($format,$fromuser,$page,$pagesize) { //example params: (,snizzo,0,10); 1722 $user=$this->_checkpassword(); 1723 //$this->checktrafficlimit($user); 1724 1725 $fromuser=strip_tags(addslashes($fromuser)); 1726 1727 /* 1728 $cache = new H01_CACHE('apifriends',array($fromuser,CONFIG_USERDB,$page,$pagesize,$format)); 1729 if ($cache->exist()) { 1730 $cache->get(); 1731 unset($cache); 1732 } else { 1733 1734 $DBuser=H01_USER::getuser($fromuser,CONFIG_USERDB); 1735 if(isset($DBuser['login'])) { 1736 if($DBuser['privacyrelations']==0) { 1737 $visible=true; 1738 }elseif($DBuser['privacyrelations']==1){ 1739 if($user<>'') $visible=true; else $visible=false; 1740 }elseif($DBuser['privacyrelations']==2){ 1741 if(($fromuser==$user) or (H01_RELATION::isrelation(1,$fromuser,CONFIG_USERDB,$user))) $visible=true; else $visible=false; 1742 }elseif($DBuser['privacyrelations']==3){ 1743 if($fromuser==$user) $visible=true; else $visible=false; 1744 } 1745 1746 if($visible){ 1747 $countapprovedrelations=H01_RELATION::countapprovedrelations(1,$fromuser,CONFIG_USERDB); 1748 $relations=H01_RELATION::getapprovedrelations(1,$fromuser,CONFIG_USERDB,$start,$count,true); 1749 $itemscount=count($relations); 1750 $xml=array(); 1751 for ($i=0; $i < $itemscount;$i++) { 1752 $xml[$i]['personid']=$relations[$i]['user']; 1753 $xml[$i]['firstname']=$relations[$i]['firstname']; 1754 $xml[$i]['lastname']=$relations[$i]['lastname']; 1755 1756 1757 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; } 1758 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; } 1759 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; } 1760 else { $pic=HOST.'/usermanager/nopic.png'; $found=false ;} 1761 $xml[$i]['avatarpic']=$pic; 1762 $xml[$i]['avatarpicfound']=$found; 1763 } 1764 $txt=$this->generatexml($format,'ok',100,'',$xml,'user','id',2,$countapprovedrelations,$pagesize); 1765 }else{ 1766 $txt=$this->generatexml($format,'failed',101,'data is private'); 1767 } 1768 }else{ 1769 $txt=$this->generatexml($format,'failed',102,'user not found'); 1770 } 1771 1772 $cache->put($txt); 1773 unset($cache); 1774 echo($txt); 1775 } 1776 */ 1777 $fan = new OCSFriendsLister; 1778 $xml = $fan->ocs_friend_list($fromuser,$page,$pagesize); 1779 $friendcount = count($xml); 1780 $txt=OCSXML::generatexml($format,'ok',100,'',$xml,'person','id',2,$friendcount,$pagesize); 1781 1782 echo $txt; 1783 } 1784 1785 1786 1787 1788 /** 1789 * invite a person as a friend 1790 * @param string $format 1791 * @param string $inviteuser 1792 * @param string $message 1793 * @return string xml/json 1794 */ 1795 private function friendinvite($format,$inviteuser,$message) { 1796 $user=$this->_checkpassword(); 1797 //$this->checktrafficlimit($user); 1798 $inviteuser = strip_tags(addslashes($inviteuser)); 1799 $message = strip_tags(addslashes($message)); 1800 1801 if($user<>'' and $inviteuser<>'' and $inviteuser<>false) { 1802 if($user<>$inviteuser) { 1803 if($message<>'') { 1804 OCSFriend::send_invitation($inviteuser, $message); 1805 echo(OCSXML::generatexml($format,'ok',100,'')); 1806 } else { 1807 echo(OCSXML::generatexml($format,'failed',101,'message must not be empty')); 1808 } 1809 }else{ 1810 echo(OCSXML::generatexml($format,'failed',102,'you can\´t invite yourself')); 1811 } 1812 } else { 1813 echo(OCSXML::generatexml($format,'failed',103,'user not found')); 1814 } 1815 1816 } 1817 1818 /** 1819 * approve a friendsship invitation 1820 * @param string $format 1821 * @param string $inviteuser 1822 * @return string xml/json 1823 */ 1824 private function friendapprove($format,$inviteuser) { 1825 $user=$this->_checkpassword(); 1826 //$this->checktrafficlimit($user); 1827 $inviteuser = strip_tags(addslashes($inviteuser)); 1828 1829 if($user<>'' and $inviteuser<>'') { 1830 OCSFriend::approve_invitation($inviteuser); 1831 echo(OCSXML::generatexml($format,'ok',100,'')); 1832 } else { 1833 echo(OCSXML::generatexml($format,'failed',101,'user not found')); 1834 } 1835 1836 } 1837 1838 1839 /** 1840 * decline a friendsship invitation 1841 * @param string $format 1842 * @param string $inviteuser 1843 * @return string xml/json 1844 */ 1845 private function frienddecline($format,$inviteuser) { 1846 $user=$this->_checkpassword(); 1847 //$this->checktrafficlimit($user); 1848 $inviteuser = strip_tags(addslashes($inviteuser)); 1849 1850 if($user<>'' and $inviteuser<>'') { 1851 OCSFriend::decline_invitation($inviteuser); 1852 echo(OCSXML::generatexml($format,'ok',100,'')); 1853 } else { 1854 echo(OCSXML::generatexml($format,'failed',101,'user not found')); 1855 } 1856 1857 } 1858 1859 1860 /** 1861 * cancel a friendsship 1862 * @param string $format 1863 * @param string $inviteuser 1864 * @return string xml/json 1865 */ 1866 private function friendcancel($format,$inviteuser) { 1867 $user=$this->_checkpassword(); 1868 //$this->checktrafficlimit($user); 1869 $inviteuser = strip_tags(addslashes($inviteuser)); 1870 1871 if($user<>'' and $inviteuser<>'') { 1872 OCSFriend::cancel_friendship($inviteuser); 1873 echo(OCSXML::generatexml($format,'ok',100,'')); 1874 } else { 1875 echo(OCSXML::generatexml($format,'failed',101,'user not found')); 1876 } 1877 1878 } 1879 1880 1881 /** 1882 * cancel a friendsship invitation 1883 * @param string $format 1884 * @param string $inviteuser 1885 * @return string xml/json 1886 */ 1887 private function friendcancelrequest($format,$inviteuser) { 1888 $user=$this->_checkpassword(); 1889 //$this->checktrafficlimit($user); 1890 $inviteuser = strip_tags(addslashes($inviteuser)); 1891 1892 if($user<>'' and $inviteuser<>'') { 1893 H01_RELATION::deleterelationrequest(1,$user,$inviteuser,CONFIG_USERDB); 1894 echo(OCSXML::generatexml($format,'ok',100,'')); 1895 } else { 1896 echo(OCSXML::generatexml($format,'failed',101,'user not found')); 1897 } 1898 1899 } 1900 1901 } 1902 1903 ?>