/[drupal]/contributions/modules/chatroom/chatroom.theme.inc
ViewVC logotype

Contents of /contributions/modules/chatroom/chatroom.theme.inc

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


Revision 1.5 - (show annotations) (download) (as text)
Fri Nov 6 16:56:18 2009 UTC (2 weeks, 6 days ago) by justinrandell
Branch: MAIN
Changes since 1.4: +106 -100 lines
File MIME type: text/x-php
sync up HEAD with 6.x-2 BETA 1
1 <?php
2 // $Id: chatroom.theme.inc,v 1.3.2.21 2009/11/06 16:42:57 justinrandell Exp $
3
4 /**
5 * $file
6 * Theme functions for chatroom.module.
7 */
8
9 /**
10 * Implementation of hook_theme().
11 */
12 function chatroom_theme($existing, $type, $theme, $path) {
13 // Add the path to our module folder so we can pick up popout template.
14 $page = $existing['page'];
15 $page['theme paths'][] = drupal_get_path('module', 'chatroom');
16 return array(
17 'page' => $page,
18 'chatroom_allowed_users_list' => array(
19 'arguments' => array('allowed_users'),
20 ),
21 'chatroom_allowed_user' => array(
22 'arguments' => array('allowed_user'),
23 ),
24 'chatroom_block_chats' => array(
25 'arguments' => array(),
26 ),
27 'chatroom_latest_message' => array(
28 'arguments' => array(
29 'message',
30 ),
31 ),
32 'chatroom_block_chatrooms' => array(
33 'arguments' => array(),
34 ),
35 'chatroom_message' => array(
36 'arguments' => array(
37 'message',
38 'node',
39 ),
40 ),
41 'chatroom_user_list' => array(
42 'arguments' => array(
43 'users',
44 'chat',
45 ),
46 ),
47 'chatroom_chat_kicked_user' => array(
48 'arguments' => array(
49 'node',
50 ),
51 ),
52 'chatroom_chat_banned_user' => array(
53 'arguments' => array(
54 'node',
55 ),
56 ),
57 'chatroom_list' => array(
58 'arguments' => array(
59 'tree',
60 ),
61 ),
62 'chatroom_chat' => array(
63 'arguments' => array(
64 'chat',
65 ),
66 ),
67 'chatroom_chat_archive' => array(
68 'arguments' => array(
69 'chat',
70 ),
71 ),
72 'chatroom_buttons' => array(
73 'arguments' => array(
74 'chat' => NULL,
75 ),
76 ),
77 'chatroom_chat_teaser' => array(
78 'arguments' => array(
79 'node',
80 ),
81 ),
82 'chatroom_teaser' => array(
83 'arguments' => array(
84 'node',
85 ),
86 ),
87 );
88 }
89
90 /**
91 * Theme the site-wide chat list block.
92 *
93 * @ingroup themeable
94 */
95 function theme_chatroom_block_chats() {
96 $content = '<ul class="menu" id="chatroom-sitewide-chats">';
97 if ($chats = chatroom_get_active_chats()) {
98 $total = variable_get('chatroom_block_chats', 5);
99 foreach ($chats as $number => $node) {
100 if ($number == $total) {
101 break;
102 }
103 $id = "chatroom-block-chats-$node->nid";
104 $content .= '<li id="' . $id .'">'. l($node->title, "node/$node->nid");
105 if (isset($chat->chatroom)) {
106 $room_link = l($node->chatroom->title, "node/$node->chatroom->nid");
107 $content .= '<br /><span class="chatroomLink">'. t('in') .' '. $room_link .'</span>';
108 }
109 if ($node->chat->popout) {
110 chatroom_set_popout_link_js($node, "#$id");
111 $content .= '<br />(' . t('This chat will load in a popout window.') . ')';
112 }
113 $content .= '</li>';
114 }
115 }
116 else {
117 $content .= '<li id="chat_empty"><em>'. t('There are no active chats.') .'</em></li>';
118 }
119 $content .= '</ul>';
120 return array(
121 'content' => $content,
122 'subject' => t('Active chats'),
123 );
124 }
125
126 /**
127 * Theme the chat room list block.
128 *
129 * @ingroup themeable
130 */
131 function theme_chatroom_block_chatrooms() {
132 $content = '<ul class="menu" id="chatroom-sitewide-chatrooms">';
133 $rooms = chatroom_get_active_chatrooms();
134 if (empty($rooms)) {
135 $content .= '<li id="chatroom_empty"><em>'. t('There are no active chat rooms.') .'</em></li>';
136 }
137 else {
138 $total = variable_get('chatroom_block_chatrooms', 5);
139 foreach ($rooms as $number => $room) {
140 if ($number == $total) {
141 break;
142 }
143 $content .= '<li id="chatroom_'. $room->nid .'">'. l($room->title, "node/$room->nid") .'</li>';
144 }
145 }
146 $content .= '</ul>';
147 return array(
148 'content' => $content,
149 'subject' => t('Active chat rooms'),
150 );
151 }
152
153 /**
154 * Format an array of messages.
155 *
156 * @ingroup themeable
157 */
158 function theme_chatroom_messages(array $messages, $node) {
159 $output = '';
160 foreach($messages as $message) {
161 $output .= theme('chatroom_message', $message, $node);
162 }
163 return $output;
164 }
165
166 /**
167 * Format a single message for display.
168 *
169 * @param mixed $message
170 * @param mixed $node
171 * @return string
172 */
173 function theme_chatroom_message($message, $node) {
174 if ($message->uid) {
175 $username = l($message->name, 'user/'. $message->uid);
176 }
177 else {
178 $username = $message->name;
179 }
180 $class = "chatroom-msg new-message" . ($message->msg_type == 'private_message' ? ' chatroom-private' : '');
181 $output = '<div class="' . $class . '">';
182 $output .= '(' . format_date($message->modified, 'custom', variable_get('chatroom_msg_date_format', 'H:i:s')) . ') <strong>' . $username . ':</strong> ';
183 $output .= check_markup($message->msg, $node->format, FALSE);
184 $output .= '</div>';
185 return $output;
186 }
187
188 /**
189 * Format the list of users in a chatroom.
190 *
191 * @ingroup themeable
192 */
193 function theme_chatroom_user_list($users, $chat) {
194 global $user;
195 $html = '<ul id="chatroom-user-list">';
196 if (!empty($users)) {
197 foreach ($users as $chat_user) {
198 $class = 'chatroom-user' . ($chat_user->sid == session_id() ? ' chatroom-current-user' : '');
199 $html .= '<li class="' . $class . '">' . theme('username', $chat_user);
200 if ($chat->chat->profile_picture) {
201 $size = variable_get('chatroom_profile_picture_preset', 0);
202 if (module_exists('imagecache') && $size && $chat_user->uid) {
203 $preset = imagecache_preset($size);
204 $alt = t("@user's picture", array('@user' => $chat_user->name));
205 $chat_user->picture = theme('imagecache', $preset['presetname'], $chat_user->picture, $alt, $alt);
206 $html .= $chat_user->picture . theme('username', $chat_user);
207 }
208 else {
209 $html .= theme('user_picture', $chat_user);
210 }
211 }
212 $html.= '</li>';
213 }
214 }
215 $html .= '</ul>';
216 return $html;
217 }
218
219 /**
220 * Format a message for display in a summary table.
221 */
222 function theme_chatroom_latest_message($message) {
223 $output = $message->msg .'<br />';
224 $output .= t('Posted by <strong>!user</strong> on !date', array(
225 '!user' => $message->uid ? l($message->name, "user/$message->uid") : variable_get('chatroom_guest_user_prefix', t('guest-')) . $message->guest_id,
226 '!date' => format_date($message->modified, 'medium'),
227 ));
228 return $output;
229 }
230
231 /**
232 * Format the chat room listing.
233 *
234 * @ingroup themeable
235 */
236 function theme_chatroom_display($tree) {
237 global $user;
238 // chat room list, chats list, and 'add new chat' link
239
240 if (!empty($tree)) {
241 $output = '<div id="chatroom">';
242 $output .= '<ul>';
243
244 if (user_access('create chat rooms')) {
245 $output .= '<li>'. l(t('Post a new chat room.'), "node/add/chatroom") .'</li>';
246 }
247 else if ($user->uid) {
248 //
249 }
250 else {
251 $output .= '<li>'. t('<a href="!login">Login</a> to post a new chat room.', array('!login' => url('user/login'))) .'</li>';
252 }
253 $output .= '</ul>';
254 $output .= theme('chatroom_list', $tree);
255 $output .= '</div>';
256 }
257 else {
258 drupal_set_title(t('No chat rooms defined'));
259 $output = '';
260 }
261
262 return $output;
263 }
264
265 /**
266 * Format the chat room table.
267 *
268 * @ingroup themeable
269 */
270 function theme_chatroom_list($rooms) {
271 global $user;
272
273 if ($rooms) {
274 $header = array(t('Chat room'), t('Chats'), t('Messages'), t('Last message'));
275 foreach ($rooms as $room) {
276 $description = "<div>\n";
277 $description .= ' <div class="name">'. l($room->title, "node/$room->nid") .'</div>';
278
279 if ($room->body) {
280 $description .= ' <div class="description">'. $room->body ."</div>\n";
281 }
282 $description .= "</div>\n";
283
284 $rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => '4'));
285
286 if (isset($room->chatroom->chats)) {
287 foreach ($room->chatroom->chats as $id => $chat) {
288 $description = "<div>\n";
289 $description .= ' <div class="name">'. l($chat->chatname, "chatroom/chat/$chat->ccid") ."</div>\n";
290 $description .= "</div>\n";
291
292 $row[] = array('data' => '&nbsp;');
293 $row[] = array('data' => $description, 'class' => 'chatroom-chat');
294 $row[] = array('data' => $chat->msg_count, 'class' => 'chatroom-msg-count');
295 $row[] = array('data' => $chat->msg_info, 'class' => 'chatrom-msg-info');
296 $rows[] = $row;
297 unset($row);
298 }
299 }
300 }
301 return theme('table', $header, $rows);
302 }
303 }
304
305 /**
306 * Get HTML for kick message.
307 *
308 * @ingroup themeable
309 */
310 function theme_chatroom_chat_kicked_user($node) {
311 $msg = $node->chat->kicked_out_message ? $node->chat->kicked_out_message : t('You have been kicked out of %chat for misbehaving.', array('%chat' => $node->title));
312 return '<div id="chatroom-kicked-msg">'. $msg .'</div>';
313 }
314
315 /**
316 * Get HTML for ban message.
317 *
318 * @ingroup themeable
319 */
320 function theme_chatroom_chat_banned_user($chat) {
321 $msg = $node->chat->banned_message ? $node->chat->banned_message : t('You have been banned from %chat for misbehaving.', array('%chat' => $node->title));
322 return '<div id="chatroom-banned-msg">'. $msg .'</div>';
323 }
324
325 /**
326 * Theme a chat.
327 *
328 * @ingroup themeable
329 */
330 function theme_chatroom_chat($node) {
331 global $user;
332
333 $output = theme('chatroom_user_list', $node->chat->users, $node);
334 $output .= '<div id="chatroom-board">';
335 foreach (chatroom_chat_load_messages($node->nid, 0, 20) as $message) {
336 $output .= theme('chatroom_message', $message, $node);
337 }
338 $output .= '</div>';
339 $output .= theme('chatroom_buttons', $node);
340 if ($node->chat->private && ($node->uid == $user->uid || user_access('administer chats'))) {
341 $output .= drupal_get_form('chatroom_chat_user_manager_form', $node);
342 }
343 if (user_access('administer chats') || user_access('administer chat rooms')) {
344 $output .= drupal_get_form('chatroom_archive_chat_form', $node->nid);
345 }
346 return $output;
347 }
348
349 /**
350 * Theme chat buttons.
351 *
352 * @ingroup themeable
353 */
354 function theme_chatroom_buttons($chat) {
355 return '<div id="chatroom-chat-buttons"><input id="chatroom-chat-message-submit" type="text" value="" /></div>';
356 }
357
358 /**
359 * Theme the chat archive page.
360 *
361 * @ingroup themeable
362 */
363 function theme_chatroom_chat_archive($node) {
364 global $user;
365
366 $is_admin = user_access('administer chats') || user_access('administer chat rooms');
367
368 $html = '<p>' . t('Archived on !date.', array('!date' => format_date($node->chat->when_archived, 'medium'))) . '</p>';
369 $html .= '<div id="chatroom-container-archive">';
370 if ($messages = chatroom_chat_load_messages($node->nid)) {
371 $table_rows = array();
372 foreach ($messages as $msg) {
373 $name = isset($msg->name) ? $msg->name : variable_get('chatroom_guest_user_prefix', t('guest-')) . $msg->guest_id;
374 if (empty($msg->recipient_uid)) {
375 $row_html = '<span class="chatroom-archive-date">'. format_date($msg->modified, 'small') .'</span>';
376 $row_html .= '<span class="chatroom-old-msg"><span class="header">' . "$name:</span>$msg->msg</span>";
377 }
378 else if ($is_admin || $user->uid == $msg->uid || $user->uid == $msg->recipient_uid) {
379 $row_html = '<span class="chatroom-archive-date">'. format_date($msg->modified, 'small') .'</span>';
380 $row_html .= '<span class="chatroom-old-msg">';
381 $row_html .= '<span class="header">' . "$name ";
382 if ($msg->uid == $user->uid && $recipient != $name) {
383 $row_html .= '<span class="chatroom-private">(privately to '. $recipient .')</span>:</span> ';
384 }
385 else {
386 $row_html .= '<span class="chatroom-private">(privately)</span>:</span> ';
387 }
388 $row_html .= $msg->msg . '</span>';
389 }
390 $table_rows[] = array($row_html);
391 }
392 $html .= theme('table', array(), $table_rows);
393 }
394 else {
395 $html .= '<p>' . t('This chat contains no messages.') . '</p>';
396 }
397 $html .= '</div>';
398 return $html;
399 }
400
401 /**
402 * Implementation of hook_preprocess_page().
403 */
404 function chatroom_preprocess_page(&$vars) {
405 // Add a template hint for the popout page template.
406 if (isset($vars['node']) && arg(2) != 'edit' && $vars['node']->type == 'chat') {
407 if ($vars['node']->chat->popout && $vars['node']->chat->when_archived === NULL) {
408 $vars['template_files'] = array('page-chat-popout');
409 }
410 }
411 }
412
413 /**
414 * Theme the teaser for a chat node.
415 */
416 function theme_chatroom_chat_teaser($node) {
417 if ($node->chat->when_archived) {
418 $params = array(
419 '!date' => format_date($node->chat->when_archived, 'medium'),
420 '%message_count', $node->chat->msg_count,
421 );
422 return t('Archived on !date, contains %message_count messages.', $params);
423 }
424 else {
425 if ($node->chat->latest_msg) {
426 $popout_text = '';
427 if ($node->chat->popout) {
428 chatroom_set_popout_link_js($node, "#node-$node->nid h2");
429 $popout_text = t('This chat will load in a popout window.');
430 }
431 $params = array(
432 '!date' => format_date($node->chat->latest_msg->modified, 'medium'),
433 '%message' => $node->chat->latest_msg->msg,
434 '!user' => theme('username', user_load($node->chat->latest_msg->uid)),
435 '%message_count' => $node->chat->msg_count,
436 );
437 return t("Last message at !date: %message by !user. Total messages: %message_count. $popout_text", $params);
438 }
439 else {
440 return t('There are no messages in this chat.');
441 }
442 }
443 }
444
445 /**
446 * Theme the teaser for a chatroom node.
447 */
448 function theme_chatroom_teaser($node) {
449 $params = array(
450 '%open_chats' => count($node->chatroom->chats),
451 );
452 return t('There are %open_chats chats in this chatroom.', $params);
453 }
454
455 /**
456 * Theme the user list widget.
457 *
458 * @param mixed $allowed_users
459 * @return string
460 */
461 function theme_chatroom_allowed_users_list($allowed_users) {
462 $html = '<ul id="chatroom_allowed_users_list">';
463 foreach ($allowed_users as $allowed_user) {
464 $html .= '<li id="chatroom_allowed_user_li_' . $allowed_user->uid . '">' . theme('chatroom_allowed_user', $allowed_user) . '</li>';
465 }
466 $html .= '</ul>';
467 return $html;
468 }
469
470 /**
471 * Theme an item in the allowed user list.
472 *
473 * @param mixed $allowed_user
474 * @return string
475 */
476 function theme_chatroom_allowed_user($allowed_user) {
477 return theme('username', $allowed_user)
478 . ' [<a id="chatroom_allowed_user_' . $allowed_user->uid
479 . '" class="chatroom-remove-user" href="#remove">'
480 . 'Click here to remove from chat.</a>]';
481 }
482

  ViewVC Help
Powered by ViewVC 1.1.2