Esempio n. 1
0
 /**
  * Standard modular run function.
  *
  * @param  MEMBER		The ID of the member we are getting link hooks for
  * @return array		List of tuples for results. Each tuple is: type,title,url
  */
 function run($member_id)
 {
     if (!addon_installed('chat')) {
         return array();
     }
     $modules = array();
     if (has_actual_page_access(get_member(), 'chat', get_page_zone('chat'))) {
         if (!is_guest() && $member_id != get_member()) {
             require_lang('chat');
             require_code('chat');
             if (!$GLOBALS['FORUM_DRIVER']->is_staff($member_id)) {
                 if (!member_blocked($member_id)) {
                     $modules[] = array('contact', do_lang_tempcode('EXPLAINED_BLOCK_MEMBER'), build_url(array('page' => 'chat', 'type' => 'blocking_add', 'member_id' => $member_id, 'redirect' => get_self_url(true)), get_module_zone('chat')));
                     if (has_specific_permission(get_member(), 'start_im')) {
                         $modules[] = array('contact', do_lang_tempcode('START_IM'), build_url(array('page' => 'chat', 'type' => 'misc', 'enter_im' => $member_id), get_module_zone('chat')));
                     }
                 } else {
                     $modules[] = array('contact', do_lang_tempcode('EXPLAINED_UNBLOCK_MEMBER'), build_url(array('page' => 'chat', 'type' => 'blocking_remove', 'member_id' => $member_id, 'redirect' => get_self_url(true)), get_module_zone('chat')));
                 }
             }
             if (!member_befriended($member_id)) {
                 $modules[] = array('contact', do_lang_tempcode('MAKE_BUDDY'), build_url(array('page' => 'chat', 'type' => 'buddy_add', 'member_id' => $member_id, 'redirect' => get_self_url(true)), get_module_zone('chat')));
             } else {
                 $modules[] = array('contact', do_lang_tempcode('DUMP_BUDDY'), build_url(array('page' => 'chat', 'type' => 'buddy_remove', 'member_id' => $member_id, 'redirect' => get_self_url(true)), get_module_zone('chat')));
             }
         }
     }
     return $modules;
 }
Esempio n. 2
0
 /**
  * Standard modular render function for profile tab hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return array			A triple: The tab title, the tab contents, the suggested tab order
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     require_lang('chat');
     require_lang('ocf');
     $title = do_lang_tempcode('FRIENDS');
     $order = 70;
     if ($leave_to_ajax_if_possible) {
         return array($title, NULL, $order);
     }
     // Friends
     $friends_a = array();
     $friends_b = array();
     $add_friend_url = new ocp_tempcode();
     $remove_friend_url = new ocp_tempcode();
     $all_buddies_link = new ocp_tempcode();
     if (addon_installed('chat')) {
         require_code('chat');
         if ($member_id_of != $member_id_viewing && !is_guest()) {
             if (!member_befriended($member_id_of)) {
                 $add_friend_url = build_url(array('page' => 'chat', 'type' => 'buddy_add', 'member_id' => $member_id_of, 'redirect' => get_self_url(true)), get_module_zone('chat'));
             } else {
                 $remove_friend_url = build_url(array('page' => 'chat', 'type' => 'buddy_remove', 'member_id' => $member_id_of, 'redirect' => get_self_url(true)), get_module_zone('chat'));
             }
         }
         $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'chat_buddies WHERE member_likes=' . strval(intval($member_id_of)) . ' OR member_liked=' . strval(intval($member_id_of)) . ' ORDER BY date_and_time', 100);
         //$rows=array(array('member_liked'=>2,'member_likes'=>3),array('member_liked'=>3,'member_likes'=>2));
         $blocked = collapse_1d_complexity('member_blocked', $GLOBALS['SITE_DB']->query_select('chat_blocking', array('member_blocked'), array('member_blocker' => $member_id_of)));
         $done_already = array();
         $all_usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, NULL, $member_id_of);
         foreach ($rows as $i => $row) {
             $f_id = $row['member_liked'] == $member_id_of ? $row['member_likes'] : $row['member_liked'];
             if (array_key_exists($f_id, $done_already)) {
                 continue;
             }
             if ($f_id == $row['member_likes'] || !in_array($f_id, $blocked)) {
                 $appears_twice = false;
                 foreach ($rows as $j => $row2) {
                     $f_id_2 = $row2['member_liked'] == $member_id_of ? $row2['member_likes'] : $row2['member_liked'];
                     if ($f_id_2 == $f_id && $i != $j) {
                         $appears_twice = true;
                         break;
                     }
                 }
                 require_code('ocf_members');
                 require_code('ocf_members2');
                 $friend_username = $GLOBALS['FORUM_DRIVER']->get_username($f_id);
                 $friend_usergroup_id = $GLOBALS['FORUM_DRIVER']->get_member_row_field($f_id, 'm_primary_group');
                 $friend_usergroup = array_key_exists($friend_usergroup_id, $all_usergroups) ? $all_usergroups[$friend_usergroup_id] : do_lang_tempcode('UNKNOWN');
                 $mutual_label = do_lang('MUTUAL_FRIEND');
                 $box = ocf_show_member_box($f_id, false, NULL, NULL, true, $f_id == $member_id_viewing || $member_id_of == $member_id_viewing ? array($mutual_label => do_lang($appears_twice ? 'YES' : 'NO')) : NULL);
                 if ($box->is_empty()) {
                     continue;
                 }
                 $friend_map = array('USERGROUP' => $friend_usergroup, 'USERNAME' => $friend_username, 'URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($f_id, false, true), 'F_ID' => strval($f_id), 'BOX' => $box);
                 if ($appears_twice) {
                     $friends_a[] = $friend_map;
                 } else {
                     $friends_b[] = $friend_map;
                 }
             }
             $done_already[$f_id] = 1;
         }
         if (count($rows) == 100) {
             $all_buddies_link = build_url(array('page' => 'chat', 'type' => 'buddies_list', 'id' => $member_id_of), get_module_zone('chat'));
         }
     }
     $content = do_template('OCF_MEMBER_PROFILE_FRIENDS', array('MEMBER_ID' => strval($member_id_of), 'FRIENDS_A' => $friends_a, 'FRIENDS_B' => $friends_b, 'ALL_BUDDIES_LINK' => $all_buddies_link, 'ADD_FRIEND_URL' => $add_friend_url, 'REMOVE_FRIEND_URL' => $remove_friend_url));
     return array($title, $content, $order);
 }
Esempio n. 3
0
/**
 * Output messages (in XML format) from up to five minutes ago (give somebody who's just joined the chatroom some chat backlog), or the messages posted since the last check.
 *
 * @param  AUTO_LINK			Room ID (or -1 to mean 'all' as used for IM global process, -2 to mean none)
 * @param  boolean			Output the backlog?
 * @param  ?AUTO_LINK		Latest received message ID (NULL: we're not getting latest messages)
 * @param  ?AUTO_LINK		Latest event ID (NULL: we're not getting events, but we do request a null event so we can use that as a future reference point)
 * @param  string				Events output to append
 */
