Getting the following error back from the Chat Log while looking at it with User 1.

warning: Invalid argument supplied for foreach() in /home/modules/chatblock/chatblock.module on line 440.

Can see the log alright with other authenticated users, but...

The other issue I am having is that "null" is displayed in the chat window, no matter what I type. And a new "null" is added roughly every 5 sec or so.

Running Drupal 5.1 with MySQL - 5.0.24a and PHP 5.1.2

Have the i18n module running.

Comments

dwees’s picture

Is it possible for me to view your chatblock in action so I can see if I can view the Javascript error that is giving you a problem? Which browser are you using to use it with? It is restricted to browsers that work with jQuery.

Dave

synesthete’s picture

My installation is at http://difuzyon.artificialeyes.tv/
Mainly I am looking at the site with Firefox 2.0.0.1 on OS X. Also having trouble with Safari 2.0.4 and Firefox 2.0.0.1 under Win XP. I am able to get Chatblock to function properly with IE 6. So I am sorry to have seemingly wasted our time with this. I am very excited about Chatblock, it is the most useful chat solution I have seen to date in Drupal. I would very much like to be able to use it. Firefox and Safari support on the Mac are a must for me. Is there anything I can do to make this possible? Thank you for your time and consideration.

dwees’s picture

Assigned: Unassigned » dwees

It looks to me like the jQuery way of getting an element that has both an ID and a name set doesn't work properly. Not sure if this is a problem in general, or just a problem with jQuery. I'll try using the forms array method next, and see if this makes a difference.

I've also noticed that one of the sites I looked at that was having a problem was using a slightly different version of jQuery, not sure if that could be the problem. Maybe there was a bug-fix?

Dave

dwees’s picture

Hopefully I've fixed this error. Wait a few hours for the CVS to be turned into an update and re-download chatblock. Then just copy over the version you have in your modules directory (just the chatblock.module file has been changed).

Alternatively, you can just examine the code below and make the changes in the module. It is pretty straight forward, I've left the lines that have been changed commented out of the script.

/*
 * Default chat block to be opened on page refreshes
 */
function chatblock_contents() {
  global $user;
  if ((variable_get('chatblock_ignore_user_1', 0)==1)&&($user->uid == 1)) {
    return '';
  }
  $output = '';
  $url = variable_get('chatblock_get_url', '');
  if ($url == '') {
    $output = "You must enter the base_url of your site before this chat block will work";
    return $output;
  }
  if (user_access('view chat')) {
    $output = '<iframe name="chatblock" src="'.$url.'/chatblock/view" style="display: block; height: 200px; width: 200px; overflow-x: hidden;">';
    $output .= '</iframe>';
    if (user_access('join chats')) {
      $output .= drupal_get_form('chatblock_chat_form');
    } //"<script type=\"text/javascript\">\n";  $output .= "
    drupal_add_js("
      // Handles the Ajax form submission if Javascript is enabled.
      function chatblockSend(el) {
        if (el) {
          el.disabled = true;
        } ;
        //var message = 'message=' + $('#edit-chatblock_text').val() + '&token=' + Math.random();
        var message = 'message=' + document.getElementById('edit-chatblock_text').value + '&token=' + Math.random();
        $.ajax({ type: 'POST', url: '$url/chatblock/update', data: message, success: chatblockhandleResponse});
        $('#edit-chatblock_text').attr('value', '');
        return false;
      }
      
      function chatblockhandleResponse(text) {
        //$('#chatblock_submit').attr({disabled: false});
        document.getElementById('chatblock_submit').disabled = false;
        return;
      }
      ", 'inline');
    //$output .= "</script>\n";
  }
  return $output;
}
synesthete’s picture

Thank you so much for the fast responses. Things are now good in Mac and Windows Firefox. Safari is still having trouble as well the newest version of Opera on Mac and Windows.

dwees’s picture

Very strange problem I noticed. If I view source with Opera, the name of the text input is 'edit-chatblock_text' on my screen and 'edit-chatblock-text' on yours. I'm going to rename this input in the module (everywhere) to chatblocktext and we'll see if removing the underscore does the trick. I'll do the same for the submit button (this means you will need to change it in the form definition too).

I'll post the code in a second.

Dave

dwees’s picture

Quick file post below for copy and paste into chatblock.module, will update CVS next (which will take 6-12 hours to show up).


/*
 * Implementation of hook_help
 */
function chatblock_help($section) {
  switch ($section) {
    case 'admin/help#chatblock':
      return t('This allows users to chat to each other via a DHTML chatblock.  Requires Javascript to be enabled in their browser.  Should update on page refreshes.');
      break;
    case 'admin/modules#description':
      return t('Creates a chatblock for users.');
      break;
  }
}

/*
 * Implementation of hook_perm
 */
function chatblock_perm() {
  return array('join chats', 'view chat', 'view chat logs'); 
}

/*
 * Implementation of hook_block
 */
function chatblock_block($op = 'list', $delta = 0, $edit = array()) {
  // The $op parameter determines what piece of information is being requested.
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Allows user to chat via a chatblock.');
      return $blocks;
    case 'configure':
      $form = array();
      if ($delta == 0) {
        // All we need to provide is a text field, Drupal will take care of
        // the other block configuration options and the save button.
        $form['chatblock_number_messages'] = array(
          '#type' => 'textfield',
          '#title' => t('Number of messages'),
          '#size' => 60,
          '#description' => t('The number of messages to show in this block.'),
          '#default_value' => variable_get('chatblock_number_messages',  100),
        );
      }
      return $form;
    case 'save':
      if ($delta == 0) {
        // Have Drupal save the string to the database.
        variable_set('chatblock_number_messages', $edit['chatblock_number_messages']);
      }
      return;
    case 'view': default:
      // If $op is "view", then we need to generate the block for display
      // purposes. The $delta parameter tells us which block is being requested.
      switch ($delta) {
        case 0:
          global $user;
          $path = drupal_get_path('module', 'chatblock');
          //drupal_add_js($path.'/js/chatblock.js');
          $block['subject'] = t('Chat');
          $block['content'] = chatblock_contents();
          break;
      }
      return $block;
  } 
}

