summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-08-13 07:23:23 +0300
committerAndrew Dolgov <[email protected]>2019-08-13 07:23:23 +0300
commit53aba7428d9cb4827ae727614f55524e43e74c1a (patch)
tree293912b1529f7d3d50ed85bb0521ea8ea0b1000d
parentbac38d9accde677203ccf08e120432521e947ecd (diff)
rewrite article enclosures, other minor fixes
-rw-r--r--init.php51
1 files changed, 21 insertions, 30 deletions
diff --git a/init.php b/init.php
index 3f01cf3..bea36f4 100644
--- a/init.php
+++ b/init.php
@@ -18,15 +18,6 @@ class Af_Zz_Api_Resize extends Plugin {
$this->host = $host;
$host->add_hook($host::HOOK_RENDER_ARTICLE_API, $this);
- //$host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this);
- }
-
- function hook_enclosure_entry($enc) {
- if (preg_match("/image/", $enc["content_type"])) {
- $enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"]);
- }
-
- return $enc;
}
private function make_thumbnail($input_filename, $output_filename, $dim_max_x = 600, $dim_max_y = 600, $force_stamp = false) {
@@ -55,27 +46,18 @@ class Af_Zz_Api_Resize extends Plugin {
// print "$o_file : $t_file : $o_height * $o_width -> $t_height * $t_width<br>";
$t_im = imageCreateTrueColor($t_width, $t_height);
+ $need_stamp = false;
if ($force_stamp || ($imageinfo && $imageinfo["mime"] == "image/gif")) {
$need_stamp = true;
- $need_alpha = false;
-
imageFill($t_im, 0, 0, 0xffffff);
- } else {
- $need_stamp = false;
- if ($imageinfo && $imageinfo["mime"] == "image/png") {
- $need_alpha = true;
-
- imagealphablending($t_im, false);
- imagesavealpha($t_im, true);
- }
}
imageCopyResampled($t_im, $o_im, 0, 0, 0, 0,
$t_width, $t_height, $o_width, $o_height);
if ($need_stamp) {
- $stamp = imagecreatefrompng('images/play-outline.png');
+ $stamp = imagecreatefrompng(__DIR__ . '/images/play-outline.png');
if ($stamp) {
$sx = imagesx($stamp);
@@ -124,7 +106,7 @@ class Af_Zz_Api_Resize extends Plugin {
else {
$this->make_thumbnail($local_filename, $resized_filename, $width, $width);
- if (file_exists($resized_filename) && filesize($resized_filename) > 0 && filesize($resized_filename) < filesize($local_filename))
+ if (file_exists($resized_filename) && filesize($resized_filename) > 0)
send_local_file($resized_filename);
else
send_local_file($local_filename);
@@ -139,14 +121,12 @@ class Af_Zz_Api_Resize extends Plugin {
$mimetype = mime_content_type($local_filename);
header("Content-type: $mimetype");
- /* MAKE RESIZED THUMBNAIL IF NEEDED, get local_filename, send it */
-
if (file_exists($resized_filename) && filesize($resized_filename) > 0)
send_local_file($resized_filename);
else {
$this->make_thumbnail($local_filename, $resized_filename, $width, $width);
- if (file_exists($resized_filename) && filesize($resized_filename) > 0 && filesize($resized_filename) < filesize($local_filename))
+ if (file_exists($resized_filename) && filesize($resized_filename) > 0)
send_local_file($resized_filename);
else
send_local_file($local_filename);
@@ -194,11 +174,11 @@ class Af_Zz_Api_Resize extends Plugin {
if (strpos($url, "data:") !== 0) {
$flag_filename = CACHE_DIR . "/images/" . sha1($url) . ".flag";
- @touch($flag_filename);
-
- return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_api_resize&pmethod=api_resize&url=" .
- urlencode($url) . "&width=" . $width;
+ if (touch($flag_filename)) {
+ return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_api_resize&pmethod=api_resize&url=" .
+ urlencode($url) . "&width=" . $width;
}
+ }
return $url;
}
@@ -231,7 +211,7 @@ class Af_Zz_Api_Resize extends Plugin {
foreach ($vids as $vid) {
$new_poster = $this->rewrite_url_if_needed($vid->getAttribute("poster"), $width);
- if ($new_poster != $vid->getAttribute("src")) {
+ if ($new_poster != $vid->getAttribute("poster")) {
$vid->setAttribute("poster", $new_poster);
$need_saving = true;
@@ -251,7 +231,18 @@ class Af_Zz_Api_Resize extends Plugin {
}
}
- if ($need_saving) $params["headline"]["content"] = $doc->saveHTML();
+ if (is_array($params["headline"]["attachments"])) {
+ $tmp =& $params["headline"]["attachments"];
+
+ for ($i = 0; $i < count($tmp); $i++) {
+ if (preg_match("/image/", $tmp[$i]["content_type"])) {
+ $tmp[$i]["content_url"] = $this->rewrite_url_if_needed($tmp[$i]["content_url"], $width);
+ }
+ }
+ }
+
+ if ($need_saving)
+ $params["headline"]["content"] = $doc->saveHTML();
return $params["headline"];
}