• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Joomla, Drupal, and Wordpress (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

List of open/active channels

Integration help for Joomla, Drupal, and Wordpress

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
3 posts • Page 1 of 1

Postby udvranto » Mon Jun 25, 2007 4:55 am

Hi I am trying to display the list of open/active channels through the drupal module. How can I get them and insert a link on it.
udvranto
Member
 
Posts: 15
Joined: Mon Jun 25, 2007 4:45 am
Top

Postby udvranto » Tue Jun 26, 2007 8:18 pm

I solved the problem partially. I added another block for active channels. But I would like to add a link to the correct node where the channel is. I don't know how to do it.

Heres is the modified phpfreechat_block function. I don't know why it is happening, but the $params['channels'] is not and array! That why I did what I did in my code. Obviously I am new in PHP. I have only one active channel.

Code: Select all
/**
* 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;
    }
  }
}
udvranto
Member
 
Posts: 15
Joined: Mon Jun 25, 2007 4:45 am
Top

Postby udvranto » Tue Jun 26, 2007 9:17 pm

Alright this one works perfectly:

Code: Select all
/**
 * 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;
    }
  }
}
udvranto
Member
 
Posts: 15
Joined: Mon Jun 25, 2007 4:45 am
Top


Post a reply
3 posts • Page 1 of 1

Return to Joomla, Drupal, and Wordpress (v1.x)

Who is online

Users browsing this forum: No registered users and 2 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub