Découpage du traitement en ercore plus de classes
This commit is contained in:
+36
-208
@@ -1,224 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
include_once 'clazz/Zincluder.php';
|
||||
include_once 'clazz/Membre.class.php';
|
||||
include_once 'includes/bdd.php';
|
||||
|
||||
$me = new Membre();
|
||||
$me->connect();
|
||||
|
||||
if($me->isAdminLevelLowerThan(15)){
|
||||
if($me->getAdminLevel()<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;
|
||||
}elseif(!isset($_GET['action'])){
|
||||
echo 'Please set an action in the URL (GET method ,name:"action")';
|
||||
exit;
|
||||
}
|
||||
|
||||
function readAlphabetic($command){
|
||||
global $pos;
|
||||
$out = "";
|
||||
while (isAlphaNumeric($command[$pos])) {
|
||||
$out .= $command[$pos];
|
||||
$pos+=1;
|
||||
switch ($_GET['action']){
|
||||
|
||||
case 'set_discutionVisibility' :
|
||||
if(!isset($_POST['discutionVisibility'])){
|
||||
echo 'You must give a discution visibility (POST method,name:"discutionVisibility")';
|
||||
exit;
|
||||
}
|
||||
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;
|
||||
if(!isset($_POST['discutionID'])){
|
||||
echo 'You must give a discution ID (POST method,name:"discutionID")';
|
||||
exit;
|
||||
}
|
||||
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+5);
|
||||
$tPos = $pos;
|
||||
while ($tPos<$maxPos) {
|
||||
$reading .= $command[$pos];
|
||||
$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<strlen($command)) {
|
||||
echo $pos;
|
||||
$nomme = array();
|
||||
$type=$command[$pos];
|
||||
if(isAlphabetic($type)){
|
||||
$nomme[0] = 'a';
|
||||
$nomme[1] = readAlphabetic($command);
|
||||
}elseif (isNumeric($type)){
|
||||
$nomme[0] = '0';
|
||||
$nomme[1] = readNumeric($command);
|
||||
}elseif ($type === '"' or $type === '\''){
|
||||
$nomme[0] = '"';
|
||||
$nomme[1] = readString($command);
|
||||
}elseif (in_array($type,$operatorsChars,TRUE)){
|
||||
$nomme[0] = "=";
|
||||
$nomme[1] = readOperator($command);
|
||||
}elseif ($type === "@"){
|
||||
$nomme[0] = "@";
|
||||
$nomme[1] = readSelector($command);
|
||||
}
|
||||
elseif ($type === ' ')break;
|
||||
else error($pos, 'Unexpected char "'.$command[$pos].'" , cannot get the term type');
|
||||
$nommes[] = $nomme;
|
||||
$pos+=1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo '<pre>';
|
||||
print_r($nommes);
|
||||
echo '</pre>';
|
||||
|
||||
function exception($reason){
|
||||
echo 'An exception occurred : '.$reason;
|
||||
exit;
|
||||
}
|
||||
|
||||
if($nommes[0][0] == 'a'){
|
||||
//Command
|
||||
$fonction = strtoupper($nommes[0][1]);
|
||||
switch ($fonction){
|
||||
case 'SET':
|
||||
if(count($nommes) !== 42)
|
||||
exception('La fonction n\'a pas recu le bon nombre d\'arguments (42)');
|
||||
if($nommes[1][0] !== '@')
|
||||
exception('Le deuxième argument doit etre un selecteur');
|
||||
switch ($nommes[1][0][0]){
|
||||
case 'Membre':
|
||||
break;
|
||||
case 'Projet':
|
||||
break;
|
||||
case 'Membre':
|
||||
break;
|
||||
case 'Projet':
|
||||
break;
|
||||
case 'Membre':
|
||||
break;
|
||||
default:
|
||||
exception('Unknown selector class :'.$nommes[1][0][0]);
|
||||
}
|
||||
|
||||
case 'DELETE':
|
||||
|
||||
default:
|
||||
exception('Unknown function '.$fonction);
|
||||
|
||||
$discutionVisibility = $_POST['discutionVisibility'];
|
||||
$discutionID = $_POST['discutionID'];
|
||||
if ($discutionVisibility !== 'p' and preg_match ( "#^a[0-9]+$#",$discutionVisibility ) != 1 and preg_match ( '#^x([0-9]+;)*([0-9]+)?$#', $discutionVisibility ) != 1 ){
|
||||
echo 'Your discution visibility is not well-formed : it should have been formed like ("p" or "x31;41;59;26;53" or "a42")';
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET autorized=? WHERE ID=?');
|
||||
$req->execute(array($discutionVisibility,$discution));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
|
||||
default :
|
||||
echo 'Unknown action : '+$_GET['action'];
|
||||
exit;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user