[ABD] Forum Notify

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Locked
User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

[ABD] Forum Notify

Post by Pda0 »

Latest version:
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 :twisted: Please be so kind of helping me finish this mod to submit it as final to the mod DB.

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
Last edited by Pda0 on Tue Apr 29, 2003 1:47 am, edited 7 times in total.

sj26
Registered User
Posts: 447
Joined: Fri Dec 14, 2001 4:06 pm
Location: /dev/cpu/[0-9]+ :D
Contact:

Post by sj26 »

What does this do that 'Watch this topic for replies' doesn't?
[ Working on: It's a secret! ]
[ Links: My Mods | My Site | PALGN ]

User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

Post by Pda0 »

Nope, this is for watching Forums, not Topics.

So, when a new topic arrives, subscribed users get an email with the link.

.pd

chinch
Registered User
Posts: 169
Joined: Mon Mar 11, 2002 7:34 pm

Post by chinch »

i will install this ASAP.

does the email include the ENTIRE TEXT of each post ? That is desired so you can read the board without having to click over :)

User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

Post by Pda0 »

chinch wrote: i will install this ASAP.

does the email include the ENTIRE TEXT of each post ? That is desired so you can read the board without having to click over :)


No it doesnt :? This MOD just adds the same functionality of topic watchs, but for forums...

I guess i can make an all-text version too though :) If its really necessary...

chinch
Registered User
Posts: 169
Joined: Mon Mar 11, 2002 7:34 pm

Post by chinch »

please :)

that would be great and saves time and bandwidth for heavy forum readers :)

User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

Post by Pda0 »

Hehe.. okay.. ill give it a try :) That would be another mod though (?) Forum subscriber instead of forum notifier... well who cares..

.pd

User avatar
anne
Registered User
Posts: 35
Joined: Wed Apr 10, 2002 9:17 am
Location: England
Contact:

Re: [RC1] Forum Notify

Post by anne »

Pda0 wrote: You can download a .zip with the files here: http://www.pda0.net/foro/viewtopic.php? ... highlight=



Hi

I am so pleased to read about this mod. Thankyou.

However I have been unable to download the file. It didn't seem to be attached to the message on this hyperlink.

Sorry to bother you.

Thanks

Anne

User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

Post by Pda0 »


User avatar
anne
Registered User
Posts: 35
Joined: Wed Apr 10, 2002 9:17 am
Location: England
Contact:

Post by anne »

Thanks! :lol:

Anne

tobiaseigen
Registered User
Posts: 37
Joined: Sun Apr 14, 2002 2:51 pm
Location: Takoma Park, MD USA
Contact:

mailing lists <> phpbb

Post by tobiaseigen »

Hi,

There's a group of us (see http://www.phpbb.com/phpBB/viewtopic.php?t=12414) trying to figure out how to integrate phpbb with mailing lists. I wonder if this script of yours wouldn't be the slickest answer to the question of how to get postings out to subscribers - they could subscribe simply within phpbb (ie. making mailman unnecessary). The reverse, though, is still a problem - how to get email contributions into the database?

If you'd be interested in helping out with this, please let me know.

Cheers,

Tobias
Kabissa - Space for change in Africa
http://www.kabissa.org

User avatar
Pda0
Registered User
Posts: 217
Joined: Sun Apr 14, 2002 5:00 am
Location: Chile

Post by Pda0 »

tobias: Well there's alot of discussion about that topic.

Personally, i find its a interesting feature... but in my eyes, clicking on a link on an email to answer the email in a forum isnt a big deal...

.pd

stevie
Registered User
Posts: 107
Joined: Wed Nov 14, 2001 4:22 am
Location: Boston area

Post by stevie »

I really agree with Pda0.

I'm also very interested in mailing list & discussion board integration.

For most mailing lists and discussion boards I take part in there's some huge ratio between "readers" and "writers" - in other words, for every message submitted, dozens/hundreds/thousands of people will read it. Also, for every regular poster there are probably dozens or hundreds of people who are lurkers or only rarely send messages.

So the fact that it's easier to add "mail-out" capabilities to phpBB than "mail-in" is great, because as far as I'm concerned some really smooth "mail-out" features will solve 90% of the "integration" issues. Each email could have at the bottom a link to "respond to this message" that would take the person right to the board and open up the thread (so they could skim the whole thread, and then click the "reply" button). Each email could also have a link to "submit a new message in xyz forum".

Mail-in features are obviously more complex, but fortunately, the lack of mail-in doesn't hurt too much. If there are a few subscribers that want to post and find the web a real hardship, they can always find a buddy to send email to and the buddy can post on their behalf.

I'm not quite ready to try out Pda0's mod yet but I plan to as soon as I get myself upgraded to 2.0 final and let the dust settle. -Steve

tobiaseigen
Registered User
Posts: 37
Joined: Sun Apr 14, 2002 2:51 pm
Location: Takoma Park, MD USA
Contact:

Post by tobiaseigen »

Pda0 and Stevie have a point.

Mailin really is a big problem - so big in fact that it's probably not worth trying to solve it. The benefits of seeing the whole thread before answering (the way I am now) are huge. I have been thinking that using our www4mail@kabissa.org web-to-email gateway would be a suitable answer for most of our members in Africa that need to do posting.. perhaps we could develop a very clean, low-bandwith, stylesheet and graphics-free template for phpbb which works well with www4mail. We're already doing this for another project - see http://info.vita-connect.org/www4mail and http://info.vita-connect.org.

As for Mailout, I think the problem would be solved if people can selectively subscribe to forums and topics, and have the option of getting the full text of every contribution (including attachments!) instead of a short notification. Like Stevie said, the email could have a link to posting a new topic as well as a link to posting a reply to the current posting.

In this scenario, www4mail users could then copy and paste either of these links into a message to www4mail@kabissa.org to reply by email. Unfortunately this might still take a while because of the delays African organisations face when sending and receiving messages. But like you said, most people do just want to receive mail - and even in Africa most email users also have some level of web access. if they have the direct link in the message they can quickly and efficiently get on the web, log into the phpbb message board and post their reply.

I would still love to see a mailin script so that I can convert all my existing MBOX mailing list archives to phpbb forums!

Cheers,

Tobias
Kabissa - Space for change in Africa
http://www.kabissa.org

chinch
Registered User
Posts: 169
Joined: Mon Mar 11, 2002 7:34 pm

Post by chinch »

on my board with about 3500 users, some want to subscribe to a topic and receive each post (with full message text) by email. It saves them from having to login and keep checking "new messages".

Then if they want to reply, they simply click the link in the email to go to the topic and reply.

this topic has gone off-topic... but can anyone help getting this hack to simply include the full message body in the email :)

Locked

Return to “[2.0.x] MODs in Development”

cron