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