/*
 * Implementation of hook_menu
 */
function chatblock_menu($may_cache) {
  global $user;
  $items = array();
  $items[] = array(
    'path' => 'chatblock/view',
    'title' => t('chatblock'),
    'callback' => 'chatblock_chat_callback',
    'access' => user_access('access content'),
    'type' => MENU_CALLBACK
  );
  $items[] = array(
    'path' => 'chatblock/update',
    'title' => t('chatblock update'),
    'callback' => 'chatblock_chat_update_callback',
    'access' => user_access('access content'),
    'type' => MENU_CALLBACK
  );
  $items[] = array(
    'path' => 'chatblock/logs',
    'title' => t('Chatblock logs'),
    'description' => t('View the logs of the chats on the site.'),
    'access' => user_access('view chat logs'),
    'callback' => 'chatblock_logs_page_view',
    'type' => MENU_NORMAL_ITEM
  );
  $items[] = array(
    'path' => 'admin/settings/chatblock',
    'title' => t('Chatblock'),
    'description' => t('Set the settings for the site-wide chat block.'),
    'access' => user_access('administer site configuration'),
    'callback' => 'chatblock_settings',
    'type' => MENU_NORMAL_ITEM
  );
  $items[] = array(
    'path' => 'chatblock/help',
    'title' => t('Chatblock help'),
    'description' => t('View some useful information about using the chatblock.'),
    'access' => user_access('join chats'),
    'callback' => 'chatblock_help_page',
    'type' => MENU_NORMAL_ITEM
  );
  return $items;
}

function chatblock_settings() {
  return drupal_get_form('chatblock_settings_form');
}

