*/'; protected $_layoutTemplate; protected $_smarty; protected $_smartyPluginPaths = array( 'lib/Smarty/Smarty/plugins', 'lib/Smarty/app_plugins' ); protected $_content = array( 'htmlAttribs' => array( 'xmlns' => 'http://www.w3.org/1999/xhtml', 'class' => 'no-js', ), 'head' => array( 'keywords' => '', 'description' => '', 'meta' => array(), 'base' => '', 'title' => '', 'stylesheet' => array(), 'script' => array(), 'inlineScript' => array(), 'readyFunctions' => array(), 'initFunctions' => array(), ), 'bodyAttribs' => array('onload' => 'bodyOnLoad()'), 'bodyTemplate' => null, 'menu' => null, 'ctrlMenu' => null, 'ITEMS' => array(), ); protected $_resourcesIgnoredAttribs = array( 'skipPacking', // якщо стилю чи скрипту в атрибутах передати 'skipPacking' => true, то Qs_Packer такі ресурси мерджити не буде ); protected $_defaultGroupName = 'ITEMS'; protected $_groupName; protected $_smartyPlugins = array( 'block' => array(), ); protected $_templateRootPath; protected $_outFilters = array(); protected $_templateDefines = array( 'BASE_URL', 'BASE_URL_LANGUAGE', 'CURRENT_PAGE', 'CURRENT_PAGE_FINAL', 'PARENT_PAGE', 'PARENT_PAGE_FINAL', 'BASE_PATH', 'CURRENT_LANGUAGE', 'SITE_LIVE', 'DEFAULT_LANGUAGE', 'NOINDEX_BEGIN', 'NOINDEX_END', 'SITE_REVISION' ); protected $_scriptDefines = array( 'BASE_URL', 'BASE_URL_LANGUAGE', 'CURRENT_PAGE', 'CURRENT_PAGE_FINAL', 'SITE_LIVE', 'PARENT_PAGE', 'PARENT_PAGE_FINAL', 'CURRENT_LANGUAGE', 'DEFAULT_LANGUAGE', 'DEBUG', 'SITE_REVISION', 'OPTIMIZE_RESOURCES', 'USE_PACKED_RESOURCES', 'IS_MOBILE' ); protected $_view; protected $_authClassName; protected $_authAdapterClassName; /** * @var Qs_Auth */ protected $_auth; /** * @var Qs_Auth_Adapter_DbTable */ protected $_authAdapter; protected $_hasAuthentication = false; protected $_options = array(); protected $_optimized = false; /** * @var Qs_Lock_RoleObj */ protected $_lockObj; public function __construct($options) { $this->setBase(Qs_Constant::get('BASE_URL') . '/'); $this->setOptions($options); Qs_Options::setConstructorOptions($this); $this->_init(); } protected function _init() { /** @var $viewRenderer Zend_Controller_Action_Helper_ViewRenderer */ $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); if (null == $viewRenderer->view) { $viewRenderer->setView(Qs_View::getInstance()); } $session = new Qs_Session_Namespace(Qs_Constant::get('CURRENT_PAGE')); if (isset($session->message)) { $this->displayMessage($session->message); } if (isset($session->error)) { $this->displayError($session->error); } if (isset($session->attention)) { $this->displayAttention($session->attention); } if ($this->_hasAuthentication) { $this->authenticate(); } return $this; } public function setAuthentication($value) { $this->_hasAuthentication = (bool) $value; return $this; } public function getAuthentication() { return (bool) $this->_hasAuthentication; } public function setOptions($options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $this->setOption($key, $value); } return $this; } public function getOptions() { return $this->_options; } public function setOption($name, $value) { $method = 'set' . ucfirst($name); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$name] = $value; } return $this; } public function getOption($name) { if (array_key_exists($name, $this->_options)) { return $this->_options[$name]; } return false; } public function setDescription($description) { $this->_content['head']['description'] = $description; return $this; } public function appendHeader($append) { $this->setHeader($this->getHeader() . $append); return $this; } public function setHeader($header) { $this->assign('header', $header); return $this; } public function getHeader() { return $this->getTemplateVariable('header'); } public function getTemplateVariables() { return $this->_content; } public function getTemplateVariable($name) { if (array_key_exists($name, $this->_content)) { return $this->_content[$name]; } return null; } public function setKeywords($keywords) { $this->_content['head']['keywords'] = $keywords; return $this; } public function getView() { if (null === $this->_view) { $this->_view = Qs_View::getInstance(); } return $this->_view; } public function clearStylesheets() { $this->_content['head']['stylesheet'] = array(); return $this; } public function clearInlineScripts() { $this->_content['head']['inlineScript'] = array(); return $this; } public function clearInitFunctions() { $this->_content['head']['initFunctions'] = array(); return $this; } public function clearScripts() { $this->_content['head']['script'] = array(); return $this; } public function setStylesheets(array $list) { $this->clearStylesheets(); foreach ($list as $options) { if (is_array($options)) { call_user_func_array(array($this, 'addStylesheet'), $options); } else { $this->addStylesheet($options); } } return $this; } public function addStylesheet($href, $_attribs = array(), $name = null) { $attribs = array( 'href' => $href, 'media' => 'screen', 'type' => 'text/css', 'rel' => 'stylesheet', ); if (null === $name) { if (strncmp($href, 'css/', 4) == 0) { $name = substr($href, 4); $name = str_replace('.css', '', $name); } else { $name = $href; } } if (isset($this->_content['head']['stylesheet'][$name])) { return $this; } $this->_content['head']['stylesheet'][$name] = array_merge($attribs, $_attribs); return $this; } public function setScripts(array $list) { $this->clearScripts(); foreach ($list as $options) { if (is_array($options)) { call_user_func_array(array($this, 'addScript'), $options); } else { $this->addScript($options); } } return $this; } public function addScript($src, $_attribs = array(), $name = null) { $attribs = array( 'src' => $src, // Tag is not correctly works in IE8 'type' => 'text/javascript', //'language' => 'JavaScript', ); if (null === $name) { if (strncmp($src, 'js/', 3) == 0) { $name = substr($src, 3, -3); } else { $name = $src; } } if (isset($this->_content['head']['script'][$name])) { return $this; } $this->_content['head']['script'][$name] = array_merge($attribs, $_attribs); return $this; } public function addInlineScript($name, $body, $_attribs = array()) { $attribs = array( 'type' => 'text/javascript', 'beforeScripts' => false ); $attribs = array_merge($attribs, $_attribs); $beforeScripts = (int) $attribs['beforeScripts']; unset($attribs['beforeScripts']); $this->_content['head']['inlineScript'][$beforeScripts][$name] = array( 'attribs' => $attribs, 'body' => $body, ); return $this; } protected function _getHeadPart($part) { if (array_key_exists($part, $this->_content['head'])) { return $this->_content['head'][$part]; } return null; } protected function _setHeadPart($part, $attribs) { $this->_content['head'][$part] = $attribs; return $this; } public function appendTitle($append) { $this->setTitle($this->getTitle() . $append); return $this; } public function setTitle($title) { return $this->_setHeadPart('title', $title); } public function getTitle() { return $this->_getHeadPart('title'); } public function setBase($base) { return $this->_setHeadPart('base', $base); } public function getTemplateDirectory() { if (null == $this->_templateRootPath) { $this->setTemplateRootPath(Qs_Constant::get('BASE_PATH') . '/tpl'); } return $this->_templateRootPath; } public function setTemplateRootPath($directory) { $this->_templateRootPath = strval($directory); if (is_object($this->_smarty)) { $this->_smarty->template_dir = $this->_templateRootPath; } return $this; } public function getLayoutTemplate() { if (null === $this->_layoutTemplate) { $this->setLayoutTemplate('index.tpl'); } return $this->_layoutTemplate; } public function setLayoutTemplate($_template) { if ('.' === dirname($_template)) { $template = $this->getTemplate($_template); } else { $template = $_template; } if (empty($template)) { $message = 'Invalid layout template "' . $_template . '" not found in paths: "' . implode('", "', $this->getTemplatePath()) . '".'; throw new Qs_Doc_Exception($message); } $this->_layoutTemplate = $template; return $this; } public function getBodyTemplate() { if (null === $this->_getHeadPart('bodyTemplate')) { $this->_setHeadPart('bodyTemplate', $this->getTemplate('Body/default.tpl')); } return $this->_getHeadPart('bodyTemplate'); } public function setBodyTemplate($_template) { if ('.' === dirname($_template)) { $template = $this->getTemplate('Body/' . $_template); } else { $template = $_template; } if (empty($template)) { Qs_Debug::log('Body template "' . $_template . '" not found in paths: "' . implode('", "', $this->getTemplatePath()) . '".'); if (false === ($template = $this->getTemplate('Body/default.tpl'))) { $message = 'Body template "' . $_template . '" not found in paths: "' . implode('", "', $this->getTemplatePath()) . '".'; throw new Qs_Doc_Exception($message); } } $this->_setHeadPart('bodyTemplate', $template); return $this; } /** * @param string $var * @param mixed $value * @return Qs_Doc */ public function assign($var, $value = false) { $this->_content[$var] = $value; return $this; } public function registerOutputFilter($filter) { $this->unregisterOutputFilter($filter); $this->_outFilters[] = $filter; return $this; } public function unregisterOutputFilter($filter) { $key = array_search($filter, $this->_outFilters); if (false !== $key) { unset($this->_outFilters[$key]); } return $this; } public function setOptimized($flag = true) { $this->_optimized = (bool) $flag; return $this; } public function getOptimized() { return $this->_optimized; } protected function _optimize() { if ($this->_optimized || !Qs_Constant::get('OPTIMIZE_RESOURCES')) { return $this; } if (false !== ($mergedStylesheets = Qs_Packer::getMergedStylesheets($this->_content['head']['stylesheet']))) { $this->setStylesheets($mergedStylesheets); } if (false !== ($mergedScripts = Qs_Packer::getMergedScripts($this->_content['head']['script']))) { $this->setScripts($mergedScripts); } $this->_optimized = true; return $this; } public function fetch($template = null) { $this->_optimize(); $this->getSmarty()->assign('view', Qs_View::getInstance()); $this->getSmarty()->assign('AUTH_INFO', $this->getAuthIdentity()); $this->getSmarty()->assign('scriptDefines', $this->_scriptDefines); $this->addInlineScript( 'isMobile', 'qs.constant("IS_TOUCHSCREEN", ' . ((Qs_Device::isTouchscreen()) ? 'true' : 'false') . ');' ); if (Qs_Navigation::isEnabled() && false != ($nav = Qs_Navigation::get())) { $this->getSmarty()->assign('NAVIGATION', $nav); } foreach ($this->_resourcesIgnoredAttribs as $attribute) { foreach (array('stylesheet', 'script') as $resourceType) { foreach ($this->_content['head'][$resourceType] as &$resource) { if (array_key_exists($attribute, $resource)) { unset($resource[$attribute]); } } } } $html = $this->fetchTemplate($template); foreach($this->_outFilters as $filter) { $html = call_user_func_array($filter, array($html, $this)); } if ('indexing' == Qs_Request::getHeader('ADAPTA_SPIDER') && 'y' == $this->getOption('isIndexing')) { $html = $this->_doIndex($html); } return $html; } public function fetchTemplate($template = null) { if (is_array($this->_templateDefines) && !empty($this->_templateDefines)) { foreach ($this->_templateDefines as $v) { $this->assign($v, Qs_Constant::get($v)); } } $this->getSmarty()->assign($this->getTemplateVariables()); $this->getSmarty()->assign('DOC', $this); $this->getSmarty()->assign('IS_TOUCHSCREEN', Qs_Device::isTouchscreen()); /** @var $debug Qs_Debug */ $debug = Zend_Registry::get('debug'); $debug->setErrorReporting($debug->getErrorReporting() ^ E_NOTICE); $html = $this->getSmarty()->fetch((null === $template) ? $this->getLayoutTemplate() : $template); $debug->restoreErrorReporting(); return $html; } protected function _doIndex($html) { /* метод поки нічого не робить, повернусь до нього коли буду робити пошук */ /*global $TIMER; $html = trim($html); if (!empty($html)) { $html = preg_replace("/\.*\<\/head\>/imsUu", '', $html); $html = preg_replace("/\]*\>.*\<\/script\>/imsUu", '', $html); $html = preg_replace("/\]+nofollow[^\>]*\>.*\<\/a\>/imsUu", '', $html); $noindexBegin = Qs_Constant::get('NOINDEX_BEGIN'); $noindexEnd = Qs_Constant::get('NOINDEX_END'); if ($noindexBegin && $noindexEnd) { $pattern = preg_quote($noindexBegin, '/') . '.*' . preg_quote($noindexEnd, '/'); $html = preg_replace('/' . $pattern . '/imsUu', '', $html); } $html = trim($html); if (!empty($html)) { $index = strip_tags($html); $index = htmlspecialchars_decode($index); $index = str_ireplace(array(' ', '©'), ' ', $index); $index = preg_replace("/\s+/msu", ' ', $index); $index = trim($index); if (!empty($index)) { stopTimer('Script duration'); $cms = App_Cms_Obj::getInstance(); $cms->updateIndex(array( 'idPage' => $this->getOption('id'), 'language' => CURRENT_LANGUAGE, 'url' => Qs_Request::getUrl(), 'title' => $this->getHeader(), 'content' => $index, 'scriptDuration' => $TIMER['Script duration']['total'], )); } } }*/ return $html; } protected function _beforeDisplay() { $this->_initFooter(); return $this; } protected function _initFooter() { $this->assign('FOOTER', str_replace('{currentYear}', date('Y'), App_Settings_Obj::get('footer'))); return $this; } public function sendHeaders() { header('Content-Type: ' . Qs_Constant::get('CONTENT_TYPE')); return $this; } public function display404($options = array()) { $notFound = new App_NotFound_View($options); $notFound->setDoc($this); $notFound->exec(); return $this; } public function display() { $this->_beforeDisplay(); $this->sendHeaders(); echo $this->fetch(); return $this; } public function __toString() { $this->_beforeDisplay(); return $this->fetch(); } protected function _displayMessageBox(array $messages, $type) { $template = $this->getTemplate($type . '.tpl'); foreach ($messages as $message) { $this->addItem(array('tpl' => $template, 'message' => $message)); } return $this; } public function displayMessage($messages) { $messages = (array) $messages; $this->_displayMessageBox($messages, static::MESSAGE_BOX_MESSAGE); return $this; } public function displayError($errors) { $errors = (array) $errors; $this->_displayMessageBox($errors, static::MESSAGE_BOX_ERROR); return $this; } public function displayAttention($attentions) { $attentions = (array) $attentions; $this->_displayMessageBox($attentions, static::MESSAGE_BOX_ATTENTION); return $this; } public function hasAuth() { $file = BASE_PATH . '/' . str_replace(array('_', '\\'), '/', $this->_authClassName) . '.php'; return (null !== $this->_auth || (null !== $this->_authClassName && file_exists($file))); } public function getAuth() { if (null === $this->_auth) { if (null === $this->_authClassName) { throw new Qs_Doc_Exception('Auth is undefined'); } else { $this->_auth = call_user_func($this->_authClassName . '::getInstance'); } } return $this->_auth; } public function setAuth($auth) { if (!($auth instanceof Qs_Auth)) { throw new Qs_Doc_Exception('Auth is not instance of Qs_Auth'); } $this->_auth = $auth; return $this; } public function getAuthAdapter() { if (null === $this->_authAdapter) { if (null === $this->_authAdapterClassName) { if (null == $this->_auth) { if (null === $this->_authClassName) { throw new Qs_Doc_Exception('AuthAdapter is undefined'); } $this->_authAdapterClassName = $this->_authClassName . 'Adapter'; } else { $this->_authAdapterClassName = get_class($this->_auth) . 'Adapter'; } } $this->_authAdapter = new $this->_authAdapterClassName(); } return $this->_authAdapter; } public function setAuthAdapter($authAdaptrer) { if (!($authAdaptrer instanceof Zend_Auth_Adapter_Interface)) { throw new Qs_Doc_Exception('AuthAdapter is not instance of Zend_Auth_Adapter_Interface'); } $this->_authAdapter = $authAdaptrer; return $this; } public function authenticate() { if ($this->getAuth()->hasIdentity()) { $data = $this->getAuth()->getIdentity(); $this->getAuthAdapter()->setIdentity($data); /** @var $result Zend_Auth_Result */ $result = $this->getAuth()->authenticate($this->getAuthAdapter()); if ($result->isValid()) { return true; } else { $this->getAuth()->clearIdentity(); } } if (Qs_Request::isXmlHttpRequest()) { $this->_processAjaxFailedAuth(); } else { $this->getAuth()->setBackUrl(Qs_Request::getUrl()); Qs_Http::redirect($this->getAuth()->getLoginUrl()); } return $this; } protected function _processAjaxFailedAuth() { $this->ajaxResponse(array( 'isValid' => true, 'sessionExpired' => true, 'loginUrl' => $this->getAuth()->getLoginUrl() . '?' . Qs_Doc::POPUP )); return $this; } public function ajaxResponse($response = array()) { header('Cache-Control: no-store, no-cache, must-revalidate, private'); header('Pragma: no-cache'); header('Content-Type: application/x-javascript; charset=utf-8'); die(json_encode($response)); } public function getAuthData($field = false, $default = null) { if ($this->hasAuth()) { return $this->getAuth()->getData($field, $default); } return $default; } public function getAuthIdentity() { if ($this->hasAuth()) { $identity = $this->getAuth()->getIdentity(); if (!empty($identity) && array_key_exists('autologinCode', $identity)) { if (count($identity) == 1) { // has only 'autologinCode' $this->authenticate(); $identity = $this->getAuth()->getIdentity(); } } return $identity; } return false; } public function addItem($item, $groupName = null) { $names = array('script', 'inlineScript', 'stylesheet', 'readyFunction', 'initFunction', 'initObject'); foreach ($names as $name) { if (isset($item[$name]) && is_array($item[$name])){ foreach ($item[$name] as $headItem ) { call_user_func_array(array($this, 'add' . ucfirst($name)), $headItem); } } } if (null === $groupName) { $groupName = $this->getGroupName(); } if (!isset($this->_content[$groupName])) { $this->_content[$groupName] = array(); } $this->_content[$groupName][] = new Qs_Doc_Item($item); return $this; } public function getGroupName() { if (null === $this->_groupName) { return $this->_defaultGroupName; } return $this->_groupName; } public function unsetGroupName() { $this->_groupName = null; return $this; } public function setGroupName($groupName) { $this->_groupName = $groupName; return $this; } public function addReadyFunction($name, $params = array()) { $this->_content['head']['readyFunctions'][] = array( 'name' => $name, 'params' => $params, ); return $this; } public function addInitFunction($name, $params = array()) { $this->_content['head']['initFunctions'][] = array( 'name' => $name, 'params' => $params, ); return $this; } public function addInitObject($name, $params = array(), $assign = null) { $this->_content['head']['initFunctions'][] = array( 'name' => $name, 'params' => $params, 'assign' => $assign, 'new' => true ); return $this; } public function getTemplate($template) { return Qs_SiteMap::getTemplate($template, $this->getTemplatePath()); } public function getTemplatePath() { if (null === $this->_templatePath) { $class = get_class($this); $this->_templatePath = substr($class, 0, strrpos($class, '_')); if (0 === strpos($this->_templatePath, 'App_')) { $this->_templatePath = substr($this->_templatePath, 4); } } return $this->_templatePath; } /** * @return Smarty */ public function getSmarty() { if (null === $this->_smarty) { if (!class_exists('Smarty') ){ require_once 'lib/Smarty/Smarty/Smarty.class.php'; } $this->_smarty = new Smarty(); $this->_smarty->compile_check = true; $this->_smarty->debugging = false; $this->_smarty->template_dir = $this->getTemplateDirectory(); $this->_smarty->cache_lifetime = 40; $this->_smarty->force_compile = false; $this->_smarty->php_handling = SMARTY_PHP_PASSTHRU; $this->_smarty->compile_dir = Qs_Constant::get('BASE_PATH') . '/tmp/tpl_c'; $this->_smarty->left_delimiter = '{'; $this->_smarty->right_delimiter = '}'; foreach ($this->_smartyPlugins['block'] as $name => $block) { $this->_smarty->_plugins['block'][$name] = $block; } foreach ($this->_smartyPluginPaths as $dir){ $this->_smarty->plugins_dir[] = Qs_Constant::get('BASE_PATH') . '/' . $dir; } } return $this->_smarty; } protected function _createItemObj($item) { $separator = (false !== strpos($item['type'], '\\')) ? '\\' : '_'; $class = Qs_SiteMap::getItemTypeClass($item['type'], 'View'); $file = BASE_PATH . '/' . str_replace($separator, '/', $class) . '.php'; if (!file_exists($file)) { Qs_Debug::log('Cms item "' . $item['type'] . '" not found'); return false; } $item['doc'] = $this; if (array_key_exists('id', $item)) { $item['idItem'] = $item['id']; } return new $class($item); } public function renderPageItems($items) { $itemObj = array(); $_pageItems = $items; $indexes = array_keys($items); while (false !== ($index = current($indexes)) && array_key_exists($index, $items)) { next($indexes); $item = $items[$index]; next($items); /** @var $obj Qs_ViewController */ if (false !== ($obj = $this->_createItemObj($item))) { $itemObj[$index] = $obj; } else { continue; } if (method_exists($itemObj[$index], 'preDispatch')) { $itemObj[$index]->preDispatch($items); } } foreach ($items as $index => $item) { if (array_key_exists($index, $itemObj)) { $obj = $itemObj[$index]; } else { if (false === ($obj = $this->_createItemObj($item))) { continue; } } if (isset($items[$index]['groupName'])) { $this->setGroupName($items[$index]['groupName']); } else { $this->unsetGroupName(); } $obj->exec(); unset($itemObj[$index]); $_pageItems[$index]['executed'] = true; } if (Qs_Constant::get('DEBUG')) { Zend_Registry::set('_pageItems', $_pageItems); } return $this; } public function registerSmartyBlock($block, $block_impl, $cacheable = true, $cache_attrs = null) { $this->_smartyPlugins['block'][$block] = array($block_impl, null, null, false, $cacheable, $cache_attrs); return $this; } public function removeItem($index, $groupName = null) { if (null === $groupName) { $groupName = $this->getGroupName(); } if (array_key_exists($index, $this->_content[$groupName])) { unset($this->_content[$groupName][$index]); } return $this; } public function setBodyAttribs($attribs) { $this->_content['bodyAttribs'] = $attribs; } public function setBodyAttrib($name, $value) { $this->_content['bodyAttribs'][$name] = $value; } public function getBodyAttribs() { return $this->_content['bodyAttribs']; } public function getMenu() { return $this->_content['menu']; } public function getCtrlMenu() { if (null === $this->_content['ctrlMenu']) { $filter = array('showInCtrlMenu' => 'y', 'requireSu' => 'n'); if ($this->hasAuth() && $this->getAuth()->getSuMode()) { unset($filter['requireSu']); } $ctrlMenu = Qs_SiteMap::find($filter); $this->_prepareCtrlMenu($ctrlMenu, $filter); $this->_content['ctrlMenu'] = $ctrlMenu; } return $this->_content['ctrlMenu']; } protected function _prepareCtrlMenu(array &$menu, array $filter) { if (!empty($menu)) { foreach ($menu as $key => &$item) { if (!empty($filter['requireSu']) && $filter['requireSu'] != $item['requireSu']) { unset($menu[$key]); } else if (!empty($item['sub'])) { $this->_prepareCtrlMenu($item['sub'], $filter); } } $menu = array_merge($menu); } return $this; } public function getBodyAttrib($name) { if (array_key_exists($name, $this->_content['bodyAttribs'])) { return $this->_content['bodyAttribs'][$name]; } return null; } public function renderScripts($excludedAttribs = null) { $html = ''; foreach ($this->_content['head']['script'] as $attribs) { if (!empty($excludedAttribs)){ if (is_array($excludedAttribs)){ foreach ($excludedAttribs as $excluded){ unset($attribs[$excluded]); } } else { unset($attribs[$excludedAttribs]); } } if (0 === strpos($attribs['src'], 'js/')) { if (Qs_Constant::get('SITE_REVISION')) { $attribs['src'] = BASE_URL . '/js-' . Qs_Constant::get('SITE_REVISION') . '/'. substr($attribs['src'], 3); } else { $attribs['src'] = BASE_URL . '/' . $attribs['src']; } } $html .= '' . "\n "; } return $html; } public function renderStylesheets() { $html = ''; foreach ($this->_content['head']['stylesheet'] as $attribs) { if (Qs_Constant::get('SITE_REVISION')) { if (0 === strpos($attribs['href'], 'css/')) { $attribs['href'] = 'css-' . Qs_Constant::get('SITE_REVISION') . '/'. substr($attribs['href'], 4); } } $html .= ' $value) { $html .= ' ' . $name . ' = "' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8'). '"'; } $html .= '/>' . "\n "; } return $html; } public function renderInlineScripts($indents = null, $beforeScripts = false) { $html = ''; $scriptsHtml = array(); $indents = (!$indents) ? 1 : $indents; $indent = str_repeat(' ', $indents * 4); $beforeScripts = (int) $beforeScripts; if (is_array($this->_content['head']['inlineScript'][$beforeScripts])) { foreach ($this->_content['head']['inlineScript'][$beforeScripts] as $name => $script) { $attribs = ''; foreach ($script['attribs'] as $attribute => $attributeValue) { $attribs .= $attribute . ' = "' . htmlspecialchars($attributeValue, ENT_COMPAT, 'UTF-8'). '" '; } $attribs = trim($attribs); $body = PHP_EOL . '/* Inline Script: ' . $name . ' */' . PHP_EOL . $script['body']; $scriptsHtml[$attribs] .= str_replace(PHP_EOL, PHP_EOL . $indent . $indent, $body) . PHP_EOL; } foreach ($scriptsHtml as $scriptAttribs => $scriptHtml) { $html = ''; } } return $html; } protected function _renderInitFunctions(array $functionsSpec = null) { $functionsSpec = (null === $functionsSpec) ? $this->_content['head']['initFunctions'] : $functionsSpec; $html = ''; foreach ($functionsSpec as $options) { $row = $options['name']; if (!empty($options['params'])) { $params = array(); foreach ($options['params'] as $param) { $params[]= Zend_Json::encode($param, false, array('enableJsonExprFinder' => true)); } $row .= '(' . implode(', ', $params) . ');'; } else { $row .= '();'; } if (isset($options['new']) && $options['new']) { $row = 'new ' . $row; } if (!empty($options['assign'])) { $row = $options['assign'] . ' = ' . $row; } $html .= $row . "\n"; } return $html; } public function renderInitFunctions() { return $this->_renderInitFunctions($this->_content['head']['initFunctions']); } public function renderReadyFunctions() { return $this->_renderInitFunctions($this->_content['head']['readyFunctions']); } function setTemplatePath($path) { $this->_templatePath = $path; return $this; } public function getUserRole() { $role = null; if ($this->hasAuth()) { $role = $this->getAuth()->getRole(); } return $role; } public function getUserId() { $id = null; if ($this->hasAuth()) { $id = $this->getAuth()->getData('id'); } return $id; } public function getLockObj() { if (null === $this->_lockObj) { $this->_lockObj = new Qs_Lock_RoleObj($this->getUserRole(), $this->getUserId(), Zend_Session::getId()); } return $this->_lockObj; } public function setHtmlAttribs(array $attribs) { if (!is_array($attribs) || !Qs_Array::isAssoc($attribs)) { throw new Qs_Exception('Attribs is not associative array'); } $this->_content['htmlAttribs'] = $attribs; return $this; } public function setHtmlAttrib($name, $value) { if (!is_string($name) || '' == $name) { throw new Qs_Exception('Wrong attribute name'); } if (!is_string($value) || '' == $value) { throw new Qs_Exception('Wrong attribute value'); } $this->_content['htmlAttribs'][$name] = $value; return $this; } public function getHtmlAttrib($name) { return isset($this->_content['htmlAttribs'][$name]) ? $this->_content['htmlAttribs'][$name] : null; } public function getHtmlAttribs() { return $this->_content['htmlAttribs']; } protected function _sendNoindexHeader() { header('X-Robots-Tag: noindex, nofollow'); return $this; } }