示例#1
0
 /**
  * Create a new template object
  * @return object
  */
 public static function create()
 {
     // Try/catch statement
     try {
         // Required Smarty libraries
         require_once dirname(__DIR__) . '/smarty/libs/Smarty.class.php';
         // Optional - load custom security features
         //require_once(__DIR__.'/smartysecuritycustom.inc.php');
         // Smarty v3.1 or newer
         $smarty = new Smarty();
         $smarty->setTemplateDir(Config::read('smarty|templateDirectory'));
         $smarty->setCompileDir(Config::read('smarty|compileDirectory'));
         $smarty->setCacheDir(Config::read('smarty|cacheDirectory'));
         // Optional - override configs
         //$smarty->setConfigDir(Config::read('smarty|configDirectory'));
         // Optional - override plugins
         //$smarty->setPluginsDir(Config::read('smarty|pluginsDirectory'));
         $smarty->setCacheLifetime(Config::read('smarty|cacheLifetime'));
         // Disable caching
         $smarty->force_compile = true;
         $smarty->compile_check = true;
         $smarty->setCaching(Smarty::CACHING_OFF);
         // Optional - enable security restrictions
         //$smarty->enableSecurity('SmartySecurityCustom');
         // Return Smarty object
         return $smarty;
     } catch (Exception $e) {
         Log::error("Error while loading template engine");
         // Exception error
         return false;
     }
 }
示例#2
0
require_once PROTECTED_PATH . '/Framework/Smarty/Smarty.class.php';
$smarty = new Smarty();
//修改 smarty 缺省的 {},太容易导致错误了
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
// smarty 缺省对所有的输出都要做 html_specialchars 防止出错
$smarty->escape_html = true;
// Smarty 严重安全漏洞,由于 smarty 不会过滤 <script language="php">phpinfo();</php> 这样的代码,我们只能自己过滤
function smarty_helper_security_output_filter($source, Smarty_Internal_Template $smartyTemplate)
{
    return preg_replace('/<script[^>]*language[^>]*>(.*?)<\\/script>/is', "", $source);
}
$smarty->registerFilter('output', 'smarty_helper_security_output_filter');
//缺省不缓存,防止出错,后面不同页面根据实际需要再自己定义缓存
$smarty->setCaching(Smarty::CACHING_OFF);
$smarty->setCacheLifetime(0);
/**
 * 定义全局的 smarty 缓存开关
 *
 * @param $enable boolean 开/关
 * @param $ttl    integer 缓存时间
 * @param $policy smarty 缓存时间的策略,比如 \Smarty::CACHING_LIFETIME_SAVED
 * */
function enableSmartyCache($enable, $ttl = 0, $policy = \Smarty::CACHING_LIFETIME_SAVED)
{
    global $f3;
    global $smarty;
    if ($enable && $f3->get('sysConfig[smarty_caching]')) {
        $smarty->setCaching($policy);
        $smarty->setCacheLifetime($ttl);
        return;
示例#3
0
文件: init.php 项目: Erdou/Rikiki-MVC
 * User: Erdal Gunyar
 * Date: 28/01/2016
 * Time: 11:48
 */
/* Path settings */
define('ROOT_DIR', getcwd() . '/');
/* Composer autoload */
require ROOT_DIR . 'app/vendor/autoload.php';
/* DB */
Propel::init(ROOT_DIR . 'db/build/conf/orm-conf.php');
/* Global variables */
global $_DATA, $_SMARTY;
$_DATA = [];
/* Smarty settings */
$_SMARTY = new Smarty();
$_SMARTY->setTemplateDir(ROOT_DIR . 'tpl');
$_SMARTY->setCompileDir(ROOT_DIR . 'app/cache/templates');
$_SMARTY->setCacheDir(ROOT_DIR . 'app/cache/full-page');
$_SMARTY->setConfigDir(ROOT_DIR . 'config/');
$caching = CACHING_ENABLED ? Smarty::CACHING_LIFETIME_CURRENT : Smarty::CACHING_OFF;
$_SMARTY->setCaching($caching);
$_SMARTY->setCacheLifetime(-1);
// Never expires
$_SMARTY->setCompileCheck(ENVIRONMENT == 'dev');
/* Session */
session_start();
if ($_SESSION['error']) {
    $_DATA['error'] = $_SESSION['error'];
    $_SESSION['error'] = false;
    unset($_SESSION['error']);
}
示例#4
0
$log_file = date('Ymd') . '.log';
$log = new Logs($debug_mode, $log_file);
//读取网站设置
$get_sysconf = 'select `key`,`value` from ' . $db->table('sysconf');
global $config;
$config_tmp = $db->fetchAll($get_sysconf);
foreach ($config_tmp as $tmp) {
    $config[$tmp['key']] = $tmp['value'];
}
//初始化smarty对象
global $smarty;
$smarty = new Smarty();
$smarty->setCompileDir(ROOT_PATH . 'control/data/compiles');
$smarty->setTemplateDir(ROOT_PATH . 'control/themes/');
$smarty->setCacheDir(ROOT_PATH . 'control/data/caches');
$smarty->setCacheLifetime(1800);
//设置缓存文件超时时间为1800秒
//Debug模式下每次都强制编译输出
if ($debug_mode) {
    //$smarty->clearAllCache();
    //$smarty->clearCompiledTemplate();
    $smarty->force_compile = true;
}
//设置系统设置
assign('config', $config);
//设置语言包
assign('lang', $lang);
//设置网站参数
assign('config', $config);
//设置模板路径
assign('template_dir', 'themes/' . $config['themes'] . '/');
示例#5
0
 /**
  *
  */
 public static function project_history()
 {
     SystemEvent::raise(SystemEvent::DEBUG, "Called.", __METHOD__);
     if (empty($GLOBALS['project']) || !$GLOBALS['project'] instanceof Project || empty($_GET['bid'])) {
         $msg = 'Invalid request';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     //
     // Viewing project build details
     //
     $build = null;
     // It's possible that no build was triggered yet.
     if (isset($_GET['bid']) && !empty($_GET['bid'])) {
         $build = Project_Build::getById($_GET['bid'], $GLOBALS['project'], $GLOBALS['user']);
     }
     if (!$build instanceof Project_Build) {
         $msg = 'Invalid request';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     //
     // We need to process a Smarty file...
     // TODO: Centralize this
     //
     require_once CINTIENT_SMARTY_INCLUDE;
     $smarty = new Smarty();
     $smarty->setAllowPhpTag(true);
     $smarty->setCacheLifetime(0);
     $smarty->setDebugging(SMARTY_DEBUG);
     $smarty->setForceCompile(SMARTY_FORCE_COMPILE);
     $smarty->setCompileCheck(SMARTY_COMPILE_CHECK);
     $smarty->setTemplateDir(SMARTY_TEMPLATE_DIR);
     $smarty->setCompileDir(SMARTY_COMPILE_DIR);
     $smarty->error_reporting = error_reporting();
     Framework_SmartyPlugin::init($smarty);
     //
     // Special tasks. This is post build, so we're fetching an existing special task (never creating it)
     //
     $specialTasks = $build->getSpecialTasks();
     $smarty->assign('project_specialTasks', $specialTasks);
     if (!empty($specialTasks)) {
         foreach ($specialTasks as $task) {
             if (!class_exists($task)) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task. [PID={$GLOBALS['project']->getId()}] [BUILD={$build->getId()}] [TASK={$task}]", __METHOD__);
                 continue;
             }
             $o = $task::getById($build, $GLOBALS['user'], Access::READ);
             //$smarty->assign($task, $o); // Register for s
             if (!$o instanceof Build_SpecialTaskInterface) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task ID. [PID={$GLOBALS['project']->getId()}] [BUILD={$build->getId()}] [TASK={$task}] [TASKID={$build->getId()}]", __METHOD__);
                 continue;
             }
             $viewData = $o->getViewData();
             if (is_array($viewData)) {
                 foreach ($viewData as $key => $value) {
                     $smarty->assign($key, $value);
                 }
             }
             $o = null;
             unset($o);
         }
     }
     // Last assignments
     $smarty->assign('project_build', $build);
     $smarty->display('includes/buildHistoryRev.inc.tpl');
 }