1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
| if (!defined('AGUEST'))
exit("Safety error.");
//Initialisation de l'include_path
$os = ((stristr(getenv('SERVER_SOFTWARE'), 'win') || stristr(getenv('SERVER_SOFTWARE'), 'microsoft'))? ';' : ':');
$path = ((defined('MX_GENERAL_PATH'))? MX_GENERAL_PATH : '').$os.((defined('MX_ERROR_PATH'))? MX_ERROR_PATH : '').$os.ini_get('include_path');
//ini_set('include_path', $path);
//Inclusion du fichier de configuration et de Error Manager
if (file_exists($chem_modelixe.'Mxconf.php')){
require_once($chem_modelixe.'Mxconf.php');
require_once($chem_modelixe.'ErrorManager.php');
}
// Desactive les fonctions de protections des variables qui pourraient etre activees
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
if (get_magic_quotes_runtime())
set_magic_quotes_runtime(0);
unregister_globals();
}
class ModeliXe extends ErrorManager{
var $template = '';
var $absolutePath = '';
var $relativePath = '';
var $sessionParameter = '';
var $mXParameterFile = '';
var $mXTemplatePath = '';
var $mXCachePath = '$chem_cache';
var $mXUrlKey = '';
var $outputSystem = '/>';
var $flagSystem = 'xml';
var $adressSystem = 'relative';
var $mXVersion = '1.0';
var $mXCacheDelay = 0;
var $debut = 0;
var $fin = 0;
var $ExecutionTime = 0;
//par d�faut pas de cache
var $ok_cache = false;
var $mXcompress = false;
var $mXsetting = false;
var $mXmodRewrite = false;
var $performanceTracer = false;
var $mXoutput = false;
var $mXsignature = false;
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, $ok_cache = false, $chem_template = ''){
function __construct ($template, $sessionParameter = '', $templateFileParameter = '', $cacheDelay = -1, $ok_cache = false, $chem_template = ''){
$this -> ok_cache = $ok_cache;
if ($chem_template){
$this -> mXTemplatePath = $chem_template;
}
$this ->ErrorManager();
$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 (<b>'.$arg.'</b>) 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 (<b>'.$arg.'</b>) 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 (<b>'.$arg.'</b>) 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 (<b>'.$source.'</b>) 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 (<b>'.$source.'</b>), see for file format and integrity.', 'GetMxFile', __FILE__, __LINE__);
fclose($read);
}
if (empty($result)) $result = '[no parsing, template file not found or invalid]';
if ($this -> mXsignature && $source != $this -> mXTemplatePath.$this -> template) $result = "\n<!--[ModeliXe ".$this -> mXVersion.']-- [StartOf'.$dyn.'Inclusion : '.$source."] -->\n\n".$result."\n\n<!--[ModeliXe ".$this -> mXVersion.']-- [EndOf'.$dyn.'Inclusion : '.$source."] -->\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 (<b>'.$this -> mXParameterFile.'</b>) 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, '<b>'.$ligne.' </b> 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 = '<mx:preformating id="'.$keyC.'"/>';
$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 (<b>'.$index.'</b>) 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('<mx:inclusion id="'.$ind.'"/>', '', $this -> templateContent[$fat]);
$this -> deleted[$index] = true;
$this -> xPattern['inclusion'][$index] = '';
break;
}
}
function MxFormField($index, $type, $name, $value, $attribut = ''){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$end = $this -> outputSystem;
switch (strtolower($type)){
case 'text':
$replace = '<input type="text" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'password':
$replace = '<input type="password" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'textarea':
$replace = '<textarea name="'.$name.'" '.$attribut.' '.$this -> htmlAtt[$index].' >'.$value.'</textarea>';
break;
case 'file':
$replace = '<input type="file" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'submit':
$replace = '<input type="submit" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'reset':
$replace = '<input type="reset" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'button':
$replace = '<input type="button" name="'.$name.'" value="'.$value.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
case 'image':
$replace = '<input type="image" name="'.$name.'" '.$attribut.' '.$this -> htmlAtt[$index].$end;
break;
default:
$this -> ErrorTracker(3, 'This type (<b>'.$type.'</b>) 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 = '<img src="'.$imag.'"') && ! $size) {
$size = @getimagesize($imag);
$ima .= ' '.$size[3];
}
if ($title == 'no') $ima .= ' ';
elseif ($title) $ima .= ' alt="'.$title.'" ';
else $ima .= ' alt="no title - source : '.basename($imag).'" ';
if ($attribut) $ima .= $attribut;
$ima .= ' '.$this -> 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 = '') {
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".'<select name="'.$name.$post.'" ';
if ($attribut) $sel .= $attribut.' ';
if ($javascript) $sel .= $javascript;
$sel .= ' '.$this -> htmlAtt[$index].' '.">\n";
if (isset($defaut) && $defaut) $sel .= "\t".'<option value="#">'.$defaut.'</option>'."\n";
$debut = 0;
$fin = count($arrayArg);
reset($arrayArg);
while (list($cle, $Avalue) = each($arrayArg)){
$test = 0;
//Build of multiple choice select from a value array
if (is_array($value) && $multiple > 0){
reset($value);
while (list($Vcle, $Vvalue) = each($value)){
if ($cle == $Vvalue && $Vvalue != '') {
$sel .= "\t".'<option value="'.$cle.'" selected="selected">'.$Avalue.'</option>'."\n";
$test = 1;
break;
}
}
if ($test == 0) $sel .= "\t".'<option value="'.$cle.'">'.$Avalue.'</option>'."\n";
}
//Simple select
else {
if ($value != '' && $cle == $value) $sel .= "\t".'<option value="'.$cle.'" selected="selected">'.$Avalue.'</option>'."\n";
else $sel .= "\t".'<option value="'.$cle.'">'.$Avalue.'</option>'."\n";
}
}
}
else {
$this -> ErrorTracker(2, 'This function need an Array in fourth argument to build the select <b>'.$index.'</b>.', 'MxSelect', __FILE__, __LINE__);
$sel = '<select name="'.$name.'">'."\n\t".'<option value="null">No record found</option>'."\n";
}
$sel .= '</select>';
$this -> select[$index] = $sel;
}
function MxUrl($index, $urlArg, $param = '', $noSid = false, $attribut = '') {
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$ok = false;
//Ajout des param�tres de sessions en cas de cache ou non
if ($this -> sessionParameter && ! $noSid) {
if ($this -> mXCacheDelay > 0) $urlArg .= '?<mx:session />';
else $urlArg .= '?'.$this -> sessionParameter;
$ok = true;
}
//Construction du lien
if (is_string($param) && $param) {
$param = explode('&',$param);
for($i = 0; $i < count($param) && $param[$i]; $i++){
$cle = explode('=', $param[$i]);
if (! $this -> mXmodRewrite) $urlArg .= ($i == 0 && !$ok) ? '?'.urlencode($cle[0]).'='.urlencode($cle[1]) : '&'.urlencode($cle[0]).'='.urlencode($cle[1]);
else $urlArg .= '/'.urlencode($cle[0]).'/'.urlencode($cle[1]);
}
}
elseif (is_array($param)){
reset($param);
if ($this->mXmodRewrite) {
while (list($cle, $valeur) = each($param)) {
$urlArg .= '/'.urlencode($cle).'/'.urlencode($valeur);
}
}
else {
while (list($cle, $valeur) = each($param)) {
if (!$ok) {
$urlArg .= '?'.urlencode($cle).'='.urlencode($valeur);
$ok = true;
}
else $urlArg .= '&'.urlencode($cle).'='.urlencode($valeur);
}
}
}
elseif ($param) $this -> ErrorTracker(3, 'The third argument must be a queryString or an array.', 'MxUrl', __FILE__, __LINE__);
//Ajout d'�ventuels attributs suppl�mentaires en dynamique
$lien = ($attribut)? ' href="'.$urlArg.'" '.$attribut : ' href="'.$urlArg.'"';
//Gestion multi-attributs
if (! ((isset($this -> attribut[$index]))? chop($this -> attribut[$index]): false)) $this -> attribut[$index] = ' href="'.$urlArg.'"';
else {
if (empty($this -> attribut[$this -> attribut[$index]])) $this -> attribut[$this -> attribut[$index]] = ' href="'.$urlArg.'"';
else $this -> attribut[$this -> attribut[$index]] .= ' href="'.$urlArg.'"';
}
}
function MxHidden ($index, $param){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$end = $this -> outputSystem;
$hidden = '';
if ($this -> mXCacheDelay == 0 && $this -> sessionParameter) $param .= '&'.$this -> sessionParameter;
if (is_string($param)) $param = explode('&',$param);
else $this -> ErrorTracker(3,'The second argument must be a queryString.', 'MxHidden', __FILE__, __LINE__);
if (! empty($param)){
for($i = 0; $i < count($param); $i++){
if ($param[$i]) {
$cle = explode('=', $param[$i]);
$hidden .= '<input type="hidden" name="'.$cle[0].'" value="'.$cle[1].'" '.$end."\n";
}
}
}
if ($this -> mXCacheDelay > 0) $hidden .= '<mx:hiddenSession />';
$this -> hidden[$index] = $hidden;
}
function MxCheckerField($index, $type, $name, $value, $checked = false, $attribut = ''){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$end = $this -> outputSystem;
$type = strtolower($type);
if ($type != "checkbox" && $type != "radio") $this -> ErrorTracker(2, 'This type (<b>'.$type.'</b>) is unknown for this CheckerField manager.', 'MxCheckerField', __FILE__, __LINE__);
$replace = '<input type="'.$type.'" name="'.$name.'" value="'.$value.'"';
if ( $checked ) $replace .= ' checked="checked"';
if ($attribut) $replace .= ' '.$attribut;
$replace .= ' '.$this -> htmlAtt[$index].$end;
$this -> checker[$index] = $replace;
}
//MX Extender----------------------------------------------------------------------------------------
function AddMxPlugIn($name, $type, $fonction){
if (! $name) $this -> ErrorTracker(2, 'You must give a name to identify the plug-in.', 'AddMxPlugIn',__FILE__, __LINE__);
if (! $type) $this -> ErrorTracker(2, 'The type of the plug-in is necessary to instanciate it.', 'AddMxPlugIn', __FILE__, __LINE__);
if (! $fonction || ! function_exists($fonction)) $this -> ErrorManager(3, 'The method addMxPlugin need the name of a function in third argument.', 'AddMxPlugIn',__FILE__, __LINE__);
if ($this -> ErrorChecker()){
switch ($type){
case 'flag':
for ($i = 0; $i < count($this -> flagArray); $i++){
if ($name == $this -> flagArray[$i]) $this -> ErrorTracker(2, 'This plug-in (<b>'.$name.'</b>) has got the same pattern as the native pattern of a ModeliXe flag.', 'AddMxPlugIn', __FILE__, __LINE__);
}
$this -> flagArray[count($this -> flagArray)] = $name;
break;
case 'attribut':
for ($i = 0; $i < count($this -> attributArray); $i++){
if ($name == $this -> attributArray[$i]) $this -> ErrorTracker(2, 'This plug-in (<b>'.$name.'</b>) has got the same pattern as the native pattern of a ModeliXe attribut.', 'AddMxPlugIn', __FILE__, __LINE__);
}
$this -> attributArray[count($this -> attributArray)] = $name;
break;
default :
$this -> ErrorTracker(2, 'This type of plug-in (<b>'.$type.'</b>) is unrecognized.', 'AddMxPlugIn', __FILE__, __LINE__);
}
}
$this -> $name = array();
$this -> plugInMethods[$name] = $fonction;
}
function SetMxPlugIn($name, $index, $arguments){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
if (isset($arguments) && ! is_array($arguments)) $this -> ErrorTracker(2, 'You must give an array of arguments for the plug-in function.', 'SetMxPlugIn', __FILE__, __LINE__);
else {
$tab = &$this -> $name;
$tab[$index] = call_user_func($this -> plugInMethods[$name], $arguments);
}
}
//MX tools -------------------------------------------------------------------------------------------------------------------
//V�rifie l'existence d'un bloc
function IsMxBloc($index){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$fat = $this -> father[$index];
if (! $fat && $index != $this -> absolutePath) return false;
else return true;
}
//V�rifie l'existence d'une balise
function IsMxFlag($index, $type){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
$tab = $this -> $type;
if (! isset($tab[$index])) return false;
else return $tab[$index];
}
//V�rifie l'existence d'un attribut
function IsMxAttribut($index){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
if (! isset($this -> attributKey[$index])) return false;
else {
if (preg_match('/;/', $this -> attribut[$index])) return $this -> attribut[$this -> attribut[$index]];
else return $this -> attribut[$index];
}
}
//Retourne tout le contenu d'un bloc
function GetMxBloc($index){
if ($this -> adressSystem == 'relative') $index = $this -> relativePath.'.'.$index;
if ($this -> sheetBuilding[$index]) return $this -> sheetBuilding[$index];
else return $this -> templateContent[$index];
}
//Construction d'une queryString
function GetQueryString($keyString, $null = 1){
$queryString = array();
if (is_array($keyString)){
reset($keyString);
while (list($Akey, $value) = each($keyString)){
if (is_array($value)) {
while (list($k, $v) = each($value)) {
array_push($queryString, urlencode($Akey.'['.$k.']').'='.urlencode($v));
}
}
elseif ($null || strlen($value)) array_push($queryString, urlencode($Akey).'='.urlencode($value));
}
return implode('&',$queryString);
}
else $this -> ErrorTracker(3, 'The argument for this function must be an associative array.', 'GetQueryString', __FILE__, __LINE__);
}
//Adressage simplifi�
function WithMxPath($path = '', $origine = ''){
if (! $origine) $origine = $this -> adressSystem;
else {
switch($origine){
case 'relative':
break;
case 'absolute':
break;
default:
$origine = 'relative';
break;
}
}
//Si on ne pr�cise pas de path on retourne au path origine
if (empty($path)){
$this -> relativePath = $this -> absolutePath;
if ($origine == 'absolute') $this -> adressSystem = 'absolute';
elseif ($origine == 'relative') $this -> adressSystem = 'relative';
}
//Sinon, en absolu on se situe dans ce path, en relatif on se situe par rapport au path relatif
if ($path) {
if ($origine == 'relative') {
//On redescend dans la hi�rarchie jusqu'au path mentionn�
if (($test = explode('../', $path)) && count($test) > 1) {
$path = substr($path, strrpos($path, '/') + 1);
$this -> relativePath = substr($this -> relativePath, 0, strlen($this -> relativePath) - strlen(strstr($this -> relativePath, $path)) - 1);
if (! $this -> relativePath) $this -> ErrorTracker(3, 'This path (<b>'.$path.'</b>) does not exist, ModeliXe can\'t build relativePath.', 'WithMxPath', __FILE__, __LINE__);
}
$this -> relativePath .= '.'.$path;
$this -> adressSystem = 'relative';
}
elseif ($origine == 'absolute') {
$this -> relativePath = $path;
$this -> adressSystem = 'absolute';
}
}
}
//Informations de licence
function AboutModeliXe($out = ''){
$texte = "\nLicence et conditions d'utilisations-----------------------------------------------------------------------------\n";
$texte .= 'ModeliXe '.$this -> mXVersion."\nModeliXe est distribu� sous licence LGPL, merci de laisser cette en-t�te, gage et garantie de cette licence.\n";
$texte .= "ModeliXe est un moteur de template destin� � �tre utilis� par des applications �crites en PHP.\n";
$texte .= " \n";
$texte .= "Copyright(c) 26 Juin 2001 - ANDRE Thierry (aka Th�o)\n";
$texte .= " \n";
$texte .= "Pour tout renseignements mailez � <a href="mailto:modelixe@free.fr">modelixe@free.fr</a> ou <a href="mailto:thierry.andre@freesbee.fr">thierry.andre@freesbee.fr</a>\n";
$texte .= "------------------------------------------------------------------------------------------------------------------\n";
if ($out) return $texte;
else print('<pre>'.$texte.'</pre>');
}
//Num�ro de version
function GetMxVersion(){
return $this -> mXVersion;
}
//Rafraichissement
function MxRefresh($query = ''){
$this -> MxClearCache('this', $query);
}
function MxRefreshAll() {
$this -> MxClearCache();
}
//Mesure de performances
function GetExecutionTime(){
$time = explode(' ',microtime());
$fin = $time[1] + $time[0];
$this -> ExecutionTime = intval(10000 * ((double)$fin - (double)$this -> debut)) / 10000;
return($this -> ExecutionTime);
}
//MX Parsing Engine------------------------------------------------------------------------------------------------------------
function MxParsing($doc = '', $path = '', $father = ''){
$countPath = Array();
//Initialisation
if (! $path) {
$original = true;
$path = $this -> absolutePath;
}
else $original = false;
$this -> father[$path] = $father;
$this -> IsALoop[$path] = false;
//Parsing des balises de bloc, extraction des sous blocs
$ok = true;
switch ($this -> flagSystem){
case 'xml':
$blocRegexp = '/<mx:bloc(?:[ ]+ref="([^"]+)")?[ ]+id="([^"]+)"[ ]*>/S';
break;
case 'classical':
$blocRegexp = '/{start(?:[ ]+ref="([^"]+)")?[ ]+id="([^"]+)"[ ]*}/S';
break;
}
if (preg_match_all($blocRegexp, $doc, $inclusion)){
for($i = 0; $ok; $i++){
//Extraction des diff�rentes informations extraites par la regex
$id = $inclusion[2][0];
$ref = $inclusion[1][0];
$pattern = $inclusion[0][0];
//Calcul des limites du bloc trait�
switch ($this -> flagSystem){
case 'xml':
$regexp = '</mx:bloc id="'.$id.'">';
break;
case 'classical':
$regexp = '{end id="'.$id.'"}';
break;
}
$startOfIntrons = strpos($doc, $pattern) + strlen($pattern);
$endOfIntrons = strpos($doc, $regexp);
$length = $endOfIntrons - $startOfIntrons;
if (! $endOfIntrons) $this -> ErrorTracker(4, 'The end of the "<b>'.$id.'</b>" bloc is not found, this bloc can\'t be generate. Verify that the end of bloc\'s flag exists and has a good form, like this pattern <b>'.htmlentities($regexp).'</b>.', 'MxParsing', __FILE__, __LINE__);
//On teste si le bloc en cours poss�de une r�f�rence vers un autre template
if (! $ref) $this -> templateContent[$path.'.'.$id] = substr($doc, $startOfIntrons, $length);
else {
if ($this -> mXTemplatePath) $ref = $this -> mXTemplatePath.$ref;
$this -> templateContent[$path.'.'.$id] = $this -> GetMxFile($ref);
}
//Cr�ation du pattern du bloc trait�
$this -> xPattern['inclusion'][$path.'.'.$id] = '<mx:inclusion id="'.$id.'"/>';
$this -> deleted[$path.'.'.$id] = false;
$this -> replacement[$path.'.'.$id] = false;
//Extraction du contenu du bloc pour reconstruire le bloc en cours
$doc = substr($doc, 0, $startOfIntrons - strlen($pattern)).'<mx:inclusion id="'.$id.'"/>'.substr($doc, $endOfIntrons + strlen($regexp));
$this -> templateContent[$path] = $doc;
//Construction de la r�f�rence � ce bloc pour la r�cursivit�
$countPath[$i] = $path.'.'.$id;
//Incr�mentation du nbre de fils pour le bloc en cours
if (! empty($this -> son[$path][0])) $compt = $this -> son[$path][0];
else {
$compt = 0;
$this -> son[$path][0] = 0;
}
//Construction de la r�f�rence au fils du bloc pars� pour le bloc en cours
$this -> son[$path][++ $compt] = $path.'.'.$id;
$this -> son[$path][0] ++;
//Test de fin de boucle
$ok = preg_match_all($blocRegexp, $doc, $inclusion);
}
}
//Parsing des balises ModeliXe
reset($this -> flagArray);
while (list($Akey, $value) = each($this -> flagArray)){
switch ($this -> flagSystem){
case 'xml':
$regexp = '/<mx:'.$value.'(?:[ ]+(?:ref|info)="(?:[^"]+)")?[ ]+id="([^"]+)"(([^>])*(?=\/>))\/>/S';
break;
case 'classical':
$regexp = '/{'.$value.'(?:[ ]+(?:ref|info)="(?:[^"]+)")?[ ]+id="([^"]+)"[ ]*(?i:htmlAtt\[([^\]]*)\])?}/S';
break;
}
if (preg_match_all($regexp, $doc, $flag)){
for ($i = 0; ; $i++){
if (empty ($flag[0][$i])) break;
//Construction du pattern et des valeurs par d�faut de ces balises
$this -> xPattern[$value][$path.'.'.$flag[1][$i]] = $flag[0][$i];
//Modification Guillaume Lelarge compatibilit� PHP3
/*<PHP3>
$ref = $this -> $value;
$ref[$path.'.'.$flag[1][$i]] = ' ';
$this -> $value = $ref;
$this -> htmlAtt[$path.'.'.$flag[1][$i]] = $flag[2][$i];
</PHP3>*/
$ref = &$this -> $value;
$ref[$path.'.'.$flag[1][$i]] = ' ';
$this -> htmlAtt[$path.'.'.$flag[1][$i]] = $flag[2][$i];
}
}
}
//Parsing des attributs de ModeliXe
switch ($this -> flagSystem){
case 'xml':
$regexp = '/mXattribut="([^"]{3,})"/Si';
$separateur = ':';
break;
case 'classical':
$regexp = '/{attribut ([^\}]+)}/Si';
$separateur = '=';
break;
}
if (preg_match_all($regexp, $doc, $flag)){
for ($i = 0, $k = 0; ; $i++){
if (empty($flag[0][$i])) break;
$pattern = $flag[0][$i];
$motif = $flag[1][$i];
$k = 0;
//Gestion de plusieurs couples de cl�-valeurs dans les attributs
$tabVal = explode(';', $motif);
for ($j = 0; $j < count($tabVal); $j++) {
$tabCle = explode($separateur, trim($tabVal[$j]));
$patternKey[++ $k] = trim($tabCle[0]);
$indexValue[$k] = trim($tabCle[1]);
//Gestion multi-attributs
if (count($tabVal) > 1) {
$this -> attribut[$path.'.'.$indexValue[$k]] = $path.'.'.$indexValue[1].';';
if ($k == 1) $this -> xPattern['attribut'][$path.'.'.$indexValue[1].';'] = $pattern;
}
else {
$this -> attribut[$path.'.'.$indexValue[$k]] = ' ';
$this -> xPattern['attribut'][$path.'.'.$indexValue[$k]] = $pattern;
}
if ($patternKey[$k] != 'url') $this -> attributKey[$path.'.'.$indexValue[$k]] = $patternKey[$k];
}
}
}
for ($i = 0; $i < count($countPath); $i++) $this -> MxParsing($this -> templateContent[$countPath[$i]], $countPath[$i], $path);
}
//MX Compression System ------------------------------------------------------------------------------------------------------------------
//V�rifie si la compression est possible et son type
function MxCheckCompress($file){
if((! $this -> mXcompress) || (! extension_loaded("zlib")) || (headers_sent()) || (strlen($file) / 1000 < 8)) return false;
global $HTTP_SERVER_VARS;
if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'x-gzip')) return "x-gzip";
if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) return "gzip";
return false;
}
//Compression des donnees destin�es au navigateur
function MxSetCompress($filecontent){
if ($encoding = $this -> MxCheckCompress($filecontent)){
header('Content-Encoding: '.$encoding);
$gzfilecontent = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$size = strlen($filecontent);
$crc32 = crc32($filecontent);
$gzfilecontent .= gzcompress($filecontent, 9);
$gzfilecontent = substr($gzfilecontent, 0, strlen($gzfilecontent) - 4);
$gzfilecontent .= pack('V',$crc32);
$gzfilecontent .= pack('V',$size);
return $gzfilecontent;
}
else return $filecontent;
}
//MX Cache system ------------------------------------------------------------------------------------------------------------------
//Retourne une cl� unique pour les arguments en POST et GET diff�rents des param�tres de session
function GetMD5UrlKey($query = ''){
global $HTTP_POST_VARS, $HTTP_GET_VARS;
if (! $query) $get = $HTTP_GET_VARS;
else $get = $query;
if (! $query) $post = $HTTP_POST_VARS;
else $post = $query;
//Int�gration du nom du fichier php appelant
$uri = getenv('REQUEST_URI');
$uri = substr($uri, 0, strpos($uri, '?'));
//Suppression des param�tres de session en GET
$chaine = '';
$this -> DeleteSessionKey($chaine, $get);
//Suppression des param�tres de session en POST
$this -> DeleteSessionKey($chaine, $post);
return (md5($chaine.$uri));
}
function DeleteSessionKey(&$chaine, $httpvar){
$param = explode('&', $this -> sessionParameter);
//Tri des tableaux pour les avoir dans le m�me ordre
if (is_array($httpvar))
asort($httpvar);
if (is_array($param))
asort($param);
//pr est un marqueur pour �viter de parcourir toutes les valeurs des param de session si ceux-ci ont d�ja �t� tous supprim�s
$pr = 0;
//suppression des param�tres de session(get ou post)
for (@reset($httpvar); $cle = @key($httpvar); @next($httpvar)){
$ok = false;
$compt = count($param);
for ($i = 0; $i < $compt && ($pr != $compt); $i++){
if (($cleU = explode('=', $param[$i])) && $cleU[0] == $cle) {
$ok = true;
$pr ++;
break;
}
}
if (! $ok) $chaine .= $cle.'='.$httpvar[$cle];
}
}
//Vidage du cache
function MxClearCache($fich = '', $query = ''){
if (! $open = @opendir($this -> mXCachePath)) $this -> ErrorTracker(3, 'Can\'t open cache directory (<b>'.$this -> mXCachePath.'</b>) to clear old files.', 'MxClearCache', __FILE__, __LINE__);
else {
while ($fichier = @readdir($open)){
if ($fichier != '.' && $fichier != '..'){
if (! $fich){
if (($currentTime = filemtime($this -> mXCachePath.$fichier)) && time() - $currentTime > $this -> mXCacheDelay) {
if (! @unlink($this -> mXCachePath.$fichier)) $this -> ErrorTracker(3, 'Can\'t unlink this file "<b>'.$fichier.'</b>" in cache directory.', 'MxClearCache', __FILE__, __LINE__);
}
}
else {
//Supprime sp�cifiquement le fichier du template en cours
$ana = explode('~', $fichier);
if ($ana[1] == $this -> template) {
//Gestion des suppressions sp�cifiques � une queryString
if ($query && $this -> GetMD5UrlKey($query) == $ana[0]){
if (! @unlink($this -> mXCachePath.$fichier)) $this -> ErrorTracker(3, 'Can\'t unlink this file "<b>'.$fichier.'</b>" in cache directory.', 'MxClearCache', __FILE__, __LINE__);
}
elseif (! @unlink($this -> mXCachePath.$fichier)) $this -> ErrorTracker(3, 'Can\'t unlink this file "<b>'.$fichier.'</b>" in cache directory.', 'MxClearCache', __FILE__, __LINE__);
}
}
}
}
@closedir($open);
}
}
//Initialisation du cache
function MxSetCache($filecontent) {
if ($this -> ok_cache){
$this -> MxClearCache('this');
if (! $cache = fopen($this -> mXCachePath.$this -> mXUrlKey.'~'.$this -> template, 'w')) $this -> ErrorTracker(4, 'Can\'t open in writing the cache file on "<b>'.$this -> mXCachePath.'/'.$this -> template.'</b>" path.', 'MxSetCache', __FILE__, __LINE__);
//Sauvegarde du contenu
if ($this -> ErrorChecker()) {
if (! $write = fputs($cache, $filecontent)) $this -> ErrorTracker(5, 'Can\'t wite the cache file on "<b>'.$this -> mXCachePath.$this -> mXUrlKey.'~'.$this -> template.'</b>" path.', 'MxSetCache', __FILE__, __LINE__);
@fclose($cache);
}
}
}
//Retourne le fichier de cache
function MxGetCache() {
$cache_file = $this -> mXCachePath.$this -> mXUrlKey.'~'.$this -> template;
if (! $open = @fopen($cache_file, 'rb')) $this -> ErrorTracker(5, 'Can\'t open the cache file on "<b>'.$cache_file.'</b>" path.', 'MxGetCache');
if (! $read = @fread($open, filesize($cache_file))) $this -> ErrorTracker(5, 'Can\'t read the cache file on "<b>'.$cache_file.'</b>" path.', 'MxGetCache', __FILE__, __LINE__);
@fclose($open);
//Parsing des param�tres de sessions
$read = $this -> MxSessionParameterParsing($read);
//Si on cherche � mesurer les performances de ModeliXe
if ($this -> performanceTracer) {
$read = str_replace('<mx:performanceTracer />', $this -> GetExecutionTime().' [cache]', $read);
}
//Si il y a une gestion de la compression, envoie des en-t�tes correspondantes
$this -> ErrorChecker();
if ($this -> mXoutput) return $read;
else print($this -> MxSetCompress($read));
exit();
}
//Teste si le fichier de cache existe et son �ch�ance
function MxCheckCache() {
$cache_file = $this -> mXCachePath.$this -> mXUrlKey.'~'.$this -> template;
if (@is_file($cache_file)){
if (($currentTime = filemtime($cache_file)) && (((time() - $currentTime) < $this -> mXCacheDelay && filemtime($this -> mXTemplatePath.$this -> template) < $currentTime))) return true;
}
else return false;
}
//MX Template Fusion Engine --------------------------------------------------------------------------------------------------
function MxSessionParameterParsing($content) {
$hidden = '';
$param = $this -> sessionParameter;
if ($param){
$content = str_replace('<mx:session />', $param, $content);
$param = explode('&', $this -> sessionParameter);
for($i = 0; $i < count($param); $i++){
if ($param[$i]) {
$cle = explode('=', $param[$i]);
$hidden .= '<input type="hidden" name="'.$cle[0].'" value="'.$cle[1].'" />'."\n";
}
}
$content = str_replace('<mx:hiddenSession />', $hidden, $content);
}
return $content;
}
//Remplace le contenu des templates pass�s en arguments
function MxReplace($path){
if (! empty($this -> sheetBuilding[$path])) $cible = $this -> sheetBuilding[$path];
else $cible = $this -> templateContent[$path];
//Remplacement de l'ensemble des attributs ModeliXe par les valeurs qui ont �t� instanci�es ou leurs valeurs par d�faut
reset($this -> attributArray);
while (list($cle, $Fkey) = each($this -> attributArray)){
$Farray = &$this -> $Fkey;
if (is_array($Farray)){
reset($Farray);
while (list($Pkey, $value) = each($Farray)){
if ($path == substr($Pkey, 0, strrpos($Pkey, '.'))) {
if (isset($this -> xPattern[$Fkey][$Pkey])){
$pattern = $this -> xPattern[$Fkey][$Pkey];
$cible = str_replace($pattern, $value, $cible);
unset($Farray[$Pkey]);
}
}
}
}
}
//Remplacement de l'ensemble des balises ModeliXe par les valeurs qui ont �t� instanci�es ou leurs valeurs par d�faut
reset($this -> flagArray);
while (list($cle, $Fkey) = each($this -> flagArray)){
$Farray = &$this -> $Fkey;
if (is_array($Farray)){
reset($Farray);
while (list($Pkey, $value) = each($Farray)){
if ($path == substr($Pkey, 0, strrpos($Pkey, '.'))) {
if (isset($this -> xPattern[$Fkey][$Pkey])){
$pattern = $this -> xPattern[$Fkey][$Pkey];
$cible = str_replace($pattern, $value, $cible);
unset($Farray[$Pkey]);
}
}
}
}
}
return $cible;
}
//Construit les blocs et associe les blocs fils aux blocs parents
function MxBlocBuilder($path = ''){
$ordre = array();
$hierarchie = 1;
if (! $path) $path = $this -> absolutePath;
$chemin = $path;
//Classement de tout les fils de path du plus proche au plus lointain
$base = count(explode('.', $path));
$k = 1;
$l = 1;
$j = 1;
for (; ;){
//Si il existe un fils on le prend
if (! empty($this -> son[$chemin][$j])) $fils = $this -> son[$chemin][$j];
else $fils = '';
//Si il existe on consid�re le dernier enregistrement trouv� pr�c�dant celui-ci
if (! empty($ordre[$hierarchie])) $ancien = $ordre[$hierarchie][count($ordre[$hierarchie])];
else $ancien = false;
if ($fils == $ancien) break;
//Si il n'y a plus de fils, on passe au noeud suivant
if (empty($fils)) {
$j = 1;
if (! empty($ordre[$k][$l])) {
$chemin = $ordre[$k][$l];
$l ++;
}
else {
$l = 1;
$k ++;
if (! empty($ordre[$k][$l])) $chemin = $ordre[$k][$l ++];
else break;
}
}
else {
$j ++;
//Si le fils n'a pas �t� d�truit on le consid�re
if ($this -> templateContent[$fils]) {
//hi�rarchie compte le nombre de blocs � partir du bloc de base
$hierarchie = count(explode('.', $fils)) - $base;
if (empty($ordre[$hierarchie])) $ordre[$hierarchie] = array();
$ordre[$hierarchie][count($ordre[$hierarchie]) + 1] = $fils;
}
}
}
//Insertion des fils les plus lointains dans les fils les plus proches jusqu'au path
for ($i = count($ordre); $i > 0; $i --){
for ($j = 1; $j <= count($ordre[$i]); $j++){
$fils = $ordre[$i][$j];
$pattern = $this -> xPattern['inclusion'][$fils];
$pere = $this -> father[$ordre[$i][$j]];
//Insertion du bloc fils dans le p�re
if ($pere == $path && $this -> IsALoop[$path]) {
if ($this -> IsALoop[$fils]) {
if ($this -> deleted[$fils]) {
$rem = ' ';
$this -> deleted[$fils] = false;
}
else $rem = $this -> loop[$fils];
$this -> loop[$pere] = str_replace($pattern, $rem, $this -> loop[$pere]);
$this -> loop[$fils] = '';
}
else {
if ($this -> deleted[$fils]) {
$rem = ' ';
$this -> deleted[$fils] = false;
}
else $rem = $this -> MxReplace($fils);
$this -> loop[$pere] = str_replace($pattern, $rem, $this -> loop[$pere]);
$this -> sheetBuilding[$fils] = '';
}
}
else {
if (! empty($this -> sheetBuilding[$pere])) $source = $this -> sheetBuilding[$pere];
else $source = $this -> templateContent[$pere];
if ($this -> IsALoop[$fils]) {
if ($this -> deleted[$fils]) {
$rem = ' ';
$this -> deleted[$fils] = false;
}
else $rem = $this -> loop[$fils];
$this -> sheetBuilding[$pere] = str_replace($pattern, $rem, $source);
$this -> loop[$fils] = '';
}
else {
if ($this -> deleted[$fils]) {
$rem = ' ';
$this -> deleted[$fils] = false;
}
else $rem = $this -> MxReplace($fils);
$this -> sheetBuilding[$pere] = str_replace($pattern, $rem, $source);
$this -> sheetBuilding[$fils] = '';
}
}
}
}
}
//Associe les boucles
function MxLoopBuilder($path = ''){
if (! $path) $path = $this -> absolutePath;
$father = $this -> father[$path];
$pattern = $this -> xPattern['inclusion'][$path];
//On saute les blocs d�truits
if ($pattern){
$this -> IsALoop[$path] = true;
if (empty($this -> loop[$path])) $this -> loop[$path] = '';
//Gestion des blocs remplac�s temporairement
if ($this -> replacement[$path]) {
$this -> loop[$path] .= $this -> MxReplace($path);
$this -> replacement[$path] = false;
$this -> sheetBuilding[$path] = '';
}
//Gestion des boucles classiques
else {
$this -> sheetBuilding[$path] = '';
if (empty($this -> loop[$path])) $this -> loop[$path] = '';
$this -> loop[$path] .= $this -> MxReplace($path);
}
}
//Insertion des fils de $path dans $path
$this -> MxBlocBuilder($path);
}
//Mx Output -------------------------------------------------------------------------------------------------------------------
//Sortie du fichier HTML g�n�r�
function MxWrite ($out = '', $renvoyer = false){
if (! $this -> mXsetting) $this -> ErrorTracker(5, 'You d\'ont intialize ModeliXe with setModeliXe method, there is no data to write.', 'MxWrite', __FILE__, __LINE__);
//Assemblage de l'ensemble des blocs fils
$this -> MxBlocBuilder();
if ($this -> mXsignature) $entete = '<!--[ModeliXe '.$this -> mXVersion.'] -- '.(($this -> isTemplateFile)? '[TemplateFile : '.$this -> mXTemplatePath.$this -> template.']' : '[Template : '.$this -> template.']').' -- [date '.date('j/m/Y H:i:s')."]-->\n";
else $entete = '';
if ($this -> ErrorChecker()) {
$filecontent = (($entete)? str_replace('<head>', '<head>'."\n".$entete,$filecontent = $this -> MxReplace($this -> absolutePath)) : $filecontent = $this -> MxReplace($this -> absolutePath));
//Remplacement des balises de param�tres
if ($this -> mXParameterFile) $filecontent = $this -> GetParameterParsing($filecontent);
//Mise en cache de la page g�n�r�e sans les param�tres de sessions
if ($this -> mXCacheDelay > 0) {
$this -> MxSetCache($filecontent);
//Parsing des param�tres de sessions
$filecontent = $this -> MxSessionParameterParsing($filecontent);
}
//Si on cherche � mesurer les performances de ModeliXe
if ($this -> performanceTracer) {
$filecontent = str_replace('<mx:performanceTracer />', $this -> GetExecutionTime(), $filecontent);
}
if ($this -> mXoutput || $renvoyer)
return $filecontent;
else
print($this -> MxSetCompress($filecontent));
}
}
} |
Partager