Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 186 lines (167 sloc) 5.819 kB
4f9b238 @zachgraves initial commit
zachgraves authored
1 <?php
e54b9da @zachgraves added license headers
zachgraves authored
2 /**
3 * Yahoo! Updates Wordpress Plugin
4 *
5 * Find documentation and support on Yahoo! Developer Network: http://developer.yahoo.com
6 *
7 * Hosted on GitHub: http://github.com/yahoo/yos-updates-wordpress/tree/master
8 *
9 * @package yos-updates-wordpress
10 * @subpackage yahoo
11 *
2428313 @zachgraves updated authors
zachgraves authored
12 * @author Ryan Kennedy
13 * @author Lawrence Morrisroe <lem@yahoo-inc.com>,
14 * @author Zach Graves <zachg@yahoo-incnc.com>
e54b9da @zachgraves added license headers
zachgraves authored
15 * @copyright Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
16 * @license BSD Open Source License
17 *
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this software and associated documentation files (the "Software"), to deal
20 * in the Software without restriction, including without limitation the rights
21 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22 * copies of the Software, and to permit persons to whom the Software is
23 * furnished to do so, subject to the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 * THE SOFTWARE.
35 **/
36
4f9b238 @zachgraves initial commit
zachgraves authored
37 function yupdates_menu() {
31c43b5 @zachgraves minor optimizations
zachgraves authored
38 global $current_user;
39 get_currentuserinfo();
4f9b238 @zachgraves initial commit
zachgraves authored
40
31c43b5 @zachgraves minor optimizations
zachgraves authored
41 if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
42 if($_REQUEST["yupdates_include_updates"]) {
43 yupdatesdb_addUpdatesUser($current_user->user_login);
44 }
45 else {
46 yupdatesdb_removeUpdatesUser($current_user->user_login);
47 }
48 }
4f9b238 @zachgraves initial commit
zachgraves authored
49
31c43b5 @zachgraves minor optimizations
zachgraves authored
50 $session = yupdates_get_session();
51 $sharingUpdates = false;
4f9b238 @zachgraves initial commit
zachgraves authored
52
31c43b5 @zachgraves minor optimizations
zachgraves authored
53 if($session->hasSession == false) {
54 $request_token = $session->store->fetchRequestToken();
55 $auth_url = ($request_token && $request_token->key) ? $session->application->getAuthorizationUrl($request_token) : "";
56 } else {
57 $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
58 }
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
59
4f9b238 @zachgraves initial commit
zachgraves authored
60 ?>
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
61
4f9b238 @zachgraves initial commit
zachgraves authored
62 <div class="wrap">
63 <h2>Yahoo! Updates</h2>
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
64
31c43b5 @zachgraves minor optimizations
zachgraves authored
65 <?php
66 if($session->application && $session->hasSession) {
67 echo <<<HTML
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
68 You have already authorized the Yahoo! Updates plugin.
4f9b238 @zachgraves initial commit
zachgraves authored
69 <form method="post">
31c43b5 @zachgraves minor optimizations
zachgraves authored
70 HTML;
71
72 if(YUPDATES_WIDGET_ENABLED) {
73 $checked = $sharingUpdates ? "checked='checked'" : "";
74 echo <<<HTML
75 <p><label for="yupdates-include-updates">Include updates in widget? <input id="yupdates-include-updates" type="checkbox" name="yupdates_include_updates" $checked></label></p>
76 <input type="submit" name="yupdates_updateusers" value="Update">
77 HTML;
78 }
4f9b238 @zachgraves initial commit
zachgraves authored
79
31c43b5 @zachgraves minor optimizations
zachgraves authored
80 echo <<<HTML
81 <input type="submit" name="yupdates_clearauthorization" value="Unauthorize"></form>
82 HTML;
83 } else {
84 echo <<<HTML
4f9b238 @zachgraves initial commit
zachgraves authored
85 You have not yet authorized the Yahoo! Updates plugin.
31c43b5 @zachgraves minor optimizations
zachgraves authored
86 <p><input type="hidden" name="yupdates_authorize" value="true"><input type="submit" value="Authorize" onclick="_yupdates_authorize();"></p>
87 HTML;
88 }
89 ?>
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
90
4f9b238 @zachgraves initial commit
zachgraves authored
91 </div>
92
93 <script type="text/javascript">
94 var _gel = function(el) {return document.getElementById(el)};
95 var _yupdates_auth_url = "<?php echo $auth_url; ?>";
a58e0e2 @zachgraves debugging issues with auth button
zachgraves authored
96
97 function _yupdates_authorize() {
98 if(_yupdates_auth_url != "")
99 PopupManager.open(_yupdates_auth_url,600,435);
100 else alert("Error: No request token / auth url");
4f9b238 @zachgraves initial commit
zachgraves authored
101 }
102 </script>
c51abce @zachgraves adding better error handling for oauth problems
zachgraves authored
103
4f9b238 @zachgraves initial commit
zachgraves authored
104 <script type="text/javascript">
105 // a simplified version of step2 popuplib.js
106 var PopupManager = {
107 popup_window:null,
108 interval:null,
109 interval_time:80,
110 waitForPopupClose: function() {
111 if(PopupManager.isPopupClosed()) {
112 PopupManager.destroyPopup();
113 window.location.reload();
114 }
115 },
116 destroyPopup: function() {
117 this.popup_window = null;
118 window.clearInterval(this.interval);
119 this.interval = null;
120 },
121 isPopupClosed: function() {
122 return (!this.popup_window || this.popup_window.closed);
123 },
124 open: function(url, width, height) {
125 this.popup_window = window.open(url,"",this.getWindowParams(width,height));
126 this.interval = window.setInterval(this.waitForPopupClose, this.interval_time);
127
128 return this.popup_window;
129 },
130 getWindowParams: function(width,height) {
131 var center = this.getCenterCoords(width,height);
132 return "width="+width+",height="+height+",status=1,location=1,resizable=yes,left="+center.x+",top="+center.y;
133 },
134 getCenterCoords: function(width,height) {
135 var parentPos = this.getParentCoords();
136 var parentSize = this.getWindowInnerSize();
137
138 var xPos = parentPos.width + Math.max(0, Math.floor((parentSize.width - width) / 2));
139 var yPos = parentPos.height + Math.max(0, Math.floor((parentSize.height - height) / 2));
140
141 return {x:xPos,y:yPos};
142 },
143 getWindowInnerSize: function() {
144 var w = 0;
145 var h = 0;
146
147 if ('innerWidth' in window) {
148 // For non-IE
149 w = window.innerWidth;
150 h = window.innerHeight;
151 } else {
152 // For IE
153 var elem = null;
154 if (('BackCompat' === window.document.compatMode) && ('body' in window.document)) {
155 elem = window.document.body;
156 } else if ('documentElement' in window.document) {
157 elem = window.document.documentElement;
158 }
159 if (elem !== null) {
160 w = elem.offsetWidth;
161 h = elem.offsetHeight;
162 }
163 }
164 return {width:w, height:h};
165 },
166 getParentCoords: function() {
167 var w = 0;
168 var h = 0;
169
170 if ('screenLeft' in window) {
171 // IE-compatible variants
172 w = window.screenLeft;
173 h = window.screenTop;
174 } else if ('screenX' in window) {
175 // Firefox-compatible
176 w = window.screenX;
177 h = window.screenY;
178 }
179 return {width:w, height:h};
180 }
181 }
182 </script>
183
184 <?php
185 }
186 ?>
Something went wrong with that request. Please try again.