Forum watch stuff ... just copied the topic watch stuff and thus needs reviewing inline with everything else ... but something needed to be added to 2.1 :)

git-svn-id: file:///svn/phpbb/trunk@2536 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-04-20 22:56:09 +00:00
parent 35c0d33ee7
commit fa3d0694a8
5 changed files with 208 additions and 18 deletions

View file

@ -199,6 +199,7 @@ define('CATEGORIES_TABLE', $table_prefix.'categories');
define('CONFIG_TABLE', $table_prefix.'config'); define('CONFIG_TABLE', $table_prefix.'config');
define('DISALLOW_TABLE', $table_prefix.'disallow'); define('DISALLOW_TABLE', $table_prefix.'disallow');
define('FORUMS_TABLE', $table_prefix.'forums'); define('FORUMS_TABLE', $table_prefix.'forums');
define('FORUMS_WATCH_TABLE', $table_prefix.'forums_watch');
define('GROUPS_TABLE', $table_prefix.'groups'); define('GROUPS_TABLE', $table_prefix.'groups');
define('POSTS_TABLE', $table_prefix.'posts'); define('POSTS_TABLE', $table_prefix.'posts');
define('POSTS_TEXT_TABLE', $table_prefix.'posts_text'); define('POSTS_TEXT_TABLE', $table_prefix.'posts_text');

View file

@ -154,6 +154,7 @@ define('CATEGORIES_TABLE', $table_prefix.'categories');
define('CONFIG_TABLE', $table_prefix.'config'); define('CONFIG_TABLE', $table_prefix.'config');
define('DISALLOW_TABLE', $table_prefix.'disallow'); define('DISALLOW_TABLE', $table_prefix.'disallow');
define('FORUMS_TABLE', $table_prefix.'forums'); define('FORUMS_TABLE', $table_prefix.'forums');
define('FORUMS_WATCH_TABLE', $table_prefix.'forums_watch');
define('GROUPS_TABLE', $table_prefix.'groups'); define('GROUPS_TABLE', $table_prefix.'groups');
define('POSTS_TABLE', $table_prefix.'posts'); define('POSTS_TABLE', $table_prefix.'posts');
define('POSTS_TEXT_TABLE', $table_prefix.'posts_text'); define('POSTS_TEXT_TABLE', $table_prefix.'posts_text');

View file

@ -611,7 +611,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
} }
else else
{ {
if ( $mode == 'reply' ) if ( $mode == 'reply' || $mode == 'newtopic' )
{ {
$sql = "SELECT ban_userid $sql = "SELECT ban_userid
FROM " . BANLIST_TABLE; FROM " . BANLIST_TABLE;
@ -629,16 +629,16 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
} }
} }
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title $sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name
FROM " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u FROM " . FORUMS_WATCH_TABLE . " w, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u
WHERE tw.topic_id = $topic_id WHERE w.forum_id = $forum_id
AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " ) AND w.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " )
AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . " AND w.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
AND t.topic_id = tw.topic_id AND f.forum_id = w.forum_id
AND u.user_id = tw.user_id"; AND u.user_id = w.user_id";
if ( !($result = $db->sql_query($sql)) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, 'Could not obtain list of forum watchers', '', __LINE__, __FILE__, $sql);
} }
$orig_word = array(); $orig_word = array();
@ -649,7 +649,7 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
$emailer = new emailer($board_config['smtp_delivery']); $emailer = new emailer($board_config['smtp_delivery']);
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path'])); $script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$script_name = ( $script_name != '' ) ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx; $script_name = ( $script_name != '' ) ? $script_name . '/viewforum.'.$phpEx : 'viewforum.'.$phpEx;
$server_name = trim($board_config['server_name']); $server_name = trim($board_config['server_name']);
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/'; $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
@ -659,13 +659,13 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
$update_watched_sql = ''; $update_watched_sql = '';
if ( $row = $db->sql_fetchrow($result) ) if ( $row = $db->sql_fetchrow($result) )
{ {
$topic_title = preg_replace($orig_word, $replacement_word, unprepare_message($row['topic_title'])); $forum_name = unprepare_message($row['forum_name']);
do do
{ {
if ( $row['user_email'] != '' ) if ( $row['user_email'] != '' )
{ {
$emailer->use_template('topic_notify', $row['user_lang']); $emailer->use_template('forum_notify', $row['user_lang']);
$emailer->email_address($row['user_email']); $emailer->email_address($row['user_email']);
$emailer->set_subject();//$lang['Topic_reply_notification'] $emailer->set_subject();//$lang['Topic_reply_notification']
$emailer->extra_headers($email_headers); $emailer->extra_headers($email_headers);
@ -674,10 +674,10 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']),
'USERNAME' => $row['username'], 'USERNAME' => $row['username'],
'SITENAME' => $board_config['sitename'], 'SITENAME' => $board_config['sitename'],
'TOPIC_TITLE' => $topic_title, 'FORUM_NAME' => $forum_name,
'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id", 'U_FORUM' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_FORUM_URL . "=$forum_id",
'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic") 'U_STOP_WATCHING_FORUM' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_FORUM_URL . "=$forum_id&unwatch=forum")
); );
$emailer->send(); $emailer->send();
@ -691,12 +691,73 @@ function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id
if ( $update_watched_sql != '' ) if ( $update_watched_sql != '' )
{ {
$sql = "UPDATE " . TOPICS_WATCH_TABLE . " $sql = "UPDATE " . FORUMS_WATCH_TABLE . "
SET notify_status = " . TOPIC_WATCH_NOTIFIED . " SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
WHERE topic_id = $topic_id WHERE forum_id = $forum_id
AND user_id IN ($update_watched_sql)"; AND user_id IN ($update_watched_sql)";
$db->sql_query($sql); $db->sql_query($sql);
} }
if ( $mode == 'reply' )
{
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title
FROM " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u
WHERE tw.topic_id = $topic_id
AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " )
AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
AND t.topic_id = tw.topic_id
AND u.user_id = tw.user_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
}
$script_name = ( $script_name != '' ) ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;
$email_headers = "From: " . $board_config['board_email'] . "\nReturn-Path: " . $board_config['board_email'] . "\r\n";
$update_watched_sql = '';
if ( $row = $db->sql_fetchrow($result) )
{
$topic_title = preg_replace($orig_word, $replacement_word, unprepare_message($row['topic_title']));
do
{
if ( $row['user_email'] != '' )
{
$emailer->use_template('topic_notify', $row['user_lang']);
$emailer->email_address($row['user_email']);
$emailer->set_subject();//$lang['Topic_reply_notification']
$emailer->extra_headers($email_headers);
$emailer->assign_vars(array(
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']),
'USERNAME' => $row['username'],
'SITENAME' => $board_config['sitename'],
'TOPIC_TITLE' => $topic_title,
'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic")
);
$emailer->send();
$emailer->reset();
$update_watched_sql .= ( $update_watched_sql != '' ) ? ', ' . $row['user_id'] : $row['user_id'];
}
}
while ( $row = $db->sql_fetchrow($result) );
}
if ( $update_watched_sql != '' )
{
$sql = "UPDATE " . TOPICS_WATCH_TABLE . "
SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
WHERE topic_id = $topic_id
AND user_id IN ($update_watched_sql)";
$db->sql_query($sql);
}
}
} }
$sql = "SELECT topic_id $sql = "SELECT topic_id
@ -843,4 +904,4 @@ function generate_smilies($mode, $page_id)
} }
} }
?> ?>

View file

@ -53,6 +53,9 @@
<tr> <tr>
<td align="left" colspan="3"><span class="nav">{PAGE_NUMBER}</span></td> <td align="left" colspan="3"><span class="nav">{PAGE_NUMBER}</span></td>
</tr> </tr>
<tr>
<td colspan="3"><span class="gensmall">{S_WATCH_FORUM}</span></td>
</tr>
</table> </table>
</form> </form>

View file

@ -117,6 +117,112 @@ if ( !$is_auth['auth_read'] || !$is_auth['auth_view'] )
// End of auth check // End of auth check
// //
//
// Is user watching this thread?
//
if( $userdata['session_logged_in'] )
{
$can_watch_forum = TRUE;
$sql = "SELECT notify_status
FROM " . FORUMS_WATCH_TABLE . "
WHERE forum_id = $forum_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain forum watch information", '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
if ( isset($HTTP_GET_VARS['unwatch']) )
{
if ( $HTTP_GET_VARS['unwatch'] == 'forum' )
{
$is_watching_forum = 0;
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "DELETE $sql_priority FROM " . FORUMS_WATCH_TABLE . "
WHERE forum_id = $forum_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not delete forum watch information", '', __LINE__, __FILE__, $sql);
}
}
$template->assign_vars(array(
'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=$start") . '">')
);
$message = $lang['No_longer_watching_forum'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=$start") . '">', '</a>');
message_die(GENERAL_MESSAGE, $message);
}
else
{
$is_watching_forum = TRUE;
if ( $row['notify_status'] )
{
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "UPDATE $sql_priority " . FORUM_WATCH_TABLE . "
SET notify_status = 0
WHERE forum_id = $forum_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not update forum watch information", '', __LINE__, __FILE__, $sql);
}
}
}
}
else
{
if ( isset($HTTP_GET_VARS['watch']) )
{
if ( $HTTP_GET_VARS['watch'] == 'forum' )
{
$is_watching_forum = TRUE;
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "INSERT $sql_priority INTO " . FORUMS_WATCH_TABLE . " (user_id, forum_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $forum_id, 0)";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not insert forum watch information", '', __LINE__, __FILE__, $sql);
}
}
$template->assign_vars(array(
'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=$start") . '">')
);
$message = $lang['You_are_watching_forum'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=$start") . '">', '</a>');
message_die(GENERAL_MESSAGE, $message);
}
else
{
$is_watching_forum = 0;
}
}
}
else
{
if ( isset($HTTP_GET_VARS['unwatch']) )
{
if ( $HTTP_GET_VARS['unwatch'] == 'forum' )
{
$header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
header($header_location . append_sid("login.$phpEx?redirect=viewforum.$phpEx&" . POST_FORUM_URL . "=$forum_id&unwatch=forum", true));
}
}
else
{
$can_watch_forum = 0;
$is_watching_forum = 0;
}
}
// //
// Handle marking posts // Handle marking posts
// //
@ -375,6 +481,23 @@ if ( $is_auth['auth_mod'] )
$s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>'); $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
} }
$s_watching_forum = '';
if ( $can_watch_forum )
{
if ( $is_watching_forum )
{
$watch_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;unwatch=forum&amp;start=$start");
$s_watching_forum = '<a href="' . $watch_url . '">' . $lang['Stop_watching_forum'] . '</a>';
$s_watching_forum_img = ( isset($images['Forum_un_watch']) ) ? '<a href="' . $watch_url . '"><img src="' . $images['Forum_un_watch'] . '" alt="' . $lang['Stop_watching_forum'] . '" title="' . $lang['Stop_watching_forum'] . '" border="0"></a>' : '';
}
else
{
$watch_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;watch=forum&amp;start=$start");
$s_watching_forum = '<a href="' . $watch_url . '">' . $lang['Start_watching_forum'] . '</a>';
$s_watching_forum_img = ( isset($images['Forum_watch']) ) ? '<a href="' . $watch_url . '"><img src="' . $images['Forum_watch'] . '" alt="' . $lang['Stop_watching_forum'] . '" title="' . $lang['Start_watching_forum'] . '" border="0"></a>' : '';
}
}
// //
// Mozilla navigation bar // Mozilla navigation bar
// //
@ -432,6 +555,7 @@ $template->assign_vars(array(
'L_AUTHOR' => $lang['Author'], 'L_AUTHOR' => $lang['Author'],
'S_AUTH_LIST' => $s_auth_can, 'S_AUTH_LIST' => $s_auth_can,
'S_WATCH_FORUM' => $s_watching_forum,
'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL ."=$forum_id"), 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL ."=$forum_id"),