Skip to content

Commit 1fe53ae

Browse files
author
ptcong
committed
update Postimage
1 parent feae19b commit 1fe53ae

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

Plugins/Postimage.php

Lines changed: 23 additions & 48 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-
* @update May 29, 2015
6+
* @update Jun 12, 2015
77
*/
88
class ChipVN_ImageUploader_Plugins_Postimage extends ChipVN_ImageUploader_Plugins_Abstract
99
{
@@ -19,7 +19,7 @@ class ChipVN_ImageUploader_Plugins_Postimage extends ChipVN_ImageUploader_Plugin
1919
*/
2020
private function getUrlEnpoint()
2121
{
22-
return $this->getCache()->has(self::SESSION_LOGIN)
22+
return $this->useAccount
2323
? self::ACCOUNT_UPLOAD_ENPOINT
2424
: self::FREE_UPLOAD_ENPOINT;
2525
}
@@ -31,18 +31,15 @@ protected function doLogin()
3131
{
3232
if (!$this->getCache()->has(self::SESSION_LOGIN)) {
3333
$this->resetHttpClient()
34+
->setFollowRedirect(true, 2)
3435
->setParameters(array(
3536
'login' => $this->username,
3637
'password' => $this->password,
37-
'submit' => '',
3838
))
3939
->execute('http://postimage.org/profile.php', 'POST');
4040

4141
$this->checkHttpClientErrors(__METHOD__);
42-
43-
if ($this->client->getResponseStatus() == 302
44-
&& $this->client->getResponseArrayCookies('userlogin') != 'deleted'
45-
) {
42+
if (($c = $this->client->getResponseArrayCookies('userlogin')) && $c['value'] != 'deleted') {
4643
$this->getCache()->set(self::SESSION_LOGIN, $this->client->getResponseArrayCookies());
4744
} else {
4845
$this->getCache()->delete(self::SESSION_LOGIN);
@@ -59,50 +56,34 @@ protected function doLogin()
5956
protected function doUpload()
6057
{
6158
$endpoint = $this->getUrlEnpoint();
62-
$time = time() * 1000 + mt_rand(1, 999);
6359
$maxFileSize = 16777216;
60+
$galleryId = '';
6461

6562
$this->resetHttpClient();
6663
if ($this->useAccount) {
6764
$this->client->setCookies($this->getCache()->get(self::SESSION_LOGIN));
65+
66+
$this->client->execute($this->getUrlEnpoint());
67+
if (preg_match('#<select.*?name="gallery".*?<option value=[\'"]([^\'"]+)[\'"]#is', $this->client, $match)) {
68+
$galleryId = $match[1];
69+
}
6870
}
71+
6972
$this->client
7073
->setSubmitMultipart()
7174
->setReferer($endpoint)
7275
->setParameters(array(
7376
'upload' => '@'.$this->file,
7477
'um' => 'computer',
75-
'gallery_id' => '',
7678
'forumurl' => $endpoint,
79+
'gallery_id' => $galleryId,
7780
'upload_error' => '',
7881
'MAX_FILE_SIZE' => $maxFileSize,
7982
))
8083
->setParameters($this->getGeneralParameters())
8184
->execute($endpoint);
8285

83-
if (!$location = $this->client->getResponseHeaders('location')) {
84-
$galleryId = (string) $this->client;
85-
$this->resetHttpClient();
86-
if ($this->useAccount) {
87-
$this->client->setCookies($this->getCache()->get(self::SESSION_LOGIN));
88-
}
89-
$this->client
90-
->setReferer($endpoint)
91-
->setParameters(array(
92-
'upload[]' => '@'.$this->file,
93-
'session_upload' => $time,
94-
'um' => 'computer',
95-
'forumurl' => $endpoint,
96-
'gallery_id' => $galleryId,
97-
'upload_error' => '',
98-
'MAX_FILE_SIZE' => $maxFileSize
99-
))
100-
->setParameters($this->getGeneralParameters())
101-
->execute($endpoint, 'POST');
102-
$this->checkHttpClientErrors(__METHOD__);
103-
104-
$location = $this->client->getResponseHeaders('location');
105-
}
86+
$location = $this->client->getResponseHeaders('location');
10687

10788
return $this->getImageFromResult($location);
10889
}
@@ -139,23 +120,17 @@ protected function doTransload()
139120
*/
140121
protected function getGeneralParameters()
141122
{
142-
$time = time() * 1000 + mt_rand(0, 999);
143-
$ui = '24__1440__900__true__?__?__'.date('d/m/Y, H:i:s A', $time).'__'.$this->client->getUserAgent().'__';
144-
145123
return array(
146-
'mode' => 'local',
147-
'areaid' => '',
148-
'hash' => '',
149-
'code' => '',
150-
'content' => '',
151-
'tpl' => '.',
152-
'ver' => '',
153-
'addform' => '',
154-
'mforum' => '',
155-
'submit' => 'Upload It!',
156-
'ui' => $ui,
157-
'adult' => 'no',
158-
'optsize' => '0',
124+
'mode' => 'local',
125+
'areaid' => '',
126+
'hash' => '',
127+
'code' => '',
128+
'content' => '',
129+
'tpl' => '.',
130+
'ver' => '',
131+
'addform' => '',
132+
'mforum' => '',
133+
'session_upload' => '',
159134
);
160135
}
161136

0 commit comments

Comments
 (0)