Smarty PHP Class Code Examples

This page contains top rated real world PHP examples of class Smarty extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: general.php Project: jeffthestampede/excelsior
0
/**
 * This function evaluates any string that contains Smarty logic / variables. It handles
 * parsing the email templates, filename strings and other such functionality. It uses on the
 * eval.tpl template, found in /global/smarty.
 *
 * @param string $placeholder_str the string containing the placeholders / Smarty logic
 * @param array $placeholders a hash of values to pass to the template. The contents of the
 *    current language file is ALWAYS sent.
 * @param string $theme
 * @return string a string containing the output of the eval()'d smarty template
 */
function ft_eval_smarty_string($placeholder_str, $placeholders = array(), $theme = "", $plugin_dirs = array())
{
    global $g_root_dir, $g_default_theme, $LANG;
    if (empty($theme) && isset($_SESSION["ft"]["account"]["theme"])) {
        $theme = $_SESSION["ft"]["account"]["theme"];
    } else {
        $theme = $g_default_theme;
    }
    $smarty = new Smarty();
    $smarty->template_dir = "{$g_root_dir}/global/smarty/";
    $smarty->compile_dir = "{$g_root_dir}/themes/{$theme}/cache/";
    foreach ($plugin_dirs as $dir) {
        $smarty->plugins_dir[] = $dir;
    }
    $smarty->assign("eval_str", $placeholder_str);
    if (!empty($placeholders)) {
        while (list($key, $value) = each($placeholders)) {
            $smarty->assign($key, $value);
        }
    }
    $smarty->assign("LANG", $LANG);
    $output = $smarty->fetch("eval.tpl");
    extract(ft_process_hook_calls("end", compact("output", "placeholder_str", "placeholders", "theme"), array("output")), EXTR_OVERWRITE);
    return $output;
}
Example #2
Show file File: smarty_template_source.php Project: rogemus/TAS-Client
0
 /**
  * initialize Source Object for given resource
  * Either [$_template] or [$smarty, $template_resource] must be specified
  *
  * @param  Smarty_Internal_Template $_template         template object
  * @param  Smarty                   $smarty            smarty object
  * @param  string                   $template_resource resource identifier
  *
  * @return Smarty_Template_Source Source Object
  * @throws SmartyException
  */
 public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
 {
     if ($_template) {
         $smarty = $_template->smarty;
         $template_resource = $_template->template_resource;
     }
     if (empty($template_resource)) {
         throw new SmartyException('Missing template name');
     }
     // parse resource_name, load resource handler, identify unique resource name
     if (preg_match('/^([A-Za-z0-9_\\-]{2,})[:]([\\s\\S]*)$/', $template_resource, $match)) {
         $type = $match[1];
         $name = $match[2];
     } else {
         // no resource given, use default
         // or single character before the colon is not a resource type, but part of the filepath
         $type = $smarty->default_resource_type;
         $name = $template_resource;
     }
     $handler = isset($smarty->_cache['resource_handlers'][$type]) ? $smarty->_cache['resource_handlers'][$type] : Smarty_Resource::load($smarty, $type);
     // create new source  object
     $source = new Smarty_Template_Source($handler, $smarty, $template_resource, $type, $name);
     $handler->populate($source, $_template);
     if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
         Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
     }
     return $source;
 }
Example #3
Show file File: smarty_internal_method_clearallcache.php Project: LEXXiY/devschool
0
 /**
  * Empty cache folder
  *
  * @api  Smarty::clearAllCache()
  * @link http://www.smarty.net/docs/en/api.clear.all.cache.tpl
  *
  * @param \Smarty  $smarty
  * @param  integer $exp_time expiration time
  * @param  string  $type     resource type
  *
  * @return integer number of cache files deleted
  */
 public function clearAllCache(Smarty $smarty, $exp_time = null, $type = null)
 {
     $smarty->_clearTemplateCache();
     // load cache resource and call clearAll
     $_cache_resource = Smarty_CacheResource::load($smarty, $type);
     return $_cache_resource->clearAll($smarty, $exp_time);
 }
Example #4
Show file File: smarty_cacheresource_custom.php Project: yangyadong/CarMarket
0
 /**
  * Unlock cache for this template
  *
  * @param Smarty $smarty Smarty object
  * @param Smarty_Template_Cached $cached cached object
  */
 public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
 {
     $cached->is_locked = false;
     $id = $cached->filepath;
     $name = $cached->source->name . '.lock';
     $this->delete($name, null, null, null);
 }
Example #5
Show file File: Temp.class.php Project: lisonglin0129/LDFRAMEWORK
0
 public function temp()
 {
     $smarty = new Smarty();
     $this->obj = $smarty;
     $smarty->caching = false;
     $smarty->template_dir = Temp . $this->TP_PATH;
     $smarty->compile_dir = Temp . $this->TP_PATH . "/" . TP_CACHE_NAME;
     @chmod(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME, 0777);
     @($handler = opendir(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME));
     if ($handler) {
         while (($file = readdir($handler)) !== false) {
             if (strlen($file) > 8) {
                 @chmod(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME . "/" . $file, 0777);
             }
         }
     }
     $smarty->registerPlugin("function", "path", "sourcepath");
     $smarty->registerPlugin("function", "App", "App");
     $smarty->registerPlugin("function", "js", "scripts");
     $smarty->registerPlugin("function", "URL", "URL");
     $smarty->registerPlugin("function", "import", "import");
     $smarty->registerPlugin("function", "nocache", "smarty_block_nocache");
     if (!DEBUG) {
         $smarty->caching = true;
         $smarty->compile_dir = Temp . $this->TP_PATH . "/" . TP_CACHE_NAME;
         $smarty->cache_lifetime = TP_CACHE_TIME;
         $smarty->tp_path = Temp . $this->TP_PATH . "/RunTime";
         $smarty->debugging = TP_DEBUG;
     }
     if (TP_PHP) {
         //$smarty->php_handling = SMARTY_PHP_ALLOW;
     }
 }
Example #6
Show file File: comment.php Project: bendroid/pligg-cms
0
 function print_summary($link, $fetch = false)
 {
     global $current_user, $the_template;
     static $comment_counter = 0;
     static $link_index = 0;
     // setup smarty
     include_once 'internal/Smarty.class.php';
     $smarty = new Smarty();
     $smarty->compile_dir = "cache/";
     $smarty->template_dir = "templates/";
     $smarty->config_dir = "";
     $smarty->assign('pligg_language', pligg_language);
     $smarty->config_load("/languages/lang_" . pligg_language . ".conf");
     // if we can't read the comment, return
     if (!$this->read) {
         return;
     }
     // counter
     $comment_counter++;
     $smarty = $this->fill_smarty($smarty);
     $smarty->assign('rand', rand(1000000, 100000000));
     if ($fetch == false) {
         $smarty->display($the_template . '/comment_show.tpl');
     } else {
         return $smarty->fetch($the_template . '/comment_show.tpl');
     }
 }
Example #7
Show file File: basics.php Project: raylouis/kvwebme
0
/**
 * set up Smarty with common functions
 *
 * @param string $compile_dir the caching directory to use
 *
 * @return object the Smarty object
 */
