Skip to content

Commit b8df0c1

Browse files
author
ptcong
committed
fix not found page url in some cases
1 parent 7db8014 commit b8df0c1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Plugins/Postimage.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin for http://postimage.org
44
*
55
* @release Jun 19, 2014
6-
* @lastupdate Jan 20, 2015
6+
* @lastupdate Mar 207, 2015
77
*/
88
class ChipVN_ImageUploader_Plugins_Postimage extends ChipVN_ImageUploader_Plugins_Abstract
99
{
@@ -164,9 +164,7 @@ protected function getGeneralParameters()
164164
*/
165165
private function getImageFromResult($url)
166166
{
167-
$imageId = $this->getMatch('#^http://post(?:img|image)\.org/\w+/([^/]+)/.*?#', $url);
168-
169-
if (! $imageId) {
167+
if (!$this->getMatch('#^http://post(?:img|image)\.org/\w+/([^/]+)/.*?#', $url)) {
170168
$this->throwException('%s: Image ID not found.', __METHOD__);
171169
}
172170

@@ -176,10 +174,19 @@ private function getImageFromResult($url)
176174

177175
$imageUrl = $this->getMatch('#id="code_2".*?>(https?://\w+\.postimg\.org/\w+/\w+\.\w+)#i', $this->client);
178176

177+
if (!$imageUrl
178+
&& $url = $this->getMatch('#id="code_1".*?>(http.*?)<#i', $this->client)
179+
) {
180+
// try to fetch direct link from image page
181+
$this->resetHttpClient()
182+
->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36')
183+
->execute($url);
184+
185+
$imageUrl = $this->getMatch('#rel="image_src".*?href="([^"]+)"#i', $this->client);
186+
}
179187
if (!$imageUrl) {
180188
$this->throwException('%s: Image URL not found.', __METHOD__);
181189
}
182-
183190
return $imageUrl;
184191
}
185192
}

0 commit comments

Comments
 (0)