1
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/16 20:13

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Minor changes to version 1.2

-resized icons to 16x16 as they were 20x20 for some reason
-added Dislike.png
-removed Reaction.png (grey icon)
-added React.png (outline icon)
-modified some styling aspects in Reaction.php to make the icons look nicer and space out a bit better
-modified ReationInfo.php to add the Dislike option

ReactionPlugin 1.2



2
BigKev73
Re: NewBB 5.01 Beta 3 (XOOPS 2.5.11, PHP 7.2 - 8.0)
  • 2021/2/15 21:25

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Everything appears to work just fine and my updated Reation plug worked just fine with it as well.

Thanks!



3
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/15 21:21

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


So I made some changes to make it more "Facebook" like.

Now it only shows the icons for the reactions that have been set for a post. There is a new "grey" like icon which acts as a menu that opens to allow a user to add a reaction, change, or remove. Anonymous users won't see that menu.

Also, I relocated the icons to the asset folder and changed some of the files. take a look at the readme and change list.

NEWBB Posts showing posts with and without any reactions
Resized Image


User clicks the grey like icon to expand it into a meuu
Resized Image


The user made a selection, the menu closed and the reaction state of the post is updated
Resized Image


The download link is the same as before, but here it is again:

ReactionPlugin 1.1

Feedback is appreciated, Enjoy!



4
BigKev73
Re: NewBB 5.01 Beta 3 (XOOPS 2.5.11, PHP 7.2 - 8.0)
  • 2021/2/15 15:24

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


You're welcome. Downloading now and will run a compare to my base to see if I missed any changes I needed to commit.



5
BigKev73
Changing Site Logo and Welcome Message with the Holiday
  • 2021/2/10 22:59

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


I made this change awile ago, but thought I would share it. This is pretty much a change to the default theme header. This is the change I made to theme.tpl to the header section.

<!-- Start Header -->
<
table cellspacing="0">
    <
tr id="header">
        <
td id="headerlogo"><a href="<{xoAppUrl /}>" title="<{$xoops_sitename}>"><{php}>
                  
//This is used to calculate the various holidays and change the main Banner Logo Appropriately
                    
$currentYear date("Y");
                
$day date("j");
                
$mnth date("n");
                
                              
//Used to Calculate floating Holidays
                
$easterday date("j"easter_date($currentYear));  
                
$eastermnth date("n"easter_date($currentYear));  
                
$edaystart = ($easterday 7);
                
$edaystop = ($easterday 2);
                if (
$edaystart<) {$edaystart 1;}
                if (
$edaystop>31 ) {$edaystop 31;}
                
                
$turkeyDay date('j'strtotime("november $currentYear fourth thursday"));
                
$turkeyStart = ($turkeyDay 7);
                
$turkeyStop = ($turkeyDay 2);
                
                               
//Normal Image
                                
$HolidayMsg "Hello";
                
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_normal.jpg";
                
                
//XMAS
                
if ($mnth == "12" AND $day <= 29){
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_xmas.jpg";
                    
$HolidayMsg "Merry Christmas";
                }else if (
$mnth == "11" AND $day $turkeyStop ) {
                       
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_xmas.jpg";
                    
$HolidayMsg "Merry Christmas";
                
                               
//NYE    
                
}else if ($mnth == "12" AND $day 29) {
                       
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_newyears.jpg";
                    
$HolidayMsg "Happy New Years";
                }else if (
$mnth == "1" AND $day 7) {
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_newyears.jpg";
                    
$HolidayMsg "Happy New Years";
                
                               
//St Pattys Day
                
}else if ($mnth == "3" AND $day 10 AND $day <= 19){
                         
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_stpattys.jpg";
                    
$HolidayMsg "Happy St. Patty's Day";
                
                               
//Easter
                
}else if ($mnth == $eastermnth AND $day >= $edaystart and $day <= $edaystop){
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_easter.jpg";
                    
$HolidayMsg "Happy Easter";
                
                               
//4th July
                
}else if ($mnth == "6" AND $day >= 28){
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_4thjuly.jpg";
                    
$HolidayMsg "Happy 4th of July";
                }else if (
$mnth == "7" AND $day <= 6){
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_4thjuly.jpg";
                    
$HolidayMsg "Happy 4th of July";
                
                               
//THANKSGIVING
                
}else if ($mnth == "11" AND $day >= $$turkeyStart AND $day <= $turkeyStop ) {
                       
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_turkey.jpg";
                    
$HolidayMsg "Happy Thanksgiving";
                
                               
//Default Normal Logo
                
}else{
                    
$logofile $this->_tpl_vars['xoops_imageurl']. "logo_normal.jpg";
                     }
                echo 
