Ejemplo 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;
 }
Ejemplo n.º 2
0
/**
 * Get a map of members viewing the specified ocPortal location.
 *
 * @param  ?ID_TEXT		The page they need to be viewing (NULL: don't care)
 * @param  ?ID_TEXT		The page-type they need to be viewing (NULL: don't care)
 * @param  ?SHORT_TEXT	The type-id they need to be viewing (NULL: don't care)
 * @param  boolean		Whether this has to be done over the forum driver (multi site network)
 * @return ?array			A map of member-ids to rows about them (except for guest, which is a count) (NULL: Too many)
 */
function get_members_viewing($page = NULL, $type = NULL, $id = NULL, $forum_layer = false)
{
    // Update the member tracking
    member_tracking_update();
    global $ZONE;
    if ($page === NULL) {
        $page = get_param('page', $ZONE['zone_default_page']);
    }
    if ($type === NULL) {
        $type = get_param('type', '/');
    }
    if ($id === NULL) {
        $id = get_param('id', '/', true);
    }
    if ($type == '/') {
        $type = '';
    }
    if ($id == '/') {
        $id = '';
    }
    $map = array();
    if ($page !== NULL && $page != '') {
        $map['mt_page'] = $page;
    }
    if ($type !== NULL && $type != '') {
        $map['mt_type'] = $type;
    }
    if ($id !== NULL && $id != '') {
        $map['mt_id'] = $id;
    }
    $map['session_invisible'] = 0;
    $db = $forum_layer ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $results = $db->query_select('member_tracking t LEFT JOIN ' . $db->get_table_prefix() . 'sessions s ON t.mt_member_id=s.the_user', array('*'), $map, ' AND mt_member_id<>' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' ORDER BY mt_member_id', 200);
    if (count($results) == 200) {
        return NULL;
    }
    unset($map['session_invisible']);
    $num_guests = $db->query_value('member_tracking t', 'COUNT(*)', $map, ' AND mt_member_id=' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()));
    $results = remove_duplicate_rows($results, 'mt_member_id');
    $out = array($GLOBALS['FORUM_DRIVER']->get_guest_id() => $num_guests);
    foreach ($results as $row) {
        if (!member_blocked(get_member(), $row['mt_member_id'])) {
            $out[$row['mt_member_id']] = $row;
        }
    }
    return $out;
}
Ejemplo n.º 3
0
/**
 * Get database rows of all the online members.
 *
 * @param  boolean		Whether to use a longer online-time -- the session expiry-time
 * @param  ?MEMBER		We really only need to make sure we get the status for this user, although at this functions discretion more may be returned and the row won't be there if the user is not online (NULL: no filter). May not be the guest ID
 * @param  integer		The total online members, returned by reference
 * @return ?array			Database rows (NULL: too many)
 */
