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

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

	$content = '';

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

	return $content;
}

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