示例#1
0
 /**
  * Handle hooks supported bot commands. Note multiple bots may support the same commands, and all respond. It is recommended all bots support the command 'help'.
  *
  * @param  AUTO_LINK		The ID of the chat room
  * @param  string			The command used. This is just the chat message, so you can encode and recognise your own parameter scheme if you like.
  * @return ?string		Bot reply (NULL: bot does not handle the command)
  */
 function handle_commands($room_id, $command)
 {
     switch ($command) {
         case 'help':
             $out = do_lang('CHAT_HELP_BOTMSG');
             return do_lang('CHAT_WEBSITE_HELPER_BOT', $out);
         case 'users_online':
             // On the site
             $count = 0;
             $members = get_online_members(true, NULL, $count);
             if (is_null($members)) {
                 return do_lang('TOO_MANY_USERS_ONLINE');
             }
             $guests = 0;
             $site_members = '';
             foreach ($members as $member) {
                 if (is_guest($member['the_user']) || is_null($member['cache_username'])) {
                     $guests++;
                 } else {
                     if ($site_members != '') {
                         $site_members .= ', ';
                     }
                     $site_members .= '{{' . $member['cache_username'] . '}}';
                 }
             }
             // In this room
             $room_members = get_chatters_in_room($room_id);
             $_room_members = '';
             foreach ($room_members as $room_member) {
                 if ($_room_members != '') {
                     $_room_members .= ', ';
                 }
                 $_room_members .= '{{' . $room_member . '}}';
             }
             // Show our complete result
             $out = do_lang('CHAT_USERSONLINE_BOTMSG', $site_members, $_room_members);
             return do_lang('CHAT_WEBSITE_HELPER_BOT', $out);
         case 'time':
             $out = do_lang('CHAT_TIME_BOTMSG', get_timezoned_date(time(), true, true, true, true));
             return do_lang('CHAT_WEBSITE_HELPER_BOT', $out);
     }
     return NULL;
 }
示例#2
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('users_online', array('h'), array()), '', '');
     } else {
         $count = 0;
         $members = get_online_members(true, NULL, $count);
         if (is_null($members)) {
             return array('', '', do_lang('TOO_MANY_USERS_ONLINE'), '');
         }
         $out = new ocp_tempcode();
         $guests = 0;
         $valid_members = array();
         foreach ($members as $member) {
             if (is_guest($member['the_user']) || is_null($member['cache_username'])) {
                 $guests++;
             } else {
                 $valid_members[$member['cache_username']] = $member['the_user'];
             }
         }
         return array('', do_template('OCCLE_USERS_ONLINE', array('_GUID' => 'fcf779ef175895d425b706e40fb3252a', 'MEMBERS' => $valid_members, 'GUESTS' => integer_format($guests))), '', '');
     }
 }
示例#3
0
/**
 * Get the number of users on the site in the last 5 minutes. The function also maintains the statistic via the sessions table.
 *
 * @return integer		The number of users on the site
 */
