diff --git a/core/util.inc.php b/core/util.inc.php index 105961da..287e0f71 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -950,21 +950,19 @@ function transload($url, $mfile) { } if($config->get_string("transload_engine") === "fopen") { - $fp = @fopen($url, "r"); - if(!$fp) { + $fp_in = @fopen($url, "r"); + $fp_out = fopen($mfile, "w"); + if(!$fp_in || !$fp_out) { return false; } - $data = ""; $length = 0; - while(!feof($fp) && $length <= $config->get_int('upload_size')) { - $data .= fread($fp, 8192); - $length = strlen($data); + while(!feof($fp_in) && $length <= $config->get_int('upload_size')) { + $data = fread($fp_in, 8192); + $length += strlen($data); + fwrite($fp_out, $data); } - fclose($fp); - - $fp = fopen($mfile, "w"); - fwrite($fp, $data); - fclose($fp); + fclose($fp_in); + fclose($fp_out); $headers = http_parse_headers(implode("\n", $http_response_header)); diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php index cf356552..3bbad680 100644 --- a/ext/danbooru_api/main.php +++ b/ext/danbooru_api/main.php @@ -321,44 +321,15 @@ class DanbooruApi extends Extension { $source = null; } } elseif (isset($_REQUEST['source']) || isset($_REQUEST['post']['source'])) { // A url was provided - $url = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source']; - $source = $url; - $tmp_filename = tempnam("/tmp", "shimmie_transload"); - - // Are we using fopen wrappers or curl? - if ($config->get_string("transload_engine") == "fopen") { - $fp = fopen($url, "r"); - if (!$fp) { - $page->set_code(409); - $page->add_http_header("X-Danbooru-Errors: fopen read error"); - } - - $data = ""; - $length = 0; - while (!feof($fp) && $length <= $config->get_int('upload_size')) { - $data .= fread($fp, 8192); - $length = strlen($data); - } - fclose($fp); - - $fp = fopen($tmp_filename, "w"); - fwrite($fp, $data); - fclose($fp); + $source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source']; + $file = tempnam("/tmp", "shimmie_transload"); + $ok = transload($source, $file); + if (!$ok) { + $page->set_code(409); + $page->add_http_header("X-Danbooru-Errors: fopen read error"); + return; } - - if ($config->get_string("transload_engine") == "curl") { - $ch = curl_init($url); - $fp = fopen($tmp_filename, "w"); - - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_HEADER, 0); - - curl_exec($ch); - curl_close($ch); - fclose($fp); - } - $file = $tmp_filename; - $filename = basename($url); + $filename = basename($source); } else { // Nothing was specified at all $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: no input files"); @@ -367,8 +338,9 @@ class DanbooruApi extends Extension { // Get tags out of url $posttags = Tag::explode(isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']); - $hash = md5_file($file); + // Was an md5 supplied? Does it match the file hash? + $hash = md5_file($file); if (isset($_REQUEST['md5']) && strtolower($_REQUEST['md5']) != $hash) { $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: md5 mismatch"); diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 8941a528..ee465965 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -23,7 +23,7 @@ class ExtensionInfo { var $description, $documentation, $version, $visibility; var $enabled; - function __construct($main) { + public function __construct($main) { $matches = array(); $lines = file($main); $number_of_lines = count($lines); @@ -156,7 +156,7 @@ class ExtManager extends Extension { /** * @param bool $all - * @return array + * @return ExtensionInfo[] */ private function get_extensions(/*bool*/ $all) { $extensions = array(); diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 0cfca51b..8e6af251 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -204,7 +204,7 @@ class Favorites extends Extension { /** * @param Image $image - * @return array + * @return string[] */ private function list_persons_who_have_favorited(Image $image) { global $database; diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index ba2fd59c..1fe56ca6 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -44,7 +44,7 @@ class ArchiveFileHandler extends Extension { } /** - * @param $ext + * @param string $ext * @return bool */ private function supported_ext($ext) { diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php index 58d93a3f..9b8eda6c 100644 --- a/ext/handle_flash/main.php +++ b/ext/handle_flash/main.php @@ -50,7 +50,7 @@ class FlashFileHandler extends DataHandlerExtension { } /** - * @param $file + * @param string $file * @return bool */ protected function check_contents(/*string*/ $file) { diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index 185bd7f3..c16fb64e 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -50,7 +50,7 @@ class IcoFileHandler extends Extension { } /** - * @param $ext + * @param string $ext * @return bool */ private function supported_ext($ext) { @@ -59,8 +59,8 @@ class IcoFileHandler extends Extension { } /** - * @param $filename - * @param $metadata + * @param string $filename + * @param mixed[] $metadata * @return Image */ private function create_image_from_data($filename, $metadata) { diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index 691fc644..069107b5 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -26,7 +26,7 @@ class MP3FileHandler extends DataHandlerExtension { /** * @param string $filename - * @param array $metadata + * @param mixed[] $metadata * @return Image|null */ protected function create_image_from_data($filename, $metadata) { diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index bacc8804..e216568a 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -67,7 +67,7 @@ class PixelFileHandler extends DataHandlerExtension { } /** - * @param $hash + * @param string $hash * @return bool */ protected function create_thumb_force(/*string*/ $hash) { @@ -91,9 +91,6 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } - /** - * @param ImageAdminBlockBuildingEvent $event - */ public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { $event->add_part("