Example #1
0
 /**
  * sfSmarty::getSmarty()
  *
  * @return Smarty object
  * @access public
  **/
 public function getSmarty()
 {
     if (!self::$smarty) {
         // get the path and instantiate the smarty object
         $smartyClassPath = sfConfig::get('app_sfSmarty_class_path', 'Smarty');
         if (substr($smartyClassPath, -1) != DIRECTORY_SEPARATOR) {
             $smartyClassPath .= DIRECTORY_SEPARATOR;
         }
         require_once dirname(__FILE__) . '/../../../' . $smartyClassPath . 'Smarty.class.php';
         self::$smarty = new Smarty();
         // set the smarty cache directory
         $smartyDirs = sfConfig::get('app_sfSmarty_cache_dir', sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'Smarty');
         if (substr($smartyDirs, -1) != DIRECTORY_SEPARATOR) {
             $smartyDirs .= DIRECTORY_SEPARATOR;
         }
         self::$smarty->compile_dir = $smartyDirs . 'templates_c';
         self::$smarty->cache_dir = $smartyDirs . 'cache';
         self::$templateSecurity = sfConfig::get('app_sfSmarty_template_security', false);
         self::$smarty->security = self::$templateSecurity;
         if (!file_exists(self::$smarty->compile_dir)) {
             if (!mkdir(self::$smarty->compile_dir, 0777, true)) {
                 throw new sfCacheException('Unable to create cache directory "' . self::$smarty->compile_dir . '"');
             }
             if (self::$log) {
                 self::$log->info(sprintf('{sfSmarty} creating compile directory: %s', self::$smarty->compile_dir));
             }
         }
         if (!file_exists(self::$smarty->cache_dir)) {
             if (!mkdir(self::$smarty->cache_dir, 0777, true)) {
                 throw new sfCacheException('Unable to create cache directory "' . self::$smarty->cache_dir . '"');
             }
             if (self::$log) {
                 self::$log->info(sprintf('{sfSmarty} creating cache directory: %s', self::$smarty->cache_dir));
             }
         }
         self::$smarty->register_compiler_function('use', array($this, 'smartyCompilerfunctionUse'));
         self::$smarty->register_postfilter(array('sfSmarty', 'smartyPostFilter'));
     }
     return self::$smarty;
 }
Example #2
0
 /**
  * Return smarty instance
  *
  * @return Smarty
  */
 public function getSmarty()
 {
     static $oSmarty;
     if (!$oSmarty) {
         //create smarty object
         require_once 'Smarty.class.php';
         $oSmarty = new Smarty();
         foreach ($this->_aSmartyProperties as $sName => $mValue) {
             $oSmarty->{$sName} = substr($sName, -4) == '_dir' ? Volcano_Tools::fixPath($mValue) : $mValue;
         }
         foreach ($this->_aCustomFunctions as $sType => $aItems) {
             foreach ($aItems as $aItem) {
                 if (substr($oSmarty->_version, 0, 1) != '2') {
                     //bad code, but smarty3 has version like 'Smarty3-SVN$Rev: 3286 $'
                     if ($sType == 'modifier' || $sType == 'function') {
                         $oSmarty->registerPlugin($sType, $aItem[1], $aItem[0]);
                     } elseif ($sType == 'outputfilter') {
                         $oSmarty->registerFilter('output', $aItem[0]);
                     } elseif ($sType == 'postfilter') {
                         $oSmarty->registerFilter('post', $aItem[0]);
                     } elseif ($sType == 'prefilter') {
                         $oSmarty->registerFilter('pre', $aItem[0]);
                     }
                 } else {
                     if ($sType == 'modifier') {
                         $oSmarty->register_modifier($aItem[1], $aItem[0]);
                     } elseif ($sType == 'function') {
                         $oSmarty->register_function($aItem[1], $aItem[0]);
                     } elseif ($sType == 'outputfilter') {
                         $oSmarty->register_outputfilter($aItem[0]);
                     } elseif ($sType == 'postfilter') {
                         $oSmarty->register_postfilter($aItem[0]);
                     } elseif ($sType == 'prefilter') {
                         $oSmarty->register_prefilter($aItem[0]);
                     }
                 }
             }
         }
     }
     $oSmarty->error_reporting = error_reporting() & ~E_NOTICE;
     return $oSmarty;
 }
Example #3
0
 /**
  * Register a postfilter function to apply
  * to a compiled template after compilation
  *
  * @param callback $function
  * @return void
  */
 function registerPostfilter($function)
 {
     $this->_smarty->register_postfilter($function);
 }