summaryrefslogtreecommitdiff
path: root/src/web/helper/image.php
blob: 8815a6c603e66ae2e0e870b1005c2cdab844ec5c (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
<?php /* Copyright (c) 2024 Freya Murphy */

function image($src, $class = NULL, $link = NULL, $click = NULL): string {
	if ($class) {
		$class = 'image-loading ' . $class;
	} else {
		$class = 'image-loading';
	}

	$content = '';

	if ($link) {
		$content .= '<a class="' . $class . '" href="' . $link . '">';
	} else if ($click) {
		$content .= '<button class="' . $class . '" onclick="' . $click . '">';
	} else {
		$content .= '<span class="' . $class . '">';
	}
	$content .= '<img src="' . $src . '" onerror="onImgError(this)" onload="onImgLoad(this)"/>';
	if ($link) {
		$content .= '</a>';
	} else if ($click) {
		$content .= '</button>';
	} else {
		$content .= '</span>';
	}

	return $content;
}

function pfp(
	$user,
	$link = TRUE,
	$click = NULL
): string {
	if ($link === TRUE) {
		$link = '/profile?id=' . $user['id'];
	}
	return image('/api/rpc/profile_avatar?user_id=' . $user['id'], 'pfp', link: $link, click: $click);
}