_template_dir = Constant::get('BASE_PATH') . '/tpl'; $this->_preDocInit($docArr); $this->assign('DOC', $docArr); $this->setMainTpl($docArr['tpl']); if (is_array($this->tpl_defines) && !empty($this->tpl_defines)) { foreach ($this->tpl_defines as $k=>$v) { $this->assign($v, Constant::get($v)); } } $this->assign('BASE_PATH', dirname(__FILE__).'/../..' ); /* require_once 'class/Session.php'; if ($error = Session::getData(CURR_PAGE, 'error') ){ Session::clearData(CURR_PAGE, 'error'); $this->addContent(array('tpl' => 'msg_error.tpl', 'text' => $error)); } if ($msg = Session::getData(CURR_PAGE, 'msg')){ Session::clearData(CURR_PAGE, 'msg'); $this->addContent(array('tpl' => 'msg.tpl', 'text' => $msg)); } */ } function setTemplateDir($dir) { $dir = strval($dir); $this->_template_dir = $dir; if (is_object($this->Smarty)) { $this->Smarty->template_dir = $this->_template_dir; } return true; } /** * Function set main template * * @param string $tpl path to template file * @access public */ function setMainTpl($tpl) { $this->main_tpl = $tpl; } /** * Function set template's title * * @param string $title title of document * @access private */ function setTitle($title) { $this->content['DOC']['title'] = $title; } /** * Function assign values to template * * @param string $var key of page parameter * @param bool $value value of page parameter * @access public */ function assign($var, $value = false) { $this->content[$var] = $value; } /** * Function * * @param callback $filter address of the filter function/method to apply to the output * @access public */ function registerOutputFilter($filter) { $this->unregisterOutputFilter($filter); $this->_out_filters[] = $filter; } /** * Function * * @param callback $filter address of the filter function/method to look and remove from the list of filters * @access public */ function unregisterOutputFilter($filter) { $key = array_search($filter, $this->_out_filters); if($key !== FALSE) unset($this->_out_filters[$key]); return $key; } /** * Function display a template * * @access public */ function fetch() { global $_DEBUG; $this->smartyInit(); $revFileName = WWW_PATH.'/rev'; if (file_exists($revFileName) && is_file($revFileName) && is_readable($revFileName)) { $rev = (int)file_get_contents($revFileName); $this->Smarty->assign('CURRENT_REVISION', $rev); } $this->Smarty->assign($this->content); debugDisableNotices(); $res = $this->Smarty->fetch($this->main_tpl); require_once('class/Const.php'); if (Constant::get('DEBUG')) { $this->Smarty->assign('debugInfo', $_DEBUG['msgs']); $res .= $this->Smarty->fetch('debug.tpl'); } debugEnableNotices(); foreach($this->_out_filters as $filter){ $res = call_user_func_array($filter, array($res, &$this)); } return $res; } /** * Function display a template * * @access public */ function display() { header('Content-Type: '.constant('CONTENT_TYPE')); echo $this->fetch(); return true; } /** * Function add content to template * * @param array $item array of parameters to add to template * @access public */ function addContent($item, $el_name = '') { if (!$item['tpl']) foreach ($item as $one_item){ $this->addItem($one_item); } else { $this->addItem($item, $el_name); } } /** * Function adding item to ITEM array * * @access public */ function addItem($item, $el_name = '', $item_list_name = 'ITEMS') { $names = array('JSs','VBs', 'CSSs', 'initFuncs'); foreach ($names as $name) { if (isset($item[$name]) && is_array($item[$name])){ foreach ($item[$name] as $file ) { $this->addItemProp($name, $file); } } unset($item[$name]); } if ($el_name != '') { $this->assign($el_name, $item); } else { $this->content[$item_list_name][] = $item; } } function addItemProp($name, $val) { if (!in_array($val, (array)$this->content['DOC'][$name] )){ $this->content['DOC'][$name][] = $val; } return true; } /** * Function return a Smarty instance * * @access public */ function & getSmarty() { if (!class_exists('Smarty') ){ require_once('lib/Smarty/Smarty/Smarty.class.php'); } $Smarty = new Smarty(); $Smarty->compile_check = true; $Smarty->debugging = SMARTY_DEBUG; //$Smarty->template_dir = Constant::get('BASE_PATH') .'/tpl'; $Smarty->template_dir = $this->_template_dir; $Smarty->cache_lifetime = 40; $Smarty->force_compile = false; $Smarty->php_handling = SMARTY_PHP_PASSTHRU; $Smarty->compile_dir = Constant::get('BASE_PATH').'/tmp/tpl_c'; $Smarty->left_delimiter = '{'; $Smarty->right_delimiter = '}'; $Smarty->file_perms = '0777'; $Smarty->dir_perms = '0777'; foreach ($this->tplPlugins as $dir){ $Smarty->plugins_dir[] = Constant::get('BASE_PATH') .'/'.$dir; } return $Smarty; } /** * Function initialize a Smarty * * @access private */ function smartyInit() { if (!(isset($this->Smarty) && is_object($this->Smarty))) { $this->Smarty = Doc::getSmarty(); } return true; } function _getClassName($type) { $className = str_replace('/', '_', $type).'View'; return $className; } function getClassPath($type) { $classFileName = Doc::_getClassFileName($type); $path = $type.'/'.$classFileName.'.php'; return $path; } function _getClassFileName($type) { preg_match('/([^\/]*)$/', $type, $match); $classFileName = $match[0].'View'; return $classFileName; } function showDocItemList($docItemList) { foreach ($docItemList as $docItemArr) { $docItem = SiteMap::getObj(Doc:: getClassPath($docItemArr['type']), $docItemArr); if (!is_null($docItem)){ $docItem->exec(&$this); } } return true; } /* function getDocItemByType($type, $opt = array() ) { $className = Doc::_getClassName($type); $classPath = Doc:: getClassPath($type); if (file_exists(BASE_PATH.'/'.$classPath)){ require_once($classPath); $docItem = new $className($opt); return $docItem; }else { return null; } } */ function enableHTTPS($convert_href = true) { require_once('class/Filter/LinksFilter.php'); $filter = new LinksFilter(array( 'FILTER_HTTPS_FROM' => BASE_URL, 'FILTER_HTTPS_TO' => str_replace('http://', 'https://', BASE_URL), 'FILTER_HTTPS_FORM' => true, 'FILTER_HTTPS_LINK' => $convert_href, )); $this->registerOutputFilter(array(&$filter, 'filter')); } function getPageIdByItem($aclItem, &$_items) { foreach ($_items as $k => $item) { if ($item['type'] == $aclItem['type'] && (isset($aclItem['name']) && $item['name'] == $aclItem['name'] || !isset($aclItem['name'])) ) { $id_doc = $item['id_doc']; unset($_items[$k]); return $id_doc; } } return false; } } function getInitFuncExParams($params = array()) { if (!empty($params)) { $ret = ''; foreach ($params as $param) { if ($param{0} == '{') { $ret .= $param; } else { $ret .= (is_numeric($param))?$param:"'".addslashes($param)."'"; } $ret .= ', '; } $ret = rtrim($ret, ', '); return $ret; } return NULL; } ?>