'<img src="' $logofile '"';    
<{/
php}> alt="<{$xoops_sitename}>"/></a></td>
        <
td id="headerbanner"><{$xoops_banner}></td>
    </
tr>
    <
tr>
        <
td id="headerbar" colspan="2" height="25" style="vertical-align: middle;"><FONT COLOR #0066FF><B>&nbsp;<{if $xoops_isuser}> <{php}>echo $HolidayMsg;<{/php}> <{$xoops_name}> and Welcome Back! &nbsp;<{else}> <{php}>echo $HolidayMsg;<{/php}>! If you're new here, please register for a free account <{/if}>&nbsp;</B></FONT COLOR></td>
    
</tr>
</
table>
<!-- 
End header -->


This looks at the date, then changes the img src to the appropriate logo depending on the holiday. It changes a few days before the holiday and reset a few days after the holiday. It also changes the welcome message that appears in the header bar. Each of those images are basically my same site logo, with a different holiday theme added to it.

Hopefully, someone else finds this useful. I am sure there is a more SMARTY way of doing this. I just figured it was easier for me to inject PHP to handle it.



6
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/6 13:12

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Thanks! Good luck with your site!



7
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/6 4:26

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Curious to hear any feedback on this if you are able to test.

Thanks!



8
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/5 21:17

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


I've updated the zip file. I found a minor issue in the ReactionUsers.php where the image links were not correct in the "users popup", after some late changes I made. That has now been corrected. Thanks!



9
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/5 18:35

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Ok here is the DL link for the Reaction Plug and here are the instructions for installing it (also included in the zip file). Please read through the entire thing before starting. I think its a pretty easy add and i've tested it on my website which is running :

XOOPS Version XOOPS 2.5.11-Beta1
PHP Version 7.4.14
mySQL Version 5.5.68-MariaDB

That being said, use at your own risk and peril.

ReactionPlugin Download



Instructions for installing the Reactions Plug-In:

These instructions are for installing into NEWBB, but the premise and file locations should be similar for each module. Please adapt as you see fit and test this on a non-production website before deploying.

Copy this entire directory to the root of the /modules/newbb folder

So it the files should end up in the following locations:

/modules/newbb/Reaction.php
/modules/newbb/class/ReactionDBCreator.php
/modules/newbb/class/ReactionEntry.php
/modules/newbb/class/ReactionUsers.php
/modules/newbb/class/ReactUpdate.php
/modules/newbb/class/ReactionEntryHandler.php
/modules/newbb/class/ReactionInfo.php
/modules/newbb/include/AddReact.js
/modules/newbb/images/Like.png
/modules/newbb/images/Love.png
/modules/newbb/images/Hug.png
/modules/newbb/images/Laugh.png
/modules/newbb/images/Wow.png
/modules/newbb/images/Sad.png
/modules/newbb/images/Hate.png

You can modify the ReactionInfo.php file to add additional reaction or remove ones you don't want by modifying the define("ReactionNames", array("Like","Love","Hug","Laugh","Wow","Sad","Hate")); constant. The names much match the base names in the images folder.

You can change the DB Table name by modifying the define("ReactionTableName", "reaction_entry");
The table prefix is automatically added. Only 1 table is needed regardless of how many modules may be using it. So this is why the table name does not include a module name.

Once you have the DB Table name how you want it, run the /modules/newbb/class/ReactionDBCreator.php to create the table. This only had to be done once. You can delete this file afterward if you wish. But it checks if the table already exists and bails out if it does. So there is no danger to leaving it.


We need to manually modify 2 of the newbb files to support this. Please backup your files in the event you need to roll back or want to remove this plugin.


Modifications needed to NEWBB files:


In file: /modules/newbb/include/images.php , around 46 change it from:

$forumImage['previous'] = $forumImage['next'] = $forumImage['right'] = $forumImage['down'] = $forumImage['up'] = $forumImage['printer'] =  $forumImage['new_forum'] =


To:

$forumImage['previous'] = $forumImage['next'] = $forumImage['right'] = $forumImage['down'] = $forumImage['up'] = $forumImage['printer'] = $forumImage['react'] =  $forumImage['new_forum'] =


Make sure the = (equal) signs are present above at the end of the line.



In file: /modules/newbb/class/Post.php ,around line 648 insert the following line:

//Added to support Reaction    
    
include_once($GLOBALS['xoops']->path('modules/newbb/Reaction.php'));
    
