Skip to content

Commit 0f3778c

Browse files
author
Phan Thanh Cong
committed
update 5.2.12
1 parent b6eb7b6 commit 0f3778c

File tree

9 files changed

+241
-185
lines changed

9 files changed

+241
-185
lines changed

Manager.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
* @author Phan Thanh Cong <[email protected]>
77
* @copyright 2010-2014 Phan Thanh Cong.
88
* @license http://www.opensource.org/licenses/mit-license.php MIT License
9-
* @version 5.1
10-
* @release Apr 08, 2014
119
* @website http://ptcong.com
1210
*/
1311

1412
class ChipVN_ImageUploader_Manager
1513
{
16-
/**
17-
* Library version
18-
*/
19-
const VERSION = '5.1';
14+
const VERSION = '5.2.12';
2015

2116
/**
2217
* Create a plugin for uploading.
@@ -29,6 +24,5 @@ public static function make($plugin)
2924
$class = 'ChipVN_ImageUploader_Plugins_' . ucfirst($plugin);
3025

3126
return new $class;
32-
3327
}
3428
}

Plugins/Abstract.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
2-
/**
3-
* @update Jun 19, 2014
4-
*/
2+
53
abstract class ChipVN_ImageUploader_Plugins_Abstract
64
{
75
const POWERED_BY = 'by-[ChipVN]-Image-Uploader';
86

97
/**
10-
* Determine if login is called
8+
* Determine if login have called
119
*
1210
* @since 5.2.0 - Jun 19, 2014
1311
* @var boolean
@@ -122,7 +120,7 @@ public function setCache($cache = '', array $options = array())
122120
*/
123121
public function createHttpClient()
124122
{
125-
$httpClient = new ChipVN_Http_Client;
123+
$httpClient = new ChipVN_Http_Client();
126124
$httpClient->useCurl($this->useCurl);
127125

128126
return $httpClient;
@@ -185,8 +183,8 @@ final public function setApi($keys)
185183
/**
186184
* Execute upload action and return URL.
187185
*
188-
* @param string $file
189-
* @return string|false
186+
* @param string $file
187+
* @return string
190188
*
191189
* @throws Exception If have an error occurred
192190
*/
@@ -206,8 +204,8 @@ final public function upload($file)
206204
/**
207205
* Execute transload action and return URL.
208206
*
209-
* @param string $url
210-
* @return string|false
207+
* @param string $url
208+
* @return string
211209
*
212210
* @throws Exception If have an error occurred
213211
*/
@@ -283,6 +281,26 @@ protected function getMatch($regex, $text, $number = 1, $default = null)
283281
return $default;
284282
}
285283

284+
/**
285+
* Helper method to get element in an array
286+
*
287+
* @param array $array
288+
* @param key $keys index.index.index
289+
* @return mixed
290+
*/
291+
protected function getElement($array, $keys, $default = null)
292+
{
293+
foreach (explode('.', $keys) as $key) {
294+
if (isset($array[$key])) {
295+
$array = $array[$key];
296+
} else {
297+
return $default;
298+
}
299+
}
300+
301+
return $array;
302+
}
303+
286304
/**
287305
* Throws an exception.
288306
*
@@ -334,8 +352,9 @@ protected function trimBaseClassName($value)
334352
$val = $this->trimBaseClassName($val);
335353
}
336354
} else {
337-
$value = str_replace('ChipVN_ImageUploader_Plugins_', '...', $value);
355+
$value = strtr($value, array('ChipVN_ImageUploader_Plugins_' => ''));
338356
}
357+
339358
return $value;
340359
}
341360
}

Plugins/Flickr.php

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

129-
header('Location: ' . $url);
129+
if(headers_sent()) {
130+
echo '<meta http-equiv="refresh" content="0; url='. $url . '"><script type="text/javascript">window.location.href = "' . $url . '";</script>';
131+
} else {
132+
header('Location: ' . $url);
133+
}
130134
exit;
131135
}
132136

@@ -147,7 +151,7 @@ protected function doLogin()
147151
$formRequest->setFollowRedirect(true, 3);
148152
$formRequest->execute($requestTokenUrl);
149153

150-
$text = $formRequest->getResponseText();
154+
$text = $formRequest;
151155
$pos = stripos($text, 'id="login_form"');
152156
$form = substr($text, $pos);
153157
$form = substr($form, 0, stripos($form, '</fieldset'));
@@ -171,8 +175,8 @@ protected function doLogin()
171175
$authRequest->setCookies($formRequest->getResponseArrayCookies());
172176
$authRequest->execute('https://login.yahoo.com/config/login');
173177

174-
if (!strpos($authRequest->getResponseText(), '/services/auth/')) {
175-
if (stripos($authRequest->getResponseText(), 'Javascript enabled')) {
178+
if (!strpos($authRequest, '/services/auth/')) {
179+
if (stripos($authRequest, 'Javascript enabled')) {
176180
$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__);
177181
}
178182
print_r($authRequest);
@@ -181,7 +185,7 @@ protected function doLogin()
181185
}
182186

183187
// go to flickr to authorize
184-
if (!$pos = strpos($text = $authRequest->getResponseText(), '/services/oauth/authorize.gne')) {
188+
if (!$pos = strpos($text = $authRequest, '/services/oauth/authorize.gne')) {
185189
$this->throwException('%s: Cannot bypass Flickr authorization.', __METHOD__);
186190
}
187191
$form = substr($text, $pos);
@@ -233,7 +237,7 @@ protected function doUpload()
233237
$this->client->setParameters($params);
234238
$this->client->setSubmitMultipart();
235239
$this->client->execute($url);
236-
$text = $this->client->getResponseText();
240+
$text = $this->client;
237241

238242
if (!$photoId = $this->getMatch('#<photoid>([\d]+)</photoid>#i', $text)) {
239243
parse_str($text, $result);
@@ -370,7 +374,7 @@ protected function getRequestTokenUrl($callback)
370374
$this->resetHttpClient();
371375
$this->client->execute($url);
372376

373-
parse_str($this->client->getResponseText(), $result);
377+
parse_str($this->client, $result);
374378
if (isset($result['oauth_problem'])) {
375379
$this->throwException('REQUEST_TOKEN_PROBLEM: "%s"', $result['oauth_problem']);
376380
}
@@ -408,7 +412,7 @@ protected function getOAuthAccessToken($requestAuthToken, $requestAuthVerifier,
408412
$this->resetHttpClient();
409413
$this->client->execute($url);
410414

411-
parse_str($this->client->getResponseText(), $result);
415+
parse_str($this->client, $result);
412416
if (isset($result['oauth_problem'])) {
413417
$this->throwException('ACCESS_TOKEN_PROBLEM: "%s"', $result['oauth_problem']);
414418
}
@@ -445,8 +449,8 @@ protected function call($method, array $params = array())
445449
$this->resetHttpClient();
446450
$this->client->execute($url);
447451

448-
if (false === $result = json_decode($this->client->getResponseText(), true)) {
449-
parse_str($this->client->getResponseText(), $result);
452+
if (false === $result = json_decode($this->client, true)) {
453+
parse_str($this->client, $result);
450454
if (isset($result['oauth_problem'])) {
451455
$this->throwException('API_PROBLEM: "%s"', $result['oauth_problem']);
452456
}

Plugins/Imageshack.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function doLogin()
3838
'remember_me' => 'true',
3939
'set_cookies' => 'true',
4040
));
41-
$result = json_decode($this->client->getResponseText(), true);
41+
$result = json_decode($this->client, true);
4242

4343
$this->checkHttpClientErrors(__METHOD__);
4444

@@ -52,7 +52,7 @@ protected function doLogin()
5252
$message = 'Login failed.';
5353
}
5454
$this->getCache()->deleteGroup($this->getIdentifier());
55-
$this->throwException('%s: %s.', __METHOD__, $message); // $this->client->getResponseText()
55+
$this->throwException('%s: %s.', __METHOD__, $message); // $this->client
5656
}
5757
}
5858

@@ -101,12 +101,12 @@ private function sendRequest(array $param)
101101
));
102102
$this->client->execute(self::UPLOAD_ENPOINT, 'POST');
103103

104-
$result = json_decode($this->client->getResponseText(), true);
104+
$result = json_decode($this->client, true);
105105

106106
$this->checkHttpClientErrors(__METHOD__);
107107

108108
if (isset($result['error']['error_message'])) {
109-
$this->throwException(__METHOD__ . ': ' . $result['error']['error_message']); // . $this->client->getResponseText()
109+
$this->throwException(__METHOD__ . ': ' . $result['error']['error_message']); // . $this->client
110110

111111
} elseif (isset($result['result']['images'][0])) {
112112
$image = $result['result']['images'][0];

0 commit comments

Comments
 (0)