| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace MGModule\DNSManager2\mgLibs;
- use MGModule\DNSManager2 as main;
- use MGModule\DNSManager2\mgLibs\custom\helpers\HTML5Pattern;
- /**
- * Smarty Wrapper
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class smarty {
- static private $_instance;
-
- private $_smarty;
- private $_templateDIR;
-
- final private function __construct(){}
- final private function __clone(){}
-
- /**
- * Get Single-top Instance
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return smarty
- */
- static function I(){
- if(empty(self::$_instance))
- {
- self::$_instance = new self();
-
- if(!class_exists('Smarty'))
- {
- if(file_exists(ROOTDIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php'))
- {
- require_once(ROOTDIR.DS.'includes'.DS.'smarty'.DS.'Smarty.class.php');
- }
- else
- {
- die('Smarty does not exists!');
- }
- }
-
- self::$_instance->_smarty = new \Smarty();
- }
-
- return self::$_instance;
- }
-
- /**
- * Set Tempalte Dir
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param string $dir
- */
- function setTemplateDir($dir){
- if(is_array($dir))
- {
- throw new exceptions\system('Wrong Template Path');
- }
- self::I()->_templateDIR = $dir;
- }
-
- /**
- * Parse Template File
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @global string $templates_compiledir
- * @param string $template
- * @param array $vars
- * @param string $customDir
- * @return string
- * @throws exceptions\system
- */
- function view($template,$vars = array(), $customDir = false){
- if(is_array($customDir))
- {
- throw new exceptions\system('Wrong Template Path');
- }
-
- global $templates_compiledir;
- if($customDir)
- {
- self::I()->_smarty->template_dir = $customDir;
- }
- else
- {
- self::I()->_smarty->template_dir = self::I()->_templateDIR;
- }
-
- self::I()->_smarty->compile_dir = $templates_compiledir;
- self::I()->_smarty->force_compile = 1;
- self::I()->_smarty->caching = 0;
- self::I()->_smarty->clearAllAssign();
-
- self::I()->_smarty->assign('MGLANG', lang::getInstance());
- self::I()->_smarty->assign('patterns', HTML5Pattern::getPatternsArray());
-
- if(is_array($vars))
- {
- foreach($vars as $key => $val)
- {
- self::I()->_smarty->assign($key, $val);
- }
- }
-
- if(is_array(self::I()->_smarty->template_dir))
- {
- $file = self::I()->_smarty->template_dir[0].DS.$template.'.tpl';
- }
- else
- {
- $file = self::I()->_smarty->template_dir.DS.$template.'.tpl';
- }
- if(!file_exists($file))
- {
- throw new exceptions\system('Unable to find Template:'.$file);
- }
-
- return self::I()->_smarty->fetch($template.'.tpl', time());
- }
- }
|