function chatblock_settings_form() {
  $form['chatblock_settings']['chatblock_get_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Base URL'),
    '#description' => t('Enter the URL to the directory your main index file is stored in.  <br />This must be a url of the style http://www.yourdomain.com, and must not end in a trailing /'),
    '#default_value' => variable_get('chatblock_get_url', ''),
    '#size' => 60,
    '#required' => TRUE
  );  
  $form['chatblock_settings']['chatblock_number_messages'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of messages'),
    '#description' => t('Enter the maximum number of messages to display in the chatblock.'),
    '#default_value' => variable_get('chatblock_number_messages', 100),
    '#size' => 60,
    '#required' => FALSE
  );
  $form['chatblock_settings']['chatblock_ignore_user_1'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore Admin'),
    '#description' => t('Ignore user 1 for the chat module so that the admin can work in peace.'),
    '#default_value' => variable_get('chatblock_ignore_user_1', 0)
  );
  $form['chatblock_settings']['chatblock_refresh_rate'] = array(
    '#type' => 'textfield',
    '#title' => t('Refresh rate'),
    '#description' => t('The number of seconds between refreshes of the chatblock text. Defaults to 5 seconds.'),
    '#default_value' => variable_get('chatblock_refresh_rate', 5)
  );
  return system_settings_form($form);
}

/*
 * Updating the database
 */
function chatblock_database($op, $message = "", $name = "") {
  global $user;
  $username = $user->name;
  if ((variable_get('chatblock_ignore_user_1', 0)==1)&&($user->uid == 1)) {
    return;
  }
  switch ($op) {
    case 'view':
      $number_messages = intval(variable_get('chatblock_number_messages', 100));
      $row = db_fetch_array(db_query("SELECT MAX(messageid) AS messageidmax FROM {chatblock} c LIMIT 1"));
      $max = $row['messageidmax'];
      $start = $max - $number_messages;
      if ($start < 0) {
        $start = 0;
      }
      $query = "SELECT c.message, c.username, c.messageid FROM {chatblock} c ORDER BY c.timestamp LIMIT %d, %d";
      $result = db_query($query, $start, $number_messages);
      $messages = array();
      while ($row = db_fetch_array($result)) {
        $messages[$row['messageid']] = array($row['username'],$row['message']);
      }
      return $messages;
      break;
    case 'update':
      $timestamp = time();
      $query = "INSERT {chatblock} (message, username, timestamp) VALUES ('%s','%s',%d)";
      $result = db_query($query, $message, $username, $timestamp);
      variable_set('chatboxlastmessage', variable_get('chatboxlastmessage', 0) + 1);
      return;
      break;
    case 'user':
      $timestamp = time();
      $query = "INSERT {chatblock} (message, username, timestamp) VALUES ('%s','%s',%d)";
      $result = db_query($query, $message, $username, $timestamp);
      variable_set('chatboxlastmessage', variable_get('chatboxlastmessage', 0) + 1);
      return;
      break;
    case 'logs':
      $query = "SELECT c.message, c.username, c.messageid FROM {chatblock} c ORDER BY c.timestamp";
      $result = pager_query($query, 20, 0);
      $messages = array();
      while ($row = db_fetch_array($result)) {
        $messages[$row['messageid']] = array($row['username'],$row['message']);
      }
      return $messages;
      break;
  }
}

/*
 * Default chat block to be opened on page refreshes
 */
