Exemplo n.º 1
0
 /**
  * Check whether code is associated with active template.
  *
  * @param string  $sCode      template's unique URI.
  * @param boolean $bSetCookie save code in COOKIE or not.
  */
 protected function _checkCode($sCode, $bSetCookie)
 {
     if (empty($sCode) || !preg_match('/^[A-Za-z0-9_-]+$/', $sCode)) {
         return;
     }
     bx_import('BxDolModuleQuery');
     $aModule = BxDolModuleQuery::getInstance()->getModuleByUri($sCode);
     if (empty($aModule) || !is_array($aModule) || (int) $aModule['enabled'] != 1 || !file_exists($this->_sRootPath . 'modules/' . $aModule['path'] . 'data/template/')) {
         return;
     }
     bx_import('BxDolModuleConfig');
     $oConfig = new BxDolModuleConfig($aModule);
     $this->_sCode = $oConfig->getUri();
     $this->_sSubPath = $oConfig->getDirectory();
     if (!$bSetCookie || bx_get('preview')) {
         return;
     }
     $aUrl = parse_url(BX_DOL_URL_ROOT);
     $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
     setcookie($this->_sCodeKey, $this->_sCode, time() + 60 * 60 * 24 * 365, $sPath);
 }