Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit aa0bb9d8d1432dec798b458c92828f8dd140a8cd 0 parents
@zachgraves zachgraves authored
Showing with 236 additions and 0 deletions.
  1. +13 −0 config.inc.php
  2. +146 −0 index.php
  3. +77 −0 js/popupmanager.js
13 config.inc.php
@@ -0,0 +1,13 @@
+<?php
+
+// Make sure you obtain application keys before continuing by visiting:
+// https://developer.yahoo.com/dashboard/createKey.html
+
+// Your consumer key goes here.
+define('CONSUMER_KEY','');
+
+// Your consumer key secret goes here.
+define('CONSUMER_SECRET','');
+
+// Your application ID goes here.
+define('APP_ID','');
146 index.php
@@ -0,0 +1,146 @@
+<?php
+// 'THE MODEL'
+
+require("config.inc.php");
+require("OAuth/OAuth.php");
+require("Yahoo/YahooOAuthApplication.class.php");
+
+$app = new YahooOAuthApplication(CONSUMER_KEY, CONSUMER_SECRET, APP_ID);
+
+if(isset($_GET['logout'])) {
+ // if a session exists and the logout flag is detected
+ // clear the session tokens and reload the page.
+ // YahooSession::clearSession();
+ oauth_unset_cookie('yos-social-rt');
+ oauth_unset_cookie('yos-social-at');
+ header("Location: /apps/popup/index.php");
+}
+
+if(array_key_exists("in_popup", $_GET)) {
+ // print_r($_COOKIE);
+ $request_token = oauth_get_cookie('yos-social-rt');
+ $app->token = $app->getAccessToken($request_token, $_GET['oauth_verifier']);
+ $app->token->expires = 'foobar';
+ oauth_set_cookie('yos-social-at', $app->token, $app->token->expires_in);
+ close_popup();
+ exit;
+
+} else {
+ $token = oauth_get_cookie('yos-social-at');
+ if($token && isset($token->yahoo_guid)) {
+ // set the token in the SDK
+ $app->token = $token;
+
+ // do it!
+ $profile = $app->getProfile($token->yahoo_guid)->profile;
+
+ if(isset($_GET['update'])) {
+ $update = $app->insertUpdate(array(
+ 'title' => "cloned the yos-social-php5 SDK on Github",
+ 'description' => "A PHP5 SDK for YQL",
+ 'link' => "http://github.com/yahoo/yos-social-php5",
+ 'imgURL' => 'http://github.com/images/modules/header/logov3.png',
+ 'imgWidth' => '100',
+ 'imgHeight' => '45'
+ ));
+ }
+ } else {
+ $callback_params = array('in_popup' => true);
+ $callback = sprintf("%s://%s%s?%s", ($_SERVER["HTTPS"] == 'on') ? 'https' : 'http', $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"], http_build_query($callback_params));
+ $request_token = $app->getRequestToken($callback);
+
+ oauth_set_cookie('yos-social-rt', $request_token, $request_token->expires_in);
+
+ $auth_url = $app->getAuthorizationUrl($request_token);
+ }
+}
+
+function close_popup()
+{
+?>
+ <script type="text/javascript">
+ window.close();
+ </script>
+<?
+}
+
+function oauth_get_cookie($name)
+{
+ return unserialize(base64_decode($_COOKIE[$name]));
+}
+
+function oauth_set_cookie($name, $data, $expires = 3600)
+{
+ setcookie($name, base64_encode(serialize($data)), time() + $expires);
+}
+
+function oauth_unset_cookie($name)
+{
+ setcookie($name, '', time()-600);
+}
+
+// NOW THE 'VIEW'
+?>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Yahoo! OAuth Example</title>
+
+ <!-- Combo-handled YUI JS files: -->
+ <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
+ <script type="text/javascript" src="js/popupmanager.js"></script>
+
+ <!-- Combo-handled YUI CSS files: -->
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.7.0/build/reset-fonts-grids/reset-fonts-grids.css&amp;2.7.0/build/base/base-min.css">
+ </head>
+ <body>
+ <?php
+ if(isset($token) && isset($profile)) {
+ // if a session does exist and the profile data was
+ // fetched without error, print out a simple usercard.
+ printf("<img src=\"%s\"/><p><h2>Hi <a href=\"%s\" target=\"_blank\">%s!</a></h2></p>\n",
+ $profile->image->imageUrl, $profile->profileUrl, $profile->nickname);
+
+ if($profile->status->message != "") {
+ $statusDate = date('F j, y, g:i a', strtotime($profile->status->lastStatusModified));
+ printf("<p><strong>&#8220;</strong>%s<strong>&#8221;</strong> on %s</p>",
+ $profile->status->message, $statusDate);
+ }
+
+ if(isset($update)) {
+ print '<p>';
+ print_r($update);
+ print '</p>';
+ }
+
+ print "<button id='uptBtn'>Post Update</button>";
+ print "<p><a href=\"?logout\">Logout</a></p>";
+ } else {
+ // if a session does not exist, output the
+ // login / share button linked to the auth_url.
+ printf("<a href=\"%s\" id=\"yloginLink\"><img src=\"http://l.yimg.com/a/i/ydn/social/updt-spurp.png\"></a>\n", $auth_url);
+ }
+ ?>
+ <script type="text/javascript">
+ var _gel = function(el) {return document.getElementById(el)};
+
+ YAHOO.util.Event.onDOMReady(function() {
+ if(_gel('yloginLink')) {
+ YAHOO.util.Event.addListener("yloginLink", "click", function(event) {
+ // block the url from opening like normal
+ YAHOO.util.Event.preventDefault(event);
+ var auth_url = _gel("yloginLink").href;
+ // open pop-up using the auth_url
+ PopupManager.open(auth_url,600,435);
+ });
+ }
+
+ if(_gel('uptBtn')) {
+ YAHOO.util.Event.addListener('uptBtn', "click", function(event) {
+ document.location = document.location+'?update';
+ });
+ }
+ });
+ </script>
+</body>
+</html>
77 js/popupmanager.js
@@ -0,0 +1,77 @@
+// a simplified version of step2 popuplib.js
+var PopupManager = {
+ popup_window:null,
+ interval:null,
+ interval_time:80,
+ waitForPopupClose: function() {
+ if(PopupManager.isPopupClosed()) {
+ PopupManager.destroyPopup();
+ window.location.reload();
+ }
+ },
+ destroyPopup: function() {
+ this.popup_window = null;
+ window.clearInterval(this.interval);
+ this.interval = null;
+ },
+ isPopupClosed: function() {
+ return (!this.popup_window || this.popup_window.closed);
+ },
+ open: function(url, width, height) {
+ this.popup_window = window.open(url,"",this.getWindowParams(width,height));
+ this.interval = window.setInterval(this.waitForPopupClose, this.interval_time);
+
+ return this.popup_window;
+ },
+ getWindowParams: function(width,height) {
+ var center = this.getCenterCoords(width,height);
+ return "width="+width+",height="+height+",status=1,location=1,resizable=yes,left="+center.x+",top="+center.y;
+ },
+ getCenterCoords: function(width,height) {
+ var parentPos = this.getParentCoords();
+ var parentSize = this.getWindowInnerSize();
+
+ var xPos = parentPos.width + Math.max(0, Math.floor((parentSize.width - width) / 2));
+ var yPos = parentPos.height + Math.max(0, Math.floor((parentSize.height - height) / 2));
+
+ return {x:xPos,y:yPos};
+ },
+ getWindowInnerSize: function() {
+ var w = 0;
+ var h = 0;
+
+ if ('innerWidth' in window) {
+ // For non-IE
+ w = window.innerWidth;
+ h = window.innerHeight;
+ } else {
+ // For IE
+ var elem = null;
+ if (('BackCompat' === window.document.compatMode) && ('body' in window.document)) {
+ elem = window.document.body;
+ } else if ('documentElement' in window.document) {
+ elem = window.document.documentElement;
+ }
+ if (elem !== null) {
+ w = elem.offsetWidth;
+ h = elem.offsetHeight;
+ }
+ }
+ return {width:w, height:h};
+ },
+ getParentCoords: function() {
+ var w = 0;
+ var h = 0;
+
+ if ('screenLeft' in window) {
+ // IE-compatible variants
+ w = window.screenLeft;
+ h = window.screenTop;
+ } else if ('screenX' in window) {
+ // Firefox-compatible
+ w = window.screenX;
+ h = window.screenY;
+ }
+ return {width:w, height:h};
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.