summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/emotes/index.php69
-rw-r--r--public/static/style.css187
-rw-r--r--src/emote.php36
-rw-r--r--src/emotes/multiple_page.php37
-rw-r--r--src/emotes/single_page.php82
5 files changed, 411 insertions, 0 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
new file mode 100644
index 0000000..a4bf585
--- /dev/null
+++ b/public/emotes/index.php
@@ -0,0 +1,69 @@
+<?php
+include "../../src/emote.php";
+
+function display_list_emotes(int $page, int $limit): array
+{
+ $db = new SQLite3("../../database.db");
+ $stmt = $db->prepare("SELECT * FROM emotes ORDER BY created_at ASC LIMIT :limit OFFSET :offset");
+ $stmt->bindValue(":offset", $page * $limit, SQLITE3_INTEGER);
+ $stmt->bindValue(":limit", $limit, SQLITE3_INTEGER);
+ $results = $stmt->execute();
+
+ $emotes = [];
+
+ while ($row = $results->fetchArray()) {
+ array_push($emotes, new Emote(
+ $row["id"],
+ $row["code"],
+ $row["ext"],
+ intval(strtotime($row["created_at"]))
+ ));
+ }
+
+ return $emotes;
+}
+
+function display_emote(int $id)
+{
+ $db = new SQLite3("../../database.db");
+ $stmt = $db->prepare("SELECT * FROM emotes WHERE id = :id");
+ $stmt->bindValue(":id", $id, SQLITE3_INTEGER);
+ $results = $stmt->execute();
+
+ if ($row = $results->fetchArray()) {
+ $emote = new Emote(
+ $row["id"],
+ $row["code"],
+ $row["ext"],
+ intval(strtotime($row["created_at"]))
+ );
+ }
+
+ if ($emote == null) {
+ echo "not found";
+ exit;
+ }
+
+ return $emote;
+}
+
+$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ||
+ $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
+$current_url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+
+$id = parse_url($current_url, PHP_URL_PATH);
+$id = substr($id, 8);
+$id = str_replace("/", "", $id);
+
+$emotes = null;
+$emote = null;
+
+if ($id == "" || !is_numeric($id)) {
+ $page = intval($_GET["p"] ?? "0");
+ $limit = 50;
+ $emotes = display_list_emotes($page, $limit);
+ include "../../src/emotes/multiple_page.php";
+} else {
+ $emote = display_emote(intval($id));
+ include "../../src/emotes/single_page.php";
+}
diff --git a/public/static/style.css b/public/static/style.css
new file mode 100644
index 0000000..f4d8380
--- /dev/null
+++ b/public/static/style.css
@@ -0,0 +1,187 @@
+:root {
+ --background-color: #d7dfcd;
+ --background-color-hover: #e4eed8;
+ --background-color-disabled: #bec6b3;
+ --border-color: #b0b9a5;
+}
+
+* {
+ padding: 0;
+ margin: 0;
+
+ font-family: Arial, Helvetica, sans-serif;
+}
+
+div {
+ display: unset;
+}
+
+table.vertical th {
+ text-align: right;
+}
+
+table.vertical th,
+table.vertical td {
+ padding: 2px;
+}
+
+.container {
+ width: 100%;
+ min-height: 100vh;
+ display: flex;
+}
+
+.wrapper {
+ flex-grow: 1;
+ display: flex;
+}
+
+main.content {
+ flex-grow: 1;
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ margin: 6px;
+}
+
+/**
+-------------
+ BUTTONS
+-------------
+*/
+
+button,
+.button {
+ background: lightgray;
+ border: 1px solid gray;
+ border-radius: 4px;
+ padding: 2px 4px;
+ font-size: 14px;
+ text-decoration: none;
+ color: black;
+}
+
+button:hover,
+.button:hover {
+ background: #b9b9b9;
+ cursor: pointer;
+}
+
+button.transparent,
+.button.transparent {
+ background: unset;
+ border: unset;
+}
+
+/**
+----------
+ LIST
+----------
+*/
+
+.items {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.items.content {
+ flex-grow: 1;
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ gap: 16px;
+}
+
+.navtab {
+ position: relative;
+ width: 50%;
+ top: 2px;
+}
+
+.full {
+ flex-grow: 1;
+}
+
+.row {
+ flex-direction: row;
+ align-items: center;
+}
+
+.right {
+ justify-content: flex-end;
+}
+
+/**
+---------
+ BOX
+---------
+*/
+
+.box {
+ background: var(--background-color);
+ border: 2px solid var(--border-color);
+ border-radius: 4px;
+ padding: 4px;
+}
+
+.box.navtab {
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+ border-bottom: unset;
+ margin: 0;
+}
+
+.box:has(.navtab) {
+ background: unset;
+ border: unset;
+ border-radius: unset;
+ padding: 0;
+
+ display: flex;
+ flex-direction: column;
+}
+
+.box:has(.navtab) .content {
+ flex-grow: 1;
+ margin: 0;
+ padding: 16px;
+}
+
+.box.emote {
+ width: 90px;
+ height: 90px;
+
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+
+ gap: 6px;
+
+ overflow: hidden;
+}
+
+.box.emote p {
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+a.box {
+ text-decoration: none;
+ color: black;
+}
+
+a.box:hover {
+ background: linear-gradient(0deg, var(--background-color-hover), var(--background-color-disabled));
+ cursor: pointer;
+}
+
+.emote-showcase {
+ flex-grow: 1;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ gap: 32px;
+ margin: 32px 0;
+} \ No newline at end of file
diff --git a/src/emote.php b/src/emote.php
new file mode 100644
index 0000000..5d39e42
--- /dev/null
+++ b/src/emote.php
@@ -0,0 +1,36 @@
+<?php
+class Emote
+{
+ public string $id;
+ public string $code;
+ public string $ext;
+ public int $created_at;
+
+ function __construct($id, $code, $ext, $created_at)
+ {
+ $this->id = $id;
+ $this->code = $code;
+ $this->ext = $ext;
+ $this->created_at = $created_at;
+ }
+
+ function get_id()
+ {
+ return $this->id;
+ }
+
+ function get_code()
+ {
+ return $this->code;
+ }
+
+ function get_ext()
+ {
+ return $this->ext;
+ }
+
+ function get_created_at()
+ {
+ return $this->created_at;
+ }
+}
diff --git a/src/emotes/multiple_page.php b/src/emotes/multiple_page.php
new file mode 100644
index 0000000..e46c7ab
--- /dev/null
+++ b/src/emotes/multiple_page.php
@@ -0,0 +1,37 @@
+<html>
+
+<head>
+ <title>AlrightTV</title>
+ <link rel="stylesheet" href="/static/style.css">
+</head>
+
+<body>
+ <div class="container">
+ <div class="wrapper">
+ <main class="content">
+ <section class="box">
+ <div class="box navtab">
+ <?php echo isset($emotes) ? "Emotes" : "Emote" ?>
+ </div>
+ <div class="box content items">
+ <?php
+ if (isset($emotes)) {
+ foreach ($emotes as $e) {
+ echo "<a class=\"box emote\" href=\"/emotes/" . $e->get_id() . "\">";
+ echo "<img src=\"/static/userdata/emotes/" . $e->get_id() . "/2x." . $e->get_ext() . "\" alt=\"" . $e->get_code() . "\"/>";
+ echo "<p>" . $e->get_code() . "</p>";
+ echo "</a>";
+ }
+ } else {
+ // info
+ echo "";
+ }
+ ?>
+ </div>
+ </section>
+ </main>
+ </div>
+ </div>
+</body>
+
+</html> \ No newline at end of file
diff --git a/src/emotes/single_page.php b/src/emotes/single_page.php
new file mode 100644
index 0000000..254e0e9
--- /dev/null
+++ b/src/emotes/single_page.php
@@ -0,0 +1,82 @@
+<html>
+
+<head>
+ <title>AlrightTV</title>
+ <link rel="stylesheet" href="/static/style.css">
+</head>
+
+<body>
+ <div class="container">
+ <div class="wrapper">
+ <main class="content">
+ <section class="box">
+ <div class="box navtab">
+ Emote - <?php echo $emote->get_code() ?>
+ </div>
+ <div class="box content">
+ <div class="emote-showcase">
+ <img src="<?php echo '/static/userdata/emotes/' . $emote->get_id() . '/' . '1x.' . $emote->get_ext() ?>"
+ alt="<?php echo $emote->get_code() ?>">
+ <img src="<?php echo '/static/userdata/emotes/' . $emote->get_id() . '/' . '2x.' . $emote->get_ext() ?>"
+ alt="<?php echo $emote->get_code() ?>">
+ <img src="<?php echo '/static/userdata/emotes/' . $emote->get_id() . '/' . '3x.' . $emote->get_ext() ?>"
+ alt="<?php echo $emote->get_code() ?>">
+ </div>
+ </div>
+ </section>
+
+ <section class="box items row">
+ <div class="items row left full">
+ <form action="/emotes/add.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>" style="display: none;">
+ <button type="submit" class="green">Add to my channel</button>
+ </form>
+ </div>
+ <div class="items row right full">
+ <form action="/emotes/rate.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>" style="display: none;">
+ <input type="text" name="rate" value="5" style="display:none;">
+ <button type="submit" class="transparent">gem</button>
+ </form>
+ <form action="/emotes/rate.php" method="POST">
+ <input type="text" name="id" value="<?php echo $emote->get_id() ?>" style="display: none;">
+ <input type="text" name="rate" value="1" style="display:none;">
+ <button type="submit" class="transparent">coal</button>
+ </form>
+ <a class="button red" href="/emotes/report.php?id=<?php echo $emote->get_id() ?>">Report
+ emote</a>
+ </div>
+ </section>
+
+ <section class="box">
+ <table class="vertical">
+ <tr>
+ <th>Uploader</th>
+ <td><?php
+ echo '<a href="/users/' . "0" . '">' . "someone" . '</a>, ';
+ echo date("d M Y", $emote->get_created_at());
+ ?></td>
+ </tr>
+ <tr>
+ <th>Rating</th>
+ <td>Not rated</td>
+ </tr>
+ </table>
+ </section>
+
+ <section class="box">
+ <div class="content">
+ <p>Added in <?php echo 20 ?> channels</p>
+ <div class="items row">
+ <a href="/users/1">forsen</a>
+ <a href="/users/2">not_forsen</a>
+ <a href="/users/3">lidl_forsen</a>
+ </div>
+ </div>
+ </section>
+ </main>
+ </div>
+ </div>
+</body>
+
+</html> \ No newline at end of file