]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_zz_imgproxy/init.php
2 class Af_Zz_ImgProxy
extends Plugin
{
7 "Load insecure images via built-in proxy (no caching)",
12 return array("needs_curl" => true);
15 function init($host) {
18 $host->add_hook($host::HOOK_RENDER_ARTICLE
, $this);
19 $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM
, $this);
20 $host->add_hook($host::HOOK_RENDER_ARTICLE_API
, $this);
23 function hook_render_article($article) {
24 return $this->hook_render_article_cdm($article);
27 function hook_render_article_api($headline) {
28 return $this->hook_render_article_cdm($headline["headline"], true);
31 /*public function vidproxy() {
32 $url = $_REQUEST["url"];
34 if (preg_match("/\.(mp4|webm|gifv)/", $url, $matches)) {
38 if ($type == "gifv") {
40 $embed_url = str_replace(".gifv", ".mp4", $embed_url);
43 header("Content-type: text/html");
45 $embed_url = htmlspecialchars("backend.php?op=pluginhandler&plugin=af_zz_imgproxy&method=imgproxy&url=" .
46 urlencode($embed_url));
48 print "<video class=\"\" autoplay=\"true\" controls=\"true\" loop=\"true\">";
49 print "<source src=\"$embed_url\" type=\"video/$type\">";
52 header("Location: " . htmlspecialchars($url));
56 public function imgproxy() {
57 $url = rewrite_relative_url(SELF_URL_PATH
, $_REQUEST["url"]);
59 if (function_exists("getimagesize")) {
60 $is = @getimagesize
($url);
61 header("Content-type: " . $is["mime"]);
64 print fetch_file_contents(array("url" => $url));
67 function rewrite_url_if_needed($url) {
68 $scheme = parse_url($url, PHP_URL_SCHEME
);
70 if ($scheme != 'https' && $scheme != "") {
71 $url = "backend.php?op=pluginhandler&plugin=af_zz_imgproxy&method=imgproxy&url=" .
72 htmlspecialchars($url);
79 function hook_render_article_cdm($article, $api_mode = false) {
83 $doc = new DOMDocument();
84 if (@$doc->loadHTML($article["content"])) {
85 $xpath = new DOMXPath($doc);
86 $imgs = $xpath->query("//img[@src]");
88 foreach ($imgs as $img) {
89 $new_src = $this->rewrite_url_if_needed($img->getAttribute("src"));
91 if ($new_src != $img->getAttribute("src")) {
92 $img->setAttribute("src", $new_src);
98 $vids = $xpath->query("//video");
100 foreach ($vids as $vid) {
101 if ($vid->hasAttribute("poster")) {
102 $new_src = $this->rewrite_url_if_needed($vid->getAttribute("poster"));
104 if ($new_src != $vid->getAttribute("poster")) {
105 $vid->setAttribute("poster", $new_src);
111 $vsrcs = $xpath->query("source", $vid);
113 foreach ($vsrcs as $vsrc) {
114 $new_src = $this->rewrite_url_if_needed($vsrc->getAttribute("src"));
116 if ($new_src != $vsrc->getAttribute("src")) {
117 $vid->setAttribute("src", $new_src);
125 if ($need_saving) $article["content"] = $doc->saveXML();
130 function api_version() {