diff --git a/ajax/showcomic.php b/ajax/showcomic.php index 26aea1a..fcb4822 100644 --- a/ajax/showcomic.php +++ b/ajax/showcomic.php @@ -69,7 +69,7 @@ if ( $extracted ) { //$myext = substr($imgname, -3); if ( ! isset(pathinfo($imgname)['extension']) ) continue; $myext = strtolower(pathinfo($imgname)['extension']); - if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + if ( in_array($myext, VALIDIMAGETYPES) ) { $imgname = str_replace("#", "", $imgname); $imgcontents = $zip->getFromIndex($i); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); @@ -84,7 +84,7 @@ if ( $extracted ) { $entry->extract(false, $comicoutputfull . $outfile); if ( ! isset(pathinfo($outfile)['extension']) ) continue; $myext = strtolower(pathinfo($outfile)['extension']); - if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + if ( in_array($myext, VALIDIMAGETYPES) ) { $files[] = basename($outfile); } } diff --git a/config-dist.php b/config-dist.php index 6f479d4..3bea0fd 100644 --- a/config-dist.php +++ b/config-dist.php @@ -43,3 +43,4 @@ define('DBNAME', 'comics'); define('SORTBYNAME', "Name"); define('SORTBYDATE', "Date"); define('SORTBYREAD', "Read"); +define('VALIDIMAGETYPES', array("jpg", "jpeg", "gif", "png", "webp")); diff --git a/functions.php b/functions.php index 121fc87..1f45cc1 100644 --- a/functions.php +++ b/functions.php @@ -14,6 +14,11 @@ function getAdultComics() { return $adultcomics; } +function safeFileName($file = "") { + $to_remove = array("<", ">", "#", "\"", "/", "\\", "*", "?", "|"); + return str_replace($to_remove, '', $file); +} + function makeThumb($item = "") { if ( $item == "" ) { return false; } $prefix = (substr(getcwd(), -4) == "ajax") ? "../" : ""; @@ -57,11 +62,7 @@ function makeThumb($item = "") { $parts = pathinfo($imgname); if ( isset($parts['extension']) ) { $imgext = strtolower($parts['extension']); - if ( (strcmp($lowest, $imgname) > 0) - && ((strcasecmp($imgext, "jpg") == 0) - || (strcasecmp($imgext, "jpeg") == 0) - || (strcasecmp($imgext, "png") == 0) - || (strcasecmp($imgext, "webp") == 0)) ) { + if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) { $lowest = $imgname; $imgdata = $zip->getFromIndex($i); } @@ -81,11 +82,7 @@ function makeThumb($item = "") { $parts = pathinfo($imgname); if ( isset($parts['extension']) ) { $imgext = strtolower($parts['extension']); - if ( (strcmp($lowest, $imgname) > 0) - && ((strcasecmp($imgext, "jpg") == 0) - || (strcasecmp($imgext, "jpeg") == 0) - || (strcasecmp($imgext, "png") == 0) - || (strcasecmp($imgext, "webp") == 0)) ) { + if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) { $lowest = $imgname; $didwrite = $entry->extract(false, $outfile); if ( !$didwrite ) { return false; }