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

Contents of /contributions/modules/skypesupport/skypesupport.module

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


Revision 1.11 - (show annotations) (download) (as text)
Mon Jun 25 15:55:14 2007 UTC (2 years, 5 months ago) by fusion94
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
Changes since 1.10: +14 -21 lines
File MIME type: text/x-php
redid the admin settings menu to make compatible with 5.x series
1 <?php
2 // $Id: skypesupport.module,v 1.10 2007/06/24 22:23:16 fusion94 Exp $
3
4 /**
5 * w00t skype support
6 * Maintainers: Steve McKenzie - steve [at] stevemckenzie.ca
7 * Tony Guntharp - fusion94 [at] damagestudios.net
8 * Special Thanks: mozillaman for the idea, finding the php class and making it work!
9 */
10
11 /**
12 * Implementation of hook_help()
13 */
14 function skypesupport_help($section) {
15 switch ($section) {
16 case 'admin/help#skypesupport':
17 return t('To use this module, it is recommended that you have the latest version of <a href="http://www.skype.com" title="Skype">Skype</a>. You also <strong>must</strong> have the setting "Allow My Status To Be Shown On The Web" enabled which is located under the Privacy Preferences in Skype.');
18 break;
19 case 'admin/modules#description':
20 return t('Adds ability to offer live support via <a href="http://www.skype.com" title="Skype">Skype</a>');
21 break;
22 }
23 }
24
25 /**
26 * Implementation of hook_perm()
27 */
28 function skypesupport_perm() {
29 return array('administer skype support users', 'provide skype support');
30 }
31
32
33 /**
34 * Implementation of hook_menu()
35 */
36 function skypesupport_menu($may_cache) {
37 $items = array();
38
39 $items[] = array(
40 'path' => variable_get('skypesupport_page_path', 'skypesupport'),
41 'title' => t('skype support'),
42 'callback' => 'skypesupport_page',
43 'access' => user_access("access content"),
44 'type' => MENU_SUGGESTED_ITEM
45 );
46
47 $items[] = array(
48 'path' => 'admin/settings/skypesupport',
49 'title' => t('Skype Support'),
50 'description' => t('Allows users to be labeled as support users for providing support via Skype.'),
51 //'callback' => 'skypesupport_admin',
52 'callback' => 'drupal_get_form',
53 'callback arguments' => array('skypesupport_admin'),
54 'access' => user_access("administer skype support users"),
55 'type' => MENU_NORMAL_ITEM
56 );
57
58
59
60 return $items;
61 }
62
63 /**
64 * Implementation of hook_settings()
65 */
66 function skypesupport_settings() {
67 $form['basic_module_settings'] = array('#type' => 'fieldset', '#title' => t('Basic Settings'), '#collapsible' => true);
68 $form['basic_module_settings']['skypesupport_page_path'] = array('#type' => 'textfield',
69 '#title' => t('Skype Support Page Path'),
70 '#size' => 40,
71 '#default_value' => variable_get('skypesupport_page_path', 'skypesupport')
72 );
73
74 return $form;
75 }
76
77 /**
78 * Implementation of hook_user()
79 */
80 function skypesupport_user($op, &$edit, &$account, $category = NULL) {
81 global $user;
82
83 $access = user_access('provide skype support', $account);
84
85 switch($op) {
86 // handle permissions
87 case 'form':
88 $users = variable_get('skypesupport_users', NULL);
89 $skype = skypesupport_check_user($account, true);
90 if ($access) {
91 if (!empty($users)) {
92 if (!$skype) {
93 $users[] = $account->uid;
94 variable_set('skypesupport_users', $users);
95 }
96 } else {
97 variable_set('skypesupport_users', array($account->uid));
98 }
99 }
100 break;
101 // handle single user status if a support user
102 case 'view':
103 if ($skype = skypesupport_check_user($account)) {
104 theme('skypesupport_css');
105 $output = theme('skypesupport_user', $account, $skype);
106 $items[] = array('class' => 'skype_support_user', 'value' => $output);
107 return array(t('Skype Support') => $items);
108 } elseif($skype = skypesupport_check_user($account, true)) {
109 theme('skypesupport_css');
110 $output = theme('skypesupport_user_status', $account, $skype);
111 $items[] = array('class' => 'skype_support_user', 'value' => $output);
112 return array(t('Skype Support') => $items);
113 }
114 break;
115 }
116 }
117
118 /**
119 * Implementation of hook_form_alter()
120 */
121 function skypesupport_form_alter($form_id, &$form) {
122 if ($form_id == 'user_edit' && $form['account']) {
123 $user = user_load(array('uid' => arg(1)));
124 $support_users = variable_get('skypesupport_users', NULL);
125 if (!empty($support_users)) {
126 foreach ($support_users as $uid => $key) {
127 if ($uid == $user->uid) {
128 $form['skype_info'] = array('#type' => 'fieldset', '#collapsible' => true, '#title' => t('Skype Information'));
129 $form['skype_info']['skype_name'] = array('#type' => 'textfield',
130 '#title' => t('Skype User Name'),
131 '#size' => 20,
132 '#default_value' => $user->skype_name
133 );
134 $form['skype_info']['available_skype_status'] = array('#type' => 'select',
135 '#title' => t('Available Status in Support'),
136 '#multiple' => true,
137 '#description' => t('Hold ctrl (command) and click at the same time to add multiple users'),
138 '#default_value' => ($user->available_skype_status) ? $user->available_skype_status : 7, // default is skype me
139 '#options' => skypesupport_status_list()
140 );
141 }
142 }
143 }
144 }
145 }
146
147 /**
148 * Implementation of hook_block()
149 */
150 function skypesupport_block($op = 'list', $delta = 0, $edit = array()) {
151 switch ($op) {
152 case 'list':
153 $blocks[]['info'] = t('Skype Support');
154 return $blocks;
155 break;
156
157 case 'view':
158 theme('skypesupport_css');
159 switch ($delta) {
160 case 0:
161 $users = variable_get('skypesupport_users', NULL);
162 $block['subject'] = t('Skype Support');
163 $block['content'] = theme('skypesupport_user_list', $users);
164 break;
165 }
166 return $block;
167 break;
168 }
169 }
170
171 /**
172 * admin page to choose users
173 */
174
175 function skypesupport_admin() {
176
177 $form['available_users'] = array('#type' => 'fieldset', '#title' => t('Support Users'), '#description' => t('Choose which users to be listed as support users'), '#collapsible' => true);
178 $form['available_users']['skypesupport_users'] = array('#type' => 'select',
179 '#multiple' => true,
180 '#title' => t('Users'),
181 '#description' => t('Hold ctrl (command) and click at the same time to add multiple users'),
182 '#default_value' => variable_get('skypesupport_users', NULL),
183 '#options' => skypesupport_user_list()
184 );
185
186 return system_settings_form($form);
187 }
188
189 /**
190 * available skype statuses
191 */
192 function skypesupport_status_list() {
193 // the order of these items must not change as their index value is what is required by the Skype API
194 return array('Unknown', 'Offline', 'Online', 'Away', 'Not Available', 'Do Not Disturb', 'Invisible', 'Skype Me');
195 }
196
197 /**
198 * get a list of users (only uid & name) to generate a selectbox on the admin page
199 */
200 function skypesupport_user_list() {
201 $result = db_query("SELECT uid, name FROM {users} ORDER BY name");
202
203 while($row = db_fetch_object($result)) {
204 if ($row->name && $row->uid > 0) {
205 $users[$row->uid] = $row->name;
206 }
207 }
208
209 return $users;
210 }
211
212 /**
213 * main page to show available support users
214 */
215 function skypesupport_page() {
216 theme('skypesupport_css');
217
218 $users = variable_get('skypesupport_users', NULL);
219 $output .= theme('skypesupport_user_list', $users);
220
221 echo theme('page', $output);
222 }
223
224 /**
225 * main function to check if a user is a support user and also if a user is available for support requests
226 */
227 function skypesupport_check_user($user, $support_user = false) {
228 $support_users = variable_get('skypesupport_users', NULL);
229 if (!empty($support_users)) {
230 foreach ($support_users as $key => $uid) {
231 if ($user->uid == $uid && $user->skype_name) {
232 require_once('skypesupport.inc');
233 $user_status = new phpSkypeStatus($user->skype_name);
234 if ($support_user) { return $user_status; }
235 if (!empty($user->available_skype_status)) {
236 foreach ($user->available_skype_status as $index => $status) {
237 if ($status == $user_status->getNum()) {
238 return $user_status;
239 }
240 }
241 }
242 }
243 }
244 }
245 }
246
247 /**
248 * themables
249 */
250
251 function theme_skypesupport_css() {
252 global $base_url;
253
254 drupal_set_html_head(theme('stylesheet_import', $base_url .'/'. drupal_get_path('module', 'skypesupport').'/skypesupport.css'));
255 }
256
257 function theme_skypesupport_user_list($users) {
258 $user_count = 0;
259
260 $output .= '<div class="skypesupport_available">'. t('Users Available For Support') .'</div>';
261 $output .= '<ul class="skypesupport_user_list">';
262
263 if (!empty($users)) {
264 foreach ($users as $key => $uid) {
265 $user = user_load(array('uid' => $uid));
266 $skype = skypesupport_check_user($user);
267 if ($skype) {
268 $output .= '<li>'. theme('skypesupport_user', $user, $skype) .'</li>';
269 $user_count++;
270 }
271 }
272 }
273
274 if ($user_count == 0) {
275 $output .= '<li>'. t('Currently No Users Available For Support') .'</li>';
276 }
277
278 $output .= '</ul>';
279
280 return $output;
281 }
282
283 function theme_skypesupport_user($user, $user_status) {
284 $output .= '<div class="skype_user">';
285 $output .= theme('skypesupport_user_status', $user, $user_status);
286 $output .= ' <a class="skypesupport_add_user" href="skype:'. $user->skype_name .'?add" title="'. t('add') .'">'. t('[add]') .'</a>';
287 $output .= ' <a class="skypesupport_userinfo_user" href="skype:'. $user->skype_name .'?userinfo" title="'. t('userinfo') .'">'. t('[userinfo]') .'</a>';
288 $output .= ' <a class="skypesupport_chat_user" href="skype:'. $user->skype_name .'?chat" title="'. t('chat') .'">'. t('[message]') .'</a>';
289 $output .= ' <a class="skypesupport_call_user" href="skype:'. $user->skype_name .'?call" title="'. t('call') .'">'. t('[call]') .'</a>';
290 $output .= '<br class="clear" />';
291 $output .= '</div>';
292
293 return $output;
294 }
295
296 function theme_skypesupport_user_status($user, $user_status) {
297 if ($user->skype_name) {
298 $language = ($user->language) ? '('. $user->language .')' : '';
299 return l($user->name, "user/$user->uid") .' is currently set to <img src="'. $user_status->getImagePath() .'" /> <em class="skype_support_user_status">'. $user_status->getText() .'</em> ' .$language;
300 }
301 }

  ViewVC Help
Powered by ViewVC 1.1.2