array( 'fallback_autoloader' => true, 'namespaces' => array( 'Zend\\' => BASE_PATH . '/lib/ZF2/library/Zend', ), 'prefixes' => array( 'Zend_' => BASE_PATH . '/lib/Zend' ), ), )); // Loading full config $config = new Zend_Config(include(CFG_FILE_NAME), true); if (file_exists(LOCAL_CFG_FILE_NAME)) { $configLocal = new Zend_Config(include(LOCAL_CFG_FILE_NAME)); $config->merge($configLocal); } // autodetect database name if empty if (('development' === APPLICATION_ENV || 'test' === APPLICATION_ENV) && empty($config->database->params->dbname)) { $path = str_replace(array('_framework', '.'), array('', '_'), strtolower(WWW_PATH)); $matches = array(); // 1 => project, 2 => subProject, 3 => trunk|branches|tags, 4 => branchPath if (preg_match('@public_html/([^/]+)(?:/([^/]+))?/(trunk|branches|tags)(?:/([^/]+))?/www@', $path, $matches)) { $prefix = ('quick_site' === $matches[1]) ? '' : 'prj_'; $project = (empty($matches[2])) ? $matches[1] : $matches[2]; $branchPath = (empty($matches[4])) ? '' : '_' . $matches[4]; $config->database->params->dbname = $prefix . $project . $branchPath; $config->session->baseName .= $branchPath; } } // read database credentials from config file (ex.: ~/.my.cnf) if (isset($config->database->configFile)) { $configFile = $config->database->configFile; if ('~' === $configFile[0]) { $usrInfo = posix_getpwuid(posix_getuid()); $configFile = $usrInfo['dir'] . substr($configFile, 1); } if (file_exists($configFile) && ($mySqlCfg = parse_ini_file($configFile, true)) && isset($mySqlCfg['mysql']) && ($mySqlCfg = $mySqlCfg['mysql']) || isset($mySqlCfg['client']) && ($mySqlCfg = $mySqlCfg['client']) ) { foreach ($mySqlCfg as $key => $value) { if ('user' == $key) { $key = 'username'; } $config->database->params->{$key} = $value; } } } // detect mobile $mobile = (bool)preg_match( '/android|ipad|ipod|iphone|playbook|blackberry|kindle/i', $_SERVER['HTTP_USER_AGENT'] ); define('IS_MOBILE', $mobile); $config->setReadOnly(); Zend_Registry::set('config', $config); unset($config); // locale settings setlocale(LC_ALL, Qs_Constant::get('SYSTEM_LOCALE')); Zend_Registry::set('Zend_Locale', Qs_Constant::get('ZEND_LOCALE')); // Кешування метаданих таблиць $cacheDir = BASE_PATH . '/tmp/cache'; if (!file_exists($cacheDir)) { $umask = umask(0); if (false === mkdir($cacheDir, 0777)) { die('Cannot create directory: ' . $cacheDir); } umask($umask); } $cache = Qs_Cache::factory('Core', 'File', array('automatic_serialization' => true)); Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); Zend_Locale_Data::setCache($cache); // Визначення CURRENT_PAGE, PARENT_PAGE, CURRENT_LANGUAGE, DEFAULT_LANGUAGE $currentPage = preg_replace('|^' . WEB_PATH . '/|', '', $_SERVER['REQUEST_URI']); $currentPage = preg_replace('/\?.*$/', '', $currentPage); $currentPageParts = explode('/', $currentPage); $firstPart = array_shift($currentPageParts); if ($firstPart == Zend_Registry::get('config')->cms->previewAlias) { $previewPageId = array_shift($currentPageParts); if (is_numeric($previewPageId) && ctype_digit($previewPageId)) { define('CMS_PREVIEW_PAGE_ID', $previewPageId); $previewPart = $firstPart . '/' . $previewPageId; $currentPage = preg_replace('/^' . preg_quote($previewPart, '/') . '($|\/)/', '', $currentPage); $language = array_shift($currentPageParts); } else { Qs_Debug::log('Wrong preview page id. REQUEST_URI: ' . $currentPage); exit; } } else { define('CMS_PREVIEW_PAGE_ID', false); $language = $firstPart; } if (!Qs_Db_Language::exists($language)) { $language = Qs_Db_Language::getDefault(); } $currentPage = preg_replace('/^' . preg_quote($language, '/') . '($|\/)/', '', $currentPage); $currentPageParts = explode('/', $currentPage); array_pop($currentPageParts); $parentPage = implode('/', $currentPageParts); $defaultLanguage = Qs_Db_Language::getDefault(); // Session define('SESSION_NAME', __getSessionName($currentPage)); session_save_path(SESSION_SAVE_PATH); session_name(SESSION_NAME); //Zend_Session::start(); try { Zend_Session::start(); } catch (Exception $e) { } // Debug $debug = Qs_Debug::getInstance(); Zend_Registry::set('debug', $debug); $languages = Qs_Db_Language::getList(); define('CURRENT_LOCALE', $languages[$language]['locale']); if (count($languages) > 1) { $fileCommonMo = BASE_PATH . '/languages/' . CURRENT_LOCALE . '/common.mo'; if (file_exists($fileCommonMo)) { $translate = new Zend_Translate('Qs_Translate_Adapter_Gettext', $fileCommonMo, CURRENT_LOCALE); if (defined('DEBUG') && DEBUG && defined('LOG_UNTRANSLATED') && (bool)LOG_UNTRANSLATED) { $fileCommonLog = BASE_PATH . '/languages/' . CURRENT_LOCALE . '/common.log'; $writer = new Zend_Log_Writer_Stream($fileCommonLog); $writer->setFormatter(new Zend_Log_Formatter_Simple("%message%\n")); $log = new Zend_Log($writer); $translate->getAdapter()->setOptions(array('log' => $log, 'logUntranslated' => true)); } Zend_Registry::set('Zend_Translate', $translate); } else { Qs_Debug::log(' translation file not found: ' . 'languages/' . CURRENT_LOCALE . '/common.mo'); } } define('CURRENT_PAGE', $currentPage); define('PARENT_PAGE', $parentPage); define('CURRENT_LANGUAGE', $language); define('DEFAULT_LANGUAGE', $defaultLanguage); if ($defaultLanguage == $language) { define('BASE_URL_LANGUAGE', BASE_URL); define('BASE_URL_LANGUAGE_HTTP', BASE_URL_HTTP); define('BASE_URL_LANGUAGE_HTTPS', BASE_URL_HTTPS); } else { define('BASE_URL_LANGUAGE', BASE_URL . '/' . CURRENT_LANGUAGE); define('BASE_URL_LANGUAGE_HTTP', BASE_URL_HTTP . '/' . CURRENT_LANGUAGE); define('BASE_URL_LANGUAGE_HTTPS', BASE_URL_HTTPS . '/' . CURRENT_LANGUAGE); } // GLOBAL FUNCTIONS function __getSessionName($currentPage) { $name = ''; /** @var $config Zend_Config */ $config = Zend_Registry::get('config')->session; if (!empty($config->baseName)) { $name = $config->baseName; if (!empty($config->rolePostfix)) { if (CMS_PREVIEW_PAGE_ID) { /** * Для прев’юву цмс сторінок має використовуватись сесія адміна, щоб перевірити чи він залогінений. */ $currentPageFirstSlice = 'admin'; } else { $currentPageFirstSlice = explode('/', $currentPage); $currentPageFirstSlice = reset($currentPageFirstSlice); } foreach ($config->rolePostfix as $rolePostfix) { if ($currentPageFirstSlice == $rolePostfix->currentPagePrefix) { $name .= $rolePostfix->sessionPostfix; break; } } } } return $name; } function __switchSession($sessionName) { $sessionName = (string) $sessionName; if (!$sessionName) { return false; } session_write_close(); session_name($sessionName); if (ini_get('session.use_cookies') && isset($_COOKIE[$sessionName])) { session_id($_COOKIE[$sessionName]); } else if (ini_get('session.use_trans_sid') && !ini_get('session.use_only_cookies') && isset($_REQUEST[$sessionName])) { session_id($_REQUEST[$sessionName]); } session_start(); return true; } function __getHttpHeader($header) { if (empty($header)) { return false; } // Try to get it from the $_SERVER array first $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header)); if (!empty($_SERVER[$temp])) { return $_SERVER[$temp]; } // This seems to be the only way to get the Authorization header on // Apache if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); if (!empty($headers[$header])) { return $headers[$header]; } } return false; } function vdie() { $version = (isset($_SERVER['SERVER_PROTOCOL']) && $_SERVER['SERVER_PROTOCOL'] === '1.0') ? '1.0' : '1.1'; header("HTTP/{$version} 303 See Other"); if ('XMLHttpRequest' == __getHttpHeader('X_REQUESTED_WITH')) { header('Content-Type: text/plain; charset=utf-8'); $delim = "\n"; $prefix = ''; $suffix = "\n"; } else { header('Content-Type: text/html; charset=utf-8'); $delim = "
\n"; $prefix = '
';
        $suffix = "
\n"; } foreach (func_get_args() as $var) { echo $prefix; var_export($var); echo $suffix, $delim; } exit; } function vlive() { $vars = func_get_args(); foreach ($vars as $var) { echo '
';
        if (is_scalar($var) || is_null($var)) {
            var_dump($var);
        } else {
            print_r($var);
        }
        echo '
'; } return true; } function logScriptDuration() { global $html; $logsPath = BASE_PATH . '/tmp/script-duration-logs'; if (!is_dir($logsPath)) { $umask = umask(0); if (false === mkdir($logsPath, 0777)) { umask($umask); return false; } umask($umask); } if (constant('MAX_SCRIPT_DURATION') < ($dutation = microtime(true) - SCRIPT_START)) { if (($fp = fopen($logsPath . '/times_' . date('Y-m-d') . '.txt', 'a+'))) { $contentLength = strlen($html); if (!$contentLength) { $contentLength = isset($_SERVER['CONTENT_LENGTH']) ? (int) $_SERVER['CONTENT_LENGTH'] : 0; } $separator = ' '; fwrite( $fp, date('Y-m-d H:i:s') . $separator . round($dutation, 4) . $separator . $_SERVER['REMOTE_ADDR'] . $separator . $_SERVER['REQUEST_METHOD'] . $separator . $contentLength . $separator . str_replace(WEB_PATH . '/', '', $_SERVER['REQUEST_URI']) . "\n" ); fclose($fp); } } // clean old logs if (date('N') == 5) { // every friday $filesList = glob($logsPath . '/times_*.txt'); if (!empty($filesList)) { $date = date('Y-m-d', strtotime(constant('LOG_SCRIPT_DURATION_LIFETIME'))); foreach ($filesList as $file) { if (basename($file) < 'times_' . $date . '.txt') { if (false === unlink($file)) { break; } } } } } return true; } // END OF GLOBAL FUNCTIONS