-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimageproxy.php
More file actions
56 lines (49 loc) · 1.5 KB
/
imageproxy.php
File metadata and controls
56 lines (49 loc) · 1.5 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
<?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;
}
preg_match_all('@src="http([^"]+)"@', $args['body'], $imagesUrl);
$srcurl = array_unique(array_pop($imagesUrl));
foreach($srcurl as $imgurl){
$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;
}
}