Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Connect
  *
  * @return void
  */
 public function connect()
 {
     if (\XLite::isAdminZone()) {
         \Includes\Utils\ConfigParser::registerConfigFile('config.demo.php');
     }
     parent::connect();
 }
Example #3
0
File: Main.php Project: kingsj/core
 /**
  * Execute certain hook handler
  *
  * @return void
  */
 public function executeHookHandler()
 {
     $driver = \XLite\Core\Database::getCacheDriverByOptions(\Includes\Utils\ConfigParser::getOptions('cache'));
     if (isset($driver)) {
         $driver->deleteAll();
     }
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
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();
Example #6
0
 /**
  * Return banner URL
  *
  * @return string
  */
 protected function getBannerURL()
 {
     return \Includes\Utils\ConfigParser::getOptions(array('marketplace', 'banner_url'));
 }
Example #7
0
 /**
  * Get options 
  * 
  * @param mixed $option Option
  *  
  * @return mixed
  */
 protected static function getOptions($option)
 {
     return \Includes\Utils\ConfigParser::getOptions($option);
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
 /**
  * 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') : '';
 }
Example #10
0
 /**
  * So called static constructor
  *
  * @return void
  */
 public static function __constructStatic()
 {
     static::$defaultLanguage = \Includes\Utils\ConfigParser::getOptions(array('language', 'default'));
 }
Example #11
0
 /**
  * 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);
     }
 }
Example #12
0
/**
 * Returns X-Cart tables prefix
 *
 * @return string
 */
function get_db_tables_prefix()
{
    return \Includes\Utils\ConfigParser::getOptions(array('database_details', 'table_prefix'));
}
Example #13
0
 /**
  * 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;
 }
Example #14
0
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();
}
Example #15
0
 /**
  * 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);
 }
Example #16
0
 /**
  * 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'));
 }
Example #17
0
 /**
  * Check - is store in development mode
  *
  * @return boolean
  */
 protected function isStoreInDevelopmentMode()
 {
     return (bool) \Includes\Utils\ConfigParser::getOptions(array('performance', 'developer_mode'));
 }
Example #18
0
    /**
     * 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>';
    }
Example #19
0
 /**
  * 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;
 }
Example #20
0
 /**
  * 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;
 }
Example #21
0
 /**
  * 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);
 }
Example #22
0
 /**
  * Check - code compressed cache enabled or not
  * 
  * @return boolean
  */
 protected function isCacheEnabled()
 {
     return \Includes\Utils\ConfigParser::getOptions(array('performance', 'compress_php_core'));
 }
Example #23
0
 /**
  * Return tables prefix in the DB
  *
  * @return string
  */
 public static function getTablesPrefix()
 {
     return \Includes\Utils\ConfigParser::getOptions(array('database_details', 'table_prefix'));
 }
Example #24
0
 /**
  * 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);
 }
Example #25
0
 /**
  * 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'));
 }
Example #26
0
 /**
  * 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);
     }
 }
Example #27
0
 /**
  * Return affiliate ID
  *
  * @return string
  */
 public static function getAffiliateId()
 {
     return \Includes\Utils\ConfigParser::getOptions(array('affiliate', 'id'));
 }
Example #28
0
 /**
  * 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);
     }
 }
Example #29
0
 /**
  * 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);
 }
Example #30
0
 /**
  * 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;
 }