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