Core Boxx – Reactions Module

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.

 

TABLE OF CONTENTS

Download & Notes Quick Reference

 

 

DOWNLOAD & NOTES

First, here are the download links and a quick “setup guide” for the impatient folks who don’t have the patience to read through everything.

 

DOWNLOAD LINKS

Download Core Boxx Reactions Module | GitHubSource Forge

 

LICENSE

Core Boxx is released under the MIT License. You are free to use it for your own personal and commercial projects, modify it as you see fit. On the condition that there 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 & REQUIREMENTS

  • Download and set up the “main Core Boxx” if you have not already done so.
  • Import lib/SQL-reacts.sql into your database.
  • It is highly recommended to have a user’s module in place.

 

QUICK REFERENCE

This section is a quick walkthrough of the general module structures.

 

THE 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 currently INT. Change this to VARCHAR, 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($id, $uid)

Get the reactions for the specified item.

  • $id Integer, the product/post/video/image ID.
  • $uid Integer, optional. Also get the reaction of this user for this specific item.
$reacts = $_CORE->Reacts->get(99, 888);
/* $reacts = [
  "react" => [
    [-1 => NUMBER OF DISLIKES],
    [1 => NUMBER OF LIKES]
  ],
  "user" => -1 OR 1 OR NONE (USER ID 888 REACTION FOR ITEM ID 99)
] */
save($id, $uid, $reaction)

Save a reaction.

  • $id item ID.
  • $uid user ID.
  • $reaction User’s reaction – 1 like, -1 dislike, 0 none (delete).
echo $_CORE->Reacts->save(123, 456, -1) // USER 456 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.

api/reacts/get/

Get reactions for the specified item.

  • $_POST['id'] – Int, post/product/video/image ID.
  • $_POST['uid'] – Int, optional user ID.
api/reacts/save/

Save/update a reaction.

  • $_POST['id'] – Int, post/product/video/image ID.
  • $_POST['uid'] – Int, user ID.
  • $_POST['reaction']1 like, -1 dislike, 0 none (delete).

 

IS THE USER MODULE NECESSARY?

Well, no. If you want to open up for public reactions, a possible alternative is to:

  • Change the uid to a VARCHAR.
  • Then, use the PHP session ID as the “temporary uid“.
  • Or generate a random ID, set it in the cookie.

Leave a Comment

Your email address will not be published. Required fields are marked *