GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "watchedthreads` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' AND `threadid` = '" . mysql_real_escape_string($_GET['threadid']) . "'"); if ($viewing_thread_is_watched == 0) { $newestreplyid = $tc_db->GetOne('SELECT `id` FROM `'.KU_DBPREFIX.'posts_'.mysql_real_escape_string($_GET['board']).'` WHERE `IS_DELETED` = 0 AND `parentid` = '.mysql_real_escape_string($_GET['threadid']).' ORDER BY `id` DESC LIMIT 1'); $newestreplyid = max(0, $newestreplyid); $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "watchedthreads` ( `threadid` , `board` , `ip` , `lastsawreplyid` ) VALUES ( " . mysql_real_escape_string($_GET['threadid']) . " , '" . mysql_real_escape_string($_GET['board']) . "' , '" . $_SERVER['REMOTE_ADDR'] . "' , " . $newestreplyid . " )"); if (KU_APC) apc_delete('watchedthreads|' . $_GET['board'] . '|' . $_SERVER['REMOTE_ADDR']); } break; case 'removethread': $viewing_thread_is_watched = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "watchedthreads` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' AND `threadid` = '" . mysql_real_escape_string($_GET['threadid']) . "'"); if ($viewing_thread_is_watched > 0) { $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "watchedthreads` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' AND `threadid` = '" . mysql_real_escape_string($_GET['threadid']) . "'"); if (KU_APC) apc_delete('watchedthreads|' . $_GET['board'] . '|' . $_SERVER['REMOTE_ADDR']); } break; default: $output .= 'Invalid operation'; } } else { /* If the user is sending this request while viewing a thread, check if it is a thread they are watching, and if so, update it to show they have viewed all current replies */ if ($_GET['threadid'] > 0) { $viewing_thread_is_watched = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "watchedthreads` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' AND `threadid` = '" . mysql_real_escape_string($_GET['threadid']) . "'"); if ($viewing_thread_is_watched > 0) { $newestreplyid = $tc_db->GetOne('SELECT `id` FROM `'.KU_DBPREFIX.'posts_'.mysql_real_escape_string($_GET['board']).'` WHERE `IS_DELETED` = 0 AND `parentid` = '.mysql_real_escape_string($_GET['threadid']).' ORDER BY `id` DESC LIMIT 1'); $newestreplyid = max(0, $newestreplyid); $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "watchedthreads` SET `lastsawreplyid` = " . $newestreplyid . " WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' AND `threadid` = '" . mysql_real_escape_string($_GET['threadid']) . "'"); if (KU_APC) apc_delete('watchedthreads|' . $_GET['board'] . '|' . $_SERVER['REMOTE_ADDR']); } } $cached = false; if (KU_APC) { $cache_threadwatch = apc_fetch('watchedthreads|' . $_GET['board'] . '|' . $_SERVER['REMOTE_ADDR']); if ($cache_threadwatch !== false) { $cached = true; $output .= $cache_threadwatch; } } if (!$cached) { $watched_threads = $tc_db->GetAll("SELECT `threadid` , `lastsawreplyid` FROM `" . KU_DBPREFIX . "watchedthreads` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' AND `board` = '" . mysql_real_escape_string($_GET['board']) . "' ORDER BY `lastsawreplyid` DESC"); if (count($watched_threads) > 0) { foreach ($watched_threads as $watched_thread) { $threadinfo = $tc_db->GetAll('SELECT `subject` , `name` , `tripcode` FROM `'.KU_DBPREFIX.'posts_'.mysql_real_escape_string($_GET['board']).'` WHERE `IS_DELETED` = 0 AND `id` = ' . $watched_thread['threadid'] . ' LIMIT 1'); $threadinfo = $threadinfo[0]; $output .= '' . $watched_thread['threadid'] . ' - '; if ($threadinfo['subject'] != '') { $output .= '' . $threadinfo['subject'] . ' - '; } $output .= formatNameAndTrip($threadinfo['name'], '', $threadinfo['tripcode'], 'Anonymous'); $numnewreplies = $tc_db->GetOne('SELECT COUNT(*) FROM `'.KU_DBPREFIX.'posts_'.mysql_real_escape_string($_GET['board']).'` WHERE `IS_DELETED` = 0 AND `parentid` = ' . $watched_thread['threadid'] . ' AND `id` > ' . $watched_thread['lastsawreplyid'] . ' LIMIT 1'); if ($numnewreplies > 0) { $output .= '' . $numnewreplies . ' new repl'; if ($numnewreplies != 1) { $output .= 'ies'; } else { $output .= 'y'; } $output .= ''; } else { $output .= '0'; } $output .= ' X
'; } } else { $output .= 'None.
'; } /*$output .= '
hide   refresh '; $output .= '
';*/ if (KU_APC) { apc_store('watchedthreads|' . $_GET['board'] . '|' . $_SERVER['REMOTE_ADDR'], $output, 600); } } } echo $output; ?>