v1.0.4: phpbb2.0.4 compatible
http://www.pda0.net/foro/viewtopic.php? ... highlight=
Update:
http://www.phpbb.com/phpBB/viewtopic.ph ... highlight=
Hi fellow phpBB'ers. Ive made a forum notifier MOD. Ive used for a little while myself, it seems its pretty stable.
You can download a .zip with the files here: http://www.pda0.net/foro/viewtopic.php? ... highlight=
This is my _very_first_ mod, so expect some nastiness in it

Thanks!
.pd
UPDATE: v1.0.2 is out
Code: Select all
#################################################################
## Mod Title: Forum Notification
## Mod Version: 1.0.2
## Author: Patricio Anguita < pda@ing.puc.cl > - www.pda0.net
## Description: This MOD will allow you to notify users whenever a new topic gets posted
## in a watched forum
##
## Installation Level: Easy
## Installation Time: 10 Minutes
## Files To Edit: posting.php, functions_post.php, constants.php , viewforum.php , lang_main.php , viewforum_body.tpl
## Included Files: createtable.txt , forum_notify.tpl (spanish) , forum_notify.tpl (english) , 'v1.0.02v1.0.1.txt' (Upgrade info)
#################################################################
## Security Disclaimer: This MOD Cannot Be Posted To Or Added At Any Non-Official phpBB Sites
#################################################################
##
## Author Notes:
##
## Remember to set up forum_notify.tpl file in the correct dir (languages/lang_xxx/)
## At the moment there is an english and also a spanish version.
## You should also modify lang_main.php of all your languages, only english and spanish modifications are shown here
##
## Remember to apply this sql statement! (Its provided on the createtable.txt file as cleartext):
## Change 'phpbb2' to whatever your prefix is....
##
## CREATE TABLE phpbb2_forums_watch (
## forum_id mediumint(8) unsigned DEFAULT '0' NOT NULL,
## user_id mediumint(8) DEFAULT '0' NOT NULL,
## PRIMARY KEY (forum_id, user_id)
## );
##
## History:
##
## v1.0.2: Added FORUM_NAME capability on the email template, and updated the email .tpl's
## Im too lazy to write v1.0.1 -> v1.0.2 instructions, but if you compare both version's file it will be easy to do.
## v1.0.1: Fixed a small typo that got to show watch_topics instead of watch_forums on the forum index page.
## This can be easily fixed without reinstalling the mod, by following 'v1.0.02v1.0.1.txt' directives.
##
## v1.0.0: First version ;)
##
##
#################################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
#################################################################
#
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
#
submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
if ( $error_msg == '' )
user_notification($mode, $post_data, $forum_id, $topic_id, $post_id, $notify_user);
#
#-----[ REPLACE WITH ]------------------------------------------
#
submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
if ( $error_msg == '' )
{
// If this post is a new topic..
if ($post_data['first_post']) {
// Check out which ppl are watching this forum..
$forum_notify_sql="select user_id from ".FORUMS_WATCH_TABLE." where forum_id='$forum_id';";
if ( $result = $db->sql_query($forum_notify_sql) )
{
// For each of the users watching the forum, set them as watchers on the topics_watch table
if ( $row = $db->sql_fetchrow($result) )
{
$dummy = true;
do {
user_notification($mode, $post_data, $forum_id, $topic_id, $post_id, $dummy , $row['user_id']);
}
while ( $row = $db->sql_fetchrow($result) );
}
}
else
{
message_die(GENERAL_ERROR, 'Could not obtain forum watch information', '', __LINE__, __FILE__, $sql);
}
}
user_notification($mode, $post_data, $forum_id, $topic_id, $post_id, $notify_user);
}
#
#-----[ OPEN ]------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------
#
function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$notify_user)
#
#-----[ REPLACE WITH ]------------------------------------------
#
function user_notification($mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$notify_user , $watch_user_id = '')
#
#-----[ FIND ]------------------------------------------
#
$current_time = time();
#
#-----[ BEFORE, ADD ]------------------------------------------
#
if (!$watch_user_id) $watch_user_id=$userdata['user_id'];
#
#-----[ FIND ]------------------------------------------
#
$delete_sql = ( !$post_data['first_post'] && !$post_data['last_post'] ) ? " AND user_id = " . $userdata['user_id'] : "";
#
#-----[ REPLACE WITH ]------------------------------------------
#
$delete_sql = ( !$post_data['first_post'] && !$post_data['last_post'] ) ? " AND user_id = " . $watch_user_id : "";
#
#-----[ FIND ]------------------------------------------
#
if ( $mode == 'reply')
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ( $mode == 'reply' || $mode == 'newtopic')
#
#-----[ FIND ]------------------------------------------
#
$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
#
#-----[ REPLACE WITH ]------------------------------------------
#
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, t.forum_id, ft.forum_name
FROM " . FORUMS_TABLE . " ft, " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u
#
#-----[ FIND ]------------------------------------------
#
AND t.topic_id = tw.topic_id
#
#-----[ AFTER, ADD ]------------------------------------------
#
AND ft.forum_id = t.forum_id
#
#-----[ FIND ]------------------------------------------
#
AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " )
#
#-----[ REPLACE WITH ]------------------------------------------
#
AND tw.user_id NOT IN (" . $watch_user_id . ", " . ANONYMOUS . $user_id_sql . " )
#
#-----[ FIND ]------------------------------------------
#
$topic_title = preg_replace($orig_word, $replacement_word, unprepare_message($row['topic_title']));
#
#-----[ AFTER, ADD ]------------------------------------------
#
$forum_name = $row['forum_name'];
#
#-----[ FIND ]------------------------------------------
#
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
#
#-----[ REPLACE WITH ]------------------------------------------
#
include_once($phpbb_root_path . 'includes/emailer.'.$phpEx);
#
#-----[ FIND ]------------------------------------------
#
$emailer->use_template('topic_notify', $row['user_lang']);
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ($mode == 'newtopic')
{
$emailer->use_template('forum_notify', $row['user_lang']);
}
else
{
$emailer->use_template('topic_notify', $row['user_lang']);
}
#
#-----[ FIND ]------------------------------------------
#
'TOPIC_TITLE' => $topic_title,
#
#-----[ AFTER, ADD ]------------------------------------------
#
'FORUM_NAME' => $forum_name,
#
#-----[ FIND ]------------------------------------------
#
FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
#
#-----[ REPLACE WITH ]------------------------------------------
#
FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $watch_user_id;
#
#-----[ FIND ]------------------------------------------
#
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
#
#-----[ REPLACE WITH ]------------------------------------------
#
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $watch_user_id;
#
#-----[ FIND ]------------------------------------------
#
$sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
#
#-----[ REPLACE WITH ]------------------------------------------
#
$sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $watch_user_id . ", $topic_id, 0)";
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]------------------------------------------
#
define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch');
#
#-----[ AFTER, ADD ]------------------------------------------
#
define('FORUMS_WATCH_TABLE', $table_prefix.'forums_watch');
#
#-----[ OPEN ]------------------------------------------
#
viewforum.php
#
#-----[ FIND ]------------------------------------------
#
// End of auth check
//
#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Handle watching forums
//
if ( $userdata['session_logged_in'] )
{
$sql = "SELECT user_id
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 ($row['user_id']) $is_watching_forum = true;
else $is_watching_forum = false;
}
}
if ( $watch == 'forums' )
{
if ( $userdata['session_logged_in'] )
{
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "INSERT $sql_priority INTO " . FORUMS_WATCH_TABLE . " (user_id, forum_id)
VALUES (" . $userdata['user_id'] . ", $forum_id)";
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") . '">')
);
}
$message = $lang['You_are_watching_forum'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ');
message_die(GENERAL_MESSAGE, $message);
}
else if ($unwatch == 'forums' )
{
if ( $userdata['session_logged_in'] )
{
$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") . '">')
);
}
$message = $lang['No_longer_watching_forum'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ');
message_die(GENERAL_MESSAGE, $message);
}
//
// Forum watch information
//
$s_watching_forum = '';
if ( $userdata['session_logged_in'] )
{
if ( $is_watching_forum )
{
$s_watching_forum = '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&unwatch=forums") . '">' . $lang['Stop_watching_forum'] . '</a>';
//$s_watching_forum_img = ( isset($images['Topic_un_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&unwatch=topic&start=$start") . '"><img src="' . $images['Topic_un_watch'] . '" alt="' . $lang['Stop_watching_forum'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
}
else
{
$s_watching_forum = '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&watch=forums") . '">' . $lang['Start_watching_forum'] . '</a>';
//$s_watching_forum_img = ( isset($images['Topic_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&watch=topic&start=$start") . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Stop_watching_forum'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
}
}
//
// End handle watching forums
//
#
#-----[ FIND ]------------------------------------------
#
$template->set_filenames(array(
'body' => 'viewforum_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx);
#
#-----[ AFTER, ADD ]------------------------------------------
#
$template->assign_vars(array('S_WATCH_FORUM' => $s_watching_forum));
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewforum_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<tr>
<td align="left" colspan="3"><span class="nav">{PAGE_NUMBER}</span></td>
</tr>
</table>
</form>
#
#-----[ REPLACE WITH ]------------------------------------------
#
<tr>
<td align="left" colspan="3"><span class="nav">{PAGE_NUMBER}</span></td>
</tr>
<tr>
<td align="left" colspan="3"><span class="gensmall">{S_WATCH_FORUM}</span></td>
</tr>
</table>
</form>
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
// Viewforum
//
#
#-----[ AFTER, ADD ]------------------------------------------
#
$lang['Stop_watching_forum'] = "Stop watching this forum";
$lang['Start_watching_forum'] = "Watch this forum for new topics";
$lang['No_longer_watching_forum'] = "You are no longer watching this forum";
$lang['You_are_watching_forum'] = "You are now watching this forum";
#
#-----[ OPEN ]------------------------------------------
#
language/lang_spanish/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
// Viewforum
//
#
#-----[ AFTER, ADD ]------------------------------------------
#
$lang['Stop_watching_forum'] = "Dejar de observar este tema";
$lang['Start_watching_forum'] = "Observar este tema por nuevos tópicos";
$lang['No_longer_watching_forum'] = "Ya no está observando este tema";
$lang['You_are_watching_forum'] = "Ahora está observando este tema";
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM