Example #1
0
 function buildView($template, $userData, $output = false)
 {
     require_once dirname(__FILE__) . '/smartyview.php';
     $view = new SmartyView();
     $view->init($this->app);
     $view->setArray($userData);
     if (!$output) {
         $result = $view->build($template);
     } else {
         $result = $view->display($template);
     }
     return $result;
 }
Example #2
0
 public function __construct()
 {
     //smarty配置
     if (!is_null(self::$smarty)) {
         return;
     }
     $smarty = new Smarty();
     $smarty->template_dir = ROOT_PATH . APP_PATH . '/' . MODULE . APP_TPL_PATH . '/' . CONTROLLER . '/';
     //模板目录
     $smarty->compile_dir = APP_TEMP_PATH . '/Compile/' . MODULE . '/';
     //模板编译目录
     $smarty->cache_dir = APP_TEMP_PATH . '/Cache/' . MODULE . '/';
     //模板缓存目录
     if (!file_exists($smarty->cache_dir)) {
         Dir::create($smarty->cache_dir);
     }
     $smarty->left_delimiter = C('LEFT_DELIMITER');
     //左边界符号
     $smarty->right_delimiter = C('RIGHT_DELIMITER');
     //右边界符
     $smarty->caching = C('CACHE_ON');
     //缓存开启
     $smarty->cache_lifetime = C('CACHE_TIME');
     //缓存时间
     // $smarty->allow_php_templates = true;
     self::$smarty = $smarty;
 }
Example #3
0
 public function &render()
 {
     $this->setAttribute('content', $this->getEngine()->fetch($this->getDirectory() . '/' . $this->contentTemplate));
     $user = $this->getContext()->getUser();
     if ($user->isAuthenticated()) {
         $roles = array();
         $user_roles = $user->getAttribute('Login')->getRoles();
         foreach ($user_roles as $role) {
             if (array_key_exists($role->name, $roles)) {
                 $roles[$role->name] = array();
             }
             $roles[$role->name][] = $role;
         }
         $commontasks = '';
         if ($this->renderTasks) {
             foreach (array_keys($roles) as $roleName) {
                 $name = str_replace(array(' ', '.', '/', '\\', '&', '?', ';'), '', $roleName);
                 $this->setAttribute('roles', $roles[$roleName]);
                 // TODO: check for template existence
                 $commontasks = $this->getEngine()->fetch($this->getDirectory() . '/commontasks/' . $name . '.tpl') . $commontasks;
             }
             $commontasks = $this->getEngine()->fetch($this->getDirectory() . '/commontasks/_everyone.tpl') . $commontasks;
         }
         $this->setAttribute("commontasks", $commontasks);
     }
     return parent::render();
 }
Example #4
0
 protected function assign($var, $value)
 {
     if (C("SMARTY_ON")) {
         parent::assign($var, $value);
     } else {
         $this->var[$var] = $value;
     }
 }
Example #5
0
 public function __construct()
 {
     if (is_null(self::$smarty)) {
         $smarty = new Smarty();
         $smarty->template_dir = APP_TPL_PATH . '/' . CONTROLLER . '/';
         $smarty->compile_dir = APP_COMPILE_PATH;
         $smarty->left_delimiter = C('SMARTY_LEFT_DELIMITER');
         $smarty->right_delimiter = C('SMARTY_RIGHT_DELIMITER');
         $smarty->cache_dir = APP_CACHE_PATH;
         $smarty->caching = C('SMARTY_CACHE_ON');
         $smarty->cache_lifetime = C('SMARTY_CACHE_LIFETIME');
         self::$smarty = $smarty;
     }
 }
Example #6
0
 public function __construct()
 {
     if (!is_null(self::$smarty)) {
         return;
     }
     $smarty = new Smarty();
     $smarty->left_delimiter = C('LEFT_DELIMITER');
     $smarty->right_delimiter = C('RIGHT_DELIMITER');
     $smarty->template_dir = APP_TPL_PATH . '/' . CONTROLLER . '/';
     $smarty->compile_dir = APP_COMPILE_PATH;
     $smarty->cache_dir = APP_CACHE_PATH;
     $smarty->caching = C('CACHE_ON');
     $smarty->cache_lifetime = C("CACHE_TIME");
     $smarty->unmuteExpectedErrors();
     self::$smarty = $smarty;
 }
Example #7
0
 /**
  * 初期処理
  * @access public
  * @param Object $contextt context
  * @return boolean 処理結果
  */
 public function initialize($context)
 {
     parent::initialize($context);
     /* 初期値をセットする */
     $this->controller = $context->getController();
     $this->request = $context->getRequest();
     $this->user = $context->getUser();
     $this->moduleName = $context->getModuleName();
     $this->actionName = $context->getActionName();
     $this->messages =& CommonMessages::getInstance();
     /* フォーム登録リストのフォームをsmartyにすべてセットする */
     $o_smarty =& $this->getEngine();
     $o_smarty->register_object("style", $this, array("request", "checkErrorElement"));
     $this->quickformSmarty = new HTML_QuickForm_Renderer_ArraySmarty($this->getEngine());
     $formList = $this->request->getAttribute('formList');
     foreach ($formList as $formName) {
         $this->setForm($formName);
     }
     /* メッセージをsmartyにセットする */
     if ($this->request->hasAttribute('messages')) {
         $messages =& $this->request->getAttribute('messages');
         $messages = array_unique($messages);
         $this->setAttributeByRef('messages', $messages);
     }
     /* エラーメッセージをsmartyにセットする */
     if ($this->request->hasErrors()) {
         $errors =& $this->request->getErrors();
         $errors = array_unique($errors);
         $this->setAttributeByRef('errors', $errors);
     }
     // 共通の CSS をセット
     array_push($this->css_file_array, ACS_SELECTION_CSS_DIR . 'default.css');
     $this->setAttribute('include_css_array', $this->css_file_array);
     // 共通の JS をセット
     array_push($this->js_file_array, ACS_JS_DIR . 'swap.js');
     $this->setAttribute('include_script_array', $this->js_file_array);
     return true;
 }