function get_num_users_site()
{
    global $NUM_USERS_SITE, $PEAK_USERS_EVER;
    $users_online_time_seconds = 60 * intval(get_option('users_online_time'));
    $NUM_USERS_SITE = get_value_newer_than('users_online', time() - $users_online_time_seconds / 2);
    if ($NUM_USERS_SITE === NULL) {
        $NUM_USERS_SITE = get_value('users_online');
        $count = 0;
        get_online_members(false, NULL, $count);
        if (strval($count) != $NUM_USERS_SITE) {
            $NUM_USERS_SITE = strval($count);
            set_value('users_online', $NUM_USERS_SITE);
        }
    }
    if (intval($NUM_USERS_SITE) > intval(get_option('maximum_users')) && intval(get_option('maximum_users')) > 1 && get_page_name() != 'login' && !has_specific_permission(get_member(), 'access_overrun_site') && !running_script('cron_bridge')) {
        $GLOBALS['HTTP_STATUS_CODE'] = '503';
        header('HTTP/1.0 503 Service Unavailable');
        critical_error('BUSY', do_lang('TOO_MANY_USERS'));
    }
    if (addon_installed('stats')) {
        $PEAK_USERS_EVER = get_value_newer_than('user_peak', time() - $users_online_time_seconds * 10);
        if ($PEAK_USERS_EVER === NULL || $PEAK_USERS_EVER == '') {
            $_peak_users_user = $GLOBALS['SITE_DB']->query_value_null_ok('usersonline_track', 'MAX(peak)', NULL, '', true);
            $PEAK_USERS_EVER = $_peak_users_user === NULL ? $NUM_USERS_SITE : strval($_peak_users_user);
            set_value('user_peak', $PEAK_USERS_EVER);
        }
        if ($NUM_USERS_SITE > $PEAK_USERS_EVER) {
            // In case the record is beaten more than once within the same second
            $time = time();
            $GLOBALS['SITE_DB']->query_delete('usersonline_track', array('date_and_time' => $time), '', 1, NULL, true);
            // New record
            $GLOBALS['SITE_DB']->query_insert('usersonline_track', array('date_and_time' => $time, 'peak' => intval($NUM_USERS_SITE)), false, true);
        }
    }
    return intval($NUM_USERS_SITE);
}
示例#4
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     unset($map);
     require_css('side_blocks');
     $count = 0;
     $members = get_online_members(false, NULL, $count);
     if (is_null($members)) {
         return new ocp_tempcode();
     }
     // Too many to show
     if (get_forum_type() == 'ocf') {
         require_code('ocf_general');
         require_code('ocf_members');
         require_css('ocf');
     }
     $out = new ocp_tempcode();
     $guests = 0;
     $_members = 0;
     $done_members = array();
     $done_ips = array();
     foreach ($members as $_member) {
         $member = $_member['the_user'];
         $name = $_member['cache_username'];
         $ip = $_member['ip'];
         if (is_guest($member) || is_null($name)) {
             if (!array_key_exists($ip, $done_ips)) {
                 $done_ips[$ip] = 1;
                 $guests++;
             }
         } else {
             if (!array_key_exists($member, $done_members)) {
                 $colour = get_forum_type() == 'ocf' ? get_group_colour(ocf_get_member_primary_group($member)) : NULL;
                 $done_members[$member] = 1;
                 $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member, true, true);
                 $out->attach(do_template('BLOCK_SIDE_USERS_ONLINE_USER', array('_GUID' => 'a0b55810fe2f306c2886ec0c4cd8e8fd', 'URL' => $url, 'NAME' => $name, 'COLOUR' => $colour)));
                 $_members++;
             }
         }
     }
     $newest = new ocp_tempcode();
     $birthdays = new ocp_tempcode();
     if (get_forum_type() == 'ocf') {
         require_lang('ocf');
         // Show newest member
         if (get_option('usersonline_show_newest_member', true) == '1') {
             $newest_member = $GLOBALS['FORUM_DB']->query_select('f_members', array('m_username', 'id'), array('m_validated' => 1), 'ORDER BY id DESC', 1);
             $username_link = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($newest_member[0]['id'], false, $newest_member[0]['m_username']);
             $newest->attach(paragraph(do_lang_tempcode('NEWEST_MEMBER_WELCOME', $username_link), 'gdgdfhrug'));
         }
         // Birthdays
         if (get_option('usersonline_show_birthdays', true) == '1') {
             require_code('ocf_members');
             $_birthdays = ocf_find_birthdays();
             foreach ($_birthdays as $_birthday) {
                 $colour = get_group_colour(ocf_get_member_primary_group($_birthday['id']));
                 $birthday = do_template('OCF_USER_MEMBER', array('_GUID' => 'b2d355ff45f4b4170b937ef0753e6a78', 'COLOUR' => $colour, 'AGE' => array_key_exists('age', $_birthday) ? integer_format($_birthday['age']) : NULL, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($_birthday['id'], false, true), 'USERNAME' => $_birthday['username']));
                 $birthdays->attach($birthday);
             }
             if (!$birthdays->is_empty()) {
                 $birthdays = do_template('OCF_BIRTHDAYS', array('_GUID' => '080ed2e74efd6410bd6b83ec01962c04', 'BIRTHDAYS' => $birthdays));
             }
         }
     }
     return do_template('BLOCK_SIDE_USERS_ONLINE', array('_GUID' => 'fdfa68dff479b4ea7d517585297ea6af', 'CONTENT' => $out, 'GUESTS' => integer_format($guests), 'MEMBERS' => integer_format($_members), '_GUESTS' => strval($guests), '_MEMBERS' => strval($_members), 'BIRTHDAYS' => $birthdays, 'NEWEST' => $newest));
 }
示例#5
0
/**
 * Do the wrapper that fits around OCF module output.
 *
 * @param  tempcode		The title for the module output that we are wrapping.
 * @param  tempcode		The module output that we are wrapping.
 * @param  boolean		Whether to include the personal bar in the wrap.
 * @param  boolean		Whether to include statistics in the wrap.
 * @param  ?AUTO_LINK	The forum to make the search link search under (NULL: Users own PT forum/unknown).
 * @return tempcode		The wrapped output.
 */
