connect($_SESSION ['session_mdp']); if(!$me->isConnected()){ echo 'Your must being connected to have access to this page'; exit; }elseif($me->isAdminLevelLowerThan(15)){ echo 'Your admin level is too low (15 or more required)'; exit; }elseif(!isset($_POST['command'])){ echo 'Please set an command in the URL (POST method ,name:"command")'; exit; } function isAlphaNumeric($char){ return isAlphabetic($char) or isNumeric($char); } function isAlphabetic($char){ return preg_match('#^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]$#',$char) === 1; } function isNumeric($char){ return preg_match('#^[0123456789]$#',$char) === 1; } function error($pos,$reason){ echo 'Error at char '.$pos.' : '.$reason; exit; } function readAlphabetic($command){ global $pos; $out = ""; while (isAlphaNumeric($command[$pos])) { $out .= $command[$pos]; $pos+=1; } return $out; } function readNumeric($command){ //TODO Add non-integer support (virgule , puissance , autres bases ...) global $pos; $out = ""; while (isNumeric($command[$pos])) { $out .= $command[$pos]; $pos+=1; } return intval($out); } function readString($command,$startChar='\"'){ global $pos; $out = ""; $startChar = $command[$pos]; $pos+=1; while (TRUE) { $char = $command[$pos]; if($char === $startChar) break; if($char === '\\'){ $pos+=1; switch ($command[$pos]){ case '\\': $char = '\\'; break; case $startChar: $char = $startChar; break; default: error($pos,'Unexpected "'.$command['pos'].'" after "\\"'); } } $out .= $char; $pos+=1; } $pos +=1; return $out; } $operators = array('=','!=','>','<','>=','=>','<=','=<','&has;','&nhas;'); $operatorsChars = array('=','!','<','>','&'); function readOperator($command,$endChar = 'abcdefghijklmnopqrstuvwxytABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789"\''){ global $pos,$operators; if($command[$pos] === '&'){ $pos+=1; $inOperator = readAlphabetic($command); if($command[$pos] !== ';'){ error($pos, 'Unexepted character at the end of the operator ' . $inOperator); } return '&'.$inOperator.';'; } $reading = ''; $lastOperator = ''; $maxPos=min(strlen($command),$pos+4); $tPos = $pos; while ($tPos<$maxPos) { //echo $reading; $reading .= $command[$tPos]; $tPos+=1; if(in_array($reading,$operators,TRUE)) $lastOperator=$reading; } $pos += strLen($lastOperator); if(!in_array($lastOperator,$operators)) error($pos, 'Unknown operator : '.$out); return $lastOperator; } function readSelector($command){ global $pos,$operatorsChars; $out = array(); $pos += 1;//@ if(!isAlphabetic($command[$pos])) error($pos,'Unexepted non-alphabetic char "'.$command[$pos].'" after @'); $className = readAlphabetic($command,'['); $pos += 1;//[ +1 $attributes = array(); while($command[$pos] !== ']'){ if($command[$pos] === ',') $pos+=1; $attributeName = readAlphabetic($command,implode($operatorsChars)); $operator = readOperator($command); $data = null; $type = $command[$pos]; if(isAlphabetic($type)){ $data = array('a',readAlphabetic($command)); }elseif (isNumeric($type)){ $data = array('0',readNumeric($command)); }elseif ($type === '"' or $type === '\''){ $data = array('"',readString($command)); }elseif ($type === "@"){ $data = array('@',readSelector($command)); } $attribute = array(); $attribute[0] = $attributeName; $attribute[1] = $operator; $attribute[2] = $data; $attributes[] = $attribute; } $pos+=1;//after "[" if($command[$pos] == ':'){ $pos+=1;//letter after ":" $selectedAttribute = readAlphabetic($command); return array($className,$attributes,$selectedAttribute); } return array($className,$attributes); } $command=$_POST['command'].' '; $nommes=array(); $pos=0; while ($pos'; print_r($nommes); echo ''; function exception($reason){ echo 'An exception occurred : '.$reason; exit; } function getObjects($selector){ } if($nommes[0][0] == 'a'){ //Command $fonction = strtoupper($nommes[0][1]); switch ($fonction){ case 'SET': /* SET selector attributeName value */ if(count($nommes) !== 4) exception('La fonction n\'a pas recu le bon nombre d\'arguments (4)'); if($nommes[1][0] !== '@') exception('Le deuxième argument doit etre un selecteur'); $objectsToSet=NULL; switch ($nommes[1][1][0]){ case 'Membre': $objectsToSet = Membre::getFromAttributes($nommes[1][1][1]); echo '
';
					print_r($objectsToSet);
					echo '
'; break; case 'Projet': //TODO add others class support break; case 'Version': break; case 'Discussion': break; case 'Message': break; default: exception('Unknown selector class :'.$nommes[1][1][0]); } if($nommes[2][0] !== 'a') exception('Le troisième paramètre doit etre une chaine de commande (chaine de caractères alphanumériques commensant par une lettre sans guillemets'); if($nommes[3][0] !== '"' and $nommes[3][0] !== '0' and $nommes[3][0] !== ':') exception('Le quatrième paramètre doit etre une variable (chaine de caractères entre guillemets, nombre ou variable de selecteur'); $attributeToSetName = $nommes[2][1]; $varToSet = $nommes[3]; //TODO add @Selector[]:var support foreach($objectsToSet as $objectToSet){ $objectToSet->setAttribute($attributeToSetName,$varToSet[1],$varToSet[0]); } echo 'SET the value '.$varToSet[1].' at attribute '.$attributeToSetName.' of '.count($objectsToSet).' objects'; break; case 'GET': /* GET selector */ if(count($nommes) !== 2) exception('La fonction n\'a pas recu le bon nombre d\'arguments (2)'); if($nommes[1][0] !== '@') exception('Le deuxième argument doit etre un selecteur'); $objectsToSet=NULL; switch ($nommes[1][1][0]){ case 'Membre': $objectsToSet = Membre::getFromAttributes($nommes[1][1][1]); break; case 'Projet': //TODO add others class support break; case 'Version': break; case 'Discussion': break; case 'Message': break; default: exception('Unknown selector class :'.$nommes[1][1][0]); } echo '
';
			print_r($objectsToSet);
			echo '
'; break; case 'DELETE': break; default: exception('Unknown function '.$fonction); } }