aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/controller/startup
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
committerJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
commit2eed7b082f83630301e51f57ca8394de228a8605 (patch)
tree1d19962d22d30f99317d9276e4bae7744fc93fc2 /public/admin/controller/startup
downloadlibrecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip
first commit
Diffstat (limited to 'public/admin/controller/startup')
-rw-r--r--public/admin/controller/startup/error.php43
-rw-r--r--public/admin/controller/startup/event.php15
-rw-r--r--public/admin/controller/startup/login.php38
-rw-r--r--public/admin/controller/startup/permission.php55
-rw-r--r--public/admin/controller/startup/router.php37
-rw-r--r--public/admin/controller/startup/sass.php27
-rw-r--r--public/admin/controller/startup/startup.php64
7 files changed, 279 insertions, 0 deletions
diff --git a/public/admin/controller/startup/error.php b/public/admin/controller/startup/error.php
new file mode 100644
index 0000000..8489b9c
--- /dev/null
+++ b/public/admin/controller/startup/error.php
@@ -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;
+ }
+}
diff --git a/public/admin/controller/startup/event.php b/public/admin/controller/startup/event.php
new file mode 100644
index 0000000..2aa9604
--- /dev/null
+++ b/public/admin/controller/startup/event.php
@@ -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']);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/public/admin/controller/startup/login.php b/public/admin/controller/startup/login.php
new file mode 100644
index 0000000..da058cc
--- /dev/null
+++ b/public/admin/controller/startup/login.php
@@ -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');
+ }
+ }
+ }
+}
diff --git a/public/admin/controller/startup/permission.php b/public/admin/controller/startup/permission.php
new file mode 100644
index 0000000..e73e504
--- /dev/null
+++ b/public/admin/controller/startup/permission.php
@@ -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/extension',
+ 'extension/feed',
+ 'extension/fraud',
+ 'extension/module',
+ 'extension/payment',
+ 'extension/shipping',
+ 'extension/theme',
+ 'extension/total',
+ 'extension/report',
+ 'extension/openbay'
+ );
+
+ 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');
+ }
+ }
+ }
+}
diff --git a/public/admin/controller/startup/router.php b/public/admin/controller/startup/router.php
new file mode 100644
index 0000000..ec8e0ca
--- /dev/null
+++ b/public/admin/controller/startup/router.php
@@ -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;
+ }
+}
diff --git a/public/admin/controller/startup/sass.php b/public/admin/controller/startup/sass.php
new file mode 100644
index 0000000..9af89b3
--- /dev/null
+++ b/public/admin/controller/startup/sass.php
@@ -0,0 +1,27 @@
+<?php
+class ControllerStartupSass extends Controller {
+ public function index() {
+ $file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css';
+
+ if (!is_file($file) || !$this->config->get('developer_sass')) {
+ include_once(DIR_STORAGE . 'vendor/scss.inc.php');
+
+ $scss = new Scssc();
+ $scss->setImportPaths(DIR_APPLICATION . 'view/stylesheet/sass/');
+
+ $output = $scss->compile('@import "_bootstrap.scss"');
+
+ $handle = fopen($file, 'w');
+
+ flock($handle, LOCK_EX);
+
+ fwrite($handle, $output);
+
+ fflush($handle);
+
+ flock($handle, LOCK_UN);
+
+ fclose($handle);
+ }
+ }
+}
diff --git a/public/admin/controller/startup/startup.php b/public/admin/controller/startup/startup.php
new file mode 100644
index 0000000..1e50294
--- /dev/null
+++ b/public/admin/controller/startup/startup.php
@@ -0,0 +1,64 @@
+<?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));
+ }
+ }
+
+ // 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')));
+
+ // OpenBay Pro
+ $this->registry->set('openbay', new Openbay($this->registry));
+ }
+} \ No newline at end of file