advanced email notification

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Ideas Centre
DWFII
Registered User
Posts: 386
Joined: Fri Oct 20, 2006 2:17 am
Name: D.W.
Contact:

Re: advanced email notification

Post by DWFII »

Too bad this forum doesn't implement polls, because I'd like to create one (although it wouldn't be exactly unbiased simply because most of those responding would be administrators rather than users).

Nevertheless, I'd like to ask all those administrators:

If a functionality like Prime Notify were offered as an option for users...a choice...how many think that the majority of their users would choose to turn it off?
DWFII
In the High Desert of Central Oregon
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: advanced email notification

Post by AmigoJack »

DWFII wrote: Sun Oct 01, 2017 2:30 pmwith no allowance for anyone else's POV
No. Other arguments are just weak or inconsistent or even contradicting. Let me show:

DWFII wrote: Sun Oct 01, 2017 2:30 pmEmail notifications from this, and other forums force me to open my browser
Wrong usage. Why not using web feeds instead? The one for this topic will give you everything and you don't need an internet browser for it, just a web feed reader.

DWFII wrote: Sun Oct 01, 2017 2:30 pmand go to my forum and even drill down to the last post in a discussion
Wrong usage: the notification e-mail is not about the last post, hence it links to the newest post for you (because while you're reading the e-mail other posts could have been added already). And the internet browser automatically scrolls to said post, because the link is anchored.

DWFII wrote: Sun Oct 01, 2017 2:30 pmI know the theory--"blank" email notifications force the user to go to the forum and that...theoretically...increases participation. But that "forcing", that lack of choice also forces many people to withdraw from engagement.
The opposite (people only reading posts thru their e-mails) will cease activity as well.

DWFII wrote: Sun Oct 01, 2017 2:30 pmAnd that lack of choice is...or ought to be...diametrically opposed to the fundamental philosophy of having a forum in the first place.
I encounter "lack of choice" quite alot nonetheless, but I also see many people having a lack of knowledge about alternative approaches - like not using a BBS in the first place. And I also don't see the need to react just in time to new posts - just visit your board (multiple times) daily and you can see all new posts in a row or process the moderation queue. You're arguing as if you'd always have time to react, but I bet you'll also sleep or be busy in other ways.

DWFII wrote: Sun Oct 01, 2017 2:30 pmThere is no reason in the world that the best features of any system shouldn't be incorporated into phpBB
While there are many, the biggest reason is: not bloating it.

DWFII wrote: Sun Oct 01, 2017 2:30 pmFacebook
There will always be a difference: Facebook and all its data is never owned by you, but with a software installation (like phpBB) you're always in control of your data.



Do you think I replied to this topic after years because of an e-mail? Or because I regularly visit the list of topics where I posted? phpBB already comes with more than most users are aware of. Yes, I know e-mails with a daily digest of full posts - but (for me) this only comes in handy for 1 or 2 very remote boards that I don't visit regularly (maybe only once a year).
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK
Contact:

Re: advanced email notification

Post by andrewilley »

What a load of twaddle from AmigoJack. Completely ignoring what both the original poster and myself said. You may not want this sort of feature, your users may not want this sort of feature (hence make it an OPTION), but please don't try to impose your limited views on everyone else.

I won't bother wasting my time running around in circles pointlessly micro-quoting other posts, so I spent my time more usefully working out a quick solution.

It's actually pretty easy to do a couple of minor code changes to achieve what we wanted. This is very raw and has no user-settable options, but try the following:


In /phpbb/noficication/type/topic.php and /phpbb/noficication/type/post.php...

Find the section near the end which starts with:

Code: Select all

public function create_insert_array($post, $pre_create_data = array())
	{
		$this->set_data('poster_id', $post['poster_id']);
		$this->set_data('topic_title', $post['topic_title']);
and add an extra line:

Code: Select all

		$this->set_data('message', $post['post_text']);
Then find the earlier section which starts with:

Code: Select all

return array(
	'AUTHOR_NAME' => htmlspecialchars_decode($username),
	'FORUM_NAME'  => htmlspecialchars_decode($this->get_data('forum_name')),
	'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),

and add an extra line to the array:

Code: Select all

	'MESSAGE' => htmlspecialchars_decode(censor_text(preg_replace('#\[[^\]]+\]#', '', strip_tags($this->get_data('message'))))),
Then in whichever language template files you wish to modify, add the text {MESSAGE} wherever you wish the new content to be included within an email. I suggest changing /language/en/email/forum_notify.txt, /language/en/email/newtopic_notify.txt and /language/en/email/topic_notify.txt but feel free to play around as you wish.

The preg_replace() in the second part is simply a quick kludge to remove bbcode, and strip_tags() removes embedded HTML from the message content, but there are probably more elegant ways to do that. Also you might want to limit the string length to just the first few hundred characters, etc. It's a start though.

As always with this sort of thing, it's best to try it on a test server first before modifying your live system.

Andre
--- Admin of www.portorleans.org
DWFII
Registered User
Posts: 386
Joined: Fri Oct 20, 2006 2:17 am
Name: D.W.
Contact:

Re: advanced email notification

Post by DWFII »

andrewilley wrote: Mon Oct 02, 2017 12:11 am so I spent my time more usefully working out a quick solution.
Andre. Three things..

First, thanks for that work. I appreciate your open-mindedness and the expenditure of your time. It is refreshing to see someone who understands.

Second, Can you post a screen shot showing an email notification generated by your code?

Third, Where would you limit the string length and what do you suggest as a good length to create a reasonable excerpt.

And...sorry one more...fourth, can you formalize this into a simple extension--one that will survive upgrading? I am clueless when it comes to coding and although I follow directions pretty good, the forum I administer is supported by a non-profit ".org" and I am reluctant to take the risk and experiment with other peoples' investments, as who should say.

Thanks again.
DWFII
In the High Desert of Central Oregon
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK
Contact:

Re: advanced email notification

Post by andrewilley »

DWFII wrote: Mon Oct 02, 2017 12:56 am First, thanks for that work. I appreciate your open-mindedness and the expenditure of your time. It is refreshing to see someone who understands.
You're welcome. I found the other posts in this thread almost dictatorial as to how people should administer their own boards (are we in an Apple forum here?).

I make no claims that my solution is perfect, or even neatly coded, but as a quick-fix in a couple of lines of code it should work. I'm afraid I have no idea how to write official Extensions, and even if I did then at the very least it should include the ability for users to turn this feature on and off - which would mean creating an entry in the database too, which is far beyond the scope of what I posted or the time and effort I would ideally want to expend.

Personally I would have thought including the first 300-500 characters should be sufficient, which could be as simple as using an extra substr() on the line that creates the content for {MESSAGE}. I'll add a bit of extra stuff to support this more tidily (taking account of not splitting words for example), and while it could be done in a single line of code it would get a bit unwieldy to read!

Andre
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK
Contact:

Re: advanced email notification

Post by andrewilley »

OK, tidied up the code, limited it to 400 characters, and added some wrapper text around the included content. I have only tested it on phpBB 3.2.1, the files may be different for older versions.

In both /phpbb/noficication/type/topic.php and /phpbb/noficication/type/post.php find the following function:

Code: Select all

	public function get_email_template_variables()
	{
		if ($this->get_data('post_username'))
		{
			$username = $this->get_data('post_username');
		}
		else
		{
			$username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
		}
		
		return array(
			'AUTHOR_NAME'		=> htmlspecialchars_decode($username),
			'POST_SUBJECT'		=> htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
			'TOPIC_TITLE'		=> htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
			'U_VIEW_POST'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
			'U_NEWEST_POST'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&e=1&view=unread#unread",
			'U_TOPIC'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
			'U_VIEW_TOPIC'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
			'U_FORUM'		=> generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}",
			'U_STOP_WATCHING_TOPIC'	=> generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic",
		);
	}
and two extra sections of code (the first bit sets up the string $trimmed_message, the second one-liner passes that onward to the email templates as "MESSAGE") as shown below:

Code: Select all

	public function get_email_template_variables()
	{
		if ($this->get_data('post_username'))
		{
			$username = $this->get_data('post_username');
		}
		else
		{
			$username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
		}

		$trimmed_message = trim(preg_replace('#\[[^\]]+\]#' , '' , strip_tags(htmlspecialchars_decode(censor_text($this->get_data('message')))))) ;
		if (strlen($trimmed_message) > 400 )
		{
			$trimmed_message = substr($trimmed_message, 0 , strrpos(substr($trimmed_message, 0 , 400) , ' ')) ;
			$trimmed_message = "The posted message begins as follows:\n---- START OF POST ----\n" . $trimmed_message . "\n---- VISIT WEBSITE FOR MORE ----" ;
		}
		else
		{
			$trimmed_message = "The posted message is as follows:\n---- START OF POST ----\n" . $trimmed_message . "\n----- END OF POST -----" ;
		}
		
		return array(
			'AUTHOR_NAME'		=> htmlspecialchars_decode($username),
			'POST_SUBJECT'		=> htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
			'TOPIC_TITLE'		=> htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
			'MESSAGE'		=> $trimmed_message,
			'U_VIEW_POST'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
			'U_NEWEST_POST'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&e=1&view=unread#unread",
			'U_TOPIC'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
			'U_VIEW_TOPIC'		=> generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
			'U_FORUM'		=> generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}",
			'U_STOP_WATCHING_TOPIC'	=> generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic",
		);
	}

Then at the end of those same two files, find the function which starts with:

Code: Select all

public function create_insert_array($post, $pre_create_data = array())
	{
		$this->set_data('poster_id', $post['poster_id']);
		$this->set_data('topic_title', $post['topic_title']);
		$this->set_data('post_subject', $post['post_subject']);
and add one extra set_data() line:

Code: Select all

		$this->set_data('message', $post['post_text']);

Finally, in /language/en/email/forum_notify.txt, /language/en/email/newtopic_notify.txt and /language/en/email/topic_notify.txt simply add the text {MESSAGE} wherever you want the post content to be included, for example something like:

Code: Select all

Hello {USERNAME},

You are receiving this notification because you are watching the topic "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply<!-- IF AUTHOR_NAME != '' --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. No more notifications will be sent until you visit the topic.

{MESSAGE}

If you want to view the newest post made since your last visit, click the following link:
{U_NEWEST_POST}
Andre
Last edited by andrewilley on Tue Oct 03, 2017 9:01 am, edited 3 times in total.
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK
Contact:

Re: advanced email notification

Post by andrewilley »

And here is the result when I posted the following response to a post on my test server:

Image

This triggered the following email to anyone following that particular topic:
From: ****@portorleans.org [mailto:****@portorleans.org]
Sent: 02 October 2017 11:37
To: ForumTestUsername
Subject: Topic reply notification - "Test message"

Hello ForumTestUsername,

You are receiving this notification because you are watching the topic "Test message" at "PortOrleans.org Discussion Forums". This topic has received a reply by Andre since your last visit. No more notifications will be sent until you visit the topic.

The posted message begins as follows:
---- START OF POST ----
Here is a test message to show how posted content can be included in an email notification.

This line of text includes bold and underlined content, which should just show as plain text in the email when the bbcode is stripped.

Here is some padding to make the actual post longer than 400 characters, which should be trimmed in the email. Here is some padding to make the actual post longer than
---- VISIT WEBSITE FOR MORE ----

If you want to view the newest post made since your last visit, click the following link:
http://192.168.1.5/forum/viewtopic.php? ... ead#unread

If you want to view the topic, click the following link:
http://192.168.1.5/forum/viewtopic.php?f=6&t=1947

If you want to view the forum, click the following link:
http://192.168.1.5/forum/viewforum.php?f=6

If you no longer wish to watch this topic you can either click the "Unsubscribe topic" link found at the bottom of the topic above, or by clicking the following link:
http://192.168.1.5/forum/viewtopic.php? ... atch=topic
(Obviously those links won't work for you, they are internal on my LAN, but you get the idea)

Andre
--- Admin of www.portorleans.org
thfisher
Registered User
Posts: 3
Joined: Thu May 18, 2017 2:36 am

Re: advanced email notification

Post by thfisher »

I had been looking for a similar extension for a forum that I manage, and eventually realized that quickest solution was to hack the phpbb code similar to what was suggested earlier. Unfortunately, that approach made it difficult to keep the forum software up to date when new releases came along.

Additionally, I have a few forums with close to 50 subscribers. My modified phpbb code would send an email out to each of those subscribers for each post to the forum, and I was occasionally hitting the daily limit on my outgoing email server.

To solve these issues, I have developed and am just starting to test an extension that may be useful for some of you who are looking for email notifications that include the full post text. I expect to roll the extension out on my forum within the next few days.

The extension provides an Administrative Control Panel page that lest administrators subscribe individual usergroups to forums. Anyone in a usergroup which is subscribed to a forum will receive an email notification (with post text) for each post or reply to that forum.

Additionally, each user can subscribe to additional forums through a User Control Panel page.

Each post results in a single outgoing email that is bcc'd to every user who is subscribed (directly or thorough a group subscription) to that forum.

If people would find this useful, I'll look at making the extension available on github.
speeds
Registered User
Posts: 22
Joined: Mon Jun 17, 2019 6:40 pm

Re: advanced email notification

Post by speeds »

Hey, did anything move forward with this plugin?
Last edited by thecoalman on Wed Jan 22, 2020 12:31 am, edited 1 time in total.
Reason: Removed entire quoted post, please use quotes appropriately. Thanks
Post Reply

Return to “Extension Requests”