smarty_internal_utility.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: smarty_internal_utility.php
  5. * SVN: $Id: $
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * For questions, help, comments, discussion, etc., please join the
  22. * Smarty mailing list. Send a blank e-mail to
  23. * smarty-discussion-subscribe@googlegroups.com
  24. *
  25. * @link http://www.smarty.net/
  26. * @copyright 2008 New Digital Group, Inc.
  27. * @author Monte Ohrt <monte at ohrt dot com>
  28. * @author Uwe Tews
  29. * @package Smarty
  30. * @subpackage PluginsInternal
  31. * @version 3-SVN$Rev: 3286 $
  32. */
  33. /**
  34. * Utility class
  35. *
  36. * @package Smarty
  37. * @subpackage Security
  38. */
  39. class Smarty_Internal_Utility {
  40. /**
  41. * private constructor to prevent calls creation of new instances
  42. */
  43. private final function __construct()
  44. {
  45. // intentionally left blank
  46. }
  47. /**
  48. * Compile all template files
  49. *
  50. * @param string $extension template file name extension
  51. * @param bool $force_compile force all to recompile
  52. * @param int $time_limit set maximum execution time
  53. * @param int $max_errors set maximum allowed errors
  54. * @param Smarty $smarty Smarty instance
  55. * @return integer number of template files compiled
  56. */
  57. public static function compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, Smarty $smarty)
  58. {
  59. // switch off time limit
  60. if (function_exists('set_time_limit')) {
  61. @set_time_limit($time_limit);
  62. }
  63. $smarty->force_compile = $force_compile;
  64. $_count = 0;
  65. $_error_count = 0;
  66. // loop over array of template directories
  67. foreach($smarty->getTemplateDir() as $_dir) {
  68. $_compileDirs = new RecursiveDirectoryIterator($_dir);
  69. $_compile = new RecursiveIteratorIterator($_compileDirs);
  70. foreach ($_compile as $_fileinfo) {
  71. if (substr($_fileinfo->getBasename(),0,1) == '.' || strpos($_fileinfo, '.svn') !== false) continue;
  72. $_file = $_fileinfo->getFilename();
  73. if (!substr_compare($_file, $extention, - strlen($extention)) == 0) continue;
  74. if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
  75. $_template_file = $_file;
  76. } else {
  77. $_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
  78. }
  79. echo '<br>', $_dir, '---', $_template_file;
  80. flush();
  81. $_start_time = microtime(true);
  82. try {
  83. $_tpl = $smarty->createTemplate($_template_file,null,null,null,false);
  84. if ($_tpl->mustCompile()) {
  85. $_tpl->compileTemplateSource();
  86. $_count++;
  87. echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
  88. flush();
  89. } else {
  90. echo ' is up to date';
  91. flush();
  92. }
  93. }
  94. catch (Exception $e) {
  95. echo 'Error: ', $e->getMessage(), "<br><br>";
  96. $_error_count++;
  97. }
  98. // free memory
  99. $smarty->template_objects = array();
  100. $_tpl->smarty->template_objects = array();
  101. $_tpl = null;
  102. if ($max_errors !== null && $_error_count == $max_errors) {
  103. echo '<br><br>too many errors';
  104. exit();
  105. }
  106. }
  107. }
  108. return $_count;
  109. }
  110. /**
  111. * Compile all config files
  112. *
  113. * @param string $extension config file name extension
  114. * @param bool $force_compile force all to recompile
  115. * @param int $time_limit set maximum execution time
  116. * @param int $max_errors set maximum allowed errors
  117. * @param Smarty $smarty Smarty instance
  118. * @return integer number of config files compiled
  119. */
  120. public static function compileAllConfig($extention, $force_compile, $time_limit, $max_errors, Smarty $smarty)
  121. {
  122. // switch off time limit
  123. if (function_exists('set_time_limit')) {
  124. @set_time_limit($time_limit);
  125. }
  126. $smarty->force_compile = $force_compile;
  127. $_count = 0;
  128. $_error_count = 0;
  129. // loop over array of template directories
  130. foreach($smarty->getConfigDir() as $_dir) {
  131. $_compileDirs = new RecursiveDirectoryIterator($_dir);
  132. $_compile = new RecursiveIteratorIterator($_compileDirs);
  133. foreach ($_compile as $_fileinfo) {
  134. if (substr($_fileinfo->getBasename(),0,1) == '.' || strpos($_fileinfo, '.svn') !== false) continue;
  135. $_file = $_fileinfo->getFilename();
  136. if (!substr_compare($_file, $extention, - strlen($extention)) == 0) continue;
  137. if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
  138. $_config_file = $_file;
  139. } else {
  140. $_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
  141. }
  142. echo '<br>', $_dir, '---', $_config_file;
  143. flush();
  144. $_start_time = microtime(true);
  145. try {
  146. $_config = new Smarty_Internal_Config($_config_file, $smarty);
  147. if ($_config->mustCompile()) {
  148. $_config->compileConfigSource();
  149. $_count++;
  150. echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
  151. flush();
  152. } else {
  153. echo ' is up to date';
  154. flush();
  155. }
  156. }
  157. catch (Exception $e) {
  158. echo 'Error: ', $e->getMessage(), "<br><br>";
  159. $_error_count++;
  160. }
  161. if ($max_errors !== null && $_error_count == $max_errors) {
  162. echo '<br><br>too many errors';
  163. exit();
  164. }
  165. }
  166. }
  167. return $_count;
  168. }
  169. /**
  170. * Delete compiled template file
  171. *
  172. * @param string $resource_name template name
  173. * @param string $compile_id compile id
  174. * @param integer $exp_time expiration time
  175. * @param Smarty $smarty Smarty instance
  176. * @return integer number of template files deleted
  177. */
  178. public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)
  179. {
  180. $_compile_dir = $smarty->getCompileDir();
  181. $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
  182. $_dir_sep = $smarty->use_sub_dirs ? DS : '^';
  183. if (isset($resource_name)) {
  184. $_save_stat = $smarty->caching;
  185. $smarty->caching = false;
  186. $tpl = new $smarty->template_class($resource_name, $smarty);
  187. $smarty->caching = $_save_stat;
  188. // remove from template cache
  189. $tpl->source; // have the template registered before unset()
  190. if ($smarty->allow_ambiguous_resources) {
  191. $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
  192. } else {
  193. $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
  194. }
  195. if (isset($_templateId[150])) {
  196. $_templateId = sha1($_templateId);
  197. }
  198. unset($smarty->template_objects[$_templateId]);
  199. if ($tpl->source->exists) {
  200. $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
  201. $_resource_part_1_length = strlen($_resource_part_1);
  202. } else {
  203. return 0;
  204. }
  205. $_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);
  206. $_resource_part_2_length = strlen($_resource_part_2);
  207. }
  208. $_dir = $_compile_dir;
  209. if ($smarty->use_sub_dirs && isset($_compile_id)) {
  210. $_dir .= $_compile_id . $_dir_sep;
  211. }
  212. if (isset($_compile_id)) {
  213. $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep;
  214. $_compile_id_part_length = strlen($_compile_id_part);
  215. }
  216. $_count = 0;
  217. try {
  218. $_compileDirs = new RecursiveDirectoryIterator($_dir);
  219. // NOTE: UnexpectedValueException thrown for PHP >= 5.3
  220. } catch (Exception $e) {
  221. return 0;
  222. }
  223. $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
  224. foreach ($_compile as $_file) {
  225. if (substr($_file->getBasename(), 0, 1) == '.' || strpos($_file, '.svn') !== false)
  226. continue;
  227. $_filepath = (string) $_file;
  228. if ($_file->isDir()) {
  229. if (!$_compile->isDot()) {
  230. // delete folder if empty
  231. @rmdir($_file->getPathname());
  232. }
  233. } else {
  234. $unlink = false;
  235. if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length)))
  236. && (!isset($resource_name)
  237. || (isset($_filepath[$_resource_part_1_length])
  238. && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0)
  239. || (isset($_filepath[$_resource_part_2_length])
  240. && substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) {
  241. if (isset($exp_time)) {
  242. if (time() - @filemtime($_filepath) >= $exp_time) {
  243. $unlink = true;
  244. }
  245. } else {
  246. $unlink = true;
  247. }
  248. }
  249. if ($unlink && @unlink($_filepath)) {
  250. $_count++;
  251. }
  252. }
  253. }
  254. // clear compiled cache
  255. Smarty_Resource::$sources = array();
  256. Smarty_Resource::$compileds = array();
  257. return $_count;
  258. }
  259. /**
  260. * Return array of tag/attributes of all tags used by an template
  261. *
  262. * @param Smarty_Internal_Template $templae template object
  263. * @return array of tag/attributes
  264. */
  265. public static function getTags(Smarty_Internal_Template $template)
  266. {
  267. $template->smarty->get_used_tags = true;
  268. $template->compileTemplateSource();
  269. return $template->used_tags;
  270. }
  271. /**
  272. * diagnose Smarty setup
  273. *
  274. * If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
  275. *
  276. * @param Smarty $smarty Smarty instance to test
  277. * @param array $errors array to push results into rather than outputting them
  278. * @return bool status, true if everything is fine, false else
  279. */
  280. public static function testInstall(Smarty $smarty, &$errors=null)
  281. {
  282. $status = true;
  283. if ($errors === null) {
  284. echo "<PRE>\n";
  285. echo "Smarty Installation test...\n";
  286. echo "Testing template directory...\n";
  287. }
  288. $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
  289. // test if all registered template_dir are accessible
  290. foreach($smarty->getTemplateDir() as $template_dir) {
  291. $_template_dir = $template_dir;
  292. $template_dir = realpath($template_dir);
  293. // resolve include_path or fail existance
  294. if (!$template_dir) {
  295. if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
  296. // try PHP include_path
  297. if ($_stream_resolve_include_path) {
  298. $template_dir = stream_resolve_include_path($_template_dir);
  299. } else {
  300. $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir);
  301. }
  302. if ($template_dir !== false) {
  303. if ($errors === null) {
  304. echo "$template_dir is OK.\n";
  305. }
  306. continue;
  307. } else {
  308. $status = false;
  309. $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
  310. if ($errors === null) {
  311. echo $message . ".\n";
  312. } else {
  313. $errors['template_dir'] = $message;
  314. }
  315. continue;
  316. }
  317. } else {
  318. $status = false;
  319. $message = "FAILED: $_template_dir does not exist";
  320. if ($errors === null) {
  321. echo $message . ".\n";
  322. } else {
  323. $errors['template_dir'] = $message;
  324. }
  325. continue;
  326. }
  327. }
  328. if (!is_dir($template_dir)) {
  329. $status = false;
  330. $message = "FAILED: $template_dir is not a directory";
  331. if ($errors === null) {
  332. echo $message . ".\n";
  333. } else {
  334. $errors['template_dir'] = $message;
  335. }
  336. } elseif (!is_readable($template_dir)) {
  337. $status = false;
  338. $message = "FAILED: $template_dir is not readable";
  339. if ($errors === null) {
  340. echo $message . ".\n";
  341. } else {
  342. $errors['template_dir'] = $message;
  343. }
  344. } else {
  345. if ($errors === null) {
  346. echo "$template_dir is OK.\n";
  347. }
  348. }
  349. }
  350. if ($errors === null) {
  351. echo "Testing compile directory...\n";
  352. }
  353. // test if registered compile_dir is accessible
  354. $__compile_dir = $smarty->getCompileDir();
  355. $_compile_dir = realpath($__compile_dir);
  356. if (!$_compile_dir) {
  357. $status = false;
  358. $message = "FAILED: {$__compile_dir} does not exist";
  359. if ($errors === null) {
  360. echo $message . ".\n";
  361. } else {
  362. $errors['compile_dir'] = $message;
  363. }
  364. } elseif (!is_dir($_compile_dir)) {
  365. $status = false;
  366. $message = "FAILED: {$_compile_dir} is not a directory";
  367. if ($errors === null) {
  368. echo $message . ".\n";
  369. } else {
  370. $errors['compile_dir'] = $message;
  371. }
  372. } elseif (!is_readable($_compile_dir)) {
  373. $status = false;
  374. $message = "FAILED: {$_compile_dir} is not readable";
  375. if ($errors === null) {
  376. echo $message . ".\n";
  377. } else {
  378. $errors['compile_dir'] = $message;
  379. }
  380. } elseif (!is_writable($_compile_dir)) {
  381. $status = false;
  382. $message = "FAILED: {$_compile_dir} is not writable";
  383. if ($errors === null) {
  384. echo $message . ".\n";
  385. } else {
  386. $errors['compile_dir'] = $message;
  387. }
  388. } else {
  389. if ($errors === null) {
  390. echo "{$_compile_dir} is OK.\n";
  391. }
  392. }
  393. if ($errors === null) {
  394. echo "Testing plugins directory...\n";
  395. }
  396. // test if all registered plugins_dir are accessible
  397. // and if core plugins directory is still registered
  398. $_core_plugins_dir = realpath(dirname(__FILE__) .'/../plugins');
  399. $_core_plugins_available = false;
  400. foreach($smarty->getPluginsDir() as $plugin_dir) {
  401. $_plugin_dir = $plugin_dir;
  402. $plugin_dir = realpath($plugin_dir);
  403. // resolve include_path or fail existance
  404. if (!$plugin_dir) {
  405. if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
  406. // try PHP include_path
  407. if ($_stream_resolve_include_path) {
  408. $plugin_dir = stream_resolve_include_path($_plugin_dir);
  409. } else {
  410. $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
  411. }
  412. if ($plugin_dir !== false) {
  413. if ($errors === null) {
  414. echo "$plugin_dir is OK.\n";
  415. }
  416. continue;
  417. } else {
  418. $status = false;
  419. $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
  420. if ($errors === null) {
  421. echo $message . ".\n";
  422. } else {
  423. $errors['plugins_dir'] = $message;
  424. }
  425. continue;
  426. }
  427. } else {
  428. $status = false;
  429. $message = "FAILED: $_plugin_dir does not exist";
  430. if ($errors === null) {
  431. echo $message . ".\n";
  432. } else {
  433. $errors['plugins_dir'] = $message;
  434. }
  435. continue;
  436. }
  437. }
  438. if (!is_dir($plugin_dir)) {
  439. $status = false;
  440. $message = "FAILED: $plugin_dir is not a directory";
  441. if ($errors === null) {
  442. echo $message . ".\n";
  443. } else {
  444. $errors['plugins_dir'] = $message;
  445. }
  446. } elseif (!is_readable($plugin_dir)) {
  447. $status = false;
  448. $message = "FAILED: $plugin_dir is not readable";
  449. if ($errors === null) {
  450. echo $message . ".\n";
  451. } else {
  452. $errors['plugins_dir'] = $message;
  453. }
  454. } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
  455. $_core_plugins_available = true;
  456. if ($errors === null) {
  457. echo "$plugin_dir is OK.\n";
  458. }
  459. } else {
  460. if ($errors === null) {
  461. echo "$plugin_dir is OK.\n";
  462. }
  463. }
  464. }
  465. if (!$_core_plugins_available) {
  466. $status = false;
  467. $message = "WARNING: Smarty's own libs/plugins is not available";
  468. if ($errors === null) {
  469. echo $message . ".\n";
  470. } elseif (!isset($errors['plugins_dir'])) {
  471. $errors['plugins_dir'] = $message;
  472. }
  473. }
  474. if ($errors === null) {
  475. echo "Testing cache directory...\n";
  476. }
  477. // test if all registered cache_dir is accessible
  478. $__cache_dir = $smarty->getCacheDir();
  479. $_cache_dir = realpath($__cache_dir);
  480. if (!$_cache_dir) {
  481. $status = false;
  482. $message = "FAILED: {$__cache_dir} does not exist";
  483. if ($errors === null) {
  484. echo $message . ".\n";
  485. } else {
  486. $errors['cache_dir'] = $message;
  487. }
  488. } elseif (!is_dir($_cache_dir)) {
  489. $status = false;
  490. $message = "FAILED: {$_cache_dir} is not a directory";
  491. if ($errors === null) {
  492. echo $message . ".\n";
  493. } else {
  494. $errors['cache_dir'] = $message;
  495. }
  496. } elseif (!is_readable($_cache_dir)) {
  497. $status = false;
  498. $message = "FAILED: {$_cache_dir} is not readable";
  499. if ($errors === null) {
  500. echo $message . ".\n";
  501. } else {
  502. $errors['cache_dir'] = $message;
  503. }
  504. } elseif (!is_writable($_cache_dir)) {
  505. $status = false;
  506. $message = "FAILED: {$_cache_dir} is not writable";
  507. if ($errors === null) {
  508. echo $message . ".\n";
  509. } else {
  510. $errors['cache_dir'] = $message;
  511. }
  512. } else {
  513. if ($errors === null) {
  514. echo "{$_cache_dir} is OK.\n";
  515. }
  516. }
  517. if ($errors === null) {
  518. echo "Testing configs directory...\n";
  519. }
  520. // test if all registered config_dir are accessible
  521. foreach($smarty->getConfigDir() as $config_dir) {
  522. $_config_dir = $config_dir;
  523. $config_dir = realpath($config_dir);
  524. // resolve include_path or fail existance
  525. if (!$config_dir) {
  526. if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
  527. // try PHP include_path
  528. if ($_stream_resolve_include_path) {
  529. $config_dir = stream_resolve_include_path($_config_dir);
  530. } else {
  531. $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir);
  532. }
  533. if ($config_dir !== false) {
  534. if ($errors === null) {
  535. echo "$config_dir is OK.\n";
  536. }
  537. continue;
  538. } else {
  539. $status = false;
  540. $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
  541. if ($errors === null) {
  542. echo $message . ".\n";
  543. } else {
  544. $errors['config_dir'] = $message;
  545. }
  546. continue;
  547. }
  548. } else {
  549. $status = false;
  550. $message = "FAILED: $_config_dir does not exist";
  551. if ($errors === null) {
  552. echo $message . ".\n";
  553. } else {
  554. $errors['config_dir'] = $message;
  555. }
  556. continue;
  557. }
  558. }
  559. if (!is_dir($config_dir)) {
  560. $status = false;
  561. $message = "FAILED: $config_dir is not a directory";
  562. if ($errors === null) {
  563. echo $message . ".\n";
  564. } else {
  565. $errors['config_dir'] = $message;
  566. }
  567. } elseif (!is_readable($config_dir)) {
  568. $status = false;
  569. $message = "FAILED: $config_dir is not readable";
  570. if ($errors === null) {
  571. echo $message . ".\n";
  572. } else {
  573. $errors['config_dir'] = $message;
  574. }
  575. } else {
  576. if ($errors === null) {
  577. echo "$config_dir is OK.\n";
  578. }
  579. }
  580. }
  581. if ($errors === null) {
  582. echo "Testing sysplugin files...\n";
  583. }
  584. // test if sysplugins are available
  585. $source = SMARTY_SYSPLUGINS_DIR;
  586. if (is_dir($source)) {
  587. $expected = array(
  588. "smarty_cacheresource.php" => true,
  589. "smarty_cacheresource_custom.php" => true,
  590. "smarty_cacheresource_keyvaluestore.php" => true,
  591. "smarty_config_source.php" => true,
  592. "smarty_internal_cacheresource_file.php" => true,
  593. "smarty_internal_compile_append.php" => true,
  594. "smarty_internal_compile_assign.php" => true,
  595. "smarty_internal_compile_block.php" => true,
  596. "smarty_internal_compile_break.php" => true,
  597. "smarty_internal_compile_call.php" => true,
  598. "smarty_internal_compile_capture.php" => true,
  599. "smarty_internal_compile_config_load.php" => true,
  600. "smarty_internal_compile_continue.php" => true,
  601. "smarty_internal_compile_debug.php" => true,
  602. "smarty_internal_compile_eval.php" => true,
  603. "smarty_internal_compile_extends.php" => true,
  604. "smarty_internal_compile_for.php" => true,
  605. "smarty_internal_compile_foreach.php" => true,
  606. "smarty_internal_compile_function.php" => true,
  607. "smarty_internal_compile_if.php" => true,
  608. "smarty_internal_compile_include.php" => true,
  609. "smarty_internal_compile_include_php.php" => true,
  610. "smarty_internal_compile_insert.php" => true,
  611. "smarty_internal_compile_ldelim.php" => true,
  612. "smarty_internal_compile_nocache.php" => true,
  613. "smarty_internal_compile_private_block_plugin.php" => true,
  614. "smarty_internal_compile_private_function_plugin.php" => true,
  615. "smarty_internal_compile_private_modifier.php" => true,
  616. "smarty_internal_compile_private_object_block_function.php" => true,
  617. "smarty_internal_compile_private_object_function.php" => true,
  618. "smarty_internal_compile_private_print_expression.php" => true,
  619. "smarty_internal_compile_private_registered_block.php" => true,
  620. "smarty_internal_compile_private_registered_function.php" => true,
  621. "smarty_internal_compile_private_special_variable.php" => true,
  622. "smarty_internal_compile_rdelim.php" => true,
  623. "smarty_internal_compile_section.php" => true,
  624. "smarty_internal_compile_setfilter.php" => true,
  625. "smarty_internal_compile_while.php" => true,
  626. "smarty_internal_compilebase.php" => true,
  627. "smarty_internal_config.php" => true,
  628. "smarty_internal_config_file_compiler.php" => true,
  629. "smarty_internal_configfilelexer.php" => true,
  630. "smarty_internal_configfileparser.php" => true,
  631. "smarty_internal_data.php" => true,
  632. "smarty_internal_debug.php" => true,
  633. "smarty_internal_filter_handler.php" => true,
  634. "smarty_internal_function_call_handler.php" => true,
  635. "smarty_internal_get_include_path.php" => true,
  636. "smarty_internal_nocache_insert.php" => true,
  637. "smarty_internal_parsetree.php" => true,
  638. "smarty_internal_resource_eval.php" => true,
  639. "smarty_internal_resource_extends.php" => true,
  640. "smarty_internal_resource_file.php" => true,
  641. "smarty_internal_resource_registered.php" => true,
  642. "smarty_internal_resource_stream.php" => true,
  643. "smarty_internal_resource_string.php" => true,
  644. "smarty_internal_smartytemplatecompiler.php" => true,
  645. "smarty_internal_template.php" => true,
  646. "smarty_internal_templatebase.php" => true,
  647. "smarty_internal_templatecompilerbase.php" => true,
  648. "smarty_internal_templatelexer.php" => true,
  649. "smarty_internal_templateparser.php" => true,
  650. "smarty_internal_utility.php" => true,
  651. "smarty_internal_write_file.php" => true,
  652. "smarty_resource.php" => true,
  653. "smarty_resource_custom.php" => true,
  654. "smarty_resource_recompiled.php" => true,
  655. "smarty_resource_uncompiled.php" => true,
  656. "smarty_security.php" => true,
  657. );
  658. $iterator = new DirectoryIterator($source);
  659. foreach ($iterator as $file) {
  660. if (!$file->isDot()) {
  661. $filename = $file->getFilename();
  662. if (isset($expected[$filename])) {
  663. unset($expected[$filename]);
  664. }
  665. }
  666. }
  667. if ($expected) {
  668. $status = false;
  669. $message = "FAILED: files missing from libs/sysplugins: ". join(', ', array_keys($expected));
  670. if ($errors === null) {
  671. echo $message . ".\n";
  672. } else {
  673. $errors['sysplugins'] = $message;
  674. }
  675. } elseif ($errors === null) {
  676. echo "... OK\n";
  677. }
  678. } else {
  679. $status = false;
  680. $message = "FAILED: ". SMARTY_SYSPLUGINS_DIR .' is not a directory';
  681. if ($errors === null) {
  682. echo $message . ".\n";
  683. } else {
  684. $errors['sysplugins_dir_constant'] = $message;
  685. }
  686. }
  687. if ($errors === null) {
  688. echo "Testing plugin files...\n";
  689. }
  690. // test if core plugins are available
  691. $source = SMARTY_PLUGINS_DIR;
  692. if (is_dir($source)) {
  693. $expected = array(
  694. "block.textformat.php" => true,
  695. "function.counter.php" => true,
  696. "function.cycle.php" => true,
  697. "function.fetch.php" => true,
  698. "function.html_checkboxes.php" => true,
  699. "function.html_image.php" => true,
  700. "function.html_options.php" => true,
  701. "function.html_radios.php" => true,
  702. "function.html_select_date.php" => true,
  703. "function.html_select_time.php" => true,
  704. "function.html_table.php" => true,
  705. "function.mailto.php" => true,
  706. "function.math.php" => true,
  707. "modifier.capitalize.php" => true,
  708. "modifier.date_format.php" => true,
  709. "modifier.debug_print_var.php" => true,
  710. "modifier.escape.php" => true,
  711. "modifier.regex_replace.php" => true,
  712. "modifier.replace.php" => true,
  713. "modifier.spacify.php" => true,
  714. "modifier.truncate.php" => true,
  715. "modifiercompiler.cat.php" => true,
  716. "modifiercompiler.count_characters.php" => true,
  717. "modifiercompiler.count_paragraphs.php" => true,
  718. "modifiercompiler.count_sentences.php" => true,
  719. "modifiercompiler.count_words.php" => true,
  720. "modifiercompiler.default.php" => true,
  721. "modifiercompiler.escape.php" => true,
  722. "modifiercompiler.from_charset.php" => true,
  723. "modifiercompiler.indent.php" => true,
  724. "modifiercompiler.lower.php" => true,
  725. "modifiercompiler.noprint.php" => true,
  726. "modifiercompiler.string_format.php" => true,
  727. "modifiercompiler.strip.php" => true,
  728. "modifiercompiler.strip_tags.php" => true,
  729. "modifiercompiler.to_charset.php" => true,
  730. "modifiercompiler.unescape.php" => true,
  731. "modifiercompiler.upper.php" => true,
  732. "modifiercompiler.wordwrap.php" => true,
  733. "outputfilter.trimwhitespace.php" => true,
  734. "shared.escape_special_chars.php" => true,
  735. "shared.literal_compiler_param.php" => true,
  736. "shared.make_timestamp.php" => true,
  737. "shared.mb_str_replace.php" => true,
  738. "shared.mb_unicode.php" => true,
  739. "shared.mb_wordwrap.php" => true,
  740. "variablefilter.htmlspecialchars.php" => true,
  741. );
  742. $iterator = new DirectoryIterator($source);
  743. foreach ($iterator as $file) {
  744. if (!$file->isDot()) {
  745. $filename = $file->getFilename();
  746. if (isset($expected[$filename])) {
  747. unset($expected[$filename]);
  748. }
  749. }
  750. }
  751. if ($expected) {
  752. $status = false;
  753. $message = "FAILED: files missing from libs/plugins: ". join(', ', array_keys($expected));
  754. if ($errors === null) {
  755. echo $message . ".\n";
  756. } else {
  757. $errors['plugins'] = $message;
  758. }
  759. } elseif ($errors === null) {
  760. echo "... OK\n";
  761. }
  762. } else {
  763. $status = false;
  764. $message = "FAILED: ". SMARTY_PLUGINS_DIR .' is not a directory';
  765. if ($errors === null) {
  766. echo $message . ".\n";
  767. } else {
  768. $errors['plugins_dir_constant'] = $message;
  769. }
  770. }
  771. if ($errors === null) {
  772. echo "Tests complete.\n";
  773. echo "</PRE>\n";
  774. }
  775. return $status;
  776. }
  777. }
  778. ?>