コード例 #1
0
 /**
  * get hiweb_tpl property in template context
  *
  * @param string $property_name property name
  *
  * @throws SmurtyException
  */
 public function __get($property_name)
 {
     switch ($property_name) {
         case 'source':
             if (strlen($this->template_resource) == 0) {
                 throw new SmurtyException('Missing template name');
             }
             $this->source = Smurty_Resource::source($this);
             // cache template object under a unique ID
             // do not cache eval resources
             if ($this->source->type != 'eval') {
                 if ($this->smurty->allow_ambiguous_resources) {
                     $_templateId = $this->source->unique_resource . $this->cache_id . $this->compile_id;
                 } else {
                     $_templateId = $this->smurty->joined_template_dir . '#' . $this->template_resource . $this->cache_id . $this->compile_id;
                 }
                 if (isset($_templateId[150])) {
                     $_templateId = sha1($_templateId);
                 }
                 $this->smurty->template_objects[$_templateId] = $this;
             }
             return $this->source;
         case 'compiled':
             $this->compiled = $this->source->getCompiled($this);
             return $this->compiled;
         case 'cached':
             if (!class_exists('Smurty_Template_Cached')) {
                 include HIWEB_CORE_HTML_ASSETS . 'smurty_cacheresource.php';
             }
             $this->cached = new Smurty_Template_Cached($this);
             return $this->cached;
         case 'compiler':
             $this->smurty->loadPlugin($this->source->compiler_class);
             $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smurty);
             return $this->compiler;
             // FIXME: routing of template -> smurty attributes
         // FIXME: routing of template -> smurty attributes
         default:
             if (property_exists($this->smurty, $property_name)) {
                 return $this->smurty->{$property_name};
             }
     }
     throw new SmurtyException("template property '{$property_name}' does not exist.");
 }
コード例 #2
0
 /**
  * Load Cache Resource Handler
  *
  * @param hiweb_tpl $smurty hiweb_tpl object
  * @param string $type   name of the cache resource
  *
  * @throws SmurtyException
  * @return Smurty_CacheResource Cache Resource Handler
  */
 public static function load(hiweb_tpl $smurty, $type = null)
 {
     if (!isset($type)) {
         $type = $smurty->caching_type;
     }
     // try smurty's cache
     if (isset($smurty->_cacheresource_handlers[$type])) {
         return $smurty->_cacheresource_handlers[$type];
     }
     // try registered resource
     if (isset($smurty->registered_cache_resources[$type])) {
         // do not cache these instances as they may vary from instance to instance
         return $smurty->_cacheresource_handlers[$type] = $smurty->registered_cache_resources[$type];
     }
     // try hiweb-core-tpl dir
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $cache_resource_class = 'Smurty_Internal_CacheResource_' . ucfirst($type);
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smurty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     // try plugins dir
     $cache_resource_class = 'Smurty_CacheResource_' . ucfirst($type);
     if ($smurty->loadPlugin($cache_resource_class)) {
         if (!isset(self::$resources[$type])) {
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smurty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     // give up
     throw new SmurtyException("Unable to load cache resource '{$type}'");
 }
コード例 #3
0
 /**
  * Load Resource Handler
  *
  * @param  hiweb_tpl $smurty smurty object
  * @param  string $type   name of the resource
  *
  * @throws SmurtyException
  * @return Smurty_Resource Resource Handler
  */
 public static function load(hiweb_tpl $smurty, $type)
 {
     // try smurty's cache
     if (isset($smurty->_resource_handlers[$type])) {
         return $smurty->_resource_handlers[$type];
     }
     // try registered resource
     if (isset($smurty->registered_resources[$type])) {
         if ($smurty->registered_resources[$type] instanceof Smurty_Resource) {
             $smurty->_resource_handlers[$type] = $smurty->registered_resources[$type];
             // note registered to smurty is not kept unique!
             return $smurty->_resource_handlers[$type];
         }
         if (!isset(self::$resources['registered'])) {
             self::$resources['registered'] = new Smurty_Internal_Resource_Registered();
         }
         if (!isset($smurty->_resource_handlers[$type])) {
             $smurty->_resource_handlers[$type] = self::$resources['registered'];
         }
         return $smurty->_resource_handlers[$type];
     }
     // try hiweb-core-tpl dir
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $_resource_class = 'Smurty_Internal_Resource_' . ucfirst($type);
             self::$resources[$type] = new $_resource_class();
         }
         return $smurty->_resource_handlers[$type] = self::$resources[$type];
     }
     // try plugins dir
     $_resource_class = 'Smurty_Resource_' . ucfirst($type);
     if ($smurty->loadPlugin($_resource_class)) {
         if (isset(self::$resources[$type])) {
             return $smurty->_resource_handlers[$type] = self::$resources[$type];
         }
         if (class_exists($_resource_class, false)) {
             self::$resources[$type] = new $_resource_class();
             return $smurty->_resource_handlers[$type] = self::$resources[$type];
         } else {
             $smurty->registerResource($type, array("smurty_resource_{$type}_source", "smurty_resource_{$type}_timestamp", "smurty_resource_{$type}_secure", "smurty_resource_{$type}_trusted"));
             // give it another try, now that the resource is registered properly
             return self::load($smurty, $type);
         }
     }
     // try streams
     $_known_stream = stream_get_wrappers();
     if (in_array($type, $_known_stream)) {
         // is known stream
         if (is_object($smurty->security_policy)) {
             $smurty->security_policy->isTrustedStream($type);
         }
         if (!isset(self::$resources['stream'])) {
             self::$resources['stream'] = new Smurty_Internal_Resource_Stream();
         }
         return $smurty->_resource_handlers[$type] = self::$resources['stream'];
     }
     // TODO: try default_(template|config)_handler
     // give up
     throw new SmurtyException("Unknown resource type '{$type}'");
 }
