summaryrefslogtreecommitdiff
path: root/src/web/lib/_model.php
blob: c29e015e8a8e4690f3c3990f04be14a210ea2fbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
	}
}