tags:

views:

26

answers:

0

Hello, the code here will get new topics and replys on a phpbb3 forum and shout them in a ajax chatbox.. The problem with this code is that it also shouts the replys. I just want new topics shouted.. Can anybody help me make this adjustment.. Thx in advance

$true_title = (($mode == 'post') || (empty($post_data['topic_title']))) ? $post_data['post_subject'] : $post_data['topic_title']; // Also catch edits to the original post topic_title :D



// Remove all the http formatting from the topic_title
        $str_from = array('<', '>', '[', ']', '.', ':', ':','&', '"');
     $str_to = array('<', '>', '[', ']', '.', ':', ':','&','"');
    $clean_title = str_replace($str_from, $str_to, $true_title);

   $chat_post =  '[url=' . generate_board_url();               // Get the board url
  $chat_post .= '/viewtopic.php?f=' . $data['forum_id'] . '&t=' . $topic_id . '&p=' . $data['post_id'] . '#p' . $data['post_id'] . ']' . $clean_title . '[/url]';


        // Get 'poster_id' details
      $csql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE user_id = ' . $data['poster_id'];
        $result = $db->sql_query($csql);
        $poster_info = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        $chat_post .= ' by [b][color=#' . $poster_info['user_colour'] . ']' . $poster_info['username'] . '[/color][/b]';

        $sql_ary = array(
'ip' => (string) 'new',                   // Ip skip
'userID' => (int) 123456,                       // I chose this.. dunno why
'userName' => (string) 'U4ALL-Bot',             // You may change this name into what you want it to be :D
'userRole' => (int) 2,                          // I give it moderator status (I like that colour)
'channel' =>  (int) 0,                          // Chat channel # where the post goes, will be written below
'dateTime' => date('Y-m-d H:i:s'),              // Must give it the current time or it wont appear
'text' => (string) $chat_post                   // The chat message (defined above)



  );

// Define which forum_id's are open to which group_id's

        $validate = array ( array ( 'group_id' => (int) 19356,  // Groupnumber having access to the particular forum_id
                                    'forum_id' => (int) 12   // Same as 1st chat channel, actualluy a forum_id
                                  )


 );

        $num_chnls = sizeof($validate);

        for ($chnl = 0; $chnl < $num_chnls; $chnl++)
          { // Check if the current topic is in a forum(_id) open to a group(_id) (of which users can be members)
        $read_acl = 'SELECT * FROM ' . ACL_GROUPS_TABLE . ' WHERE forum_id = ' . $data['forum_id'] . ' AND group_id = ' . $validate[$chnl]['group_id'];
          $result = $db->sql_query($read_acl);

      $chat_row = $db->sql_fetchrow($result);

   $db->sql_freeresult($result);

          if ($chat_row)
            { // If the rights are there, post the message for this chat/forum_if (they are the same!)
            $sql_ary['channel'] = $validate[$chnl]['forum_id'];
         $chat_sql = 'INSERT INTO ajax_chat_messages ' . $db->sql_build_array('INSERT', $sql_ary);
            $db->sql_query($chat_sql);
            $db->sql_freeresult($chat_sql);
            }
          }