PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/template/tbs_class.php

http://xinix.googlecode.com/
PHP | 3727 lines | 3173 code | 366 blank | 188 comment | 882 complexity | 41c6a89de40054813191ac103a451e25 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. ********************************************************
  4. TinyButStrong - Template Engine for Pro and Beginners
  5. ------------------------
  6. Version : 3.5.3 for PHP 4
  7. Date : 2010-04-12
  8. Web site : http://www.tinybutstrong.com
  9. Author : http://www.tinybutstrong.com/onlyyou.html
  10. ********************************************************
  11. This library is free software.
  12. You can redistribute and modify it even for commercial usage,
  13. but you must accept and respect the LPGL License version 3.
  14. */
  15. // Check PHP version
  16. if (version_compare(PHP_VERSION,'4.0.6')<0) echo '<br><b>TinyButStrong Error</b> (PHP Version Check) : Your PHP version is '.PHP_VERSION.' while TinyButStrong needs PHP version 4.0.6 or higher.';
  17. if (!is_callable('array_key_exists')) {
  18. function array_key_exists (&$key,&$array) {return key_exists($key,$array);}
  19. }
  20. if (!is_callable('property_exists')) {
  21. function property_exists(&$obj,$prop) {return true;}
  22. }
  23. // Render flags
  24. define('TBS_NOTHING', 0);
  25. define('TBS_OUTPUT', 1);
  26. define('TBS_EXIT', 2);
  27. // Plug-ins actions
  28. define('TBS_INSTALL', -1);
  29. define('TBS_ISINSTALLED', -3);
  30. // *********************************************
  31. class clsTbsLocator {
  32. var $PosBeg = false;
  33. var $PosEnd = false;
  34. var $Enlarged = false;
  35. var $FullName = false;
  36. var $SubName = '';
  37. var $SubOk = false;
  38. var $SubLst = array();
  39. var $SubNbr = 0;
  40. var $PrmLst = array();
  41. var $PrmIfNbr = false;
  42. var $MagnetId = false;
  43. var $BlockFound = false;
  44. var $FirstMerge = true;
  45. var $ConvProtect = true;
  46. var $ConvStr = true;
  47. var $ConvMode = 1; // Normal
  48. var $ConvBr = true;
  49. }
  50. // *********************************************
  51. class clsTbsDataSource {
  52. var $Type = false;
  53. var $SubType = 0;
  54. var $SrcId = false;
  55. var $Query = '';
  56. var $RecSet = false;
  57. var $RecKey = '';
  58. var $RecNum = 0;
  59. var $RecNumInit = 0;
  60. var $RecSaving = false;
  61. var $RecSaved = false;
  62. var $RecBuffer = false;
  63. var $CurrRec = false;
  64. var $TBS = false;
  65. var $OnDataOk = false;
  66. var $OnDataPrm = false;
  67. var $OnDataPrmDone = array();
  68. var $OnDataPi = false;
  69. function DataAlert($Msg) {
  70. return $this->TBS->meth_Misc_Alert('when merging block '.$this->TBS->_ChrOpen.$this->TBS->_CurrBlock.$this->TBS->_ChrClose,$Msg);
  71. }
  72. function DataPrepare(&$SrcId,&$TBS) {
  73. $this->SrcId = &$SrcId;
  74. $this->TBS = &$TBS;
  75. $FctInfo = false;
  76. $FctObj = false;
  77. if (is_array($SrcId)) {
  78. $this->Type = 0;
  79. } elseif (is_resource($SrcId)) {
  80. $Key = get_resource_type($SrcId);
  81. switch ($Key) {
  82. case 'mysql link' : $this->Type = 6; break;
  83. case 'mysql link persistent' : $this->Type = 6; break;
  84. case 'mysql result' : $this->Type = 6; $this->SubType = 1; break;
  85. case 'pgsql link' : $this->Type = 7; break;
  86. case 'pgsql link persistent' : $this->Type = 7; break;
  87. case 'pgsql result' : $this->Type = 7; $this->SubType = 1; break;
  88. case 'sqlite database' : $this->Type = 8; break;
  89. case 'sqlite database (persistent)' : $this->Type = 8; break;
  90. case 'sqlite result' : $this->Type = 8; $this->SubType = 1; break;
  91. default :
  92. $FctInfo = $Key;
  93. $FctCat = 'r';
  94. }
  95. } elseif (is_string($SrcId)) {
  96. switch (strtolower($SrcId)) {
  97. case 'array' : $this->Type = 0; $this->SubType = 1; break;
  98. case 'clear' : $this->Type = 0; $this->SubType = 3; break;
  99. case 'mysql' : $this->Type = 6; $this->SubType = 2; break;
  100. case 'text' : $this->Type = 2; break;
  101. case 'num' : $this->Type = 1; break;
  102. default :
  103. $FctInfo = $SrcId;
  104. $FctCat = 'k';
  105. }
  106. } elseif (is_a($SrcId,'Iterator')) {
  107. $this->Type = 9; $this->SubType = 1;
  108. } elseif (is_a($SrcId,'ArrayObject')) {
  109. $this->Type = 9; $this->SubType = 2;
  110. } elseif (is_a($SrcId,'IteratorAggregate')) {
  111. $this->Type = 9; $this->SubType = 3;
  112. } elseif (is_object($SrcId)) {
  113. $FctInfo = get_class($SrcId);
  114. $FctCat = 'o';
  115. $FctObj = &$SrcId;
  116. $this->SrcId = &$SrcId;
  117. } elseif ($SrcId===false) {
  118. $this->DataAlert('the specified source is set to FALSE. Maybe your connection has failed.');
  119. } else {
  120. $this->DataAlert('unsupported variable type : \''.gettype($SrcId).'\'.');
  121. }
  122. if ($FctInfo!==false) {
  123. $ErrMsg = false;
  124. if ($TBS->meth_Misc_UserFctCheck($FctInfo,$FctCat,$FctObj,$ErrMsg)) {
  125. $this->Type = $FctInfo['type'];
  126. if ($this->Type!==5) {
  127. if ($this->Type===4) {
  128. $this->FctPrm = array(false,0);
  129. $this->SrcId = &$FctInfo['open'][0];
  130. }
  131. $this->FctOpen = &$FctInfo['open'];
  132. $this->FctFetch = &$FctInfo['fetch'];
  133. $this->FctClose = &$FctInfo['close'];
  134. }
  135. } else {
  136. $this->Type = $this->DataAlert($ErrMsg);
  137. }
  138. }
  139. return ($this->Type!==false);
  140. }
  141. function DataOpen(&$Query) {
  142. // Init values
  143. unset($this->CurrRec); $this->CurrRec = true;
  144. if ($this->RecSaved) {
  145. $this->FirstRec = true;
  146. unset($this->RecKey); $this->RecKey = '';
  147. $this->RecNum = $this->RecNumInit;
  148. if ($this->OnDataOk) $this->OnDataArgs[1] = &$this->CurrRec;
  149. return true;
  150. }
  151. unset($this->RecSet); $this->RecSet = false;
  152. $this->RecNumInit = 0;
  153. $this->RecNum = 0;
  154. if (isset($this->TBS->_piOnData)) {
  155. $this->OnDataPi = true;
  156. $this->OnDataPiRef = &$this->TBS->_piOnData;
  157. $this->OnDataOk = true;
  158. }
  159. if ($this->OnDataOk) {
  160. $this->OnDataArgs = array();
  161. $this->OnDataArgs[0] = &$this->TBS->_CurrBlock;
  162. $this->OnDataArgs[1] = &$this->CurrRec;
  163. $this->OnDataArgs[2] = &$this->RecNum;
  164. $this->OnDataArgs[3] = &$this->TBS;
  165. }
  166. switch ($this->Type) {
  167. case 0: // Array
  168. if (($this->SubType===1) and (is_string($Query))) $this->SubType = 2;
  169. if ($this->SubType===0) {
  170. if (PHP_VERSION==='4.4.1') {$this->RecSet = $this->SrcId;} else {$this->RecSet = &$this->SrcId;} // bad bug in PHP 4.4.1
  171. } elseif ($this->SubType===1) {
  172. if (is_array($Query)) {
  173. if (PHP_VERSION==='4.4.1') {$this->RecSet = $Query;} else {$this->RecSet = &$Query;}
  174. } else {
  175. $this->DataAlert('type \''.gettype($Query).'\' not supported for the Query Parameter going with \'array\' Source Type.');
  176. }
  177. } elseif ($this->SubType===2) {
  178. // TBS query string for array and objects, syntax: "var[item1][item2]->item3[item4]..."
  179. $x = trim($Query);
  180. $z = chr(0);
  181. $x = str_replace(array(']->','][','->','['),$z,$x);
  182. if (substr($x,strlen($x)-1,1)===']') $x = substr($x,0,strlen($x)-1);
  183. $ItemLst = explode($z,$x);
  184. $ItemNbr = count($ItemLst);
  185. $Item0 = &$ItemLst[0];
  186. // Check first item
  187. if ($Item0[0]==='~') {
  188. $Item0 = substr($Item0,1);
  189. if ($this->TBS->ObjectRef!==false) {
  190. $Var = &$this->TBS->ObjectRef;
  191. $i = 0;
  192. } else {
  193. $i = $this->DataAlert('invalid query \''.$Query.'\' because property ObjectRef is not set.');
  194. }
  195. } else {
  196. if (isset($GLOBALS[$Item0])) {
  197. if ((PHP_VERSION==='4.4.1') and is_array($GLOBALS[$Item0])) {$Var = $GLOBALS[$Item0];} else {$Var = &$GLOBALS[$Item0];}
  198. $i = 1;
  199. } else {
  200. $i = $this->DataAlert('invalid query \''.$Query.'\' because global variable \''.$Item0.'\' is not found.');
  201. }
  202. }
  203. // Check sub-items
  204. $Empty = false;
  205. while (($i!==false) and ($i<$ItemNbr) and ($Empty===false)) {
  206. $x = $ItemLst[$i];
  207. if (is_array($Var)) {
  208. if (isset($Var[$x])) {
  209. $Var = &$Var[$x];
  210. } else {
  211. $Empty = true;
  212. }
  213. } elseif (is_object($Var)) {
  214. $ArgLst = $this->TBS->f_Misc_CheckArgLst($x);
  215. if (method_exists($Var,$x)) {
  216. $f = array(&$Var,$x); unset($Var);
  217. $Var = call_user_func_array($f,$ArgLst);
  218. } elseif (property_exists(get_class($Var),$x)) {
  219. if (isset($Var->$x)) $Var = &$Var->$x;
  220. } elseif (isset($Var->$x)) {
  221. $Var = $Var->$x; // useful for overloaded property
  222. } else {
  223. $Empty = true;
  224. }
  225. } else {
  226. $i = $this->DataAlert('invalid query \''.$Query.'\' because item \''.$ItemLst[$i].'\' is neither an Array nor an Object. Its type is \''.gettype($Var).'\'.');
  227. }
  228. if ($i!==false) $i++;
  229. }
  230. // Assign data
  231. if ($i!==false) {
  232. if ($Empty) {
  233. $this->RecSet = array();
  234. } else {
  235. $this->RecSet = &$Var;
  236. }
  237. }
  238. } elseif ($this->SubType===3) { // Clear
  239. $this->RecSet = array();
  240. }
  241. // First record
  242. if ($this->RecSet!==false) {
  243. $this->RecNbr = $this->RecNumInit + count($this->RecSet);
  244. $this->FirstRec = true;
  245. $this->RecSaved = true;
  246. $this->RecSaving = false;
  247. }
  248. break;
  249. case 6: // MySQL
  250. switch ($this->SubType) {
  251. case 0: $this->RecSet = @mysql_query($Query,$this->SrcId); break;
  252. case 1: $this->RecSet = $this->SrcId; break;
  253. case 2: $this->RecSet = @mysql_query($Query); break;
  254. }
  255. if ($this->RecSet===false) $this->DataAlert('MySql error message when opening the query: '.mysql_error());
  256. break;
  257. case 1: // Num
  258. $this->RecSet = true;
  259. $this->NumMin = 1;
  260. $this->NumMax = 1;
  261. $this->NumStep = 1;
  262. if (is_array($Query)) {
  263. if (isset($Query['min'])) $this->NumMin = $Query['min'];
  264. if (isset($Query['step'])) $this->NumStep = $Query['step'];
  265. if (isset($Query['max'])) {
  266. $this->NumMax = $Query['max'];
  267. } else {
  268. $this->RecSet = $this->DataAlert('the \'num\' source is an array that has no value for the \'max\' key.');
  269. }
  270. if ($this->NumStep==0) $this->RecSet = $this->DataAlert('the \'num\' source is an array that has a step value set to zero.');
  271. } else {
  272. $this->NumMax = ceil($Query);
  273. }
  274. if ($this->RecSet) {
  275. if ($this->NumStep>0) {
  276. $this->NumVal = $this->NumMin;
  277. } else {
  278. $this->NumVal = $this->NumMax;
  279. }
  280. }
  281. break;
  282. case 2: // Text
  283. if (is_string($Query)) {
  284. $this->RecSet = &$Query;
  285. } else {
  286. $this->RecSet = ''.$Query;
  287. }
  288. break;
  289. case 3: // Custom function
  290. $FctOpen = $this->FctOpen;
  291. $this->RecSet = $FctOpen($this->SrcId,$Query);
  292. if ($this->RecSet===false) $this->DataAlert('function '.$FctOpen.'() has failed to open query {'.$Query.'}');
  293. break;
  294. case 4: // Custom method from ObjectRef
  295. $this->RecSet = call_user_func_array($this->FctOpen,array(&$this->SrcId,&$Query));
  296. if ($this->RecSet===false) $this->DataAlert('method '.get_class($this->FctOpen[0]).'::'.$this->FctOpen[1].'() has failed to open query {'.$Query.'}');
  297. break;
  298. case 5: // Custom method of object
  299. $this->RecSet = $this->SrcId->tbsdb_open($this->SrcId,$Query);
  300. if ($this->RecSet===false) $this->DataAlert('method '.get_class($this->SrcId).'::tbsdb_open() has failed to open query {'.$Query.'}');
  301. break;
  302. case 7: // PostgreSQL
  303. switch ($this->SubType) {
  304. case 0: $this->RecSet = @pg_query($this->SrcId,$Query); break;
  305. case 1: $this->RecSet = $this->SrcId; break;
  306. }
  307. if ($this->RecSet===false) $this->DataAlert('PostgreSQL error message when opening the query: '.pg_last_error($this->SrcId));
  308. break;
  309. case 8: // SQLite
  310. switch ($this->SubType) {
  311. case 0: $this->RecSet = @sqlite_query($this->SrcId,$Query); break;
  312. case 1: $this->RecSet = $this->SrcId; break;
  313. }
  314. if ($this->RecSet===false) $this->DataAlert('SQLite error message when opening the query:'.sqlite_error_string(sqlite_last_error($this->SrcId)));
  315. break;
  316. case 9: // Iterator
  317. if ($this->SubType==1) {
  318. $this->RecSet = $this->SrcId;
  319. } else { // 2 or 3
  320. $this->RecSet = $this->SrcId->getIterator();
  321. }
  322. $this->RecSet->rewind();
  323. break;
  324. }
  325. if (($this->Type===0) or ($this->Type===9)) {
  326. unset($this->RecKey); $this->RecKey = '';
  327. } else {
  328. if ($this->RecSaving) {
  329. unset($this->RecBuffer); $this->RecBuffer = array();
  330. }
  331. $this->RecKey = &$this->RecNum; // Not array: RecKey = RecNum
  332. }
  333. return ($this->RecSet!==false);
  334. }
  335. function DataFetch() {
  336. if ($this->RecSaved) {
  337. if ($this->RecNum<$this->RecNbr) {
  338. if ($this->FirstRec) {
  339. if ($this->SubType===2) { // From string
  340. reset($this->RecSet);
  341. $this->RecKey = key($this->RecSet);
  342. $this->CurrRec = &$this->RecSet[$this->RecKey];
  343. } else {
  344. $this->CurrRec = reset($this->RecSet);
  345. $this->RecKey = key($this->RecSet);
  346. }
  347. $this->FirstRec = false;
  348. } else {
  349. if ($this->SubType===2) { // From string
  350. next($this->RecSet);
  351. $this->RecKey = key($this->RecSet);
  352. $this->CurrRec = &$this->RecSet[$this->RecKey];
  353. } else {
  354. $this->CurrRec = next($this->RecSet);
  355. $this->RecKey = key($this->RecSet);
  356. }
  357. }
  358. if ((!is_array($this->CurrRec)) and (!is_object($this->CurrRec))) $this->CurrRec = array('key'=>$this->RecKey, 'val'=>$this->CurrRec);
  359. $this->RecNum++;
  360. if ($this->OnDataOk) {
  361. if ($this->OnDataPrm) call_user_func_array($this->OnDataPrmRef,$this->OnDataArgs);
  362. if ($this->OnDataPi) $this->TBS->meth_PlugIn_RunAll($this->OnDataPiRef,$this->OnDataArgs);
  363. if ($this->SubType!==2) $this->RecSet[$this->RecKey] = $this->CurrRec; // save modifications because array reading is done without reference :(
  364. }
  365. } else {
  366. unset($this->CurrRec); $this->CurrRec = false;
  367. }
  368. return;
  369. }
  370. switch ($this->Type) {
  371. case 6: // MySQL
  372. $this->CurrRec = mysql_fetch_assoc($this->RecSet);
  373. break;
  374. case 1: // Num
  375. if (($this->NumVal>=$this->NumMin) and ($this->NumVal<=$this->NumMax)) {
  376. $this->CurrRec = array('val'=>$this->NumVal);
  377. $this->NumVal += $this->NumStep;
  378. } else {
  379. $this->CurrRec = false;
  380. }
  381. break;
  382. case 2: // Text
  383. if ($this->RecNum===0) {
  384. if ($this->RecSet==='') {
  385. $this->CurrRec = false;
  386. } else {
  387. $this->CurrRec = &$this->RecSet;
  388. }
  389. } else {
  390. $this->CurrRec = false;
  391. }
  392. break;
  393. case 3: // Custom function
  394. $FctFetch = $this->FctFetch;
  395. $this->CurrRec = $FctFetch($this->RecSet,$this->RecNum+1);
  396. break;
  397. case 4: // Custom method from ObjectRef
  398. $this->FctPrm[0] = &$this->RecSet; $this->FctPrm[1] = $this->RecNum+1;
  399. $this->CurrRec = call_user_func_array($this->FctFetch,$this->FctPrm);
  400. break;
  401. case 5: // Custom method of object
  402. $this->CurrRec = $this->SrcId->tbsdb_fetch($this->RecSet,$this->RecNum+1);
  403. break;
  404. case 7: // PostgreSQL
  405. $this->CurrRec = @pg_fetch_array($this->RecSet,$this->RecNum,PGSQL_ASSOC); // warning comes when no record left.
  406. break;
  407. case 8: // SQLite
  408. $this->CurrRec = sqlite_fetch_array($this->RecSet,SQLITE_ASSOC);
  409. break;
  410. case 9: // Iterator
  411. if ($this->RecSet->valid()) {
  412. $this->CurrRec = $this->RecSet->current();
  413. $this->RecKey = $this->RecSet->key();
  414. $this->RecSet->next();
  415. } else {
  416. $this->CurrRec = false;
  417. }
  418. break;
  419. }
  420. // Set the row count
  421. if ($this->CurrRec!==false) {
  422. $this->RecNum++;
  423. if ($this->OnDataOk) {
  424. $this->OnDataArgs[1] = &$this->CurrRec; // Reference has changed if ($this->SubType===2)
  425. if ($this->OnDataPrm) call_user_func_array($this->OnDataPrmRef,$this->OnDataArgs);
  426. if ($this->OnDataPi) $this->TBS->meth_PlugIn_RunAll($this->OnDataPiRef,$this->OnDataArgs);
  427. }
  428. if ($this->RecSaving) $this->RecBuffer[$this->RecKey] = $this->CurrRec;
  429. }
  430. }
  431. function DataClose() {
  432. $this->OnDataOk = false;
  433. $this->OnDataPrm = false;
  434. $this->OnDataPi = false;
  435. if ($this->RecSaved) return;
  436. switch ($this->Type) {
  437. case 6: mysql_free_result($this->RecSet); break;
  438. case 3: $FctClose=$this->FctClose; $FctClose($this->RecSet); break;
  439. case 4: call_user_func_array($this->FctClose,array(&$this->RecSet)); break;
  440. case 5: $this->SrcId->tbsdb_close($this->RecSet); break;
  441. case 7: pg_free_result($this->RecSet); break;
  442. }
  443. if ($this->RecSaving) {
  444. $this->RecSet = &$this->RecBuffer;
  445. $this->RecNbr = $this->RecNumInit + count($this->RecSet);
  446. $this->RecSaving = false;
  447. $this->RecSaved = true;
  448. }
  449. }
  450. }
  451. // *********************************************
  452. class clsTinyButStrong {
  453. // Public properties
  454. var $Source = '';
  455. var $Render = 3;
  456. var $TplVars = array();
  457. var $ObjectRef = false;
  458. var $NoErr = false;
  459. var $Assigned = array();
  460. // Undocumented (can change at any version)
  461. var $Version = '3.5.3';
  462. var $Charset = '';
  463. var $TurboBlock = true;
  464. var $VarPrefix = '';
  465. var $Protect = true;
  466. var $ErrCount = 0;
  467. var $ErrMsg = '';
  468. var $AttDelim = false;
  469. var $MethodsAllowed = false;
  470. // Private
  471. var $_ErrMsgName = '';
  472. var $_LastFile = '';
  473. var $_CharsetFct = false;
  474. var $_Mode = 0;
  475. var $_CurrBlock = '';
  476. var $_ChrOpen = '[';
  477. var $_ChrClose = ']';
  478. var $_ChrVal = '[val]';
  479. var $_ChrProtect = '&#91;';
  480. var $_PlugIns = array();
  481. var $_PlugIns_Ok = false;
  482. var $_piOnFrm_Ok = false;
  483. function clsTinyButStrong($Chrs='',$VarPrefix='') {
  484. if ($Chrs!=='') {
  485. $Ok = false;
  486. $Len = strlen($Chrs);
  487. if ($Len===2) { // For compatibility
  488. $this->_ChrOpen = $Chrs[0];
  489. $this->_ChrClose = $Chrs[1];
  490. $Ok = true;
  491. } else {
  492. $Pos = strpos($Chrs,',');
  493. if (($Pos!==false) and ($Pos>0) and ($Pos<$Len-1)) {
  494. $this->_ChrOpen = substr($Chrs,0,$Pos);
  495. $this->_ChrClose = substr($Chrs,$Pos+1);
  496. $Ok = true;
  497. }
  498. }
  499. if ($Ok) {
  500. $this->_ChrVal = $this->_ChrOpen.'val'.$this->_ChrClose;
  501. $this->_ChrProtect = '&#'.ord($this->_ChrOpen[0]).';'.substr($this->_ChrOpen,1);
  502. } else {
  503. $this->meth_Misc_Alert('with clsTinyButStrong() function','value \''.$Chrs.'\' is a bad tag delimitor definition.');
  504. }
  505. }
  506. $this->VarPrefix = $VarPrefix;
  507. // Links to global variables
  508. global $_TBS_FormatLst, $_TBS_UserFctLst, $_TBS_AutoInstallPlugIns;
  509. if (!isset($_TBS_FormatLst)) $_TBS_FormatLst = array();
  510. if (!isset($_TBS_UserFctLst)) $_TBS_UserFctLst = array();
  511. $this->_FormatLst = &$_TBS_FormatLst;
  512. $this->_UserFctLst = &$_TBS_UserFctLst;
  513. // Auto-installing plug-ins
  514. if (isset($_TBS_AutoInstallPlugIns)) foreach ($_TBS_AutoInstallPlugIns as $pi) $this->PlugIn(TBS_INSTALL,$pi);
  515. }
  516. // Public methods
  517. function LoadTemplate($File,$Charset='') {
  518. if ($File==='') {
  519. $this->meth_Misc_Charset($Charset);
  520. return true;
  521. }
  522. $Ok = true;
  523. if ($this->_PlugIns_Ok) {
  524. if (isset($this->_piBeforeLoadTemplate) or isset($this->_piAfterLoadTemplate)) {
  525. // Plug-ins
  526. $ArgLst = func_get_args();
  527. $ArgLst[0] = &$File;
  528. $ArgLst[1] = &$Charset;
  529. if (isset($this->_piBeforeLoadTemplate)) $Ok = $this->meth_PlugIn_RunAll($this->_piBeforeLoadTemplate,$ArgLst);
  530. }
  531. }
  532. // Load the file
  533. if ($Ok!==false) {
  534. if (!is_null($File)) {
  535. $x = '';
  536. if (!$this->f_Misc_GetFile($x,$File,$this->_LastFile)) return $this->meth_Misc_Alert('with LoadTemplate() method','file \''.$File.'\' is not found or not readable.');
  537. if ($Charset==='+') {
  538. $this->Source .= $x;
  539. } else {
  540. $this->Source = $x;
  541. }
  542. }
  543. if ($this->_Mode==0) {
  544. if (!is_null($File)) $this->_LastFile = $File;
  545. if ($Charset!=='+') $this->TplVars = array();
  546. $this->meth_Misc_Charset($Charset);
  547. }
  548. // Automatic fields and blocks
  549. $this->meth_Merge_AutoOn($this->Source,'onload',true,true);
  550. }
  551. // Plug-ins
  552. if ($this->_PlugIns_Ok and isset($ArgLst) and isset($this->_piAfterLoadTemplate)) $Ok = $this->meth_PlugIn_RunAll($this->_piAfterLoadTemplate,$ArgLst);
  553. return $Ok;
  554. }
  555. function GetBlockSource($BlockName,$List=false,$KeepDefTags=true,$ReplaceWith=false) {
  556. $RetVal = array();
  557. $Nbr = 0;
  558. $Pos = 0;
  559. $FieldOutside = false;
  560. $P1 = false;
  561. $Mode = ($KeepDefTags) ? 3 : 2;
  562. $PosBeg1 = 0;
  563. while ($Loc = $this->meth_Locator_FindBlockNext($this->Source,$BlockName,$Pos,'.',$Mode,$P1,$FieldOutside)) {
  564. $Nbr++;
  565. if ($Nbr==1) $PosBeg1 = $Loc->PosBeg;
  566. if ($List) $RetVal[$Nbr] = $Loc->BlockSrc;
  567. $Pos = $Loc->PosEnd;
  568. $P1 = false;
  569. }
  570. if ($Nbr==0) return false;
  571. if (!$List) $RetVal = substr($this->Source,$PosBeg1,$Pos-$PosBeg1+1);
  572. if ($ReplaceWith!==false) $this->Source = substr($this->Source,0,$PosBeg1).$ReplaceWith.substr($this->Source,$Pos+1);
  573. return $RetVal;
  574. }
  575. function MergeBlock($BlockLst,$SrcId='assigned',$Query='') {
  576. if ($SrcId==='assigned') {
  577. $Arg = array($BlockLst,&$SrcId,&$Query);
  578. if (!$this->meth_Misc_Assign($BlockLst, $Arg, 'MergeBlock')) return 0;
  579. $BlockLst = $Arg[0]; $SrcId = &$Arg[1]; $Query = &$Arg[2];
  580. }
  581. if (is_string($BlockLst)) $BlockLst = explode(',',$BlockLst);
  582. if ($SrcId==='cond') {
  583. $Nbr = 0;
  584. foreach ($BlockLst as $Block) {
  585. $Block = trim($Block);
  586. if ($Block!=='') $Nbr += $this->meth_Merge_AutoOn($this->Source,$Block,true,true);
  587. }
  588. return $Nbr;
  589. } else {
  590. return $this->meth_Merge_Block($this->Source,$BlockLst,$SrcId,$Query,false,0);
  591. }
  592. }
  593. function MergeField($NameLst,$Value='assigned',$IsUserFct=false,$DefaultPrm=false) {
  594. $FctCheck = $IsUserFct;
  595. if ($PlugIn = isset($this->_piOnMergeField)) $ArgPi = array('','',&$Value,0,&$this->Source,0,0);
  596. $SubStart = 0;
  597. $Ok = true;
  598. $Prm = is_array($DefaultPrm);
  599. if ( ($Value==='assigned') and ($NameLst!=='var') and ($NameLst!=='onshow') and ($NameLst!=='onload') ) {
  600. $Arg = array($NameLst,&$Value,&$IsUserFct,&$DefaultPrm);
  601. if (!$this->meth_Misc_Assign($NameLst, $Arg, 'MergeField')) return false;
  602. $NameLst = $Arg[0]; $Value = &$Arg[1]; $IsUserFct = &$Arg[2]; $DefaultPrm = &$Arg[3];
  603. }
  604. $NameLst = explode(',',$NameLst);
  605. foreach ($NameLst as $Name) {
  606. $Name = trim($Name);
  607. $Cont = false;
  608. switch ($Name) {
  609. case '': $Cont=true;break;
  610. case 'onload': $this->meth_Merge_AutoOn($this->Source,'onload',true,true);$Cont=true;break;
  611. case 'onshow': $this->meth_Merge_AutoOn($this->Source,'onshow',true,true);$Cont=true;break;
  612. case 'var': $this->meth_Merge_AutoVar($this->Source,true);$Cont=true;break;
  613. }
  614. if ($Cont) continue;
  615. if ($PlugIn) $ArgPi[0] = $Name;
  616. $PosBeg = 0;
  617. // Initilize the user function (only once)
  618. if ($FctCheck) {
  619. $FctInfo = $Value;
  620. $ErrMsg = false;
  621. if (!$this->meth_Misc_UserFctCheck($FctInfo,'f',$ErrMsg,$ErrMsg)) return $this->meth_Misc_Alert('with MergeField() method',$ErrMsg);
  622. $FctArg = array('','');
  623. $SubStart = false;
  624. $FctCheck = false;
  625. }
  626. while ($Loc = $this->meth_Locator_FindTbs($this->Source,$Name,$PosBeg,'.')) {
  627. if ($Prm) $Loc->PrmLst = array_merge($DefaultPrm,$Loc->PrmLst);
  628. // Apply user function
  629. if ($IsUserFct) {
  630. $FctArg[0] = &$Loc->SubName; $FctArg[1] = &$Loc->PrmLst;
  631. $Value = call_user_func_array($FctInfo,$FctArg);
  632. }
  633. // Plug-ins
  634. if ($PlugIn) {
  635. $ArgPi[1] = $Loc->SubName; $ArgPi[3] = &$Loc->PrmLst; $ArgPi[5] = &$Loc->PosBeg; $ArgPi[6] = &$Loc->PosEnd;
  636. $Ok = $this->meth_PlugIn_RunAll($this->_piOnMergeField,$ArgPi);
  637. }
  638. // Merge the field
  639. if ($Ok) {
  640. $PosBeg = $this->meth_Locator_Replace($this->Source,$Loc,$Value,$SubStart);
  641. } else {
  642. $PosBeg = $Loc->PosEnd;
  643. }
  644. }
  645. }
  646. }
  647. function Show($Render=false) {
  648. $Ok = true;
  649. if ($Render===false) $Render = $this->Render;
  650. if ($this->_PlugIns_Ok) {
  651. if (isset($this->_piBeforeShow) or isset($this->_piAfterShow)) {
  652. // Plug-ins
  653. $ArgLst = func_get_args();
  654. $ArgLst[0] = &$Render;
  655. if (isset($this->_piBeforeShow)) $Ok = $this->meth_PlugIn_RunAll($this->_piBeforeShow,$ArgLst);
  656. }
  657. }
  658. if ($Ok!==false) {
  659. $this->meth_Merge_AutoOn($this->Source,'onshow',true,true);
  660. $this->meth_Merge_AutoVar($this->Source,true);
  661. }
  662. if ($this->_PlugIns_Ok and isset($ArgLst) and isset($this->_piAfterShow)) $this->meth_PlugIn_RunAll($this->_piAfterShow,$ArgLst);
  663. if ($this->_ErrMsgName!=='') $this->MergeField($this->_ErrMsgName, $this->ErrMsg);
  664. if (($Render & TBS_OUTPUT)==TBS_OUTPUT) echo $this->Source;
  665. if (($this->_Mode==0) and (($Render & TBS_EXIT)==TBS_EXIT)) exit;
  666. return $Ok;
  667. }
  668. function PlugIn($Prm1,$Prm2=0) {
  669. if (is_numeric($Prm1)) {
  670. switch ($Prm1) {
  671. case TBS_INSTALL:
  672. $PlugInId = $Prm2;
  673. // Try to install the plug-in
  674. if (isset($this->_PlugIns[$PlugInId])) {
  675. return $this->meth_Misc_Alert('with PlugIn() method','plug-in \''.$PlugInId.'\' is already installed.');
  676. } else {
  677. $ArgLst = func_get_args();
  678. array_shift($ArgLst); array_shift($ArgLst);
  679. return $this->meth_PlugIn_Install($PlugInId,$ArgLst,false);
  680. }
  681. case TBS_ISINSTALLED:
  682. // Check if the plug-in is installed
  683. return isset($this->_PlugIns[$Prm2]);
  684. case -4: // Deactivate special plug-ins
  685. $this->_PlugIns_Ok_save = $this->_PlugIns_Ok;
  686. $this->_PlugIns_Ok = false;
  687. return true;
  688. case -5: // Deactivate OnFormat
  689. $this->_piOnFrm_Ok_save = $this->_piOnFrm_Ok;
  690. $this->_piOnFrm_Ok = false;
  691. return true;
  692. case -10: // Restore
  693. if (isset($this->_PlugIns_Ok_save)) $this->_PlugIns_Ok = $this->_PlugIns_Ok_save;
  694. if (isset($this->_piOnFrm_Ok_save)) $this->_piOnFrm_Ok = $this->_piOnFrm_Ok_save;
  695. return true;
  696. }
  697. } elseif (is_string($Prm1)) {
  698. // Plug-in's command
  699. $PlugInId = $Prm1;
  700. if (!isset($this->_PlugIns[$PlugInId])) {
  701. if (!$this->meth_PlugIn_Install($PlugInId,array(),true)) return false;
  702. }
  703. if (!isset($this->_piOnCommand[$PlugInId])) return $this->meth_Misc_Alert('with PlugIn() method','plug-in \''.$PlugInId.'\' can\'t run any command because the OnCommand event is not defined or activated.');
  704. $ArgLst = func_get_args();
  705. array_shift($ArgLst);
  706. $Ok = call_user_func_array($this->_piOnCommand[$PlugInId],$ArgLst);
  707. if (is_null($Ok)) $Ok = true;
  708. return $Ok;
  709. }
  710. return $this->meth_Misc_Alert('with PlugIn() method','\''.$Prm1.'\' is an invalid plug-in key, the type of the value is \''.gettype($Prm1).'\'.');
  711. }
  712. // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  713. function meth_Locator_FindTbs(&$Txt,$Name,$Pos,$ChrSub) {
  714. // Find a TBS Locator
  715. $PosEnd = false;
  716. $PosMax = strlen($Txt) -1;
  717. $Start = $this->_ChrOpen.$Name;
  718. do {
  719. // Search for the opening char
  720. if ($Pos>$PosMax) return false;
  721. $Pos = strpos($Txt,$Start,$Pos);
  722. // If found => next chars are analyzed
  723. if ($Pos===false) {
  724. return false;
  725. } else {
  726. $Loc = &new clsTbsLocator;
  727. $ReadPrm = false;
  728. $PosX = $Pos + strlen($Start);
  729. $x = $Txt[$PosX];
  730. if ($x===$this->_ChrClose) {
  731. $PosEnd = $PosX;
  732. } elseif ($x===$ChrSub) {
  733. $Loc->SubOk = true; // it is no longer the false value
  734. $ReadPrm = true;
  735. $PosX++;
  736. } elseif (strpos(';',$x)!==false) {
  737. $ReadPrm = true;
  738. $PosX++;
  739. } else {
  740. $Pos++;
  741. }
  742. $Loc->PosBeg = $Pos;
  743. if ($ReadPrm) {
  744. $this->f_Loc_PrmRead($Txt,$PosX,false,'\'',$this->_ChrOpen,$this->_ChrClose,$Loc,$PosEnd);
  745. if ($PosEnd===false) {
  746. $this->meth_Misc_Alert('','can\'t found the end of the tag \''.substr($Txt,$Pos,$PosX-$Pos+10).'...\'.');
  747. $Pos++;
  748. }
  749. }
  750. }
  751. } while ($PosEnd===false);
  752. $Loc->PosEnd = $PosEnd;
  753. if ($Loc->SubOk) {
  754. $Loc->FullName = $Name.'.'.$Loc->SubName;
  755. $Loc->SubLst = explode('.',$Loc->SubName);
  756. $Loc->SubNbr = count($Loc->SubLst);
  757. } else {
  758. $Loc->FullName = $Name;
  759. }
  760. if ($ReadPrm and isset($Loc->PrmLst['comm'])) {
  761. $Loc->PosBeg0 = $Loc->PosBeg;
  762. $Loc->PosEnd0 = $Loc->PosEnd;
  763. $comm = $Loc->PrmLst['comm'];
  764. if (($comm===true) or ($comm==='')) {
  765. $Loc->Enlarged = $this->f_Loc_EnlargeToStr($Txt,$Loc,'<!--' ,'-->');
  766. } else {
  767. $Loc->Enlarged = $this->f_Loc_EnlargeToTag($Txt,$Loc,$comm,false);
  768. }
  769. }
  770. return $Loc;
  771. }
  772. function &meth_Locator_SectionNewBDef(&$LocR,$BlockName,$Txt,$PrmLst) {
  773. $Chk = true;
  774. $LocLst = array();
  775. $LocNbr = 0;
  776. // Cache TBS locators
  777. if ($this->TurboBlock) {
  778. $Chk = false;
  779. $Pos = 0;
  780. $PrevEnd = -1;
  781. $PrevIsAMF = false;
  782. while ($Loc = $this->meth_Locator_FindTbs($Txt,$BlockName,$Pos,'.')) {
  783. $IsAMF = false;
  784. if (($Loc->SubName==='#') or ($Loc->SubName==='$')) {
  785. $Loc->IsRecInfo = true;
  786. $Loc->RecInfo = $Loc->SubName;
  787. $Loc->SubName = '';
  788. } else {
  789. $Loc->IsRecInfo = false;
  790. }
  791. if ($Loc->PosBeg>$PrevEnd) { // No embedding
  792. if (isset($Loc->PrmLst['att'])) {
  793. $LocSrc = substr($Txt,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);
  794. $this->f_Xml_AttFind($Txt,$Loc,true,$this->AttDelim);
  795. if ($Loc->AttForward) {
  796. $IsAMF = true;
  797. } else {
  798. for ($i=$LocNbr;$i>0;$i--) {
  799. if ($LocLst[$i]->PosEnd>=$Loc->PosBeg) {
  800. $LocNbr--;
  801. } else {
  802. $i = 0;
  803. }
  804. }
  805. }
  806. unset($Loc->PrmLst['att']);
  807. }
  808. $LocNbr++;
  809. } else {
  810. // The previous tag is embedding => no increment, then previous Loc is overwrited
  811. $Chk = true;
  812. if ($PrevIsAMF) {
  813. $l = &$LocLst[$LocNbr];
  814. $this->meth_Misc_Alert('','TBS is not able to merge the field '.$LocSrc.' because parameter \'att\' makes this fied moving forward over another TBS field.');
  815. }
  816. }
  817. $PrevEnd = $Loc->PosEnd;
  818. $PrevIsAMF = false;
  819. if ($IsAMF) {
  820. $Pos = $Loc->PrevPosBeg;
  821. $PrevIsAMF = true;
  822. } elseif ($Loc->Enlarged) { // Parameter 'comm'
  823. $Pos = $Loc->PosBeg0+1;
  824. $Loc->Enlarged = false;
  825. } else {
  826. $Pos = $Loc->PosBeg+1;
  827. }
  828. $LocLst[$LocNbr] = $Loc;
  829. }
  830. }
  831. // Create the object
  832. $o = (object) null;
  833. $o->Prm = $PrmLst;
  834. $o->LocLst = $LocLst;
  835. $o->LocNbr = $LocNbr;
  836. $o->Name = $BlockName;
  837. $o->Src = $Txt;
  838. $o->Chk = $Chk;
  839. $o->IsSerial = false;
  840. $o->AutoSub = false;
  841. $i = 1;
  842. while (isset($PrmLst['sub'.$i])) {
  843. $o->AutoSub = $i;
  844. $i++;
  845. }
  846. $LocR->BDefLst[] = &$o; // Can be usefull for plug-in
  847. return $o;
  848. }
  849. function meth_Locator_SectionAddGrp(&$LocR,$BlockName,&$BDef,$Type,$Field,$Prm) {
  850. $BDef->PrevValue = false;
  851. $BDef->Type = $Type;
  852. // Save sub items in a structure near to Locator.
  853. $Field0 = $Field;
  854. if (strpos($Field,$this->_ChrOpen)===false) $Field = $this->_ChrOpen.$BlockName.'.'.$Field.$this->_ChrClose;
  855. $BDef->FDef = &$this->meth_Locator_SectionNewBDef($LocR,$BlockName,$Field,array());
  856. if ($BDef->FDef->LocNbr==0) $this->meth_Misc_Alert('Parameter '.$Prm,'The value \''.$Field0.'\' is unvalide for this parameter.');
  857. if ($Type==='H') {
  858. if ($LocR->HeaderFound===false) {
  859. $LocR->HeaderFound = true;
  860. $LocR->HeaderNbr = 0;
  861. $LocR->HeaderDef = array(); // 1 to HeaderNbr
  862. }
  863. $i = ++$LocR->HeaderNbr;
  864. $LocR->HeaderDef[$i] = &$BDef;
  865. } else {
  866. if ($LocR->FooterFound===false) {
  867. $LocR->FooterFound = true;
  868. $LocR->FooterNbr = 0;
  869. $LocR->FooterDef = array(); // 1 to FooterNbr
  870. }
  871. $BDef->AddLastGrp = ($Type==='F');
  872. $i = ++$LocR->FooterNbr;
  873. $LocR->FooterDef[$i] = &$BDef;
  874. }
  875. }
  876. function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$SubStart) {
  877. // This function enables to merge a locator with a text and returns the position just after the replaced block
  878. // This position can be useful because we don't know in advance how $Value will be replaced.
  879. // Found the value if there is a subname
  880. if (($SubStart!==false) and $Loc->SubOk) {
  881. for ($i=$SubStart;$i<$Loc->SubNbr;$i++) {
  882. $x = $Loc->SubLst[$i]; // &$Loc... brings an error with Event Example, I don't know why.
  883. if (is_array($Value)) {
  884. if (isset($Value[$x])) {
  885. $Value = &$Value[$x];
  886. } elseif (array_key_exists($x,$Value)) {// can happens when value is NULL
  887. $Value = &$Value[$x];
  888. } else {
  889. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item \''.$x.'\' is not an existing key in the array.',true);
  890. unset($Value); $Value = ''; break;
  891. }
  892. } elseif (is_object($Value)) {
  893. $ArgLst = $this->f_Misc_CheckArgLst($x);
  894. if (method_exists($Value,$x)) {
  895. if ($this->MethodsAllowed or !in_array(strtok($Loc->FullName,'.'),array('onload','onshow','var')) ) {
  896. $x = call_user_func_array(array(&$Value,$x),$ArgLst);
  897. } else {
  898. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'\''.$x.'\' is a method and the current TBS settings do not allow to call methods on automatic fields.',true);
  899. $x = '';
  900. }
  901. } elseif (property_exists($Value,$x)) {
  902. $x = &$Value->$x;
  903. } elseif (isset($Value->$x)) {
  904. $x = $Value->$x; // useful for overloaded property
  905. } else {
  906. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item '.$x.'\' is neither a method nor a property in the class \''.get_class($Value).'\'.',true);
  907. unset($Value); $Value = ''; break;
  908. }
  909. $Value = &$x; unset($x); $x = '';
  910. } else {
  911. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item before \''.$x.'\' is neither an object nor an array. Its type is '.gettype($Value).'.',true);
  912. unset($Value); $Value = ''; break;
  913. }
  914. }
  915. }
  916. $CurrVal = $Value; // Unlink
  917. if (isset($Loc->PrmLst['onformat'])) {
  918. if ($Loc->FirstMerge) {
  919. $Loc->OnFrmInfo = $Loc->PrmLst['onformat'];
  920. $Loc->OnFrmArg = array($Loc->FullName,'',&$Loc->PrmLst,&$this);
  921. $ErrMsg = false;
  922. if (!$this->meth_Misc_UserFctCheck($Loc->OnFrmInfo,'f',$ErrMsg,$ErrMsg)) {
  923. unset($Loc->PrmLst['onformat']);
  924. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'(parameter onformat) '.$ErrMsg);
  925. $Loc->OnFrmInfo = 'pi'; // Execute the function pi() just to avoid extra error messages
  926. }
  927. } else {
  928. $Loc->OnFrmArg[3] = &$this; // bugs.php.net/51174
  929. }
  930. $Loc->OnFrmArg[1] = &$CurrVal;
  931. if (isset($Loc->PrmLst['subtpl'])) {
  932. $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal);
  933. call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmArg);
  934. $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal);
  935. $Loc->ConvProtect = false;
  936. $Loc->ConvStr = false;
  937. } else {
  938. call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmArg);
  939. }
  940. }
  941. if ($Loc->FirstMerge) {
  942. if (isset($Loc->PrmLst['frm'])) {
  943. $Loc->ConvMode = 0; // Frm
  944. $Loc->ConvProtect = false;
  945. } else {
  946. // Analyze parameter 'htmlconv'
  947. if (isset($Loc->PrmLst['htmlconv'])) {
  948. $x = strtolower($Loc->PrmLst['htmlconv']);
  949. $x = '+'.str_replace(' ','',$x).'+';
  950. if (strpos($x,'+esc+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvEsc = true; }
  951. if (strpos($x,'+wsp+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvWS = true; }
  952. if (strpos($x,'+js+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvJS = true; }
  953. if (strpos($x,'+url+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvUrl = true; }
  954. if (strpos($x,'+no+')!==false) $Loc->ConvStr = false;
  955. if (strpos($x,'+yes+')!==false) $Loc->ConvStr = true;
  956. if (strpos($x,'+nobr+')!==false) {$Loc->ConvStr = true; $Loc->ConvBr = false; }
  957. } else {
  958. if ($this->Charset===false) $Loc->ConvStr = false; // No conversion
  959. }
  960. // Analyze parameter 'protect'
  961. if (isset($Loc->PrmLst['protect'])) {
  962. $x = strtolower($Loc->PrmLst['protect']);
  963. if ($x==='no') {
  964. $Loc->ConvProtect = false;
  965. } elseif ($x==='yes') {
  966. $Loc->ConvProtect = true;
  967. }
  968. } elseif ($this->Protect===false) {
  969. $Loc->ConvProtect = false;
  970. }
  971. }
  972. if ($Loc->Ope = isset($Loc->PrmLst['ope'])) {
  973. $OpeLst = explode(',',$Loc->PrmLst['ope']);
  974. $Loc->OpeAct = array();
  975. $Loc->OpeArg = array();
  976. foreach ($OpeLst as $i=>$ope) {
  977. if ($ope==='list') {
  978. $Loc->OpeAct[$i] = 1;
  979. $Loc->OpePrm[$i] = (isset($Loc->PrmLst['valsep'])) ? $Loc->PrmLst['valsep'] : ',';
  980. } elseif ($ope==='minv') {
  981. $Loc->OpeAct[$i] = 11;
  982. $Loc->MSave = $Loc->MagnetId;
  983. } else {
  984. $x = substr($ope,0,4);
  985. if ($x==='max:') {
  986. if (isset($Loc->PrmLst['maxhtml'])) {$Loc->OpeAct[$i]=2;} elseif (isset($Loc->PrmLst['maxutf8'])) {$Loc->OpeAct[$i]=4;} else {$Loc->OpeAct[$i]=3;}
  987. $Loc->OpePrm[$i] = intval(trim(substr($ope,4)));
  988. $Loc->OpeEnd = (isset($Loc->PrmLst['maxend'])) ? $Loc->PrmLst['maxend'] : '...';
  989. if ($Loc->OpePrm[$i]<=0) $Loc->Ope = false;
  990. } elseif ($x==='mod:') {$Loc->OpeAct[$i] = 5; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  991. } elseif ($x==='add:') {$Loc->OpeAct[$i] = 6; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  992. } elseif ($x==='mul:') {$Loc->OpeAct[$i] = 7; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  993. } elseif ($x==='div:') {$Loc->OpeAct[$i] = 8; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  994. } elseif ($x==='mok:') {$Loc->OpeAct[$i] = 9; $Loc->OpeMOK[] = trim(substr($ope,4)); $Loc->MSave = $Loc->MagnetId;
  995. } elseif ($x==='mko:') {$Loc->OpeAct[$i] =10; $Loc->OpeMKO[] = trim(substr($ope,4)); $Loc->MSave = $Loc->MagnetId;
  996. } elseif ($x==='nif:') {$Loc->OpeAct[$i] =12; $Loc->OpePrm[$i] = trim(substr($ope,4));
  997. } elseif (isset($this->_piOnOperation)) {
  998. $Loc->OpeAct[$i] = 0;
  999. $Loc->OpePrm[$i] = $ope;
  1000. $Loc->OpeArg[$i] = array($Loc->FullName,&$CurrVal,&$Loc->PrmLst,&$Txt,$Loc->PosBeg,$Loc->PosEnd,&$Loc);
  1001. $Loc->PrmLst['_ope'] = $Loc->PrmLst['ope'];
  1002. } elseif (!isset($Loc->PrmLst['noerr'])) {
  1003. $this->meth_Misc_Alert($Loc,'parameter ope doesn\'t support value \''.$ope.'\'.',true);
  1004. }
  1005. }
  1006. }
  1007. }
  1008. $Loc->FirstMerge = false;
  1009. }
  1010. $ConvProtect = $Loc->ConvProtect;
  1011. // Plug-in OnFormat
  1012. if ($this->_piOnFrm_Ok) {
  1013. if (isset($Loc->OnFrmArgPi)) {
  1014. $Loc->OnFrmArgPi[1] = &$CurrVal;
  1015. $Loc->OnFrmArgPi[3] = &$this; // bugs.php.net/51174
  1016. } else {
  1017. $Loc->OnFrmArgPi = array($Loc->FullName,&$CurrVal,&$Loc->PrmLst,&$this);
  1018. }
  1019. $this->meth_PlugIn_RunAll($this->_piOnFormat,$Loc->OnFrmArgPi);
  1020. }
  1021. // Operation
  1022. if ($Loc->Ope) {
  1023. foreach ($Loc->OpeAct as $i=>$ope) {
  1024. switch ($ope) {
  1025. case 0:
  1026. $Loc->PrmLst['ope'] = $Loc->OpePrm[$i]; // for compatibility
  1027. $OpeArg = &$Loc->OpeArg[$i];
  1028. $OpeArg[1] = &$CurrVal; $OpeArg[3] = &$Txt;
  1029. if (!$this->meth_PlugIn_RunAll($this->_piOnOperation,$OpeArg)) return $Loc->PosBeg;
  1030. break;
  1031. case 1: if (is_array($CurrVal)) $CurrVal = implode($Loc->OpePrm[$i],$CurrVal); break;
  1032. case 2: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $this->f_Xml_Max($CurrVal,$Loc->OpePrm[$i],$Loc->OpeEnd); break;
  1033. case 3: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $CurrVal = substr(''.$CurrVal,0,$Loc->OpePrm[$i]).$Loc->OpeEnd; break;
  1034. case 4: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $CurrVal = mb_substr(''.$CurrVal,0,$Loc->OpePrm[$i],'UTF-8').$Loc->OpeEnd; break;
  1035. case 5: $CurrVal = ('0'+$CurrVal) % $Loc->OpePrm[$i]; break;
  1036. case 6: $CurrVal = ('0'+$CurrVal) + $Loc->OpePrm[$i]; break;
  1037. case 7: $CurrVal = ('0'+$CurrVal) * $Loc->OpePrm[$i]; break;
  1038. case 8: $CurrVal = ('0'+$CurrVal) / $Loc->OpePrm[$i]; break;
  1039. case 9; case 10:
  1040. if ($ope===9) {
  1041. $CurrVal = (in_array((string)$CurrVal,$Loc->OpeMOK)) ? ' ' : '';
  1042. } else {
  1043. $CurrVal = (in_array((string)$CurrVal,$Loc->OpeMKO)) ? '' : ' ';
  1044. } // no break here
  1045. case 11:
  1046. if ((string)$CurrVal==='') {
  1047. if ($Loc->MagnetId===0) $Loc->MagnetId = $Loc->MSave;
  1048. } else {
  1049. if ($Loc->MagnetId!==0) {
  1050. $Loc->MSave = $Loc->MagnetId;
  1051. $Loc->MagnetId = 0;
  1052. }
  1053. $CurrVal = '';
  1054. }
  1055. break;
  1056. case 12: if ((string)$CurrVal===$Loc->OpePrm[$i]) $CurrVal = ''; break;
  1057. }
  1058. }
  1059. }
  1060. // String conversion or format
  1061. if ($Loc->ConvMode===1) { // Usual string conversion
  1062. if (!is_string($CurrVal)) $CurrVal =(string)$CurrVal; // (string) is faster than strval() and settype()
  1063. if ($Loc->ConvStr) $this->meth_Conv_Str($CurrVal,$Loc->ConvBr);
  1064. } elseif ($Loc->ConvMode===0) { // Format
  1065. $CurrVal = $this->meth_Misc_Format($CurrVal,$Loc->PrmLst);
  1066. } elseif ($Loc->ConvMode===2) { // Special string conversion
  1067. if (!is_string($CurrVal)) $CurrVal = (string)$CurrVal;
  1068. if ($Loc->ConvStr) $this->meth_Conv_Str($CurrVal,$Loc->ConvBr);
  1069. if ($Loc->ConvEsc) $CurrVal = str_replace('\'','\'\'',$CurrVal);
  1070. if ($Loc->ConvWS) {
  1071. $check = ' ';
  1072. $nbsp = '&nbsp;';
  1073. do {
  1074. $pos = strpos($CurrVal,$check);
  1075. if ($pos!==false) $CurrVal = substr_replace($CurrVal,$nbsp,$pos,1);
  1076. } while ($pos!==false);
  1077. }
  1078. if ($Loc->ConvJS) {
  1079. $CurrVal = addslashes($CurrVal); // apply to ('), ("), (\) and (null)
  1080. $CurrVal = str_replace(array("\n","\r","\t"),array('\n','\r','\t'),$CurrVal);
  1081. }
  1082. if ($Loc->ConvUrl) $CurrVal = urlencode($CurrVal);
  1083. }
  1084. // if/then/else process, there may be several if/then
  1085. if ($Loc->PrmIfNbr) {
  1086. $z = false;
  1087. $i = 1;
  1088. while ($i!==false) {
  1089. if ($Loc->PrmIfVar[$i]) $Loc->PrmIfVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmIf[$i],true);
  1090. $x = str_replace($this->_ChrVal,$CurrVal,$Loc->PrmIf[$i]);
  1091. if ($this->f_Misc_CheckCondition($x)) {
  1092. if (isset($Loc->PrmThen[$i])) {
  1093. if ($Loc->PrmThenVar[$i]) $Loc->PrmThenVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmThen[$i],true);
  1094. $z = $Loc->PrmThen[$i];
  1095. }
  1096. $i = false;
  1097. } else {
  1098. $i++;
  1099. if ($i>$Loc->PrmIfNbr) {
  1100. if (isset($Loc->PrmLst['else'])) {
  1101. if ($Loc->PrmElseVar) $Loc->PrmElseVar = $this->meth_Merge_AutoVar($Loc->PrmLst['else'],true);
  1102. $z =$Loc->PrmLst['else'];
  1103. }
  1104. $i = false;
  1105. }
  1106. }
  1107. }
  1108. if ($z!==false) {
  1109. if ($ConvProtect) {
  1110. $CurrVal = str_replace($this->_ChrOpen,$this->_ChrProtect,$CurrVal); // TBS protection
  1111. $ConvProtect = false;
  1112. }
  1113. $CurrVal = str_replace($this->_ChrVal,$CurrVal,$z);
  1114. }
  1115. }
  1116. if (isset($Loc->PrmLst['file'])) {
  1117. $x = $Loc->PrmLst['file'];
  1118. if ($x===true) $x = $CurrVal;
  1119. $this->meth_Merge_AutoVar($x,false);
  1120. $x = trim(str_replace($this->_ChrVal,$CurrVal,$x));
  1121. $CurrVal = '';
  1122. if ($x!=='') {
  1123. if ($this->f_Misc_GetFile($CurrVal,$x,$this->_LastFile)) {
  1124. if (isset($Loc->PrmLst['getbody'])) $CurrVal = $this->f_Xml_GetPart($CurrVal,$Loc->PrmLst['getbody'],true);
  1125. if (isset($Loc->PrmLst['rename'])) $this->meth_Locator_Rename($CurrVal, $Loc->PrmLst['rename']);
  1126. } else {
  1127. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'the file \''.$x.'\' given by parameter file is not found or not readable.',true);
  1128. }
  1129. $ConvProtect = false;
  1130. }
  1131. }
  1132. if (isset($Loc->PrmLst['script'])) {// Include external PHP script
  1133. $x = $Loc->PrmLst['script'];
  1134. if ($x===true) $x = $CurrVal;
  1135. $this->meth_Merge_AutoVar($x,false);
  1136. $x = trim(str_replace($this->_ChrVal,$CurrVal,$x));
  1137. if ($x!=='') {
  1138. $this->_Subscript = $x;
  1139. $this->CurrPrm = &$Loc->PrmLst;
  1140. $sub = isset($Loc->PrmLst['subtpl']);
  1141. if ($sub) $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal);
  1142. if ($this->meth_Misc_RunSubscript($CurrVal,$Loc->PrmLst)===false) {
  1143. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'the file \''.$x.'\' given by parameter script is not found or not readable.',true);
  1144. }
  1145. if ($sub) $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal);
  1146. if (isset($Loc->PrmLst['getbody'])) $CurrVal = $this->f_Xml_GetPart($CurrVal,$Loc->PrmLst['getbody'],true);
  1147. if (isset($Loc->PrmLst['rename'])) $this->meth_Locator_Rename($CurrVal, $Loc->PrmLst['rename']);
  1148. unset($this->CurrPrm);
  1149. $ConvProtect = false;
  1150. }
  1151. }
  1152. if (isset($Loc->PrmLst['att'])) $this->f_Xml_AttFind($Txt,$Loc,true,$this->AttDelim);
  1153. // Case when it's an empty string
  1154. if ($CurrVal==='') {
  1155. if ($Loc->MagnetId===false) {
  1156. if (isset($Loc->PrmLst['.'])) {
  1157. $Loc->MagnetId = -1;
  1158. } elseif (isset($Loc->PrmLst['ifempty'])) {
  1159. $Loc->MagnetId = -2;
  1160. } elseif (isset($Loc->PrmLst['magnet'])) {
  1161. $Loc->MagnetId = 1;
  1162. $Loc->PosBeg0 = $Loc->PosBeg;
  1163. $Loc->PosEnd0 = $Loc->PosEnd;
  1164. if ($Loc->PrmLst['magnet']==='#') {
  1165. if (isset($Loc->AttBeg)) {
  1166. $Loc->MagnetId = -3;
  1167. } else {
  1168. $this->meth_Misc_Alert($Loc,'parameter \'magnet=#\' cannot be processed because parameter \'att\' is not set or the attribute is not found.',true);
  1169. }
  1170. } elseif (isset($Loc->PrmLst['mtype'])) {
  1171. switch ($Loc->PrmLst['mtype']) {
  1172. case 'm+m': $Loc->MagnetId = 2; break;
  1173. case 'm*': $Loc->MagnetId = 3; break;
  1174. case '*m': $Loc->MagnetId = 4; break;
  1175. }
  1176. }
  1177. } elseif (isset($Loc->PrmLst['attadd'])) {
  1178. // In order to delete extra space
  1179. $Loc->PosBeg0 = $Loc->PosBeg;
  1180. $Loc->PosEnd0 = $Loc->PosEnd;
  1181. $Loc->MagnetId = 5;
  1182. } else {
  1183. $Loc->MagnetId = 0;
  1184. }
  1185. }
  1186. switch ($Loc->MagnetId) {
  1187. case 0: break;
  1188. case -1: $CurrVal = '&nbsp;'; break; // Enables to avoid null cells in HTML tables
  1189. case -2: $CurrVal = $Loc->PrmLst['ifempty']; break;
  1190. case -3: $Loc->Enlarged = true; $Loc->PosBeg = $Loc->AttBegM; $Loc->PosEnd = $Loc->AttEnd; break;
  1191. case 1:
  1192. $Loc->Enlarged = true;
  1193. $this->f_Loc_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false);
  1194. break;
  1195. case 2:
  1196. $Loc->Enlarged = true;
  1197. $CurrVal = $this->f_Loc_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],true);
  1198. break;
  1199. case 3:
  1200. $Loc->Enlarged = true;
  1201. $Loc2 = $this->f_Xml_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,false,1,false);
  1202. if ($Loc2!==false) {
  1203. $Loc->PosBeg = $Loc2->PosBeg;
  1204. if ($Loc->PosEnd<$Loc2->PosEnd) $Loc->PosEnd = $Loc2->PosEnd;
  1205. }
  1206. break;
  1207. case 4:
  1208. $Loc->Enlarged = true;
  1209. $Loc2 = $this->f_Xml_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,true,1,false);
  1210. if ($Loc2!==false) $Loc->PosEnd = $Loc2->PosEnd;
  1211. break;
  1212. case 5:
  1213. $Loc->Enlarged = true;
  1214. if (substr($Txt,$Loc->PosBeg-1,1)==' ') $Loc->PosBeg--;
  1215. break;
  1216. }
  1217. $NewEnd = $Loc->PosBeg; // Useful when mtype='m+m'
  1218. } else {
  1219. if ($ConvProtect) $CurrVal = str_replace($this->_ChrOpen,$this->_ChrProtect,$CurrVal); // TBS protection
  1220. $NewEnd = $Loc->PosBeg + strlen($CurrVal);
  1221. }
  1222. $Txt = substr_replace($Txt,$CurrVal,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);
  1223. return $NewEnd; // Return the new end position of the field
  1224. }
  1225. function meth_Locator_FindBlockNext(&$Txt,$BlockName,$PosBeg,$ChrSub,$Mode,&$P1,&$FieldBefore) {
  1226. // Return the first block locator just after the PosBeg position
  1227. // Mode = 1 : Merge_Auto => doesn't save $Loc->BlockSrc, save the bounds of TBS Def tags instead, return also fields
  1228. // Mode = 2 : FindBlockLst or GetBlockSource => save $Loc->BlockSrc without TBS Def tags
  1229. // Mode = 3 : GetBlockSource => save $Loc->BlockSrc with TBS Def tags
  1230. $SearchDef = true;
  1231. $FirstField = false;
  1232. // Search for the first tag with parameter "block"
  1233. while ($SearchDef and ($Loc = $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,$ChrSub))) {
  1234. if (isset($Loc->PrmLst['block'])) {
  1235. if (isset($Loc->PrmLst['p1'])) {
  1236. if ($P1) return false;
  1237. $P1 = true;
  1238. }
  1239. $Block = $Loc->PrmLst['block'];
  1240. $SearchDef = false;
  1241. } elseif ($Mode===1) {
  1242. return $Loc;
  1243. } elseif ($FirstField===false) {
  1244. $FirstField = $Loc;
  1245. }
  1246. $PosBeg = $Loc->PosEnd;
  1247. }
  1248. if ($SearchDef) {
  1249. if ($FirstField!==false) $FieldBefore = true;
  1250. return false;
  1251. }
  1252. $Loc->PosDefBeg = -1;
  1253. if ($Block==='begin') { // Block definied using begin/end
  1254. if (($FirstField!==false) and ($FirstField->PosEnd<$Loc->PosBeg)) $FieldBefore = true;
  1255. $Opened = 1;
  1256. while ($Loc2 = $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,$ChrSub)) {
  1257. if (isset($Loc2->PrmLst['block'])) {
  1258. switch ($Loc2->PrmLst['block']) {
  1259. case 'end': $Opened--; break;
  1260. case 'begin': $Opened++; break;
  1261. }
  1262. if ($Opened==0) {
  1263. if ($Mode===1) {
  1264. $Loc->PosBeg2 = $Loc2->PosBeg;
  1265. $Loc->PosEnd2 = $Loc2->PosEnd;
  1266. } else {
  1267. if ($Mode===2) {
  1268. $Loc->BlockSrc = substr($Txt,$Loc->PosEnd+1,$Loc2->PosBeg-$Loc->PosEnd-1);
  1269. } else {
  1270. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$Loc2->PosEnd-$Loc->PosBeg+1);
  1271. }
  1272. $Loc->PosEnd = $Loc2->PosEnd;
  1273. }
  1274. $Loc->BlockFound = true;
  1275. return $Loc;
  1276. }
  1277. }
  1278. $PosBeg = $Loc2->PosEnd;
  1279. }
  1280. return $this->meth_Misc_Alert($Loc,'a least one tag with parameter \'block=end\' is missing.',false,'in block\'s definition');
  1281. }
  1282. if ($Mode===1) {
  1283. $Loc->PosBeg2 = false;
  1284. } else {
  1285. $beg = $Loc->PosBeg;
  1286. $end = $Loc->PosEnd;
  1287. if ($this->f_Loc_EnlargeToTag($Txt,$Loc,$Block,false)===false) return $this->meth_Misc_Alert($Loc,'at least one tag corresponding to '.$Loc->PrmLst['block'].' is not found. Check opening tags, closing tags and embedding levels.',false,'in block\'s definition');
  1288. if ($Loc->SubOk or ($Mode===3)) {
  1289. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);
  1290. $Loc->PosDefBeg = $beg - $Loc->PosBeg;
  1291. $Loc->PosDefEnd = $end - $Loc->PosBeg;
  1292. } else {
  1293. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$beg-$Loc->PosBeg).substr($Txt,$end+1,$Loc->PosEnd-$end);
  1294. }
  1295. }
  1296. $Loc->BlockFound = true;
  1297. if (($FirstField!==false) and ($FirstField->PosEnd<$Loc->PosBeg)) $FieldBefore = true;
  1298. return $Loc; // methods return by ref by default
  1299. }
  1300. function meth_Locator_Rename(&$Txt, $Replace) {
  1301. // Rename or delete TBS tags names
  1302. if (is_string($Replace)) $Replace = explode(',',$Replace);
  1303. foreach ($Replace as $x) {
  1304. if (is_string($x)) $x = explode('=', $x);
  1305. if (count($x)==2) {
  1306. $old = trim($x[0]);
  1307. $new = trim($x[1]);
  1308. if ($old!=='') {
  1309. if ($new==='') {
  1310. $q = false;
  1311. $s = 'clear';
  1312. $this->meth_Merge_Block($Txt, $old, $s, $q, false, false);
  1313. } else {
  1314. $old = $this->_ChrOpen.$old;
  1315. $old = array($old.'.', $old.' ', $old.';');
  1316. $new = $this->_ChrOpen.$new;
  1317. $new = array($new.'.', $new.' ', $new.';');
  1318. $Txt = str_replace($old,$new,$Txt);
  1319. }
  1320. }
  1321. }
  1322. }
  1323. }
  1324. function meth_Locator_FindBlockLst(&$Txt,$BlockName,$Pos,$SpePrm) {
  1325. // Return a locator object covering all block definitions, even if there is no block definition found.
  1326. $LocR = &new clsTbsLocator;
  1327. $LocR->P1 = false;
  1328. $LocR->FieldOutside = false;
  1329. $LocR->FOStop = false;
  1330. $LocR->BDefLst = array();
  1331. $LocR->NoData = false;
  1332. $LocR->Special = false;
  1333. $LocR->HeaderFound = false;
  1334. $LocR->FooterFound = false;
  1335. $LocR->SerialEmpty = false;
  1336. $LocR->GrpBreak = false; // Only for plug-ins
  1337. $LocR->WhenFound = false;
  1338. $LocR->WhenDefault = false;
  1339. $LocR->SectionNbr = 0; // Normal sections
  1340. $LocR->SectionLst = array(); // 1 to SectionNbr
  1341. $BDef = false;
  1342. $ParentLst = array();
  1343. $Pid = 0;
  1344. do {
  1345. if ($BlockName==='') {
  1346. $Loc = false;
  1347. } else {
  1348. $Loc = $this->meth_Locator_FindBlockNext($Txt,$BlockName,$Pos,'.',2,$LocR->P1,$LocR->FieldOutside);
  1349. }
  1350. if ($Loc===false) {
  1351. if ($Pid>0) { // parentgrp mode => disconnect $Txt from the source
  1352. $Parent = &$ParentLst[$Pid];
  1353. $Src = $Txt;
  1354. $Txt = &$Parent->Txt;
  1355. if ($LocR->BlockFound) {
  1356. // Redefine the Header block
  1357. $Parent->Src = substr($Src,0,$LocR->PosBeg);
  1358. // Add a Footer block
  1359. $BDef = &$this->meth_Locator_SectionNewBDef($LocR,$BlockName,substr($Src,$LocR->PosEnd+1),$Parent->Prm);
  1360. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'F',$Parent->Fld,'parentgrp');
  1361. }
  1362. // Now go down to previous level
  1363. $Pos = $Parent->Pos;
  1364. $LocR->PosBeg = $Parent->Beg;
  1365. $LocR->PosEnd = $Parent->End;
  1366. $LocR->BlockFound = true;
  1367. unset($Parent);
  1368. unset($ParentLst[$Pid]);
  1369. $Pid--;
  1370. $Loc = true;
  1371. }
  1372. } else {
  1373. $Pos = $Loc->PosEnd;
  1374. // Define the block limits
  1375. if ($LocR->BlockFound) {
  1376. if ( $LocR->PosBeg > $Loc->PosBeg ) $LocR->PosBeg = $Loc->PosBeg;
  1377. if ( $LocR->PosEnd < $Loc->PosEnd ) $LocR->PosEnd = $Loc->PosEnd;
  1378. } else {
  1379. $LocR->BlockFound = true;
  1380. $LocR->PosBeg = $Loc->PosBeg;
  1381. $LocR->PosEnd = $Loc->PosEnd;
  1382. }
  1383. // Merge block parameters
  1384. if (count($Loc->PrmLst)>0) $LocR->PrmLst = array_merge($LocR->PrmLst,$Loc->PrmLst);
  1385. // Force dynamic parameter to be cachable
  1386. if ($Loc->PosDefBeg>=0) {
  1387. $dynprm = array('when','headergrp','footergrp','parentgrp');
  1388. foreach($dynprm as $dp) {
  1389. $n = 0;
  1390. if ((isset($Loc->PrmLst[$dp])) and (strpos($Loc->PrmLst[$dp],$this->_ChrOpen.$BlockName)!==false)) {
  1391. $n++;
  1392. if ($n==1) {
  1393. $len = $Loc->PosDefEnd - $Loc->PosDefBeg + 1;
  1394. $x = substr($Loc->BlockSrc,$Loc->PosDefBe

Large files files are truncated, but you can click here to view the full file