@@ -126,10 +126,10 @@ protected function requestToken($callback)
126
126
{
127
127
$ url = $ this ->getRequestTokenUrl ($ callback );
128
128
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> ' ;
131
131
} else {
132
- header ('Location: ' . $ url );
132
+ header ('Location: ' . $ url );
133
133
}
134
134
exit ;
135
135
}
@@ -147,9 +147,9 @@ protected function doLogin()
147
147
$ requestTokenUrl = $ this ->getRequestTokenUrl ('http://ptcong.com ' );
148
148
149
149
// 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 );
153
153
154
154
$ text = $ formRequest ;
155
155
$ pos = stripos ($ text , 'id="login_form" ' );
@@ -167,20 +167,19 @@ protected function doLogin()
167
167
ksort ($ params );
168
168
169
169
// 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 ' );
177
177
178
178
if (!strpos ($ authRequest , '/services/auth/ ' )) {
179
179
if (stripos ($ authRequest , 'Javascript enabled ' )) {
180
180
$ 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__ );
181
181
}
182
182
print_r ($ authRequest );
183
-
184
183
$ this ->throwException ('%s: Cannot reach the Flickr Authorization page or your account is incorrect. ' , __METHOD__ );
185
184
}
186
185
@@ -195,11 +194,11 @@ protected function doLogin()
195
194
preg_match_all ('#input.*?name="(.*?)".*?value="(.*?)"#is ' , $ form , $ matches );
196
195
$ params = array_combine ($ matches [1 ], $ matches [2 ]);
197
196
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 ' );
203
202
204
203
$ location = $ this ->client ->getResponseHeaders ('location ' );
205
204
if (!($ requestAuthToken = $ this ->getMatch ('#oauth_token=([\w-]+)#i ' , $ location ))
@@ -231,26 +230,25 @@ protected function doUpload()
231
230
));
232
231
233
232
list ($ url , $ params ) = $ this ->prepareOAuthRequestData (self ::UPLOAD_ENDPOINT , 'POST ' , $ params );
234
- $ params ['photo ' ] = '@ ' . $ this ->file ;
233
+ $ params ['photo ' ] = '@ ' . $ this ->file ;
235
234
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 );
241
239
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 );
244
242
if (isset ($ result ['oauth_problem ' ])) {
245
243
$ this ->throwException ('UPLOAD_PROBLEM: "%s" ' , $ result ['oauth_problem ' ]);
246
244
} 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 );
249
247
$ this ->throwException ('UPLOAD_PROBLEM: "%s" (%d) ' , $ msg , $ error );
250
248
}
251
249
}
252
250
$ result = $ this ->call ('flickr.photos.getInfo ' , array (
253
- 'photo_id ' => $ photoId
251
+ 'photo_id ' => $ photoId,
254
252
));
255
253
256
254
return $ this ->getPhotoUrl ($ result ['photo ' ]);
@@ -272,7 +270,7 @@ protected function getPhotoUrl(array $photo)
272
270
'{server-id} ' => $ photo ['server ' ],
273
271
'{id} ' => $ photo ['id ' ],
274
272
'{o-secret} ' => $ photo ['originalsecret ' ],
275
- '{o-format} ' => $ photo ['originalformat ' ]
273
+ '{o-format} ' => $ photo ['originalformat ' ],
276
274
)
277
275
);
278
276
}
@@ -298,7 +296,7 @@ protected function prepareOAuthRequestData($url_endpoint, $method = 'GET', $para
298
296
$ baseString = $ this ->getBaseString ($ url_endpoint , $ method , $ params );
299
297
$ params = $ this ->pushSignature ($ params , $ baseString , $ secretKey2 );
300
298
if ($ method == 'GET ' ) {
301
- $ url = $ url_endpoint . '? ' . http_build_query ($ params );
299
+ $ url = $ url_endpoint. '? ' . http_build_query ($ params );
302
300
} else {
303
301
$ url = $ url_endpoint ;
304
302
}
@@ -319,7 +317,7 @@ protected function getParameters(array $params)
319
317
'oauth_timestamp ' => time (),
320
318
'oauth_consumer_key ' => $ this ->apiKey ,
321
319
'oauth_signature_method ' => 'HMAC-SHA1 ' ,
322
- 'oauth_version ' => '1.0 '
320
+ 'oauth_version ' => '1.0 ' ,
323
321
);
324
322
ksort ($ params );
325
323
@@ -334,7 +332,7 @@ protected function getParameters(array $params)
334
332
*/
335
333
protected function getBaseString ($ url , $ method , array $ params )
336
334
{
337
- return $ method . '& ' . urlencode ($ url ). '& ' . urlencode (http_build_query ($ params ));
335
+ return $ method. '& ' . urlencode ($ url ).'& ' .urlencode (http_build_query ($ params ));
338
336
}
339
337
340
338
/**
@@ -352,7 +350,7 @@ protected function pushSignature(&$params, $baseString, $secretKey2 = null)
352
350
$ secretKey2 = $ cache ->get (self ::REQUEST_OAUTH_SECRET , '' );
353
351
}
354
352
355
- $ secret = $ this ->secret . '& ' . $ secretKey2 ;
353
+ $ secret = $ this ->secret . '& ' . $ secretKey2 ;
356
354
$ params ['oauth_signature ' ] = base64_encode (hash_hmac ('sha1 ' , $ baseString , $ secret , true ));
357
355
358
356
return $ params ;
@@ -384,9 +382,9 @@ protected function getRequestTokenUrl($callback)
384
382
$ this ->getCache ()->set (self ::REQUEST_OAUTH_TOKEN , $ result ['oauth_token ' ]);
385
383
$ this ->getCache ()->set (self ::REQUEST_OAUTH_SECRET , $ result ['oauth_token_secret ' ]);
386
384
387
- list ($ url , ) = $ this ->prepareOAuthRequestData (self ::AUTH_ENDPOINT , 'GET ' , array (
385
+ list ($ url ,) = $ this ->prepareOAuthRequestData (self ::AUTH_ENDPOINT , 'GET ' , array (
388
386
'oauth_token ' => $ result ['oauth_token ' ],
389
- 'perms ' => 'write '
387
+ 'perms ' => 'write ' ,
390
388
));
391
389
392
390
return $ url ;
@@ -405,12 +403,11 @@ protected function getOAuthAccessToken($requestAuthToken, $requestAuthVerifier,
405
403
// get access token
406
404
$ params = $ this ->getParameters (array (
407
405
'oauth_token ' => $ requestAuthToken ,
408
- 'oauth_verifier ' => $ requestAuthVerifier
406
+ 'oauth_verifier ' => $ requestAuthVerifier,
409
407
));
410
408
list ($ url , $ params ) = $ this ->prepareOAuthRequestData (self ::ACCESS_TOKEN_ENDPOINT , 'GET ' , $ params , $ secretKey2 );
411
409
412
- $ this ->resetHttpClient ();
413
- $ this ->client ->execute ($ url );
410
+ $ this ->resetHttpClient ()->execute ($ url );
414
411
415
412
parse_str ($ this ->client , $ result );
416
413
if (isset ($ result ['oauth_problem ' ])) {
@@ -442,12 +439,11 @@ protected function call($method, array $params = array())
442
439
'method ' => $ method ,
443
440
'oauth_token ' => $ this ->getAccessToken (),
444
441
'format ' => 'json ' ,
445
- 'nojsoncallback ' => '1 '
442
+ 'nojsoncallback ' => '1 ' ,
446
443
));
447
444
list ($ url , $ params ) = $ this ->prepareOAuthRequestData (self ::API_ENDPOINT , 'GET ' , $ params );
448
445
449
- $ this ->resetHttpClient ();
450
- $ this ->client ->execute ($ url );
446
+ $ this ->resetHttpClient ()->execute ($ url );
451
447
452
448
if (false === $ result = json_decode ($ this ->client , true )) {
453
449
parse_str ($ this ->client , $ result );
0 commit comments