gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

smarty_internal_testinstall.php (26244B)


      1 <?php
      2 /**
      3  * Smarty Internal TestInstall
      4  * Test Smarty installation
      5  *
      6  * @package    Smarty
      7  * @subpackage Utilities
      8  * @author     Uwe Tews
      9  */
     10 /**
     11  * TestInstall class
     12  *
     13  * @package    Smarty
     14  * @subpackage Utilities
     15  */
     16 class Smarty_Internal_TestInstall
     17 {
     18     /**
     19      * diagnose Smarty setup
     20      * If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
     21      *
     22      * @param  Smarty $smarty Smarty instance to test
     23      * @param  array  $errors array to push results into rather than outputting them
     24      *
     25      * @return bool   status, true if everything is fine, false else
     26      */
     27     public static function testInstall(Smarty $smarty, &$errors = null)
     28     {
     29         $status = true;
     30 
     31         if ($errors === null) {
     32             echo "<PRE>\n";
     33             echo "Smarty Installation test...\n";
     34             echo "Testing template directory...\n";
     35         }
     36 
     37         $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
     38 
     39         // test if all registered template_dir are accessible
     40         foreach ($smarty->getTemplateDir() as $template_dir) {
     41             $_template_dir = $template_dir;
     42             $template_dir = realpath($template_dir);
     43             // resolve include_path or fail existence
     44             if (!$template_dir) {
     45                 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
     46                     // try PHP include_path
     47                     if ($_stream_resolve_include_path) {
     48                         $template_dir = stream_resolve_include_path($_template_dir);
     49                     } else {
     50                         $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir);
     51                     }
     52 
     53                     if ($template_dir !== false) {
     54                         if ($errors === null) {
     55                             echo "$template_dir is OK.\n";
     56                         }
     57 
     58                         continue;
     59                     } else {
     60                         $status = false;
     61                         $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
     62                         if ($errors === null) {
     63                             echo $message . ".\n";
     64                         } else {
     65                             $errors['template_dir'] = $message;
     66                         }
     67 
     68                         continue;
     69                     }
     70                 } else {
     71                     $status = false;
     72                     $message = "FAILED: $_template_dir does not exist";
     73                     if ($errors === null) {
     74                         echo $message . ".\n";
     75                     } else {
     76                         $errors['template_dir'] = $message;
     77                     }
     78 
     79                     continue;
     80                 }
     81             }
     82 
     83             if (!is_dir($template_dir)) {
     84                 $status = false;
     85                 $message = "FAILED: $template_dir is not a directory";
     86                 if ($errors === null) {
     87                     echo $message . ".\n";
     88                 } else {
     89                     $errors['template_dir'] = $message;
     90                 }
     91             } elseif (!is_readable($template_dir)) {
     92                 $status = false;
     93                 $message = "FAILED: $template_dir is not readable";
     94                 if ($errors === null) {
     95                     echo $message . ".\n";
     96                 } else {
     97                     $errors['template_dir'] = $message;
     98                 }
     99             } else {
    100                 if ($errors === null) {
    101                     echo "$template_dir is OK.\n";
    102                 }
    103             }
    104         }
    105 
    106         if ($errors === null) {
    107             echo "Testing compile directory...\n";
    108         }
    109 
    110         // test if registered compile_dir is accessible
    111         $__compile_dir = $smarty->getCompileDir();
    112         $_compile_dir = realpath($__compile_dir);
    113         if (!$_compile_dir) {
    114             $status = false;
    115             $message = "FAILED: {$__compile_dir} does not exist";
    116             if ($errors === null) {
    117                 echo $message . ".\n";
    118             } else {
    119                 $errors['compile_dir'] = $message;
    120             }
    121         } elseif (!is_dir($_compile_dir)) {
    122             $status = false;
    123             $message = "FAILED: {$_compile_dir} is not a directory";
    124             if ($errors === null) {
    125                 echo $message . ".\n";
    126             } else {
    127                 $errors['compile_dir'] = $message;
    128             }
    129         } elseif (!is_readable($_compile_dir)) {
    130             $status = false;
    131             $message = "FAILED: {$_compile_dir} is not readable";
    132             if ($errors === null) {
    133                 echo $message . ".\n";
    134             } else {
    135                 $errors['compile_dir'] = $message;
    136             }
    137         } elseif (!is_writable($_compile_dir)) {
    138             $status = false;
    139             $message = "FAILED: {$_compile_dir} is not writable";
    140             if ($errors === null) {
    141                 echo $message . ".\n";
    142             } else {
    143                 $errors['compile_dir'] = $message;
    144             }
    145         } else {
    146             if ($errors === null) {
    147                 echo "{$_compile_dir} is OK.\n";
    148             }
    149         }
    150 
    151         if ($errors === null) {
    152             echo "Testing plugins directory...\n";
    153         }
    154 
    155         // test if all registered plugins_dir are accessible
    156         // and if core plugins directory is still registered
    157         $_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins');
    158         $_core_plugins_available = false;
    159         foreach ($smarty->getPluginsDir() as $plugin_dir) {
    160             $_plugin_dir = $plugin_dir;
    161             $plugin_dir = realpath($plugin_dir);
    162             // resolve include_path or fail existence
    163             if (!$plugin_dir) {
    164                 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
    165                     // try PHP include_path
    166                     if ($_stream_resolve_include_path) {
    167                         $plugin_dir = stream_resolve_include_path($_plugin_dir);
    168                     } else {
    169                         $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
    170                     }
    171 
    172                     if ($plugin_dir !== false) {
    173                         if ($errors === null) {
    174                             echo "$plugin_dir is OK.\n";
    175                         }
    176 
    177                         continue;
    178                     } else {
    179                         $status = false;
    180                         $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
    181                         if ($errors === null) {
    182                             echo $message . ".\n";
    183                         } else {
    184                             $errors['plugins_dir'] = $message;
    185                         }
    186 
    187                         continue;
    188                     }
    189                 } else {
    190                     $status = false;
    191                     $message = "FAILED: $_plugin_dir does not exist";
    192                     if ($errors === null) {
    193                         echo $message . ".\n";
    194                     } else {
    195                         $errors['plugins_dir'] = $message;
    196                     }
    197 
    198                     continue;
    199                 }
    200             }
    201 
    202             if (!is_dir($plugin_dir)) {
    203                 $status = false;
    204                 $message = "FAILED: $plugin_dir is not a directory";
    205                 if ($errors === null) {
    206                     echo $message . ".\n";
    207                 } else {
    208                     $errors['plugins_dir'] = $message;
    209                 }
    210             } elseif (!is_readable($plugin_dir)) {
    211                 $status = false;
    212                 $message = "FAILED: $plugin_dir is not readable";
    213                 if ($errors === null) {
    214                     echo $message . ".\n";
    215                 } else {
    216                     $errors['plugins_dir'] = $message;
    217                 }
    218             } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
    219                 $_core_plugins_available = true;
    220                 if ($errors === null) {
    221                     echo "$plugin_dir is OK.\n";
    222                 }
    223             } else {
    224                 if ($errors === null) {
    225                     echo "$plugin_dir is OK.\n";
    226                 }
    227             }
    228         }
    229         if (!$_core_plugins_available) {
    230             $status = false;
    231             $message = "WARNING: Smarty's own libs/plugins is not available";
    232             if ($errors === null) {
    233                 echo $message . ".\n";
    234             } elseif (!isset($errors['plugins_dir'])) {
    235                 $errors['plugins_dir'] = $message;
    236             }
    237         }
    238 
    239         if ($errors === null) {
    240             echo "Testing cache directory...\n";
    241         }
    242 
    243         // test if all registered cache_dir is accessible
    244         $__cache_dir = $smarty->getCacheDir();
    245         $_cache_dir = realpath($__cache_dir);
    246         if (!$_cache_dir) {
    247             $status = false;
    248             $message = "FAILED: {$__cache_dir} does not exist";
    249             if ($errors === null) {
    250                 echo $message . ".\n";
    251             } else {
    252                 $errors['cache_dir'] = $message;
    253             }
    254         } elseif (!is_dir($_cache_dir)) {
    255             $status = false;
    256             $message = "FAILED: {$_cache_dir} is not a directory";
    257             if ($errors === null) {
    258                 echo $message . ".\n";
    259             } else {
    260                 $errors['cache_dir'] = $message;
    261             }
    262         } elseif (!is_readable($_cache_dir)) {
    263             $status = false;
    264             $message = "FAILED: {$_cache_dir} is not readable";
    265             if ($errors === null) {
    266                 echo $message . ".\n";
    267             } else {
    268                 $errors['cache_dir'] = $message;
    269             }
    270         } elseif (!is_writable($_cache_dir)) {
    271             $status = false;
    272             $message = "FAILED: {$_cache_dir} is not writable";
    273             if ($errors === null) {
    274                 echo $message . ".\n";
    275             } else {
    276                 $errors['cache_dir'] = $message;
    277             }
    278         } else {
    279             if ($errors === null) {
    280                 echo "{$_cache_dir} is OK.\n";
    281             }
    282         }
    283 
    284         if ($errors === null) {
    285             echo "Testing configs directory...\n";
    286         }
    287 
    288         // test if all registered config_dir are accessible
    289         foreach ($smarty->getConfigDir() as $config_dir) {
    290             $_config_dir = $config_dir;
    291             $config_dir = realpath($config_dir);
    292             // resolve include_path or fail existence
    293             if (!$config_dir) {
    294                 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
    295                     // try PHP include_path
    296                     if ($_stream_resolve_include_path) {
    297                         $config_dir = stream_resolve_include_path($_config_dir);
    298                     } else {
    299                         $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir);
    300                     }
    301 
    302                     if ($config_dir !== false) {
    303                         if ($errors === null) {
    304                             echo "$config_dir is OK.\n";
    305                         }
    306 
    307                         continue;
    308                     } else {
    309                         $status = false;
    310                         $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
    311                         if ($errors === null) {
    312                             echo $message . ".\n";
    313                         } else {
    314                             $errors['config_dir'] = $message;
    315                         }
    316 
    317                         continue;
    318                     }
    319                 } else {
    320                     $status = false;
    321                     $message = "FAILED: $_config_dir does not exist";
    322                     if ($errors === null) {
    323                         echo $message . ".\n";
    324                     } else {
    325                         $errors['config_dir'] = $message;
    326                     }
    327 
    328                     continue;
    329                 }
    330             }
    331 
    332             if (!is_dir($config_dir)) {
    333                 $status = false;
    334                 $message = "FAILED: $config_dir is not a directory";
    335                 if ($errors === null) {
    336                     echo $message . ".\n";
    337                 } else {
    338                     $errors['config_dir'] = $message;
    339                 }
    340             } elseif (!is_readable($config_dir)) {
    341                 $status = false;
    342                 $message = "FAILED: $config_dir is not readable";
    343                 if ($errors === null) {
    344                     echo $message . ".\n";
    345                 } else {
    346                     $errors['config_dir'] = $message;
    347                 }
    348             } else {
    349                 if ($errors === null) {
    350                     echo "$config_dir is OK.\n";
    351                 }
    352             }
    353         }
    354 
    355         if ($errors === null) {
    356             echo "Testing sysplugin files...\n";
    357         }
    358         // test if sysplugins are available
    359         $source = SMARTY_SYSPLUGINS_DIR;
    360         if (is_dir($source)) {
    361             $expected = array(
    362                 "smarty_cacheresource.php"                                  => true,
    363                 "smarty_cacheresource_custom.php"                           => true,
    364                 "smarty_cacheresource_keyvaluestore.php"                    => true,
    365                 "smarty_data.php"                                           => true,
    366                 "smarty_internal_cacheresource_file.php"                    => true,
    367                 "smarty_internal_compile_append.php"                        => true,
    368                 "smarty_internal_compile_assign.php"                        => true,
    369                 "smarty_internal_compile_block.php"                         => true,
    370                 "smarty_internal_compile_break.php"                         => true,
    371                 "smarty_internal_compile_call.php"                          => true,
    372                 "smarty_internal_compile_capture.php"                       => true,
    373                 "smarty_internal_compile_config_load.php"                   => true,
    374                 "smarty_internal_compile_continue.php"                      => true,
    375                 "smarty_internal_compile_debug.php"                         => true,
    376                 "smarty_internal_compile_eval.php"                          => true,
    377                 "smarty_internal_compile_extends.php"                       => true,
    378                 "smarty_internal_compile_for.php"                           => true,
    379                 "smarty_internal_compile_foreach.php"                       => true,
    380                 "smarty_internal_compile_function.php"                      => true,
    381                 "smarty_internal_compile_if.php"                            => true,
    382                 "smarty_internal_compile_include.php"                       => true,
    383                 "smarty_internal_compile_include_php.php"                   => true,
    384                 "smarty_internal_compile_insert.php"                        => true,
    385                 "smarty_internal_compile_ldelim.php"                        => true,
    386                 "smarty_internal_compile_nocache.php"                       => true,
    387                 "smarty_internal_compile_private_block_plugin.php"          => true,
    388                 "smarty_internal_compile_private_function_plugin.php"       => true,
    389                 "smarty_internal_compile_private_modifier.php"              => true,
    390                 "smarty_internal_compile_private_object_block_function.php" => true,
    391                 "smarty_internal_compile_private_object_function.php"       => true,
    392                 "smarty_internal_compile_private_print_expression.php"      => true,
    393                 "smarty_internal_compile_private_registered_block.php"      => true,
    394                 "smarty_internal_compile_private_registered_function.php"   => true,
    395                 "smarty_internal_compile_private_special_variable.php"      => true,
    396                 "smarty_internal_compile_rdelim.php"                        => true,
    397                 "smarty_internal_compile_section.php"                       => true,
    398                 "smarty_internal_compile_setfilter.php"                     => true,
    399                 "smarty_internal_compile_while.php"                         => true,
    400                 "smarty_internal_compilebase.php"                           => true,
    401                 "smarty_internal_config_file_compiler.php"                  => true,
    402                 "smarty_internal_configfilelexer.php"                       => true,
    403                 "smarty_internal_configfileparser.php"                      => true,
    404                 "smarty_internal_data.php"                                  => true,
    405                 "smarty_internal_debug.php"                                 => true,
    406                 "smarty_internal_extension_codeframe.php"                   => true,
    407                 "smarty_internal_extension_config.php"                      => true,
    408                 "smarty_internal_extension_defaulttemplatehandler.php"      => true,
    409                 "smarty_internal_filter_handler.php"                        => true,
    410                 "smarty_internal_function_call_handler.php"                 => true,
    411                 "smarty_internal_get_include_path.php"                      => true,
    412                 "smarty_internal_nocache_insert.php"                        => true,
    413                 "smarty_internal_parsetree.php"                             => true,
    414                 "smarty_internal_parsetree_code.php"                        => true,
    415                 "smarty_internal_parsetree_dq.php"                          => true,
    416                 "smarty_internal_parsetree_dqcontent.php"                   => true,
    417                 "smarty_internal_parsetree_tag.php"                         => true,
    418                 "smarty_internal_parsetree_template.php"                    => true,
    419                 "smarty_internal_parsetree_text.php"                        => true,
    420                 "smarty_internal_resource_eval.php"                         => true,
    421                 "smarty_internal_resource_extends.php"                      => true,
    422                 "smarty_internal_resource_file.php"                         => true,
    423                 "smarty_internal_resource_php.php"                          => true,
    424                 "smarty_internal_resource_registered.php"                   => true,
    425                 "smarty_internal_resource_stream.php"                       => true,
    426                 "smarty_internal_resource_string.php"                       => true,
    427                 "smarty_internal_smartytemplatecompiler.php"                => true,
    428                 "smarty_internal_template.php"                              => true,
    429                 "smarty_internal_templatebase.php"                          => true,
    430                 "smarty_internal_templatecompilerbase.php"                  => true,
    431                 "smarty_internal_templatelexer.php"                         => true,
    432                 "smarty_internal_templateparser.php"                        => true,
    433                 "smarty_internal_utility.php"                               => true,
    434                 "smarty_internal_write_file.php"                            => true,
    435                 "smarty_resource.php"                                       => true,
    436                 "smarty_resource_custom.php"                                => true,
    437                 "smarty_resource_recompiled.php"                            => true,
    438                 "smarty_resource_uncompiled.php"                            => true,
    439                 "smarty_security.php"                                       => true,
    440                 "smarty_template_cached.php"                                => true,
    441                 "smarty_template_compiled.php"                              => true,
    442                 "smarty_template_config.php"                                => true,
    443                 "smarty_template_source.php"                                => true,
    444                 "smarty_undefined_variable.php"                             => true,
    445                 "smarty_variable.php"                                       => true,
    446                 "smartycompilerexception.php"                               => true,
    447                 "smartyexception.php"                                       => true,
    448             );
    449             $iterator = new DirectoryIterator($source);
    450             foreach ($iterator as $file) {
    451                 if (!$file->isDot()) {
    452                     $filename = $file->getFilename();
    453                     if (isset($expected[$filename])) {
    454                         unset($expected[$filename]);
    455                     }
    456                 }
    457             }
    458             if ($expected) {
    459                 $status = false;
    460                 $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected));
    461                 if ($errors === null) {
    462                     echo $message . ".\n";
    463                 } else {
    464                     $errors['sysplugins'] = $message;
    465                 }
    466             } elseif ($errors === null) {
    467                 echo "... OK\n";
    468             }
    469         } else {
    470             $status = false;
    471             $message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory';
    472             if ($errors === null) {
    473                 echo $message . ".\n";
    474             } else {
    475                 $errors['sysplugins_dir_constant'] = $message;
    476             }
    477         }
    478 
    479         if ($errors === null) {
    480             echo "Testing plugin files...\n";
    481         }
    482         // test if core plugins are available
    483         $source = SMARTY_PLUGINS_DIR;
    484         if (is_dir($source)) {
    485             $expected = array(
    486                 "block.textformat.php"                  => true,
    487                 "function.counter.php"                  => true,
    488                 "function.cycle.php"                    => true,
    489                 "function.fetch.php"                    => true,
    490                 "function.html_checkboxes.php"          => true,
    491                 "function.html_image.php"               => true,
    492                 "function.html_options.php"             => true,
    493                 "function.html_radios.php"              => true,
    494                 "function.html_select_date.php"         => true,
    495                 "function.html_select_time.php"         => true,
    496                 "function.html_table.php"               => true,
    497                 "function.mailto.php"                   => true,
    498                 "function.math.php"                     => true,
    499                 "modifier.capitalize.php"               => true,
    500                 "modifier.date_format.php"              => true,
    501                 "modifier.debug_print_var.php"          => true,
    502                 "modifier.escape.php"                   => true,
    503                 "modifier.regex_replace.php"            => true,
    504                 "modifier.replace.php"                  => true,
    505                 "modifier.spacify.php"                  => true,
    506                 "modifier.truncate.php"                 => true,
    507                 "modifiercompiler.cat.php"              => true,
    508                 "modifiercompiler.count_characters.php" => true,
    509                 "modifiercompiler.count_paragraphs.php" => true,
    510                 "modifiercompiler.count_sentences.php"  => true,
    511                 "modifiercompiler.count_words.php"      => true,
    512                 "modifiercompiler.default.php"          => true,
    513                 "modifiercompiler.escape.php"           => true,
    514                 "modifiercompiler.from_charset.php"     => true,
    515                 "modifiercompiler.indent.php"           => true,
    516                 "modifiercompiler.lower.php"            => true,
    517                 "modifiercompiler.noprint.php"          => true,
    518                 "modifiercompiler.string_format.php"    => true,
    519                 "modifiercompiler.strip.php"            => true,
    520                 "modifiercompiler.strip_tags.php"       => true,
    521                 "modifiercompiler.to_charset.php"       => true,
    522                 "modifiercompiler.unescape.php"         => true,
    523                 "modifiercompiler.upper.php"            => true,
    524                 "modifiercompiler.wordwrap.php"         => true,
    525                 "outputfilter.trimwhitespace.php"       => true,
    526                 "shared.escape_special_chars.php"       => true,
    527                 "shared.literal_compiler_param.php"     => true,
    528                 "shared.make_timestamp.php"             => true,
    529                 "shared.mb_str_replace.php"             => true,
    530                 "shared.mb_unicode.php"                 => true,
    531                 "shared.mb_wordwrap.php"                => true,
    532                 "variablefilter.htmlspecialchars.php"   => true,
    533             );
    534             $iterator = new DirectoryIterator($source);
    535             foreach ($iterator as $file) {
    536                 if (!$file->isDot()) {
    537                     $filename = $file->getFilename();
    538                     if (isset($expected[$filename])) {
    539                         unset($expected[$filename]);
    540                     }
    541                 }
    542             }
    543             if ($expected) {
    544                 $status = false;
    545                 $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected));
    546                 if ($errors === null) {
    547                     echo $message . ".\n";
    548                 } else {
    549                     $errors['plugins'] = $message;
    550                 }
    551             } elseif ($errors === null) {
    552                 echo "... OK\n";
    553             }
    554         } else {
    555             $status = false;
    556             $message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory';
    557             if ($errors === null) {
    558                 echo $message . ".\n";
    559             } else {
    560                 $errors['plugins_dir_constant'] = $message;
    561             }
    562         }
    563 
    564         if ($errors === null) {
    565             echo "Tests complete.\n";
    566             echo "</PRE>\n";
    567         }
    568 
    569         return $status;
    570     }
    571 }