forked from evandrofisico/roundcube-imageproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageproxy.php
More file actions
65 lines (59 loc) · 1.74 KB
/
imageproxy.php
File metadata and controls
65 lines (59 loc) · 1.74 KB
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
<?php
/**
* Image Proxy
*
* Plugin to enable the use of the go imageproxy inside roundcube.
* It by default only supports the signed request format.
*
* @version @package_version@
* @license GNU GPLv3+
* @author evandrofisico
* @website http://roundcube.net
*/
class imageproxy extends rcube_plugin
{
public $task = 'mail';
/**
* Plugin initilization.
*/
function init()
{
$rcube = rcube::get_instance();
$this->add_hook('message_part_after', array($this, 'message_part_after'));
}
function message_part_after($args)
{
if ($args['type'] == 'html') {
$this->load_config();
$rcube = rcube::get_instance();
if (!$rcube->config->get('imageproxy_url', false)) {
return $args;
}
//Check for http OR https images
preg_match_all('@src="(http|https)([^"]+)"@', $args['body'], $imagesUrl);
$srcurl = array_pop($imagesUrl);
foreach($srcurl as $imgurl){
if(strpos($imgurl, "s://") === 0)
{
$newpath = $this->image_proxy_path("https".$imgurl);
error_log($newpath);
$args["body"] = str_replace("https".$imgurl,$newpath,$args["body"]);
}
else
{
$newpath = $this->image_proxy_path("http".$imgurl);
error_log($newpath);
$args["body"] = str_replace("http".$imgurl,$newpath,$args["body"]);
}
}
}
return $args;
}
function image_proxy_path($url){
$rcube = rcube::get_instance();
$proxypath = $rcube->config->get('imageproxy_url');
$signature = $rcube->config->get('imageproxy_signature');
$imghs = str_replace(array('+','/'),array('-','_'),base64_encode(hash_hmac("sha256",html_entity_decode($url),$signature,true)));
return $proxypath."/s".$imghs."/".$url;
}
}