From 4d003f7edf696e7607284f9a6dd082e2b336c64f Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Wed, 16 Jul 2003 11:46:04 +0000 Subject: [PATCH] Online tracking img load switch git-svn-id: file:///svn/phpbb/trunk@4269 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_board.php | 8 +- phpBB/language/en/lang_admin.php | 4 + phpBB/viewtopic.php | 242 ++++++++++++++++++++++++------- 3 files changed, 197 insertions(+), 57 deletions(-) diff --git a/phpBB/adm/admin_board.php b/phpBB/adm/admin_board.php index 548d322a9c..fc9a12d365 100644 --- a/phpBB/adm/admin_board.php +++ b/phpBB/adm/admin_board.php @@ -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) lang['YES_ONLINE']; ?>:
lang['YES_ONLINE_EXPLAIN']; ?> />lang['YES'] ?>    /> lang['NO']; ?> + + lang['YES_ONLINE_TRACK']; ?>:
lang['YES_ONLINE_TRACK_EXPLAIN']; ?> + />lang['YES'] ?>    /> lang['NO']; ?> + lang['VIEW_ONLINE_TIME']; ?>:
lang['VIEW_ONLINE_TIME_EXPLAIN']; ?> diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php index daa7fcbe45..310f802a33 100644 --- a/phpBB/language/en/lang_admin.php +++ b/phpBB/language/en/lang_admin.php @@ -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', diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 2de840f72d..6f3b672195 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -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&f=$forum_id&t=$topic_id&p=$post_id#$post_id"); + $message = ($updated) ? $user->lang['RATING_UPDATED'] : $user->lang['RATING_ADDED']; + $message = $message . '

' . sprintf($user->lang['RETURN_POST'], "", ''); + 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 @@ -599,18 +707,11 @@ 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']; + $attach_list[] = $row['post_id']; - if ($row['post_approved']) - { - $has_attachments = TRUE; - } - } - else + if ($row['post_approved']) { - $display_notice = TRUE; + $has_attachments = TRUE; } } @@ -676,18 +777,21 @@ do $user_sig = $row['user_sig']; $bbcode_bitfield |= $row['user_sig_bbcode_bitfield']; } - +//'' . $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' => '' . $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&mode=viewprofile&u=$poster_id", @@ -762,45 +866,73 @@ 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)) { - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - - $sql = 'SELECT a.post_id, d.* - FROM ' . ATTACHMENTS_TABLE . ' a, ' . ATTACHMENTS_DESC_TABLE . ' d - WHERE a.post_id IN (' . implode(', ', $attach_list) . ') - AND a.attach_id = d.attach_id - ORDER BY d.filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', a.post_id ASC'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) + if ($auth->acl_get('f_download', $forum_id)) { - $attachments[$row['post_id']][] = $row; - } - $db->sql_freeresult($result); + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - // No attachments exist, but post table thinks they do - // so go ahead and reset post_attach flags - if (!count($attachments)) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 0 - WHERE post_id IN (' . implode(', ', $attach_list) . ')'; - $db->sql_query($sql); + $sql = 'SELECT a.post_id, d.* + FROM ' . ATTACHMENTS_TABLE . ' a, ' . ATTACHMENTS_DESC_TABLE . ' d + WHERE a.post_id IN (' . implode(', ', $attach_list) . ') + AND a.attach_id = d.attach_id + ORDER BY d.filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', a.post_id ASC'; + $result = $db->sql_query($sql); - // We need to update the topic indicator too if the complete topic is now without an attachment - if (count($rowset) != $total_posts) + while ($row = $db->sql_fetchrow($result)) { - // Not all posts are displayed so we query the db to find if there's any attachment for this topic - $sql = 'SELECT a.post_id - FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p - WHERE p.topic_id = $topic_id - AND p.post_approved = 1 - AND p.post_id = a.post_id"; - $result = $db->sql_query_limit($sql, 1); + $attachments[$row['post_id']][] = $row; + } + $db->sql_freeresult($result); - if (!$db->sql_fetchrow($result)) + // No attachments exist, but post table thinks they do + // so go ahead and reset post_attach flags + if (!count($attachments)) + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_attachment = 0 + WHERE post_id IN (' . implode(', ', $attach_list) . ')'; + $db->sql_query($sql); + + // We need to update the topic indicator too if the complete topic is now without an attachment + if (count($rowset) != $total_posts) + { + // Not all posts are displayed so we query the db to find if there's any attachment for this topic + $sql = 'SELECT a.post_id + FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p + WHERE p.topic_id = $topic_id + AND p.post_approved = 1 + AND p.post_id = a.post_id"; + $result = $db->sql_query_limit($sql, 1); + + if (!$db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_attachment = 0 + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + } + } + else { $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_attachment = 0 @@ -808,21 +940,18 @@ if (count($attach_list)) $db->sql_query($sql); } } - else + elseif ($has_attachments && !$topic_data['topic_attachment']) { + // Topic has approved attachments but its flag is wrong $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_attachment = 0 + SET topic_attachment = 1 WHERE topic_id = $topic_id"; $db->sql_query($sql); } } - elseif ($has_attachments && !$topic_data['topic_attachment']) + else { - // Topic has approved attachments but its flag is wrong - $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_attachment = 1 - WHERE topic_id = $topic_id"; - $db->sql_query($sql); + $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', '\\\\1', '\\0')", '>' . $message . '<'), 1, -1)); + $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '\\\\1', '\\0')", '>' . $message . '<'), 1, -1)); } @@ -975,6 +1104,7 @@ foreach ($rowset as $i => $row) 'POST_ICON_IMG' => (!empty($row['icon_id'])) ? '' : '', '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&mode=edit&f=$forum_id&p=" . $row['post_id'] : '', 'U_QUOTE' => ($auth->acl_get('f_quote', $forum_id)) ? "posting.$phpEx$SID&mode=quote&f=$forum_id&p=" . $row['post_id'] : '',