function ocf_wrapper($title, $content, $show_personal_bar = true, $show_stats = true, $forum_id = NULL)
{
    global $ZONE;
    $wide = is_wide();
    if ($wide == 0 && get_value('force_forum_bar') !== '1') {
        $show_personal_bar = false;
        $show_stats = false;
    }
    // Notifications
    if (!is_guest() && (get_page_name() == 'forumview' || get_page_name() == 'topicview' || get_page_name() == 'vforums')) {
        $cache_identifier = serialize(array(get_member()));
        $_notifications = NULL;
        if ((get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0)) {
            $_notifications = get_cache_entry('_new_pp', $cache_identifier, 10000);
        }
        if (is_null($_notifications)) {
            require_code('ocf_notifications');
            list($notifications, $num_unread_pps) = generate_notifications($cache_identifier);
        } else {
            list($__notifications, $num_unread_pps) = $_notifications;
            $notifications = new ocp_tempcode();
            if (!$notifications->from_assembly($__notifications, true)) {
                require_code('ocf_notifications');
                list($notifications, $num_unread_pps) = generate_notifications($cache_identifier);
            }
            if (!$notifications->is_empty()) {
                require_javascript('javascript_ajax');
            }
        }
    } else {
        $notifications = new ocp_tempcode();
        $num_unread_pps = 0;
    }
    if ($show_personal_bar) {
        if (get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
            $member_info = ocf_read_in_member_profile(get_member(), true);
            $profile_url = $GLOBALS['OCF_DRIVER']->member_profile_url(get_member(), true, true);
            $_new_topics = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE NOT t_forum_id IS NULL AND t_cache_first_time>' . strval((int) $member_info['last_visit_time']));
            $new_topics = $_new_topics[0]['mycnt'];
            $_new_posts = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE NOT p_cache_forum_id IS NULL AND p_time>' . strval((int) $member_info['last_visit_time']));
            $new_posts = $_new_posts[0]['mycnt'];
            $max_avatar_height = ocf_get_member_best_group_property(get_member(), 'max_avatar_height');
            // Any unread PT-PPs?
            $pt_extra = $num_unread_pps == 0 ? new ocp_tempcode() : do_lang_tempcode('NUM_UNREAD', integer_format($num_unread_pps));
            $personal_topic_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => get_member()), get_module_zone('members'), NULL, true, false, false, 'tab__pts');
            $head = do_template('OCF_MEMBER_BAR', array('_GUID' => 's3kdsadf0p3wsjlcfksdj', 'AVATAR' => array_key_exists('avatar', $member_info) ? $member_info['avatar'] : '', 'PROFILE_URL' => $profile_url, 'USERNAME' => $member_info['username'], 'LOGOUT_URL' => build_url(array('page' => 'login', 'type' => 'logout'), get_module_zone('login')), 'NUM_POINTS_ADVANCE' => array_key_exists('num_points_advance', $member_info) ? make_string_tempcode(integer_format($member_info['num_points_advance'])) : do_lang('NA'), 'NUM_POINTS' => array_key_exists('points', $member_info) ? integer_format($member_info['points']) : '', 'NUM_POSTS' => integer_format($member_info['posts']), 'PRIMARY_GROUP' => $member_info['primary_group_name'], 'LAST_VISIT_DATE_RAW' => strval($member_info['last_visit_time']), 'LAST_VISIT_DATE' => $member_info['last_visit_time_string'], 'PERSONAL_TOPIC_URL' => $personal_topic_url, 'NEW_POSTS_URL' => build_url(array('page' => 'vforums', 'type' => 'misc'), get_module_zone('vforums')), 'UNREAD_TOPICS_URL' => build_url(array('page' => 'vforums', 'type' => 'unread'), get_module_zone('vforums')), 'RECENTLY_READ_URL' => build_url(array('page' => 'vforums', 'type' => 'recently_read'), get_module_zone('vforums')), 'INLINE_PERSONAL_POSTS_URL' => build_url(array('page' => 'topicview'), get_module_zone('topicview')), 'PT_EXTRA' => $pt_extra, 'NEW_TOPICS' => integer_format($new_topics), 'NEW_POSTS' => integer_format($new_posts), 'MAX_AVATAR_HEIGHT' => strval($max_avatar_height)));
        } else {
            if (count($_POST) > 0) {
                $_this_url = build_url(array('page' => 'forumview'), 'forum', array('keep_session' => 1));
            } else {
                $_this_url = build_url(array('page' => '_SELF'), '_SELF', array('keep_session' => 1), true);
            }
            $this_url = $_this_url->evaluate();
            $login_url = build_url(array('page' => 'login', 'type' => 'login', 'redirect' => $this_url), get_module_zone('login'));
            $full_link = build_url(array('page' => 'login', 'type' => 'misc', 'redirect' => $this_url), get_module_zone('login'));
            $join_url = build_url(array('page' => 'join', 'redirect' => $this_url), get_module_zone('join'));
            $head = do_template('OCF_GUEST_BAR', array('NAVIGATION' => '', 'LOGIN_URL' => $login_url, 'JOIN_LINK' => $join_url, 'FULL_LINK' => $full_link));
        }
    } else {
        $head = new ocp_tempcode();
    }
    if ($show_stats) {
        $stats = ocf_get_forums_stats();
        // Users online
        $users_online = new ocp_tempcode();
        $count = 0;
        $members = get_online_members(false, NULL, $count);
        $groups_seen = array();
        if (!is_null($members)) {
            //$members=collapse_2d_complexity('the_user','cache_username',$members);
            $guests = 0;
            foreach ($members as $bits) {
                $member = $bits['the_user'];
                $username = $bits['cache_username'];
                if ($member == $GLOBALS['OCF_DRIVER']->get_guest_id()) {
                    $guests++;
                    continue;
                }
                if (is_null($username)) {
                    continue;
                }
                $url = $GLOBALS['OCF_DRIVER']->member_profile_url($member, false, true);
                if (!array_key_exists('m_primary_group', $bits)) {
                    $bits['m_primary_group'] = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member, 'm_primary_group');
                }
                $pgid = $bits['m_primary_group'];
                //$GLOBALS['FORUM_DRIVER']->get_member_row_field($member,'m_primary_group');
                if (is_null($pgid)) {
                    continue;
                }
                // Deleted member
                $groups_seen[$pgid] = 1;
                $col = get_group_colour($pgid);
                $usergroup = ocf_get_group_name($pgid);
                if (get_value('disable_user_online_groups') === '1') {
                    $usergroup = NULL;
                    $col = NULL;
                    $groups_seen = array();
                }
                $users_online->attach(do_template('OCF_USER_MEMBER', array('_GUID' => 'a9cb1af2a04b14edd70749c944495bff', 'COLOUR' => $col, 'PROFILE_URL' => $url, 'USERNAME' => $username, 'USERGROUP' => $usergroup)));
            }
            if ($guests != 0) {
                if (!$users_online->is_empty()) {
                    $users_online->attach(do_lang_tempcode('LIST_SEP'));
                }
                $users_online->attach(do_lang_tempcode('NUM_GUESTS', integer_format($guests)));
            }
        }
        // Birthdays
        $_birthdays = ocf_find_birthdays();
        $birthdays = new ocp_tempcode();
        foreach ($_birthdays as $_birthday) {
            $birthday_link = build_url(array('page' => 'topics', 'type' => 'birthday', 'id' => $_birthday['username']), get_module_zone('topics'));
            $birthday = do_template('OCF_BIRTHDAY_LINK', array('_GUID' => 'a98959187d37d80e134d47db7e3a52fa', 'AGE' => array_key_exists('age', $_birthday) ? integer_format($_birthday['age']) : NULL, 'PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($_birthday['id'], false, true), 'USERNAME' => $_birthday['username'], 'BIRTHDAY_LINK' => $birthday_link));
            $birthdays->attach($birthday);
        }
        if (!$birthdays->is_empty()) {
            $birthdays = do_template('OCF_BIRTHDAYS', array('_GUID' => '03da2c0d46e76407d63bff22aac354bd', 'BIRTHDAYS' => $birthdays));
        }
        // Usergroup keys
        $groups = array();
        $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, NULL, NULL, true);
        foreach ($all_groups as $gid => $gtitle) {
            if ($gid == db_get_first_id()) {
                continue;
            }
            // Throw out the first, guest
            if (array_key_exists($gid, $groups_seen)) {
                $groups[] = array('GCOLOUR' => get_group_colour($gid), 'GID' => strval($gid), 'GTITLE' => $gtitle);
            }
        }
        $foot = do_template('OCF_STATS', array('_GUID' => 'sdflkdlfd303frksdf', 'NEWEST_MEMBER_PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($stats['newest_member_id'], false, true), 'NEWEST_MEMBER_USERNAME' => $stats['newest_member_username'], 'NUM_MEMBERS' => integer_format($stats['num_members']), 'NUM_TOPICS' => integer_format($stats['num_topics']), 'NUM_POSTS' => integer_format($stats['num_posts']), 'BIRTHDAYS' => $birthdays, 'USERS_ONLINE' => $users_online, 'USERS_ONLINE_URL' => has_actual_page_access(get_member(), 'onlinemembers') ? build_url(array('page' => 'onlinemembers'), get_module_zone('onlinemembers')) : new ocp_tempcode(), 'GROUPS' => $groups));
    } else {
        $foot = new ocp_tempcode();
    }
    $wrap = do_template('OCF_WRAPPER', array('_GUID' => '456c21db6c09ae260accfa4c2a59fce7', 'TITLE' => $title, 'NOTIFICATIONS' => $notifications, 'HEAD' => $head, 'FOOT' => $foot, 'CONTENT' => $content));
    return $wrap;
}
示例#6
0
/**
 * Find if a member is online.
 *
 * @param  MEMBER			The member to check
 * @return boolean		Whether they are online
 */
function member_is_online($member_id)
{
    $count = 0;
    $online = get_online_members(false, $member_id, $count);
    foreach ($online as $m) {
        if ($m['the_user'] == $member_id) {
            return true;
        }
    }
    return false;
}
示例#7
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     if (get_forum_type() != 'ocf') {
         warn_exit(do_lang_tempcode('NO_OCF'));
     } else {
         ocf_require_all_forum_stuff();
     }
     $title = get_page_title('USERS_ONLINE');
     global $EXTRA_HEAD;
     $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />');
     // XHTMLXHTML
     $count = 0;
     $members = get_online_members(has_specific_permission(get_member(), 'show_user_browsing'), NULL, $count);
     if (is_null($members) && has_specific_permission(get_member(), 'show_user_browsing')) {
         $members = get_online_members(false, NULL, $count);
     }
     if (is_null($members)) {
         warn_exit(do_lang_tempcode('TOO_MANY_USERS_ONLINE'));
     }
     $rows = new ocp_tempcode();
     $members = array_reverse($members);
     global $M_SORT_KEY;
     $M_SORT_KEY = 'last_activity';
     usort($members, 'multi_sort');
     $members = array_reverse($members);
     foreach ($members as $row) {
         $last_activity = $row['last_activity'];
         $member = $row['the_user'];
         $name = $row['cache_username'];
         $location = $row['the_title'];
         if ($location == '' && $row['the_type'] == 'rss') {
             $location = 'RSS';
             $at_url = make_string_tempcode(find_script('backend'));
         } elseif ($location == '' && $row['the_page'] == '') {
             $at_url = new ocp_tempcode();
         } else {
             $map = array('page' => $row['the_page']);
             if ($row['the_type'] != '') {
                 $map['type'] = $row['the_type'];
             }
             if ($row['the_id'] != '') {
                 $map['id'] = $row['the_id'];
             }
             $at_url = build_url($map, $row['the_zone']);
         }
         $ip = $row['ip'];
         if (substr($ip, -1) == '*') {
             if (is_guest($member)) {
                 if (addon_installed('stats')) {
                     $test = $GLOBALS['SITE_DB']->query_value_null_ok('stats', 'ip', array('the_user' => -$row['the_session']));
                     if (!is_null($test) && $test != '') {
                         $ip = $test;
                     } else {
                         $test = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT ip FROM ' . get_table_prefix() . 'stats WHERE ip LIKE \'' . db_encode_like(str_replace('*', '%', $ip)) . '\' ORDER BY date_and_time DESC');
                         if (!is_null($test) && $test != '') {
                             $ip = $test;
                         }
                     }
                 }
             } else {
                 $test = $GLOBALS['FORUM_DRIVER']->get_member_ip($member);
                 if (!is_null($test) && $test != '') {
                     $ip = $test;
                 }
             }
         }
         $link = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($member, false, $name);
         if ($ip != '') {
             // CRON?
             $rows->attach(do_template('OCF_MEMBER_ONLINE_ROW', array('_GUID' => '2573786f3bccf9e613b125befb3730e8', 'IP' => $ip, 'AT_URL' => $at_url, 'LOCATION' => $location, 'MEMBER' => $link, 'TIME' => integer_format(intval((time() - $last_activity) / 60)))));
         }
     }
     return do_template('OCF_MEMBERS_ONLINE_SCREEN', array('_GUID' => '2f63e2926c5a4690d905f97661afe6cc', 'TITLE' => $title, 'ROWS' => $rows));
 }