loadPlugin() public method

Takes unknown classes and loads plugin files for them class name format: Smarty_PluginType_PluginName plugin filename format: plugintype.pluginname.php
public loadPlugin ( string $plugin_name, boolean $check = true ) : string | boolean
$plugin_name string class plugin name to load
$check boolean check if already loaded
return string | boolean |boolean filepath of loaded file or false
 /**
  * Load compiler object
  *
  * @throws \SmartyException
  */
 public function loadCompiler()
 {
     if (!class_exists($this->source->handler->compiler_class)) {
         $this->smarty->loadPlugin($this->source->handler->compiler_class);
     }
     $this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class, $this->source->handler->template_parser_class, $this->smarty);
 }
 public static function load(Smarty $smarty, $type = null)
 {
     if (!isset($type)) {
         $type = $smarty->caching_type;
     }
     if (isset($smarty->_cacheresource_handlers[$type])) {
         return $smarty->_cacheresource_handlers[$type];
     }
     if (isset($smarty->registered_cache_resources[$type])) {
         return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
     }
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
     if ($smarty->loadPlugin($cache_resource_class)) {
         if (!isset(self::$resources[$type])) {
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     throw new SmartyException("Unable to load cache resource '{$type}'");
 }
 /**
  * Load Cache Resource Handler
  *
  * @param Smarty $smarty Smarty object
  * @param string $type name of the cache resource
  * @return Smarty_CacheResource Cache Resource Handler
  */
 public static function load(Smarty $smarty, $type = null)
 {
     if (!isset($type)) {
         $type = $smarty->caching_type;
     }
     // try smarty's cache
     if (isset($smarty->_cacheresource_handlers[$type])) {
         return $smarty->_cacheresource_handlers[$type];
     }
     // try registered resource
     if (isset($smarty->registered_cache_resources[$type])) {
         // do not cache these instances as they may vary from instance to instance
         return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
     }
     // try sysplugins dir
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     // try plugins dir
     $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
     if ($smarty->loadPlugin($cache_resource_class)) {
         if (!isset(self::$resources[$type])) {
             self::$resources[$type] = new $cache_resource_class();
         }
         return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
     }
     // give up
     throw new SmartyException("Unable to load cache resource '{$type}'");
 }
    /**
     * get Smarty property in template context
     *
     * @param string $property_name property name
     */
    public function __get($property_name)
    {
        switch ($property_name) {
            case 'source':
                if (strlen($this->template_resource) == 0) {
                    throw new SmartyException('Missing template name');
                }
                $this->source = Smarty_Resource::source($this);
                // cache template object under a unique ID
                // do not cache eval resources
                if ($this->source->type != 'eval') {
                    if ($this->smarty->allow_ambiguous_resources) {
                        $_templateId = $this->source->unique_resource . $this->cache_id . $this->compile_id;
                    } else {
                        $_templateId = $this->smarty->joined_template_dir . '#' . $this->template_resource . $this->cache_id . $this->compile_id;
                    }

                    if (isset($_templateId[150])) {
                        $_templateId = sha1($_templateId);
                    }
                    $this->smarty->template_objects[$_templateId] = $this;
                }

                return $this->source;

            case 'compiled':
                $this->compiled = $this->source->getCompiled($this);

                return $this->compiled;

            case 'cached':
                if (!class_exists('Smarty_Template_Cached')) {
                    include SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
                }
                $this->cached = new Smarty_Template_Cached($this);

                return $this->cached;

            case 'compiler':
                $this->smarty->loadPlugin($this->source->compiler_class);
                $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);

                return $this->compiler;

            // FIXME: routing of template -> smarty attributes
            default:
                if (property_exists($this->smarty, $property_name)) {
                    return $this->smarty->$property_name;
                }
        }

        throw new SmartyException("template property '$property_name' does not exist.");
    }
Beispiel #5
0
 /**
  * Smarty loadPlugin method wrapper, allows to load smarty classes outside default directory
  * @param  string $plugin_name class plugin name to load
  * @param  bool   $check       check if already loaded
  * @return string |boolean filepath of loaded file or false
  */
 public function loadPlugin($plugin_name, $check = true)
 {
     if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) {
         return true;
     }
     $_name_parts = explode('_', $plugin_name, 3);
     if (strtolower($_name_parts[1]) == 'internal') {
         $file = Registry::get('config.dir.functions') . 'smarty_plugins/' . strtolower($plugin_name) . '.php';
         if (file_exists($file)) {
             require_once $file;
             return $file;
         }
     }
     return parent::loadPlugin($plugin_name, $check);
 }
 /**
  * load a filter of specified type and name
  *
  * @param  string $type filter type
  * @param  string $name filter name
  *
  * @throws SmartyException if filter could not be loaded
  */
 public function loadFilter($type, $name)
 {
     $_plugin = "smarty_{$type}filter_{$name}";
     $_filter_name = $_plugin;
     if ($this->smarty->loadPlugin($_plugin)) {
         if (class_exists($_plugin, false)) {
             $_plugin = array($_plugin, 'execute');
         }
         if (is_callable($_plugin)) {
             $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
             return true;
         }
     }
     throw new SmartyException("{$type}filter \"{$name}\" not callable");
 }
 /**
  * Check for plugins and return function name
  *
  * @param         $plugin_name
  * @param  string $plugin_type type of plugin
  *
  * @return string call name of function
  */
 public function getPlugin($plugin_name, $plugin_type)
 {
     $function = null;
     if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
         if (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) {
             $function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
         } elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) {
             $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type];
             $function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
         }
     } else {
         if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) {
             $function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
         } elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) {
             $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type];
             $function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
         }
     }
     if (isset($function)) {
         if ($plugin_type == 'modifier') {
             $this->modifier_plugins[$plugin_name] = true;
         }
         return $function;
     }
     // loop through plugin dirs and find the plugin
     $function = 'smarty_' . $plugin_type . '_' . $plugin_name;
     $file = $this->smarty->loadPlugin($function, false);
     if (is_string($file)) {
         if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
             $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
             $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
         } else {
             $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file;
             $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
         }
         if ($plugin_type == 'modifier') {
             $this->modifier_plugins[$plugin_name] = true;
         }
         return $function;
     }
     if (is_callable($function)) {
         // plugin function is defined in the script
         return $function;
     }
     return false;
 }
 /**
  * get Smarty property in template context
  *
  * @param string $property_name property name
  */
 public function __get($property_name)
 {
     switch ($property_name) {
         case 'source':
             if (empty($this->template_resource)) {
                 throw new SmartyException("Unable to parse resource name \"{$this->template_resource}\"");
             }
             $this->source = Smarty_Resource::source($this);
             // cache template object under a unique ID
             // do not cache eval resources
             if ($this->source->type != 'eval') {
                 $_templateId = sha1($this->source->unique_resource . $this->cache_id . $this->compile_id);
                 $this->smarty->template_objects[$_templateId] = $this;
             }
             return $this->source;
         case 'compiled':
             $this->compiled = $this->source->getCompiled($this);
             return $this->compiled;
         case 'cached':
             if (!class_exists('Smarty_Template_Cached')) {
                 include SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
             }
             $this->cached = new Smarty_Template_Cached($this);
             return $this->cached;
         case 'compiler':
             $this->smarty->loadPlugin($this->source->compiler_class);
             $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
             return $this->compiler;
             // FIXME: routing of template -> smarty attributes
         // FIXME: routing of template -> smarty attributes
         default:
             if (property_exists($this->smarty, $property_name)) {
                 return $this->smarty->{$property_name};
             }
     }
     throw new SmartyException("template property '{$property_name}' does not exist.");
 }
 /**
  * Load Resource Handler
  *
  * @param Smarty $smarty    smarty object
  * @param string $type      name of the resource
  * @return Smarty_Resource Resource Handler
  */
 public static function load(Smarty $smarty, $type)
 {
     // try smarty's cache
     if (isset($smarty->_resource_handlers[$type])) {
         return $smarty->_resource_handlers[$type];
     }
     // try registered resource
     if (isset($smarty->registered_resources[$type])) {
         if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
             $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
             // note registered to smarty is not kept unique!
             return $smarty->_resource_handlers[$type];
         }
         if (!isset(self::$resources['registered'])) {
             self::$resources['registered'] = new Smarty_Internal_Resource_Registered();
         }
         if (!isset($smarty->_resource_handlers[$type])) {
             $smarty->_resource_handlers[$type] = self::$resources['registered'];
         }
         return $smarty->_resource_handlers[$type];
     }
     // try sysplugins dir
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
             self::$resources[$type] = new $_resource_class();
         }
         return $smarty->_resource_handlers[$type] = self::$resources[$type];
     }
     // try plugins dir
     $_resource_class = 'Smarty_Resource_' . ucfirst($type);
     if ($smarty->loadPlugin($_resource_class)) {
         if (isset(self::$resources[$type])) {
             return $smarty->_resource_handlers[$type] = self::$resources[$type];
         }
         if (class_exists($_resource_class, false)) {
             self::$resources[$type] = new $_resource_class();
             return $smarty->_resource_handlers[$type] = self::$resources[$type];
         } else {
             $smarty->registerResource($type, array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
             // give it another try, now that the resource is registered properly
             return self::load($smarty, $type);
         }
     }
     // try streams
     $_known_stream = stream_get_wrappers();
     if (in_array($type, $_known_stream)) {
         // is known stream
         if (is_object($smarty->security_policy)) {
             $smarty->security_policy->isTrustedStream($type);
         }
         if (!isset(self::$resources['stream'])) {
             self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
         }
         return $smarty->_resource_handlers[$type] = self::$resources['stream'];
     }
     // TODO: try default_(template|config)_handler
     // give up
     throw new SmartyException("Unkown resource type '{$type}'");
 }
Beispiel #10
0
 /**
  * Load compiler object
  *
  * @throws \SmartyException
  */
 public function loadCompiler()
 {
     $this->smarty->loadPlugin($this->source->compiler_class);
     $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
 }
 public static function load(Smarty $smarty, $type)
 {
     if (isset($smarty->_resource_handlers[$type])) {
         return $smarty->_resource_handlers[$type];
     }
     if (isset($smarty->registered_resources[$type])) {
         if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
             $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
             return $smarty->_resource_handlers[$type];
         }
         if (!isset(self::$resources['registered'])) {
             self::$resources['registered'] = new Smarty_Internal_Resource_Registered();
         }
         if (!isset($smarty->_resource_handlers[$type])) {
             $smarty->_resource_handlers[$type] = self::$resources['registered'];
         }
         return $smarty->_resource_handlers[$type];
     }
     if (isset(self::$sysplugins[$type])) {
         if (!isset(self::$resources[$type])) {
             $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
             self::$resources[$type] = new $_resource_class();
         }
         return $smarty->_resource_handlers[$type] = self::$resources[$type];
     }
     $_resource_class = 'Smarty_Resource_' . ucfirst($type);
     if ($smarty->loadPlugin($_resource_class)) {
         if (isset(self::$resources[$type])) {
             return $smarty->_resource_handlers[$type] = self::$resources[$type];
         }
         if (class_exists($_resource_class, false)) {
             self::$resources[$type] = new $_resource_class();
             return $smarty->_resource_handlers[$type] = self::$resources[$type];
         } else {
             $smarty->registerResource($type, array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
             return self::load($smarty, $type);
         }
     }
     $_known_stream = stream_get_wrappers();
     if (in_array($type, $_known_stream)) {
         if (is_object($smarty->security_policy)) {
             $smarty->security_policy->isTrustedStream($type);
         }
         if (!isset(self::$resources['stream'])) {
             self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
         }
         return $smarty->_resource_handlers[$type] = self::$resources['stream'];
     }
     throw new SmartyException("Unkown resource type '{$type}'");
 }
 /**
  * get Smarty property in template context
  *
  * @param string $property_name property name
  *
  * @return mixed
  * @throws SmartyException
  */
 public function __get($property_name)
 {
     switch ($property_name) {
         case 'source':
             $this->loadSource();
             return $this->source;
         case 'compiled':
             $this->compiled = Smarty_Template_Compiled::load($this);
             return $this->compiled;
         case 'cached':
             $this->cached = Smarty_Template_Cached::load($this);
             return $this->cached;
         case 'compiler':
             $this->smarty->loadPlugin($this->source->compiler_class);
             $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
             return $this->compiler;
             // FIXME: routing of template -> smarty attributes
         // FIXME: routing of template -> smarty attributes
         default:
             if (property_exists($this->smarty, $property_name)) {
                 return $this->smarty->{$property_name};
             }
             throw new SmartyException("template property '{$property_name}' does not exist.");
     }
 }
 /**
  * Load Resource Handler
  *
  * @param Smarty $smarty        smarty object
  * @param string $resource_type name of the resource
  * @return Smarty_Resource Resource Handler
  */
 public static function load(Smarty $smarty, $resource_type)
 {
     // try the instance cache
     if (isset(self::$resources[$resource_type])) {
         return self::$resources[$resource_type];
     }
     // try registered resource
     if (isset($smarty->registered_resources[$resource_type])) {
         if ($smarty->registered_resources[$resource_type] instanceof Smarty_Resource) {
             return self::$resources[$resource_type] = $smarty->registered_resources[$resource_type];
         }
         if (!isset(self::$resources['registered'])) {
             self::$resources['registered'] = new Smarty_Internal_Resource_Registered();
         }
         return self::$resources['registered'];
     }
     // try sysplugins dir
     if (isset(self::$sysplugins[$resource_type])) {
         $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($resource_type);
         return self::$resources[$resource_type] = new $_resource_class();
     }
     // try plugins dir
     $_resource_class = 'Smarty_Resource_' . ucfirst($resource_type);
     if ($smarty->loadPlugin($_resource_class)) {
         if (class_exists($_resource_class, false)) {
             return self::$resources[$resource_type] = new $_resource_class();
         } else {
             $smarty->registerResource($resource_type, array("smarty_resource_{$resource_type}_source", "smarty_resource_{$resource_type}_timestamp", "smarty_resource_{$resource_type}_secure", "smarty_resource_{$resource_type}_trusted"));
             // give it another try, now that the resource is registered properly
             return self::load($smarty, $resource_type);
         }
     }
     // try streams
     $_known_stream = stream_get_wrappers();
     if (in_array($resource_type, $_known_stream)) {
         // is known stream
         if (is_object($smarty->security_policy)) {
             $smarty->security_policy->isTrustedStream($resource_type);
         }
         if (!isset(self::$resources['stream'])) {
             self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
         }
         return self::$resources['stream'];
     }
     // give up
     throw new SmartyException('Unkown resource type \'' . $resource_type . '\'');
 }
 /**
  * Takes unknown classes and loads plugin files for them
  * class name format: Smarty_PluginType_PluginName
  * plugin filename format: plugintype.pluginname.php
  *
  * @param  string $plugin_name class plugin name to load
  * @param  bool   $check       check if already loaded
  * @return string |boolean filepath of loaded file or false
  */
 public function loadPlugin($plugin_name, $check = true)
 {
     return $this->smarty->loadPlugin($plugin_name, $check);
 }