summaryrefslogtreecommitdiff
path: root/web/core/main.php
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/core/main.php
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 'web/core/main.php')
-rw-r--r--web/core/main.php123
1 files changed, 0 insertions, 123 deletions
diff --git a/web/core/main.php b/web/core/main.php
deleted file mode 100644
index c3c65dd..0000000
--- a/web/core/main.php
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php /* Copyright (c) 2024 Freya Murphy */
-class MainModel {
-
- // loaded route infomation
- public $info;
- public $db;
- public $user_id;
-
- private $users;
-
- function __construct() {
- $this->info = NULL;
- $this->db = new DatabaseHelper();
- $this->users = array();
- $_SESSION['jwt'] = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicmVzdF91c2VyIiwidXNlcl9pZCI6MSwiZXhwIjoxNzExODUxMDUzfQ.FUcFO44SWV--YtVOy7NftTF8OeeOYGZDaDHigygQxsY';
- if (array_key_exists('jwt', $_SESSION)) {
- $this->get_session($_SESSION['jwt']);
- } else {
- $this->user_id = NULL;
- };
- }
-
- private function get_session($jwt) {
- $query = $this->db
- ->select("_api.verify_jwt('" . $jwt . "') AS user_id;");
- $result = $query->row();
- $user_id = $result['user_id'];
- if ($user_id) {
- $this->user_id = $user_id;
- }
- }
-
- public function link_css($path) {
- return '<link rel="stylesheet" href="/public/' . $path . '">';
- }
-
- public function link_js($path) {
- return '<script src="/public/'. $path . '"></script>';
- }
-
- public function user() {
- if ($this->user_id) {
- return $this->db
- ->select('*')
- ->from('api.user')
- ->where('id')
- ->eq($this->user_id)
- ->row();
- } else {
- return NULL;
- }
- }
-
- public function get_num($key, $default = NULL) {
- if (!array_key_exists($key, $_GET)) {
- if ($default !== NULL) {
- return $default;
- } else {
- error_page(400, lang('error_400'));
- }
- } else {
- $val = $_GET[$key];
- $val = intval($val);
- if ($val < 0) {
- return 0;
- } else {
- return $val;
- }
- }
- }
-
- public function get_users($objs) {
- $ids = array();
- foreach ($objs as $obj) {
- $id = $obj['user_id'];
- if (!array_key_exists($id, $this->users)) {
- array_push($ids, intval($id));
- }
- }
- if (!empty($ids)) {
- $result = $this->db
- ->select('*')
- ->from('api.user')
- ->where_in('id', $ids)
- ->rows();
- foreach ($result as $user) {
- $id = $user['id'];
- $this->users[$id] = $user;
- }
- }
- return $this->users;
- }
-
- public function display_name($user) {
- $name = '';
- if ($user['first_name']) {
- $name .= $user['first_name'];
- }
- if ($user['middle_name']) {
- if ($name != '') {
- $name .= ' ';
- }
- $name .= $user['middle_name'];
- }
- if ($user['last_name']) {
- if ($name != '') {
- $name .= ' ';
- }
- $name .= $user['last_name'];
- }
- if ($name == '') {
- $name = '@' . $user['username'];
- }
- return $name;
- }
-
- public function display_date($date) {
- return $date;
- }
-
-}
-
-?>