TABLE OF CONTENTS
DOWNLOAD & INSTALLATION
First, the download links for the module, and also “installation instructions”.
LICENSE & DOWNLOAD
Core Boxx is released under the MIT License. You are free to use it for personal and commercial projects, and modify it as you see fit. On the condition that the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.
INSTALLATION
- Install the Users Module first.
- Copy/unzip this module into your existing Core Boxx project folder.
- Access
http://your-site.com/install/reactions
, this will automatically:- Import
lib/SQL-Reactions.sql
into your database. - Delete
PAGE-install-reactions.php
itself.
- Import
- After installation, access
http://your-site.com/reactions
for the demo page.
SORRY FOR THE ADS...
But someone has to pay the bills, and sponsors are paying for it. I insist on not turning Code Boxx into a "paid scripts" business, and I don't "block people with Adblock". Every little bit of support helps.
Buy Me A Coffee Code Boxx eBooks
FILES LIST
LIBRARIES
lib/LIB-Reactions.php
The reactions library.lib/SQL-Reactions.sql
Reactions database.
API
lib/API-Reactions.php
The reactions API endpoint.
ASSETS & PAGES
pages/PAGE-reactions.php
Demo page.assets/PAGE-reacions.js
Simple Javascript for the demo page.assets/PAGE-reactions.css
Simple CSS for the demo page.assets/reactions.png
Dummy product image.
DEVELOPMENT NOTES
It is possible to open the system up for “public reactions”, without the need for user registration.
- Change the
user_id
to aVARCHAR
. - Then, generate a random string in the cookie as the “temporary
user_id
“.
But of course, this is not the safest method – This is very susceptible to spam.
DATABASE REFERENCE
There is only one table to store the “likes/dislikes”. Feel free to add more fields as required.
REACTIONS TABLE
Field | Description |
id |
Primary key. The ID of the post/product/image/video – Whatever you want to add reactions to. |
user_id |
The user who made the reaction. |
reaction |
This is “preset” to 1 for like, 2 for dislike. |
P.S. Feel free to modify it to your own needs. For examples:
id
is currentlyBIGINT
. Change this toVARCHAR
, if you are using something like “SKU” for products.reaction
is pretty much an open field. Add your own “reaction codes” as you like, examples –3
for annoyed,4
for angry,5
for rage.
LIBRARY REFERENCE
Lastly, the list of library functions and API endpoints.
REACTIONS LIBRARY FUNCTIONS
Get the reactions for the specified item.
$id
Integer, the product/post/video/image ID.
$reacts = $_CORE->Reactions->get(99);
/* $reacts = [
"react" => [
[1 => NUMBER OF LIKES],
[2 => NUMBER OF DISLIKES]
],
"user" => REACTION CODE (NULL FOR NONE)
] */
Save a reaction. The user must be signed in first.
$id
item ID.$reaction
User’s reaction –0
none (delete),1
like,2
dislike.$get
Iftrue
, callget()
and return the updated reactions. Defaultfalse
.
echo $_CORE->Reactions->save(123, 2) // USER DISLIKE ITEM 123
? "OK" : $_CORE->error;
REACTIONS API FUNCTIONS
Get reactions for the specified item.
$_POST["id"]
– Int, post/product/video/image ID.
Save/update a reaction.
$_POST["id"]
– Int, post/product/video/image ID.$_POST["reaction"]
–0
none (delete),1
like,2
dislike