User Tools

Site Tools


products:stewnotice

Notifications

Some utilities to extend the phpfox notification module.

Features

* Notices provide a visual clue to the user that something needs attention.

* Notices are always sent. No messing with email transports or user group limits.

* Send a notice when user email notifications are returned as undeliverable

* Disable all notifications for a user.

* Send notices to individuals or groups from the admin cp

* Purge notifications

* Send reminders and notices when subscription expires.

* Use as api for bounce notifications from mail chimp, mandrill etc

* No core hacks

* Supports language packs

* Hooks in place so it can be adapted quickly for your site

Install

Same as all modules. Unzip and copy or ftp the contents of upload to your server.

What is a notification?

The notification system in phpfox is driven by two tables.

What the users sees is defined by templates: data for the templates is gathered via callbacks.

On every page refresh, and at timed intervals thereafter, the core phpfox script will ask the server if any new notifications have arrived for the current user. TODO: Where is that timer setting?

In the standard template, clicking the notification icon brings up a list of five or so of the most recent notifications.

These items are table rows from phpfox_notifications.

For each row, the notification service spins through a list of active modules, hands them the current row, and asks for some data back. Specifically it wants a link, a title, and an icon.

Since one module may provide for more than one kind of notification, the callback system was tweaked so that the item rows itself told the notification which callback to use.

Confused? Read flexibility. In a few lines of code you can format any kind of notification for any durn thing you want.

NT notification table