function chatblock_contents() {
  global $user;
  if ((variable_get('chatblock_ignore_user_1', 0)==1)&&($user->uid == 1)) {
    return '';
  }
  $output = '';
  $url = variable_get('chatblock_get_url', '');
  if ($url == '') {
    $output = "You must enter the base_url of your site before this chat block will work";
    return $output;
  }
  if (user_access('view chat')) {
    $output = '<iframe name="chatblock" src="'.$url.'/chatblock/view" style="display: block; height: 200px; width: 200px; overflow-x: hidden;">';
    $output .= '</iframe>';
    if (user_access('join chats')) {
      $output .= drupal_get_form('chatblock_chat_form');
    } //"<script type=\"text/javascript\">\n";  $output .= "
    drupal_add_js("
      // Handles the Ajax form submission if Javascript is enabled.
      function chatblockSend(el) {
        if (el) {
          el.disabled = true;
        } ;
        //var message = 'message=' + $('#edit-chatblocktext').val() + '&token=' + Math.random();
        var message = 'message=' + document.getElementById('edit-chatblocktext').value + '&token=' + Math.random();
        $.ajax({ type: 'POST', url: '$url/chatblock/update', data: message, success: chatblockhandleResponse});
        $('#edit-chatblocktext').attr('value', '');
        return false;
      }
      
      function chatblockhandleResponse(text) {
        //$('#chatblocksubmit').attr({disabled: false});
        document.getElementById('chatblocksubmit').disabled = false;
        return;
      }
      ", 'inline');
    //$output .= "</script>\n";
  }
  return $output;
}

/*
 * Get the current messages and display them.
 */
function chatblock_messages() {
  $messages = chatblock_database('view');
  $nums = array_keys($messages);
  $url = variable_get('chatblock_get_url', '');
  $rate = variable_get('chatblock_refresh_rate', 5)*1000;
  if (!isset($_POST['chatboxtoken'])) {
    $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
    $output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
    $output = "<head>\n";
    $output .= "<title>Chatbox Iframe</title>\n";
    $output .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url/modules/chatblock/css/chatblock.css\" />\n";
    $output .= "<script type=\"text/javascript\" src=\"$url/misc/jquery.js\"></script>\n";
    $output .= "<script type=\"text/javascript\">\n";
    $output .= "function chatboxInitScroll() {
                  if (document.body.scrollHeight){
                    window.scrollTo(0, document.body.scrollHeight);
                  } else if (screen.height) {
                    // IE5 window.scrollTo(0, screen.height);
                  }
                }
                
                function chatboxGetMessage() {
                    var messageid = document.getElementById('chatblocklastmessage').innerHTML;
                    var message = 'messageid=' + messageid + '&chatboxtoken=' + Math.random(); 
                    $.ajax({ type: 'POST', url: '$url/chatblock/view', data: message, success: chatblockResponse });
                }
                
                function chatblockResponse(text) {
                   var matches;
                   if (matches = /last(.*?)num/.exec(text)) {
                     document.getElementById('chatblocklastmessage').innerHTML = matches[1];
                     text = text.replace(\"last\" + matches[1] + \"num\", \"\");
                   }
                   document.getElementById('chatboxwindow').innerHTML += text;
                   chatboxInitScroll();
                   return;
                }
                
                chatBlockInterval = window.setInterval(chatboxGetMessage, $rate);
                \n";
    $output .= "</script>\n";
    $output .= "</head>\n";
    $output .= "<body style=\"width:180px\" onload=\"chatboxInitScroll();\">\n";
    $output .= "<div id=\"chatboxwindow\">\n";
    if (count($messages) > 0) {
      foreach ($messages as $key => $value) {
        $message = chatblock_filter_message($value[1]);
        $output .= '<br /><div style="width: 160px"><span style="color: red">'.$value[0].': </span> '.$message.'</div>';
      }
    }
    $output .= "</div>\n";
    $output .= "<div id=\"chatblocklastmessage\" style=\"display: none;\">".$nums[count($messages)-1]."</div>\n";
    $output .= "</body>\n";
    $output .= "</html>\n";
    return $output;
  } else {
    $lastnum = $_POST['messageid'];
    $nextnum = variable_get('chatboxlastmessage', 0);
    if (count($messages) > 0) {
      foreach ($messages as $key => $value) {
        if ($lastnum < $key) {
          $message = chatblock_filter_message($value[1]);
          $output .= '<br /><div style="width: 160px"><span style="color: red">'.$value[0].': </span> '.$message.'</div><div style="display: none;">last'.$nums[count($messages)-1].'num</div>';
        }
      }
    }
    return $output;
  }
}

/*
 *  This function filters the messages and adds the smileys and extra if any.
 */
function chatblock_filter_message($message) {
  $url = variable_get('chatblock_get_url', '');
  $message = chatblock_find_url($message);
  $message = preg_replace("/>\:>/" , '<img src="'.$url.'/modules/chatblock/images/twisted.gif" alt=":twisted:" />', $message);
  $message = preg_replace("/\?\:\)/" , '<img src="'.$url.'/modules/chatblock/images/think.gif" alt=":think:" />', $message);
  $message = preg_replace("/N\:\)/" , '<img src="'.$url.'/modules/chatblock/images/naughty.gif" alt=":naughty:" />', $message);
  $message = preg_replace("/O\:\)/" , '<img src="'.$url.'/modules/chatblock/images/angel.gif" alt=":angel:" />', $message);
  $message = preg_replace("/\:D/" , '<img src="'.$url.'/modules/chatblock/images/biggrin.gif" alt=":biggrin:" />', $message);
  $message = preg_replace("/\:P/" , '<img src="'.$url.'/modules/chatblock/images/tongue.gif" alt=":tongue:" />', $message);
  $message = preg_replace("/\:o/" , '<img src="'.$url.'/modules/chatblock/images/impressed.gif" alt=":impressed:" />', $message);
  $message = preg_replace("/\:\|/" , '<img src="'.$url.'/modules/chatblock/images/neutral.gif" alt=":neutral:" />', $message);
  $message = preg_replace("/8-\)/" , '<img src="'.$url.'/modules/chatblock/images/cool.gif" alt=":cool:" />', $message);
  $message = preg_replace("/\%\)/" , '<img src="'.$url.'/modules/chatblock/images/confused.gif" alt=":confused:" />', $message);
  $message = preg_replace("/\:\[/" , '<img src="'.$url.'/modules/chatblock/images/ashamed.gif" alt=":ashamed:" />', $message);
  $message = preg_replace("/oO/" , '<img src="'.$url.'/modules/chatblock/images/eh.gif" alt=":eh:" />', $message);
  $message = preg_replace("/\^\^/" , '<img src="'.$url.'/modules/chatblock/images/kidding.gif" alt=":kidding:" />', $message);
  $message = preg_replace("/>\:\{/" , '<img src="'.$url.'/modules/chatblock/images/mad.gif" alt=":mad:" />', $message);
  $message = preg_replace("/\:applause\:/" , '<img src="'.$url.'/modules/chatblock/images/applause.gif" alt="applause" />', $message);
  $message = preg_replace("/\!\:{/" , '<img src="'.$url.'/modules/chatblock/images/silenced.gif" alt=":silenced:" />', $message);
  $message = preg_replace("/8\)/" , '<img src="'.$url.'/modules/chatblock/images/rolleyes.gif" alt=":rolleyes:" />', $message);
  $message = preg_replace("/\:S/" , '<img src="'.$url.'/modules/chatblock/images/sick.gif" alt=":sick:" />', $message);
  $message = preg_replace("/\:IW\:/" , '<img src="'.$url.'/modules/chatblock/images/whistle.gif" alt=":whistle:" />', $message);
  $message = preg_replace("/\:\)/" , '<img src="'.$url.'/modules/chatblock/images/smile.gif" alt=":smile:" />', $message);
  $message = preg_replace("/\:\(/" , '<img src="'.$url.'/modules/chatblock/images/sad.gif" alt=":sad:" />', $message);
  return $message;
}

/*
 * Parse the message and convert the URLs
 */

function chatblock_find_url($string){
//"www."
   $pattern_preg1 = '#(^|\s)(www|WWW)\.([^\s<>\.]+)\.([^\s\n<>]+)#sm';
   $replace_preg1 = '\\1<a href="http://\\2.\\3.\\4" target="_blank" class="link">\\2.\\3.\\4</a>';

//"http://"
   $pattern_preg2 = '#(^|[^\"=\]]{1})(http|HTTP)(s|S)?://([^\s<>\.]+)\.([^\s<>]+)#sm';
   $replace_preg2 = '\\1<a href="\\2\\3://\\4.\\5" target="_blank" class="link">\\2\\3://\\4.\\5</a>';
  
   $string = preg_replace($pattern_preg1, $replace_preg1, $string);
   $string = preg_replace($pattern_preg2, $replace_preg2, $string);

   return $string;
}

/*
 * This is the callback controller for updating the chatblock via Ajax.
 */
function chatblock_chat_callback() {
   $output = chatblock_messages();
   echo $output;
   return;
}

/*
 *  This is the basic chatblock form to display.
 */
function chatblock_chat_form(){
  $form = array();
  $form['chatblocktext'] = array(
    '#type' => 'textfield',
    '#size' => 20
  );
  $form['chatblocksubmit'] = array(
    '#type' => 'submit',
    '#attributes' => array('id' => 'chatblocksubmit', 'onclick' => 'return chatblockSend(this);'),
    '#value' => t('send')
  );
  return $form;
}

/* 
 * This callback inserts the current message into the database
 */
function chatblock_chat_update_callback() {
  if (isset($_POST['message'])) {
    $message = strip_tags($_POST['message']);
  }
  if (isset($_POST['chatboxtoken'])) {
    return;
  }
  chatblock_database('update', $message);
  return;
}

/*
 * Implementation of hook_user
 */
function chatblock_user($op, &$edit, &$account, $category = NULL){
  $username = $account->name;
  switch($op) {
    case 'login':
      chatblock_database('user',' has just logged in.', $username);
      break;
    case 'logout':
      chatblock_database('user',' has just logged out.', $username);
      break;
  }
}

/*
 * Our custom submission stuff so that the messages are sent to the correct location
 */
function chatblock_chat_form_submit($form_id, $form_values) {
  if (isset($form_values['chatblocktext'])) {
    $message = strip_tags($form_values['chatblocktext']);
    chatblock_database('update', $message);
  }
  return;
}

/*
 * View the chat logs, as a menu Callback
 */
function chatblock_logs_page_view() {
  $messages = chatblock_database('logs');
  $output = '';
  if (!is_array($messages)) {
    $messages = array();
  }
  foreach ($messages as $key => $values) {
    $message = chatblock_filter_message($values[1]);
    $output .= '<br /><div style="width: 160px"><span style="color: red">'.$values[0].': </span> '.$message.'</div>';
  }
  $output .= theme_pager(array(), 20, 0);
  return $output;
}

function chatblock_help_page() {
  $output = '';
  $url = variable_get('chatblock_get_url', '');
  if ($url == '') {
    $output = 'In order for this page to be useful for your users, enter the base_url at admin/settings/chatblock';
    return $output;
  }
  $header = array(t('Text'), t('Replacement image/text'));
  $rows = array(
   array(":D" , '<img src="'.$url.'/modules/chatblock/images/biggrin.gif" alt=":D" />'),
   array(":)" , '<img src="'.$url.'/modules/chatblock/images/smile.gif" alt=":)" />'),
   array(":P" , '<img src="'.$url.'/modules/chatblock/images/tongue.gif" alt=":P" />'),
   array(":(" , '<img src="'.$url.'/modules/chatblock/images/sad.gif" alt=":(" />'),
   array(":o" , '<img src="'.$url.'/modules/chatblock/images/impressed.gif" alt=":o" />'),
   array(":|" , '<img src="'.$url.'/modules/chatblock/images/neutral.gif" alt=":|" />'),
   array("8-)" , '<img src="'.$url.'/modules/chatblock/images/cool.gif" alt="8-)" />'),
   array("%)" , '<img src="'.$url.'/modules/chatblock/images/confused.gif" alt="%)" />'),
   array(":[" , '<img src="'.$url.'/modules/chatblock/images/ashamed.gif" alt=":[" />'),
   array("O:)" , '<img src="'.$url.'/modules/chatblock/images/angel.gif" alt="O:)" />'),
   array("oO" , '<img src="'.$url.'/modules/chatblock/images/eh.gif" alt="oO" />'),
   array("^^" , '<img src="'.$url.'/modules/chatblock/images/kidding.gif" alt="^^" />'),
   array(">:(" , '<img src="'.$url.'/modules/chatblock/images/mad.gif" alt=">:(" />'),
   array(">:>" , '<img src="'.$url.'/modules/chatblock/images/twisted.gif" alt=">:>" />'),
   array(":applause:" , '<img src="'.$url.'/modules/chatblock/images/applause.gif" alt=":applause:" />'),
   array("!:{" , '<img src="'.$url.'/modules/chatblock/images/kidding.gif" alt="!:{" />'),
   array("N:)" , '<img src="'.$url.'/modules/chatblock/images/naughty.gif" alt="N:)" />'),
   array("8)" , '<img src="'.$url.'/modules/chatblock/images/rolleyes.gif" alt="8)" />'),
   array(":S" , '<img src="'.$url.'/modules/chatblock/images/sick.gif" alt=":S" />'),
   array("?:)" , '<img src="'.$url.'/modules/chatblock/images/think.gif" alt="?:)" />'),
   array(":IW:" , '<img src="'.$url.'/modules/chatblock/images/whistle.gif" alt=":IW:" />'),
   array("http://www.somedomain.com" , '<a href="http://www.somedomain.com" onclick="return false">http:www.somedomain.com</a>'),
   array("www.somedomain.com", '<a href="http://www.somedomain.com" onclick="return false">http:www.somedomain.com</a>')
  );
  $output .= '<p>This shows some shortcuts for some smileys and replacement text.</p>';
  $output .= theme('table', $header, $rows);
  return $output;
}

synesthete’s picture

Updated the module.Some new strange behaviors with Firefox and Opera on both Mac and PC. After typing and sending a message the send button greys out and I can no longer send messages without manually refreshing the whole page. Safari is working, but displaying "null" in the chat window after the entry is posted. IE 6 still fine.

ben soo’s picture

i'm seeing the same behavior.

dwees’s picture

Okay, well I'll try accessing the two elements in question using the forms array. However, I'm consistently not seeing the same behaviour on my website. Strangely enough, yesterday I looked at someone else's site and it had the exact same code as my site, and I looked at both sites with different tabs in the same browser, and his site did not work, and mine did. This leads me to believe that it might be an incompatibility with the theme of the website.

Anyway here is attempt number 3, just change the function in question.

/*
 * Default chat block to be opened on page refreshes
 */
function chatblock_contents() {
  global $user;
  if ((variable_get('chatblock_ignore_user_1', 0)==1)&&($user->uid == 1)) {
    return '';
  }
  $output = '';
  $url = variable_get('chatblock_get_url', '');
  if ($url == '') {
    $output = "You must enter the base_url of your site before this chat block will work";
    return $output;
  }
  if (user_access('view chat')) {
    $output = '<iframe name="chatblock" src="'.$url.'/chatblock/view" style="display: block; height: 200px; width: 200px; overflow-x: hidden;">';
    $output .= '</iframe>';
    if (user_access('join chats')) {
      $output .= drupal_get_form('chatblock_chat_form');
    } //"<script type=\"text/javascript\">\n";  $output .= "
    drupal_add_js("
      // Handles the Ajax form submission if Javascript is enabled.
      function chatblockSend(el) {
        if (el) {
          el.disabled = true;
        } ;
        //var message = 'message=' + $('#edit-chatblocktext').val() + '&token=' + Math.random();
        //var message = 'message=' + document.getElementById('edit-chatblocktext').value + '&token=' + Math.random();
        var message = 'message=' + document.getElementById('chatblock_chat_form').elements['chatblocktext'].value + '&token=' + Math.random();
        $.ajax({ type: 'POST', url: '$url/chatblock/update', data: message, success: chatblockhandleResponse});
        $('#edit-chatblocktext').attr('value', '');
        return false;
      }
      
      function chatblockhandleResponse(text) {
        //$('#chatblocksubmit').attr({disabled: false});
        //document.getElementById('chatblocksubmit').disabled = false;
        document.getElementById('chatblock_chat_form').elements['op'].disabled = false;
        return;
      }
      ", 'inline');
    //$output .= "</script>\n";
  }
  return $output;
}

dwees’s picture

Another thing to try, assuming you've made the previous change is this:

/*
 *  This is the basic chatblock form to display.
 */
function chatblock_chat_form(){
  $form = array();
  $form['chatblocktext'] = array(
    '#type' => 'textfield',
    '#size' => 20
  );
  $form['chatblocksubmit'] = array(
    '#type' => 'submit',
    '#attributes' => array('onclick' => 'return chatblockSend(this);'),
    '#value' => t('send')
  );  // 'id' => 'chatblocksubmit', 
  return $form;
}
dwees’s picture

Slightly 'improved' version out. Wait 12 hours or so and download it.

Thanks btw to all the people who are doing so much testing, it's much appreciated.

Dave

ben soo’s picture

Is because we think it a good idea!

synesthete’s picture

This last patch seems to have been a bit of a step backwards for me. Can no longer post to Chatblock in Safari or Opera on the Mac, nor Opera on the PC. Thank you, Dwees for actively working on this very promising module.

synesthete’s picture

The code in comment #11 that is. Will have to wait patiently for the CVS to update try out the latest version.

dwees’s picture

Status: Active » Closed (fixed)

Hopefully these JavaScript errors have been fixed by removing the - or _ from the form element ids. Seems to work in Firefox 2.0.x

Dave