first commit

This commit is contained in:
Konstantin
2026-05-30 09:27:58 +03:00
commit de0344d218
2371 changed files with 661486 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
class ControllerStartupError extends Controller {
public function index() {
$this->registry->set('log', new Log($this->config->get('config_error_filename')));
set_error_handler(array($this, 'handler'));
}
public function handler($code, $message, $file, $line) {
// error suppressed with @
if (error_reporting() === 0) {
return false;
}
switch ($code) {
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 ($this->config->get('config_error_display')) {
echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
}
if ($this->config->get('config_error_log')) {
$this->log->write('PHP ' . $error . ': ' . $message . ' in ' . $file . ' on line ' . $line);
}
return true;
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
class ControllerStartupEvent extends Controller {
public function index() {
// Add events from the DB
$this->load->model('setting/event');
$results = $this->model_setting_event->getEvents();
foreach ($results as $result) {
$this->event->register(substr($result['trigger'], strpos($result['trigger'], '/') + 1), new Action($result['action']), $result['sort_order']);
}
}
}
@@ -0,0 +1,25 @@
<?php
class ControllerStartupMaintenance extends Controller {
public function index() {
if ($this->config->get('config_maintenance')) {
// Route
if (isset($this->request->get['route']) && $this->request->get['route'] != 'startup/router') {
$route = $this->request->get['route'];
} else {
$route = $this->config->get('action_default');
}
$ignore = array(
'common/language/language',
'common/currency/currency'
);
// Show site if logged in as admin
$this->user = new Cart\User($this->registry);
if ((substr($route, 0, 17) != 'extension/payment' && substr($route, 0, 3) != 'api') && !in_array($route, $ignore) && !$this->user->isLogged()) {
return new Action('common/maintenance');
}
}
}
}
@@ -0,0 +1,36 @@
<?php
class ControllerStartupRouter extends Controller {
public function index() {
// Route
if (isset($this->request->get['route']) && $this->request->get['route'] != 'startup/router') {
$route = $this->request->get['route'];
} else {
$route = $this->config->get('action_default');
}
// Sanitize the call
$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);
// Trigger the pre events
$result = $this->event->trigger('controller/' . $route . '/before', array(&$route, &$data));
if (!is_null($result)) {
return $result;
}
// We dont want to use the loader class as it would make an controller callable.
$action = new Action($route);
// Any output needs to be another Action object.
$output = $action->execute($this->registry);
// Trigger the post events
$result = $this->event->trigger('controller/' . $route . '/after', array(&$route, &$data, &$output));
if (!is_null($result)) {
return $result;
}
return $output;
}
}
+185
View File
@@ -0,0 +1,185 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
class ControllerStartupSeoUrl extends Controller {
//seopro start
private $seo_pro;
public function __construct($registry) {
parent::__construct($registry);
$this->seo_pro = new SeoPro($registry);
}
//seopro end
public function index() {
// Add rewrite to url class
if ($this->config->get('config_seo_url')) {
$this->url->addRewrite($this);
}
// Decode URL
if (isset($this->request->get['_route_'])) {
$parts = explode('/', $this->request->get['_route_']);
//seopro prepare route
if($this->config->get('config_seo_pro')){
$parts = $this->seo_pro->prepareRoute($parts);
}
//seopro prepare route end
// remove any empty arrays from trailing
if (utf8_strlen(end($parts)) == 0) {
array_pop($parts);
}
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} else {
$this->request->get['path'] .= '_' . $url[1];
}
}
if ($url[0] == 'manufacturer_id') {
$this->request->get['manufacturer_id'] = $url[1];
}
if ($url[0] == 'information_id') {
$this->request->get['information_id'] = $url[1];
}
if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
$this->request->get['route'] = $query->row['query'];
}
} else {
if(!$this->config->get('config_seo_pro')){
$this->request->get['route'] = 'error/not_found';
}
break;
}
}
if (!isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/info';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
}
}
//seopro validate
if($this->config->get('config_seo_pro')){
$this->seo_pro->validate();
}
//seopro validate
}
public function rewrite($link) {
$url_info = parse_url(str_replace('&amp;', '&', $link));
if($this->config->get('config_seo_pro')){
$url = null;
} else {
$url = '';
}
$data = array();
parse_str($url_info['query'], $data);
//seo_pro baseRewrite
if($this->config->get('config_seo_pro')){
list($url, $data, $postfix) = $this->seo_pro->baseRewrite($data, (int)$this->config->get('config_language_id'));
}
//seo_pro baseRewrite
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
} else {
$url = '';
break;
}
}
unset($data[$key]);
}
}
}
//seo_pro add blank url
unset($data['route']);
$query = '';
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
}
if ($query) {
$query = '?' . str_replace('&', '&amp;', trim($query, '&'));
}
}
if($this->config->get('config_seo_pro')) {
$condition = ($url !== null);
} else {
$condition = $url;
}
if ($condition) {
if($this->config->get('config_seo_pro')){
if($this->config->get('config_page_postfix') && $postfix) {
$url .= $this->config->get('config_page_postfix');
} elseif($this->config->get('config_seopro_addslash') || !empty( $query)) {
$url .= '/';
}
}
return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
} else {
return $link;
}
}
}
@@ -0,0 +1,31 @@
<?php
class ControllerStartupSession extends Controller {
public function index() {
if (isset($this->request->get['api_token']) && isset($this->request->get['route']) && substr($this->request->get['route'], 0, 4) == 'api/') {
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, date_modified) < NOW()");
// Make sure the IP is allowed
$api_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (a.api_id = ai.api_id) WHERE a.status = '1' AND `as`.`session_id` = '" . $this->db->escape($this->request->get['api_token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
if ($api_query->num_rows) {
$this->session->start($this->request->get['api_token']);
// keep the session alive
$this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_query->row['api_session_id'] . "'");
}
} else {
if (isset($this->request->cookie[$this->config->get('session_name')])) {
$session_id = $this->request->cookie[$this->config->get('session_name')];
} else {
$session_id = '';
}
$this->session->start($session_id);
//setcookie($this->config->get('session_name'), $this->session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));
// FIX: expires - Unix time
setcookie($this->config->get('session_name'), $this->session->getId(), (ini_get('session.cookie_lifetime') ? (time() + ini_get('session.cookie_lifetime')) : 0), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));
}
}
}
+202
View File
@@ -0,0 +1,202 @@
<?php
class ControllerStartupStartup extends Controller {
public function index() {
// Store
if ($this->request->server['HTTPS']) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $this->db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $this->db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}
if (isset($this->request->get['store_id'])) {
$this->config->set('config_store_id', (int)$this->request->get['store_id']);
} else if ($query->num_rows) {
$this->config->set('config_store_id', $query->row['store_id']);
} else {
$this->config->set('config_store_id', 0);
}
if (!$query->num_rows) {
$this->config->set('config_url', HTTP_SERVER);
$this->config->set('config_ssl', HTTPS_SERVER);
}
// Settings
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE store_id = '0' OR store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY store_id ASC");
foreach ($query->rows as $result) {
if (!$result['serialized']) {
$this->config->set($result['key'], $result['value']);
} else {
$this->config->set($result['key'], json_decode($result['value'], true));
}
}
// Set time zone
if ($this->config->get('config_timezone')) {
date_default_timezone_set($this->config->get('config_timezone'));
// Sync PHP and DB time zones.
$this->db->query("SET time_zone = '" . $this->db->escape(date('P')) . "'");
}
// Theme
$this->config->set('template_cache', $this->config->get('developer_theme'));
// Url
$this->registry->set('url', new Url($this->config->get('config_url'), $this->config->get('config_ssl')));
// Language
$code = '';
$this->load->model('localisation/language');
$languages = $this->model_localisation_language->getLanguages();
if (isset($this->session->data['language'])) {
$code = $this->session->data['language'];
}
if (isset($this->request->cookie['language']) && !array_key_exists($code, $languages)) {
$code = $this->request->cookie['language'];
}
// Language Detection
if (!empty($this->request->server['HTTP_ACCEPT_LANGUAGE']) && !array_key_exists($code, $languages)) {
$detect = '';
$browser_languages = explode(',', $this->request->server['HTTP_ACCEPT_LANGUAGE']);
// Try using local to detect the 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 (!$detect) {
// Try using language folder to detect the language
foreach ($browser_languages as $browser_language) {
if (array_key_exists(strtolower($browser_language), $languages)) {
$detect = strtolower($browser_language);
break;
}
}
}
$code = $detect ? $detect : '';
}
if (!array_key_exists($code, $languages)) {
$code = $this->config->get('config_language');
}
if (!isset($this->session->data['language']) || $this->session->data['language'] != $code) {
$this->session->data['language'] = $code;
}
if (!isset($this->request->cookie['language']) || $this->request->cookie['language'] != $code) {
setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
}
// Overwrite the default language object
$language = new Language($code);
$language->load($code);
$this->registry->set('language', $language);
// Set the config language_id
$this->config->set('config_language_id', $languages[$code]['language_id']);
// Customer
$customer = new Cart\Customer($this->registry);
$this->registry->set('customer', $customer);
// Customer Group
if (isset($this->session->data['customer']) && isset($this->session->data['customer']['customer_group_id'])) {
// For API calls
$this->config->set('config_customer_group_id', $this->session->data['customer']['customer_group_id']);
} elseif ($this->customer->isLogged()) {
// Logged in customers
$this->config->set('config_customer_group_id', $this->customer->getGroupId());
} elseif (isset($this->session->data['guest']) && isset($this->session->data['guest']['customer_group_id'])) {
$this->config->set('config_customer_group_id', $this->session->data['guest']['customer_group_id']);
} else {
$this->config->set('config_customer_group_id', $this->config->get('config_customer_group_id'));
}
// Tracking Code
if (isset($this->request->get['tracking'])) {
setcookie('tracking', $this->request->get['tracking'], time() + 3600 * 24 * 1000, '/');
$this->db->query("UPDATE `" . DB_PREFIX . "marketing` SET clicks = (clicks + 1) WHERE code = '" . $this->db->escape($this->request->get['tracking']) . "'");
}
// Currency
$code = '';
$this->load->model('localisation/currency');
$currencies = $this->model_localisation_currency->getCurrencies();
if (isset($this->session->data['currency'])) {
$code = $this->session->data['currency'];
}
if (isset($this->request->cookie['currency']) && !array_key_exists($code, $currencies)) {
$code = $this->request->cookie['currency'];
}
if (!array_key_exists($code, $currencies)) {
$code = $this->config->get('config_currency');
}
if (!isset($this->session->data['currency']) || $this->session->data['currency'] != $code) {
$this->session->data['currency'] = $code;
}
if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
setcookie('currency', $code, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
}
$this->registry->set('currency', new Cart\Currency($this->registry));
// Tax
$this->registry->set('tax', new Cart\Tax($this->registry));
// PHP v7.4+ validation compatibility.
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
$this->tax->setShippingAddress($this->session->data['shipping_address']['country_id'], $this->session->data['shipping_address']['zone_id']);
} elseif ($this->config->get('config_tax_default') == 'shipping') {
$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
}
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {
$this->tax->setPaymentAddress($this->session->data['payment_address']['country_id'], $this->session->data['payment_address']['zone_id']);
} elseif ($this->config->get('config_tax_default') == 'payment') {
$this->tax->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
}
$this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
// Weight
$this->registry->set('weight', new Cart\Weight($this->registry));
// Length
$this->registry->set('length', new Cart\Length($this->registry));
// Cart
$this->registry->set('cart', new Cart\Cart($this->registry));
// Encryption
$this->registry->set('encryption', new Encryption($this->config->get('config_encryption')));
}
}