$app=Application::from_api_key($db,$_REQUEST['key'])or$apiResponse->die("Invalid application API key");
switch($command=$url[1]){
case'':
//Nothing to do
//TODO: offer documentation instead
die();
case'checkuserkey':
if(count($url)<2){
$apiResponse->die("/checkuserkey/ must be followed by an user key");
}
$reply=(boolean)$app->get_perso_id($url[2]);
$apiResponse->output($reply,"check");
break;
case'pushuserdata':
if(count($url)<3){
$apiResponse->die("/pushuserdata/ must be followed by an user key");
}
$perso_id=$app->get_perso_id($url[2])or$apiResponse->die("Invalid application user key");
//then, falls to 'pushdata'
case'pushdata':
$data_id=$_REQUEST['data']?:new_guid();
//Gets data
switch($mode=$_REQUEST['mode']){
case'':
$apiResponse->die("Add in your data posted or in the URL mode=file to read data from the file posted (one file per api call) or mode=request to read data from \$_REQUEST['data'].");
case'request':
$data=$_REQUEST['data'];
$format="raw";
break;
case'file':
$file=$_FILES['datafile']['tmp_name']or$apiResponse->die("File is missing");
if(!is_uploaded_file($file)){
$apiResponse->die("Invalid form request");
}
$data="";
if(preg_match('/\.tar$/',$file)){
$format="tar";
$data=file_get_contents($file);
}elseif(preg_match('/\.tar\.bz2$/',$file)){
$format="tar";
}elseif(preg_match('/\.bz2$/',$file)){
$format="raw";
}else{
$format="raw";
$data=file_get_contents($file);
}
if($data===""){
//.bz2
$bz=bzopen($file,"r")or$apiResponse->die("Couldn't open $file");