Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 160 lines (137 sloc) 5.099 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>,
6304536 @zachgraves fixed my email address in the comments, also updated the ico warning
zachgraves authored
14 * @author Zach Graves <zachg@yahoo-inc.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 **/
4f9b238 @zachgraves initial commit
zachgraves authored
36
37 function yupdates_yahoo_updates_widget($args) {
9d54a9d @zachgraves nothing major. just fixing my indents
zachgraves authored
38 extract($args);
1bcdd47 @zachgraves new widget markup
zachgraves authored
39
40 $users = yupdatesdb_listUpdatesUsers();
41 $updates = array();
42
43 foreach($users as $user) {
44 $session = yupdates_get_session($user);
45
46 if($session->hasSession) {
47 $userUpdates = $session->application->getUpdates(0,20);
48
49 if($userUpdates) {
50 $updates = array_merge($updates, $userUpdates);
51 }
52 }
53 }
54
55 usort($updates, "yupdates_compare_updates");
56
57 echo $before_widget;
58 echo $before_title . "Yahoo! Updates" . $after_title;
59
60 $includedUpdates = 0;
61 $widgetCount = yupdatesdb_getWidgetCount();
62
63 for($i = 0; $i < count($updates) && $includedUpdates < $widgetCount; $i++) {
64 $update = $updates[$i];
65 if(!property_exists($update, "SCL") || $update->SCL === "PUBLIC") {
66 $update_iconURL = $update->loc_iconURL;
67 $update_date = yupdates_ago($update->lastUpdated);
68 $update_title = $update->title;
69
70 $update_text_patterns = array('/{profile_nickname}/i', "/".$update->loc_shortFormRaw."/i");
71 $update_text_replacements = array($update->profile_nickname, $update_title);
72 $update_text = preg_replace($update_text_patterns, $update_text_replacements, $update->loc_longFormRaw);
73
74 $update_via = sprintf("<a href='%s' target='blank'>%s</a> via <a href='%s' target='blank'>%s</a>",
75 $update->link,
76 $update_date,
77 $update->loc_topLevelURL,
78 $update->loc_localizedName);
79
80 echo <<<HTML
81 <div style="padding: 3px">
82 <div style='display: block; float: left; clear: none'>
83 <img src='$update_iconURL' style='width: 16px'>
84 </div>
85 <div style='margin: 0px 0px 0px 22px'>
86 $update_text
87 <p><span style="font-size:10px">$update_via</span></p>
88 </div>
89 </div>
90 HTML;
91
92 $includedUpdates++;
93 }
94 }
95
96 if($includedUpdates == 0) {
97 echo "No updates at this time";
98 }
99 echo $after_widget;
4f9b238 @zachgraves initial commit
zachgraves authored
100 }
101
102 function yupdates_yahoo_updates_widget_control() {
1bcdd47 @zachgraves new widget markup
zachgraves authored
103 $count = yupdatesdb_getWidgetCount();
104 if($_POST["yupdateswidgetsubmit"]) {
105 $newCount = $_POST["yupdateswidgetcount"];
106 if(is_numeric($newCount) && ($newCount >= 0)) {
107 yupdatesdb_setWidgetCount($newCount);
108 $count = $newCount;
109 }
110 }
dd0088e @zachgraves fixed issues for request token on first setup
zachgraves authored
111 echo <<<HTML
112 <p><label for="yupdates-widget-count">Number of Updates to Display:
113 <input type="text" id="yupdates-widget-count" name="yupdateswidgetcount" size="2" value="$count"></label></p>
114 <input type="hidden" name="yupdateswidgetsubmit" value="1">
115 HTML;
4f9b238 @zachgraves initial commit
zachgraves authored
116 }
117
118 if(YUPDATES_WIDGET_ENABLED) {
1bcdd47 @zachgraves new widget markup
zachgraves authored
119 add_action("init", "yupdates_register_widgets");
4f9b238 @zachgraves initial commit
zachgraves authored
120 }
121
122 function yupdates_register_widgets() {
1bcdd47 @zachgraves new widget markup
zachgraves authored
123 register_sidebar_widget("Yahoo! Updates", "yupdates_yahoo_updates_widget", null, "yupdates");
124 register_widget_control("Yahoo! Updates", "yupdates_yahoo_updates_widget_control", null, 75, "yupdates");
4f9b238 @zachgraves initial commit
zachgraves authored
125 }
126
127 function yupdates_compare_updates($a, $b) {
1bcdd47 @zachgraves new widget markup
zachgraves authored
128 return $b->lastUpdated - $a->lastUpdated;
4f9b238 @zachgraves initial commit
zachgraves authored
129 }
130
131 function yupdates_ago($timestamp) {
1bcdd47 @zachgraves new widget markup
zachgraves authored
132 $difference = time() - $timestamp;
133 $unit = NULL;
134
135 if($difference < 60) {
9d54a9d @zachgraves nothing major. just fixing my indents
zachgraves authored
136 return "moments ago";
137 } else {
4f9b238 @zachgraves initial commit
zachgraves authored
138 $difference = round($difference / 60);
1bcdd47 @zachgraves new widget markup
zachgraves authored
139 if($difference < 60) {
140 $unit = $difference == 1 ? "minute" : "minutes";
141 } else {
142 $difference = round($difference / 60);
143 if($difference < 24) {
144 $unit = $difference == 1 ? "hour" : "hours";
9d54a9d @zachgraves nothing major. just fixing my indents
zachgraves authored
145 } else {
1bcdd47 @zachgraves new widget markup
zachgraves authored
146 $difference = round($difference / 24);
147 if($difference < 7) {
148 $unit = $difference == 1 ? "day" : "days";
149 } else {
150 return "a while ago";
151 }
152 }
153 }
154 }
155
156 return sprintf("%d %s ago", $difference, $unit);
4f9b238 @zachgraves initial commit
zachgraves authored
157 }
158
159 ?>
Something went wrong with that request. Please try again.