Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 179 lines (165 sloc) 5.839 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 *
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
31c43b5e »
2009-09-23 minor optimizations
35 require_once("lib/OAuth/OAuth.php");
36 require_once("lib/Yahoo/YahooOAuthApplication.class.php");
4f9b2385 »
2009-09-22 initial commit
37
38 function yupdates_menu() {
31c43b5e »
2009-09-23 minor optimizations
39 global $current_user;
40 get_currentuserinfo();
4f9b2385 »
2009-09-22 initial commit
41
31c43b5e »
2009-09-23 minor optimizations
42 if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
43 if($_REQUEST["yupdates_include_updates"]) {
44 yupdatesdb_addUpdatesUser($current_user->user_login);
45 }
46 else {
47 yupdatesdb_removeUpdatesUser($current_user->user_login);
48 }
49 }
4f9b2385 »
2009-09-22 initial commit
50
31c43b5e »
2009-09-23 minor optimizations
51 $session = yupdates_get_session();
52 $sharingUpdates = false;
4f9b2385 »
2009-09-22 initial commit
53
31c43b5e »
2009-09-23 minor optimizations
54 if($session->hasSession == false) {
55 $request_token = $session->store->fetchRequestToken();
56 $auth_url = ($request_token && $request_token->key) ? $session->application->getAuthorizationUrl($request_token) : "";
57 } else {
58 $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
59 }
4f9b2385 »
2009-09-22 initial commit
60 ?>
61 <div class="wrap">
62 <h2>Yahoo! Updates</h2>
31c43b5e »
2009-09-23 minor optimizations
63 <?php
64 if($session->application && $session->hasSession) {
65 echo <<<HTML
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;
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 }
4f9b2385 »
2009-09-22 initial commit
77
31c43b5e »
2009-09-23 minor optimizations
78 echo <<<HTML
79 <input type="submit" name="yupdates_clearauthorization" value="Unauthorize"></form>
80 HTML;
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; ?>";
93 var _yupdates_authorize = function() {
94 if(_yupdates_auth_url != "") PopupManager.open(_yupdates_auth_url,600,435);
95 }
96 </script>
97 <script type="text/javascript">
98 // a simplified version of step2 popuplib.js
99 var PopupManager = {
100 popup_window:null,
101 interval:null,
102 interval_time:80,
103 waitForPopupClose: function() {
104 if(PopupManager.isPopupClosed()) {
105 PopupManager.destroyPopup();
106 window.location.reload();
107 }
108 },
109 destroyPopup: function() {
110 this.popup_window = null;
111 window.clearInterval(this.interval);
112 this.interval = null;
113 },
114 isPopupClosed: function() {
115 return (!this.popup_window || this.popup_window.closed);
116 },
117 open: function(url, width, height) {
118 this.popup_window = window.open(url,"",this.getWindowParams(width,height));
119 this.interval = window.setInterval(this.waitForPopupClose, this.interval_time);
120
121 return this.popup_window;
122 },
123 getWindowParams: function(width,height) {
124 var center = this.getCenterCoords(width,height);
125 return "width="+width+",height="+height+",status=1,location=1,resizable=yes,left="+center.x+",top="+center.y;
126 },
127 getCenterCoords: function(width,height) {
128 var parentPos = this.getParentCoords();
129 var parentSize = this.getWindowInnerSize();
130
131 var xPos = parentPos.width + Math.max(0, Math.floor((parentSize.width - width) / 2));
132 var yPos = parentPos.height + Math.max(0, Math.floor((parentSize.height - height) / 2));
133
134 return {x:xPos,y:yPos};
135 },
136 getWindowInnerSize: function() {
137 var w = 0;
138 var h = 0;
139
140 if ('innerWidth' in window) {
141 // For non-IE
142 w = window.innerWidth;
143 h = window.innerHeight;
144 } else {
145 // For IE
146 var elem = null;
147 if (('BackCompat' === window.document.compatMode) && ('body' in window.document)) {
148 elem = window.document.body;
149 } else if ('documentElement' in window.document) {
150 elem = window.document.documentElement;
151 }
152 if (elem !== null) {
153 w = elem.offsetWidth;
154 h = elem.offsetHeight;
155 }
156 }
157 return {width:w, height:h};
158 },
159 getParentCoords: function() {
160 var w = 0;
161 var h = 0;
162
163 if ('screenLeft' in window) {
164 // IE-compatible variants
165 w = window.screenLeft;
166 h = window.screenTop;
167 } else if ('screenX' in window) {
168 // Firefox-compatible
169 w = window.screenX;
170 h = window.screenY;
171 }
172 return {width:w, height:h};
173 }
174 }
175 </script>
176
177 <?php
178 }
179 ?>
Something went wrong with that request. Please try again.