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