Respect coding style

This commit is contained in:
Thomas Müller 2012-09-10 14:59:08 +03:00
parent 0444877218
commit 5a65c5a46c
1 changed files with 82 additions and 88 deletions

View File

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