summaryrefslogtreecommitdiff
path: root/web/_controller
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-03-30 12:14:42 -0400
committerFreya Murphy <freya@freyacat.org>2024-03-30 12:14:42 -0400
commit1f04b83be337cc91a3fabcf4e574e2306f3d2eaa (patch)
tree74d7d65a7047e60d1877384e3c7b0d70c7b0e49a /web/_controller
parentstart database (user and post), and initial barebones home page (diff)
downloadxssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.tar.gz
xssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.tar.bz2
xssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.zip
refactor
Diffstat (limited to '')
-rw-r--r--web/_controller/_index.php23
-rw-r--r--web/_controller/apps/error.php20
-rw-r--r--web/_controller/apps/home.php (renamed from web/routes/home/controller.php)45
-rw-r--r--web/_controller/modal.php26
-rw-r--r--web/_controller/template.php22
5 files changed, 116 insertions, 20 deletions
diff --git a/web/_controller/_index.php b/web/_controller/_index.php
new file mode 100644
index 0000000..fdf9440
--- /dev/null
+++ b/web/_controller/_index.php
@@ -0,0 +1,23 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class _index_controller extends Controller {
+
+ // the home model
+ private $home_model;
+
+ // the request model
+ private $request_model;
+
+ // the caceh model
+ private $cache_model;
+
+ public function index(): void {
+ if ($this->main->session) {
+ $this->redirect('/home');
+ } else {
+ $this->redirect('/login');
+ }
+ }
+
+}
+
+?>
diff --git a/web/_controller/apps/error.php b/web/_controller/apps/error.php
new file mode 100644
index 0000000..5ce9ec4
--- /dev/null
+++ b/web/_controller/apps/error.php
@@ -0,0 +1,20 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class Error_controller extends Controller {
+
+ private $error_model;
+
+ function __construct($load) {
+ parent::__construct($load);
+ $this->error_model = $this->load->model('apps/error');
+ }
+
+ public function index() {
+ parent::index();
+ $data = $this->error_model->get_data();
+ $this->view('header', $data);
+ $this->view('apps/error/main', $data);
+ }
+
+}
+
+?>
diff --git a/web/routes/home/controller.php b/web/_controller/apps/home.php
index 775e43a..25c8c4e 100644
--- a/web/routes/home/controller.php
+++ b/web/_controller/apps/home.php
@@ -1,22 +1,31 @@
<?php /* Copyright (c) 2024 Freya Murphy */
-class HomeController extends Controller {
+class Home_controller extends Controller {
- private $model;
+ // the home model
+ private $home_model;
- function __construct($model) {
- parent::__construct();
- $this->model = $model;
+ // the request model
+ private $request_model;
+
+ // the caceh model
+ private $cache_model;
+
+ function __construct($load) {
+ parent::__construct($load);
+ $this->home_model = $this->load->model('apps/home');
+ $this->request_model = $this->load->model('request');
+ $this->cache_model = $this->load->model('cache');
}
- public function index() {
+ public function index(): void {
parent::index();
- $data = $this->model->get_data();
+ $data = $this->home_model->get_data();
$this->view('header', $data);
- $this->app_view('main', $data);
+ $this->view('apps/home/main', $data);
}
- public function posts() {
- $page = $this->main->get_num('page', 0);
+ public function posts(): void {
+ $page = $this->request_model->get_int('page', 0);
$page_size = 20;
$offset = $page * $page_size;
@@ -30,7 +39,7 @@ class HomeController extends Controller {
$query = $query->select('p.*, FALSE as liked');
}
- $query = $query->from('admin.post p');
+ $query = $query->from('api.post p');
if ($user) {
$query = $query->join('admin.like l', 'p.id = l.post_id')
@@ -42,7 +51,7 @@ class HomeController extends Controller {
->offset($offset)
->rows();
- $users = $this->main->get_users($posts);
+ $users = $this->cache_model->get_users($posts);
foreach ($posts as $post) {
$data = array();
@@ -52,9 +61,9 @@ class HomeController extends Controller {
}
}
- public function comments() {
- $page = $this->main->get_num('page', 0);
- $id = $this->main->get_num('id');
+ public function comments(): void {
+ $page = $this->request_model->get_int('page', 0);
+ $id = $this->request_model->get_int('id');
$page_size = 20;
$offset = $page * $page_size;
@@ -65,7 +74,7 @@ class HomeController extends Controller {
->offset($offset)
->rows();
- $users = $this->main->get_users($comments);
+ $users = $this->cache_model->get_users($comments);
foreach ($comments as $comment) {
$data = array();
@@ -75,10 +84,6 @@ class HomeController extends Controller {
}
}
- public function new_post_modal() {
- $this->modal(lang('new_post_modal_title'), 'new-post');
- }
-
}
?>
diff --git a/web/_controller/modal.php b/web/_controller/modal.php
new file mode 100644
index 0000000..9ae4ca8
--- /dev/null
+++ b/web/_controller/modal.php
@@ -0,0 +1,26 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class Modal_controller extends Controller {
+
+
+ function __construct($load) {
+ parent::__construct($load);
+ }
+
+ /**
+ * @param string $name
+ * @param array $data
+ */
+ private function modal($name, $data = array()): void {
+ $title = lang($name . '_modal_title');
+ $data['title'] = $title;
+ $data['content'] = $name;
+ $this->view('template/modal', $data);
+ }
+
+ public function new_post(): void {
+ $this->modal('new_post');
+ }
+}
+
+?>
+
diff --git a/web/_controller/template.php b/web/_controller/template.php
new file mode 100644
index 0000000..7a8cdf8
--- /dev/null
+++ b/web/_controller/template.php
@@ -0,0 +1,22 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class Template_controller extends Controller {
+
+ // the request model
+ private $request_model;
+
+ function __construct($load) {
+ parent::__construct($load);
+ $this->request_model = $this->load->model('request');
+ }
+
+ public function toast(): void {
+ $data = array(
+ 'msg' => $this->request_model->get_str('msg', FALSE),
+ 'detail' => $this->request_model->get_str('detail', FALSE),
+ 'hint' => $this->request_model->get_str('hint', FALSE)
+ );
+ $this->view('template/toast', $data);
+ }
+
+}
+