コード例 #4
0
 /**
  * Подключение модуля функций hiweb_tpl
  * @return hiweb_tpl
  */
 public function tpl()
 {
     static $class = null;
     if (!is_object($class) && file_exists(dirname(__FILE__) . '/hiweb-core-tpl.php')) {
         require_once dirname(__FILE__) . '/hiweb-core-tpl.php';
         $class = new hiweb_tpl();
         $class->registerPlugin('block', 'lang', array($this, 'tplBlock_lang'));
         $class->registerPlugin('modifier', 'lang', array($this, 'tplModifier_lang'));
         $class->registerPlugin('modifier', 'allow', array($this->string(), 'getStr_allowSymbols'));
         $class->registerPlugin('modifier', 'print_r', array($this, 'print_r'));
         $class->registerPlugin('modifier', 'tpl', array($this->file(), 'getHtml_fromTplStr'));
         $class->registerPlugin('block', 'helpPoint', array($this->wizard(), 'getHtml_helpPoint'));
         $class->registerPlugin('block', 'helpPointImage', array($this->wizard(), 'getHtml_helpPointImage'));
         $cachePath = HIWEB_DIR_CACHE . DIR_SEPARATOR . 'tpl';
         $this->file()->do_foldersAutoCreate($cachePath);
         $class->template_dir = $cachePath . "/templates";
         $class->compile_dir = $cachePath . "/templates_c";
         $class->config_dir = $cachePath . "/config";
         $class->cache_dir = $cachePath . "/cache";
         //$smarty->plugins_dir[]  = $theme_path . "/plugins";
         //$smarty->trusted_dir  = $theme_path . "/trusted";
     }
     return $class;
 }
