function read_tree($force = false) { global $db, $userdata, $board_config, $HTTP_COOKIE_VARS; global $tree; global $phpbb_root_path, $phpEx; // get censored words $orig_word = array(); $replacement_word = array(); obtain_word_list($orig_word, $replacement_word); //-- mod : keep unread ----------------------------------------------------------------------------- //-- delete // // read the user cookie // $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array(); // $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array(); // $tracking_all = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) ? intval($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) : -1; //-- fin mod : keep unread ------------------------------------------------------------------------- // extended auth compliancy $sql_extend_auth = ''; if (defined('EXTEND_AUTH_INSTALLED')) { $sql_extend_auth = ' AND aa.auth_type = ' . POST_FORUM_URL; } // try the cache $use_cache_file = false; create_tree(); // read the user auth and the last post of each forums if ($userdata['session_logged_in']) { $sql_select = ', a.*, ug.user_id'; $sql_from = "LEFT JOIN " . AUTH_ACCESS_TABLE . " a ON a.forum_id = f.forum_id )\n\t\t\t\t\tLEFT JOIN " . USER_GROUP_TABLE . " ug ON ug.group_id = a.group_id AND ug.user_id = " . intval($userdata['user_id']) . " AND ug.user_pending=0 )"; } else { $sql_select = ''; $sql_from = '))'; } $sql = "SELECT f.forum_id AS forum_id_main, f.forum_last_post_id {$sql_select}\n\t\t\t\tFROM ((" . FORUMS_TABLE . " f {$sql_from}"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Couldn\'t access list of last posts from forums', '', __LINE__, __FILE__, $sql); } $u_access = array(); $s_last_posts = ''; $last_posts = array(); while ($row = $db->sql_fetchrow($result)) { // get the last post if (!empty($row['forum_last_post_id']) && !isset($last_posts[$row['forum_last_post_id']])) { $last_posts[$row['forum_last_post_id']] = $row['forum_id_main']; $s_last_posts .= (empty($s_last_posts) ? '' : ', ') . $row['forum_last_post_id']; } // get the access auth if ($userdata['session_logged_in'] && $row['user_id'] == $userdata['user_id']) { $u_access[$row['forum_id_main']][] = $row; } } $userdata['user_forums_auth'] = $u_access; $sql_last_posts = empty($s_last_posts) ? '' : " OR p.post_id IN ({$s_last_posts})"; // read the last or unread posts //-- mod : keep unread ----------------------------------------------------------------------------- //-- delete // $user_lastvisit = $userdata['session_logged_in'] ? $userdata['user_lastvisit'] : 99999999999; //-- add // get last visit for guest if (!$userdata['session_logged_in']) { $userdata['user_lastvisit'] = $board_config['guest_lastvisit']; } $user_lastvisit = $userdata['user_lastvisit']; // unreads $sql_unreads = ''; if (!empty($board_config['tracking_unreads'])) { // get the unreads topic id @reset($board_config['tracking_unreads']); while (list($id, $time) = @each($board_config['tracking_unreads'])) { // don't add obsolete cookies if ($time > intval($board_config['tracking_all']) && $time > intval($board_config['tracking_topics'][$id])) { $sql_unreads .= (empty($sql_unreads) ? '' : ', ') . $id; } } if (!empty($sql_unreads)) { $sql_unreads = " OR p.topic_id IN ({$sql_unreads})"; } } // prepare the result $new_unreads = array(); //-- fin mod : keep unread ------------------------------------------------------------------------- //-- mod : keep unread ----------------------------------------------------------------------------- // here we added // $sql_unreads //-- modify $sql = "SELECT p.forum_id, p.topic_id, p.post_time, p.post_username, u.username, u.user_id, t.topic_last_post_id, t.topic_title\n\t\t\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u\n\t\t\t\tWHERE ( p.post_time > {$user_lastvisit} {$sql_last_posts} {$sql_unreads} )\n\t\t\t\t\t\tAND p.post_id = t.topic_last_post_id\n\t\t\t\t\t\tAND t.topic_id = p.topic_id AND t.forum_id = p.forum_id AND t.topic_moved_id = 0\n\t\t\t\t\t\tAND u.user_id = p.poster_id"; //-- fin mod : keep unread ------------------------------------------------------------------------- if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Couldn\'t access list of unread posts from forums', '', __LINE__, __FILE__, $sql); } $new_topic_data = array(); while ($row = $db->sql_fetchrow($result)) { //-- mod : keep unread ----------------------------------------------------------------------------- //-- delete // if ( $row['post_time'] > $user_lastvisit ) // { //-- add // get some ids $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; // check the validity of the cookies : forum if (isset($board_config['tracking_forums'][$forum_id])) { if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_forums'][$forum_id]) { unset($board_config['tracking_forums'][$forum_id]); } } // topic cookie still valid ? if (isset($board_config['tracking_topics'][$topic_id])) { if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_topics'][$topic_id] || isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] >= $board_config['tracking_topics'][$topic_id]) { unset($board_config['tracking_topics'][$topic_id]); } } // unread cookie still valid ? if (isset($board_config['tracking_unreads'][$topic_id])) { if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_unreads'][$topic_id] || isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] >= $board_config['tracking_unreads'][$topic_id] || isset($board_config['tracking_topics'][$topic_id]) && $board_config['tracking_topics'][$topic_id] >= $board_config['tracking_unreads'][$topic_id]) { unset($board_config['tracking_unreads'][$topic_id]); } } // have we got a last visit time for this topic $topic_last_read = intval($board_config['tracking_unreads'][$topic_id]); if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] > $topic_last_read) { $topic_last_read = $board_config['tracking_all']; } if (isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] > $topic_last_read) { $topic_last_read = $board_config['tracking_forums'][$forum_id]; } if (isset($board_config['tracking_topics'][$topic_id]) && $board_config['tracking_topics'][$topic_id] > $topic_last_read) { $topic_last_read = $board_config['tracking_topics'][$topic_id]; } if (empty($topic_last_read)) { $topic_last_read = $userdata['user_lastvisit']; } // check the topic last visit time if ($row['post_time'] > $topic_last_read) { $new_unreads[$topic_id] = $topic_last_read; //-- fin mod : keep unread ------------------------------------------------------------------------- $new_topic_data[$row['forum_id']][$row['topic_id']] = $row['post_time']; } if (isset($last_posts[$row['topic_last_post_id']])) { // topic title censor if (count($orig_word)) { $row['topic_title'] = preg_replace($orig_word, $replacement_word, $row['topic_title']); } // store the added columns $idx = $tree['keys'][POST_FORUM_URL . $row['forum_id']]; @reset($row); while (list($key, $value) = @each($row)) { $nkey = intval($key); if ($key != "{$nkey}") { $tree['data'][$idx][$key] = $row[$key]; } } } } //-- mod : keep unread ----------------------------------------------------------------------------- //-- add // update the unread topics from the list readed $board_config['tracking_unreads'] = $new_unreads; // except the cookies write_cookies($userdata); //-- fin mod : keep unread ------------------------------------------------------------------------- // set the unread flag $tree['unread_topics'] = array(); for ($i = 0; $i < count($tree['data']); $i++) { if ($tree['type'][$i] == POST_FORUM_URL) { // get the last post time per forums $forum_id = $tree['id'][$i]; $unread_topics = false; if (!empty($new_topic_data[$forum_id])) { $forum_last_post_time = 0; @reset($new_topic_data[$forum_id]); while (list($check_topic_id, $check_post_time) = @each($new_topic_data[$forum_id])) { //-- mod : keep unread ----------------------------------------------------------------------------- //-- delete // if ( empty($tracking_topics[$check_topic_id]) ) // { //-- fin mod : keep unread ------------------------------------------------------------------------- $unread_topics = true; $forum_last_post_time = max($check_post_time, $forum_last_post_time); //-- mod : keep unread ----------------------------------------------------------------------------- //-- delete // } // else // { // if ( $tracking_topics[$check_topic_id] < $check_post_time ) // { // $unread_topics = true; // $forum_last_post_time = max($check_post_time, $forum_last_post_time); // } // } // } // // // is there a cookie for this forum ? // if ( !empty($tracking_forums[$forum_id]) ) // { // if ( $tracking_forums[$forum_id] > $forum_last_post_time ) // { // $unread_topics = false; // } // } // // // is there a cookie for all forums ? // if ( $tracking_all > $forum_last_post_time ) // { // $unread_topics = false; //-- fin mod : keep unread ------------------------------------------------------------------------- } } // store the result $tree['unread_topics'][$i] = $unread_topics; } } return; }
$mark_read = isset($HTTP_POST_VARS['mark']) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark']; } else { $mark_read = ''; } // // Handle marking posts // if ($mark_read == 'forums') { //START MOD Keep_unread_2 * Mark everything as read $board_config['tracking_time'] = time(); //at this moment $board_config['tracking_forums'] = array(); //clean $board_config['tracking_unreads'] = array(); //clean write_cookies($userdata); //END MOD Keep_unread_2 $template->assign_vars(array("META" => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.{$phpEx}") . '">')); $message = $lang['Forums_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.{$phpEx}") . '">', '</a> '); message_die(GENERAL_MESSAGE, $message); } // // End handle marking posts // //-- mod: sf $_sf_root_forum_id = 0; } else { // we are in viewforum if (!defined('IN_PHPBB')) { die('Hack attempt!'); }
function list_new_unreads(&$forum_unread, $check_auth = 0) { global $board_config, $userdata, $db; //Clean tracking_forums $tracking_time = $board_config['tracking_time'] != 0 ? $board_config['tracking_time'] : $userdata['user_lastvisit']; if ($tracking_time == '') { $tracking_time = 0; } if (!empty($board_config['tracking_forums'])) { @reset($board_config['tracking_forums']); //Mark whole forum as read records while (list($id, $time) = @each($board_config['tracking_forums'])) { //obsolete if forum was marked read before current visit time if ($time <= $tracking_time) { unset($board_config['tracking_forums'][$id]); } } } //get list of remembered topic id's @reset($board_config['tracking_unreads']); //Mark whole forum as read records $list_unreads = ''; while (list($id, $time) = @each($board_config['tracking_unreads'])) { if ($id) { $list_unreads .= ($list_unreads ? ',' : '') . $id; } } $new_unreads = array(); $forum_unread = array(); $sql_and = array(); $sql_and[] = "p.post_time > {$tracking_time}"; if (!empty($list_unreads)) { $sql_and[] = "t.topic_id IN ({$list_unreads}) AND (p.post_time <= {$tracking_time})"; } $check_auth_sql = ''; // the next line of code artificially sets $auth_list to true so that when it is used later on // in an if statement the if statement will resolve to true if either (a) $check_auth is false (since in // that case $auth_list never gets reset) or (b) $check_auth is true and the user is authorized // to view some forums $auth_list = TRUE; if ($check_auth) { // get a list of all forums the user is allowed to read $is_auth_ary = array(); $forum_ids = array(); $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); if (count($is_auth_ary)) { foreach ($is_auth_ary as $forum_id => $auths) { if ($auths['auth_read']) { $forum_ids[] = $forum_id; } } } $auth_list = implode(",", $forum_ids); $check_auth_sql = "AND t.forum_id IN (" . $auth_list . ")"; } //Get all topics // note that $auth_list may resolve to true if $check_auth is false (i.e. we are not checking authorizations on this board) // or alternatively if we are checking authorizations and there are in fact forums the user is authorized to view; // however, if we are checking authorizations and there are no forums the user is authorized to view we can skip the rest of this // since the user will not be shown any unreads, and that's what the next if statement is for if ($auth_list) { // V: made that into one unique query $sql = "SELECT t.forum_id, t.topic_id, p.post_time\r\n\t\t\t\tFROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p\r\n\t\t\t\tWHERE p.post_id = t.topic_last_post_id\r\n\t\t\t\tAND (" . implode(') OR (', $sql_and) . ")\r\n\t\t\t\t{$check_auth_sql}\r\n\t\t\t\tAND t.topic_moved_id = 0"; // this gets cached along with the posts if (!($result = $db->sql_query($sql, false, 'posts_'))) { message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql); } while ($topic_data = $db->sql_fetchrow($result)) { $id = $topic_data['topic_id']; $topic_last_read = topic_last_read($topic_data['forum_id'], $id); if ($topic_data['post_time'] > $topic_last_read) { $new_unreads[$id] = $topic_last_read; $forum_unread[$topic_data['forum_id']] = true; } } $db->sql_freeresult($result); } $board_config['tracking_time'] = time(); $board_config['tracking_unreads'] = $new_unreads; write_cookies($userdata); //save return $new_unreads; }