OpenCart index.php
define('VERSION', '2.0.0.0');
if (is_file('config.php')) { require_once('config.php'); }
require_once(DIR_SYSTEM . 'startup.php');
$registry = new Registry();
$loader = new Loader($registry); $registry->set('load', $loader);
$config = new Config(); $registry->set('config', $config);
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); $registry->set('db', $db);
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) { $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'"); } else { $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'"); } if ($store_query->num_rows) { $config->set('config_store_id', $store_query->row['store_id']); } else { $config->set('config_store_id', 0); }
$query = $db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE store_id = '0' OR store_id = '" . (int)$config->get('config_store_id') . "' ORDER BY store_id ASC");
foreach ($query->rows as $result) { if (!$result['serialized']) { $config->set($result['key'], $result['value']); } else { $config->set($result['key'], unserialize($result['value'])); } } if (!$store_query->num_rows) { $config->set('config_url', HTTP_SERVER); $config->set('config_ssl', HTTPS_SERVER); }
$url = new Url($config->get('config_url'), $config->get('config_secure') ? $config->get('config_ssl') : $config->get('config_url')); $registry->set('url', $url);
$log = new Log($config->get('config_error_filename')); $registry->set('log', $log);
function error_handler($errno, $errstr, $errfile, $errline) { global $log, $config; // error suppressed with @ if (error_reporting() === 0) { return false; } switch ($errno) { case E_NOTICE: case E_USER_NOTICE: $error = 'Notice'; break; case E_WARNING: case E_USER_WARNING: $error = 'Warning'; break; case E_ERROR: case E_USER_ERROR: $error = 'Fatal Error'; break; default: $error = 'Unknown'; break; } if ($config->get('config_error_display')) { echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>'; } if ($config->get('config_error_log')) { $log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline); } return true; }
set_error_handler('error_handler');
$request = new Request(); $registry->set('request', $request);
$response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $response->setCompression($config->get('config_compression')); $registry->set('response', $response);
$cache = new Cache('file'); $registry->set('cache', $cache);
$session = new Session(); $registry->set('session', $session);
$languages = array(); $query = $db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE status = '1'"); foreach ($query->rows as $result) { $languages[$result['code']] = $result; } $detect = ''; if (isset($request->server['HTTP_ACCEPT_LANGUAGE']) && $request->server['HTTP_ACCEPT_LANGUAGE']) { $browser_languages = explode(',', $request->server['HTTP_ACCEPT_LANGUAGE']); foreach ($browser_languages as $browser_language) { foreach ($languages as $key => $value) { if ($value['status']) { $locale = explode(',', $value['locale']); if (in_array($browser_language, $locale)) { $detect = $key; break 2; } } } } } if (isset($session->data['language']) && array_key_exists($session->data['language'], $languages) && $languages[$session->data['language']]['status']) { $code = $session->data['language']; } elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages) && $languages[$request->cookie['language']]['status']) { $code = $request->cookie['language']; } elseif ($detect) { $code = $detect; } else { $code = $config->get('config_language'); } if (!isset($session->data['language']) || $session->data['language'] != $code) { $session->data['language'] = $code; } if (!isset($request->cookie['language']) || $request->cookie['language'] != $code) { setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $request->server['HTTP_HOST']); } $config->set('config_language_id', $languages[$code]['language_id']); $config->set('config_language', $languages[$code]['code']);
$language = new Language($languages[$code]['directory']); $language->load($languages[$code]['filename']); $registry->set('language', $language);
$registry->set('document', new Document());
$customer = new Customer($registry); $registry->set('customer', $customer);
if ($customer->isLogged()) { $config->set('config_customer_group_id', $customer->getGroupId()); } elseif (isset($session->data['customer'])) { // For API calls $config->set('config_customer_group_id', $session->data['customer']['customer_group_id']); } elseif (isset($session->data['guest'])) { $config->set('config_customer_group_id', $session->data['guest']['customer_group_id']); }
$registry->set('affiliate', new Affiliate($registry));
$registry->set('currency', new Currency($registry));
$registry->set('tax', new Tax($registry));
$registry->set('weight', new Weight($registry));
$registry->set('length', new Length($registry));
$registry->set('cart', new Cart($registry));
$registry->set('encryption', new Encryption($config->get('config_encryption')));
$registry->set('openbay', new Openbay($registry));
$event = new Event($registry); $registry->set('event', $event); $query = $db->query("SELECT * FROM " . DB_PREFIX . "event"); foreach ($query->rows as $result) { $event->register($result['trigger'], $result['action']); }
$controller = new Front($registry);
$controller->addPreAction(new Action('common/maintenance'));
$controller->addPreAction(new Action('common/seo_url'));
if (isset($request->get['route'])) { $action = new Action($request->get['route']); } else { $action = new Action('common/home'); }
$controller->dispatch($action, new Action('error/not_found'));
$response->output();
Добавить комментарий