| 1 |
<?php
|
| 2 |
/*
|
| 3 |
* Gabbly.com Chat Integration
|
| 4 |
*
|
| 5 |
* @author: Mike Carter <ixis.co.uk/contact>
|
| 6 |
*/
|
| 7 |
|
| 8 |
// $Id$
|
| 9 |
|
| 10 |
define(CHAT_GABBLY_ROOMS, "Room 1\nRoom 2\nRoom 3");
|
| 11 |
|
| 12 |
function chat_gabbly_help($section) {
|
| 13 |
switch($section) {
|
| 14 |
case 'admin/modules#description':
|
| 15 |
return t('Integrate live chat on your site.');
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
function chat_gabbly_perm() {
|
| 20 |
return array('access chat');
|
| 21 |
}
|
| 22 |
|
| 23 |
function chat_gabbly_menu($may_cache) {
|
| 24 |
global $user;
|
| 25 |
$items = array();
|
| 26 |
|
| 27 |
if ($may_cache) {
|
| 28 |
$items[] = array(
|
| 29 |
'path' => 'chat', 'title' => t('chat'),
|
| 30 |
'callback' => 'chat_gabbly_page',
|
| 31 |
'access' => user_access('access chat'),
|
| 32 |
'type' => MENU_SUGGESTED_ITEM);
|
| 33 |
|
| 34 |
}
|
| 35 |
return $items;
|
| 36 |
}
|
| 37 |
|
| 38 |
function chat_gabbly_page() {
|
| 39 |
global $user;
|
| 40 |
$params = "&nick={$user->name}";
|
| 41 |
|
| 42 |
// Prevent logged in users from changing their username
|
| 43 |
if($user->uid != 0) {
|
| 44 |
$params .= '&dnc=true';
|
| 45 |
}
|
| 46 |
|
| 47 |
$site = variable_get('site_name', 'chat');
|
| 48 |
$room = (arg(1) != '') ? arg(1) : $site;
|
| 49 |
|
| 50 |
drupal_set_title(t('Room: %room', array('%room' => $room) ));
|
| 51 |
|
| 52 |
watchdog('chat', t('Entered the %room chat room', array('%room' => theme('placeholder', $room))),
|
| 53 |
WATCHDOG_NOTICE, l(t('Visit room'), 'chat/'.check_plain($room)) );
|
| 54 |
|
| 55 |
// Make the chat room private by obscuring the room name
|
| 56 |
if(variable_get('chat_gabbly_private', 0)) {
|
| 57 |
$room .= '_'.md5($site);
|
| 58 |
}
|
| 59 |
$params .= '&t=' . urlencode($site . ': ' . $room);
|
| 60 |
|
| 61 |
$params .= '&pw=' . variable_get('chat_gabbly_pw', '78');
|
| 62 |
|
| 63 |
return theme('chat_gabbly_widget', "http://cw.gabbly.com/gabbly/cw.jsp?e=1{$params}");
|
| 64 |
}
|
| 65 |
|
| 66 |
function chat_gabbly_settings() {
|
| 67 |
$form['chat_gabbly_private'] = array(
|
| 68 |
'#type' => 'checkbox',
|
| 69 |
'#title' => t('Make chat rooms private to site'),
|
| 70 |
'#default_value' => variable_get('chat_gabbly_private', 0),
|
| 71 |
'#description' => t("Prevents the chatroom(s) appearing on gabbly.com list."),
|
| 72 |
);
|
| 73 |
$form['chat_gabbly_pw'] = array(
|
| 74 |
'#type' => 'textfield',
|
| 75 |
'#title' => t('User List Width'),
|
| 76 |
'#default_value' => variable_get('chat_gabbly_pw', '78'),
|
| 77 |
'#description' => t('The width in pixels of the user list panel. The default width is 78, anything less than this means the user list is closed by default.')
|
| 78 |
);
|
| 79 |
|
| 80 |
return $form;
|
| 81 |
}
|
| 82 |
|
| 83 |
function chat_gabbly_block($op = 'list', $delta = 0, $edit = array()) {
|
| 84 |
switch($op) {
|
| 85 |
case 'list':
|
| 86 |
$blocks[0] = array('info' => t('Chat Rooms'),
|
| 87 |
'weight' => 0, 'enabled' => 0, 'region' => 'left');
|
| 88 |
/*$blocks[1] = array('info' => t('Chat Room Presence'),
|
| 89 |
'weight' => 0, 'enabled' => 0, 'region' => 'left');*/
|
| 90 |
return $blocks;
|
| 91 |
break;
|
| 92 |
|
| 93 |
case 'configure':
|
| 94 |
switch($delta) {
|
| 95 |
case '0':
|
| 96 |
$form['chat_gabbly_rooms'] = array(
|
| 97 |
'#type' => 'textarea',
|
| 98 |
'#rows' => 10,
|
| 99 |
'#title' => t('Chatrooms'),
|
| 100 |
'#default_value' => variable_get('chat_gabbly_rooms', CHAT_GABBLY_ROOMS),
|
| 101 |
'#description' => t('List names for your chatrooms, one room name per line.')
|
| 102 |
);
|
| 103 |
}
|
| 104 |
return $form;
|
| 105 |
break;
|
| 106 |
|
| 107 |
case 'save':
|
| 108 |
switch($delta) {
|
| 109 |
case 0:
|
| 110 |
variable_set('chat_gabbly_rooms', $edit['chat_gabbly_rooms']);
|
| 111 |
break;
|
| 112 |
}
|
| 113 |
break;
|
| 114 |
|
| 115 |
case 'view':
|
| 116 |
switch($delta) {
|
| 117 |
case 0:
|
| 118 |
if(user_access('access chat')) {
|
| 119 |
$rooms = variable_get('chat_gabbly_rooms', CHAT_GABBLY_ROOMS);
|
| 120 |
$room_list = explode("\n", $rooms);
|
| 121 |
|
| 122 |
// Turn each room in to a clickable link
|
| 123 |
foreach($room_list as $key => $room) {
|
| 124 |
$room_list[$key] = l($room, 'chat/'.check_plain($room));
|
| 125 |
}
|
| 126 |
|
| 127 |
$room_list = array(-1 => l(t('Lobby'), 'chat')) + $room_list;
|
| 128 |
|
| 129 |
$block['subject'] = t('Chat Rooms');
|
| 130 |
$block['content'] = theme('item_list', $room_list);
|
| 131 |
}
|
| 132 |
break;
|
| 133 |
|
| 134 |
case 1:
|
| 135 |
//<img src = 'http://www.gabbly.com/gabbly/presencebutton?t=peep' border = '0'>
|
| 136 |
break;
|
| 137 |
}
|
| 138 |
|
| 139 |
return $block;
|
| 140 |
break;
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
function theme_chat_gabbly_widget($url) {
|
| 145 |
return "<iframe id='chatgabbly' src='{$url}' scrolling='no' style='width:100%; height:300px' frameborder='0'><p>".t('Your browser needs frames support.')."</p></iframe>";
|
| 146 |
}
|