smarty_internal_utility.php 33 KB

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