示例#1
0
 /**
  * The actualiser for editing a message.
  *
  * @return tempcode	The UI.
  */
 function _chat_edit_message()
 {
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     $delete = post_param_integer('delete', 0);
     if ($delete == 1) {
         return $this->_chat_delete_message();
     } else {
         $message_id = get_param_integer('id');
         $room_id = $GLOBALS['SITE_DB']->query_value_null_ok('chat_messages', 'room_id', array('id' => $message_id));
         if (is_null($room_id)) {
             warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
         }
         check_chatroom_access($room_id);
         $room_details = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id), '', 1);
         if (!array_key_exists(0, $room_details)) {
             warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
         }
         $row = $room_details[0];
         $has_mod_access = has_specific_permission(get_member(), 'edit_lowrange_content', 'cms_chat', array('chat', $room_id)) || $row['room_owner'] == get_member() && has_specific_permission(get_member(), 'moderate_my_private_rooms');
         if (!$has_mod_access) {
             access_denied('SPECIFIC_PERMISSION', 'edit_lowrange_content');
         }
         $title = get_page_title('EDIT_MESSAGE');
         $_message_parsed = insert_lang_comcode(wordfilter_text(post_param('message')), 4);
         $GLOBALS['SITE_DB']->query_update('chat_messages', array('the_message' => $_message_parsed, 'text_colour' => post_param('textcolour'), 'font_name' => post_param('fontname')), array('id' => $message_id), '', 1);
         log_it('EDIT_MESSAGE', strval($message_id), post_param('message'));
         decache('side_shoutbox');
         require_code('templates_donext');
         return do_next_manager($title, do_lang_tempcode('SUCCESS'), NULL, NULL, NULL, array('_SELF', array('type' => 'ed', 'id' => $message_id, 'room_id' => $room_id), '_SELF'), array('_SELF', array('type' => 'room', 'id' => $room_id), '_SELF'), NULL, array('_SELF', array(), '_SELF'), NULL, NULL, NULL, NULL, NULL, array(), array(), array(has_actual_page_access(get_member(), 'admin_chat') ? array('chatrooms', array('admin_chat', array('type' => 'misc'), get_module_zone('admin_chat')), do_lang('ROOMS')) : NULL), do_lang('SETUP'));
     }
 }
示例#2
0
/**
 * Enter a message into the database for the specified room, and with the specified parameters. The message is filtered for banned words, and is compressed into a tempcode storage format.
 *
 * @param  AUTO_LINK		The room ID for the message to be posted in
 * @param  LONG_TEXT		The message body
 * @param  SHORT_TEXT	The font name for the message
 * @param  SHORT_TEXT	The text colour for the message
 * @param  SHORT_INTEGER  The wrap position for the message
 * @return boolean		Whether the message was successfully posted or not
*/
function chat_post_message($room_id, $message, $font_name, $text_colour, $wrap_pos = 60)
{
    // If it contains chatcode then we'll need to disable the word-filter
    if (strpos($message, '[') !== false && strpos($message, ']') !== false) {
        $wrap_pos = NULL;
    }
    // Have we been blocked by flood control?
    $is_im = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'is_im', array('id' => $room_id));
    if ($is_im) {
        $time_last_message = NULL;
    } else {
        if (is_guest()) {
            $time_last_map = array('ip_address' => get_ip_address(), 'system_message' => 0);
        } else {
            $time_last_map = array('user_id' => get_member(), 'system_message' => 0);
        }
        $time_last_message = $GLOBALS['SITE_DB']->query_value_null_ok('chat_messages', 'MAX(date_and_time)', $time_last_map);
        if (!is_null($time_last_message)) {
            $time_left = $time_last_message - time() + intval(get_option('chat_flood_timelimit'));
        }
    }
    if (is_null($time_last_message) || $time_left <= 0) {
        // Check colour and font
        if ($text_colour == '') {
            $text_colour = get_option('chat_default_post_colour');
        }
        if ($font_name == '') {
            $font_name = get_option('chat_default_post_font');
        }
        // Decode colour code
        if (substr($text_colour, 0, 2) == '0x') {
            $text_colour = '#' . substr($text_colour, 2, strlen($text_colour) - 2);
        }
        // Store as assembled tempcode
        $_message_parsed = insert_lang_comcode(wordfilter_text($message), 4, NULL, false, NULL, $wrap_pos);
        $message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => get_ip_address(), 'room_id' => $room_id, 'user_id' => get_member(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => $text_colour, 'font_name' => $font_name), true);
        $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
        fwrite($myfile, strval($message_id));
        fclose($myfile);
        sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
        // Bot support
        $hooks = find_all_hooks('modules', 'chat_bots');
        foreach (array_keys($hooks) as $hook) {
            require_code('hooks/modules/chat_bots/' . filter_naughty_harsh($hook));
            $ob = object_factory('Hook_chat_bot_' . $hook, true);
            if (!is_null($ob) && method_exists($ob, 'reply_to_any_communication')) {
                $response = $ob->reply_to_any_communication($room_id, $message);
                if (!is_null($response)) {
                    // Store bots message
                    $_message_parsed = insert_lang_comcode(wordfilter_text($response), 4, NULL, false, NULL, $wrap_pos);
                    $bot_message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => $hook, 'room_id' => $room_id, 'user_id' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')), true);
                    $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
                    fwrite($myfile, strval($bot_message_id));
                    fclose($myfile);
                    sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
                }
            }
        }
        // Update points
        if (addon_installed('points')) {
            require_code('points');
            $_count = point_info(get_member());
            $count = array_key_exists('points_gained_chat', $_count) ? $_count['points_gained_chat'] : 0;
            $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_chat', $count + 1);
        }
        decache('side_shoutbox');
        return true;
    }
    // Flood prevention has blocked us. Send a PM about it
    require_lang('chat');
    $_message_parsed = insert_lang_comcode('[private="' . $GLOBALS['FORUM_DRIVER']->get_username(get_member()) . '"]' . do_lang('FLOOD_CONTROL_BLOCKED', integer_format($time_left)) . '[/private]', 4, NULL, false, NULL);
    // Can't wrap system messages, the Comcode parser won't know 'private' is a real tag so will wrap inside it's definition
    $message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 1, 'ip_address' => get_ip_address(), 'room_id' => $room_id, 'user_id' => get_member(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')), true);
    $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
    fwrite($myfile, strval($message_id));
    fclose($myfile);
    sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat');
    return false;
}