/** * Return full URL for the resource * * @param string $url URL part to add OPTIONAL * @param boolean $isSecure Use HTTP or HTTPS OPTIONAL * @param array $params URL parameters OPTIONAL * @param string $output URL output type OPTIONAL * @param boolean $isSession Use session ID parameter OPTIONAL * * @return string */ public static function getShopURL($url = '', $isSecure = null, array $params = array(), $output = null, $isSession = null) { if (!preg_match('/^https?:\\/\\//Ss', $url)) { if (!isset($isSecure)) { $isSecure = static::isHTTPS(); } if (!isset($output)) { $output = static::URL_OUTPUT_FULL; } $hostDetails = \Includes\Utils\ConfigParser::getOptions('host_details'); $host = $hostDetails['http' . ($isSecure ? 's' : '') . '_host']; if ($host) { $proto = ($isSecure ? 'https' : 'http') . '://'; if ('/' != substr($url, 0, 1)) { $url = $hostDetails['web_dir_wo_slash'] . '/' . $url; } $isSession = is_null($isSession) ? $isSecure : $isSession; if ($isSession) { $session = \XLite\Core\Session::getInstance(); $url .= (false !== strpos($url, '?') ? '&' : '?') . $session->getName() . '=' . $session->getID(); } foreach ($params as $name => $value) { $url .= (false !== strpos($url, '?') ? '&' : '?') . $name . '=' . $value; } if (static::URL_OUTPUT_FULL == $output) { $url = $proto . $host . $url; } } } return $url; }
/** * Connect * * @return void */ public function connect() { if (\XLite::isAdminZone()) { \Includes\Utils\ConfigParser::registerConfigFile('config.demo.php'); } parent::connect(); }
/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { $driver = \XLite\Core\Database::getCacheDriverByOptions(\Includes\Utils\ConfigParser::getOptions('cache')); if (isset($driver)) { $driver->deleteAll(); } }
/** * Compose clean URL * * @param string $target Page identifier OPTIONAL * @param string $action Action to perform OPTIONAL * @param array $params Additional params OPTIONAL * * @return string * @see ____func_see____ * @since 1.0.21 */ public static function buildCleanURL($target = '', $action = '', array $params = array()) { $result = null; $urlParams = array(); if ('page' === $target && !empty($params['id'])) { $page = \XLite\Core\Database::getRepo('\\XLite\\Module\\CDev\\SimpleCMS\\Model\\Page')->find($params['id']); if (isset($page) && $page->getCleanURL()) { $urlParams[] = $page->getCleanURL() . '.html'; unset($params['id']); } } if (!empty($urlParams)) { static::buildCleanURLHook($target, $action, $params, $urlParams); unset($params['target']); $result = \Includes\Utils\ConfigParser::getOptions(array('host_details', 'web_dir_wo_slash')); $result .= '/' . implode('/', array_reverse($urlParams)); if (!empty($params)) { $result .= '?' . http_build_query($params); } } return $result ?: parent::buildCleanURL($target, $action, $params); }
define('LC_OS_WINDOWS', 'WIN' === strtoupper(substr(PHP_OS, 0, 3))); // Disabled xdebug coverage for Selenium-based tests [DEVELOPMENT PURPOSE] if (isset($_COOKIE) && !empty($_COOKIE['no_xdebug_coverage']) && function_exists('xdebug_stop_code_coverage')) { @xdebug_stop_code_coverage(); } // Autoloading routines require_once LC_DIR_INCLUDES . 'Autoloader.php'; \Includes\Autoloader::registerAll(); // Fire the error if LC is not installed if (!defined('XLITE_INSTALL_MODE')) { \Includes\ErrorHandler::checkIsLCInstalled(); } // So called "developer" mode. Set it to "false" in production mode! define('LC_DEVELOPER_MODE', (bool) \Includes\Utils\ConfigParser::getOptions(array('performance', 'developer_mode'))); // Clean URLs support define('LC_USE_CLEAN_URLS', (bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'enabled'))); // Correct error handling mode ini_set('display_errors', LC_DEVELOPER_MODE); // Fatal error and exception handlers register_shutdown_function(array('\\Includes\\ErrorHandler', 'shutdown')); set_exception_handler(array('\\Includes\\ErrorHandler', 'handleException')); @umask(00); // :FIXME: to remove require_once LC_DIR_INCLUDES . 'prepend.php'; // Safe mode if (!defined('XLITE_INSTALL_MODE')) { \Includes\SafeMode::initialize(); } // Check and (if needed) rebuild classes cache if (!defined('LC_DO_NOT_REBUILD_CACHE')) { \Includes\Decorator\Utils\CacheManager::rebuildCache();
/** * Return banner URL * * @return string */ protected function getBannerURL() { return \Includes\Utils\ConfigParser::getOptions(array('marketplace', 'banner_url')); }
/** * Get options * * @param mixed $option Option * * @return mixed */ protected static function getOptions($option) { return \Includes\Utils\ConfigParser::getOptions($option); }
/** * Common logging procedure * * @param string $method Method to call * @param string $action Current request action * @param string $message Message to log * @param array $args Message args OPTIONAL * @param array $data Data sent/received OPTIONAL * * @return void */ protected function logCommon($method, $action, $message, array $args = array(), array $data = array()) { $message = 'Marketplace [' . $action . ']: ' . lcfirst($message); if (!empty($data) && \Includes\Utils\ConfigParser::getOptions(array('marketplace', 'log_data'))) { $message .= '; data: ' . PHP_EOL . '{{data}}'; $args += array('data' => print_r($data, true)); } \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, $args, false); }
/** * Return Image Magick executable * * @return string */ public static function getImageMagickExecutable() { $imageMagickPath = \Includes\Utils\ConfigParser::getOptions(array('images', 'image_magick_path')); return !empty($imageMagickPath) ? \Includes\Utils\FileManager::findExecutable($imageMagickPath . 'convert') : ''; }
/** * So called static constructor * * @return void */ public static function __constructStatic() { static::$defaultLanguage = \Includes\Utils\ConfigParser::getOptions(array('language', 'default')); }
/** * Set output per tick(s) * * @return void */ protected static function setFastCGITimeoutEcho() { if (\Includes\Utils\ConfigParser::getOptions(array('decorator', 'use_output'))) { declare (ticks=10000); register_tick_function(array('\\Includes\\Utils\\Operator', 'showMessage'), '.', false); } }
/** * Returns X-Cart tables prefix * * @return string */ function get_db_tables_prefix() { return \Includes\Utils\ConfigParser::getOptions(array('database_details', 'table_prefix')); }
/** * Return true if specified product assigned to multiple categories * (when cleanURL is enabled, URL for products should be built with category path) * * @param \XLite\Model\Product $product Product * * @return boolean */ protected function isProductHasMultipleCategories($product) { $result = LC_USE_CLEAN_URLS && !(bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only')); if (!$result) { $categories = $product->getCategories(); $result = 1 < count($categories); } return $result; }
define('LC_DIR_CACHE_IMAGES', LC_DIR_VAR . 'images' . LC_DS); define('LC_DIR_SERVICE', LC_DIR_FILES . 'service' . LC_DS); define('LC_OS_WINDOWS', 'WIN' === strtoupper(substr(PHP_OS, 0, 3))); // Disabled xdebug coverage for Selenium-based tests [DEVELOPMENT PURPOSE] if (isset($_COOKIE) && !empty($_COOKIE['no_xdebug_coverage']) && function_exists('xdebug_stop_code_coverage')) { @xdebug_stop_code_coverage(); } // Autoloading routines require_once LC_DIR_INCLUDES . 'Autoloader.php'; \Includes\Autoloader::registerAll(); // Fire the error if LC is not installed if (!defined('XLITE_INSTALL_MODE')) { \Includes\ErrorHandler::checkIsLCInstalled(); } // So called "developer" mode. Set it to "false" in production mode! define('LC_DEVELOPER_MODE', (bool) \Includes\Utils\ConfigParser::getOptions(array('performance', 'developer_mode'))); // Correct error handling mode ini_set('display_errors', LC_DEVELOPER_MODE); // Fatal error and exception handlers register_shutdown_function(array('\\Includes\\ErrorHandler', 'shutdown')); set_exception_handler(array('\\Includes\\ErrorHandler', 'handleException')); @umask(00); require_once LC_DIR_INCLUDES . 'prepend.php'; // Safe mode if (!defined('XLITE_INSTALL_MODE')) { \Includes\SafeMode::initialize(); } // Check and (if needed) rebuild classes cache if (!defined('LC_DO_NOT_REBUILD_CACHE')) { \Includes\Decorator\Utils\CacheManager::rebuildCache(); }
/** * Get parsed URL for Set-Cookie * * @param boolean $secure Secure protocol or not OPTIONAL * * @return array */ protected static function getCookieURL($secure = false) { $url = $secure ? 'http://' . \Includes\Utils\ConfigParser::getOptions(array('host_details', 'http_host')) : 'https://' . \Includes\Utils\ConfigParser::getOptions(array('host_details', 'https_host')); $url .= \Includes\Utils\ConfigParser::getOptions(array('host_details', 'web_dir')); return parse_url($url); }
/** * Returns 'use_canonical_urls_only' option value * * @return boolean */ public function isUseCanonicalURL() { return (bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only')); }
/** * Check - is store in development mode * * @return boolean */ protected function isStoreInDevelopmentMode() { return (bool) \Includes\Utils\ConfigParser::getOptions(array('performance', 'developer_mode')); }
/** * Display profiler report * * @return void */ protected function display() { $totalQueriesTime = 0; foreach (self::$queries as $q => $d) { $cnt = count($d['time']); $sum = array_sum($d['time']); self::$queries[$q] = array('count' => $cnt, 'max' => empty($d['time']) ? 0 : max($d['time']), 'min' => empty($d['time']) ? 0 : min($d['time']), 'avg' => 0 < $cnt ? $sum / $cnt : 0, 'trace' => $d['trace']); $totalQueriesTime += $sum; } $execTime = number_format($this->stop_time - $this->start_time, 4, self::DEC_POINT, self::THOUSANDS_SEP); $memoryPeak = round(memory_get_peak_usage() / 1024 / 1024, 3); $totalQueries = count(self::$queries); $totalQueriesTime = number_format($totalQueriesTime, 4, self::DEC_POINT, self::THOUSANDS_SEP); $dbConnectTime = number_format($this->dbConnectTime, 4, self::DEC_POINT, self::THOUSANDS_SEP); $unitOfWorkSize = \XLite\Core\Database::getEM()->getUnitOfWork()->size(); $this->includedFilesTotal = round($this->includedFilesTotal / 1024, 3); $html = <<<HTML <div class="inner-profiler"> <table cellspacing="0" cellpadding="3" style="width: auto;"> <tr> <td><strong>Execution time</strong></td> <td>{$execTime}</td> </tr> <tr> <td><strong>Memory usage (peak)</strong></td> <td>{$memoryPeak} Mb</td> </tr> <tr> <td><strong>SQL queries count</strong></td> <td>{$totalQueries}</td> </tr> <tr> <td><strong>SQL queries duration</strong></td> <td>{$totalQueriesTime} sec.</td> </tr> <tr> <td><strong>Included files count</strong></td> <td>{$this->includedFilesCount}</td> </tr> <tr> <td><strong>Included files total size</strong></td> <td>{$this->includedFilesTotal} Kb.</td> </tr> <tr> <td><strong>Database connect time</strong></td> <td>{$dbConnectTime} sec.</td> </tr> <tr> <td><strong>Doctrine UnitOfWork final size</strong></td> <td>{$unitOfWorkSize} models</td> </tr> </table> HTML; echo $html; if (!empty($this->messages)) { $html = <<<HTML <br /><br /> <table cellspacing="0" cellpadding="3" border="1" style="width: auto; top: 0; z-index: 10000; background-color: #fff;"> <caption style="font-weight: bold; text-align: left;">Profiler Messages</caption> HTML; foreach ($this->messages as $message) { $html .= <<<HTML <tr><td>{$message}</td></tr> HTML; } $html .= <<<HTML </table> HTML; echo $html; if (LC_DEVELOPER_MODE && \Includes\Utils\ConfigParser::getOptions(array('profiler_details', 'show_messages_on_top'))) { $html = str_replace(PHP_EOL, ' ', $html) . '<br /><br />'; echo '<script type="text/javascript">jQuery("#profiler-messages").html(\'' . $html . '\');</script>'; } } if (self::$queries) { $html = <<<HTML <br /><br /> <table cellspacing="0" cellpadding="3" border="1" style="width: auto;"> <caption style="font-weight: bold; text-align: left;">Queries log</caption> <tr> <th>Times</th> <th>Max. duration, sec.</th> <th>Query</th> </tr> HTML; echo $html; $warnStyle = ' background-color: red; font-weight: bold;'; foreach (self::$queries as $query => $d) { $timesLimit = self::QUERY_LIMIT_TIMES < $d['count'] ? $warnStyle : ''; $durationLimit = self::QUERY_LIMIT_DURATION < $d['max'] ? $warnStyle : ''; echo '<tr>' . "\n" . '<td style="vertical-align: top;' . $timesLimit . '">' . $d['count'] . '</td>' . '<td style="vertical-align: top;' . $durationLimit . '">' . number_format($d['max'], 4, self::DEC_POINT, self::THOUSANDS_SEP) . '</td><td style="white-space: nowrap;">' . $query . '<br />' . implode(' << ', $d['trace']) . '</td></tr>' . "\n"; } echo '</table>'; } if (self::$memoryPoints) { $html = <<<HTML <table cellspacing="0" cellpadding="3" border="1" style="width: auto;"> <caption style="font-weight: bold; text-align: left;">Memory points</caption> <tr> <th nowrap="nowrap">Memory, Mbytes</th> <th nowrap="nowrap">Changes, Mbytes</th> <th>Back trace</th> </tr> HTML; echo $html; $lastMem = 0; foreach (self::$memoryPoints as $d) { $diff = $d['memory'] - $lastMem; $m = number_format(round($d['memory'] / 1024 / 1024, 3), 3, self::DEC_POINT, self::THOUSANDS_SEP); $md = number_format(round($diff / 1024 / 1024, 3), 3, self::DEC_POINT, self::THOUSANDS_SEP); echo '<tr>' . '<td>' . $m . '</td>' . '<td>' . $md . '</td>' . '<td>' . implode(' << ', $d['trace']) . '</td>' . '</tr>'; $lastMem = $d['memory']; } echo '</table>'; } if ($this->points) { $html = <<<HTML <table cellspacing="0" cellpadding="3" border="1" style="width: auto;"> <caption style="font-weight: bold; text-align: left;">Log points</caption> <tr> <th>Duration, sec.</th> <th>Point name</th> </tr> HTML; echo $html; foreach ($this->points as $name => $d) { echo '<tr><td>' . number_format($d['time'], 4, self::DEC_POINT, self::THOUSANDS_SEP) . '</td><td>' . $name . '</td></tr>'; } echo '</table>'; } echo '</div>'; }
/** * Return current separator for clean URLs * * @return string */ public static function getCleanURLSeparator() { $result = \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'default_separator')); if (empty($result) || !preg_match('/' . static::getCleanURLAllowedCharsPattern() . '/S', $result)) { $result = static::CLEAN_URL_DEFAULT_SEPARATOR; } return $result; }
/** * Get the list of disabled system modules * * @return array */ protected static function getSystemModules() { $modules = array(); if (!\Includes\Utils\ConfigParser::getOptions(array('performance', 'ignore_system_modules'))) { foreach (static::getModulesList() as $module => $data) { if (static::callModuleMethod($module, 'isSystem')) { $modules[$module] = $data; } } } return $modules; }
/** * Get product URL * * @param \XLite\Model\Product $product Product object * @param integer $categoryId Category ID * * @return string */ protected function getProductURL(\XLite\Model\Product $product, $categoryId = null) { $params = array(); $params['product_id'] = $product->getProductId(); if ($categoryId) { $found = false; $firstId = null; $productCategories = $product->getCategories(); if ($productCategories && (1 < count($productCategories) || LC_USE_CLEAN_URLS && !(bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only')))) { foreach ($productCategories as $category) { if (!isset($firstId)) { $firstId = $category->getCategoryId(); } if ($category->getCategoryId() == $categoryId) { $found = true; break; } } if (!$found) { $categoryId = $firstId; } } else { $categoryId = null; } if ($categoryId) { $params['category_id'] = $categoryId; } } return \XLite\Core\Converter::buildURL('product', '', $params); }
/** * Check - code compressed cache enabled or not * * @return boolean */ protected function isCacheEnabled() { return \Includes\Utils\ConfigParser::getOptions(array('performance', 'compress_php_core')); }
/** * Return tables prefix in the DB * * @return string */ public static function getTablesPrefix() { return \Includes\Utils\ConfigParser::getOptions(array('database_details', 'table_prefix')); }
/** * Parse both config files * * @param array|string $names Option names tree OPTIONAL * * @return array|mixed */ public static function getOptions($names = null) { return \Includes\Utils\ConfigParser::getOptions($names); }
/** * Return true if software reset is enabled in config file * * @return boolean */ public static function isSoftwareResetEnabled() { return !(bool) \Includes\Utils\ConfigParser::getOptions(array('decorator', 'disable_software_reset')); }
/** * Log access to unknow property * * @param string $property Property name * @param boolean $isGetter Flag: is called property getter (true) or setter (false) OPTIONAL * * @return void */ protected function logWrongPropertyAccess($property, $isGetter = true) { if (false && LOG_DEBUG == \Includes\Utils\ConfigParser::getOptions(array('log_details', 'level'))) { \XLite\Logger::getInstance()->log(sprintf('Requested %s for unknown property: %s::%s', $isGetter ? 'getter' : 'setter', get_class($this), $property), LOG_ERR); } }
/** * Return affiliate ID * * @return string */ public static function getAffiliateId() { return \Includes\Utils\ConfigParser::getOptions(array('affiliate', 'id')); }
/** * Check if LC is installed * * @return void */ public static function checkIsLCInstalled() { if (!\Includes\Utils\ConfigParser::getOptions(array('database_details', 'database'))) { $link = \Includes\Utils\URLManager::getShopURL('install.php'); $message = \Includes\Utils\ConfigParser::getInstallationLng() === 'ru' ? '<a href="' . $link . '">Запустите установку магазина</a>' : '<a href="' . $link . '">Click here</a> to run the installation wizard.'; static::showErrorPage(self::ERROR_NOT_INSTALLED, $message); } }
/** * Run an upgrade step * * @param string $method Upgrade cell method to call * @param array $params Call params OPTIONAL * * @return mixed */ protected function runStep($method, array $params = array()) { return \Includes\Utils\Operator::executeWithCustomMaxExecTime(\Includes\Utils\ConfigParser::getOptions(array('marketplace', 'upgrade_step_time_limit')), array(\XLite\Upgrade\Cell::getInstance(), $method), $params); }
/** * Get array of trusted domains * * @return array */ public static function getTrustedDomains() { $result = array(); $trustedURLs = \Includes\Utils\ConfigParser::getOptions(array('other', 'trusted_domains')); if (!empty($trustedURLs)) { $result = array_map('trim', explode(',', $trustedURLs)); } return $result; }