January 18, 2004

New Topic notification

Posted at 11:07 AM Gems, Notebook

There's a phpBB hack to add Forum-wide email notification to phpBB boards. It's a good hack, except that it generates notification emails for all replies to all forum topics. This is a bit too much notification.

Following is a method for reducing forum-level notification so that they are only sent when a new topic is created.

  • First, fully install and test the phpBB Forum Notification hack.
  • Then, re-open the file include/functions_post.php
  • Find

    $sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name 
    FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . FORUMS_WATCH_TABLE . " fw, " . FORUMS_TABLE . " f
    WHERE fw.forum_id = $forum_id
    AND fw.user_id NOT IN (" . $already_mailed . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " )
    AND t.topic_id = $topic_id
    AND f.forum_id = $forum_id
    AND f.forum_notify = '1'
    AND u.user_id = fw.user_id";
    if ( !($result = $db->sql_query($sql)) )
    {
    message_die(GENERAL_ERROR, "", "", __LINE__, __FILE__, $sql);
    }

    $script_name = preg_replace("/^\/?(.*?)\/?$/", "\\1", trim($board_config['script_path']));
    $script_name_forum = ( $script_name != '' ) ? $script_name . '/viewforum.'.$phpEx : 'viewforum.'.$phpEx;
    $script_name = ( $script_name != '' ) ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;

    $temp_is_auth = array();

    if ( $row = $db->sql_fetchrow($result) )
    {
    $topic_title = preg_replace($orig_word, $replacement_word, unprepare_message($row['topic_title']));
    $post_text = preg_replace($orig_word, $replacement_word, unprepare_message($post_data['message']));

    do
    {
    $temp_userdata = get_userdata($row['user_id']);
    $temp_is_auth = auth(AUTH_ALL, $forum_id, $temp_userdata, -1);

    // another security check (i.e. the forum might have become private and
    // there are still users who have notification activated)
    if( $temp_is_auth['auth_read'] && $temp_is_auth['auth_view'] )
    {
    if ( $row['user_email'] != "" )
    {
    $emailer->use_template("forum_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("
    ", "\n", "-- \n" . $board_config['board_email_sig']),
    "USERNAME" => $row['username'],
    "SITENAME" => $board_config['sitename'],
    "TOPIC_TITLE" => $topic_title,
    "POST_TEXT" => $post_text,
    "POSTERNAME" => $post_data['username'],
    "U_TOPIC" => $server_protocol . $server_name . $server_port . $script_name . "?" . POST_POST_URL . "=$post_id#$post_id",
    "FORUM_NAME" => $row['forum_name'],
    "U_STOP_WATCHING_FORUM" => $server_protocol . $server_name . $server_port .
    $script_name_forum . "?" . POST_FORUM_URL . "=$forum_id&unwatch=forum")
    );

    $emailer->send();
    $emailer->reset();

    }
    }
    }
    while ( $row = $db->sql_fetchrow($result) );
    }

  • Delete this code block (or comment it out). Careful! There's a similar block above this which sends the default phpBB topic-reply notification and you'll want to keep that.
Save the file. Now your forums should be enabled to notify for new topics in watched forums as well as new replies in watched topics.

p.

Presently listening to:
Kashmir - Led Zeppelin - Physical Graffitti (08:33)




 
Posted by Patrick at January 18, 2004 11:07 AM