diff --git a/lib/ocs.php b/lib/ocs.php index 3a9be4cf09..7350c3c882 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -84,7 +84,7 @@ class OC_OCS { $method='get'; }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { $method='put'; - parse_str(file_get_contents("php://input"),$put_vars); + parse_str(file_get_contents("php://input"), $put_vars); }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $method='post'; }else{ @@ -94,8 +94,8 @@ class OC_OCS { // preprocess url $url = strtolower($_SERVER['REQUEST_URI']); - if(substr($url,(strlen($url)-1))<>'/') $url.='/'; - $ex=explode('/',$url); + if(substr($url, (strlen($url)-1))<>'/') $url.='/'; + $ex=explode('/', $url); $paracount=count($ex); $format = self::readData($method, 'format', 'text', ''); @@ -107,23 +107,23 @@ class OC_OCS { // PERSON // personcheck - POST - PERSON/CHECK - }elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')) { + } elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')) { $login = self::readData($method, 'login', 'text'); $passwd = self::readData($method, 'password', 'text'); - OC_OCS::personcheck($format,$login,$passwd); + OC_OCS::personcheck($format, $login, $passwd); // ACTIVITY // activityget - GET ACTIVITY page,pagesize als urlparameter }elseif(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) { $page = self::readData($method, 'page', 'int', 0); - $pagesize = self::readData($method, 'pagesize','int', 10); + $pagesize = self::readData($method, 'pagesize', 'int', 10); if($pagesize<1 or $pagesize>100) $pagesize=10; - OC_OCS::activityget($format,$page,$pagesize); + OC_OCS::activityget($format, $page, $pagesize); // activityput - POST ACTIVITY }elseif(($method=='post') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) { $message = self::readData($method, 'message', 'text'); - OC_OCS::activityput($format,$message); + OC_OCS::activityput($format, $message); // PRIVATEDATA @@ -138,7 +138,7 @@ class OC_OCS { $key=$ex[$paracount-2]; $app=$ex[$paracount-3]; - OC_OCS::privateDataGet($format, $app,$key); + OC_OCS::privateDataGet($format, $app, $key); // set - POST DATA }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'setattribute')) { @@ -160,23 +160,23 @@ class OC_OCS { // quotaget }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) { $user=$ex[$paracount-3]; - OC_OCS::quotaget($format,$user); + OC_OCS::quotaget($format, $user); // quotaset }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) { $user=$ex[$paracount-3]; $quota = self::readData('post', 'quota', 'int'); - OC_OCS::quotaset($format,$user,$quota); + OC_OCS::quotaset($format, $user, $quota); // keygetpublic }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'publickey')) { $user=$ex[$paracount-3]; - OC_OCS::publicKeyGet($format,$user); + OC_OCS::publicKeyGet($format, $user); // keygetprivate }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')) { $user=$ex[$paracount-3]; - OC_OCS::privateKeyGet($format,$user); + OC_OCS::privateKeyGet($format, $user); // add more calls here @@ -196,7 +196,7 @@ class OC_OCS { }else{ $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; $txt.=OC_OCS::getdebugoutput(); - echo(OC_OCS::generatexml($format,'failed',999,$txt)); + echo(OC_OCS::generatexml($format, 'failed', 999, $txt)); } exit(); } @@ -237,7 +237,7 @@ class OC_OCS { $identifieduser=''; } }else{ - if(!OC_User::login($authuser,$authpw)) { + if(!OC_User::login($authuser, $authpw)) { if($forceuser) { header('WWW-Authenticate: Basic realm="your valid user account or api key"'); header('HTTP/1.0 401 Unauthorized'); @@ -283,69 +283,69 @@ class OC_OCS { $writer = xmlwriter_open_memory(); xmlwriter_set_indent( $writer, 2 ); xmlwriter_start_document($writer ); - xmlwriter_start_element($writer,'ocs'); - xmlwriter_start_element($writer,'meta'); - xmlwriter_write_element($writer,'status',$status); - xmlwriter_write_element($writer,'statuscode',$statuscode); - xmlwriter_write_element($writer,'message',$message); + xmlwriter_start_element($writer, 'ocs'); + xmlwriter_start_element($writer, 'meta'); + xmlwriter_write_element($writer, 'status', $status); + xmlwriter_write_element($writer, 'statuscode', $statuscode); + xmlwriter_write_element($writer, 'message', $message); if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount); - if(!empty($itemsperpage)) xmlwriter_write_element($writer,'itemsperpage',$itemsperpage); + if(!empty($itemsperpage)) xmlwriter_write_element($writer, 'itemsperpage', $itemsperpage); xmlwriter_end_element($writer); if($dimension=='0') { // 0 dimensions - xmlwriter_write_element($writer,'data',$data); + xmlwriter_write_element($writer, 'data', $data); }elseif($dimension=='1') { - xmlwriter_start_element($writer,'data'); + xmlwriter_start_element($writer, 'data'); foreach($data as $key=>$entry) { - xmlwriter_write_element($writer,$key,$entry); + xmlwriter_write_element($writer, $key, $entry); } xmlwriter_end_element($writer); }elseif($dimension=='2') { xmlwriter_start_element($writer,'data'); foreach($data as $entry) { - xmlwriter_start_element($writer,$tag); - if(!empty($tagattribute)) { - xmlwriter_write_attribute($writer,'details',$tagattribute); - } - foreach($entry as $key=>$value) { - if(is_array($value)) { - foreach($value as $k=>$v) { - xmlwriter_write_element($writer,$k,$v); - } - } else { - xmlwriter_write_element($writer,$key,$value); - } - } - xmlwriter_end_element($writer); - } + xmlwriter_start_element($writer, $tag); + if(!empty($tagattribute)) { + xmlwriter_write_attribute($writer, 'details', $tagattribute); + } + foreach($entry as $key=>$value) { + if(is_array($value)) { + foreach($value as $k=>$v) { + xmlwriter_write_element($writer, $k, $v); + } + } else { + xmlwriter_write_element($writer, $key, $value); + } + } + xmlwriter_end_element($writer); + } xmlwriter_end_element($writer); }elseif($dimension=='3') { - xmlwriter_start_element($writer,'data'); + xmlwriter_start_element($writer, 'data'); foreach($data as $entrykey=>$entry) { - xmlwriter_start_element($writer,$tag); - if(!empty($tagattribute)) { - xmlwriter_write_attribute($writer,'details',$tagattribute); - } - foreach($entry as $key=>$value) { - if(is_array($value)) { - xmlwriter_start_element($writer,$entrykey); - foreach($value as $k=>$v) { - xmlwriter_write_element($writer,$k,$v); - } - xmlwriter_end_element($writer); - } else { - xmlwriter_write_element($writer,$key,$value); - } - } - xmlwriter_end_element($writer); + xmlwriter_start_element($writer, $tag); + if(!empty($tagattribute)) { + xmlwriter_write_attribute($writer, 'details', $tagattribute); + } + foreach($entry as $key=>$value) { + if(is_array($value)) { + xmlwriter_start_element($writer, $entrykey); + foreach($value as $k=>$v) { + xmlwriter_write_element($writer, $k, $v); + } + xmlwriter_end_element($writer); + } else { + xmlwriter_write_element($writer, $key, $value); + } + } + xmlwriter_end_element($writer); } xmlwriter_end_element($writer); }elseif($dimension=='dynamic') { - xmlwriter_start_element($writer,'data'); - OC_OCS::toxml($writer,$data,'comment'); + xmlwriter_start_element($writer, 'data'); + OC_OCS::toxml($writer, $data, 'comment'); xmlwriter_end_element($writer); } @@ -364,18 +364,15 @@ class OC_OCS { $key = $node; } if (is_array($value)) { - xmlwriter_start_element($writer,$key); - OC_OCS::toxml($writer,$value,$node); + xmlwriter_start_element($writer, $key); + OC_OCS::toxml($writer,$value, $node); xmlwriter_end_element($writer); }else{ - xmlwriter_write_element($writer,$key,$value); + xmlwriter_write_element($writer, $key, $value); } } } - - - /** * return the config data of this server * @param string $format @@ -383,17 +380,16 @@ class OC_OCS { */ private static function apiConfig($format) { $user=OC_OCS::checkpassword(false); - $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'],0,-11).''; + $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'], 0, -11).''; $xml['version']='1.7'; $xml['website']='ownCloud'; $xml['host']=OCP\Util::getServerHost(); $xml['contact']=''; $xml['ssl']='false'; - echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'config','',1)); + echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'config', '', 1)); } - /** * check if the provided login/apikey/password is valid * @param string $format @@ -403,19 +399,17 @@ class OC_OCS { */ private static function personCheck($format,$login,$passwd) { if($login<>'') { - if(OC_User::login($login,$passwd)) { + if(OC_User::login($login, $passwd)) { $xml['person']['personid']=$login; - echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'person','check',2)); + echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'person', 'check', 2)); }else{ - echo(OC_OCS::generatexml($format,'failed',102,'login not valid')); + echo(OC_OCS::generatexml($format, 'failed', 102, 'login not valid')); } }else{ - echo(OC_OCS::generatexml($format,'failed',101,'please specify all mandatory fields')); + echo(OC_OCS::generatexml($format, 'failed', 101, 'please specify all mandatory fields')); } } - - // ACTIVITY API ############################################# /** @@ -425,12 +419,12 @@ class OC_OCS { * @param string $pagesize * @return string xml/json */ - private static function activityGet($format,$page,$pagesize) { + private static function activityGet($format, $page, $pagesize) { $user=OC_OCS::checkpassword(); //TODO - $txt=OC_OCS::generatexml($format,'ok',100,'',$xml,'activity','full',2,$totalcount,$pagesize); + $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'activity', 'full', 2, $totalcount,$pagesize); echo($txt); } @@ -443,7 +437,7 @@ class OC_OCS { private static function activityPut($format,$message) { // not implemented in ownCloud $user=OC_OCS::checkpassword(); - echo(OC_OCS::generatexml($format,'ok',100,'')); + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } // PRIVATEDATA API ############################################# @@ -455,9 +449,9 @@ class OC_OCS { * @param string $key * @return string xml/json */ - private static function privateDataGet($format,$app="",$key="") { + private static function privateDataGet($format, $app="", $key="") { $user=OC_OCS::checkpassword(); - $result=OC_OCS::getData($user,$app,$key); + $result=OC_OCS::getData($user, $app, $key); $xml=array(); foreach($result as $i=>$log) { $xml[$i]['key']=$log['key']; @@ -480,8 +474,8 @@ class OC_OCS { */ private static function privateDataSet($format, $app, $key, $value) { $user=OC_OCS::checkpassword(); - if(OC_OCS::setData($user,$app,$key,$value)) { - echo(OC_OCS::generatexml($format,'ok',100,'')); + if(OC_OCS::setData($user, $app, $key, $value)) { + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } } @@ -497,8 +491,8 @@ class OC_OCS { return; //key and app are NOT optional here } $user=OC_OCS::checkpassword(); - if(OC_OCS::deleteData($user,$app,$key)) { - echo(OC_OCS::generatexml($format,'ok',100,'')); + if(OC_OCS::deleteData($user, $app, $key)) { + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } } @@ -510,7 +504,7 @@ class OC_OCS { * @param bool $like use LIKE instead of = when comparing keys * @return array */ - public static function getData($user,$app="",$key="") { + public static function getData($user, $app="", $key="") { if($app) { $apps=array($app); }else{ @@ -520,14 +514,14 @@ class OC_OCS { $keys=array($key); }else{ foreach($apps as $app) { - $keys=OC_Preferences::getKeys($user,$app); + $keys=OC_Preferences::getKeys($user, $app); } } $result=array(); foreach($apps as $app) { foreach($keys as $key) { - $value=OC_Preferences::getValue($user,$app,$key); - $result[]=array('app'=>$app,'key'=>$key,'value'=>$value); + $value=OC_Preferences::getValue($user, $app, $key); + $result[]=array('app'=>$app, 'key'=>$key, 'value'=>$value); } } return $result; @@ -542,7 +536,7 @@ class OC_OCS { * @return bool */ public static function setData($user, $app, $key, $value) { - return OC_Preferences::setValue($user,$app,$key,$value); + return OC_Preferences::setValue($user, $app, $key, $value); } /** @@ -553,7 +547,7 @@ class OC_OCS { * @return string xml/json */ public static function deleteData($user, $app, $key) { - return OC_Preferences::deleteKey($user,$app,$key); + return OC_Preferences::deleteKey($user, $app, $key); }