From a039026e7ec345150b730e10eebbb4c646ece49e Mon Sep 17 00:00:00 2001 From: Greg Sarjeant <1686767+gsarjeant@users.noreply.github.com> Date: Wed, 28 May 2025 20:32:25 -0400 Subject: [PATCH] Add mood feature. --- tkr/bootstrap.php | 3 +- tkr/lib/config.php | 6 + tkr/lib/emoji.php | 304 +++++++++++++++++++++++++++++++++++++++ tkr/lib/mood.php | 67 +++++++++ tkr/public/css/tkr.css | 54 +++++++ tkr/public/index.php | 13 +- tkr/public/login.php | 5 +- tkr/public/save_tick.php | 13 +- tkr/public/set_mood.php | 44 ++++++ 9 files changed, 490 insertions(+), 19 deletions(-) create mode 100644 tkr/lib/emoji.php create mode 100644 tkr/lib/mood.php create mode 100644 tkr/public/css/tkr.css create mode 100644 tkr/public/set_mood.php diff --git a/tkr/bootstrap.php b/tkr/bootstrap.php index 454de86..0f46872 100644 --- a/tkr/bootstrap.php +++ b/tkr/bootstrap.php @@ -38,7 +38,8 @@ function confirm_setup(): void { id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, display_name TEXT NOT NULL, - password_hash TEXT NOT NULL + password_hash TEXT NOT NULL, + mood TEXT NULL )"); $db->exec("CREATE TABLE IF NOT EXISTS settings ( diff --git a/tkr/lib/config.php b/tkr/lib/config.php index 012c885..4d998f0 100644 --- a/tkr/lib/config.php +++ b/tkr/lib/config.php @@ -3,23 +3,29 @@ require_once __DIR__ . '/../bootstrap.php'; confirm_setup(); +// Made this a class so it could be more obvious where config settings are coming from. +// Felt too much like magic constants in other files before. class Config { + // properties and default values public string $siteTitle = 'My tkr'; public string $siteDescription = ''; public string $basePath = '/'; public int $itemsPerPage = 25; + // load config from sqlite database public static function load(): self { $db = get_db(); $stmt = $db->query("SELECT site_title, site_description, base_path, items_per_page FROM settings WHERE id=1"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $c = new self(); + if ($row) { $c->siteTitle = $row['site_title']; $c->siteDescription = $row['site_description']; $c->basePath = $row['base_path']; $c->itemsPerPage = (int) $row['items_per_page']; } + return $c; } } \ No newline at end of file diff --git a/tkr/lib/emoji.php b/tkr/lib/emoji.php new file mode 100644 index 0000000..7cb450f --- /dev/null +++ b/tkr/lib/emoji.php @@ -0,0 +1,304 @@ + [ + ['๐', 'grinning face'], + ['๐', 'grinning face with big eyes'], + ['๐', 'grinning face with smiling eyes'], + ['๐', 'beaming face with smiling eyes'], + ['๐', 'grinning squinting face'], + ['๐ ', 'grinning face with sweat'], + ['๐', 'face with tears of joy'], + ['๐คฃ', 'rolling on the floor laughing'], + ['๐', 'smiling face with smiling eyes'], + ['๐', 'smiling face with halo'], + ['๐', 'slightly smiling face'], + ['๐', 'upside-down face'], + ['๐', 'winking face'], + ['๐', 'relieved face'], + ['๐', 'smiling face with heart-eyes'], + ['๐ฅฐ', 'smiling face with hearts'], + ['๐', 'face blowing a kiss'], + ['๐', 'kissing face'], + ['๐', 'kissing face with closed eyes'], + ['๐', 'face savoring food'], + ['๐', 'face with tongue'], + ['๐', 'winking face with tongue'], + ['๐', 'squinting face with tongue'], + ['๐คช', 'zany face'], + ['๐คจ', 'face with raised eyebrow'], + ], + 'gestures' => [ + ['๐', 'waving hand'], + ['๐ค', 'raised back of hand'], + ['๐๏ธ', 'hand with fingers splayed'], + ['โ', 'raised hand'], + ['๐', 'vulcan salute'], + ['๐', 'OK hand'], + ['๐ค', 'pinched fingers'], + ['๐ค', 'pinching hand'], + ['โ๏ธ', 'victory hand'], + ['๐ค', 'crossed fingers'], + ['๐ค', 'love-you gesture'], + ['๐ค', 'sign of the horns'], + ['๐ค', 'call me hand'], + ['๐', 'backhand index pointing left'], + ['๐', 'backhand index pointing right'], + ['๐', 'backhand index pointing up'], + ['๐', 'middle finger'], + ['๐', 'backhand index pointing down'], + ['โ๏ธ', 'index pointing up'], + ['๐', 'thumbs up'], + ['๐', 'thumbs down'], + ['โ', 'raised fist'], + ['๐', 'oncoming fist'], + ['๐ค', 'left-facing fist'], + ['๐ค', 'right-facing fist'], + ], + 'nature' => [ + ['โ๏ธ', 'sun'], + ['๐ค๏ธ', 'sun behind small cloud'], + ['โ ', 'sun behind cloud'], + ['๐ฅ๏ธ', 'sun behind large cloud'], + ['๐ฆ๏ธ', 'sun behind rain cloud'], + ['๐ง๏ธ', 'cloud with rain'], + ['๐จ๏ธ', 'cloud with snow'], + ['โ๏ธ', 'snowflake'], + ['๐ฉ๏ธ', 'cloud with lightning'], + ['๐ช๏ธ', 'tornado'], + ['๐', 'rainbow'], + ['๐ฅ', 'fire'], + ['๐ง', 'droplet'], + ['๐', 'water wave'], + ['๐ซ๏ธ', 'fog'], + ['๐ฌ๏ธ', 'wind face'], + ['๐', 'leaf fluttering in wind'], + ['๐', 'fallen leaf'], + ['๐', 'maple leaf'], + ['๐พ', 'sheaf of rice'], + ['๐ต', 'cactus'], + ['๐ด', 'palm tree'], + ['๐ณ', 'deciduous tree'], + ['๐ฒ', 'evergreen tree'], + ['๐ธ', 'cherry blossom'], + ], + 'animals' => [ + ['๐ถ', 'dog face'], + ['๐ฑ', 'cat face'], + ['๐ญ', 'mouse face'], + ['๐น', 'hamster face'], + ['๐ฐ', 'rabbit face'], + ['๐ฆ', 'fox face'], + ['๐ป', 'bear face'], + ['๐ผ', 'panda face'], + ['๐จ', 'koala'], + ['๐ฏ', 'tiger face'], + ['๐ฆ', 'lion face'], + ['๐ฎ', 'cow face'], + ['๐ท', 'pig face'], + ['๐ธ', 'frog face'], + ['๐ต', 'monkey face'], + ['๐', 'see-no-evil monkey'], + ['๐', 'hear-no-evil monkey'], + ['๐', 'speak-no-evil monkey'], + ['๐', 'chicken'], + ['๐ง', 'penguin'], + ['๐ฆ', 'bird'], + ['๐ค', 'baby chick'], + ['๐ฃ', 'hatching chick'], + ['๐บ', 'wolf face'], + ['๐ฆ', 'unicorn face'], + ], + 'people' => [ + ['๐ง', 'person'], + ['๐ฉ', 'woman'], + ['๐จ', 'man'], + ['๐ถ', 'baby'], + ['๐ง', 'girl'], + ['๐ฆ', 'boy'], + ['๐ง', 'child'], + ['๐ต', 'older woman'], + ['๐ด', 'older man'], + ['๐ง', 'older adult'], + ['๐ฒ', 'person with skullcap'], + ['๐ง', 'woman with headscarf'], + ['๐ณ', 'person wearing turban'], + ['๐ฎ', 'police officer'], + ['๐ต๏ธ', 'detective'], + ['๐ท', 'construction worker'], + ['๐', 'guard'], + ['๐ธ', 'princess'], + ['๐คด', 'prince'], + ['๐ฆธ', 'superhero'], + ['๐ฆน', 'supervillain'], + ['๐ง', 'mage'], + ['๐ง', 'vampire'], + ['๐ง', 'zombie'], + ['๐ง', 'genie'], + ], + 'emotions' => [ + ['โค๏ธ', 'red heart'], + ['๐งก', 'orange heart'], + ['๐', 'yellow heart'], + ['๐', 'green heart'], + ['๐', 'blue heart'], + ['๐', 'purple heart'], + ['๐ค', 'black heart'], + ['๐ค', 'white heart'], + ['๐ค', 'brown heart'], + ['๐', 'sparkling heart'], + ['๐', 'growing heart'], + ['๐', 'beating heart'], + ['๐', 'revolving hearts'], + ['๐', 'two hearts'], + ['๐', 'heart with arrow'], + ['๐', 'heart with ribbon'], + ['๐', 'broken heart'], + ['โฃ๏ธ', 'heart exclamation'], + ['๐', 'heart decoration'], + ['๐ค', 'zzz'], + ['๐คฏ', 'exploding head'], + ['๐ฑ', 'face screaming in fear'], + ['๐ฅต', 'hot face'], + ['๐ฅถ', 'cold face'], + ['๐คฌ', 'face with symbols on mouth'], + ], + 'activities' => [ + ['๐ด', 'person biking'], + ['๐ต', 'person mountain biking'], + ['๐', 'person running'], + ['๐โโ๏ธ', 'woman running'], + ['๐๏ธ', 'person lifting weights'], + ['๐', 'person swimming'], + ['๐', 'person surfing'], + ['๐ฃ', 'person rowing boat'], + ['๐คฝ', 'person playing water polo'], + ['๐คพ', 'person playing handball'], + ['โน๏ธ', 'person bouncing ball'], + ['๐คธ', 'person cartwheeling'], + ['๐ง', 'person in lotus position'], + ['๐', 'horse racing'], + ['๐ง', 'person climbing'], + ['๐๏ธ', 'camping'], + ['๐ฃ', 'fishing pole'], + ['โบ', 'tent'], + ['๐ฟ', 'skis'], + ['๐', 'snowboarder'], + ['๐น', 'skateboard'], + ['๐ผ', 'roller skate'], + ['๐งบ', 'basket'], + ['๐ฏ', 'bullseye'], + ['๐๏ธ', 'person golfing'], + ], + 'hobbies' => [ + ['๐', 'books'], + ['๐', 'open book'], + ['๐ง', 'headphone'], + ['๐ต', 'musical note'], + ['๐ถ', 'musical notes'], + ['๐ค', 'microphone'], + ['๐ผ', 'musical score'], + ['๐ท', 'saxophone'], + ['๐ธ', 'guitar'], + ['๐น', 'musical keyboard'], + ['๐บ', 'trumpet'], + ['๐ป', 'violin'], + ['๐ช', 'banjo'], + ['โ๏ธ', 'writing hand'], + ['๐๏ธ', 'pen'], + ['๐', 'memo'], + ['๐ท', 'camera'], + ['๐ธ', 'camera with flash'], + ['๐จ', 'artist palette'], + ['๐งต', 'thread'], + ['๐งถ', 'yarn'], + ['๐ชก', 'sewing needle'], + ['๐น', 'video camera'], + ['๐ฌ', 'clapper board'], + ['๐งฉ', 'puzzle piece'], + ], + 'tech' => [ + ['๐ป', 'laptop'], + ['๐ฅ๏ธ', 'desktop computer'], + ['๐จ๏ธ', 'printer'], + ['๐ฑ๏ธ', 'computer mouse'], + ['โจ๏ธ', 'keyboard'], + ['๐ฑ', 'mobile phone'], + ['๐ฒ', 'mobile phone with arrow'], + ['๐', 'telephone receiver'], + ['โ๏ธ', 'telephone'], + ['๐', 'pager'], + ['๐ ', 'fax machine'], + ['๐', 'battery'], + ['๐', 'electric plug'], + ['๐ฝ', 'computer disk'], + ['๐พ', 'floppy disk'], + ['๐ฟ', 'optical disk'], + ['๐', 'dvd'], + ['๐งฎ', 'abacus'], + ['๐น๏ธ', 'joystick'], + ['๐ก', 'satellite antenna'], + ['๐', 'magnifying glass tilted left'], + ['๐', 'magnifying glass tilted right'], + ['๐งญ', 'compass'], + ['๐', 'bar chart'], + ['๐', 'chart increasing'], + ], + 'travel' => [ + ['โ๏ธ', 'airplane'], + ['๐ซ', 'airplane departure'], + ['๐ฌ', 'airplane arrival'], + ['๐', 'automobile'], + ['๐', 'taxi'], + ['๐', 'sport utility vehicle'], + ['๐', 'bus'], + ['๐', 'trolleybus'], + ['๐๏ธ', 'racing car'], + ['๐', 'police car'], + ['๐', 'ambulance'], + ['๐', 'fire engine'], + ['๐', 'minibus'], + ['๐ป', 'pickup truck'], + ['๐', 'delivery truck'], + ['๐', 'articulated lorry'], + ['๐', 'tractor'], + ['๐ฒ', 'bicycle'], + ['๐ด', 'kick scooter'], + ['๐จ', 'police car light'], + ['โต', 'sailboat'], + ['๐ค', 'speedboat'], + ['๐ณ๏ธ', 'passenger ship'], + ['โด๏ธ', 'ferry'], + ['๐', 'helicopter'], + ], + 'food' => [ + ['๐', 'red apple'], + ['๐', 'banana'], + ['๐', 'grapes'], + ['๐', 'strawberry'], + ['๐', 'watermelon'], + ['๐', 'pineapple'], + ['๐ฅญ', 'mango'], + ['๐', 'peach'], + ['๐', 'cherries'], + ['๐ ', 'tomato'], + ['๐ฅฆ', 'broccoli'], + ['๐ฅ', 'carrot'], + ['๐ฝ', 'ear of corn'], + ['๐ฅ', 'potato'], + ['๐', 'bread'], + ['๐ฅ', 'croissant'], + ['๐ฅ', 'baguette bread'], + ['๐ง', 'cheese wedge'], + ['๐', 'pizza'], + ['๐', 'hamburger'], + ['๐', 'french fries'], + ['๐ญ', 'hot dog'], + ['๐ฅช', 'sandwich'], + ['๐ฎ', 'taco'], + ['๐ฃ', 'sushi'], + ], + + //'custom' => get_user_emojis($db), + ]; +} diff --git a/tkr/lib/mood.php b/tkr/lib/mood.php new file mode 100644 index 0000000..4b1c44d --- /dev/null +++ b/tkr/lib/mood.php @@ -0,0 +1,67 @@ +prepare("SELECT mood FROM user WHERE username=?"); + $stmt->execute([$_SESSION['username']]); + $row = $stmt->fetch(); + + return $row['mood']; +} + +function save_mood(string $mood): void { + $config = Config::load(); + $db = get_db(); + + $stmt = $db->prepare("UPDATE user SET mood=? WHERE username=?"); + $stmt->execute([$mood, $_SESSION['username']]); + + header("Location: $config->basePath"); + exit; +} + +function render_emoji_tabs(?string $selected_emoji = null): string { + $emoji_groups = get_emojis_with_labels(); + + ob_start(); + ?> + + $emojis): ?> +
+ + +Current mood: = get_mood() ?> | Set your mood
Logout = htmlspecialchars($_SESSION['username']) ?>
diff --git a/tkr/public/login.php b/tkr/public/login.php index 0f6ddd4..fb02e53 100644 --- a/tkr/public/login.php +++ b/tkr/public/login.php @@ -1,7 +1,9 @@ basePath); exit; \ No newline at end of file diff --git a/tkr/public/set_mood.php b/tkr/public/set_mood.php new file mode 100644 index 0000000..574e858 --- /dev/null +++ b/tkr/public/set_mood.php @@ -0,0 +1,44 @@ +basePath); + exit; +} +?> + + + + +