Skip to content

Commit dd45d59

Browse files
author
Phan Thanh Cong
committed
update 5.2.13
1 parent e776b36 commit dd45d59

File tree

8 files changed

+267
-261
lines changed

8 files changed

+267
-261
lines changed

Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class ChipVN_ImageUploader_Manager
1313
{
14-
const VERSION = '5.2.12';
14+
const VERSION = '5.2.13'; // Jan 19, 2015
1515

1616
/**
1717
* Create a plugin for uploading.

Plugins/Abstract.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function setCache($cache = '', array $options = array())
106106
$this->cache = $cache;
107107
} elseif (is_string($cache)) {
108108
$this->cache = ChipVN_Cache_Manager::make($cache, $options + array(
109-
'group' => $this->getIdentifier()
109+
'group' => $this->getIdentifier(),
110110
));
111111
}
112112

@@ -140,12 +140,14 @@ public function useCurl($useCurl)
140140
/**
141141
* Reset request.
142142
*
143-
* @return void
143+
* @return ChipVN_Http_Client
144144
*/
145145
protected function resetHttpClient()
146146
{
147147
$this->client->reset();
148148
$this->client->useCurl($this->useCurl);
149+
150+
return $this->client;
149151
}
150152

151153
/**
@@ -223,7 +225,7 @@ final public function transload($url)
223225
*/
224226
final public function getIdentifier()
225227
{
226-
return md5($this->getName() . $this->username . $this->password);
228+
return md5($this->getName().$this->username.$this->password);
227229
}
228230

229231
/**

Plugins/Flickr.php

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ protected function requestToken($callback)
126126
{
127127
$url = $this->getRequestTokenUrl($callback);
128128

129-
if(headers_sent()) {
130-
echo '<meta http-equiv="refresh" content="0; url='. $url . '"><script type="text/javascript">window.location.href = "' . $url . '";</script>';
129+
if (headers_sent()) {
130+
echo '<meta http-equiv="refresh" content="0; url='.$url.'"><script type="text/javascript">window.location.href = "'.$url.'";</script>';
131131
} else {
132-
header('Location: ' . $url);
132+
header('Location: '.$url);
133133
}
134134
exit;
135135
}
@@ -147,9 +147,9 @@ protected function doLogin()
147147
$requestTokenUrl = $this->getRequestTokenUrl('http://ptcong.com');
148148

149149
// follow to login form
150-
$formRequest = $this->createHttpClient();
151-
$formRequest->setFollowRedirect(true, 3);
152-
$formRequest->execute($requestTokenUrl);
150+
$formRequest = $this->createHttpClient()
151+
->setFollowRedirect(true, 3)
152+
->execute($requestTokenUrl);
153153

154154
$text = $formRequest;
155155
$pos = stripos($text, 'id="login_form"');
@@ -167,20 +167,19 @@ protected function doLogin()
167167
ksort($params);
168168

169169
// submit login form
170-
$authRequest = $this->createHttpClient();
171-
$authRequest->setMethod('POST');
172-
$authRequest->setFollowRedirect(true, 4);
173-
$authRequest->setParameters($params);
174-
$authRequest->setReferer($formRequest->getTarget());
175-
$authRequest->setCookies($formRequest->getResponseArrayCookies());
176-
$authRequest->execute('https://login.yahoo.com/config/login');
170+
$authRequest = $this->createHttpClient()
171+
->setFollowRedirect(true, 4)
172+
->setParameters($params)
173+
->setReferer($formRequest->getTarget())
174+
->setCookies($formRequest->getResponseArrayCookies())
175+
->setMethod('POST')
176+
->execute('https://login.yahoo.com/config/login');
177177

178178
if (!strpos($authRequest, '/services/auth/')) {
179179
if (stripos($authRequest, 'Javascript enabled')) {
180180
$this->throwException('%s: Yahoo detected automatic sign in and try to restrict. Please run script get AUTH_TOKEN, AUTH_SECRET then call setAccessToken($token, $secret) before.', __METHOD__);
181181
}
182182
print_r($authRequest);
183-
184183
$this->throwException('%s: Cannot reach the Flickr Authorization page or your account is incorrect.', __METHOD__);
185184
}
186185

@@ -195,11 +194,11 @@ protected function doLogin()
195194
preg_match_all('#input.*?name="(.*?)".*?value="(.*?)"#is', $form, $matches);
196195
$params = array_combine($matches[1], $matches[2]);
197196

198-
$this->resetHttpClient();
199-
$this->client->setCookies($cookies);
200-
$this->client->setParameters($params);
201-
$this->client->setMethod('POST');
202-
$this->client->execute('https://www.flickr.com//services/oauth/authorize.gne');
197+
$this->resetHttpClient()
198+
->setCookies($cookies)
199+
->setParameters($params)
200+
->setMethod('POST')
201+
->execute('https://www.flickr.com//services/oauth/authorize.gne');
203202

204203
$location = $this->client->getResponseHeaders('location');
205204
if (!($requestAuthToken = $this->getMatch('#oauth_token=([\w-]+)#i', $location))
@@ -231,26 +230,25 @@ protected function doUpload()
231230
));
232231

233232
list($url, $params) = $this->prepareOAuthRequestData(self::UPLOAD_ENDPOINT, 'POST', $params);
234-
$params['photo'] = '@' . $this->file;
233+
$params['photo'] = '@'.$this->file;
235234

236-
$this->resetHttpClient();
237-
$this->client->setParameters($params);
238-
$this->client->setSubmitMultipart();
239-
$this->client->execute($url);
240-
$text = $this->client;
235+
$this->resetHttpClient()
236+
->setParameters($params)
237+
->setSubmitMultipart()
238+
->execute($url);
241239

242-
if (!$photoId = $this->getMatch('#<photoid>([\d]+)</photoid>#i', $text)) {
243-
parse_str($text, $result);
240+
if (!$photoId = $this->getMatch('#<photoid>([\d]+)</photoid>#i', $this->client)) {
241+
parse_str($this->client, $result);
244242
if (isset($result['oauth_problem'])) {
245243
$this->throwException('UPLOAD_PROBLEM: "%s"', $result['oauth_problem']);
246244
} else {
247-
$error = $this->getMatch('#code="(.+?)"#', $text);
248-
$msg = $this->getMatch('#msg="(.+?)"#', $text);
245+
$error = $this->getMatch('#code="(.+?)"#', $this->client);
246+
$msg = $this->getMatch('#msg="(.+?)"#', $this->client);
249247
$this->throwException('UPLOAD_PROBLEM: "%s" (%d)', $msg, $error);
250248
}
251249
}
252250
$result = $this->call('flickr.photos.getInfo', array(
253-
'photo_id' => $photoId
251+
'photo_id' => $photoId,
254252
));
255253

256254
return $this->getPhotoUrl($result['photo']);
@@ -272,7 +270,7 @@ protected function getPhotoUrl(array $photo)
272270
'{server-id}' => $photo['server'],
273271
'{id}' => $photo['id'],
274272
'{o-secret}' => $photo['originalsecret'],
275-
'{o-format}' => $photo['originalformat']
273+
'{o-format}' => $photo['originalformat'],
276274
)
277275
);
278276
}
@@ -298,7 +296,7 @@ protected function prepareOAuthRequestData($url_endpoint, $method = 'GET', $para
298296
$baseString = $this->getBaseString($url_endpoint, $method, $params);
299297
$params = $this->pushSignature($params, $baseString, $secretKey2);
300298
if ($method == 'GET') {
301-
$url = $url_endpoint . '?' . http_build_query($params);
299+
$url = $url_endpoint.'?'.http_build_query($params);
302300
} else {
303301
$url = $url_endpoint;
304302
}
@@ -319,7 +317,7 @@ protected function getParameters(array $params)
319317
'oauth_timestamp' => time(),
320318
'oauth_consumer_key' => $this->apiKey,
321319
'oauth_signature_method' => 'HMAC-SHA1',
322-
'oauth_version' => '1.0'
320+
'oauth_version' => '1.0',
323321
);
324322
ksort($params);
325323

@@ -334,7 +332,7 @@ protected function getParameters(array $params)
334332
*/
335333
protected function getBaseString($url, $method, array $params)
336334
{
337-
return $method . '&' . urlencode($url). '&'. urlencode(http_build_query($params));
335+
return $method.'&'.urlencode($url).'&'.urlencode(http_build_query($params));
338336
}
339337

340338
/**
@@ -352,7 +350,7 @@ protected function pushSignature(&$params, $baseString, $secretKey2 = null)
352350
$secretKey2 = $cache->get(self::REQUEST_OAUTH_SECRET, '');
353351
}
354352

355-
$secret = $this->secret . '&' . $secretKey2;
353+
$secret = $this->secret.'&'.$secretKey2;
356354
$params['oauth_signature'] = base64_encode(hash_hmac('sha1', $baseString, $secret, true));
357355

358356
return $params;
@@ -384,9 +382,9 @@ protected function getRequestTokenUrl($callback)
384382
$this->getCache()->set(self::REQUEST_OAUTH_TOKEN, $result['oauth_token']);
385383
$this->getCache()->set(self::REQUEST_OAUTH_SECRET, $result['oauth_token_secret']);
386384

387-
list($url, ) = $this->prepareOAuthRequestData(self::AUTH_ENDPOINT, 'GET', array(
385+
list($url,) = $this->prepareOAuthRequestData(self::AUTH_ENDPOINT, 'GET', array(
388386
'oauth_token' => $result['oauth_token'],
389-
'perms' => 'write'
387+
'perms' => 'write',
390388
));
391389

392390
return $url;
@@ -405,12 +403,11 @@ protected function getOAuthAccessToken($requestAuthToken, $requestAuthVerifier,
405403
// get access token
406404
$params = $this->getParameters(array(
407405
'oauth_token' => $requestAuthToken,
408-
'oauth_verifier' => $requestAuthVerifier
406+
'oauth_verifier' => $requestAuthVerifier,
409407
));
410408
list($url, $params) = $this->prepareOAuthRequestData(self::ACCESS_TOKEN_ENDPOINT, 'GET', $params, $secretKey2);
411409

412-
$this->resetHttpClient();
413-
$this->client->execute($url);
410+
$this->resetHttpClient()->execute($url);
414411

415412
parse_str($this->client, $result);
416413
if (isset($result['oauth_problem'])) {
@@ -442,12 +439,11 @@ protected function call($method, array $params = array())
442439
'method' => $method,
443440
'oauth_token' => $this->getAccessToken(),
444441
'format' => 'json',
445-
'nojsoncallback' => '1'
442+
'nojsoncallback' => '1',
446443
));
447444
list($url, $params) = $this->prepareOAuthRequestData(self::API_ENDPOINT, 'GET', $params);
448445

449-
$this->resetHttpClient();
450-
$this->client->execute($url);
446+
$this->resetHttpClient()->execute($url);
451447

452448
if (false === $result = json_decode($this->client, true)) {
453449
parse_str($this->client, $result);

Plugins/Imageshack.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ChipVN_ImageUploader_Plugins_Imageshack extends ChipVN_ImageUploader_Plugi
2020
*/
2121
protected function getApiURL($path)
2222
{
23-
return self::API_ENDPOINT . $path;
23+
return self::API_ENDPOINT.$path;
2424
}
2525

2626
/**
@@ -30,21 +30,21 @@ protected function doLogin()
3030
{
3131
// session_login is array
3232
if (!$this->getCache()->get('session_login')) {
33-
$this->resetHttpClient();
34-
$this->client->setReferer('https://imageshack.com/');
35-
$this->client->execute(self::LOGIN_ENDPOINT, 'POST', array(
36-
'username' => $this->username,
37-
'password' => $this->password,
38-
'remember_me' => 'true',
39-
'set_cookies' => 'true',
40-
));
41-
$result = json_decode($this->client, true);
33+
$this->resetHttpClient()
34+
->setReferer('https://imageshack.com/')
35+
->setParameters(array(
36+
'username' => $this->username,
37+
'password' => $this->password,
38+
'remember_me' => 'true',
39+
'set_cookies' => 'true',
40+
))
41+
->execute(self::LOGIN_ENDPOINT, 'POST');
4242

4343
$this->checkHttpClientErrors(__METHOD__);
44+
$result = json_decode($this->client, true);
4445

4546
if (!empty($result['result']['userid'])) {
4647
$this->getCache()->set('session_login', $result['result']);
47-
4848
} else {
4949
if (isset($result['error']['error_message'])) {
5050
$message = $result['error']['error_message'];
@@ -64,7 +64,7 @@ protected function doLogin()
6464
*/
6565
protected function doUpload()
6666
{
67-
return $this->sendRequest(array('file' => '@' . $this->file));
67+
return $this->sendRequest(array('file' => '@'.$this->file));
6868
}
6969

7070
/**
@@ -93,25 +93,23 @@ private function sendRequest(array $param)
9393

9494
$session = $this->getCache()->get('session_login');
9595

96-
$this->resetHttpClient();
97-
$this->client->setSubmitMultipart();
98-
$this->client->setParameters($param + array(
99-
'auth_token' => $session['auth_token'],
100-
'api_key' => $this->apiKey,
101-
));
102-
$this->client->execute(self::UPLOAD_ENPOINT, 'POST');
103-
104-
$result = json_decode($this->client, true);
96+
$this->resetHttpClient()
97+
->setSubmitMultipart()
98+
->setParameters($param + array(
99+
'auth_token' => $session['auth_token'],
100+
'api_key' => $this->apiKey,
101+
))
102+
->execute(self::UPLOAD_ENPOINT, 'POST');
105103

106104
$this->checkHttpClientErrors(__METHOD__);
105+
$result = json_decode($this->client, true);
107106

108107
if (isset($result['error']['error_message'])) {
109-
$this->throwException(__METHOD__ . ': ' . $result['error']['error_message']); // . $this->client
110-
108+
$this->throwException(__METHOD__.': '.$result['error']['error_message']); // . $this->client
111109
} elseif (isset($result['result']['images'][0])) {
112110
$image = $result['result']['images'][0];
113111

114-
return 'http://imageshack.com/a/img' . $image['server'] . '/' . $image['bucket'] . '/' . $image['filename'];
112+
return 'http://imageshack.com/a/img'.$image['server'].'/'.$image['bucket'].'/'.$image['filename'];
115113
}
116114

117115
return false;

0 commit comments

Comments
 (0)