11
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/3 14:54

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Let me try to clean up the code a bit to make it a tad easier to reuse.

Currently, I hacked this into my website as proof of concept and it's just HTML/PHP. So the page refreshes and scrolls back to the post in question after a like/unlike is clicked. The proper way would be to do it with javascript so that a page refresh is not required.

Let me noodle on it, and then I will post the code.



12
BigKev73
Adding a LIke Feature to NEWBB
  • 2021/1/31 22:35

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


I was able to wire in a "Like" feature into the posts for NewBB. It shows a 'Thumbs' up icon if your a logged-in user and haven't liked that post yet. A 'thumbs down' icon if you already liked it, and want to un-like it. If your an anonymous user, then you don't see either.

If there are any likes, then it shows a count with a link to pop up a box that shows which users liked it.

It involves changes to Post.php, newbb_thread.tpl, and image.php, mostly to support adding the buttons to the $thread_action array.

Then there are 3 new small php files. like.php, unlink.php, and wholiked.php

Finally, there is a new table add called xoo_nebb_likes which has 4 cols; id, postID, UID, name

I'll share the changes with anyone interested. But I am sure there is a more elegant want to incorporate this. Especially the needs DB calls to make them more "core" to the post object. But since I build these changes for my own website, I tend to be more hardcoded in adding things.

Resized Image



13
BigKev73
2.5.10+ Getting new PM to send Notification Email
  • 2021/1/26 16:57

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


I was running an old 2.2.4RC2 website and recently converted over to XOOPS 2.5.11-Beta1

I've had to weave back in all my prior hacks/mods to restore some of the functionality I had before. One of those was getting a notification when a new PM was sent. I couldn't figure out why this wasn't working. Then looking at the code in pmlite.php I noticed this TODO comment at around line 86:


// @todo: Send notification email if user has selected this in the profile




So I made two changes to enabled this functionality again.

1) Change the above to read:

// Added by BigKev73 to enabled email on new PM
            
$sUser $member_handler->getUser(XoopsRequest::getInt('to_userid'0'POST'));
            
$rez=  $pm_handler->sendPMEmail($pm$sUser);


2) At this code into ..modules/pm/class/message.php after the sendEmail function (around line 191):

//added by BigKev73 to renable sending a email when a new PM is created
public function sendPMEmail(PmMessage $pmXoopsUser $user)
    {
        global 
$xoopsConfig;

        if (
is_object($user)) {
           
        
$from = new XoopsUser($pm->getVar('from_userid'));
        
$to   = new XoopsUser($pm->getVar('to_userid'));
            
$msg 'You received a new Private Message from ' $from->getVar('name');
            
$msg .= "nn";
            
$msg .= "Sent: " formatTimestamp($pm->getVar('msg_time'));
             
$msg .= "n";
            
$msg .= "n Subject: " $pm->getVar('subject') . "n";
            
$msg .= "n Message: " strip_tags(str_replace(array('<p>''</p>''<br>''<br>'), "n"$pm->getVar('msg_text'))) . "nn";
            
$msg .= "--------------n";
            
$msg .= $xoopsConfig['sitename'] . ': ' XOOPS_URL "n";
    
            
$xoopsMailer xoops_getMailer();
            
$xoopsMailer->useMail();
            
$xoopsMailer->setToEmails($user->getVar('email'));
            
$xoopsMailer->setFromEmail($xoopsConfig['from']);
            
$xoopsMailer->setFromName($xoopsConfig['fromname']);
            
$xoopsMailer->setSubject(sprintf("You received a Private Message on " $xoopsConfig['sitename']));
            
$xoopsMailer->setBody($msg);
    
            return 
$xoopsMailer->send();
        }else {
            return 
null;
        }
    }


A couple of notes:

1) You can obviously use variable tokens instead of the literal message strings I am using
2) I am using users 'name' on my website instead of uname. So change the
$msg 'You received a new Private Message from ' $from->getVar('name');
to
$msg 'You received a new Private Message from ' $from->getVar('uname'); if you want the default.

3) I'm also using a specific noreply@sitename.com email address vs the normal admin email when sending things out. So if you want to change the email, then change the following lines:

$xoopsMailer->setFromEmail($xoopsConfig['from']);
 
$xoopsMailer->setFromName($xoopsConfig['fromname']);

to
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
        
$xoopsMailer->setFromName($xoopsConfig['sitename']);


4) This is basically a modified version of the sendEmail function, that is taylored with a more tailored message. This could be wired up to a template as needed.

Hope this helps!

-BigKev




TopTop
« 1 (2)



Login

Who's Online

263 user(s) are online (168 user(s) are browsing Support Forums)


Members: 0


Guests: 263


more...

Donat-O-Meter

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

Latest GitHub Commits