summaryrefslogtreecommitdiff
path: root/src/web/core/_controller.php
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-04-01 11:09:25 -0400
committerFreya Murphy <freya@freyacat.org>2024-04-01 11:09:25 -0400
commit3a82baec9d793edf81ac2b151b0f4d4159641375 (patch)
treef9d50c296b078ac48c2a2391c172c3ccf37edb3f /src/web/core/_controller.php
parentrefactor asset dir, refactor oberver in lib (diff)
downloadxssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.tar.gz
xssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.tar.bz2
xssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.zip
login and register, liking on homepage
Diffstat (limited to 'src/web/core/_controller.php')
-rw-r--r--src/web/core/_controller.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/web/core/_controller.php b/src/web/core/_controller.php
new file mode 100644
index 0000000..4a788d3
--- /dev/null
+++ b/src/web/core/_controller.php
@@ -0,0 +1,64 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+abstract class Controller {
+
+ // the main model
+ public $main;
+
+ // the loader
+ public $load;
+
+ // the database
+ public $db;
+
+ /**
+ * Creates a constructor
+ * @param Loader $load - the website loaded object
+ */
+ function __construct($load) {
+ $this->load = $load;
+ $this->main = $this->load->model('main');
+ $this->db = $this->main->db;
+
+ $info = $this->main->info;
+ $lang = $info['lang'];
+ $this->load->lang($lang);
+ $app = $info['app'];
+ if ($app) {
+ $this->load->app_lang($lang, $app);
+ }
+ }
+
+ public function index() {}
+
+ public function redirect($link) {
+ header('Location: '. $link, true, 301);
+ die();
+ }
+
+ protected function view($__name, $data = array()) {
+ $__root = $GLOBALS['webroot'];
+ $__path = $__root . '/_views/' . $__name . '.php';
+ if (is_file($__path)) {
+ extract($data);
+ require($__path);
+ return;
+ }
+ }
+
+ protected function is_ajax(): bool {
+ $_POST = json_decode(
+ file_get_contents("php://input"), true
+ );
+ return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
+ }
+
+ protected function error($code): void {
+ $_GET['code'] = $code;
+ $this->main->info['app'] = 'error';
+ $error_controller = $this->load->controller('apps/error');
+ $error_controller->index();
+ die();
+ }
+
+}
+?>