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 '
Search:
'; + +// 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++) { + for ($i = 0; $i < count($files); $i++) { $image = $files[$i]; - $next = strtoupper($image[7]); - $fname = str_replace("`Q", "?", pathinfo($image, PATHINFO_FILENAME)); - /*$imagesmall = "emotes/resized/" . pathinfo($image, PATHINFO_BASENAME); - if (pathinfo($image, PATHINFO_EXTENSION) == "jpg" || pathinfo($image, PATHINFO_EXTENSION) == "png"){ - if (!file_exists($imagesmall)){ - createThumbnail(pathinfo($image, PATHINFO_BASENAME), 300, 300, "emotes", "emotes/resized/"); - } + $next = strtoupper($image[7]); + $fname = str_replace("`Q", "?", pathinfo($image, PATHINFO_FILENAME)); + /*$imagesmall = "emotes/resized/" . pathinfo($image, PATHINFO_BASENAME); + if (pathinfo($image, PATHINFO_EXTENSION) == "jpg" || pathinfo($image, PATHINFO_EXTENSION) == "png"){ + if (!file_exists($imagesmall)){ + createThumbnail(pathinfo($image, PATHINFO_BASENAME), 300, 300, "emotes", "emotes/resized/"); + } + } + else{ + $imagesmall = $image; + }*/ + $hidden = substr($fname, -1) === "~"; + + if (is_numeric($next)){ + $next = "0-9"; } - else{ - $imagesmall = $image; - }*/ - $hidden = substr($fname, -1) === "~"; - - if (is_numeric($next)){ - $next = "0-9"; - } - if ($next != $prev){ - echo '

' . $next . '

'; - } - if (!$hidden){ - echo ''; - } - else { - echo ''; - } - $prev = $next; + if ($next != $prev){ + echo '

' . $next . '

'; + } + if (!$hidden){ + echo ''; + } + else { + echo ''; + } + $prev = $next; + } } ?>