pub / tw2html

Checks online status of streams on twitch.tv and lets you watch them
git clone https://https://src.jayvii.de/pub/tw2html.git
Home | Log | Files | Exports | Refs | README | RSS

commit 83a119e44e0ad94bab25e1c1c1a0149477bb9a7b
parent 0df26c53d9c27096d584c13819ca48441c3910e5
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Mon, 21 Oct 2024 18:15:35 +0200

fix: load HTML header before processing input

Diffstat:
Mindex.php | 65++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/index.php b/index.php @@ -5,36 +5,6 @@ <!DOCTYPE html> <html> -<?php - - /* Initilise streams array */ - $streams = array(); - - // Fetch POST argument or the COOKIE - // Cookie should have lowest priority (fallback), POST first (intend) - if (!is_null($_COOKIE["streams"])) { - $streams = explode(",", $_COOKIE["streams"]); - } - if (!is_null($_POST["streams"])) { - $streams = urldecode($_POST["streams"]); - $streams = preg_replace('/[^a-z0-9\-\_\.\,]+/', '', $streams); - $streams = explode(",", $streams); - } - - // Sort streams by alphabet - sort($streams); - - /* refresh cookie */ - header( - "Set-Cookie: " . - "streams=" . implode(",", $streams) . ";" . - "Max-Age=" . 31536000 . "; " . /* 60 x 60 x 24 x 365 = 1 year */ - "Domain=" . $_SERVER["SERVER_NAME"] . "; " . - "SameSite=Strict;" - ); - -?> - <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Twitch Streams</title> @@ -51,9 +21,40 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> + <?php + + /* Initilise streams array */ + $streams = array(); + + // Fetch POST argument or the COOKIE + // Cookie should have lowest priority (fallback), POST first (intend) + if (!is_null($_COOKIE["streams"])) { + $streams = explode(",", $_COOKIE["streams"]); + } + if (!is_null($_POST["streams"])) { + $streams = urldecode($_POST["streams"]); + $streams = preg_replace('/[^a-z0-9\-\_\.\,]+/', '', $streams); + $streams = explode(",", $streams); + } + + // Sort streams by alphabet + sort($streams); + + /* refresh cookie */ + header( + "Set-Cookie: " . + "streams=" . implode(",", $streams) . ";" . + "Max-Age=" . 31536000 . "; " . /* 60 x 60 x 24 x 365 = 1 year */ + "Domain=" . $_SERVER["SERVER_NAME"] . "; " . + "SameSite=Strict;" + ); + + ?> + <body onload="tw2html_daemon();"> <header> + <!-- Buttons --> <nav> <a href="#" onclick="tw2html_reload();">Reload</a> @@ -62,8 +63,10 @@ Development </a> </nav> + <!-- Headline --> <h1>Streams</h1> + <!-- Loading Indicator --> <div id="loading_indicators"> <?php @@ -74,12 +77,12 @@ id="loading_indicator_<?php echo $stream; ?>" title="<?php echo $stream; ?>" > - ■ </span> <?php } ?> </div> + </header> <!-- Search Bar -->