INTRODUCTION
This is a simple like/dislike reactions (or upvote/downvote) module for Core Boxx – With a predefined reactions table, library, and API. Simply plug this one into Core Boxx, and let your users vote away.
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.
Download Core Boxx Reactions Module | GitHub | Source Forge
INSTALLATION & REQUIREMENTS
- The user’s module must be installed.
- Unzip this module into your existing Core Boxx project folder.
- Import
lib/SQL-Reacts.sql
into your database.
FILES LIST
lib/LIB-Reacts.php
The reactions library.lib/API-Reacts.php
The reactions API endpoint.pages/PAGE-reacts.php
Demo page.assets/lidi.js
Simple like/dislike “widget” Javascript.assets/lidi.css
Simple like/dislike “widget” CSS.assets/lidi.png
Thumbs up and thumbs down image.assets/PAGE-reacts.js
Demo page Javascript.
DEVELOPMENT NOTES
It is possible to open the system up for “public reactions”, without the need for user registration.
- Change the
uid
to aVARCHAR
. - Then, generate a random string in the cookie as the “temporary
uid
“.
But of course, this is not the safest method – This is very susceptible to spam.
REACTIONS REFERENCE
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 dislike, 1 for like. |
P.S. Feel free to modify 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. Come up with your own “reaction codes” –2
for annoyed,3
for angry,4
for rage.
REACTIONS LIBRARY FUNCTIONS
Get the reactions for the specified item.
$id
Integer, the product/post/video/image ID.
$reacts = $_CORE->Reacts->get(99);
/* $reacts = [
"react" => [
[-1 => NUMBER OF DISLIKES],
[1 => NUMBER OF LIKES]
],
"user" => -1 OR 1 OR NONE
] */
Save a reaction. The user must be signed in first.
$id
item ID.$reaction
User’s reaction –1
like,-1
dislike,0
none (delete).
echo $_CORE->Reacts->save(123, -1) // USER DISLIKE ITEM 123
? "OK" : $_CORE->error;
REACTIONS API FUNCTIONS
Accessible at http://yoursite.com/api/reacts/REQUEST/
. These are pretty much a replica of the above library functions, except in REST API format. Feel free to delete api/API-reacts.php
if you don’t intend to integrate an API.
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"]
–1
like,-1
dislike,0
none (delete).