-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.php
101 lines (81 loc) · 2.19 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* If any img src of an image is an http link, just proxy it
*
* This solves HTTPS mixed content problems when TT-RSS runs with HTTPS only
*
* heavily inspired by https://github.com/Alekc/af_refspoof
* heavily inspired by https://tt-rss.org/gitlab/fox/tt-rss/blob/master/plugins/af_zz_imgsetsizes/init.php
*/
class af_https_proxy_assets extends Plugin
{
protected $host;
function about()
{
return array(
'1.0',
'replace image links by adding an proxy before',
'campino2k',
);
}
function flags()
{
return array('needs_curl' => true );
}
function init($host)
{
require_once ('PhCURL.php');
$this->host = $host;
#$this->dbh = Db::get();
$host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
}
function hook_render_article_cdm($article)
{
$doc = new DOMDocument();
$doc->loadHTML($charset_hack . $article["content"]);
$found = false;
if ($doc) {
$xpath = new DOMXpath($doc);
$images = $xpath->query('(//img[@src])');
foreach ($images as $img) {
$src = $img->getAttribute("src");
// only replace path if it's a http path
if( strpos( $src, 'http:' ) === 0 ) {
$src = substr( $src, 7 );
//$src = rawurlencode( $src );
$proxy_url ="/backend.php?op=pluginhandler&method=proxy&plugin=af_https_proxy_assets&url={$src}";
$img->setAttribute('src', $proxy_url);
}
//$srcset = $img->getAttribute("srcset");
$srcset = str_replace(
'http://',
'/backend.php?op=pluginhandler&method=proxy&plugin=af_https_proxy_assets&url=',
$srcset
);
$img->setAttribute('srcset', $srcset );
}
$article["content"] = $doc->saveHTML();
}
return $article;
}
function proxy()
{
//$target_url = $_REQUEST['url'];
$target_url = str_replace(' ', '%20', urldecode( $_REQUEST['url'] ));
$client = new PhCURL('http://' . $target_url);
$client->loadCommonSettings();
$client->enableBinaryTransfer(true);
$client->enableAutoReferer(true);
$client->enableHeaderInOutput(false);
$client->setUserAgent();
$client->GET();
ob_end_clean();
header("Content-Type: ". $client->getContentType());
echo $client->getData();
exit(1);
}
function api_version()
{
return 2;
}
}