CREATE TABLE IF NOT EXISTS `phpfox_notification` (
  `notification_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type_id` varchar(75) NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `item_title` varchar(255) DEFAULT NULL,
  `item_server_id` tinyint(1) NOT NULL DEFAULT '0',
  `item_image` varchar(50) DEFAULT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `owner_user_id` int(10) unsigned NOT NULL DEFAULT '0',
  `is_seen` tinyint(1) NOT NULL DEFAULT '0',
  `time_stamp` int(10) unsigned NOT NULL,
  PRIMARY KEY (`notification_id`),
  KEY `user_id` (`user_id`),
  KEY `owner_user_id` (`owner_user_id`),
  KEY `notification_id` (`notification_id`,`user_id`),
  KEY `user_id_2` (`user_id`,`is_seen`),
  KEY `type_id` (`type_id`,`item_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=331397 ;

UNT user notification table

CREATE TABLE IF NOT EXISTS `phpfox_user_notification` (
  `user_id` int(10) unsigned NOT NULL,
  `user_notification` varchar(100) NOT NULL,
  KEY `user_id` (`user_id`,`user_notification`),
  KEY `user_id_2` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Cron job for bounced emails

A cron job scans your mailbox for messages returned from site notifications.

IMAP access to your mailbox is required.

Set a return address

You will need to determine where your “undeliverable mail” messages are going.

Configure your “returned mail path” by consulting your host.

The following is a sample from php.ini that shows how to send bounce notices to an email owned by “bouncer@mysite.com”

Details will vary by installation. No guru required. Set an email address for returned mail.

php_value[sendmail_path] = /usr/sbin/sendmail -t -i -f no-reply@mysite.com -r bouncer@mysite.com

IDEA: This is probably covered in the mailer classes that fox uses. I've set mine via the system (php.ini) but it may be better to dig into those mail classes.

.

Settings

Under setting for StewNotice, enter details so the add-on can log in to your mailbox.

* IMAP mailbox Format given at http://ca2.php.net/manual/en/function.imap-open.php Your host will supply this information.

* username

* password - Entered and shown in plain text as a setting in admincp. If only bounces go to this mailbox that is no problem (and will make monitoring progress easier).

Cron job

This is the code to add to your cron table:

Phpfox::getService('stewnotice.cron')->notifyBouncedEmails();

NB: Check out the Cron Job Manager from Abstract Enterprises http://www.phpfox.com/addons/view/v3-cronjob-manager/

The full signature for this method is:

notifyBouncedEmails(iStart,iLimit)

The extra arguments are provided for the case where server execution time is limited, and the mailbox is large. You may specify a starting offset and a maximum number of messages to process.

Preview mode

As the cron job finds bounced messages, it disables notifications for the user and sends them a new notification on site AND it deletes the email.

Preview modes does NOT delete the email. Instead it creates /file/log/stewnotice-deleted-bounces.log with an entry for each email processed.

This allows you to test out the module without removing any bounced messages. Once you have your messages and flow tested and working, switch preview mode off.

Trace (debug) log

When DEBUG is ON, stewnotice generates a trace to /file/log/stewnotice-bounced.log

This is intended for development, but may assist advanced users with troubleshooting.

When a user sees a bounced notification, she is looking at the LINK and PHRASE you specified the in settings for stewnotice.bounce_notification_url

* Set it to # for no link

* Set it to page.mypage for any custom page or controller/template pair on your site. Then you have to build a page that waves your hands dramatically and engagingly while being informative and succinct in six languages on twelve devices. Good luck with that.

* Set as stewnotice.testmail to use a test page that allows users to send an email to themselves. Be careful you do not expose this page to guests or you may become a spam factory! We wanted this to be easy and simple and free of validation and verification hurdles. You may need to add constrains for your site. More work needed here, we should be smart enough to detect an instant bounce… the guys keep trying their old mail and getting nothing duh Not tested enough. What happens with mobile?

* Use the plugin hook stewnotice.notify_bounced for complete control

Cron job for Expired Subscriptions

We've only written what we needed, and our system is customized. It won't do what you want.

But it's a good starting point. The code is clean, simple and well documented. It demonstrates creating the entries and updating the database.

Cannibalize it, cut and slice and paste. Your local consultant should be able to bolt it on in short order.

Sending notice from admincp

Not done. Stalled out here. Can do, but not sure it's worth the effort.

So far we have no pressing need for an admin interface.

phpMyAdmin is what we use to browse and manage the tables. Cron jobs make the entries.

We have no need to send anything custom or one-off.

Yet.

So there are screens here for add/index/manage but they are totally unsupported and never implemented.

Nothing but a skeleton for somebody who needs to take it further.

We are working on a desktop “admin center”, so we'd put our notification interface there…

Purge Notifications

Here is the cron job code:

Phpfox::getService('stewnotice.cron')->notification_purge();

It relies on the setting stewnotice.cron_keep_days stewnotice.cron_keep_days

So if you have the setting at 30 (one month), all notification prior to 30 days are removed.

So what happens when a dude gets a notification that his email is bouncing, but he does not log in for the next 30 days?

All is lost. His notifications were automatically shut off and the notification which said so is now deleted !

So the purge service delete those notifications. The user must delete it himself (which is already supported on the notification page).

Or, if you are using the testmail page, the default verbiage includes a link to say “Hey I got it!”. And that link sets the email and deletes the notification.

Settings

IMAP mailbox

Specify the inbox that bounced messages go to. That information can be set up a number of different ways. Ask your host. The format is given by the php imap_open function http://ca3.php.net/imap_open.

Ours looks something like this: {mail.mysite.com/tls/novalidate-cert}. Since we have a separate account where bounced messages go, and the default mailbox for imap_open is “inbox”, we have not specified the inbox here.

IMAP username

IMAP password

The email or username and password required to access the mailbox.

Preview Mode

Normally bounced emails are deleted from the mailbox as they are processed.

Set this true to prevent deletion.

Use this in combination with debug mode and your test site to ensure everything looks good before your first live run.

Where should the notification for bounced emails link to?

You may create your own page or index/controller pair.

Hooks are also available if you want to build it in code.

In our case, we enter stewnotice.testmail which is a page where users can send themselves emails until they get it right.

Not we do not push them through the standard fox email verification process. If you prefer to do that

CRON Days to keep notifications

If you use the notification purge in your cron job, it will delete notifications older than this many days

Hooks

stewnotice.notify_bounced

stewnotice.notify_test

stewnotice.mail_send_call

Download and demo

Not available online. Inquire within.

products/stewnotice.txt · Last modified: 2014/06/15 09:31 by steward