Online tracking img load switch

git-svn-id: file:///svn/phpbb/trunk@4269 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-07-16 11:46:04 +00:00
parent 1ccfd3f862
commit 4d003f7edf
3 changed files with 197 additions and 57 deletions

View file

@ -114,7 +114,7 @@ while ($row = $db->sql_fetchrow($result))
if (isset($_POST['submit']))
{
add_log('admin', 'LOG_' . strtoupper($mode) . '_CONFIG');
trigger_error($user->lang['Config_updated']);
trigger_error($user->lang['CONFIG_UPDATED']);
}
adm_page_header($user->lang[$l_title]);
@ -590,6 +590,8 @@ switch ($mode)
$load_db_lastread_no = (!$new['load_db_lastread']) ? 'checked="checked"' : '';
$load_online_yes = ($new['load_online']) ? 'checked="checked"' : '';
$load_online_no = (!$new['load_online']) ? 'checked="checked"' : '';
$load_onlinetrack_yes = ($new['load_onlinetrack']) ? 'checked="checked"' : '';
$load_onlinetrack_no = (!$new['load_onlinetrack']) ? 'checked="checked"' : '';
$load_birthdays_yes = ($new['load_birthdays']) ? 'checked="checked"' : '';
$load_birthdays_no = (!$new['load_birthdays']) ? 'checked="checked"' : '';
$moderators_yes = ($new['load_moderators']) ? 'checked="checked"' : '';
@ -626,6 +628,10 @@ switch ($mode)
<td class="row1"><?php echo $user->lang['YES_ONLINE']; ?>: <br /><span class="gensmall"><?php echo $user->lang['YES_ONLINE_EXPLAIN']; ?></span></td>
<td class="row2"><input type="radio" name="load_online" value="1"<?php echo $load_online_yes ?> /><?php echo $user->lang['YES'] ?>&nbsp; &nbsp;<input type="radio" name="load_online" value="0" <?php echo $load_online_no ?> /> <?php echo $user->lang['NO']; ?></td>
</tr>
<tr>
<td class="row1"><?php echo $user->lang['YES_ONLINE_TRACK']; ?>: <br /><span class="gensmall"><?php echo $user->lang['YES_ONLINE_TRACK_EXPLAIN']; ?></span></td>
<td class="row2"><input type="radio" name="load_onlinetrack" value="1"<?php echo $load_onlinetrack_yes ?> /><?php echo $user->lang['YES'] ?>&nbsp; &nbsp;<input type="radio" name="load_onlinetrack" value="0" <?php echo $load_onlinetrack_no ?> /> <?php echo $user->lang['NO']; ?></td>
</tr>
<tr>
<td class="row1"><?php echo $user->lang['VIEW_ONLINE_TIME']; ?>: <br /><span class="gensmall"><?php echo $user->lang['VIEW_ONLINE_TIME_EXPLAIN']; ?></span></td>
<td class="row2"><input class="post" type="text" size="4" maxlength="3" name="load_online_time" value="<?php echo $new['load_online_time']; ?>" /></td>

View file