コード例 #5
0
 /**
  * diagnose hiweb_tpl setup
  * If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
  *
  * @param  hiweb_tpl $smurty hiweb_tpl instance to test
  * @param  array  $errors array to push results into rather than outputting them
  *
  * @return bool   status, true if everything is fine, false else
  */
 public static function testInstall(hiweb_tpl $smurty, &$errors = null)
 {
     $status = true;
     if ($errors === null) {
         echo "<PRE>\n";
         echo "hiweb_tpl Installation test...\n";
         echo "Testing template directory...\n";
     }
     $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
     // test if all registered template_dir are accessible
     foreach ($smurty->getTemplateDir() as $template_dir) {
         $_template_dir = $template_dir;
         $template_dir = realpath($template_dir);
         // resolve include_path or fail existence
         if (!$template_dir) {
             if ($smurty->use_include_path && !preg_match('/^([\\/\\\\]|[a-zA-Z]:[\\/\\\\])/', $_template_dir)) {
                 // try PHP include_path
                 if ($_stream_resolve_include_path) {
                     $template_dir = stream_resolve_include_path($_template_dir);
                 } else {
                     $template_dir = Smurty_Internal_Get_Include_Path::getIncludePath($_template_dir);
                 }
                 if ($template_dir !== false) {
                     if ($errors === null) {
                         echo "{$template_dir} is OK.\n";
                     }
                     continue;
                 } else {
                     $status = false;
                     $message = "FAILED: {$_template_dir} does not exist (and couldn't be found in include_path either)";
                     if ($errors === null) {
                         echo $message . ".\n";
                     } else {
                         $errors['template_dir'] = $message;
                     }
                     continue;
                 }
             } else {
                 $status = false;
                 $message = "FAILED: {$_template_dir} does not exist";
                 if ($errors === null) {
                     echo $message . ".\n";
                 } else {
                     $errors['template_dir'] = $message;
                 }
                 continue;
             }
         }
         if (!is_dir($template_dir)) {
             $status = false;
             $message = "FAILED: {$template_dir} is not a directory";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['template_dir'] = $message;
             }
         } elseif (!is_readable($template_dir)) {
             $status = false;
             $message = "FAILED: {$template_dir} is not readable";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['template_dir'] = $message;
             }
         } else {
             if ($errors === null) {
                 echo "{$template_dir} is OK.\n";
             }
         }
     }
     if ($errors === null) {
         echo "Testing compile directory...\n";
     }
     // test if registered compile_dir is accessible
     $__compile_dir = $smurty->getCompileDir();
     $_compile_dir = realpath($__compile_dir);
     if (!$_compile_dir) {
         $status = false;
         $message = "FAILED: {$__compile_dir} does not exist";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['compile_dir'] = $message;
         }
     } elseif (!is_dir($_compile_dir)) {
         $status = false;
         $message = "FAILED: {$_compile_dir} is not a directory";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['compile_dir'] = $message;
         }
     } elseif (!is_readable($_compile_dir)) {
         $status = false;
         $message = "FAILED: {$_compile_dir} is not readable";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['compile_dir'] = $message;
         }
     } elseif (!is_writable($_compile_dir)) {
         $status = false;
         $message = "FAILED: {$_compile_dir} is not writable";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['compile_dir'] = $message;
         }
     } else {
         if ($errors === null) {
             echo "{$_compile_dir} is OK.\n";
         }
     }
     if ($errors === null) {
         echo "Testing plugins directory...\n";
     }
     // test if all registered plugins_dir are accessible
     // and if core plugins directory is still registered
     $_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins');
     $_core_plugins_available = false;
     foreach ($smurty->getPluginsDir() as $plugin_dir) {
         $_plugin_dir = $plugin_dir;
         $plugin_dir = realpath($plugin_dir);
         // resolve include_path or fail existence
         if (!$plugin_dir) {
             if ($smurty->use_include_path && !preg_match('/^([\\/\\\\]|[a-zA-Z]:[\\/\\\\])/', $_plugin_dir)) {
                 // try PHP include_path
                 if ($_stream_resolve_include_path) {
                     $plugin_dir = stream_resolve_include_path($_plugin_dir);
                 } else {
                     $plugin_dir = Smurty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
                 }
                 if ($plugin_dir !== false) {
                     if ($errors === null) {
                         echo "{$plugin_dir} is OK.\n";
                     }
                     continue;
                 } else {
                     $status = false;
                     $message = "FAILED: {$_plugin_dir} does not exist (and couldn't be found in include_path either)";
                     if ($errors === null) {
                         echo $message . ".\n";
                     } else {
                         $errors['plugins_dir'] = $message;
                     }
                     continue;
                 }
             } else {
                 $status = false;
                 $message = "FAILED: {$_plugin_dir} does not exist";
                 if ($errors === null) {
                     echo $message . ".\n";
                 } else {
                     $errors['plugins_dir'] = $message;
                 }
                 continue;
             }
         }
         if (!is_dir($plugin_dir)) {
             $status = false;
             $message = "FAILED: {$plugin_dir} is not a directory";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['plugins_dir'] = $message;
             }
         } elseif (!is_readable($plugin_dir)) {
             $status = false;
             $message = "FAILED: {$plugin_dir} is not readable";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['plugins_dir'] = $message;
             }
         } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
             $_core_plugins_available = true;
             if ($errors === null) {
                 echo "{$plugin_dir} is OK.\n";
             }
         } else {
             if ($errors === null) {
                 echo "{$plugin_dir} is OK.\n";
             }
         }
     }
     if (!$_core_plugins_available) {
         $status = false;
         $message = "WARNING: hiweb_tpl's own libs/plugins is not available";
         if ($errors === null) {
             echo $message . ".\n";
         } elseif (!isset($errors['plugins_dir'])) {
             $errors['plugins_dir'] = $message;
         }
     }
     if ($errors === null) {
         echo "Testing cache directory...\n";
     }
     // test if all registered cache_dir is accessible
     $__cache_dir = $smurty->getCacheDir();
     $_cache_dir = realpath($__cache_dir);
     if (!$_cache_dir) {
         $status = false;
         $message = "FAILED: {$__cache_dir} does not exist";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['cache_dir'] = $message;
         }
     } elseif (!is_dir($_cache_dir)) {
         $status = false;
         $message = "FAILED: {$_cache_dir} is not a directory";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['cache_dir'] = $message;
         }
     } elseif (!is_readable($_cache_dir)) {
         $status = false;
         $message = "FAILED: {$_cache_dir} is not readable";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['cache_dir'] = $message;
         }
     } elseif (!is_writable($_cache_dir)) {
         $status = false;
         $message = "FAILED: {$_cache_dir} is not writable";
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['cache_dir'] = $message;
         }
     } else {
         if ($errors === null) {
             echo "{$_cache_dir} is OK.\n";
         }
     }
     if ($errors === null) {
         echo "Testing configs directory...\n";
     }
     // test if all registered config_dir are accessible
     foreach ($smurty->getConfigDir() as $config_dir) {
         $_config_dir = $config_dir;
         $config_dir = realpath($config_dir);
         // resolve include_path or fail existence
         if (!$config_dir) {
             if ($smurty->use_include_path && !preg_match('/^([\\/\\\\]|[a-zA-Z]:[\\/\\\\])/', $_config_dir)) {
                 // try PHP include_path
                 if ($_stream_resolve_include_path) {
                     $config_dir = stream_resolve_include_path($_config_dir);
                 } else {
                     $config_dir = Smurty_Internal_Get_Include_Path::getIncludePath($_config_dir);
                 }
                 if ($config_dir !== false) {
                     if ($errors === null) {
                         echo "{$config_dir} is OK.\n";
                     }
                     continue;
                 } else {
                     $status = false;
                     $message = "FAILED: {$_config_dir} does not exist (and couldn't be found in include_path either)";
                     if ($errors === null) {
                         echo $message . ".\n";
                     } else {
                         $errors['config_dir'] = $message;
                     }
                     continue;
                 }
             } else {
                 $status = false;
                 $message = "FAILED: {$_config_dir} does not exist";
                 if ($errors === null) {
                     echo $message . ".\n";
                 } else {
                     $errors['config_dir'] = $message;
                 }
                 continue;
             }
         }
         if (!is_dir($config_dir)) {
             $status = false;
             $message = "FAILED: {$config_dir} is not a directory";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['config_dir'] = $message;
             }
         } elseif (!is_readable($config_dir)) {
             $status = false;
             $message = "FAILED: {$config_dir} is not readable";
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['config_dir'] = $message;
             }
         } else {
             if ($errors === null) {
                 echo "{$config_dir} is OK.\n";
             }
         }
     }
     if ($errors === null) {
         echo "Testing sysplugin files...\n";
     }
     // test if hiweb-core-tpl are available
     $source = HIWEB_CORE_HTML_ASSETS;
     if (is_dir($source)) {
         $expected = array("smurty_cacheresource.php" => true, "smurty_cacheresource_custom.php" => true, "smurty_cacheresource_keyvaluestore.php" => true, "smurty_config_source.php" => true, "smurty_internal_cacheresource_file.php" => true, "smurty_internal_compile_append.php" => true, "smurty_internal_compile_assign.php" => true, "smurty_internal_compile_block.php" => true, "smurty_internal_compile_break.php" => true, "smurty_internal_compile_call.php" => true, "smurty_internal_compile_capture.php" => true, "smurty_internal_compile_config_load.php" => true, "smurty_internal_compile_continue.php" => true, "smurty_internal_compile_debug.php" => true, "smurty_internal_compile_eval.php" => true, "smurty_internal_compile_extends.php" => true, "smurty_internal_compile_for.php" => true, "smurty_internal_compile_foreach.php" => true, "smurty_internal_compile_function.php" => true, "smurty_internal_compile_if.php" => true, "smurty_internal_compile_include.php" => true, "smurty_internal_compile_include_php.php" => true, "smurty_internal_compile_insert.php" => true, "smurty_internal_compile_ldelim.php" => true, "smurty_internal_compile_nocache.php" => true, "smurty_internal_compile_private_block_plugin.php" => true, "smurty_internal_compile_private_function_plugin.php" => true, "smurty_internal_compile_private_modifier.php" => true, "smurty_internal_compile_private_object_block_function.php" => true, "smurty_internal_compile_private_object_function.php" => true, "smurty_internal_compile_private_print_expression.php" => true, "smurty_internal_compile_private_registered_block.php" => true, "smurty_internal_compile_private_registered_function.php" => true, "smurty_internal_compile_private_special_variable.php" => true, "smurty_internal_compile_rdelim.php" => true, "smurty_internal_compile_section.php" => true, "smurty_internal_compile_setfilter.php" => true, "smurty_internal_compile_while.php" => true, "smurty_internal_compilebase.php" => true, "smurty_internal_config.php" => true, "smurty_internal_config_file_compiler.php" => true, "smurty_internal_configfilelexer.php" => true, "smurty_internal_configfileparser.php" => true, "smurty_internal_data.php" => true, "smurty_internal_debug.php" => true, "smurty_internal_filter_handler.php" => true, "smurty_internal_function_call_handler.php" => true, "smurty_internal_get_include_path.php" => true, "smurty_internal_nocache_insert.php" => true, "smurty_internal_parsetree.php" => true, "smurty_internal_resource_eval.php" => true, "smurty_internal_resource_extends.php" => true, "smurty_internal_resource_file.php" => true, "smurty_internal_resource_registered.php" => true, "smurty_internal_resource_stream.php" => true, "smurty_internal_resource_string.php" => true, "smurty_internal_smurtytemplatecompiler.php" => true, "smurty_internal_template.php" => true, "smurty_internal_templatebase.php" => true, "smurty_internal_templatecompilerbase.php" => true, "smurty_internal_templatelexer.php" => true, "smurty_internal_templateparser.php" => true, "smurty_internal_utility.php" => true, "smurty_internal_write_file.php" => true, "smurty_resource.php" => true, "smurty_resource_custom.php" => true, "smurty_resource_recompiled.php" => true, "smurty_resource_uncompiled.php" => true, "smurty_security.php" => true);
         $iterator = new DirectoryIterator($source);
         foreach ($iterator as $file) {
             if (!$file->isDot()) {
                 $filename = $file->getFilename();
                 if (isset($expected[$filename])) {
                     unset($expected[$filename]);
                 }
             }
         }
         if ($expected) {
             $status = false;
             $message = "FAILED: files missing from libs/hiweb-core-tpl: " . join(', ', array_keys($expected));
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['hiweb-core-tpl'] = $message;
             }
         } elseif ($errors === null) {
             echo "... OK\n";
         }
     } else {
         $status = false;
         $message = "FAILED: " . HIWEB_CORE_HTML_ASSETS . ' is not a directory';
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['sysplugins_dir_constant'] = $message;
         }
     }
     if ($errors === null) {
         echo "Testing plugin files...\n";
     }
     // test if core plugins are available
     $source = HIWEB_TPL_PLUGINS_DIR;
     if (is_dir($source)) {
         $expected = array("block.textformat.php" => true, "function.counter.php" => true, "function.cycle.php" => true, "function.fetch.php" => true, "function.html_checkboxes.php" => true, "function.html_image.php" => true, "function.html_options.php" => true, "function.html_radios.php" => true, "function.html_select_date.php" => true, "function.html_select_time.php" => true, "function.html_table.php" => true, "function.mailto.php" => true, "function.math.php" => true, "modifier.capitalize.php" => true, "modifier.date_format.php" => true, "modifier.debug_print_var.php" => true, "modifier.escape.php" => true, "modifier.regex_replace.php" => true, "modifier.replace.php" => true, "modifier.spacify.php" => true, "modifier.truncate.php" => true, "modifiercompiler.cat.php" => true, "modifiercompiler.count_characters.php" => true, "modifiercompiler.count_paragraphs.php" => true, "modifiercompiler.count_sentences.php" => true, "modifiercompiler.count_words.php" => true, "modifiercompiler.default.php" => true, "modifiercompiler.escape.php" => true, "modifiercompiler.from_charset.php" => true, "modifiercompiler.indent.php" => true, "modifiercompiler.lower.php" => true, "modifiercompiler.noprint.php" => true, "modifiercompiler.string_format.php" => true, "modifiercompiler.strip.php" => true, "modifiercompiler.strip_tags.php" => true, "modifiercompiler.to_charset.php" => true, "modifiercompiler.unescape.php" => true, "modifiercompiler.upper.php" => true, "modifiercompiler.wordwrap.php" => true, "outputfilter.trimwhitespace.php" => true, "shared.escape_special_chars.php" => true, "shared.literal_compiler_param.php" => true, "shared.make_timestamp.php" => true, "shared.mb_str_replace.php" => true, "shared.mb_unicode.php" => true, "shared.mb_wordwrap.php" => true, "variablefilter.htmlspecialchars.php" => true);
         $iterator = new DirectoryIterator($source);
         foreach ($iterator as $file) {
             if (!$file->isDot()) {
                 $filename = $file->getFilename();
                 if (isset($expected[$filename])) {
                     unset($expected[$filename]);
                 }
             }
         }
         if ($expected) {
             $status = false;
             $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected));
             if ($errors === null) {
                 echo $message . ".\n";
             } else {
                 $errors['plugins'] = $message;
             }
         } elseif ($errors === null) {
             echo "... OK\n";
         }
     } else {
         $status = false;
         $message = "FAILED: " . HIWEB_TPL_PLUGINS_DIR . ' is not a directory';
         if ($errors === null) {
             echo $message . ".\n";
         } else {
             $errors['plugins_dir_constant'] = $message;
         }
     }
     if ($errors === null) {
         echo "Tests complete.\n";
         echo "</PRE>\n";
     }
     return $status;
 }
