コード例 #1
0
ファイル: Ksmarty.php プロジェクト: Xackery/coop
 /**
  * Ksmarty singleton instance 
  *
  * @return  singleton
  */
 public static function instance()
 {
     // Check if the instance already exists
     if (Ksmarty::$instance === NULL) {
         // Load Smarty
         if (!class_exists('Smarty', FALSE)) {
             require Kohana::find_file('vendor', 'smarty/Smarty.class');
         }
         // Initialize Smarty
         $s = new Smarty();
         // Apply configuration data
         $config = Kohana::$config->load('smarty');
         $s->compile_dir = $config->compile_dir;
         $s->plugins_dir = $config->plugins_dir;
         $s->cache_dir = $config->cache_dir;
         $s->config_dir = $config->config_dir;
         $s->debug_tpl = $config->debug_tpl;
         $s->debugging_ctrl = $config->debugging_ctrl;
         $s->debugging = $config->debugging;
         $s->caching = $config->caching;
         $s->force_compile = $config->force_compile;
         // Check to see if we're using Smarty 3, in a PHP 4 compatible way
         if (!array_key_exists('_version', get_class_vars('Smarty'))) {
             // If so, we need to set the security policy using the new method
             if ($config->security) {
                 if ($config->security_policy !== NULL) {
                     $s->enableSecurity($config->security_policy);
                 } else {
                     // Use default settings
                     $s->enableSecurity();
                 }
             }
         } else {
             $s->security = $config->security;
         }
         // Register the autoload filters
         $s->autoload_filters = array('pre' => $config->pre_filters, 'post' => $config->post_filters, 'output' => $config->output_filters);
         // Create the instance singleton
         Ksmarty::$instance = $s;
     }
     // Return the singleton
     return Ksmarty::$instance;
 }
コード例 #2
0
ファイル: View.php プロジェクト: Xackery/coop
 /**
  * Captures the output that is generated when a view is included.
  * The view data will be extracted to make local variables. This method
  * is static to prevent object scope resolution.
  *
  * @param   string  filename
  * @param   array   variables
  * @return  string
  */
 protected static function capture($template, array $data)
 {
     if ($template == '') {
         return;
     }
     // Load Ksmarty only if it's activated and the template-extension matches
     $config = Kohana::$config->load('smarty');
     if ($config->integration && substr(strrchr($template, '.'), 1) == $config->template_ext) {
         // Get the Smarty instance
         $smarty = Ksmarty::instance();
         // Assign all the variables
         foreach ($data as $key => $value) {
             $smarty->assign($key, $value);
         }
         // Fetch the template output
         $output = $smarty->fetch($template);
     } else {
         $output = parent::capture($template, $data);
     }
     // Return the parsed output
     return $output;
 }