console.log('.json_encode($obj).');'; } function get_page_header( ?string $page_title = null, bool $include_app_name = true, array $scripts = [] ): string { global $api; $greeting = ''; $logout_link = ''; $newpoll_class = ''; if ($api->isAuthenticated(false, true)) { $u = $api->getAuthorizedUser(); $greeting = 'Welcome, ' . ($u->name ?? '@'.$u->username); $logout_link = 'Logout'; } else { $newpoll_class = 'disabled'; $greeting = 'Login with pnut'; } $title = ''; if ($include_app_name) { $title = $api->app_name; } if (!empty($page_title)) { $title .= $include_app_name ? ' > ' : ''; $title .= $page_title; } $script_str = ''; foreach ($scripts as $script) { $script_str .= ''; } $home_link = get_icon_link( 'index.php', 'Home', 'home', 'homelink' ); $new_poll_link = get_icon_link( 'new_poll.php', 'New Poll', 'plus', 'newpolllink' ); $favicons = '' . '' . '' . '' . '' . '' . '' . '' . '' . ''; return '' . $favicons . ''.$title.'' . $script_str . '
' . $home_link . $new_poll_link . $greeting . '
' . $logout_link . '
'; } function get_icon_link(string $href, string $label, string $icon, string $class) { return '' . '
' . file_get_contents(__DIR__.'/icons/'.$icon.'.svg') . ''.$label.'
'; } function get_page_footer() { $version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version']; $repo_link = get_icon_link( 'https://phlaym.net/git/phlaym/Dragonpolls', 'Source Code', 'src', 'sourcecode' ); $issues_link = get_icon_link( 'https://github.com/hutattedonmyarm/Dragonpolls/issues', 'Issues', 'issues', 'issues' ); return '
'; } function redirect($to) { header('Location: '.$to); die('' .''); } 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); } function make_banner(string $type, string $content, string $custom_symbol = null): string { if (empty($custom_symbol)) { $custom_symbol = $type === 'success' ? '✓' : '𐄂'; } return ''; } function quit(string $error, string $error_details = '') { die(make_banner('error', $error) . $error_details . get_page_footer()); }