Exemplo n.º 1
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('send_chatmessage', array('h'), array(true, true)), '', '');
     } else {
         if (!array_key_exists(0, $parameters)) {
             return array('', '', '', do_lang('MISSING_PARAM', '1', 'send_chatmessage'));
         }
         if (!array_key_exists(1, $parameters)) {
             return array('', '', '', do_lang('MISSING_PARAM', '2', 'send_chatmessage'));
         }
         require_code('chat');
         if (is_numeric($parameters[0])) {
             $chatroom = $parameters[0];
         } elseif ($parameters[0] == 'first-watched') {
             $_chatroom = get_value('occle_watched_chatroom');
             $chatroom = is_null($_chatroom) ? $GLOBALS['SITE_DB']->query_value_null_ok('chat_rooms', 'id', NULL, 'ORDER BY id') : intval($_chatroom);
         } else {
             $chatroom = get_chatroom_id($parameters[0]);
         }
         if (is_null($chatroom)) {
             return array('', '', '', do_lang('MISSING_RESOURCE'));
         }
         chat_post_message($chatroom, $parameters[1], get_option('chat_default_post_font'), get_option('chat_default_post_colour'));
         return array('', '', do_lang('SUCCESS'), '');
     }
 }
Exemplo n.º 2
0
 /**
  * The actualiser to add a chat room.
  *
  * @return tempcode		The UI to choose a chat room (probably what was just added, but...)
  */
 function _chat_private()
 {
     $title = get_page_title('CREATE_PRIVATE_ROOM');
     require_code('chat2');
     if (is_guest()) {
         access_denied('NOT_AS_GUEST');
     }
     check_specific_permission('create_private_room');
     // Check the input
     $room_name = post_param('room_name', do_lang('CHAT_PRIVATE_DEFAULT_ROOM_NAME', $GLOBALS['FORUM_DRIVER']->get_username(get_member())));
     $room_lang = post_param('room_lang', user_lang());
     list($allow2, $allow2_groups, $disallow2, $disallow2_groups) = read_in_chat_perm_fields();
     $allow = explode(',', $allow2);
     $new_room_id = add_chatroom(post_param('c_welcome'), $room_name, get_member(), $allow2, $allow2_groups, $disallow2, $disallow2_groups, $room_lang);
     $rooms = chat_get_all_rooms();
     // For each person in the allow list, insert a private message into every room (except the new one) asking them to join the new room
     foreach ($allow as $person) {
         $person = trim($person);
         if ($person != '' && $person != $GLOBALS['FORUM_DRIVER']->get_username(get_member()) && $person != do_lang('GUEST')) {
             foreach ($rooms as $room) {
                 if ($room['id'] != $new_room_id) {
                     chat_post_message($room['id'], '[invite="' . $person . '"]' . $room_name . '[/invite]', get_option('chat_default_post_font'), get_option('chat_default_post_colour'));
                 }
             }
         }
     }
     // Set access
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'chat', 'category_name' => strval($new_room_id)));
     foreach (array_keys($groups) as $group_id) {
         if (in_array($group_id, $admin_groups)) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'chat', 'category_name' => strval($new_room_id), 'group_id' => $group_id));
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'room', 'id' => $new_room_id), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Exemplo n.º 3
0
/**
 * Handle an AJAX message posting request.
 *
 * @param  AUTO_LINK		Room ID
 * @param  string			The message
 * @param  string			Font name
 * @param  string			Font colour
 * @param  BINARY			Whether this is the first message sent out to this room, since some change
 */