コード例 #6
0
 /**
  * Empty cache for a specific template
  *
  * @param hiweb_tpl  $smurty
  * @param string  $resource_name template name
  * @param string  $cache_id      cache id
  * @param string  $compile_id    compile id
  * @param integer $exp_time      expiration time (number of seconds, not timestamp)
  *
  * @return integer number of cache files deleted
  */
 public function clear(hiweb_tpl $smurty, $resource_name, $cache_id, $compile_id, $exp_time)
 {
     $_cache_id = isset($cache_id) ? preg_replace('![^\\w\\|]+!', '_', $cache_id) : null;
     $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null;
     $_dir_sep = $smurty->use_sub_dirs ? '/' : '^';
     $_compile_id_offset = $smurty->use_sub_dirs ? 3 : 0;
     if (($_dir = realpath($smurty->getCacheDir())) === false) {
         return 0;
     }
     $_dir .= '/';
     $_dir_length = strlen($_dir);
     if (isset($_cache_id)) {
         $_cache_id_parts = explode('|', $_cache_id);
         $_cache_id_parts_count = count($_cache_id_parts);
         if ($smurty->use_sub_dirs) {
             foreach ($_cache_id_parts as $id_part) {
                 $_dir .= $id_part . DIR_SEPARATOR;
             }
         }
     }
     if (isset($resource_name)) {
         $_save_stat = $smurty->caching;
         $smurty->caching = true;
         $tpl = new $smurty->template_class($resource_name, $smurty);
         $smurty->caching = $_save_stat;
         // remove from template cache
         $tpl->source;
         // have the template registered before unset()
         if ($smurty->allow_ambiguous_resources) {
             $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
         } else {
             $_templateId = $smurty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
         }
         if (isset($_templateId[150])) {
             $_templateId = sha1($_templateId);
         }
         unset($smurty->template_objects[$_templateId]);
         if ($tpl->source->exists) {
             $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
         } else {
             return 0;
         }
     }
     $_count = 0;
     $_time = time();
     if (file_exists($_dir)) {
         $_cacheDirs = new RecursiveDirectoryIterator($_dir);
         $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($_cache as $_file) {
             if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
                 continue;
             }
             // directory ?
             if ($_file->isDir()) {
                 if (!$_cache->isDot()) {
                     // delete folder if empty
                     @rmdir($_file->getPathname());
                 }
             } else {
                 $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
                 $_parts_count = count($_parts);
                 // check name
                 if (isset($resource_name)) {
                     if ($_parts[$_parts_count - 1] != $_resourcename_parts) {
                         continue;
                     }
                 }
                 // check compile id
                 if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
                     continue;
                 }
                 // check cache id
                 if (isset($_cache_id)) {
                     // count of cache id parts
                     $_parts_count = isset($_compile_id) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
                     if ($_parts_count < $_cache_id_parts_count) {
                         continue;
                     }
                     for ($i = 0; $i < $_cache_id_parts_count; $i++) {
                         if ($_parts[$i] != $_cache_id_parts[$i]) {
                             continue 2;
                         }
                     }
                 }
                 // expired ?
                 if (isset($exp_time)) {
                     if ($exp_time < 0) {
                         preg_match('#\'cache_lifetime\' =>\\s*(\\d*)#', file_get_contents($_file), $match);
                         if ($_time < @filemtime($_file) + $match[1]) {
                             continue;
                         }
                     } else {
                         if ($_time - @filemtime($_file) < $exp_time) {
                             continue;
                         }
                     }
                 }
                 $_count += @unlink((string) $_file) ? 1 : 0;
             }
         }
     }
     return $_count;
 }