function get_online_members($longer_time, $filter, &$count)
{
    $users_online_time_seconds = $longer_time ? 60 * 60 * intval(get_option('session_expiry_time')) : 60 * intval(get_option('users_online_time'));
    if (get_value('session_prudence') === '1') {
        // If we have multiple servers this many not be accurate as we probably turned replication off for the sessions table. The site design should be updated to not show this kind of info
        $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'sessions WHERE last_activity>' . strval($users_online_time_seconds));
        if (!is_null($filter)) {
            return $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'sessions WHERE last_activity>' . strval($users_online_time_seconds) . ' AND the_user='******'FORUM_DRIVER']->get_guest_id();
    global $SESSION_CACHE;
    $members_online = 0;
    foreach ($SESSION_CACHE as $row) {
        if (!isset($row['the_user'])) {
            continue;
        }
        // Workaround to HipHop PHP weird bug
        if ($row['last_activity'] > $cutoff && $row['session_invisible'] == 0) {
            if ($row['the_user'] == $guest_id) {
                $count++;
                $members[] = $row;
                $members_online++;
                if ($members_online == 200) {
                    if (!is_null($filter)) {
                        // Unless we are filtering
                        return $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'sessions WHERE last_activity>' . strval($users_online_time_seconds) . ' AND the_user='******'the_user'])) {
                $count++;
                $members[-$row['the_user']] = $row;
                // - (minus) is just a hackerish thing to allow it to do a unique, without messing with the above
            }
        }
    }
    return $members;
}
Ejemplo n.º 4
0
 /**
  * The UI to choose a chat room.
  *
  * @return tempcode		The UI
  */
 function chat_lobby()
 {
     require_javascript('javascript_ajax_people_lists');
     // Who are we viewing the lobby of?
     $member_id = get_param_integer('member_id', get_member());
     if (!is_guest($member_id)) {
         enforce_personal_access($member_id);
     }
     // Starting an IM? The IM will popup by AJAX once the page loads, because it's in the system now
     $enter_im = get_param_integer('enter_im', NULL);
     if (!is_null($enter_im) && !is_guest()) {
         $test = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval($enter_im) . '%') . '\'');
         $found_one = false;
         foreach ($test as $t) {
             if (check_chatroom_access($t, true, $enter_im) && check_chatroom_access($t, true, get_member())) {
                 $found_one = true;
             }
         }
         if (!$found_one) {
             require_code('chat2');
             add_chatroom('', $GLOBALS['FORUM_DRIVER']->get_username(get_member()), get_member(), strval(get_member()) . ',' . strval($enter_im), '', '', '', user_lang(), 1);
         }
     }
     // And empty IM conversations
     $old_dead_ims = $GLOBALS['SITE_DB']->query('SELECT r.* FROM ' . get_table_prefix() . 'chat_rooms r JOIN ' . get_table_prefix() . 'chat_events e ON e.e_room_id=r.id AND ' . db_string_equal_to('e.e_type_code', 'JOIN_IM') . ' LEFT JOIN ' . get_table_prefix() . 'chat_messages m ON m.room_id=r.id WHERE r.is_im=1 AND e_date_and_time<' . strval(time() - CHAT_EVENT_PRUNE) . ' AND m.id IS NULL');
     foreach ($old_dead_ims as $old) {
         require_code('chat2');
         delete_chatroom($old['id']);
     }
     // Prune chat events
     $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'chat_events WHERE e_date_and_time<' . strval(time() - CHAT_EVENT_PRUNE));
     enter_chat_lobby();
     // Generic stuff: Title, feed URL
     $title = get_page_title('CHAT_LOBBY');
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=chat&filter=';
     // Rooms
     $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('is_im' => 0), 'ORDER BY room_name DESC', 200);
     if (count($rows) == 200) {
         $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('is_im' => 0, 'allow_list' => ''), 'ORDER BY room_name DESC', 200);
     }
     $fields = new ocp_tempcode();
     foreach ($rows as $myrow) {
         // Check to see if we are on the room's allow list, if we aren't, don't display the room :D
         $showroom = check_chatroom_access($myrow, true, $member_id);
         if (!handle_chatroom_pruning($myrow) && $showroom) {
             $users = get_chatters_in_room($myrow['id']);
             $usernames = get_chatters_in_room_tpl($users);
             //$url=build_url(array('page'=>'_SELF','mode'=>$mode,'type'=>'room','id'=>$myrow['id']),'_SELF');
             $url = build_url(array('page' => '_SELF', 'type' => 'room', 'id' => $myrow['id']), '_SELF');
             $room_link = do_template('CHAT_ROOM_LINK', array('PRIVATE' => $myrow['allow_list'] != '' || $myrow['allow_list_groups'] != '', 'ID' => strval($myrow['id']), 'NAME' => $myrow['room_name'], 'USERNAMES' => $usernames, 'URL' => $url));
             $fields->attach($room_link);
         }
     }
     // Extra links
     if (has_actual_page_access($member_id, 'cms_chat')) {
         $modlink = hyperlink(build_url(array('page' => 'cms_chat'), get_module_zone('cms_chat')), do_lang_tempcode('CHAT_MOD_PANEL'));
     } else {
         $modlink = new ocp_tempcode();
     }
     if (!is_guest()) {
         $blocking_link = hyperlink(build_url(array('page' => '_SELF', 'type' => 'blocking_interface'), '_SELF'), do_lang_tempcode('MEMBER_BLOCKING'));
     } else {
         $blocking_link = new ocp_tempcode();
     }
     if (has_specific_permission($member_id, 'create_private_room') && !is_guest()) {
         $private_room = hyperlink(build_url(array('page' => '_SELF', 'type' => 'private'), '_SELF'), do_lang_tempcode('CREATE_PRIVATE_ROOM'));
     } else {
         $private_room = new ocp_tempcode();
     }
     // Buddy list and IM
     if ($member_id == get_member() && !is_guest()) {
         $post_url_add_buddy = build_url(array('page' => '_SELF', 'type' => 'buddy_add', 'redirect' => get_self_url(true)), '_SELF');
         $post_url_remove_buddies = build_url(array('page' => '_SELF', 'type' => 'buddy_remove', 'redirect' => get_self_url(true)), '_SELF');
     } else {
         $post_url_add_buddy = new ocp_tempcode();
         $post_url_remove_buddies = new ocp_tempcode();
     }
     $online_url = $GLOBALS['FORUM_DRIVER']->online_members_url();
     $can_im = has_specific_permission(get_member(), 'start_im');
     $buddies = array();
     $buddy_rows = $GLOBALS['SITE_DB']->query_select('chat_buddies', array('*'), array('member_likes' => $member_id), 'ORDER BY date_and_time', 100);
     $buddy_active = get_chatters_in_room(NULL);
     global $SESSION_CACHE;
     $users_online_time_seconds = CHAT_ACTIVITY_PRUNE;
     foreach ($buddy_rows as $buddy) {
         if (array_key_exists($buddy['member_liked'], $buddy_active) && !member_blocked(get_member(), $buddy['member_liked'])) {
             $online_text = do_lang_tempcode('ACTIVE');
         } else {
             $online_text = member_is_online($buddy['member_liked']) ? do_lang_tempcode('ONLINE') : do_lang_tempcode('OFFLINE');
         }
         $username = array_key_exists($buddy['member_liked'], $buddy_active) ? $buddy_active[$buddy['member_liked']] : $GLOBALS['FORUM_DRIVER']->get_username($buddy['member_liked']);
         if (!is_null($username)) {
             $member_profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($buddy['member_liked'], true, true);
             $buddies[] = array('DATE_AND_TIME_RAW' => strval($buddy['date_and_time']), 'DATE_AND_TIME' => get_timezoned_date($buddy['date_and_time'], false), 'MEMBER_PROFILE_LINK' => $member_profile_url, 'MEMBER_ID' => strval($buddy['member_liked']), 'USERNAME' => $username, 'ONLINE_TEXT' => $online_text);
         }
     }
     $messages_php = find_script('messages');
     $im_area_template = do_template('CHAT_LOBBY_IM_AREA', array('_GUID' => 'cd230527da03caa596135f74647b2ca7', 'MESSAGES_PHP' => $messages_php, 'ROOM_ID' => '__room_id__'));
     $make_buddy_url = build_url(array('page' => '_SELF', 'type' => 'buddy_add', 'member_id' => '__id__'), '_SELF');
     $block_member_url = build_url(array('page' => '_SELF', 'type' => 'blocking_add', 'member_id' => '__id__'), '_SELF');
     $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url(-100, true, true);
     if (is_object($profile_url)) {
         $profile_url = $profile_url->evaluate();
     }
     $profile_url = str_replace('-100', '__id__', $profile_url);
     $im_participant_template = do_template('CHAT_LOBBY_IM_PARTICIPANT', array('_GUID' => '9a36efe3a449dabac6ef9866d1f6f48a', 'PROFILE_URL' => $profile_url, 'ID' => '__id__', 'ROOM_ID' => '__room_id__', 'USERNAME' => '__username__', 'ONLINE' => '__online__', 'AVATAR_URL' => '__avatar_url__', 'MAKE_BUDDY_URL' => $make_buddy_url, 'BLOCK_MEMBER_URL' => $block_member_url));
     if (!is_guest()) {
         $seteffectslink = hyperlink(build_url(array('page' => '_SELF', 'type' => 'set_effects'), '_SELF'), do_lang_tempcode('CHAT_SET_EFFECTS'), true);
     } else {
         $seteffectslink = new ocp_tempcode();
     }
     $message = new ocp_tempcode();
     $message->attach(do_lang_tempcode('WELCOME_CHAT_LOBBY', $private_room->is_empty() ? new ocp_tempcode() : do_lang_tempcode('WELCOME_CHAT_LOBBY_PRIVATE_ROOMS'), $can_im ? do_lang_tempcode('WELCOME_CHAT_LOBBY_USE_IM') : new ocp_tempcode(), $can_im ? do_lang_tempcode(get_option('sitewide_im') == '1' ? 'WELCOME_CHAT_LOBBY_USE_IM2_SITEWIDE' : 'WELCOME_CHAT_LOBBY_USE_IM2_NO_SITEWIDE') : new ocp_tempcode()));
     if (has_actual_page_access(get_member(), 'admin_chat')) {
         $add_room_url = build_url(array('page' => 'admin_chat', 'type' => 'ad'), get_module_zone('admin_chat'));
     } else {
         $add_room_url = new ocp_tempcode();
     }
     return do_template('CHAT_LOBBY_SCREEN', array('_GUID' => 'f82ddfd0dccbd25752dd05a1d87429e2', 'ADD_ROOM_URL' => $add_room_url, 'MESSAGE' => $message, 'CHAT_SOUND' => get_chat_sound_tpl(), 'IM_PARTICIPANT_TEMPLATE' => $im_participant_template, 'IM_AREA_TEMPLATE' => $im_area_template, 'BUDDIES' => $buddies, 'CAN_IM' => $can_im, 'ONLINE_URL' => $online_url, 'URL_ADD_BUDDY' => $post_url_add_buddy, 'URL_REMOVE_BUDDIES' => $post_url_remove_buddies, 'TITLE' => $title, 'ROOMS' => $fields, 'PRIVATE_ROOM' => $private_room, 'MOD_LINK' => $modlink, 'BLOCKING_LINK' => $blocking_link, 'SETEFFECTS_LINK' => $seteffectslink));
 }
Ejemplo n.º 5
0
/**
 * Get some template code showing the number of chatters in a room.
 *
 * @param	array				A mapping (user=>username) of the chatters in the room
 * @return	tempcode			The Tempcode
*/
function get_chatters_in_room_tpl($users)
{
    $usernames = new ocp_tempcode();
    $some_users = false;
    foreach ($users as $member_id => $username) {
        if (!member_blocked(get_member(), $member_id)) {
            $some_users = true;
            if (!$usernames->is_empty()) {
                $usernames->attach(escape_html(', '));
            }
            if (!is_guest($member_id)) {
                if (get_forum_type() == 'ocf') {
                    require_code('ocf_general');
                    require_code('ocf_members');
                    $colour = get_group_colour(ocf_get_member_primary_group($member_id));
                    $usernames->attach(do_template('OCF_USER_MEMBER', array('PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id, true, true), 'USERNAME' => $username, 'COLOUR' => $colour)));
                } else {
                    $usernames->attach($GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($member_id, true, $username));
                }
            } else {
                $usernames->attach(escape_html(do_lang('GUEST')));
            }
        }
    }
    if (!$some_users) {
        $usernames = do_lang_tempcode('NONE_EM');
    }
    return $usernames;
}