PageRenderTime 69ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/msn/Yahoo.inc

https://bitbucket.org/rbonesource1234/no2co2
Pascal | 2009 lines | 974 code | 203 blank | 832 comment | 153 complexity | bed595e41f2bb8fe8b3885aee162f2ad MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * YOS PHP SDK for accessing social and data apis at Yahoo!
  4. *
  5. * @package yos-social-php
  6. * @author Yahoo! Developer Network
  7. * @example http://developer.yahoo.com/social/sdk/php/
  8. *
  9. * @copyright Copyright (c) 2009 Yahoo! Inc. All rights reserved.
  10. * @license BSD License (http://www.opensource.org/licenses/bsd-license.php)
  11. *
  12. * The copyrights embodied in the content of this file are licensed under the
  13. * BSD (revised) open source license.
  14. *
  15. * Redistribution and use of this software in source and binary forms, with
  16. * or without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * * Redistributions of source code must retain the above
  20. * copyright notice, this list of conditions and the
  21. * following disclaimer.
  22. *
  23. * * Redistributions in binary form must reproduce the above
  24. * copyright notice, this list of conditions and the
  25. * following disclaimer in the documentation and/or other
  26. * materials provided with the distribution.
  27. *
  28. * * Neither the name of Yahoo! Inc. nor the names of its
  29. * contributors may be used to endorse or promote products
  30. * derived from this software without specific prior
  31. * written permission of Yahoo! Inc.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  36. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  37. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  38. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  39. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  40. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  41. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  42. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. * Please see the Yahoo! Developer Network forums for support: http://developer.yahoo.net/forum/
  45. *
  46. * Documentation: http://developer.yahoo.com/social/sdk/php/
  47. */
  48. // Use OAuthConsumer as a test to see if any other instances of OAuth.php may
  49. // have been included. require_once() won't catch situations where multiple
  50. // copies of OAuth.php are included by different parts of an application.
  51. if(!class_exists("OAuthConsumer")) {
  52. require_once("OAuth.php");
  53. }
  54. define("OAUTH_PARAMS_IN_HEADERS", "HEADERS");
  55. define("OAUTH_PARAMS_IN_POST_BODY", "POSTBODY");
  56. define("OAUTH_SIGNATURE_PLAINTEXT", "PLAINTEXT");
  57. define("OAUTH_SIGNATURE_HMAC_SHA1", "HMAC_SHA1");
  58. define("YAHOO_YAP_SESSION_TYPE", "YAHOO_YAP_SESSION_TYPE");
  59. define("YAHOO_OAUTH_RT_SESSION_TYPE", "YAHOO_OAUTH_RT_SESSION_TYPE");
  60. define("YAHOO_OAUTH_AT_SESSION_TYPE", "YAHOO_OAUTH_AT_SESSION_TYPE");
  61. global $YahooConfig, $GLOBAL_YAHOO_SESSION, $GLOBAL_YAHOO_LOGGER_DEBUG, $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION;
  62. $YahooConfig = array(
  63. "SOCIAL_WS_HOSTNAME" => "social.yahooapis.com",
  64. "PRESENCE_WS_HOSTNAME" => "social.yahooapis.com",
  65. "UPDATES_WS_HOSTNAME" => "social.yahooapis.com",
  66. "QUERY_WS_HOSTNAME" => "query.yahooapis.com",
  67. "OAUTH_HOSTNAME" => "api.login.yahoo.com",
  68. "YAP_WS_HOSTNAME" => "appstore.apps.yahooapis.com"
  69. );
  70. $GLOBAL_YAHOO_SESSION = NULL;
  71. $GLOBAL_YAHOO_LOGGER_DEBUG = false;
  72. $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION = "LOG";
  73. class YahooUtil {
  74. function current_url() {
  75. return sprintf("http://%s%s",$_SERVER["HTTP_HOST"],$_SERVER["REQUEST_URI"]);
  76. }
  77. function verify_signature($consumer, $token=NULL, $oauth_signature) {
  78. $oauth_signature_method = new OAuthSignatureMethod_HMAC_SHA1();
  79. $oauth_consumer = new OAuthConsumer($consumer->key, $consumer->secret);
  80. $oauth_token = ($token) ? new OAuthToken($token->key, $token->secret) : NULL;
  81. $oauth_request = OAuthRequest::from_request();
  82. $ok = $oauth_signature_method->check_signature($oauth_request, $oauth_consumer, $oauth_token, $oauth_signature);
  83. return $ok;
  84. }
  85. function is_yap_canvas() {
  86. return (isset($_POST['yap_appid'])
  87. && isset($_POST['yap_view']));
  88. }
  89. function is_response_error($response) {
  90. return (is_null($response) || $response["code"] != 200);
  91. }
  92. }
  93. class YahooException extends Exception {
  94. }
  95. /**
  96. * Logging wrapper for the Yahoo objects.
  97. *
  98. * @brief Logging wrapper for the Yahoo objects.
  99. */
  100. class YahooLogger {
  101. /**
  102. * Log a message at the debug level.
  103. *
  104. * @param $message The message to log.
  105. */
  106. function debug($message, $object = NULL) {
  107. global $GLOBAL_YAHOO_LOGGER_DEBUG;
  108. global $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION;
  109. if($GLOBAL_YAHOO_LOGGER_DEBUG) {
  110. if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "CONSOLE") {
  111. print("DEBUG - $message\n");
  112. if(!is_null($object)) {
  113. print("DEBUG OBJECT - " . print_r($object, true) . "\n");
  114. }
  115. }
  116. else if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "LOG") {
  117. error_log("DEBUG - $message");
  118. if(!is_null($object)) {
  119. error_log("DEBUG OBJECT - " . print_r($object, true));
  120. }
  121. }
  122. }
  123. }
  124. /**
  125. * Log a message at the info level.
  126. *
  127. * @param $message The message to log.
  128. */
  129. function info($message, $object = NULL) {
  130. global $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION;
  131. if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "CONSOLE") {
  132. print("INFO - $message\n");
  133. if(!is_null($object)) {
  134. print("INFO OBJECT - " . print_r($object, true) . "\n");
  135. }
  136. }
  137. else if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "LOG") {
  138. error_log("INFO - $message");
  139. if(!is_null($object)) {
  140. error_log("INFO OBJECT - " . print_r($object, true));
  141. }
  142. }
  143. }
  144. /**
  145. * Log a message at the error level.
  146. *
  147. * @param $message The message to log.
  148. */
  149. function error($message, $object = NULL) {
  150. global $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION;
  151. if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "CONSOLE") {
  152. print("ERROR - $message\n");
  153. if(!is_null($object)) {
  154. print("ERROR OBJECT - " . print_r($object, true) . "\n");
  155. }
  156. }
  157. else if($GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION == "LOG") {
  158. error_log("ERROR - $message");
  159. if(!is_null($object)) {
  160. error_log("ERROR OBJECT - " . print_r($object, true));
  161. }
  162. }
  163. }
  164. /**
  165. * Enables/disables session debugging.
  166. *
  167. * @param $debug Boolean to enable/disable debugging.
  168. */
  169. function setDebug($debug) {
  170. global $GLOBAL_YAHOO_LOGGER_DEBUG;
  171. $GLOBAL_YAHOO_LOGGER_DEBUG = (bool) $debug;
  172. }
  173. /**
  174. * Allows callers to configure where debugging output is sent.
  175. *
  176. * @param $destination "LOG" to use YahooLogger::error, "CONSOLE" to use printf,
  177. * "NULL" to disable all logging output.
  178. * @return boolean True on success, false on failure.
  179. */
  180. function setDebugDestination($destination) {
  181. global $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION;
  182. if($destination == "LOG" || $destination == "CONSOLE" ||
  183. $destination == "NULL") {
  184. $GLOBAL_YAHOO_LOGGER_DEBUG_DESTINATION = $destination;
  185. return true;
  186. }
  187. else {
  188. return false;
  189. }
  190. }
  191. }
  192. /**
  193. * Defines a session between an application and the Yahoo! platform.
  194. *
  195. * @brief Defines a session between an application and the Yahoo! platform.
  196. */
  197. class YahooSession {
  198. /**
  199. * @private
  200. */
  201. var $guid = NULL;
  202. /**
  203. * @private
  204. */
  205. var $consumer = NULL;
  206. /**
  207. * @private
  208. */
  209. var $accessToken = NULL;
  210. /**
  211. * @private
  212. */
  213. var $applicationId = NULL;
  214. /**
  215. * @private
  216. */
  217. var $client = NULL;
  218. /**
  219. * @private
  220. */
  221. var $application = NULL;
  222. /**
  223. * @private
  224. */
  225. function YahooSession($consumer, $accessToken, $applicationId)
  226. {
  227. $this->consumer = $consumer;
  228. $this->accessToken = $accessToken;
  229. $this->applicationId = $applicationId;
  230. $this->guid = $accessToken->guid;
  231. $this->client = new OAuthClient($consumer, $accessToken);
  232. $this->application = new YahooApplication($consumer->key, $consumer->secret);
  233. $this->application->token = $this->accessToken;
  234. }
  235. /**
  236. * @private
  237. */
  238. function getConsumer() {
  239. return $this->consumer;
  240. }
  241. /**
  242. * @private
  243. */
  244. function getAccessToken() {
  245. return $this->accessToken;
  246. }
  247. /**
  248. * @private
  249. */
  250. function getApplicationId() {
  251. return $this->applicationId;
  252. }
  253. /**
  254. * Gets the currently sessioned user.
  255. *
  256. * @return YahooUser The currently sessioned YahooUser.
  257. */
  258. function getSessionedUser() {
  259. return new YahooUser($this, $this->guid, true);
  260. }
  261. /**
  262. * Gets the user who owns the application install.
  263. * Only valid when viewed in YAP, otherwise will default
  264. * to the logged-in user.
  265. *
  266. * @return YahooUser The currently sessioned YahooUser.
  267. */
  268. function getOwner() {
  269. if(isset($this->accessToken->owner)) {
  270. return $this->getUser($this->accessToken->owner);
  271. }
  272. else {
  273. return $this->getSessionedUser();
  274. }
  275. }
  276. /**
  277. * Gets the user indicated by the GUID given.
  278. *
  279. * @param $guid The GUID of the user to get.
  280. * @return YahooUser The user indicated by the GUID given.
  281. */
  282. function getUser($guid) {
  283. return new YahooUser($this, $guid, isset($this->guid) && ($guid == $this->guid));
  284. }
  285. /**
  286. * Executes the given YQL query.
  287. *
  288. * @param $yql The query to execute.
  289. * @param $env A URL to a YQL environment file.
  290. * @return The response or NULL if the request fails..
  291. */
  292. function query($yql, $env=NULL) {
  293. return $this->application->query($yql, $env);
  294. }
  295. /**
  296. * @private
  297. */
  298. function redirectForAuthorization($consumerKey, $consumerSecret, $callback = NULL, $sessionStore = NULL) {
  299. $url = YahooSession::createAuthorizationUrl($consumerKey, $consumerSecret, $callback, $sessionStore);
  300. if(!is_null($url)) {
  301. header(sprintf("Location: %s", $url));
  302. exit();
  303. }
  304. else {
  305. // TODO: throw a YahooException
  306. YahooLogger::error("Failed to create authorization URLs");
  307. }
  308. }
  309. /**
  310. * Destroys the current session, effectively logging out the current
  311. * user.
  312. *
  313. * @param $sessionStore The session store implementation to clear. See
  314. * YahooSessionStore for more information. If no
  315. * session store is provided, clearSession will
  316. * instantiate a NativeSessionStore and use that.
  317. */
  318. function clearSession($sessionStore = NULL) {
  319. global $GLOBAL_YAHOO_SESSION;
  320. if(is_null($sessionStore)) {
  321. $sessionStore = new NativeSessionStore();
  322. }
  323. $sessionStore->clearRequestToken();
  324. $sessionStore->clearAccessToken();
  325. $GLOBAL_YAHOO_SESSION = NULL;
  326. }
  327. /**
  328. * Checks to see if there is a session in this PHP page request.
  329. * Doesn't cause any redirects for the user to log in, for that
  330. * you should call requireSession().
  331. *
  332. * @param $consumerKey The OAuth consumer key.
  333. * @param $consumerSecret The OAuth consumer key secret.
  334. * @param $applicationId The application ID, optional.
  335. * @param $sessionStore The session store implementation to use. See
  336. * YahooSessionStore for more information. If no
  337. * session store is provided, clearSession will
  338. * instantiate a NativeSessionStore and use that.
  339. * @return boolean True if a session is present, false otherwise.
  340. */
  341. function hasSession($consumerKey, $consumerSecret, $applicationId = NULL, $sessionStore = NULL, $verifier = NULL)
  342. {
  343. if(is_null($sessionStore)) {
  344. $sessionStore = new NativeSessionStore();
  345. }
  346. if(is_null($verifier) && array_key_exists("oauth_verifier", $_GET)) {
  347. $verifier = $_GET["oauth_verifier"];
  348. }
  349. $session = YahooSession::initSession($consumerKey, $consumerSecret, $applicationId, FALSE, NULL, $sessionStore, $verifier);
  350. return !is_null($session);
  351. }
  352. /**
  353. * Requires that there be a session in this PHP page request. Generates
  354. * a redirect for the user to log in, if necessary. You must call
  355. * requireSession() before any data is sent back to the user in order
  356. * for the redirect to work.
  357. *
  358. * @param $consumerKey The OAuth consumer key.
  359. * @param $consumerSecret The OAuth consumer key secret.
  360. * @param $applicationId The application ID, optional.
  361. * @param $callback The callback URL to redirect the user to after
  362. * they verify the application access. If no callback
  363. * is provided, the current page URL will be used.
  364. * @param $sessionStore The session store implementation to use. See
  365. * YahooSessionStore for more information. If no
  366. * session store is provided, clearSession will
  367. * instantiate a NativeSessionStore and use that.
  368. * @param $verifier The oauth_verifier returned by the OAuth servers
  369. * after authorization. Passing NULL indicates that
  370. * authorization was completed previously or that
  371. * requireSession() should look for oauth_verifier in
  372. * the $_GET superglobal.
  373. * @return YahooSession The current session or NULL if a session cannot
  374. * be established.
  375. */
  376. function requireSession($consumerKey, $consumerSecret, $applicationId = NULL,
  377. $callback = NULL, $sessionStore = NULL, $verifier = NULL)
  378. {
  379. if(is_null($sessionStore)) {
  380. $sessionStore = new NativeSessionStore();
  381. }
  382. if(is_null($verifier) && array_key_exists("oauth_verifier", $_GET)) {
  383. $verifier = $_GET["oauth_verifier"];
  384. }
  385. return YahooSession::initSession($consumerKey, $consumerSecret, $applicationId, TRUE, $callback, $sessionStore, $verifier);
  386. }
  387. /**
  388. * Creates authorization URLs, allowing applications to manage their
  389. * user experience when the user needs to be sent to Yahoo! to authorize
  390. * the application to access their account.
  391. *
  392. * @param $consumerKey The OAuth consumer key.
  393. * @param $consumerSecret The OAuth consumer key secret.
  394. * @param $callback The callback URL to redirect the user to after
  395. * they verify the application access. If no callback
  396. * is provided, the current page URL will be used.
  397. * Use the "oob" callback for desktop clients or for
  398. * web clients where no callback should be used.
  399. * @param $sessionStore The session store implementation to use. See
  400. * YahooSessionStore for more information. If no
  401. * session store is provided, createAuthorizationUrl
  402. * will instantiate a NativeSessionStore and use that.
  403. * @return stdclass A PHP object with two properties: "urlWithCallback"
  404. * and "urlWithoutCallback". This allows the application
  405. * to mix and match authorizations that do and don't
  406. * have callbacks in the URLs. urlWithoutCallback is
  407. * useful for JavaScript popup windows while
  408. * urlWithCallback is useful for normal <a href>
  409. * tags.
  410. */
  411. function createAuthorizationUrl($consumerKey, $consumerSecret, $callback = NULL, $sessionStore = NULL)
  412. {
  413. global $GLOBAL_YAHOO_SESSION;
  414. if(is_null($sessionStore)) {
  415. $sessionStore = new NativeSessionStore();
  416. }
  417. // No callback URL supplied. Build one from the current URL.
  418. if(is_null($callback)) {
  419. $callback = YahooUtil::current_url();
  420. }
  421. // Redirect the user to log in.
  422. $requestToken = YahooAuthorization::getRequestToken($consumerKey, $consumerSecret, $callback);
  423. if(!is_null($requestToken))
  424. {
  425. $sessionStore->storeRequestToken($requestToken);
  426. $url = YahooAuthorization::createAuthorizationUrl($requestToken, $callback);
  427. return $url;
  428. }
  429. else
  430. {
  431. YahooLogger::error("Failed to create request token");
  432. $GLOBAL_YAHOO_SESSION = NULL;
  433. return null;
  434. }
  435. }
  436. function initSessionFromYAP($consumerKey, $consumerSecret, $appid)
  437. {
  438. global $GLOBAL_YAHOO_SESSION;
  439. if(!YahooUtil::is_yap_canvas()) {
  440. // TODO: throw a YahooException
  441. return NULL;
  442. }
  443. $consumer = new stdclass();
  444. $consumer->key = $consumerKey;
  445. $consumer->secret = $consumerSecret;
  446. if ($consumer->key != $_POST["yap_consumer_key"]) {
  447. YahooLogger::error("Consumer key from YAP does not match provided key.");
  448. // TODO: throw a YahooException
  449. $GLOBAL_YAHOO_SESSION = NULL;
  450. return;
  451. }
  452. $signature_ok = YahooUtil::verify_signature($consumer, null, $_REQUEST['oauth_signature']);
  453. if (!$signature_ok)
  454. {
  455. YahooLogger::error("Signature from YAP failed.");
  456. // TODO: throw a YahooException
  457. $GLOBAL_YAHOO_SESSION = NULL;
  458. return;
  459. }
  460. $accessToken = new stdclass();
  461. $accessToken->key = $_POST["yap_viewer_access_token"];
  462. $accessToken->secret = $_POST["yap_viewer_access_token_secret"];
  463. $accessToken->guid = $_POST["yap_viewer_guid"];
  464. $accessToken->owner = $_POST["yap_owner_guid"];
  465. $accessToken->tokenExpires = -1;
  466. YahooLogger::debug("YAP AT: " . $accessToken->key . " ATS: " . $accessToken->secret);
  467. $applicationId = $_POST["yap_appid"];
  468. $GLOBAL_YAHOO_SESSION = new YahooSession($consumer, $accessToken, $applicationId);
  469. return $GLOBAL_YAHOO_SESSION;
  470. }
  471. /**
  472. * @private
  473. */
  474. function initSession($consumerKey, $consumerSecret, $applicationId, $redirect, $callback, $sessionStore, $verifier)
  475. {
  476. global $GLOBAL_YAHOO_SESSION;
  477. if(!is_null($GLOBAL_YAHOO_SESSION)) {
  478. return $GLOBAL_YAHOO_SESSION;
  479. }
  480. $consumer = new stdclass();
  481. $consumer->key = $consumerKey;
  482. $consumer->secret = $consumerSecret;
  483. $checkSession = YahooSession::checkSession($type, $sessionStore);
  484. if(!$checkSession) {
  485. // There doesn't appear to be a session here.
  486. if($redirect) {
  487. $GLOBAL_YAHOO_SESSION = NULL;
  488. YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
  489. }
  490. else {
  491. // Don't redirect the user, just inform the caller that
  492. // no session is present.
  493. // TODO: throw a YahooException
  494. $GLOBAL_YAHOO_SESSION = NULL;
  495. }
  496. }
  497. else if($type == YAHOO_OAUTH_AT_SESSION_TYPE) {
  498. // Found an OAuth Access Token session.
  499. $accessToken = $sessionStore->fetchAccessToken();
  500. $now = time();
  501. YahooLogger::debug("OAuth AT: " . $accessToken->key . " ATS: ". $accessToken->secret);
  502. if($accessToken->consumer != $consumerKey)
  503. {
  504. YahooLogger::error("Consumer key for token does not match the defined Consumer Key. The Consumer Key has probably changed since the user last authorized the application.");
  505. YahooSession::clearSession($sessionStore);
  506. if($redirect) {
  507. YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
  508. }
  509. }
  510. if($accessToken->tokenExpires >= 0) {
  511. YahooLogger::debug('AT Expires in: ' . ($accessToken->tokenExpires - $now));
  512. }
  513. if(($accessToken->tokenExpires >= 0) && ($accessToken->tokenExpires - $now) < 30) {
  514. // The access token will expire in less than 30 seconds or
  515. // it may have expired already. Try to get a new one.
  516. YahooSession::accessTokenExpired($accessToken, $consumer, $applicationId, $sessionStore);
  517. }
  518. else {
  519. // The access token is still good for a little while, continue using it.
  520. $GLOBAL_YAHOO_SESSION = new YahooSession($consumer, $accessToken, $applicationId);
  521. }
  522. }
  523. else if($type == YAHOO_OAUTH_RT_SESSION_TYPE)
  524. {
  525. if(is_null($verifier)) {
  526. // Can't proceed without the oauth_verifier, treat it as
  527. // though there's no session present.
  528. $sessionStore->clearRequestToken();
  529. // TODO: throw a YahooException
  530. $GLOBAL_YAHOO_SESSION = NULL;
  531. }
  532. // Found an OAuth Request Token session.
  533. $requestToken = $sessionStore->fetchRequestToken();
  534. $accessToken = YahooAuthorization::getAccessToken($consumerKey, $consumerSecret, $requestToken, $verifier);
  535. if(!is_null($accessToken)) {
  536. $sessionStore->storeAccessToken($accessToken);
  537. $sessionStore->clearRequestToken();
  538. $GLOBAL_YAHOO_SESSION = new YahooSession($consumer, $accessToken, $applicationId);
  539. }
  540. else if($redirect)
  541. {
  542. // TODO: Add redirect counter so this doesn't happen over and over and over when Yahoo! is completely busted.
  543. // The fetch for the access token failed. Generate a new
  544. // request token and try again.
  545. $GLOBAL_YAHOO_SESSION = NULL;
  546. YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
  547. }
  548. else
  549. {
  550. // Don't redirect the user, just inform the caller that
  551. // no session is present.
  552. $sessionStore->clearRequestToken();
  553. $GLOBAL_YAHOO_SESSION = NULL;
  554. }
  555. }
  556. else if($type == YAHOO_YAP_SESSION_TYPE)
  557. {
  558. // Found a YAP session.
  559. $GLOBAL_YAHOO_SESSION = YahooSession::initSessionFromYAP($consumerKey, $consumerSecret, $applicationId);
  560. }
  561. else
  562. {
  563. YahooLogger::error("Unknown session type found");
  564. // TODO: throw a YahooException
  565. $GLOBAL_YAHOO_SESSION = NULL;
  566. }
  567. return $GLOBAL_YAHOO_SESSION;
  568. }
  569. /**
  570. * @private
  571. */
  572. function accessTokenExpired($accessToken, $consumer, $applicationId, $sessionStore)
  573. {
  574. global $GLOBAL_YAHOO_SESSION;
  575. $now = time();
  576. if(($accessToken->handleExpires === -1) ||
  577. ($now < $accessToken->handleExpires)) {
  578. // Either the access session handle doesn't expire
  579. // or it hasn't expired yet. Get a new access token.
  580. $newAccessToken = YahooAuthorization::getAccessToken(
  581. $consumer->key, $consumer->secret, $accessToken, null);
  582. if(is_null($newAccessToken)) {
  583. YahooLogger::error("Failed to fetch access token");
  584. $GLOBAL_YAHOO_SESSION = NULL;
  585. }
  586. $sessionStore->storeAccessToken($newAccessToken);
  587. YahooLogger::debug("Got new AT/ATS from ASH!");
  588. YahooLogger::debug("OAuth AT: " . $newAccessToken->key . " ATS: ". $newAccessToken->secret);
  589. $GLOBAL_YAHOO_SESSION = new YahooSession(
  590. $consumer, $newAccessToken, $applicationId);
  591. }
  592. else
  593. {
  594. // The access token is expired and we don't have
  595. // a sufficient access session handle to renew
  596. // the access token. Clear the cookie and redirect
  597. // to authorization point or return a NULL session.
  598. $sessionStore->clearAccessToken();
  599. if ($redirect) {
  600. YahooSession::redirectForAuthorization($consumer->key, $consumer->secret, $callback, $sessionStore);
  601. } else {
  602. $GLOBAL_YAHOO_SESSION = NULL;
  603. }
  604. }
  605. }
  606. /**
  607. * @private
  608. *
  609. * Checks to see if the current PHP page request has a session and, if so,
  610. * indicates what type of session is present.
  611. *
  612. * @param[out] $sessionType The session type present, if any.
  613. * @return boolean True if a session is present, false otherwise.
  614. */
  615. function checkSession(&$sessionType, $sessionStore) {
  616. if(array_key_exists("yap_appid", $_POST)) {
  617. $sessionType = YAHOO_YAP_SESSION_TYPE;
  618. return true;
  619. }
  620. else if($sessionStore->hasAccessToken()) {
  621. $sessionType = YAHOO_OAUTH_AT_SESSION_TYPE;
  622. return true;
  623. }
  624. else if($sessionStore->hasRequestToken()) {
  625. $sessionType = YAHOO_OAUTH_RT_SESSION_TYPE;
  626. return true;
  627. }
  628. else {
  629. return false;
  630. }
  631. }
  632. }
  633. /**
  634. * Represents a Yahoo! application.
  635. *
  636. * @brief Represents a Yahoo! application.
  637. */
  638. class YahooApplication {
  639. /**
  640. * @private
  641. */
  642. var $consumer = NULL;
  643. /**
  644. * @private
  645. * @deprecated
  646. */
  647. var $client = NULL;
  648. /**
  649. * @private
  650. */
  651. var $token = NULL;
  652. /**
  653. * Constructs a new YahooApplication object.
  654. *
  655. * @param $consumerKey The consumer key of the application.
  656. * @param $consumerKeySecret The consumer key secret of the application.
  657. */
  658. function YahooApplication($consumerKey, $consumerKeySecret) {
  659. $this->consumer = new OAuthConsumer($consumerKey, $consumerKeySecret);
  660. }
  661. /**
  662. * Sets the small view for the user given by the GUID.
  663. *
  664. * @param $guid The GUID of the user to set the small view for.
  665. * @param $content The content to set the small view to.
  666. * @return True on success, false otherwise.
  667. */
  668. function setSmallView($guid, $content) {
  669. global $YahooConfig;
  670. $client = new OAuthClient($this->consumer, NULL);
  671. $request_url = sprintf("http://%s/v1/cache/view/small/%s", $YahooConfig["YAP_WS_HOSTNAME"], urlencode($guid));
  672. $response = $client->put($request_url, "text/html;charset=utf-8", $content);
  673. return !(YahooUtil::is_response_error($response));
  674. }
  675. /**
  676. * Executes the given YQL query.
  677. *
  678. * @param $yql The query to execute.
  679. * @param $env A URL to a YQL environment file.
  680. * @return The response or NULL if the request fails..
  681. */
  682. function query($yql, $env=NULL)
  683. {
  684. global $YahooConfig;
  685. $client = new OAuthClient($this->consumer, $this->token);
  686. $request_url = sprintf("http://%s/v1/yql",$YahooConfig["QUERY_WS_HOSTNAME"]);
  687. $params = array('q' => $yql, 'format' => 'json', 'env' => 'http://datatables.org/alltables.env');
  688. if(!is_null($env)) {
  689. $params['env'] = $env;
  690. }
  691. $response = $client->get($request_url, $params, 30);
  692. if(YahooUtil::is_response_error($response)) {
  693. return NULL;
  694. }
  695. $resultSet = json_decode($response["responseBody"]);
  696. return $resultSet;
  697. }
  698. }
  699. /**
  700. * Represents a Yahoo! user.
  701. *
  702. * @brief Represents a Yahoo! user.
  703. */
  704. class YahooUser {
  705. /**
  706. * @private
  707. */
  708. var $session = NULL;
  709. /**
  710. * @private
  711. */
  712. var $guid = NULL;
  713. /**
  714. * @private
  715. */
  716. var $sessioned = false;
  717. /**
  718. * @private
  719. */
  720. var $client = NULL;
  721. /**
  722. * @private
  723. */
  724. function YahooUser($session, $guid, $sessioned) {
  725. $this->session = $session;
  726. $this->client = $session->client;
  727. $this->guid = $guid;
  728. $this->sessioned = $sessioned;
  729. }
  730. /**
  731. * Gets the user's status message.
  732. *
  733. * @return The status of the user or NULL if the fetch fails.
  734. */
  735. function getStatus() {
  736. global $YahooConfig;
  737. $request_url = sprintf("http://%s/v1/user/%s/profile/status",
  738. $YahooConfig["SOCIAL_WS_HOSTNAME"],urlencode($this->guid));
  739. $response = $this->client->get($request_url);
  740. if(is_null($response)) {
  741. return NULL;
  742. }
  743. else if($response["code"] == 404) {
  744. // No presence is set, return an empty presence.
  745. $status = new stdclass();
  746. $status->message = "";
  747. $status->lastStatusModified = NULL;
  748. $status->uri = NULL;
  749. return $status;
  750. }
  751. else if($response["code"] != 200) {
  752. return NULL;
  753. }
  754. else {
  755. $rsp = json_decode($response["responseBody"]);
  756. return $rsp->status;
  757. }
  758. }
  759. /**
  760. * Sets the user's status message.
  761. *
  762. * @param $message The new status message for the user.
  763. * @return The status message on success, NULL on failure.
  764. */
  765. function setStatus($message) {
  766. global $YahooConfig;
  767. if(!$this->sessioned) {
  768. YahooLogger::error("Can't set the status of an unsessioned user");
  769. return NULL;
  770. }
  771. $message = array("message" => $message);
  772. $status = array("status" => $message);
  773. $status_json = json_encode($status);
  774. $request_url = sprintf("http://%s/v1/user/%s/profile/status", $YahooConfig["SOCIAL_WS_HOSTNAME"], $this->guid);
  775. $response = $this->client->put($request_url, "application/json", $status_json);
  776. if(YahooUtil::is_response_error($response)) {
  777. return NULL;
  778. }
  779. $status = json_decode($response["responseBody"]);
  780. return $status;
  781. }
  782. /**
  783. * Gets the updates for the current user.
  784. *
  785. * @param $start The starting offset to list updates from. (default = 0)
  786. * @param $count The number of updates to request. (default = 10)
  787. * @return An array of updates for the current user.
  788. */
  789. function getUpdates($start = 0, $count = 10) {
  790. $parameters = array("start" => $start, "count" => $count, "transform" => '(sort "pubDate" numeric descending (all))');
  791. $updates = $this->get_resource("updates", $parameters);
  792. return $updates->updates;
  793. }
  794. /**
  795. * Gets the updates for the connections of the current user.
  796. *
  797. * @param $start The starting offset to list updates from.
  798. * @param $count The number of updates to request.
  799. * @return A list of updates for the connections of the current user.
  800. */
  801. function getConnectionUpdates($start = 0, $count = 10) {
  802. $parameters = array("start" => $start, "count" => $count, "transform" => '(sort "pubDate" numeric descending (all))');
  803. $updates = $this->get_resource("updates/connections", $parameters);
  804. return $updates->updates;
  805. }
  806. /**
  807. * Inserts an update for the current user.
  808. *
  809. * @param $suid Identifier that globally unique for a given
  810. * collectionId within producing source.
  811. * @param $title Title for the update.
  812. * @param $link Link back to the cause of the event.
  813. * @param $description Descriptive text associated with the update,
  814. * optional.
  815. * @param $date The date of the update event, optional, defaults to now.
  816. */
  817. function insertUpdate($suid, $title, $link, $description="", $date=NULL) {
  818. global $YahooConfig;
  819. // Make sure this YahooUser is sessioned.
  820. if(!$this->sessioned) {
  821. YahooLogger::error("Can't insert updates for an unsessioned user");
  822. return NULL;
  823. }
  824. if (is_null($date)) {
  825. $date = time();
  826. }
  827. // Make sure an application ID was given.
  828. $appid = $this->session->getApplicationId();
  829. if(empty($appid)) {
  830. YahooLogger::error("No application ID given, can't insert update");
  831. return NULL;
  832. }
  833. $source = sprintf("APP.%s", $appid);
  834. $update = array(
  835. "collectionID" => $this->guid,
  836. "collectionType" => "guid",
  837. "class" => "app",
  838. "source" => $source,
  839. "type" => 'appActivity',
  840. "suid" => $suid,
  841. "title" => $title,
  842. "description" => $description,
  843. "link" => $link,
  844. "pubDate" => (string)$date
  845. );
  846. $update_body = array("updates" => array($update));
  847. $update_body_json = json_encode($update_body);
  848. $request_url = sprintf("http://%s/v1/user/%s/updates/%s/%s", $YahooConfig["UPDATES_WS_HOSTNAME"], $this->guid, $source, urlencode($suid));
  849. $response = $this->client->put($request_url, "application/json", $update_body_json);
  850. return !(YahooUtil::is_response_error($response));
  851. }
  852. /**
  853. * Deletes the update of the given SUID. Only allows deleting updates
  854. * that were inserted by your own application. You won't be able to
  855. * delete updates from other applications.
  856. *
  857. * @param $suid The SUID of the update to be deleted.
  858. * @return boolean True on success, false on failure.
  859. */
  860. function deleteUpdate($suid) {
  861. global $YahooConfig;
  862. // Make sure this YahooUser is sessioned.
  863. if(!$this->sessioned) {
  864. YahooLogger::error("Can't delete updates for an unsessioned user");
  865. return FALSE;
  866. }
  867. // Make sure an application ID was given.
  868. $appid = $this->session->getApplicationId();
  869. if( empty($appid) ) {
  870. YahooLogger::error("No application ID given, can't delete update");
  871. return FALSE;
  872. }
  873. $source = sprintf("APP.%s", $appid);
  874. $request_url = sprintf("http://%s/v1/user/%s/updates/%s/%s", $YahooConfig["UPDATES_WS_HOSTNAME"], $this->guid, $source, urlencode($suid));
  875. $response = $this->client->delete($request_url);
  876. return !(YahooUtil::is_response_error($response));
  877. }
  878. /**
  879. * Loads the extended profile of the current user.
  880. *
  881. * @return The extended profile of the current user.
  882. */
  883. function getProfile() {
  884. global $YahooConfig;
  885. $profile = $this->get_resource("profile");
  886. return $profile->profile;
  887. }
  888. /**
  889. * Gets a list of connections for the current user.
  890. *
  891. * @param[in,out] $start The starting offset.
  892. * @param[in,out] $count The number of connections to fetch.
  893. * @param[out] $total The total number of contacts available.
  894. * @return List of connections for the current user.
  895. */
  896. function getConnections(&$start, &$count, &$total) {
  897. global $YahooConfig;
  898. $parameters = array("view" => "usercard", "start" => $start, "count" => $count);
  899. $connections = $this->get_resource("connections",$parameters);
  900. $start = $connections->connections->start;
  901. $count = $connections->connections->count;
  902. $total = $connections->connections->total;
  903. return $connections->connections->connection;
  904. }
  905. /**
  906. * Gets a list of contacts for the current user.
  907. *
  908. * @param $start The starting offset.
  909. * @param $count The number of contacts to fetch.
  910. * @return List of contacts for the current user.
  911. */
  912. function getContacts($start = 0, $count = 10) {
  913. global $YahooConfig;
  914. if(!$this->sessioned) {
  915. YahooLogger::error("Can't get contacts for an unsessioned user");
  916. return NULL;
  917. }
  918. $parameters = array("view" => "tinyusercard", "start" => $start, "count" => $count);
  919. $contacts = $this->get_resource("contacts",$parameters);
  920. return $contacts;
  921. }
  922. function getContact($contact_id)
  923. {
  924. global $YahooConfig;
  925. if(!$this->sessioned) {
  926. YahooLogger::error("Can't get contacts for an unsessioned user");
  927. return NULL;
  928. }
  929. $parameters = array();
  930. $contacts = $this->get_resource(sprintf("contact/%s", $contact_id), $parameters);
  931. return $contacts;
  932. }
  933. function getContactSync($rev = 0)
  934. {
  935. global $YahooConfig;
  936. if(!$this->sessioned) {
  937. YahooLogger::error("Can't get contacts for an unsessioned user");
  938. return NULL;
  939. }
  940. $parameters = array('view' => 'sync', 'rev' => $rev);
  941. $contactsync = $this->get_resource("contacts",$parameters);
  942. return $contactsync;
  943. }
  944. function syncContacts($contactsync)
  945. {
  946. global $YahooConfig;
  947. if(!$this->sessioned) {
  948. YahooLogger::error("Can't get contacts for an unsessioned user");
  949. return NULL;
  950. }
  951. $parameters = array('format' => 'json');
  952. $data = array('contactsync' => $contactsync);
  953. $body = json_encode($data);
  954. $request_url = sprintf("http://%s/v1/user/%s/contacts", $YahooConfig["SOCIAL_WS_HOSTNAME"], $this->guid);
  955. $response = $this->client->put($request_url, "application/json", $body);
  956. return !(YahooUtil::is_response_error($response));
  957. }
  958. function addContact($contact)
  959. {
  960. global $YahooConfig;
  961. if(!$this->sessioned) {
  962. YahooLogger::error("Can't get contacts for an unsessioned user");
  963. return NULL;
  964. }
  965. $data = array('contact' => $contact);
  966. $body = json_encode($data);
  967. $request_url = sprintf("http://%s/v1/user/%s/contacts", $YahooConfig["SOCIAL_WS_HOSTNAME"], $this->guid);
  968. $response = $this->client->post($request_url, "application/json", $body);
  969. return !(YahooUtil::is_response_error($response));
  970. }
  971. /**
  972. * Sets the small view for the current user.
  973. *
  974. * @param $content The content to set the small view to.
  975. * @return True on success, false otherwise.
  976. */
  977. function setSmallView($content) {
  978. return $this->session->application->setSmallView($this->guid, $content);
  979. }
  980. /**
  981. * @private
  982. */
  983. function get_resource($resource, $parameters=array())
  984. {
  985. global $YahooConfig;
  986. $request_url = sprintf("http://%s/v1/user/%s/%s",
  987. $YahooConfig["SOCIAL_WS_HOSTNAME"], urlencode($this->guid), $resource);
  988. $response = $this->client->get($request_url,$parameters);
  989. $data = json_decode($response["responseBody"]);
  990. return (YahooUtil::is_response_error($response)) ? null : $data;
  991. }
  992. ///////////////////////////////////////////////////////////////////////////
  993. // Deprecated methods
  994. ///////////////////////////////////////////////////////////////////////////
  995. /**
  996. * Loads the extended profile of the current user.
  997. * @deprecated As of 1.2, replaced by getProfile.
  998. * @return The extended profile of the current user.
  999. */
  1000. function loadProfile() {
  1001. // method renamed, keeping for compatibility.
  1002. YahooLogger::info("loadProfile is deprecated since 1.2: Please use getProfile");
  1003. return $this->getProfile();
  1004. }
  1005. /**
  1006. * Lists the updates for the current user.
  1007. * @deprecated As of 1.2, replaced by getUpdates.
  1008. *
  1009. *
  1010. * @param $start The starting offset to list updates from. (default = 0)
  1011. * @param $count The number of updates to request. (default = 10)
  1012. * @return A list of updates for the current user.
  1013. */
  1014. function listUpdates($start = 0, $count = 10) {
  1015. // method renamed, keeping for compatibility.
  1016. YahooLogger::info("listUpdates is deprecated since 1.2: Please use getUpdates");
  1017. return $this->getUpdates($start, $count);
  1018. }
  1019. /**
  1020. * Gets the updates for the connections of the current user.
  1021. * @deprecated As of 1.2, replaced by getConnectionUpdates.
  1022. * @param $start The starting offset to list updates from.
  1023. * @param $count The number of updates to request.
  1024. * @return An array of updates for the connections of the current user.
  1025. */
  1026. function listConnectionUpdates($start = 0, $count = 10) {
  1027. // method renamed, keeping for compatibility.
  1028. YahooLogger::info("listConnectionUpdates is deprecated since 1.2: Please use getConnectionUpdates");
  1029. return $this->getConnectionUpdates($start, $count);
  1030. }
  1031. /**
  1032. * Gets the presence of the user, including the status.
  1033. *
  1034. * @return The presence of the user or NULL if the fetch fails.
  1035. * @deprecated As of 1.2, replaced by getStatus
  1036. */
  1037. function getPresence() {
  1038. global $YahooConfig;
  1039. YahooLogger::info("getPresence is deprecated since 1.2: Please use getStatus.");
  1040. $request_url = sprintf("http://%s/v1/user/%s/presence/presence",
  1041. $YahooConfig["PRESENCE_WS_HOSTNAME"],urlencode($this->guid));
  1042. $response = $this->client->get($request_url);
  1043. if(is_null($response)) {
  1044. return NULL;
  1045. }
  1046. else if($response["code"] == 404) {
  1047. // No presence is set, return an empty presence.
  1048. $presence = new stdclass();
  1049. $presence->value = new stdclass();
  1050. $presence->value->status = "";
  1051. return $presence;
  1052. }
  1053. else if($response["code"] != 200) {
  1054. return NULL;
  1055. }
  1056. else {
  1057. $presence = json_decode($response["responseBody"]);
  1058. return $presence->presence;
  1059. }
  1060. }
  1061. /**
  1062. * Sets the presence of the user.
  1063. *
  1064. * @param $status The new status message for the user.
  1065. * @return The status message on success, NULL on failure.
  1066. * @deprecated As of 1.2, replaced by setStatus
  1067. */
  1068. function setPresence($status) {
  1069. global $YahooConfig;
  1070. YahooLogger::info("setPresence is deprecated since 1.2: Please use setStatus");
  1071. if(!$this->sessioned) {
  1072. YahooLogger::error("Can't set the presence of an unsessioned user");
  1073. return NULL;
  1074. }
  1075. $presence = array("status" => $status);
  1076. $presence_json = json_encode($presence);
  1077. $request_url = sprintf("http://%s/v1/user/%s/presence/presence", $YahooConfig["PRESENCE_WS_HOSTNAME"], $this->guid);
  1078. $response = $this->client->put($request_url, "application/json", $presence_json);
  1079. if(YahooUtil::is_response_error($response)) {
  1080. return NULL;
  1081. }
  1082. $presence = json_decode($response["responseBody"]);
  1083. return $presence;
  1084. }
  1085. ///////////////////////////////////////////////////////////////////////////
  1086. // End Deprecated methods
  1087. ///////////////////////////////////////////////////////////////////////////
  1088. }
  1089. /**
  1090. * @private
  1091. */
  1092. class YahooAuthorization {
  1093. function getRequestToken($consumerKey, $consumerSecret, $callback) {
  1094. global $YahooConfig;
  1095. if(is_null($callback)) {
  1096. $callback = "oob";
  1097. }
  1098. $consumer = new OAuthConsumer($consumerKey, $consumerSecret);
  1099. $client = new OAuthClient($consumer, NULL, OAUTH_PARAMS_IN_POST_BODY, OAUTH_SIGNATURE_HMAC_SHA1);
  1100. $request_url = sprintf("https://%s/oauth/v2/get_request_token", $YahooConfig["OAUTH_HOSTNAME"]);
  1101. $parameters = array("oauth_callback" => $callback);
  1102. $response = $client->post($request_url, "application/x-www-form-urlencoded", $parameters);
  1103. if(is_null($response)) {
  1104. YahooLogger::error("OAuth call to get request token failed");
  1105. return NULL;
  1106. }
  1107. parse_str($response["responseBody"], $token);
  1108. if($response["code"] != 200) {
  1109. $problem = array_key_exists("oauth_problem", $token) ?
  1110. $token["oauth_problem"] : "unknown problem";
  1111. YahooLogger::error("Failed to create request token: $problem");
  1112. return NULL;
  1113. }
  1114. if(!array_key_exists("oauth_callback_confirmed", $token) ||
  1115. !$token["oauth_callback_confirmed"]) {
  1116. // Callback wasn't confirmed.
  1117. YahooLogger::error("Failed to create request token: callback was not confirmed");
  1118. return NULL;
  1119. }
  1120. $requestToken = new stdclass();
  1121. $requestToken->key = $token["oauth_token"];
  1122. $requestToken->secret = $token["oauth_token_secret"];
  1123. return $requestToken;
  1124. }
  1125. function createAuthorizationUrl($requestToken) {
  1126. global $YahooConfig;
  1127. if(!is_object($requestToken) || !property_exists($requestToken, "key")) {
  1128. YahooLogger::error("Request token doesn't have a 'key' property");
  1129. return NULL;
  1130. }
  1131. return sprintf("https://%s/oauth/v2/request_auth?oauth_token=%s", $YahooConfig["OAUTH_HOSTNAME"], urlencode($requestToken->key));
  1132. }
  1133. function getAccessToken($consumerKey, $consumerSecret, $requestToken, $verifier) {
  1134. $at = YahooAuthorization::getAccessTokenProxy($consumerKey, $consumerSecret, $requestToken, $verifier);
  1135. if(is_null($at)) {
  1136. // Failed to fetch the access token, sleep for 250ms and
  1137. // then try one more time.
  1138. YahooLogger::info("Failed to fetch access token, retrying");
  1139. usleep(250000);
  1140. $at = YahooAuthorization::getAccessTokenProxy($consumerKey, $consumerSecret, $requestToken, $verifier);
  1141. }
  1142. return $at;
  1143. }
  1144. function getAccessTokenProxy($consumerKey, $consumerSecret, $requestToken, $verifier) {
  1145. global $YahooConfig;
  1146. $request_url = sprintf("https://%s/oauth/v2/get_token", $YahooConfig["OAUTH_HOSTNAME"]);
  1147. $consumer = new OAuthConsumer($consumerKey, $consumerSecret);
  1148. $parameters = array();
  1149. if(property_exists($requestToken, "sessionHandle")) {
  1150. $parameters["oauth_session_handle"] = $requestToken->sessionHandle;
  1151. }
  1152. if(!is_null($verifier)) {
  1153. $parameters["oauth_verifier"] = $verifier;
  1154. }
  1155. $client = new OAuthClient($consumer, $requestToken, OAUTH_PARAMS_IN_POST_BODY);
  1156. $response = $client->post($request_url, "application/x-www-form-urlencoded", $parameters);
  1157. if(is_null($response)) {
  1158. YahooLogger::error("OAuth call to get access token failed");
  1159. return NULL;
  1160. }
  1161. parse_str($response["responseBody"], $token);
  1162. if($response["code"] != 200) {
  1163. YahooLogger::error("Failed to fetch access token: " . $token["oauth_problem"]);
  1164. return NULL;
  1165. }
  1166. $now = time();
  1167. $accessToken = new stdclass();
  1168. $accessToken->key = $token["oauth_token"];
  1169. $accessToken->secret = $token["oauth_token_secret"];
  1170. $accessToken->guid = $token["xoauth_yahoo_guid"];
  1171. $accessToken->consumer = $consumerKey;
  1172. $accessToken->sessionHandle = $token["oauth_session_handle"];
  1173. // Check to see if the access token ever expires.
  1174. YahooLogger::debug('AT expires in '.$token['oauth_expires_in'].'; ASH expires in '.$token["oauth_authorization_expires_in"]);
  1175. if(array_key_exists("oauth_expires_in", $token)) {
  1176. $accessToken->tokenExpires = $now + $token["oauth_expires_in"];
  1177. }
  1178. else {
  1179. $accessToken->tokenExpires = -1;
  1180. }
  1181. // Check to see if the access session handle ever expires.
  1182. if(array_key_exists("oauth_authorization_expires_in", $token)) {
  1183. $accessToken->handleExpires = $now +
  1184. $token["oauth_authorization_expires_in"];
  1185. }
  1186. else {
  1187. $accessToken->handleExpires = -1;
  1188. }
  1189. return $accessToken;
  1190. }
  1191. }
  1192. /**
  1193. * Cookie-based implementation of the session store. This is the default
  1194. * session storage used by the Y!OS PHP SDK. Developers are free to
  1195. * implement their own session store implementations and pass them to
  1196. * YahooSession::hasSession, YahooSession::requireSession and
  1197. * YahooSession::clearSession. By default, if no sessiā€¦

Large files files are truncated, but you can click here to view the full file