function Core_smartySetup($compile_dir)
{
    global $DBVARS, $PLUGINS, $PAGEDATA;
    require_once SCRIPTBASE . '/ww.incs/vendor/Smarty-3.1.19/libs/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->left_delimiter = '{{';
    $smarty->right_delimiter = '}}';
    $smarty->assign('WEBSITE_TITLE', htmlspecialchars($DBVARS['site_title']));
    $smarty->assign('WEBSITE_SUBTITLE', htmlspecialchars($DBVARS['site_subtitle']));
    $smarty->assign('GLOBALS', $GLOBALS);
    $smarty->assign('LANGUAGE', @$_SESSION['language']);
    $smarty->assign('LOCATIONNAME', @$_SESSION['location']['name']);
    $smarty->registerPlugin('function', 'BREADCRUMBS', 'Template_breadcrumbs');
    $smarty->registerPlugin('function', 'LANGUAGES', 'Core_languagesGetUi');
    $smarty->registerPlugin('function', 'LOCATIONSELECTOR', 'Core_locationsGetUi');
    $smarty->registerPlugin('function', 'LOGO', 'Template_logoDisplay');
    $smarty->registerPlugin('function', 'MENU', 'menuDisplay');
    $smarty->registerPlugin('function', 'STATSVALUE', 'Template_statsValue');
    $smarty->assign('QRCODE', '/a/f=qrCode/id=' . $PAGEDATA->id);
    $smarty->registerPlugin('function', 'nuMENU', 'Core_menuShowFg');
    foreach ($PLUGINS as $pname => $plugin) {
        if (isset($plugin['frontend']['template_functions'])) {
            foreach ($plugin['frontend']['template_functions'] as $fname => $vals) {
                $smarty->registerPlugin('function', $fname, $vals['function']);
            }
        }
    }
    $smarty->compile_dir = $compile_dir;
    return $smarty;
}
Example #8
Show file File: smarty_internal_smartytemplatecompiler.php Project: rogemus/TAS-Client
0
 /**
  * Initialize compiler
  *
  * @param string $lexer_class  class name
  * @param string $parser_class class name
  * @param Smarty $smarty       global instance
  */
 public function __construct($lexer_class, $parser_class, Smarty $smarty)
 {
     parent::__construct($smarty);
     // get required plugins
     $this->lexer_class = $lexer_class;
     $this->parser_class = $parser_class;
 }
Example #9
Show file File: View.php Project: mamtou/wavephp
0
 /**
  * 初始化smarty模板引擎
  */
 public function __construct()
 {
     $app = Wave::app();
     require $app->frameworkPath . 'Library/Smarty/Smarty.class.php';
     $dir = $app->projectPath . $app->projectName;
     $config = Wave::app()->config['smarty'];
     $smarty = new Smarty();
     $smarty->left_delimiter = $config['left_delimiter'];
     $smarty->right_delimiter = $config['right_delimiter'];
     $smarty->debugging = $config['debugging'];
     $smarty->caching = $config['caching'];
     $smarty->cache_lifetime = $config['cache_lifetime'];
     $smarty->compile_check = $config['compile_check'];
     $smarty->template_dir = $dir . '/' . $config['template_dir'];
     $smarty->cache_dir = $dir . '/' . $config['cache_dir'];
     $smarty->config_dir = $dir . '/' . $config['config_dir'];
     $smarty->compile_dir = $app->projectPath . $config['compile_dir'];
     if (!is_dir($smarty->template_dir)) {
         mkdir($smarty->template_dir);
     }
     if (!is_dir($smarty->compile_dir)) {
         mkdir($smarty->compile_dir);
     }
     if ($config['caching']) {
         if (!is_dir($smarty->cache_dir)) {
             mkdir($smarty->cache_dir);
         }
         if (!is_dir($smarty->config_dir)) {
             mkdir($smarty->config_dir);
         }
     }
     $this->engin = $smarty;
 }
Example #10
Show file File: smarty_cacheresource_custom.php Project: RqHe/aunet1
0
 return;

mestamp = null;
is->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $timestamp);
ched->timestamp = isset($timestamp) ? $timestamp : false;
ched->exists = !!$cached->timestamp;


Example #11
Show file File: common.php Project: kamilpacaq/drydock
0
/**
 * Initialize a new Smarty object.
 * 
 * @return object A new instance of the Smarty class
 */
function smsimple()
{
    require_once "_Smarty/Smarty.class.php";
    $sm = new Smarty();
    //$sm->debugging=true;  //uncomment to enable debugging window for smarty
    return $sm;
}
Example #12
Show file File: install.php Project: kamilpacaq/drydock
0
function smsimple($path)
{
    require_once $path . "_Smarty/Smarty.class.php";
    $sm = new Smarty();
    //$sm->debugging=true;
    return $sm;
}
Example #13
Show file File: function.php Project: quekaihua/Mytieba
0
/**
 * 返回一个Smaryty实例
 * @return Smarty
 */
function V($dir = '')
{
    $smarty = new Smarty();
    $smarty->template_dir = C('TEMPLATE_DIR') . '/' . $dir;
    $smarty->compile_dir = C('COMPILE_DIR');
    return $smarty;
}
Example #14
Show file File: smarty_internal_method_clearcache.php Project: rogemus/TAS-Client
0
 /**
  * Empty cache for a specific template
  *
  * @api  Smarty::clearCache()
  * @link http://www.smarty.net/docs/en/api.clear.cache.tpl
  *
  * @param \Smarty  $smarty
  * @param  string  $template_name template name
  * @param  string  $cache_id      cache id
  * @param  string  $compile_id    compile id
  * @param  integer $exp_time      expiration time
  * @param  string  $type          resource type
  *
  * @return integer number of cache files deleted
  */
 public function clearCache(Smarty $smarty, $template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
 {
     $smarty->_clearTemplateCache();
     // load cache resource and call clear
     $_cache_resource = Smarty_CacheResource::load($smarty, $type);
     return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
 }
Example #15
Show file File: function.php Project: Root-Whoami/xss
0
function InitSmarty($isAdmin = 0)
{
    require_once ROOT_PATH . '/libs/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = ($isAdmin == 0 ? TEMPLATE_PATH : ADMIN_PATH) . '/templates';
    return $smarty;
}
Example #16
Show file File: smarty_cacheresource.php Project: rogemus/TAS-Client
0
 /**
  * Load Cache Resource Handler
  *
  * @param Smarty $smarty Smarty object
  * @param string $type   name of the cache resource
  *
  * @throws SmartyException
  * @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->_cache['cacheresource_handlers'][$type])) {
         return $smarty->_cache['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->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type];
     }
     // try sysplugins dir
     if (isset(self::$sysplugins[$type])) {
         $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
         return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
     }
     // try plugins dir
     $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
     if ($smarty->loadPlugin($cache_resource_class)) {
         return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
     }
     // give up
     throw new SmartyException("Unable to load cache resource '{$type}'");
 }
Example #17
Show file File: smarty_internal_method_clearcache.php Project: dayday0769/smarty
0
 /**
  * Empty cache for a specific template
  *
  * @api  Smarty::clearCache()
  * @link http://www.smarty.net/docs/en/api.clear.cache.tpl
  *
  * @param \Smarty  $smarty
  * @param  string  $template_name template name
  * @param  string  $cache_id      cache id
  * @param  string  $compile_id    compile id
  * @param  integer $exp_time      expiration time
  * @param  string  $type          resource type
  *
  * @return integer number of cache files deleted
  */
 public function clearCache(Smarty $smarty, $template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
 {
     // load cache resource and call clear
     $_cache_resource = Smarty_CacheResource::load($smarty, $type);
     $_cache_resource->invalidLoadedCache($smarty);
     return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
 }
Example #18
Show file File: smarty_cacheresource.php Project: dayday0769/smarty
0
 /**
  * Invalid Loaded Cache Files
  *
  * @param Smarty $smarty Smarty object
  */
 public function invalidLoadedCache(Smarty $smarty)
 {
     $smarty->_cache['isCached'] = array();
     if (isset($smarty->ext->_subtemplate)) {
         $smarty->ext->_subtemplate->tplObjects = array();
     }
 }
Example #19
Show file File: smarty_internal_method_clearallcache.php Project: dayday0769/smarty
0
 /**
  * Empty cache folder
  *
  * @api  Smarty::clearAllCache()
  * @link http://www.smarty.net/docs/en/api.clear.all.cache.tpl
  *
  * @param \Smarty  $smarty
  * @param  integer $exp_time expiration time
  * @param  string  $type     resource type
  *
  * @return integer number of cache files deleted
  */
 public function clearAllCache(Smarty $smarty, $exp_time = null, $type = null)
 {
     // load cache resource and call clearAll
     $_cache_resource = Smarty_CacheResource::load($smarty, $type);
     $_cache_resource->invalidLoadedCache($smarty);
     return $_cache_resource->clearAll($smarty, $exp_time);
 }
Example #20
Show file File: SmartyTemplate.php Project: jkimdon/cohomeals
0
 function renderEntries(Search_ResultSet $entries)
 {
     global $tikipath;
     $smarty = new Smarty();
     $smarty->setCompileDir($tikipath . 'templates_c');
     $smarty->setTemplateDir(null);
     $smarty->setTemplateDir(dirname($this->templateFile));
     $smarty->setPluginsDir(array($tikipath . TIKI_SMARTY_DIR, SMARTY_DIR . 'plugins'));
     $secpol = new Tiki_Security_Policy($smarty);
     $secpol->secure_dir[] = dirname($this->templateFile);
     $smarty->enableSecurity($secpol);
     if ($this->changeDelimiters) {
         $smarty->left_delimiter = '{{';
         $smarty->right_delimiter = '}}';
     }
     foreach ($this->data as $key => $value) {
         $smarty->assign($key, $value);
     }
     $smarty->assign('results', $entries);
     $smarty->assign('facets', array_map(function ($facet) {
         return array('name' => $facet->getName(), 'label' => $facet->getLabel(), 'options' => $facet->getOptions(), 'operator' => $facet->getOperator());
     }, $entries->getFacets()));
     $smarty->assign('count', count($entries));
     $smarty->assign('offset', $entries->getOffset());
     $smarty->assign('offsetplusone', $entries->getOffset() + 1);
     $smarty->assign('offsetplusmaxRecords', $entries->getOffset() + $entries->getMaxRecords());
     $smarty->assign('maxRecords', $entries->getMaxRecords());
     return $smarty->fetch($this->templateFile);
 }
Example #21
Show file File: Emails_class.php Project: alex-k/velotur
0
 function Send($object, $template_name, $recipients, $dump = false)
 {
     global $_CONF;
     $smarty = new Smarty();
     $smarty->assign($object->getValues());
     $subject = " ";
     $headers = " ";
     $smarty->assign('msubject', $subject);
     $smarty->assign('mheaders', $headers);
     $out = $smarty->fetch($_CONF[root_dir] . $_CONF[emails_dir] . $_CONF[$template_name]);
     $body = $smarty->getSmartyVar('capture.body');
     $subject = $smarty->getSmartyVar('capture.subject');
     $from = $smarty->getSmartyVar('capture.from');
     if (empty($from)) {
         $from = $_CONF[mail_from];
     }
     $headers = array();
     if ($add_h = explode("\n", $smarty->getSmartyVar('capture.headers'))) {
         $headers = array_merge($headers, $add_h);
     }
     if (!is_array($recipients) && is_string($recipients)) {
         $recipients = array($recipients);
     }
     if ($dump) {
         mydump($body);
         mydump($subject);
         mydump($headers);
         mydump($recipients);
         exit;
     }
     if ($_CONF[mail_enabled] != 'FALSE') {
         return pmail($recipients, $body, $subject, $headers, $from);
     }
     //exit();
 }
Example #22
Show file File: link.php Project: Grprashanthkumar/ColfusionWeb
0
 function print_summary($type = 'full', $fetch = false, $link_summary_template = 'link_summary.tpl')
 {
     global $current_user, $globals, $the_template, $smarty, $ranklist;
     // DB 09/03/08
     if (!is_numeric($this->id)) {
         return false;
     }
     ///
     include_once './Smarty.class.php';
     $main_smarty = new Smarty();
     $main_smarty->compile_check = false;
     // enable caching at your own risk. this code is still experimental
     //$smarty->cache = true;
     $main_smarty->cache_lifetime = 120;
     $main_smarty->compile_dir = mnmpath . "cache/templates_c/";
     $main_smarty->template_dir = mnmpath . "templates/";
     $main_smarty->cache_dir = mnmpath . "cache/";
     $main_smarty->config_dir = "";
     $main_smarty->assign('pligg_language', pligg_language);
     $main_smarty->config_load(lang_loc . "/languages/lang_" . pligg_language . ".conf");
     if (phpnum() == 4) {
         $main_smarty->force_compile = true;
     }
     $main_smarty = $this->fill_smarty($main_smarty, $type);
     $main_smarty->assign('use_title_as_link', use_title_as_link);
     $main_smarty->assign('open_in_new_window', open_in_new_window);
     $main_smarty->assign('the_template', The_Template);
     include mnminclude . 'extra_fields_smarty.php';
     if ($fetch == false) {
         $main_smarty->display($the_template . '/' . $link_summary_template, 'story' . $this->id . "|" . $current_user->user_id . "|" . $type);
     } else {
         return $main_smarty->fetch($the_template . '/' . $link_summary_template, 'story' . $this->id . "|" . $current_user->user_id . "|" . $type);
     }
 }