summaryrefslogtreecommitdiff
path: root/src/web/lib/_controller.php
blob: 122a7a7fe17c910f40d2a4e066fe91d395acf66c (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
<?php /* Copyright (c) 2024 Freya Murphy */

class XSS_Controller extends Controller {
	use XSS_Base;

	protected $model;

	public function __construct() {
		$this->model = new XSS_model();
		$this->load_lang('common', 'api');
	}

	/**
	* Formats a users's name
	* @param array $user - the $user
	* @returns the user's formatted display name
	*/
	public function format_name(array $user): string {
		$name = '';
		// first_name
		if ($user['first_name'])
			$name .= $user['first_name'];
		// middle_name
		if ($user['middle_name']) {
			if ($name != '')
				$name .= ' ';
			$name .= $user['middle_name'];
		}
		// last_name
		if ($user['last_name']) {
			if ($name != '')
				$name .= ' ';
			$name .= $user['last_name'];
		}
		if ($name == '') {
			$name = '@' . $user['username'];
		}
		return $name;
	}

	/**
	 * Formats a ISO date
	 * @param $iso_date the ISO date
	 */
	public function format_date(string $iso_date): string
	{
		return date("Y-m-d D H:i", strtotime($iso_date));
	}
}