コード例 #7
0
ファイル: hiweb-core-tpl.php プロジェクト: njxqlus/hiweb-core
 /**
  * Enable error handler to mute expected messages
  *
  * @return void
  */
 public static function muteExpectedErrors()
 {
     /*
         error muting is done because some people implemented custom error_handlers using
         http://php.net/set_error_handler and for some reason did not understand the following paragraph:
     
             It is important to remember that the standard PHP error handler is completely bypassed for the
             error types specified by error_types unless the callback function returns FALSE.
             error_reporting() settings will have no effect and your error handler will be called regardless -
             however you are still able to read the current value of error_reporting and act appropriately.
             Of particular note is that this value will be 0 if the statement that caused the error was
             prepended by the @ error-control operator.
     
         hiweb_tpl deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
             - @filemtime() is almost twice as fast as using an additional file_exists()
             - between file_exists() and filemtime() a possible race condition is opened,
               which does not exist using the simple @filemtime() approach.
     */
     $error_handler = array('hiweb_tpl', 'mutingErrorHandler');
     $previous = set_error_handler($error_handler);
     // avoid dead loops
     if ($previous !== $error_handler) {
         hiweb_tpl::$_previous_error_handler = $previous;
     }
 }
コード例 #8
0
 /**
  * Initialize new hiweb_tplChild object
  *
  * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     // register {php} tag
     $this->registerPlugin('block', 'php', 'smurty_php_tag');
 }