/[drupal]/contributions/modules/onlinestatus/messengers.inc.php
ViewVC logotype

Contents of /contributions/modules/onlinestatus/messengers.inc.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Thu Apr 19 09:26:19 2007 UTC (2 years, 7 months ago) by xeniac
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.11: +6 -6 lines
File MIME type: text/x-php
Added a Patch from Rob Loach to support Drupal 5:
Loading the CSS with drupal_add_css() to conform with drupal 5.
style.css has been renamed to onlinestatus.css
Added an uninstall hook in onlinestatus.info
1 <?php
2 // $Id: messengers.inc.php,v 1.11 2006/11/06 00:38:35 xeniac Exp $
3 /**
4 * @file
5 * Messenger support for the Onlinestatus Indicator.
6 *
7 * This file will be loaded by onlinestatus_messenger() and adds support for the
8 * different Instant Messenger types.
9 *
10 * This file is part of Onlinestatus Indicator.
11 *
12 * Onlinestatus Indicator is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
16 *
17 * Onlinestatus Indicator is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with Onlinestatus Indicator; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 * @author Christian Edelmann <xeniac@gmx.at>
27 * @version $Revision: 1.11 $
28 */
29
30 /**
31 * Onlinestatus Indicator support for Yahoo! Messenger
32 *
33 * @param string $op possible operations: update, url, validate
34 * @param string $account AIM Screenname
35 * @return string
36 */
37 function onlinestatus_messenger_aim($op, $account) {
38 switch ($op) {
39 case 'update' :
40 $url = sprintf('http://big.oscar.aol.com/%s?on_url=online&off_url=offline', $account);
41 $data = onlinestatus_fetch_url($url, true, false);
42 if (strchr($data, 'online')) {
43 return 'online';
44 }
45 elseif (strchr($data, 'offline')) {
46 return 'offline';
47 }
48 else {
49 return 'unknown';
50 }
51 case 'url' :
52 return sprintf('aim:GoIM?screenname=%s', $account);
53 case 'validate' :
54 if (preg_match('/^([a-zA-Z][a-zA-Z0-9]{3,16}(@mac\.com)?)$/', $account)) {
55 return true;
56 }
57 else {
58 return false;
59 }
60 }
61 }
62
63
64 /**
65 * Onlinestatus Indicator support for Google Talk
66 *
67 * @param string $op possible operations: description, update, url, settings, validate
68 * @param string $account the gmail.com mail address
69 * @return string
70 */
71 function onlinestatus_messenger_gtalk($op, $account = null) {
72 switch ($op) {
73 case 'description' :
74 return t('Support for GoogleTalk is very prelimanary at the Moment, you get the best Results with the PSI Messenger.').'<br />'. onlinestatus_messenger_jabber('description');
75 case 'update' :
76 return onlinestatus_messenger_jabber($op,"$account@gmail.com");
77 case 'url' :
78 return sprintf('xmpp:%s', "$account@gmail.com");
79 case 'settings' :
80 $return['onlinestatus_gtalk'] = array (
81 '#type' => 'markup',
82 '#value' => '<div>'.t('At this Point we handle GoogleTalk as an Jabber Account on gmail.com. Unforunely it seems that the GoogleTalk Client does not support status notification.').'</div>');
83 return $return;
84 case 'validate' :
85 if (valid_email_address("$account@gmail.com")) {
86 return true;
87 }
88 else {
89 return false;
90 }
91 }
92 }
93
94
95 /**
96 * Onlinestatus Indicator support for ICQ
97 *
98 * @param string $op possible operations: update, url, validate
99 * @param string $account the Yahoo! Account
100 * @return string
101 */
102 function onlinestatus_messenger_icq($op, $account = null) {
103 switch ($op) {
104 case 'update' :
105 $url = sprintf('http://status.icq.com/online.gif?icq=%s&img=1', $account);
106 $data = onlinestatus_fetch_url($url, true, true);
107 if (strstr($data, 'online0') != false) {
108 $status = 'offline';
109 }
110 elseif (strstr($data, 'online1') != false) {
111 $status = 'online';
112 }
113 else {
114 $status = 'unknown';
115 }
116 return $status;
117 case url :
118 return sprintf('http://www.icq.com/whitepages/wwp.php?to=%d', $account);
119 case 'validate' :
120 if (preg_match('/^\d*$/', $account) && strlen($account) <= 32) {
121 return true;
122 }
123 else {
124 return false;
125 }
126 }
127 }
128
129 /**
130 * Onlinestatus Indicator support for Jabber
131 *
132 * @param string $op possible operations: description, update, settings, url, validate
133 * @param string $account the Jabber ID
134 * @return string
135 */
136 function onlinestatus_messenger_jabber($op, $account = null) {
137 switch ($op) {
138 case 'description' :
139 return t('For Jabber Onlinestatus, please Allow user %jabber to see your online status.', array ('%jabber' => variable_get('onlinestatus_jabberuser', 'onlinestatus@jabber.org')));
140 case 'update' :
141 //Query Edgar
142 if (variable_get('onlinestatus_edgar', true)) {
143 $url = sprintf('%s/status.php?jid=%s&type=text', variable_get('onlinestatus_edgarserver', 'http://edgar.netflint.net'), $account);
144 $data = strtok(onlinestatus_fetch_url($url, false, false), ':');
145 switch ($data) {
146 case 'Online' :
147 case 'Free for chat' :
148 case 'Away' :
149 case 'Not Available' :
150 case 'Do not disturb' :
151 return 'online';
152 case 'Offline' :
153 return 'offline';
154 default :
155 return 'unknown';
156 }
157 //Query Onlinestaus.org
158 } else {
159 $url = sprintf('%s/jabber/%s', variable_get('onlinestatus_osiserver', ''), urlencode($account));
160 $data = onlinestatus_fetch_url($url, true, false);
161 if (strchr($data, 'online')) {
162 return 'online';
163 }
164 elseif (strchr($data, 'offline')) {
165 return 'offline';
166 }
167 else {
168 return 'unknown';
169 }
170 }
171 case 'url' :
172 return sprintf('xmpp:%s', $account);
173 case 'settings' :
174 $return['onlinestatus_jabberuser'] = array ('#type' => 'textfield', '#title' => t('Account of your Jabber Bot'), '#default_value' => variable_get('onlinestatus_jabberuser', ''), '#description' => t('The Online Status Indicator Service needs an Bot to fetch the Status Information from Jabber users. Your Users must add this Bot to their Buddylist.<br/> You can find the account of the jabber bot on your <a href="!url">onlinestatus.org server</a>',array('!url' => variable_get('onlinestatus_osiserver','').'/register?type=jabber&name=user@example.com&onurl=&offurl=&unknownurl=&ircchannel=')),);
175 $return['onlinestatus_edgar'] = array ('#type' => 'checkbox', '#title' => t('Use Edgar'), '#default_value' => variable_get('onlinestatus_edgar', 'false'), '#description' => t('Use an <a href="!edgar">Edgar Server</a> instead of the <a href="!osi">Onlinestatus.org</a> Server.', array ('!edgar' => 'http://edgar.netflint.net', '!osi' => 'http://onlinestatus.org')));
176 $return['onlinestatus_edgarserver'] = array ('#type' => 'textfield', '#title' => t('Edgar Server'), '#default_value' => variable_get('onlinestatus_edgarserver', 'http://edgar.netflint.net'), '#description' => t("If you want to use <a href=\"!url\">Edgar</a> for Jabber, enter the URL to your Edgar Server.", array ('!url' => 'http://edgar.netflint.net')));
177 return $return;
178 case 'validate' :
179 if (valid_email_address($account)) {
180 return true;
181 }
182 else {
183 return false;
184 }
185 }
186 }
187
188
189 /**
190 * Onlinestatus Indicator support for MSN Messenger
191 *
192 * @param string $op possible operations: description, update, url, validate
193 * @param string $account the .net Passport Login
194 * @return string
195 */
196 function onlinestatus_messenger_msn($op, $account = null) {
197 switch ($op) {
198 case 'description' :
199 return t('Please check your Privacy settings in MSN Messenger. Make sure &quot;All other users&quot; is in your Allow list.');
200 case 'update' :
201 $url = sprintf('%s/msn/%s',variable_get('onlinestatus_osiserver', ''), $account);
202 $date = onlinestatus_fetch_url($url, true, false, false);
203 if (strstr($data, 'online')) {
204 return 'online';
205 }
206 elseif (strstr($data, 'offline')) {
207 return 'offline';
208 }
209 else {
210 return 'unknown';
211 }
212 case 'url' :
213 return '#';
214 case 'validate':
215 if (valid_email_address($account)) {
216 return true;
217 }
218 else {
219 return false;
220 }
221 }
222 }
223
224
225 /**
226 * Onlinestatus Indicator support for Skype
227 *
228 * @param string $op possible operations: description, update, url, validate
229 * @param string $account the Skype Username
230 * @return string
231 */
232 function onlinestatus_messenger_skype($op, $account = null) {
233 switch ($op) {
234 case 'description' :
235 return t('You need at least Skype 2.0.0.81 for this Feature. If you have problemes open your privacy Settings and check the "Allow Status to be shown on the Web" option.');
236 case 'update' :
237 $url = sprintf('http://mystatus.skype.com/%s.txt', $account);
238 $status = onlinestatus_fetch_url($url, false, false);
239 switch ($status) {
240 case 'Online' : //online
241 case 'Skype Me' : //skype me
242 case 'Away' : //away
243 case 'Not Available' : //not available
244 case 'Do Not Disturb' : //dnd
245 case 'e167636c89d10c794bc4a96533a32f25' : //On a Call
246 return 'online';
247 case 'Invisible' : //Invisible
248 case 'Offline' : //offline
249 return 'offline';
250 default :
251 return 'unknown';
252 }
253 case 'url' :
254 return sprintf('callto://%s', $account);
255 case 'validate' :
256 if (preg_match('/\b^[a-zA-Z][a-zA-Z_\d]{3,15}/', $account) && strlen($account) <= 32) {
257 return true;
258 } else {
259 return false;
260 }
261 }
262 }
263
264
265 /**
266 * Onlinestatus Indicator support for Xfire
267 *
268 * @param string $op possible operations: description, update, url, validate
269 * @param string $account the Skype Username
270 * @return string
271 */
272 function onlinestatus_messenger_xfire($op, $account) {
273 switch ($op) {
274 case 'description' :
275 return false;
276 case 'update' :
277 $url = sprintf('http://www.xfire.com/profile/%s/', $account);
278 $data = onlinestatus_fetch_url($url, false, false);
279 if (strstr($data, 'class="offline"><b>offline</b></span>')) {
280 return 'offline';
281 } elseif (strstr($data, 'class="online"><b>online</b></span>')) {
282 return 'online';
283 } else {
284 return 'unknown';
285 }
286 case 'url' :
287 return sprintf('http://www.xfire.com/profile/%s/', $account);
288 case 'validate' :
289 if (preg_match('/\b^[a-zA-Z\d]{1,25}/', $account) && strlen($account) <= 16) {
290 return true;
291 }
292 else {
293 return false;
294 }
295 }
296 }
297
298 /**
299 * Onlinestatus Indicator support for Yahoo! Messenger
300 *
301 * @param string $op possible operations: description, update, url, validate
302 * @param string $account the Yahoo! Account
303 * @return string
304 */
305 function onlinestatus_messenger_yahoo($op , $account = null) {
306 switch ($op) {
307 case 'description' :
308 return t('Edit your <a href="!url">Yahoo profile</a> and uncheck the <em>&ldquo;Check the box to hide my online status from other users&rdquo;</em> box.', array ('!url' => 'http://login.yahoo.com/config/edit_identity?.src=prf&.done=http://messenger.yahoo.com/'));
309 case 'update' :
310 $ch = curl_init();
311 curl_setopt($ch, CURLOPT_TIMEOUT, variable_get('onlinestatus_timeout', 3));
312 curl_setopt($ch, CURLOPT_URL, sprintf('http://opi.yahoo.com/online?u=%s&m=t', $account));
313 curl_setopt($ch, CURLOPT_HEADER, 0);
314 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
315 if (curl_errno($ch)) {
316 error_handler(curl_errno($ch), curl_error($ch), __FILE__, __LINE__);
317 }
318 $data = curl_exec($ch);
319 curl_close($ch);
320 if (strchr($data, 'NOT ONLINE') == false) {
321 $status = 'online';
322 }
323 else {
324 $status = 'offline';
325 }
326 unset ($ch, $data);
327 return $status;
328 case 'url' :
329 return sprintf('http://edit.yahoo.com/config/send_webmesg?.target=%s&.src=pg', $account);
330 case 'validate' :
331 if (preg_match('/\b[a-zA-Z\d_]{2,32}/', $account) && strlen($account) <= 32) {
332 return true;
333 }
334 else {
335 return false;
336 }
337 }
338 }
339 ?>

  ViewVC Help
Powered by ViewVC 1.1.2