diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8bd4a3a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+emotes
\ No newline at end of file
diff --git a/emotes.php b/emotes.php
index 91dec70..52f32b2 100644
--- a/emotes.php
+++ b/emotes.php
@@ -96,113 +96,168 @@ function toggleHidden(){
$old_y)
- {
- $thumb_w = $new_width;
- $thumb_h = $old_y*($new_height/$old_x);
- }
+ if($old_x > $old_y)
+ {
+ $thumb_w = $new_width;
+ $thumb_h = $old_y*($new_height/$old_x);
+ }
- if($old_x < $old_y)
- {
- $thumb_w = $old_x*($new_width/$old_y);
- $thumb_h = $new_height;
- }
+ if($old_x < $old_y)
+ {
+ $thumb_w = $old_x*($new_width/$old_y);
+ $thumb_h = $new_height;
+ }
- if($old_x == $old_y)
- {
- $thumb_w = $new_width;
- $thumb_h = $new_height;
- }
+ if($old_x == $old_y)
+ {
+ $thumb_w = $new_width;
+ $thumb_h = $new_height;
+ }
- $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
+ $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
- imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
+ imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
- // New save location
- $new_thumb_loc = $moveToDir . $image_name;
+ // New save location
+ $new_thumb_loc = $moveToDir . $image_name;
- if($mime['mime']=='image/png') {
- $result = imagepng($dst_img,$new_thumb_loc,8);
- }
- if($mime['mime']=='image/jpg' || $mime['mime']=='image/jpeg' || $mime['mime']=='image/pjpeg') {
- $result = imagejpeg($dst_img,$new_thumb_loc,80);
- }
+ if($mime['mime']=='image/png') {
+ $result = imagepng($dst_img,$new_thumb_loc,8);
+ }
+ if($mime['mime']=='image/jpg' || $mime['mime']=='image/jpeg' || $mime['mime']=='image/pjpeg') {
+ $result = imagejpeg($dst_img,$new_thumb_loc,80);
+ }
- imagedestroy($dst_img);
- imagedestroy($src_img);
+ imagedestroy($dst_img);
+ imagedestroy($src_img);
- return $result;
+ return $result;
}
$files = glob("emotes/*.*");
usort($files, 'strnatcasecmp');
$prev = '?';
-echo 'total emotes: ' . count($files) . '' . 'randoms: gun, shades, smug, stare, thumbsup (use !randemote)' . '';
+echo 'total emotes: ' . count($files) . '' . 'randoms: gun, shades, smug, stare, thumbsup (use !randemote)' . '';
+
+// Generate a form for the search box. This consists of a text box (which should contain the previous search term, if any),
+// a "Search" button which submits the form and reloads the page, and a "Clear" button which returns to viewing all emotes.
+echo '
';
+
+// If the search query string is set, filter $files for filenames which have substrings matching the search query, and
+// then return those thumbnails only.
+if (isset($_GET["search_query"]) && isset($_GET["form_submit"]) && $_GET["form_submit"] === "Search") {
+ $needle = filter_var($_GET["search_query"], FILTER_SANITIZE_STRING);
-echo '
';
-for ($i = 0; $i < count($files); $i++) {
+ // If the search query is an empty string, we don't want to show anything; otherwise we could accidentally show all emotes,
+ // as the empty string is a substring of all strings, and that would be slow.
+ $filtered = [];
+ if ($needle !== "") {
+ $filtered = array_values(array_filter($files, function($image) use ($needle) {
+ $fname = str_replace("`Q", "?", pathinfo($image, PATHINFO_FILENAME));
+ return strpos($fname, $needle) !== false;
+ }));
+ }
+
+ echo '