Example #8
0
 public function __construct()
 {
     //smarty配置
     if (!is_null(self::$smarty)) {
         return;
     }
     $smarty = new Smarty();
     $smarty->template_dir = APP_TPL_PATH . '/' . CONTROLLER . '/';
     //模板目录
     $smarty->compile_dir = APP_COMPILE_PATH;
     //模板编译目录
     $smarty->cache_dir = APP_CACHE_PATH;
     //模板缓存目录
     $smarty->left_delimiter = C('LEFT_DELIMITER');
     //左边界符号
     $smarty->right_delimiter = C('RIGHT_DELIMITER');
     //右边界符
     $smarty->caching = C('CACHE_ON');
     //缓存开启
     $smarty->cache_lifetime = C('CACHE_TIME');
     //缓存时间
     self::$smarty = $smarty;
 }
Example #9
0
 /**
  * Creates new Smarty object instance if it doesn't already exist, and returns it.
  *
  * @throws RuntimeException If Smarty lib directory does not exist
  * @return Smarty Instance
  */
 public static function getInstance()
 {
     if (!self::$smartyInstance instanceof Smarty) {
         if (!is_dir(self::$smartyDirectory)) {
             throw new RuntimeException('Cannot set the Smarty lib directory : ' . self::$smartyDirectory . '. Directory does not exist.');
         }
         require_once self::$smartyDirectory . '/Smarty.class.php';
         self::$smartyInstance = new Smarty();
         self::$smartyInstance->template_dir = is_null(self::$smartyTemplatesDirectory) ? $this->getTemplatesDirectory() : self::$smartyTemplatesDirectory;
         if (self::$smartyCompileDirectory) {
             self::$smartyInstance->compile_dir = self::$smartyCompileDirectory;
         }
         if (self::$smartyCacheDirectory) {
             self::$smartyInstance->cache_dir = self::$smartyCacheDirectory;
         }
     }
     return self::$smartyInstance;
 }
Example #10
0
 /**
  * [assign 向模板分配变量]
  * 如果以数组做参数,必须使用关联数组
  * @param  [type] $var   [description]
  * @param  [type] $value [description]
  * @return null
  */
 protected function assign($var, $value = null)
 {
     if (C('SMARTY_ON')) {
         return parent::assign($var, $value);
     }
     if (is_array($var)) {
         foreach ($var as $k => $v) {
             if (!is_string($k)) {
                 halt('如果使用数组向模板分配变量,必须使用关联数组');
             } else {
                 $this->vars[$k] = $v;
             }
         }
     }
     if (is_string($var)) {
         $this->vars[$var] = $value;
     }
 }
 public function &render()
 {
     $request = $this->getContext()->getRequest();
     $this->setAttribute('nocList', $request->getAttribute("nocList"));
     return parent::render();
 }
Example #12
0
 public static function conf($conf)
 {
     self::$conf = $conf;
 }
 /**
  * Sets some  in this case, we leave it all up to the child classes to reimplement
  * this and by default call View::render()
  *
  * @returns always true
  */
 function render()
 {
     if (!$this->isCached()) {
         // and then add our stuff to the view...
         $this->setValue('archives', $this->_getArchives());
         $this->setValue('recentposts', $this->_getRecentPosts());
         $this->setValue('mylinkscategories', $this->_getLinkCategories());
         $this->setValue('monthposts', $this->_getMonthPosts());
         $this->setValue('articlecategories', $this->_getArticleCategories());
         $this->generateCalendar($this->getValue('Year'), $this->getValue('Month'));
         // also, let's not forget about the plugins...
         // put the plugins in the context
         $plugins = $this->_pm->getPlugins();
         foreach ($plugins as $name => $plugin) {
             $this->setValue($name, $plugin);
         }
     }
     //
     // these things can go in since they do not mean much overhead when generating the view...
     //
     $this->setValue('locale', $this->_blogInfo->getLocale());
     $this->setValue('version', Version::getVersion());
     $this->setValue('now', new Timestamp());
     $this->setValue('blog', $this->_blogInfo);
     $this->setValue('url', $this->_blogInfo->getBlogRequestGenerator());
     $this->setValue('utils', $this->_blogInfo->getBlogRequestGenerator());
     $this->setValue('blogsettings', $this->_blogInfo->getSettings());
     $this->setValue('rss', new RssParser());
     // ask the parent to do something, if needed
     parent::render();
 }