1
Qlazon
To force notifications on users?
  • 2007/6/8 13:29

  • Qlazon

  • Just popping in

  • Posts: 27

  • Since: 2007/4/29


I'd like to force some notifications on my xoops-site users. Especially news and calendar events. Is it possible to do that? Preferably the notification would be on as standard when they register at the site, but with an option to delete the notification later, if they want to. Else if I could just force it constantly.

It seems a bit too much to send newsletters after every update.

2
mboyden
Re: To force notifications on users?
  • 2007/6/8 14:30

  • mboyden

  • Moderator

  • Posts: 484

  • Since: 2005/3/9 1


I haven't seen this before posted on this site.

However, I will note that I did change the code in my sites to use by default e-mail notification, which was pretty easy. I've also changed the PM code to send (anonymous) e-mails to the users since none of my clients ever want PMs on their site (although it's another way to bring people back to the site). That information will be posted soon, but I'm still testing and integrating it.

There is the possibility that you could use the SmartMail module from SmartFactory. It seems intriguing but also daunting but may do what you need and want.

If you wanted users to have certain notifications, you could probably add some code in the registration process to enter those into the database, stealing some code from the notifications functionality.
Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development

3
Dave_L
Re: To force notifications on users?
  • 2007/6/8 14:56

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


You can subscribe a user for notification for an event, using the method XoopsNotification::subscribe (the function "subscribe" in kernel/notification.php).

4
Qlazon
Re: To force notifications on users?
  • 2007/6/9 12:00

  • Qlazon

  • Just popping in

  • Posts: 27

  • Since: 2007/4/29


I'm no coding wiz, even though I've registered that XOOPS code is quite easily altered. Like MBoyden I'd really like to force people to use mail in stead of PM-notification, unless I manage to make the site popular enough for the users to login every week...

Dave_l's suggestion on subscribing users is probably useable since I'm not going to have more than maybe 50 users on the site.

Thank you for the tips, and MBoyden - please submit the code once you work out the knacks.

5
Marco
Re: To force notifications on users?
  • 2007/6/9 12:11

  • Marco

  • Home away from home

  • Posts: 1256

  • Since: 2004/3/15


or run a query reguarly by crontab or xoopscare module...
marco
Do synergy or die.

6
mboyden
Re: To force notifications on users?
  • 2007/6/9 13:46

  • mboyden

  • Moderator

  • Posts: 484

  • Since: 2005/3/9 1


Okay, it was really pretty easy to make the change for the PM (private messenging) from creating an inbox message to creating an e-mail message. There are two things to do. First, edit XOOPS_ROOT/pmlite.php. Secondly, add a template file to your language//mail_templates directory.

I'll note, too, that there is a hack on SmartFactory's website, I think called PM Notification that will notify users via e-mail about new PM messages (this is ala eBay style). This was another thought I had, but my clients have generally preferred to just straight e-mail (and it keeps your database smaller).

Edit XOOPS_ROOT/pmlite.php

Comment out or remove the following code (lines 66-76 in 2.0.16 release v2 dated 2005-11-02 by skalpa):

$pm_handler =& xoops_gethandler('privmessage');
            
$pm =& $pm_handler->create();
            
$pm->setVar("subject"$_POST['subject']);
            
$pm->setVar("msg_text"$_POST['message']);
            
$pm->setVar("to_userid"$_POST['to_userid']);
            
$pm->setVar("from_userid"$xoopsUser->getVar("uid"));
            if (!
$pm_handler->insert($pm)) {
                echo 
$pm->getHtmlErrors();
                echo 
""._PM_GOBACK."";
            } else {
                echo 
"

"._PM_MESSAGEPOSTED."

javascript:window.opener.location='".XOOPS_URL."/viewpmsg.php';window.close();">"._PM_CLICKHERE."javascript:window.close();">"._PM_ORCLOSEWINDOW."
";
            }


replace it with:

$xoopsMailer =& getMailer();
            
$xoopsMailer->useMail();
            
$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/mail_template");
            
$xoopsMailer->setTemplate('pmsg.tpl');
            
$xoopsMailer->assign("SITENAME"$xoopsConfig['sitename']);
            
$xoopsMailer->assign("SITEURL"XOOPS_URL."/");
            
$xoopsMailer->assign("SITESLOGAN"$xoopsConfig['slogan']);
            
$xoopsMailer->assign("FROM_NAME"$xoopsUser->getVar('name'));
            
$toUser = new XoopsUser($_POST['to_userid']);
            
$xoopsMailer->assign("TO_NAME"$toUser->getVar('name'));
            
$xoopsMailer->assign("ADMINMAIL"$xoopsConfig['adminmail']);
            
$xoopsMailer->assign("BODY"stripSlashes($_POST['message']));
            
$xoopsMailer->assign("REPLY_URL"XOOPS_URL."/pmlite.php?send2=1&to_userid=".$xoopsUser->getVar('uid'));
            
$xoopsMailer->setToEmails($toUser->getVar('email'));
            
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
            
$xoopsMailer->setFromName($xoopsConfig['sitename']);
            
$xoopsMailer->setSubject($_POST['subject']);
            if (
$xoopsMailer->send()) {
                echo 
"

"._PM_MESSAGEPOSTED."

javascript:window.close();">"._PM_ORCLOSEWINDOW."
";
            } else {
                
//relevant error messages
                
echo $xoopsMailer->getErrors();
                echo 
""._PM_GOBACK."";
            }


Add Mail Template

Then you need to add a new template that matches the one used in this code (i used pmsg.tpl). I placed mine in XOOPS_ROOT/language/english/mail_templates/pmsg.tpl. Place yours in the appropriate language area.

{TO_NAME}:

{
FROM_NAMEhas sent the message below using anonymous messenging on {SITENAME} ({SITESLOGAN}). To reply to the authorplease use the Reply URL below the message. Do not reply to this messageit will not be received.

From: {FROM_NAME}

{
BODY}

Reply URL (cut and paste if necessary):
{
REPLY_URL}

If 
you have any problems with this service or users of this serviceplease contact the site administrators at {SITENAME}.

Best Regards,
{
SITENAMETeam
{SITEURL}


Finally, you can use other variables and such in the template as long as you edit the code in pmlite.php to match it and contain the right information. Also note that j-a-v-a-s-c-r-i-p-t is replaced in postings with tammairanslip, so the code above reflects that replacement and you will have to replace it back. I will eventually do a better write-up than this and post it here in the forums along with a link to download the files.

If one wanted, they could likely easily edit this to do both, or you could try the SmartFactory's hack to notify users.

Let me know if you run into problems using it. I did some basic testing although I didn't try to abuse it too much. It doesn't do HTML, but that is next on my list of things related to this.

Generally, my philosophy is to not touch the core because I don't want to spend hours on all my websites updating core. This is such a simple one, though, that I did it. You'll also likely want to remove links to the Inbox from the User Menu and other locations that link to it and/or just redirect them somewhere else if they try (like the home page).

Good luck!
Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development

7
Qlazon
Re: To force notifications on users?
  • 2007/6/9 13:54

  • Qlazon

  • Just popping in

  • Posts: 27

  • Since: 2007/4/29


Thanx Marco! I installed XoopsCare and understand it's use.. I'm just poor when it comes to mySQL (among other things :) ) Is it just a simple line that someone can share with me, or can someone point me in the direction of a good website with the information? That would be greatly appreciated.

Login

Who's Online

399 user(s) are online (296 user(s) are browsing Support Forums)


Members: 0


Guests: 399


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits