From 252e4cfa9c2236e50f38adc4611396a5665f8301 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Tue, 23 Jul 2024 16:34:35 +0200 Subject: Add codegen & emoticons --- src/codegen/emoticons.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/codegen/emoticons.php (limited to 'src/codegen/emoticons.php') diff --git a/src/codegen/emoticons.php b/src/codegen/emoticons.php new file mode 100644 index 0000000..51b9ed6 --- /dev/null +++ b/src/codegen/emoticons.php @@ -0,0 +1,36 @@ + [ + pathinfo($i, PATHINFO_FILENAME), + getimagesize($em_dir . "/" . $i)["3"] + ], + array_values( + array_filter( + scandir($em_dir), + fn($i) => + $i[0] !== "." && + is_file($em_dir . "/" . $i) && + strtolower(pathinfo($i, PATHINFO_EXTENSION)) === "gif" + ) + ) +); + +usort($emoticons, fn($a, $b) => strlen($b[0]) <=> strlen($a[0])); + +$emoticons_alpha_lookup = []; +foreach ($emoticons as $i => $emoticon) { + $emoticons_alpha_lookup []= [$i, $emoticon[0]]; +} +usort($emoticons_alpha_lookup, fn($a, $b) => $a[1] <=> $b[1]); +$emoticons_alpha_lookup = array_column($emoticons_alpha_lookup, 0); + +return [ + "emoticons.js", + "/* auto-generated at " . date("c") . " */\nvar EMOTICONS = " . + json_encode([ + $emoticons, + $emoticons_alpha_lookup, + ], JSON_PRETTY_PRINT) . ";\n", +]; -- cgit v1.2.3