Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 184 lines (166 sloc) 5.895 kb
4f9b2385 »
2009-09-22 initial commit
1 <?php
e54b9daa »
2009-09-22 added license headers
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 *
2428313f »
2010-01-22 updated authors
12 * @author Ryan Kennedy
13 * @author Lawrence Morrisroe <lem@yahoo-inc.com>,
6304536b »
2010-02-24 fixed my email address in the comments, also updated the ico warning
14 * @author Zach Graves <zachg@yahoo-inc.com>
e54b9daa »
2009-09-22 added license headers
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
4f9b2385 »
2009-09-22 initial commit
37 function yupdates_menu() {
9e4d21db »
2010-01-25 soft tabs
38 global $current_user;
39 get_currentuserinfo();
40
41 if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
42 if($_REQUEST["yupdates_include_updates"]) {
43 yupdatesdb_addUpdatesUser($current_user->user_login);
44 } else {
45 yupdatesdb_removeUpdatesUser($current_user->user_login);
46 }
47 }
4f9b2385 »
2009-09-22 initial commit
48
9e4d21db »
2010-01-25 soft tabs
49 $session = yupdates_get_session();
50 $sharingUpdates = false;
c51abce3 »
2009-09-25 adding better error handling for oauth problems
51
9e4d21db »
2010-01-25 soft tabs
52 if($session->hasSession == false) {
53 $request_token = $session->store->fetchRequestToken();
54 $auth_url = ($request_token && $request_token->key) ? $session->application->getAuthorizationUrl($request_token) : "";
55 } else {
56 $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
57 }
4f9b2385 »
2009-09-22 initial commit
58 ?>
c51abce3 »
2009-09-25 adding better error handling for oauth problems
59
4f9b2385 »
2009-09-22 initial commit
60 <div class="wrap">
61 <h2>Yahoo! Updates</h2>
c51abce3 »
2009-09-25 adding better error handling for oauth problems
62
31c43b5e »
2009-09-23 minor optimizations
63 <?php
9e4d21db »
2010-01-25 soft tabs
64 if($session->application && $session->hasSession) {
65 echo <<<HTML
c51abce3 »
2009-09-25 adding better error handling for oauth problems
66 You have already authorized the Yahoo! Updates plugin.
4f9b2385 »
2009-09-22 initial commit
67 <form method="post">
31c43b5e »
2009-09-23 minor optimizations
68 HTML;
9e4d21db »
2010-01-25 soft tabs
69
70 if(YUPDATES_WIDGET_ENABLED) {
31c43b5e »
2009-09-23 minor optimizations
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 }
9e4d21db »
2010-01-25 soft tabs
77
78 echo <<<HTML
31c43b5e »
2009-09-23 minor optimizations
79 <input type="submit" name="yupdates_clearauthorization" value="Unauthorize"></form>
80 HTML;
9e4d21db »
2010-01-25 soft tabs
81 } else {
82 echo <<<HTML
4f9b2385 »
2009-09-22 initial commit
83 You have not yet authorized the Yahoo! Updates plugin.
31c43b5e »
2009-09-23 minor optimizations
84 <p><input type="hidden" name="yupdates_authorize" value="true"><input type="submit" value="Authorize" onclick="_yupdates_authorize();"></p>
85 HTML;
86 }
87 ?>
4f9b2385 »
2009-09-22 initial commit
88 </div>
89
90 <script type="text/javascript">
91 var _gel = function(el) {return document.getElementById(el)};
92 var _yupdates_auth_url = "<?php echo $auth_url; ?>";
a58e0e26 »
2009-09-24 debugging issues with auth button
93
94 function _yupdates_authorize() {
95 if(_yupdates_auth_url != "")
96 PopupManager.open(_yupdates_auth_url,600,435);
97 else alert("Error: No request token / auth url");
4f9b2385 »
2009-09-22 initial commit
98 }
99 </script>
c51abce3 »
2009-09-25 adding better error handling for oauth problems
100
4f9b2385 »
2009-09-22 initial commit
101 <script type="text/javascript">
102 // a simplified version of step2 popuplib.js
103 var PopupManager = {
104 popup_window:null,
105 interval:null,
106 interval_time:80,
107 waitForPopupClose: function() {
108 if(PopupManager.isPopupClosed()) {
109 PopupManager.destroyPopup();
110 window.location.reload();
111 }
112 },
113 destroyPopup: function() {
114 this.popup_window = null;
115 window.clearInterval(this.interval);
116 this.interval = null;
117 },
118 isPopupClosed: function() {
119 return (!this.popup_window || this.popup_window.closed);
120 },
121 open: function(url, width, height) {
122 this.popup_window = window.open(url,"",this.getWindowParams(width,height));
123 this.interval = window.setInterval(this.waitForPopupClose, this.interval_time);
124
125 return this.popup_window;
126 },
127 getWindowParams: function(width,height) {
128 var center = this.getCenterCoords(width,height);
129 return "width="+width+",height="+height+",status=1,location=1,resizable=yes,left="+center.x+",top="+center.y;
130 },
131 getCenterCoords: function(width,height) {
132 var parentPos = this.getParentCoords();
133 var parentSize = this.getWindowInnerSize();
134
135 var xPos = parentPos.width + Math.max(0, Math.floor((parentSize.width - width) / 2));
136 var yPos = parentPos.height + Math.max(0, Math.floor((parentSize.height - height) / 2));
137
138 return {x:xPos,y:yPos};
139 },
140 getWindowInnerSize: function() {
141 var w = 0;
142 var h = 0;
143
144 if ('innerWidth' in window) {
145 // For non-IE
146 w = window.innerWidth;
147 h = window.innerHeight;
148 } else {
149 // For IE
150 var elem = null;
151 if (('BackCompat' === window.document.compatMode) && ('body' in window.document)) {
152 elem = window.document.body;
153 } else if ('documentElement' in window.document) {
154 elem = window.document.documentElement;
155 }
156 if (elem !== null) {
157 w = elem.offsetWidth;
158 h = elem.offsetHeight;
159 }
160 }
161 return {width:w, height:h};
162 },
163 getParentCoords: function() {
164 var w = 0;
165 var h = 0;
166
167 if ('screenLeft' in window) {
168 // IE-compatible variants
169 w = window.screenLeft;
170 h = window.screenTop;
171 } else if ('screenX' in window) {
172 // Firefox-compatible
173 w = window.screenX;
174 h = window.screenY;
175 }
176 return {width:w, height:h};
177 }
178 }
179 </script>
180
181 <?php
182 }
9e4d21db »
2010-01-25 soft tabs
183 ?>
Something went wrong with that request. Please try again.