diff options
Diffstat (limited to 'src/web/helper/image.php')
-rw-r--r-- | src/web/helper/image.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/web/helper/image.php b/src/web/helper/image.php new file mode 100644 index 0000000..ac2f808 --- /dev/null +++ b/src/web/helper/image.php @@ -0,0 +1,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); +} |