Added support for higher pixel density avatars, added link to create new polls

This commit is contained in:
2021-04-04 09:44:33 +02:00
parent 4bf3a3f552
commit 50750c6808
5 changed files with 86 additions and 7 deletions

View File

@ -17,11 +17,13 @@ function get_page_header(
global $api;
$greeting = '';
$logout_link = '';
$newpoll_class = '';
if ($api->isAuthenticated(false, true)) {
$u = $api->getAuthorizedUser();
$greeting = 'Welcome, ' . ($u->name ?? '@'.$u->username);
$logout_link = '<a href="logout.php" class="logout">Logout</a>';
} else {
$newpoll_class = 'disabled';
$greeting = '<a href="' . $api->getAuthURL() . '">Login with pnut</a>';
}
$title = '';
@ -36,12 +38,16 @@ function get_page_header(
foreach ($scripts as $script) {
$script_str .= '<script src="scripts/' . $script . '.js"></script>';
}
return '<html><head><meta charset="utf-8"><title>'.$title.'</title><link rel="stylesheet" href="styles/style.css">'
. $script_str
. '</head><body><header>'
. '<a href="index.php" class="homelink" title="Home"><div class="linkcontents">'
. file_get_contents(__DIR__.'/icons/home.svg')
. '<span class="linklabel">Home</span></div></a>'
. '<a href="new_poll.php" class="newpolllink '.$newpoll_class.'" title="New Poll"><div class="linkcontents">'
. file_get_contents(__DIR__.'/icons/plus.svg') //TODO
. '<span class="linklabel">New Poll</span></div></a>'
. $greeting
. '<div class="spacer"></div>'
. $logout_link
@ -54,3 +60,12 @@ function redirect($to)
die('<html><meta http-equiv="refresh" content="0;url='.$to.'">'
.'<script>window.location.replace("'.$to.'");</script></html>');
}
function get_source_set($user, int $base_size, int $max_scale = 3): string
{
$srcset_entries = [$user->getAvatarUrl($base_size)];
for ($s = 2; $s <= $max_scale; $s++) {
$srcset_entries[] = $user->getAvatarUrl($base_size * $s) . ' ' . $s . 'x';
}
return implode(', ', $srcset_entries);
}