/[drupal]/contributions/modules/xmppframework/xmppframework.module
ViewVC logotype

Contents of /contributions/modules/xmppframework/xmppframework.module

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Oct 2 20:57:51 2008 UTC (13 months, 3 weeks ago) by darrenferguson
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Committing the xmppframework to the repository
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Module providing an XMPPFramework for drupal
7 */
8
9 define('XMPPFRAMEWORK_PATH', drupal_get_path('module', 'xmppframework'));
10 define('XMPPFRAMEWORK_API', variable_get('xmppframework_api', ''));
11
12 /**
13 * Implementation of hook_help().
14 */
15 function xmppframework_help($path, $arg) {
16 $output = '';
17 switch ($path) {
18 case 'admin/modules#name':
19 $output = t('xmppframework');
20 break;
21 case 'admin/modules#description':
22 $output = t('Provides an xmpp framework for Drupal');
23 break;
24 case 'admin/help#xmppframework':
25 $output = '<p>'. t('The xmppframework module allows you to communicate with xmpp servers via specified transports') .'</p>';
26 break;
27 }
28 return $output;
29 }
30
31 /**
32 * Implementation of hook_perm()
33 */
34 function xmppframework_perm() {
35 return array('administer xmpp framework');
36 }
37
38 /**
39 * Implementation of hook_menu()
40 */
41 function xmppframework_menu() {
42 $items['admin/xmppframework'] = array(
43 'title' => 'XMPP Framework',
44 'access arguments' => array('administer xmpp framework'),
45 'description' => 'Administer and configure the xmpp framework',
46 'page callback' => 'system_admin_menu_block_page',
47 'file' => 'system.admin.inc',
48 'file path' => drupal_get_path('module', 'system'),
49 );
50 $items['admin/xmppframework/settings'] = array(
51 'title' => 'Settings',
52 'access arguments' => array('administer xmpp framework'),
53 'description' => 'XMPP Framework settings',
54 'page callback' => 'drupal_get_form',
55 'page arguments' => array('xmppframework_admin_settings'),
56 'file' => 'xmppframework.admin.inc',
57 );
58 return $items;
59 }
60
61 /**
62 * Retrieve all available xmpp apis
63 *
64 * @param $api
65 * The xmpp api we wish to retrieve the information about
66 * @param $property
67 * The property of the xmpp api we wish to find
68 * @param $refresh
69 * Determine whether we refresh the info cache or not
70 */
71 function xmppframework_apis($api = NULL, $property = NULL, $refresh = FALSE) {
72 static $info;
73 if (!$info || $refresh) {
74 $info = module_invoke_all('xmpp', 'info');
75 }
76 // checks to see if we are looking for specific information or not
77 if ($api && $property) {
78 return $info[$api][$property];
79 } elseif ($api) {
80 return $info[$api];
81 }
82 return $info;
83 }
84
85 /**
86 * Function will return a boolean depending on if the function is
87 * supported by the underlying transport protocol being initialized
88 *
89 * @param $op
90 * Operation we wish to perform
91 */
92 function xmppframework_underlying_function_exists($op = NULL) {
93 if (!$op) {
94 return FALSE;
95 }
96
97 // determine if the underlying api actually supports the operation
98 $info = xmppframework_apis(XMPPFRAMEWORK_API);
99 if ($info && function_exists($info['operation'])) {
100 $func = call_user_func($info['operation'], $op);
101 if ($func && function_exists($func)) {
102 return TRUE;
103 }
104 }
105 return FALSE;
106 }
107
108 /**
109 * Sends a message via the framework
110 *
111 * @param $to
112 * Jid of person receiving the message
113 * @param $type
114 * XMPP Type of message
115 * @param $body
116 * Body text of message
117 * @param $subject
118 * Subject of the message
119 */
120 function xmppframework_send_message($to, $type = 'chat', $body = null, $subject = null) {
121 $info = xmppframework_apis(XMPPFRAMEWORK_API);
122 if ($info && function_exists($info['operation'])) {
123 $func = call_user_func($info['operation'], 'send_message');
124 if ($func && function_exists($func)) {
125 if (!call_user_func($func, $to, $type, $body, $subject)) {
126 watchdog('xmppframework', t('Failed to send message to user %to', array('%to' => $to)), WATCHDOG_ERROR);
127 }
128 }
129 }
130 }
131
132 /**
133 * Deletes a user via the framework
134 *
135 * @param $name
136 * User Name
137 * @param $host
138 * Server
139 * @param $password
140 * User Password
141 */
142 function xmppframework_delete_account($name, $host, $password) {
143 $info = xmppframework_apis(XMPPFRAMEWORK_API);
144 if ($info && function_exists($info['operation'])) {
145 $func = call_user_func($info['operation'], 'delete_account');
146 if ($func && function_exists($func)) {
147 if (!call_user_func($func, $name, $host, $password)) {
148 watchdog('xmppframework', t('Failed to delete %user account from server', array('%user' => $name)), WATCHDOG_ERROR);
149 }
150 }
151 }
152 }
153
154 /**
155 * @param $name
156 * The name of the muc being created
157 * @param $service
158 * The conference server the muc will be created on
159 * @param $server
160 * The server the muc will be created on
161 * @param $title
162 * The description name for the room
163 */
164 function xmppframework_create_muc($name, $service, $server, $title) {
165 $info = xmppframework_apis(XMPPFRAMEWORK_API);
166 if ($info && function_exists($info['operation'])) {
167 $func = call_user_func($info['operation'], 'create_muc');
168 if ($func && function_exists($func)) {
169 if (!call_user_func($func, $name, $service, $server, $title)) {
170 watchdog('xmppframework', t('Failed to create muc: %name', array('%name' => $name)), WATCHDOG_ERROR);
171 }
172 }
173 }
174 }
175
176 /**
177 * @param $name
178 * The name of the muc being configured
179 * @param $service
180 * The conference server the muc resides on
181 * @param $server
182 * The server the muc resides on
183 * @param $title
184 * New title for the muc
185 */
186 function xmppframework_configure_muc($name, $service, $server, $title) {
187 $info = xmppframework_apis(XMPPFRAMEWORK_API);
188 if ($info && function_exists($info['operation'])) {
189 $func = call_user_func($info['operation'], 'configure_muc');
190 if ($func && function_exists($func)) {
191 if (!call_user_func($func, $name, $service, $server, $title)) {
192 watchdog('xmppframework', t('Failed to configure muc: %name', array('%name' => $name)), WATCHDOG_ERROR);
193 }
194 }
195 }
196 }
197
198 /**
199 * @param $name
200 * The name of the muc being created
201 * @param $service
202 * The conference server the muc will be created on
203 * @param $server
204 * The server the muc will be created on
205 */
206 function xmppframework_delete_muc($name, $service, $server) {
207 $info = xmppframework_apis(XMPPFRAMEWORK_API);
208 if ($info && function_exists($info['operation'])) {
209 $func = call_user_func($info['operation'], 'delete_muc');
210 if ($func && function_exists($func)) {
211 if (!call_user_func($func, $name, $service, $server)) {
212 watchdog('xmppframework', t('Failed to delete muc: %name', array('%name' => $name)), WATCHDOG_ERROR);
213 }
214 }
215 }
216 }
217
218 /**
219 * @param $uname
220 * XMPP User name
221 * @param $userver
222 * XMPP User server
223 * @param $cname
224 * Contact name
225 * @param $cserver
226 * Contact server
227 * @param $nick
228 * Nickname for contact
229 * @param $group
230 * Group for contact
231 * @param $subscription
232 * Subscription i.e. both, to, from, none
233 */
234 function xmppframework_add_rosteritem($uname, $userver, $cname, $cserver, $nick, $group, $subscription) {
235 $info = xmppframework_apis(XMPPFRAMEWORK_API);
236 if ($info && function_exists($info['operation'])) {
237 $func = call_user_func($info['operation'], 'add_rosteritem');
238 if ($func && function_exists($func)) {
239 if (!call_user_func($func, $uname, $userver, $cname, $cserver, $nick, $group, $subscription)) {
240 watchdog('xmppframework', t('Failed to add %cname to %uname roster', array('%cname' => $cname, '%uname' => $uname)), WATCHDOG_ERROR);
241 }
242 }
243 }
244 }
245
246 /**
247 * @param $uname
248 * XMPP User name
249 * @param $userver
250 * XMPP User server
251 * @param $cname
252 * Contact name
253 * @param $cserver
254 * Contact server
255 */
256 function xmppframework_delete_rosteritem($uname, $userver, $cname, $cserver) {
257 $info = xmppframework_apis(XMPPFRAMEWORK_API);
258 if ($info && function_exists($info['operation'])) {
259 $func = call_user_func($info['operation'], 'delete_rosteritem');
260 if ($func && function_exists($func)) {
261 if (!call_user_func($func, $uname, $userver, $cname, $cserver)) {
262 watchdog('xmppframework', t('Failed to delete %cname from %uname roster', array('%cname' => $cname, '%uname' => $uname)), WATCHDOG_ERROR);
263 }
264 }
265 }
266 }
267
268 /**
269 * Retrieve users vcard
270 *
271 * @param $user
272 * User we wish to retrieve the vcard for
273 *
274 * @return array with vcard information same structure as the array we send
275 */
276 function xmppframework_get_vcard($user = NULL) {
277 if (!$user) {
278 global $user;
279 }
280 $info = xmppframework_apis(XMPPFRAMEWORK_API);
281 if ($info && function_exists($info['operation'])) {
282 $func = call_user_func($info['operation'], 'get_vcard');
283 if ($func && function_exists($func)) {
284 $data = call_user_func($func);
285 // if data is not an array then there was an error when trying to retrieve the users vcard
286 if (!is_array($data)) {
287 watchdog('xmppframework', t('Failed to retrieve %user vcard from server', array('%user' => $user->name)), WATCHDOG_ERROR);
288 }
289 }
290 return $data;
291 }
292 return false;
293 }
294
295 /**
296 * Sets users vcard in the system
297 *
298 * @param $vcard
299 * Array containing the vcard
300 *
301 * Below is an example of the array structure being passed when sending vcard
302 * $vcard = array();
303 * $vcard['fn'] = 'Test Example User';
304 * $vcard['n'] = array('middle' => 'Example', 'first' => 'Test', 'Last' => 'User');
305 * $vcard['nickname'] = 'Herbert';
306 * $vcard['bday'] = '02/12/2001';
307 *
308 */
309 function xmppframework_set_vcard($vcard = array()) {
310 global $user;
311 $info = xmppframework_apis(XMPPFRAMEWORK_API);
312 if ($info && function_exists($info['operation'])) {
313 $func = call_user_func($info['operation'], 'set_vcard');
314 if ($func && function_exists($func)) {
315 if (!call_user_func($func, $vcard)) {
316 watchdog('xmppframework', t('Failed to set %user vcard', array('%user' => $user->name)), WATCHDOG_ERROR);
317 }
318 }
319 }
320 }
321
322 /**
323 * Gets users roster
324 *
325 * @param $user
326 * User object
327 */
328 function xmppframework_get_roster($user = NULL) {
329 $info = xmppframework_apis(XMPPFRAMEWORK_API);
330 if ($info && function_exists($info['operation'])) {
331 $func = call_user_func($info['operation'], 'get_roster');
332 if ($func && function_exists($func)) {
333 if (!($roster = call_user_func($func, $user))) {
334 watchdog('xmppframework', t('Failed to retrieve roster'), WATCHDOG_ERROR);
335 }
336 }
337 }
338 return $roster;
339 }
340
341 /**
342 * Gets the number of resources for a particular user
343 *
344 */
345 function xmppframework_get_user_resources() {
346 $info = xmppframework_apis(XMPPFRAMEWORK_API);
347 if ($info && function_exists($info['operation'])) {
348 $func = call_user_func($info['operation'], 'get_user_resources');
349 if ($func && function_exists($func)) {
350 $resources = call_user_func($func, $user);
351 if (!is_numeric($resources)) {
352 watchdog('xmppframework', t('Failed to retrieve the number of user resources'), WATCHDOG_ERROR);
353 }
354 }
355 }
356 return $resources;
357 }

  ViewVC Help
Powered by ViewVC 1.1.2