PageRenderTime 60ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/core/Associates/Smarty/sysplugins/smarty_internal_utility.php

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