3
3
* Plugin for http://postimage.org.
4
4
*
5
5
* @release Jun 19, 2014
6
- * @update May 29 , 2015
6
+ * @update Jun 12 , 2015
7
7
*/
8
8
class ChipVN_ImageUploader_Plugins_Postimage extends ChipVN_ImageUploader_Plugins_Abstract
9
9
{
@@ -19,7 +19,7 @@ class ChipVN_ImageUploader_Plugins_Postimage extends ChipVN_ImageUploader_Plugin
19
19
*/
20
20
private function getUrlEnpoint ()
21
21
{
22
- return $ this ->getCache ()-> has ( self :: SESSION_LOGIN )
22
+ return $ this ->useAccount
23
23
? self ::ACCOUNT_UPLOAD_ENPOINT
24
24
: self ::FREE_UPLOAD_ENPOINT ;
25
25
}
@@ -31,18 +31,15 @@ protected function doLogin()
31
31
{
32
32
if (!$ this ->getCache ()->has (self ::SESSION_LOGIN )) {
33
33
$ this ->resetHttpClient ()
34
+ ->setFollowRedirect (true , 2 )
34
35
->setParameters (array (
35
36
'login ' => $ this ->username ,
36
37
'password ' => $ this ->password ,
37
- 'submit ' => '' ,
38
38
))
39
39
->execute ('http://postimage.org/profile.php ' , 'POST ' );
40
40
41
41
$ 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 ' ) {
46
43
$ this ->getCache ()->set (self ::SESSION_LOGIN , $ this ->client ->getResponseArrayCookies ());
47
44
} else {
48
45
$ this ->getCache ()->delete (self ::SESSION_LOGIN );
@@ -59,50 +56,34 @@ protected function doLogin()
59
56
protected function doUpload ()
60
57
{
61
58
$ endpoint = $ this ->getUrlEnpoint ();
62
- $ time = time () * 1000 + mt_rand (1 , 999 );
63
59
$ maxFileSize = 16777216 ;
60
+ $ galleryId = '' ;
64
61
65
62
$ this ->resetHttpClient ();
66
63
if ($ this ->useAccount ) {
67
64
$ 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
+ }
68
70
}
71
+
69
72
$ this ->client
70
73
->setSubmitMultipart ()
71
74
->setReferer ($ endpoint )
72
75
->setParameters (array (
73
76
'upload ' => '@ ' .$ this ->file ,
74
77
'um ' => 'computer ' ,
75
- 'gallery_id ' => '' ,
76
78
'forumurl ' => $ endpoint ,
79
+ 'gallery_id ' => $ galleryId ,
77
80
'upload_error ' => '' ,
78
81
'MAX_FILE_SIZE ' => $ maxFileSize ,
79
82
))
80
83
->setParameters ($ this ->getGeneralParameters ())
81
84
->execute ($ endpoint );
82
85
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 ' );
106
87
107
88
return $ this ->getImageFromResult ($ location );
108
89
}
@@ -139,23 +120,17 @@ protected function doTransload()
139
120
*/
140
121
protected function getGeneralParameters ()
141
122
{
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
-
145
123
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 ' => '' ,
159
134
);
160
135
}
161
136
0 commit comments