Skip to content

HTTPS clone URL

Subversion checkout URL

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