@ -501,6 +501,8 @@ $lang = array_merge($lang, array(
'VIEW_ONLINE_TIME_EXPLAIN' => 'How long before users drop out of the viewonline listings, lower equals less processing.',
'YES_ONLINE' => 'Enable online user listings',
'YES_ONLINE_EXPLAIN' => 'Display online user information on index, forum and topic pages.',
'YES_ONLINE_TRACK' => 'Enable display of user online img',
'YES_ONLINE_TRACK_EXPLAIN' => 'Display online information for user in profiles and viewtopic.',
'YES_BIRTHDAYS' => 'Enable birthday listing',
'YES_MODERATORS' => 'Enable display of Moderators',
'YES_SEARCH' => 'Enable search facilities',
@ -636,6 +638,8 @@ $lang = array_merge($lang, array(
'KARMA_SETTINGS' => 'Karma Settings',
'KARMA_SETTINGS_EXPLAIN'=> 'Here you can enable and disable the user Karma rating system. You can also modify the weighting factors used to derive each users karma.',
'CONFIG_UPDATED' => 'Configuration updated successfully',
'AVATARS_GALLERY' => 'Avatar Gallery',
'AVATARS_PERSONAL' => 'Personal Avatars',

View file

@ -217,6 +217,114 @@ if ($forum_password)
}
/*
// Not final in the slightest! Far too simplistic
if (isset($_GET['rate']))
{
// Check for rating count for previous X time
// Grab existing rating for this post, if it exists
$sql = 'SELECT *
FROM ' . RATINGS_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . "
AND post_id = $post_id";
$result = $db->sql_query($sql);
switch ($_GET['rate'])
{
case 'good':
$rate = 1;
break;
case 'bad':
$rate = -1;
break;
}
$updated = ($row = $db->sql_fetchrow($result)) ? true : false;
$db->sql_freeresult($result);
// Insert rating if appropriate
$sql = (!$updated) ? 'INSERT INTO ' . RATINGS_TABLE . ' (user_id, post_id, rating, rating_time) VALUES (' . $user->data['user_id'] . ", $post_id, $rate, " . time() . ')' : 'UPDATE ' . RATINGS_TABLE . " SET rating = $rate, rating_time = " . time() . " WHERE post_id = $post_id AND user_id = " . $user->data['user_id'];
// $db->sql_query($sql);
// Rating sum and count since first post
$sql = 'SELECT p.poster_id, SUM(r.rating) AS rated, COUNT(r.rating) as total_ratings
FROM ' . RATINGS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . " p2
WHERE p2.post_id = $post_id
AND p.poster_id = p2.poster_id
AND p.post_time < " . (time() - (30 * 86400)) . '
AND r.post_id = p.post_id
AND r.user_id <> p2.poster_id
GROUP BY p.poster_id';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$total_ratings = $row['total_ratings'];
$historic_rating = ($row['rated'] / $row['total_ratings']) * 0.30;
// Rating sum and count past thirty days
$sql = 'SELECT p.poster_id, SUM(r.rating) AS rated, COUNT(r.rating) as total_ratings
FROM ' . RATINGS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . " p2
WHERE p2.post_id = $post_id
AND p.poster_id = p2.poster_id
AND p.post_time > " . (time() - (30 * 86400)) . '
AND r.post_id = p.post_id
AND r.user_id <> p2.poster_id
GROUP BY p.poster_id';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$total_ratings += $row['total_ratings'];
$thirty_day_rating = ($row['rated'] / $row['total_ratings']) * 0.50;
if ($total_ratings > $config['min_ratings'])
{
// Post count and reg date for this user
$sql = 'SELECT user_id, user_regdate, user_posts
FROM ' . USERS_TABLE . '
WHERE user_id = ' . $row['poster_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$post_count_rating = ($row['user_posts'] / $config['num_posts']) * 0.1;
$day_rating = (($row['user_regdate'] > $config['board_startdate']) ? $config['board_startdate'] / $row['user_regdate'] : 1) * 0.1;
$poster_id = $row['user_id'];
// Number of rated posts by this user
// $sql = 'SELECT COUNT(DISTINCT(p.post_id)) AS rated_posts
// FROM ' . RATINGS_TABLE . ' r , ' . POSTS_TABLE . " p
// WHERE p.poster_id = $poster_id
// AND r.post_id = p.post_id
// AND r.user_id <> $poster_id";
// $result = $db->sql_query($sql);
// $row = $db->sql_fetchrow($result);
// $db->sql_freeresult($result);
$karma = ($historic_rating + $thirty_day_rating + $day_rating + $post_count_rating) * 5;
$karma = ($karma < 0) ? floor($karma) : (($karma > 0) ? ceil($karma) : 0);
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_karma = $karma
WHERE user_id = $poster_id";
// $db->sql_query($sql);
}
meta_refresh(3, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;p=$post_id#$post_id");
$message = ($updated) ? $user->lang['RATING_UPDATED'] : $user->lang['RATING_ADDED'];
$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_POST'], "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;p=$post_id#$post_id\">", '</a>');
trigger_error($message);
}
*/
// What is start equal to?
if (!empty($post_id))
{
@ -527,7 +635,7 @@ if (!empty($poll_start))
'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
'POLL_OPTION_PERCENT' => $option_pct_txt,
'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * $user->theme['poll_length']), true),
'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250), true),
'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $voted_id)) ? true : false)
);
}
@ -556,14 +664,14 @@ if (!empty($poll_start))
// Container for user details, only process once
$user_cache = $attachments = $attach_list = $rowset = $update_count = array();
$user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = array();
$has_attachments = FALSE;
$force_encoding = '';
$bbcode_bitfield = $i = 0;
// Go ahead and pull all data for this topic
$sql = "SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, u.user_karma, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_jabber, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.*
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u
$sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, u.user_karma, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_jabber, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_allow_viewonline, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.*
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.topic_id = $topic_id
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1') . "
$limit_posts_time
@ -598,8 +706,6 @@ do
// Does post have an attachment? If so, add it to the list
if ($row['post_attachment'] && $config['allow_attachments'])
{
if ($auth->acl_get('f_download', $forum_id))
{
$attach_list[] = $row['post_id'];
@ -608,11 +714,6 @@ do
$has_attachments = TRUE;
}
}
else
{
$display_notice = TRUE;
}
}
$rowset[] = array(
'post_id' => $row['post_id'],
@ -676,18 +777,21 @@ do
$user_sig = $row['user_sig'];
$bbcode_bitfield |= $row['user_sig_bbcode_bitfield'];
}
//'<img src="images/karma' . $row['user_karma'] . '.gif" alt="' . $user->lang['KARMA_LEVEL'] . ': ' . $user->lang['KARMA'][$row['user_karma']] . '" title="' . $user->lang['KARMA_LEVEL'] . ': ' . $user->lang['KARMA'][$row['user_karma']] . '" />',
$id_cache[] = $poster_id;
$user_cache[$poster_id] = array(
'joined' => $user->format_date($row['user_regdate'], $user->lang['DATE_FORMAT']),
'posts' => (!empty($row['user_posts'])) ? $row['user_posts'] : '',
'from' => (!empty($row['user_from'])) ? $row['user_from'] : '',
'karma' => (!empty($row['user_karma'])) ? $row['user_karma'] : 0,
'karma_img' => '<img src="images/karma' . $row['user_karma'] . '.gif" alt="' . $user->lang['KARMA_LEVEL'] . ': ' . $user->lang['KARMA'][$row['user_karma']] . '" title="' . $user->lang['KARMA_LEVEL'] . ': ' . $user->lang['KARMA'][$row['user_karma']] . '" />',
'karma_img' => '',
'sig' => $user_sig,
'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
'viewonline' => $row['user_allow_viewonline'],
'avatar' => '',
'profile' => "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=$poster_id",
@ -762,9 +866,29 @@ while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result);
// Generate online information for user
if ($config['load_onlinetrack'] && sizeof($id_cache))
{
$sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_allow_viewonline) AS viewonline
FROM ' . SESSIONS_TABLE . '
WHERE session_user_id IN (' . implode(', ', $id_cache) . ')
GROUP BY session_user_id';
$result = $db->sql_query($sql);
$update_time = $config['load_online_time'] * 60;
while ($row = $db->sql_fetchrow($result))
{
$user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline'] && $user_cache[$row['session_user_id']]['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
}
}
unset($id_cache);
// Pull attachment data
if (count($attach_list))
{
if ($auth->acl_get('f_download', $forum_id))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$sql = 'SELECT a.post_id, d.*
@ -824,6 +948,11 @@ if (count($attach_list))
WHERE topic_id = $topic_id";
$db->sql_query($sql);
}
}
else
{
$display_notice = TRUE;
}
}
@ -926,7 +1055,7 @@ foreach ($rowset as $i => $row)
{
// This was shamelessly 'borrowed' from volker at multiartstudio dot de
// via php.net's annotated manual
$message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '<span class=\"posthighlight\">\\\\1</span>', '\\0')", '>' . $message . '<'), 1, -1));
$message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '<span class=\"posthilit\">\\\\1</span>', '\\0')", '>' . $message . '<'), 1, -1));
}
@ -975,6 +1104,7 @@ foreach ($rowset as $i => $row)
'POST_ICON_IMG' => (!empty($row['icon_id'])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '',
'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'],
'KARMA_IMG' => $user_cache[$poster_id]['karma_img'],
'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$config['load_trackonline']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('btn_online', $user->lang['ONLINE']) : $user->img('btn_offline', $user->lang['OFFLINE'])),
'U_EDIT' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? "posting.$phpEx$SID&amp;mode=edit&amp;f=$forum_id&amp;p=" . $row['post_id'] : '',
'U_QUOTE' => ($auth->acl_get('f_quote', $forum_id)) ? "posting.$phpEx$SID&amp;mode=quote&amp;f=$forum_id&amp;p=" . $row['post_id'] : '',