function _chat_messages_script_ajax($room_id, $backlog = false, $message_id = NULL, $event_id = NULL, $events_output = '')
{
    if ($event_id == -1) {
        $event_id = NULL;
    }
    require_lang('chat');
    require_lang('submitban');
    $room_check = NULL;
    if ($room_id >= 0) {
        $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'is_im', 'c_welcome', 'allow_list_groups', 'disallow_list_groups', 'allow_list', 'disallow_list', 'room_owner'), 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)) {
            return;
        }
        // Possibly the room was closed already
        $welcome = array_key_exists(get_member(), get_chatters_in_room($room_id)) || !$backlog || get_param_integer('no_reenter_message', 0) == 1 ? NULL : $room_check[0]['c_welcome'];
    } else {
        $welcome = NULL;
    }
    if ($room_id >= 0) {
        $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id));
        if (array_key_exists(0, $room_check)) {
            chat_room_prune($room_id);
        }
    } elseif ($room_id != -2) {
        // Note that *we are still here*
        if ($room_id == -1) {
            $GLOBALS['SITE_DB']->query_update('chat_active', array('date_and_time' => time()), array('member_id' => get_member()));
        } else {
            $GLOBALS['SITE_DB']->query_delete('chat_active', array('member_id' => get_member(), 'room_id' => $room_id), '', 1);
            $GLOBALS['SITE_DB']->query_insert('chat_active', array('member_id' => get_member(), 'date_and_time' => time(), 'room_id' => $room_id));
        }
    }
    if (is_null($room_check)) {
        $room_check = $GLOBALS['SITE_DB']->query('SELECT id,is_im,c_welcome,allow_list_groups,disallow_list_groups,allow_list,disallow_list,room_owner FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval(get_member()) . '%') . '\'');
    }
    $from_id = NULL;
    $start = NULL;
    if (!$backlog) {
        $from_id = $message_id;
    } else {
        $start = time() - CHAT_BACKLOG_TIME;
    }
    $messages = $room_id == -2 ? array() : chat_get_room_content($room_id, $room_check, 20, false, false, $start, NULL, $from_id, NULL, $welcome, true, get_param_integer('no_reenter_message', 0) == 0);
    $stored_id = array_key_exists(0, $messages) ? $messages[0]['id'] : NULL;
    $messages_output = '';
    foreach ($messages as $_message) {
        $edit_url = new ocp_tempcode();
        $chat_ban_url = new ocp_tempcode();
        $chat_unban_url = new ocp_tempcode();
        if (!is_null($room_check) && array_key_exists(0, $room_check)) {
            $moderator = is_chat_moderator($_message['member_id'], $room_id, $room_check[0]['room_owner']);
            $edit_url = build_url(array('page' => 'cms_chat', 'type' => 'ed', 'id' => $_message['id'], 'room_id' => $_message['room_id']), get_module_zone('cms_chat'));
            if (has_specific_permission(get_member(), 'ban_chatters_from_rooms')) {
                if (check_chatroom_access($room_check[0], true, $_message['member_id'])) {
                    $chat_ban_url = build_url(array('page' => 'cms_chat', 'type' => 'ban', 'id' => $_message['room_id'], 'member_id' => $_message['member_id']), get_module_zone('cms_chat'));
                    $chat_unban_url = new ocp_tempcode();
                } else {
                    $chat_ban_url = new ocp_tempcode();
                    $chat_unban_url = build_url(array('page' => 'cms_chat', 'type' => 'unban', 'id' => $_message['room_id'], 'member_id' => $_message['member_id']), get_module_zone('cms_chat'));
                }
            }
        } else {
            $moderator = false;
        }
        if (addon_installed('actionlog') && has_actual_page_access(get_member(), 'admin_actionlog') && preg_match('#[:\\.]#', $_message['ip_address']) != 0) {
            if (is_guest($_message['member_id'])) {
                $ban_url = build_url(array('page' => 'admin_actionlog', 'type' => 'toggle_ip_ban', 'id' => $_message['ip_address']), 'adminzone');
            } else {
                $ban_url = build_url(array('page' => 'admin_actionlog', 'type' => 'toggle_submitter_ban', 'id' => $_message['member_id']), 'adminzone');
            }
            //$ban_url=build_url(array('page'=>'admin_actionlog','type'=>'multi_ban','id'=>$_message['ip_address'].':'.$_message['username']),'adminzone');
        } else {
            $ban_url = new ocp_tempcode();
        }
        if ($room_id != -1 && addon_installed('actionlog') && (has_actual_page_access(get_member(), 'admin_actionlog') || has_actual_page_access(get_member(), 'cms_chat'))) {
            $staff_actions = do_template('CHAT_STAFF_ACTIONS', array('_GUID' => 'd3fbcaa9eee688452091583ee436e465', 'CHAT_BAN_URL' => $chat_ban_url, 'CHAT_UNBAN_URL' => $chat_unban_url, 'EDIT_URL' => $edit_url, 'BAN_URL' => $ban_url));
        } else {
            $staff_actions = new ocp_tempcode();
        }
        $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($_message['member_id']);
        if (!is_guest($_message['member_id'])) {
            $user = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($_message['member_id'], true, $_message['username']);
        } else {
            if (preg_match('#[:\\.]#', $_message['ip_address']) != 0) {
                $user = make_string_tempcode(escape_html(do_lang('GUEST') . '-' . substr(md5($_message['ip_address']), 0, 5)));
            } else {
                $user = make_string_tempcode(escape_html($_message['ip_address']));
            }
        }
        $template = do_template('CHAT_MESSAGE', array('_GUID' => '6bcac8d9fdd166cde266f8d23b790b69', 'SYSTEM_MESSAGE' => strval($_message['system_message']), 'STAFF' => $moderator, 'OLD_MESSAGES' => $backlog, 'AVATAR_URL' => $avatar_url, 'STAFF_ACTIONS' => $staff_actions, 'USER' => $user, 'MESSAGE' => $_message['the_message'], 'TIME' => $_message['date_and_time_nice'], '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="' . strval($_message['id']) . '" timestamp="' . strval($_message['date_and_time']) . '">' . $template->evaluate() . '</div>';
    }
    // Members update, but only for the room interface
    if ($room_id >= 0) {
        $tpl = get_chatters_in_room_tpl(get_chatters_in_room($room_id));
        $events_output .= '<chat_members_update>' . escape_html($tpl->evaluate()) . '</chat_members_update>';
    }
    // IM events and invitations, but only for the lobby IM interface
    $invitations_output = '';
    if ($room_id < 0) {
        $room_check = list_to_map('id', $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval(get_member()) . '%') . '\''));
        foreach ($room_check as $room) {
            if (check_chatroom_access($room, true, NULL, true)) {
                if ($room['allow_list'] == strval(get_member()) && is_null($event_id)) {
                    require_code('chat2');
                    delete_chatroom($room['id']);
                } else {
                    $people_in_room = explode(',', $room['allow_list']);
                    if ($room['room_name'] == $GLOBALS['FORUM_DRIVER']->get_username(get_member()) && count($people_in_room) > 1) {
                        $test = $GLOBALS['FORUM_DRIVER']->get_username(intval($people_in_room[1]));
                        if (!is_null($test)) {
                            $room['room_name'] = $test;
                        }
                    }
                    // Find who else is in room
                    $participants = '';
                    foreach ($people_in_room as $person) {
                        if (intval($person) != get_member()) {
                            if ($participants != '') {
                                $participants .= '';
                            }
                            $participants .= $person;
                        }
                    }
                    $num_posts = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)', array('room_id' => $room['id']));
                    $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($room['room_owner']);
                    $invitations_output .= '<chat_invite num_posts="' . strval($num_posts) . '" you="' . strval(get_member()) . '" inviter="' . (is_null($room['room_owner']) ? '' : strval($room['room_owner'])) . '" participants="' . xmlentities($participants) . '" room_name="' . xmlentities($room['room_name']) . '" avatar_url="' . xmlentities($avatar_url) . '">' . strval($room['id']) . '</chat_invite>';
                }
            }
        }
        if (!is_null($event_id)) {
            $events = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_events WHERE id>' . strval((int) $event_id));
            foreach ($events as $event) {
                if ($event['e_member_id'] == get_member()) {
                    continue;
                }
                if (is_guest($event['e_member_id'])) {
                    continue;
                }
                $send_out = false;
                switch ($event['e_type_code']) {
                    case 'BECOME_INACTIVE':
                    case 'BECOME_ACTIVE':
                        if (!member_blocked(get_member(), $event['e_member_id']) && member_befriended($event['e_member_id'])) {
                            $send_out = true;
                        }
                        break;
                    case 'PREINVITED_TO_IM':
                    case 'JOIN_IM':
                        if (array_key_exists($event['e_room_id'], $room_check) && check_chatroom_access($room_check[$event['e_room_id']], true, NULL, true)) {
                            $send_out = true;
                        }
                        break;
                    case 'DEINVOLVE_IM':
                        if (array_key_exists($event['e_room_id'], $room_check) && check_chatroom_access($room_check[$event['e_room_id']], true, NULL, true)) {
                            $send_out = true;
                        }
                        break;
                    case 'INVITED_TO_IM':
                        // Ignore this one
                        break;
                }
                if ($send_out) {
                    $username = $GLOBALS['FORUM_DRIVER']->get_username($event['e_member_id']);
                    $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($event['e_member_id']);
                    if (!is_null($username)) {
                        $events_output .= '<chat_event away="' . (chatter_active($event['e_member_id']) ? '0' : '1') . '" event_type="' . $event['e_type_code'] . '" member_id="' . strval($event['e_member_id']) . '" username="******" avatar_url="' . xmlentities($avatar_url) . '" room_id="' . (is_null($event['e_room_id']) ? '' : strval($event['e_room_id'])) . '">' . strval($event['id']) . '</chat_event>';
                    }
                }
            }
        } else {
            $max_id = $GLOBALS['SITE_DB']->query_value('chat_events', 'MAX(id)');
            if (is_null($max_id)) {
                $max_id = db_get_first_id() - 1;
            }
            $events_output .= '<chat_event type="NULL">' . strval($max_id) . '</chat_event>';
        }
    }
    if ($messages_output == '') {
        $messages_output = '<chat_null>' . strval($room_id) . '</chat_null>';
    }
    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>
		' . $events_output . $invitations_output . $messages_output . '
	</result>
</response>';
    echo $output;
}