summaryrefslogtreecommitdiff
path: root/src/web/lib/_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/lib/_model.php')
-rw-r--r--src/web/lib/_model.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/web/lib/_model.php b/src/web/lib/_model.php
new file mode 100644
index 0000000..c29e015
--- /dev/null
+++ b/src/web/lib/_model.php
@@ -0,0 +1,61 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+
+class XSS_Model extends Model {
+ use XSS_Base;
+
+ private static array $loaded_users = array();
+
+ /**
+ * Gets an array of users with IDs specified by 'user_id' in $objs
+ */
+ public function get_users($objs) {
+ // null check
+ if (!$objs)
+ return self::$loaded_users;
+
+ $ids = array();
+ // get all user_id's to load (not in loaded_users)
+ foreach ($objs as $obj) {
+ $id = $obj['user_id'];
+ if (!isset(self::$loaded_users[$id]))
+ $ids[] = intval($id);
+ }
+ // if there are users to load
+ if (count($ids)) {
+ $result = $this->db()
+ ->select('*')
+ ->from('api.user')
+ ->where_in('id', $ids)
+ ->rows();
+ foreach ($result as $user)
+ self::$loaded_users[$user['id']] = $user;
+ }
+ // return result
+ return self::$loaded_users;
+ }
+
+ /**
+ * Gets the page's title
+ */
+ public function get_title(): string {
+ $xssbook = lang('xssbook');
+ $title = lang('title');
+ if ($title)
+ return "$xssbook - $title";
+ return $xssbook;
+ }
+
+ /**
+ * Adds title to base data
+ */
+ #[\Override]
+ public function get_data(): ?array {
+ $data = parent::get_data();
+ // title
+ $data['title'] = $this->get_title();
+ // session
+ $auth_model = $this->load_model('auth');
+ $data['session'] = $auth_model->session();;
+ return $data;
+ }
+}