';
var $flagSystem = 'xml';
var $adressSystem = 'relative';
var $mXVersion = '1.2';
var $mXCacheDelay = 0;
var $debut = 0;
var $fin = 0;
var $ExecutionTime = 0;
var $mXcompress = false;
var $mXsetting = false;
var $mXmodRewrite = false;
var $performanceTracer = false;
var $mXoutput = false;
var $mXsignature = true;
var $isTemplateFile = true;
var $templateContent = array();
var $sheetBuilding = array();
var $deleted = array();
var $replacement = array();
var $loop = array();
var $IsALoop = array();
var $xPattern = array();
var $formField = array();
var $checker = array();
var $attribut = array();
var $attributKey = array();
var $htmlAtt = array();
var $select = array();
var $hidden = array();
var $image = array();
var $text = array();
var $father = array();
var $son = array();
var $plugInMethods = array();
var $flagArray = array(0 => 'hidden', 1 => 'select', 2 => 'image', 3 => 'text', 4 => 'checker', 5 => 'formField');
var $attributArray = array(0 => 'attribut');
//MX Generator----------------------------------------------------------------------------------------------------
//Constructeur de ModeliXe
// function ModeliXe ($template, $sessionParameter = '', $templateFileParameter = '', $cacheDelay = -1){
public function __construct($template, $sessionParameter = '', $templateFileParameter = '', $cacheDelay = -1){
// $this->ErrorManager();
parent::__construct();
$time = explode(' ',microtime());
$this->debut = $time[1] + $time[0];
//Gestion des paramètres par défaut
//Definition du systeme de compression
if (defined('MX_COMPRESS')) $this->SetMxCompress(MX_COMPRESS);
//Activation du mode rewrite
if (defined('MX_REWRITEURL')) $this->SetMxModRewrite(MX_REWRITEURL);
//Activation de la signature
if (defined('MX_SIGNATURE')) $this->SetMxSignature(MX_SIGNATURE);
//Définition du répertoire de template
if (defined('MX_TEMPLATE_PATH')) $this->SetMxTemplatePath(MX_TEMPLATE_PATH);
//Définition du fichier de paramétrage
if (defined('MX_DEFAULT_PARAMETER') && ! $templateFileParameter)
$this->SetMxFileParameter(MX_DEFAULT_PARAMETER);
elseif ($templateFileParameter != '')
$this->SetMxFileParameter($templateFileParameter);
//Définition du type de balisage
if (defined('MX_FLAGS_TYPE')) $this->SetMxFlagsType(MX_FLAGS_TYPE);
//Définition du type de balisage en sortie
if (defined('MX_OUTPUT_TYPE')) $this->SetMxOutputType(MX_OUTPUT_TYPE);
//Définition du répertoire de cache
if (defined('MX_CACHE_PATH')) $this->SetMxCachePath(MX_CACHE_PATH);
if (defined('MX_CACHE_DELAY')) $this->SetMxCacheDelay(MX_CACHE_DELAY);
if ($cacheDelay >= 0 && $cacheDelay != '') $this->SetMxCacheDelay($cacheDelay);
//Activation du traceur de performance
if (defined('MX_PERFORMANCE_TRACER') && MX_PERFORMANCE_TRACER == 'on') $this->performanceTracer = true;
//Gestion des paramètres de sessions
if ($sessionParameter) $this->sessionParameter = $sessionParameter;
//Instanciation de la ressource templates
if (@is_file($this->mXTemplatePath.$template)) $this->template = $template;
elseif (isset($template)) {
$this->template = $template;
$this->isTemplateFile = false;
}
else $this->ErrorTracker (5, 'No template file defined.', 'ModeliXe', __FILE__, __LINE__);
//Affectation du path d'origine
if ($this->ErrorChecker()) {
$this->absolutePath = substr(basename($this->template), 0, strpos(basename($this->template), '.'));
$this->relativePath = $this->absolutePath;
}
}
//Setting ModeliXe -------------------------------------------------------------------------------------------
//Méthode d'instanciation du template
function SetModelixe($out = ''){
if ($this->mXsetting) $this->ErrorTracker(4, 'You can\'t re-use this method after instanciate ModeliXe once time.', 'SetModelixe', __FILE__, __LINE__);
if ($out) $this->mXoutput = true;
//Test du cache et insertion éventuelle
if ($this->mXCacheDelay > 0){
$this->mXUrlKey = $this->GetMD5UrlKey();
if ($this->MxCheckCache())$this->MxGetCache();
}
//Initialisation de la classe
$this->GetMxFile();
if ($this->ErrorChecker()) $this->MxParsing($this->templateContent[$this->absolutePath]);
$this->mXsetting = true;
}
//Instanciation de la compression
function SetMxCompress($arg = ''){
if ($arg != 'on') $this->mXcompress = false;
else $this->mXcompress = true;
return $this->mXcompress;
}
//Instanciation du mode rewrite
function SetMxModRewrite($arg = ''){
if ($arg != 'on') $this->mXmodRewrite = false;
else $this->mXmodRewrite = true;
return $this->mXmodRewrite;
}
//Instanciation de la signature
function SetMxSignature($arg = ''){
if ($arg != 'on') $this->mXsignature = false;
else $this->mXsignature = true;
return $this->mXsignature;
}
//Instanciation du template path
function SetMxTemplatePath($arg = ''){
if ($this->mXsetting) $this->ErrorTracker(1, 'You can\'t use this method after instanciate ModeliXe with setModeliXe method, it will be without effects.', 'SetMxTemplatePath', __FILE__, __LINE__);
else {
if ($arg[strlen($arg) - 1] != '/' && $arg) $arg .= '/';
if (! is_dir($arg)) $this->ErrorTracker(5, 'The MX_TEMPLATE_PATH ('.$arg.') is not a directory.', 'SetMxTemplatePath', __FILE__, __LINE__);
else $this->mXTemplatePath = $arg;
}
return $this->mXTemplatePath;
}
//Instanciation du fichier de paramètre
function SetMxFileParameter($arg = ''){
if ($arg != '' && ! is_file($arg)) $this->ErrorTracker(1, 'The parameter\'s file path ('.$arg.') does not exist.', 'SetMxFileParameter', __FILE__, __LINE__);
else $this->mXParameterFile = $arg;
return $this->mXParameterFile;
}
//Instanciation du balisage du template
function SetMxFlagsType($arg){
if ($this->mXsetting) $this->ErrorTracker(1, 'You can\'t use this method after instanciate ModeliXe with setModeliXe method, it will be without effects.', 'SetMxFlagsType', __FILE__, __LINE__);
else {
switch (strtolower($arg)){
case 'classical':
$this->flagSystem = 'classical';
break;
case 'pear':
$this->flagSystem = 'classical';
break;
case 'xml':
$this->flagSystem = 'xml';
break;
default:
$this->ErrorTracker(2, 'This type of flag system ('.$arg.') is unrecognized.', 'SetMxFlagsType', __FILE__, __LINE__);
}
}
return $this->flagSystem;
}
//Instanciation du balisage de sortie
function SetMxOutputType($arg){
if ($this->mXsetting) $this->ErrorTracker(1, 'You can\'t use this method after instanciate ModeliXe with setModeliXe method, it will be without effects.', 'SetMxOutputType', __FILE__, __LINE__);
else {
switch (strtolower($arg)){
case 'xhtml':
$this->outputSystem = '/>';
break;
case 'html':
$this->outputSystem = '>';
break;
default:
$this->ErrorTracker(2, 'This type of output flag system ('.$arg.') is unrecognized.', 'SetMxOutputType', __FILE__, __LINE__);
}
}
return $arg;
}
//Instanciation du répertoire de cache
function SetMxCachePath($arg){
if ($this->mXsetting) $this->ErrorTracker(1, 'You can\'t use this method after instanciate ModeliXe with setModeliXe method, it will be without effects.', 'SetMxCachePath', __FILE__, __LINE__);
else {
if ($arg[strlen($arg) - 1] != '/') $arg .= '/';
if (! is_dir($arg) && $arg != '') $this->ErrorTracker(5, 'The MxCachePath ('.$arg.') is not a directory.', 'SetMxCachePath', __FILE__, __LINE__);
elseif ($arg) $this->mXCachePath = $arg;
}
return $this->mXCachePath;
}
//Instanciation du délai de cache
function SetMxCacheDelay($arg){
if ($this->mXsetting) $this->ErrorTracker(1, 'You can\'t use this method after instanciate ModeliXe with setModeliXe method, it will be without effects.', 'SetMxCachePath', __FILE__, __LINE__);
elseif ($arg >= 0) $this->mXCacheDelay = (integer)$arg;
return $this->mXCacheDelay;
}
//Instanciation des paramètres de session
function SetMxSession($arg){
$this->sessionParameter = $arg;
}
//Setting tools -----------------------------------------------------------------------------------------------
//Recherche du fichier de template
function GetMxFile($source = ''){
if (! $source) $source = $this->mXTemplatePath.$this->template;
if (! $read = @fopen($source, 'rb')) $this->ErrorTracker (3, 'Can\'t open this template file ('.$source.') in read, see for change the read modalities.', 'GetMxFile', __FILE__, __LINE__);
else {
if (! $result = @fread($read, filesize($source))) $this->ErrorTracker (3, 'Can\'t read the template file ('.$source.'), see for file format and integrity.', 'GetMxFile', __FILE__, __LINE__);
fclose($read);
}
/* Correction d'un bug : le bloc inclu était interprété comme un
commentaire HTML par certains navigateurs (testé avec Firefox 0.9) */
if (empty($result)) $result = '[no parsing, template file not found or invalid]';
if ($this->mXsignature && $source != $this->mXTemplatePath.$this->template) $result = "\n\n\n".$result."\n\n\n";
//Affectation du path d'origine, et du content du template
if ($source == $this->mXTemplatePath.$this->template) $this->templateContent[$this->absolutePath] = $result;
else return $result;
}
//Lecture du fichier de configuration et parsing
function GetParameterParsing ($template){
$ligne = '';
$signal = '';
if (! $read = @fopen($this->mXParameterFile, 'r')) $this->ErrorTracker(4, 'The mXParameterFile ('.$this->mXParameterFile.') can\'t be open, the first parsing can\'t be do.', 'GetParameterParsing', __FILE__, __LINE__);
for ($multi = false; !feof($read) && $this->ErrorChecker(); $ligne = trim(@fgets($read, 1200))){
if (strlen($ligne)) {
if ($ligne[0] == '#' && $ligne[1] != '#'){
//Changement d'état pour les paramètres
switch(strtolower($ligne)){
case '#flag' :
$signal = 'flag';
break;
case '#attribut' :
$signal = 'attribut';
break;
default :
$this->ErrorTracker(3, ''.$ligne.' is not a valid section parameter type', 'GetParameterParsing', __FILE__, __LINE__);
break;
}
}
else {
if($ligne[0] == '#') $ligne = substr($ligne,1);
if (! $multi){
$keyC = chop(substr($ligne, 0, strpos($ligne, '=') - 1));
//Gestion du multiligne, début d'une valeur sur plusieurs lignes
if (($content = ltrim(substr($ligne, strpos($ligne, '=') + 1))) && substr($content, 0, 3) == '"""') {
$multi = true;
$content = substr($content, 3);
}
}
//Gestion du multiligne, fin d'une valeur sur plusieurs lignes
else {
if (substr($ligne, strlen($ligne) - 3) == '"""') {
$multi = false;
$content .= ' '.substr($ligne, 0, strpos($ligne, '"""'));
}
else $content .= ' '.$ligne;
}
//Si nous ne sommes pas dans une valeur sur plusieurs lignes (valeur compléte)
if (! $multi){
switch ($this->flagSystem){
case 'xml':
$flagRegexp = '';
$attRegexp = 'mXpreformating="'.$keyC.'"';
break;
case 'classical':
$flagRegexp = '{preformating id="'.$keyC.'"}';
$attRegexp = '{preformatingAtt id="'.$keyC.'"}';
break;
}
if ($signal == 'flag') $template = str_replace($flagRegexp, $content, $template);
if ($signal == 'attribut') $template = str_replace($attRegexp, $content, $template);
}
}
}
}
if ($read) @fclose($read);
return $template;
}
//MX Builder-----------------------------------------------------------------------------------------
function MxBloc($index, $mod, $value = ''){
$mod = substr(strtolower($mod), 0, 4);
if ($this->adressSystem == 'relative') {
if ($index) $index = $this->relativePath.'.'.$index;
else $index = $this->relativePath;
}
else $index = $this->absolutePath.'.'.$index;
$fat = $this->father[$index];
if (! $fat && $index != $this->absolutePath) $this->ErrorTracker(2, 'The current path ('.$index.') does not exist, or was deleting, him or his father, before.', 'MxBloc', __FILE__, __LINE__);
switch ($mod){
//Looping
case 'loop':
$this->MxLoopBuilder($index);
break;
//Deleting
case 'dele':
$this->sheetBuilding[$index] = ' ';
$this->loop[$index] = '';
$this->deleted[$index] = true;
break;
//Concatenating
case 'appe':
if (@is_file($value)) $value = $this->GetMxFile($value);
$this->templateContent[$index] .= $value;
$this->MxParsing($value, $index, $this->father[$index]);
break;
//Replacing
case 'repl':
if (@is_file($value)) $value = $this->GetMxFile($value);
$this->sheetBuilding[$index] = $value;
$this->replacement[$index] = true;
break;
//Modify template references of this bloc
case 'modi':
$this->sheetBuilding[$index] = '';
$this->loop[$index] = '';
if (@is_file($value)) $value = $this->GetMxFile($value);
$this->templateContent[$index] = $value;
$this->MxParsing($value, $index, $this->father[$index]);
break;
//Reset, destroy all references
case 'rese':
$this->sheetBuilding[$index] = '';
$this->loop[$index] = '';
$this->templateContent[$index] = '';
$ind = substr($index, strrpos($index, '.') + 1);
$this->templateContent[$fat] = str_replace('', '', $this->templateContent[$fat]);
$this->deleted[$index] = true;
$this->xPattern['inclusion'][$index] = '';
break;
}
}
function MxFormField($index, $type, $name, $value, $attribut = '', $placeholder='', $special=''){
if ($this->adressSystem == 'relative') $index = $this->relativePath.'.'.$index;
$end = $this->outputSystem;
switch (strtolower($type)){
case 'text':
$replace = 'htmlAtt[$index].$end;
break;
case 'email':
$replace = 'htmlAtt[$index].$end;
break;
case 'password':
$replace = 'htmlAtt[$index].$end.$special;
break;
case 'textarea':
$replace = '';
break;
case 'file':
$replace = 'htmlAtt[$index].$end;
break;
case 'submit':
$replace = 'htmlAtt[$index].$end;
break;
case 'reset':
$replace = 'htmlAtt[$index].$end;
break;
case 'button':
$replace = 'htmlAtt[$index].$end;
break;
case 'image':
$replace = 'htmlAtt[$index].$end;
break;
case 'range':
//
$replace = 'htmlAtt[$index].$end;
break;
default:
$this->ErrorTracker(3, 'This type ('.$type.') is unknown for this formField manager.', 'MxFormField', __FILE__, __LINE__);
}
$this->formField[$index] = $replace;
}
function MxImage($index, $imag, $title = '', $attribut = '', $size = false){
if ($this->adressSystem == 'relative') $index = $this->relativePath.'.'.$index;
$end = $this->outputSystem;
// if (($ima = 'htmlAtt[$index].$end;
$this->image[$index] = $ima;
}
function MxText($index, $att){
if ($this->adressSystem == 'relative') $index = $this->relativePath.'.'.$index;
$this->text[$index] = $att;
}
function MxAttribut($index, $att){
if ($this->adressSystem == 'relative') $index = $this->relativePath.'.'.$index;
$marqueur = '';
//Gestion des mailto et des javascripts dans les href
if (strtolower($this->attributKey[$index]) == 'mailto' || strtolower($this->attributKey[$index]) == 'javascript') $marqueur = ' href="';
//Gestion multi-attributs
if (! ((isset($this->attribut[$index]))? chop($this->attribut[$index]): false) ) {
if ($marqueur) $this->attribut[$index] = $marqueur.$this->attributKey[$index].':'.$att.'"';
else $this->attribut[$index] = $this->attributKey[$index].'="'.$att.'"';
}
else {
if (empty($this->attribut[$this->attribut[$index]])) {
if ($marqueur) $this->attribut[$this->attribut[$index]] = ' '.$marqueur.$this->attributKey[$index].':'.$att.'"';
else $this->attribut[$this->attribut[$index]] = ' '.$this->attributKey[$index].'="'.$att.'"';
}
else {
if ($marqueur) $this->attribut[$this->attribut[$index]] .= $marqueur.$this->attributKey[$index].':'.$att.'"';
else $this->attribut[$this->attribut[$index]] .= ' '.$this->attributKey[$index].'="'.$att.'"';
}
}
}
function MxSelect($index, $name, $value, $arrayArg, $defaut = '', $multiple = '', $javascript = '', $attributes = '') {
if ($this->adressSystem == 'relative') $index = $this->relativePath.'.'.$index;
$sel = '';
if ($multiple && $multiple > 0) {
$attribut = 'size="'.$multiple.'" multiple="multiple" ';
$post = '[]';
}
else {
$attribut = '';
$post = '';
}
//Build of a select tag from an array
if (is_array($arrayArg)){
$sel = "\n".'