diff options
author | Freya Murphy <freya@freyacat.org> | 2024-12-23 11:13:27 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-12-23 11:13:27 -0500 |
commit | 5a2ba9c2e7605bb788bc406184547d22c6436867 (patch) | |
tree | cbd988d534e8a8593a31d70571222443f80da0b3 /src/web/lib/image.php | |
parent | fix about modal (diff) | |
download | xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.gz xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.bz2 xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.zip |
v2.1.0, refactor w/ crimson
Diffstat (limited to 'src/web/lib/image.php')
-rw-r--r-- | src/web/lib/image.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/web/lib/image.php b/src/web/lib/image.php new file mode 100644 index 0000000..6d42678 --- /dev/null +++ b/src/web/lib/image.php @@ -0,0 +1,77 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +function image( + $src, + $class = NULL, + $link = NULL, + $click = NULL, + $height = NULL, + $width = NULL, + $mime = NULL, +): string { + if ($class) { + $class = 'image loading ' . $class; + } else { + $class = 'image loading'; + } + + $content = ''; + + // dont need mime for images + if ($mime && strpos($mime, 'image') !== FALSE) { + $mime = NULL; + } + + if ($link) { + $content .= '<a class="' . $class . '" href="' . $link . '">'; + } else if ($click) { + $content .= '<button class="' . $class . '" onclick="' . $click . '">'; + } else { + $content .= '<span class="' . $class . '">'; + } + if ($mime) { + $content .= '<object class="inner" type="' . $mime . '" data="' . $src . '" '; + } else { + $content .= '<img class="inner" src="' . $src . '" '; + } + if ($height) { + $content .= "height=\"{$height}\" "; + } + if ($width) { + $content .= "width=\"{$width}\" "; + } + if ($mime) { + $content .= '></object>'; + } else { + $content .= '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']; + } + $mime = NULL; + if (isset($user['avatar_mime'])) { + $mime = $user['avatar_mime']; + } + return image('/api/rpc/profile_avatar?user_id=' . $user['id'], + 'pfp', + link: $link, + click: $click, + mime: $mime + ); +} |