Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 43b6ee4

Browse files
committed
merge PR #6
closes #6
1 parent f6da43f commit 43b6ee4

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

files/lib/page/ImageProxyPage.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace wcf\page;
3+
use wcf\system\event\EventHandler;
34
use wcf\util\Signer;
45

56
/**
@@ -108,6 +109,7 @@ public function store() {
108109
if (@file_put_contents($this->getLocalLink(), $imagestring) === false) {
109110
throw new \wcf\system\exception\SystemException('cannot store proxyimage');
110111
}
112+
EventHandler::getInstance()->fireAction($this, 'imageStored');
111113
}
112114

113115
/**
@@ -179,4 +181,4 @@ public function show() {
179181
$reader->send();
180182
exit;
181183
}
182-
}
184+
}

files/lib/system/event/listener/ProxyListener.class.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,76 @@
11
<?php
2-
namespace wcf\system\event\listener;
3-
use wcf\util\Signer;
2+
namespace wcf\system\event\listener;
3+
use wcf\util\Signer;
44

55
/**
6-
* Replace images with proxy images.
7-
*
6+
* Replace images with proxy images.
7+
*
88
* @author Joshua Rüsweg
99
* @copyright 2015 Joshua Rüsweg
1010
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1111
* @package be.bastelstu.josh.imageproxy
1212
*/
1313
class ProxyListener implements \wcf\system\event\listener\IParameterizedEventListener {
14-
14+
1515
/**
1616
* @see \wcf\system\event\IEventListener::execute()
1717
*/
1818
public function execute($eventObj, $className, $eventName, array &$parameters) {
19-
if (!MODULE_PROXY) return;
20-
19+
if (!MODULE_PROXY) return;
20+
2121
if (!$eventObj->message || \wcf\data\bbcode\BBCodeCache::getInstance()->getBBCodeByTag('img') === null) {
2222
return;
2323
}
24-
24+
2525
// match [img]link[/img]
26-
preg_match_all('~\[img\]([^\]]*)\[\/img\]~i', $eventObj->message, $matches, PREG_SET_ORDER);
27-
26+
preg_match_all('~\[img\](?P<url>[^\]]*)\[\/img\]~i', $eventObj->message, $matches, PREG_SET_ORDER);
27+
2828
// match all [img=link,(none|left|right|center),[0-9]+]
29-
preg_match_all("~\[img=\'([^\]]*)\',(none|left|right|center),([0-9]+)\](\[\/img\])?~i", $eventObj->message, $matches2, PREG_SET_ORDER);
30-
29+
preg_match_all("~\[img=\'(?P<url>[^\]]*)\',(?P<orientation>none|left|right|center),(?P<size>[0-9]+)\](\[\/img\])?~i", $eventObj->message, $matches2, PREG_SET_ORDER);
30+
3131
// match all [img=link,(none|left|right|center)]
32-
preg_match_all("~\[img=\'([^\]]*)\',(none|left|right|center)\](\[\/img\])?~i", $eventObj->message, $matches3, PREG_SET_ORDER);
32+
preg_match_all("~\[img=\'(?P<url>[^\]]*)\',(?P<orientation>none|left|right|center)\](\[\/img\])?~i", $eventObj->message, $matches3, PREG_SET_ORDER);
3333

3434
// match [img=link]
35-
preg_match_all("~\[img=\'?([^\,\]]*)\'?\](\[\/img\])?~i", $eventObj->message, $matches4, PREG_SET_ORDER);
35+
preg_match_all("~\[img=\'?(?P<url>[^\,\]]*)\'?\](\[\/img\])?~i", $eventObj->message, $matches4, PREG_SET_ORDER);
3636

3737
$matches = array_merge($matches, $matches2, $matches3, $matches4);
3838

3939
foreach ($matches as $match) {
4040
if (function_exists('gethostbyname')) {
41-
// is localhost?
42-
$url = parse_url($match[1]);
41+
// is localhost?
42+
$url = parse_url($match['url']);
4343

4444
if ($url === false) {
4545
// url isn't a url
4646
continue;
4747
}
4848

49-
$host = @gethostbyname($url['host']);
50-
$localhost = false;
49+
$host = @gethostbyname($url['host']);
5150

5251
if (\wcf\system\Regex::compile('127.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}')->match($host)) {
53-
$localhost = true;
52+
continue;
5453
}
5554

5655
if (\wcf\system\Regex::compile('10.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}')->match($host)) {
57-
$localhost = true;
56+
continue;
5857
}
5958

6059
if (\wcf\system\Regex::compile('192.168.[0-9]{1,3}.[0-9]{1,3}')->match($host)) {
61-
$localhost = true;
60+
continue;
6261
}
6362

6463
if (\wcf\system\Regex::compile('172.16.[0-9]{1,3}.[0-9]{1,3}')->match($host)) {
65-
$localhost = true;
64+
continue;
6665
}
6766

68-
if (!$localhost && !\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match[1])) {
69-
$eventObj->message = \wcf\util\StringUtil::replaceIgnoreCase($match[0], '[img=\''. $this->buildImageURL($match[1]) .'\''. ((isset($match[2]) && $match[2] != '[/img]') ? ','.$match[2].((isset($match[3]) && $match[3] != '[/img]') ? ','.$match[3] : '') : '') .'][/img]', $eventObj->message);
67+
if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match['url'])) {
68+
$eventObj->message = \wcf\util\StringUtil::replaceIgnoreCase($match[0], '[img=\''. $this->buildImageURL($match['url']) .'\''. ((isset($match['orientation'])) ? ','.$match['orientation'].((isset($match['size'])) ? ','.$match['size'] : '') : '') .'][/img]', $eventObj->message);
7069
}
7170
}
7271
}
7372
}
74-
73+
7574
public static function buildImageURL($url) {
7675
return \wcf\system\request\LinkHandler::getInstance()->getLink('ImageProxy', array('image' => Signer::createSignedString($url)));
7776
}

0 commit comments

Comments
 (0)