first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
class ControllerStartupError extends Controller {
|
||||
public function index() {
|
||||
$this->registry->set('log', new Log($this->config->get('config_error_filename') ? $this->config->get('config_error_filename') : $this->config->get('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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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) {
|
||||
if ((substr($result['trigger'], 0, 6) == 'admin/') && $result['status']) {
|
||||
$this->event->register(substr($result['trigger'], 6), new Action($result['action']), $result['sort_order']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class ControllerStartupLogin extends Controller {
|
||||
public function index() {
|
||||
$route = isset($this->request->get['route']) ? $this->request->get['route'] : '';
|
||||
|
||||
$ignore = array(
|
||||
'common/login',
|
||||
'common/forgotten',
|
||||
'common/reset'
|
||||
);
|
||||
|
||||
// User
|
||||
$this->registry->set('user', new Cart\User($this->registry));
|
||||
|
||||
if (!$this->user->isLogged() && !in_array($route, $ignore)) {
|
||||
return new Action('common/login');
|
||||
}
|
||||
|
||||
if (isset($this->request->get['route'])) {
|
||||
$ignore = array(
|
||||
'common/login',
|
||||
'common/logout',
|
||||
'common/forgotten',
|
||||
'common/reset',
|
||||
'error/not_found',
|
||||
'error/permission'
|
||||
);
|
||||
|
||||
if (!in_array($route, $ignore) && (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token']))) {
|
||||
return new Action('common/login');
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token'])) {
|
||||
return new Action('common/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
class ControllerStartupPermission extends Controller {
|
||||
public function index() {
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = '';
|
||||
|
||||
$part = explode('/', $this->request->get['route']);
|
||||
|
||||
if (isset($part[0])) {
|
||||
$route .= $part[0];
|
||||
}
|
||||
|
||||
if (isset($part[1])) {
|
||||
$route .= '/' . $part[1];
|
||||
}
|
||||
|
||||
// If a 3rd part is found we need to check if its under one of the extension folders.
|
||||
$extension = array(
|
||||
'extension/advertise',
|
||||
'extension/dashboard',
|
||||
'extension/analytics',
|
||||
'extension/captcha',
|
||||
'extension/currency',
|
||||
'extension/extension',
|
||||
'extension/feed',
|
||||
'extension/fraud',
|
||||
'extension/module',
|
||||
'extension/payment',
|
||||
'extension/shipping',
|
||||
'extension/theme',
|
||||
'extension/total',
|
||||
'extension/report'
|
||||
);
|
||||
|
||||
if (isset($part[2]) && in_array($route, $extension)) {
|
||||
$route .= '/' . $part[2];
|
||||
}
|
||||
|
||||
// We want to ingore some pages from having its permission checked.
|
||||
$ignore = array(
|
||||
'common/dashboard',
|
||||
'common/login',
|
||||
'common/logout',
|
||||
'common/forgotten',
|
||||
'common/reset',
|
||||
'error/not_found',
|
||||
'error/permission'
|
||||
);
|
||||
|
||||
if (!in_array($route, $ignore) && !$this->user->hasPermission('access', $route)) {
|
||||
return new Action('error/permission');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
$action = new Action($route);
|
||||
|
||||
// Any output needs to be another Action object.
|
||||
$output = $action->execute($this->registry, $data);
|
||||
|
||||
// Trigger the post events
|
||||
$result = $this->event->trigger('controller/' . $route . '/after', array(&$route, &$output));
|
||||
|
||||
if (!is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
class ControllerStartupStartup extends Controller {
|
||||
public function index() {
|
||||
// Settings
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '0'");
|
||||
|
||||
foreach ($query->rows as $setting) {
|
||||
if (!$setting['serialized']) {
|
||||
$this->config->set($setting['key'], $setting['value']);
|
||||
} else {
|
||||
$this->config->set($setting['key'], json_decode($setting['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'));
|
||||
|
||||
// Language
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $this->db->escape($this->config->get('config_admin_language')) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$this->config->set('config_language_id', $query->row['language_id']);
|
||||
}
|
||||
|
||||
// Language
|
||||
$language = new Language($this->config->get('config_admin_language'));
|
||||
$language->load($this->config->get('config_admin_language'));
|
||||
$this->registry->set('language', $language);
|
||||
|
||||
// Customer
|
||||
$this->registry->set('customer', new Cart\Customer($this->registry));
|
||||
|
||||
// Currency
|
||||
$this->registry->set('currency', new Cart\Currency($this->registry));
|
||||
|
||||
// Tax
|
||||
$this->registry->set('tax', new Cart\Tax($this->registry));
|
||||
|
||||
if ($this->config->get('config_tax_default') == 'shipping') {
|
||||
$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
|
||||
}
|
||||
|
||||
if ($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')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user