Moderators: OldWolf, re*s.t.a.r.s.*2
/**
* Implementation of hook_block().
* S M Mahbub Murshed, June 26, 2007
*/
function phpfreechat_block($op = 'list', $delta = 0, $edit = array()) {
global $user, $base_url;
if ($op == 'list') {
$block[0]['info'] = t('Who is chatting');
$block[1]['info'] = t('Who is chatting on...');
$block[2]['info'] = t('Latest from...');
$block[3]['info'] = t('Active channels');
return $block;
}
else if ($op == 'configure' && $delta > 0) {
$form['phpfreechat_block'] = array(
'#type' => 'textfield',
'#title' => t('Channel Name'),
'#default_value' => variable_get('phpfreechat_block_channel_'.$delta, ''),
'#description' => t('Enter the channel name to use')
);
return $form;
}
else if ($op == 'save' && $delta > 0) {
variable_set('phpfreechat_block_channel_'.$delta, $edit['phpfreechat_block']);
}
else if ($op == 'view') {
if (user_access('access content')) {
if (!phpfreechat_check_install()) {
$block['content'] = phpfreechat_not_found();
return $block;
}
$params = phpfreechat_load_params();
require_once 'phpfreechat/src/pfcinfo.class.php';
$info = new pfcInfo(md5($base_url), $params['data_private_path']);
if ($delta == 0) {
$users = $info->getOnlineNick(NULL);
$nd_users = count($users);
$block['content'] .= theme_item_list($users);
$block['subject'] = t('who is chatting').' ('.t($nd_users).')';
}
if ($delta == 1) {
$channel = variable_get('phpfreechat_block_channel_1', '');
$users = $info->getOnlineNick($channel);
$nd_users = count($users);
$block['content'] .= theme_item_list($users);
$block['subject'] = t('who is chatting on ').$channel.' ('.t($nd_users).')';
}
if ($delta == 2) {
$channel = variable_get('phpfreechat_block_channel_2', '');
$lastmsg_raw = $info->getLastMsg($channel, 10);
$output = '';
foreach($lastmsg_raw["data"] as $m) {
$output .= $m["sender"].': ';
$output .= '<em>' . $m["param"].'</em><br />';
$date = $m["date"];
$time = $m["time"];
}
$output .= t('Last chat: ');
// Convert to US style date
$date = preg_replace("/^s*([0-9]{1,2})[/. -]+([0-9]{1,2})[/. -]+([0-9]{1,4})/", "\2/\1/\3", $date);
$output .= format_interval(time() - strtotime($date.' '.$time));
$output .= t(' ago');
$block['content'] .= $output;
$block['subject'] = t('latest from ').$channel;
}
if ($delta == 3) {
if(is_array($params['channels'])) {
$nd_chan = count($params['channels']);
for($i = 0; $i < $nd_chan; $i++) {
$users = $info->getOnlineNick($params['channels'][$i]);
$nd_users = count($users);
$block['content'] .= $params['channels'][$i].' ('.t($nd_users).')';
$block['content'] .= theme_item_list($users);
if($i!=$nd_chan-1)
$block['content'] .= '<br />';
}
}
else {
$users = $info->getOnlineNick($params[0]['channels']);
$nd_users = count($users);
$block['content'] .= $params['channels'].' ('.t($nd_users).')';
$block['content'] .= theme_item_list($users);
}
$block['subject'] = t('Active channels');
}
return $block;
}
}
}
/**
* Implementation of hook_block().
* S M Mahbub Murshed June 26, 2007
* udvranto@yahoo.com
*/
function phpfreechat_block($op = 'list', $delta = 0, $edit = array()) {
global $user, $base_url;
if ($op == 'list') {
$block[0]['info'] = t('Who is chatting');
$block[1]['info'] = t('Who is chatting on...');
$block[2]['info'] = t('Latest from...');
$block[3]['info'] = t('Active channels');
return $block;
}
else if ($op == 'configure' && $delta > 0) {
$form['phpfreechat_block'] = array(
'#type' => 'textfield',
'#title' => t('Channel Name'),
'#default_value' => variable_get('phpfreechat_block_channel_'.$delta, ''),
'#description' => t('Enter the channel name to use')
);
return $form;
}
else if ($op == 'save' && $delta > 0) {
variable_set('phpfreechat_block_channel_'.$delta, $edit['phpfreechat_block']);
}
else if ($op == 'view') {
if (user_access('access content')) {
if (!phpfreechat_check_install()) {
$block['content'] = phpfreechat_not_found();
return $block;
}
$params = phpfreechat_load_params();
require_once 'phpfreechat/src/pfcinfo.class.php';
$info = new pfcInfo(md5($base_url), $params['data_private_path']);
if ($delta == 0) {
$users = $info->getOnlineNick(NULL);
$nd_users = count($users);
$block['content'] .= theme_item_list($users);
$block['subject'] = t('who is chatting').' ('.t($nd_users).')';
}
if ($delta == 1) {
$channel = variable_get('phpfreechat_block_channel_1', '');
$users = $info->getOnlineNick($channel);
$nd_users = count($users);
$block['content'] .= theme_item_list($users);
$block['subject'] = t('who is chatting on ').$channel.' ('.t($nd_users).')';
}
if ($delta == 2) {
$channel = variable_get('phpfreechat_block_channel_2', '');
$lastmsg_raw = $info->getLastMsg($channel, 10);
$output = '';
foreach($lastmsg_raw["data"] as $m) {
$output .= $m["sender"].': ';
$output .= '<em>' . $m["param"].'</em><br />';
$date = $m["date"];
$time = $m["time"];
}
$output .= t('Last chat: ');
// Convert to US style date
$date = preg_replace("/^s*([0-9]{1,2})[/. -]+([0-9]{1,2})[/. -]+([0-9]{1,4})/", "\2/\1/\3", $date);
$output .= format_interval(time() - strtotime($date.' '.$time));
$output .= t(' ago');
$block['content'] .= $output;
$block['subject'] = t('latest from ').$channel;
}
if ($delta == 3) {
$channels = db_query('SELECT nid, phpfreechat_title FROM {phpfreechat} WHERE phpfreechat_enabled = 1 ORDER BY nid DESC');
while ($channel = db_fetch_object($channels)) {
$users = $info->getOnlineNick($channel->phpfreechat_title);
$nd_users = count($users);
$block['content'] .= l($channel->phpfreechat_title, 'node/'. $channel->nid, array('title' => t('Chat on %channel',array('%channel' => $channel->phpfreechat_title)))).' ('.t($nd_users).')';
$block['content'] .= theme_item_list($users);
}
$block['subject'] = t('Active channels');
}
return $block;
}
}
}
Return to Joomla, Drupal, and Wordpress (v1.x)
Users browsing this forum: No registered users and 12 guests