summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-02-23 22:04:00 +0300
committerAndrew Dolgov <[email protected]>2022-02-23 22:04:00 +0300
commit46cdeea9b70b04e3b96ac8be44a98a24f7311e2f (patch)
tree7fa6e47b2d0074f3d2df7f92f2a5116b89c16ba2
parent410df099846bea3329027ad0389405fafff6cda5 (diff)
* ignore magnet: scheme
* rewrite usages of some deprecated functions
-rw-r--r--init.php13
1 files changed, 8 insertions, 5 deletions
diff --git a/init.php b/init.php
index ac61cb8..768e142 100644
--- a/init.php
+++ b/init.php
@@ -3,6 +3,7 @@ class Api_Resize_Media extends Plugin {
const MAX_WIDTH = 1024;
const DEFAULT_QUALITY = 80;
+ const IGNORE_SCHEMES = [ "magnet", "data" ];
/** @var PluginHost $host */
private $host;
@@ -120,7 +121,7 @@ class Api_Resize_Media extends Plugin {
Debug::log("[api_resize_media] checking URL $url (force_stamp=$force_stamp)...",
Debug::LOG_VERBOSE);
- $url = validate_url($url);
+ $url = UrlHelper::validate($url);
if (!$url) {
Debug::log("[api_resize_media] URL failed validation, skipping.", Debug::LOG_VERBOSE);
@@ -139,7 +140,7 @@ class Api_Resize_Media extends Plugin {
$this->cache->touch($local_filename_flag);
if (!$this->cache->exists($local_filename)) {
- $data = fetch_file_contents(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
+ $data = UrlHelper::fetch(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
if ($data) {
if (!$this->cache->put($local_filename, $data)) {
@@ -179,7 +180,7 @@ class Api_Resize_Media extends Plugin {
public function api_resize() : void {
- $url = validate_url($_REQUEST["url"]);
+ $url = UrlHelper::validate($_REQUEST["url"]);
$width = (int) $_REQUEST["width"];
$force_stamp = sql_bool_to_bool($_REQUEST["force_stamp"]);
@@ -222,7 +223,7 @@ class Api_Resize_Media extends Plugin {
}
} else {
- $data = fetch_file_contents(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
+ $data = UrlHelper::fetch(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
if ($data) {
if ($this->cache->put($local_filename, $data)) {
@@ -280,7 +281,9 @@ class Api_Resize_Media extends Plugin {
}
private function rewrite_url_if_needed(string $url, int $width, bool $force_stamp = false) : string {
- if (strpos($url, "data:") !== 0 && $width > 0) {
+ $scheme = parse_url($url, PHP_URL_SCHEME) ?? "";
+
+ if ($width > 0 && !in_array($scheme, self::IGNORE_SCHEMES)) {
if ($width > self::MAX_WIDTH)
$width = self::MAX_WIDTH;