Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 158 lines (135 sloc) 4.668 kb
4f9b238 @zachgraves initial commit
zachgraves authored
1 <?php
2 require_once("yosdk_lib5/OAuth/OAuth.php");
3 require_once("yosdk_lib5/Yahoo/YahooOAuthApplication.class.php");
4 require_once("WordPressSessionStore.php");
5
6 function yupdates_menu() {
7 global $current_user;
8 get_currentuserinfo();
9
10 if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
11 if($_REQUEST["yupdates_include_updates"]) {
12 yupdatesdb_addUpdatesUser($current_user->user_login);
13 }
14 else {
15 yupdatesdb_removeUpdatesUser($current_user->user_login);
16 }
17 }
18
19 // fetch application keys from user options
20 $ck = get_option("yupdates_consumer_key");
21 $cks = get_option("yupdates_consumer_secret");
22 $appid = get_option("yupdates_application_id");
23
24 $session_store = yupdates_get_sessionStore();
25
26 $application = new YahooOAuthApplication($ck, $cks, $appid);
27 $application_has_session = yupdates_has_session($application, $session_store);
28
29 $session = NULL;
30 $user = NULL;
31 $sharingUpdates = false;
32
33 if($application_has_session == false) {
34 $request_token = $session_store->fetchRequestToken();
35 $auth_url = ($request_token && $request_token->key) ? $application->getAuthorizationUrl($request_token) : "";
36 } else {
37 $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
38 }
39 ?>
40 <div class="wrap">
41 <h2>Yahoo! Updates</h2>
42 <?php if(!is_null($application) && $application_has_session) { ?>
43
44 You have authorized the Yahoo! Updates plugin.
45 <form method="post">
46
47 <?php if(YUPDATES_WIDGET_ENABLED) { ?>
48
49 <p><label for="yupdates-include-updates">Include updates in widget? <input id="yupdates-include-updates" type="checkbox" name="yupdates_include_updates"<?php echo $sharingUpdates ? " checked='checked'" : "" ?>></label></p>
50 <input type="submit" name="yupdates_updateusers" value="Update">
51
52 <?php } ?>
53
54 <input type="submit" name="yupdates_clearauthorization" value="Unauthorize">
55 </form>
56
57 <?php } else { ?>
58
59 You have not yet authorized the Yahoo! Updates plugin.
60 <p>
61 <input type="hidden" name="yupdates_authorize" value="true">
62 <input type="submit" value="Authorize" onclick="_yupdates_authorize();">
63 </p>
64
65 <?php } ?>
66
67 </div>
68
69 <script type="text/javascript">
70 var _gel = function(el) {return document.getElementById(el)};
71 var _yupdates_auth_url = "<?php echo $auth_url; ?>";
72 var _yupdates_authorize = function() {
73 if(_yupdates_auth_url != "") PopupManager.open(_yupdates_auth_url,600,435);
74 }
75 </script>
76 <script type="text/javascript">
77 // a simplified version of step2 popuplib.js
78 var PopupManager = {
79 popup_window:null,
80 interval:null,
81 interval_time:80,
82 waitForPopupClose: function() {
83 if(PopupManager.isPopupClosed()) {
84 PopupManager.destroyPopup();
85 window.location.reload();
86 }
87 },
88 destroyPopup: function() {
89 this.popup_window = null;
90 window.clearInterval(this.interval);
91 this.interval = null;
92 },
93 isPopupClosed: function() {
94 return (!this.popup_window || this.popup_window.closed);
95 },
96 open: function(url, width, height) {
97 this.popup_window = window.open(url,"",this.getWindowParams(width,height));
98 this.interval = window.setInterval(this.waitForPopupClose, this.interval_time);
99
100 return this.popup_window;
101 },
102 getWindowParams: function(width,height) {
103 var center = this.getCenterCoords(width,height);
104 return "width="+width+",height="+height+",status=1,location=1,resizable=yes,left="+center.x+",top="+center.y;
105 },
106 getCenterCoords: function(width,height) {
107 var parentPos = this.getParentCoords();
108 var parentSize = this.getWindowInnerSize();
109
110 var xPos = parentPos.width + Math.max(0, Math.floor((parentSize.width - width) / 2));
111 var yPos = parentPos.height + Math.max(0, Math.floor((parentSize.height - height) / 2));
112
113 return {x:xPos,y:yPos};
114 },
115 getWindowInnerSize: function() {
116 var w = 0;
117 var h = 0;
118
119 if ('innerWidth' in window) {
120 // For non-IE
121 w = window.innerWidth;
122 h = window.innerHeight;
123 } else {
124 // For IE
125 var elem = null;
126 if (('BackCompat' === window.document.compatMode) && ('body' in window.document)) {
127 elem = window.document.body;
128 } else if ('documentElement' in window.document) {
129 elem = window.document.documentElement;
130 }
131 if (elem !== null) {
132 w = elem.offsetWidth;
133 h = elem.offsetHeight;
134 }
135 }
136 return {width:w, height:h};
137 },
138 getParentCoords: function() {
139 var w = 0;
140 var h = 0;
141
142 if ('screenLeft' in window) {
143 // IE-compatible variants
144 w = window.screenLeft;
145 h = window.screenTop;
146 } else if ('screenX' in window) {
147 // Firefox-compatible
148 w = window.screenX;
149 h = window.screenY;
150 }
151 return {width:w, height:h};
152 }
153 }
154 </script>
155
156 <?php
157 }
158 ?>
Something went wrong with that request. Please try again.