function _chat_post_message_ajax($room_id, $message, $font, $colour, $first_message)
{
    $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id), '', 1);
    if (!array_key_exists(0, $room_check)) {
        // This room doesn't exist
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    if (!check_chatroom_access($room_check[0], true)) {
        require_lang('chat');
        $the_message = do_lang('BANNED_FROM_CHAT');
        $_message = array('system_message' => 1, 'ip_address' => get_ip_address(), 'room_id' => $room_id, 'user_id' => get_member(), 'date_and_time' => time(), 'member_id' => get_member(), 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font'));
        $template = do_template('CHAT_MESSAGE', array('SYSTEM_MESSAGE' => strval($_message['system_message']), 'STAFF' => false, 'OLD_MESSAGES' => false, 'AVATAR_URL' => '', 'STAFF_ACTIONS' => '', 'USER' => strval($_message['member_id']), 'MESSAGE' => $the_message, 'TIME' => get_timezoned_date($_message['date_and_time']), 'RAW_TIME' => strval($_message['date_and_time']), 'FONT_COLOUR' => $_message['text_colour'], 'FONT_FACE' => $_message['font_name']));
        $messages_output = '<div xmlns="http://www.w3.org/1999/xhtml" sender_id="' . strval($_message['member_id']) . '" room_id="' . strval($_message['room_id']) . '" id="123456789" timestamp="' . strval($_message['date_and_time']) . '">' . $template->evaluate() . '</div>';
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        // Date in the past
        header('Content-Type: application/xml');
        $output = '<' . '?xml version="1.0" encoding="' . get_charset() . '" ?' . '>
<!DOCTYPE xc:content [
<!ENTITY euro "&#8364;">
<!ENTITY ldquo "&#8220;">
<!ENTITY rdquo "&#8221;">
<!ENTITY lsquo "&#8216;">
<!ENTITY rsquo "&#8217;">
<!ENTITY dagger "&#8224;">
<!ENTITY Dagger "&#8225;">
<!ENTITY permil "&#8240;">
<!ENTITY Scaron "&#352;">
<!ENTITY scaron "&#353;">
<!ENTITY Yuml "&#376;">
<!ENTITY ndash "&#8211;">
<!ENTITY mdash "&#8212;">
<!ENTITY hellip "&#8230;">
<!ENTITY copy "&#169;">
<!ENTITY nbsp " ">
<!ENTITY fnof "&#402;">
<!ENTITY reg "&#174;">
<!ENTITY trade "&#8482;">
<!ENTITY raquo "&#187;">
<!ENTITY frac14 "&#188;">
<!ENTITY frac12 "&#189;">
<!ENTITY frac34 "&#190;">
]>

<response>
	<result>
		' . $messages_output . '
	</result>
</response>';
        echo $output;
        return;
    }
    if ($message == '') {
        $return = '0';
    } else {
        //$prefs=@$_COOKIE['ocp_chat_prefs'];
        //$prefs=@explode(';',$prefs);
        //$font=isset($prefs[1])?$prefs[1]:get_option('chat_default_post_font');
        //$colour=isset($prefs[0])?$prefs[0]:get_option('chat_default_post_colour');
        if (chat_post_message($room_id, $message, $font, $colour, 60)) {
            $return = '1';
        } else {
            $return = '0';
        }
    }
    if ($room_check[0]['is_im'] == 1) {
        $invited_already = NULL;
        $active_members = NULL;
        $allow_list = explode(',', $room_check[0]['allow_list']);
        foreach ($allow_list as $_allow) {
            $_allow = trim($_allow);
            $allow = intval($_allow);
            if ($allow != $room_check[0]['room_owner'] && $allow != get_member()) {
                if (is_null($invited_already)) {
                    $invited_already = collapse_1d_complexity('e_member_id', $GLOBALS['SITE_DB']->query_select('chat_events', array('e_member_id'), array('e_room_id' => $room_id, 'e_type_code' => 'INVITED_TO_IM')));
                }
                if (!in_array($allow, $invited_already)) {
                    // Send out invitation if they're not active
                    if (is_null($active_members)) {
                        $active_members = get_chatters_in_room($room_id);
                    }
                    if (!array_key_exists($allow, $active_members)) {
                        $event_id = $GLOBALS['SITE_DB']->query_insert('chat_events', array('e_type_code' => 'INVITED_TO_IM', 'e_member_id' => $allow, 'e_room_id' => $room_id, 'e_date_and_time' => time()), true);
                        $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat');
                        fwrite($myfile, strval($event_id));
                        fclose($myfile);
                        sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat');
                        require_lang('chat');
                        $zone = get_module_zone('chat');
                        $_lobby_url = build_url(array('page' => 'chat'), $zone, NULL, false, false, true);
                        $lobby_url = $_lobby_url->evaluate();
                        $subject = do_lang('IM_INVITED_SUBJECT', NULL, NULL, NULL, get_lang($allow));
                        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
                        $username2 = $GLOBALS['FORUM_DRIVER']->get_username($allow);
                        $message = do_lang('IM_INVITED_MESSAGE', get_timezoned_date(time(), true), $username, array($lobby_url, $username2, $message), get_lang($allow));
                        require_code('notifications');
                        dispatch_notification('im_invited', NULL, $subject, $message, array($allow), $room_check[0]['room_owner'], 1);
                    }
                }
            }
        }
    }
    /*if ($return=='0') Flood control creates error, but we'd rather see it shown inline
    	{
    			header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    			header('Content-Type: application/xml');
    			$output='<'.'?xml version="1.0" encoding="'.get_charset().'" ?'.'>
    <!DOCTYPE xc:content [
    <!ENTITY euro "&#8364;">
    <!ENTITY ldquo "&#8220;">
    <!ENTITY rdquo "&#8221;">
    <!ENTITY lsquo "&#8216;">
    <!ENTITY rsquo "&#8217;">
    <!ENTITY dagger "&#8224;">
    <!ENTITY Dagger "&#8225;">
    <!ENTITY permil "&#8240;">
    <!ENTITY Scaron "&#352;">
    <!ENTITY scaron "&#353;">
    <!ENTITY Yuml "&#376;">
    <!ENTITY ndash "&#8211;">
    <!ENTITY mdash "&#8212;">
    <!ENTITY hellip "&#8230;">
    <!ENTITY copy "&#169;">
    <!ENTITY nbsp " ">
    <!ENTITY fnof "&#402;">
    <!ENTITY reg "&#174;">
    <!ENTITY trade "&#8482;">
    <!ENTITY raquo "&#187;">
    <!ENTITY frac14 "&#188;">
    <!ENTITY frac12 "&#189;">
    <!ENTITY frac34 "&#190;">
    ]>
    
    <error />';
    			echo $output;
    
    		return;
    	}*/
    // Send response of new messages, so we get instant result
    _chat_messages_script_ajax($room_check[0]['is_im'] == 1 ? -1 : $room_id, false, either_param_integer('message_id'), either_param_integer('event_id'));
}