$thread_action['react']['text'] =  BuildButtonsForm($post_id);


So when done it should look something like the following.

if ($topicHandler->getPermission($forum_id$topic_status'print')) {
            
$thread_action['print']['image']  = newbbDisplayImage('printer'_MD_NEWBB_PRINT);
            
$thread_action['print']['link']   = XOOPS_URL '/modules/newbb/print.php?form=2&amp;forum=' $forum_id '&amp;topic_id=' $topic_id;
            
$thread_action['print']['name']   = _MD_NEWBB_PRINT;
            
$thread_action['print']['target'] = '_blank';
  }

 
//Added to support Reaction
 
include_once($GLOBALS['xoops']->path('modules/newbb/Reaction.php'));
 
$thread_action['react']['text'] =  BuildButtonsForm($post_id);
            
 if (
$GLOBALS['xoopsModuleConfig']['show_sociallinks']) {
            
$full_title  $this->getVar('subject');
            
$clean_title preg_replace('/[^A-Za-z0-9-]+/''+'$this->getVar('subject'));


Basically, we are inserting it on the post footer between the print button and the social links. But if you wanted to move it, you could.

And that should be it. Once this is all in place, you should see the row of reaction icons at the bottom of each post when viewing a thread. Anytime a post has a reaction to it, it will show a (#) after the row icons to show how many reactions it has. Click on that opens a pop-up that shows what users reacted to it and how they reacted.

If you are a logged-in user, you can click any of the Icon to set your reaction to a post. That icon should show about 1/3rd larger to denote that if your reaction to it. If click another reaction on the same post, then it will reset to the new one. If you select the denoted icon, remove your reaction. You can only have 1 reaction to a single post.

If you look at the code added to the Post.php, the call to BuildButtonsForm does all the work for building the icons. You pass in the PostID that is how it knows what post you are on and uses that to store the value in the database.

So this can easily be added to another module. The code automatically detects what module it is installed under and uses that module's ID when storing reactions in the database. so only one table is needed regardless of the number of modules using it.

Hope this is helpful

-BigKev73



10
BigKev73
Re: Adding a LIke Feature to NEWBB
  • 2021/2/5 1:05

  • BigKev73

  • Just popping in

  • Posts: 13

  • Since: 2021/1/26


Ok, I made some significant changes. Take a look at this screen shot:

Resized Image


Basically in the footer section of each post in NEWBB, you will see 6 different "Reaction" icons. If you're a logged-in user, you can choose one. It will only allow you to select one at a time. The selected one becomes larger to show that is the one you selected for that particular post. If you select the same one again the in un-selects it. Also, you see the Reaction count to the right change as you make a selection. Clicking on the count shows the pop-up that shows the reactions that have been set for that post. You can click on a user there and it will take you to their profile page.

If you are not logged in (an anonymous user) then it will still show the icons, but you cant select any of them aka they do nothing, But, they can still see the Reaction count and view the pop-up.

It appears to work great, I'll have my users play with it for a bit. I figured out how to splice it into NEWBB with only a few minor manual changes. I still need to write some code to create the DB table automatically.

I rewrote this to be agnostic. The DB table has an ID, a Module ID, an Item ID, UID, ReactID and a Date

This allows it to work for any module. In the case of NEWBB it sets it Module ID, and then the Item ID is the Post ID. The React ID is the code for the reaction 0 = Like, 6 = Hate, etc.

It uses a couple of new PHP Class files and a JS file that wires up all the Reaction buttons so no page refresh is required when a user makes a section. The buttons are wired to call into the JS file and pass ItemID and ReactID assigned to the button. The JS code then checks to see if any other reaction for the post from that user was already chosen. If so, it resets it and updated the DB via a call to a PHP page that handles that. The JS code then takes care of updating the page buttons and react count as appropriately, without having the refresh the page. Once this is wired into NEWBB with the few minor changes, it should be possible to add more reaction choices without any further code changes in NEWBB as really new thinks it's only adding a single button. But it really injects an HTML form with all the buttons that are part of it. So from that standpoint, it's extendable. Also, the same thing should work for just about any other module as well.

I'm going to let my users beat it up for a few days which I get the DB Table creation code written, then I'll post some files and instructions on how to wire it up.




TopTop
(1) 2 »



Login

Username:
Password:

Lost Password? Register now!

Who's Online

79 user(s) are online (37 user(s) are browsing Support Forums)


Members: 0


Guests: 79


more...

Donat-O-Meter

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

Latest GitHub Commits