Core Boxx – Comments Module

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.

Download Core Boxx Comments Module | GitHubSource Forge

 

INSTALLATION & REQUIREMENTS

  • Install the “main” Core Boxx and the user module first.
  • Unzip this module into your existing Core Boxx project folder.
  • Import lib/SQL-Comments.sql into your database.
  • Access http://yoursite.com/comment for the demo page.

 

FILES LIST

LIBRARIES

  • lib/LIB-Comments.php The comments library.
  • lib/SQL-Comments.sql Comments database table.

API

  • lib/API-comments.php Comments API endpoint.

ASSETS & PAGES

  • pages/PAGE-comment.php Comments demo page.
  • assets/PAGE-comment.js Comments demo page Javascript.

 

DEVELOPMENT NOTES

  • This module assumes that comments are only open for registered users.
  • If you want to open up for the public, some form of identification needs still needs to be in place – Use a random cookie session ID as the “user ID”.
  • Also, you decide if users can update and delete their own comments.

 

 

DATABASE REFERENCE

There is only one comment table. This should be enough in most cases, feel free to add more fields as required.

 

COMMENTS TABLE

Field Description
comment_id Primary key, auto-increment.
user_id The user that made the comment.
id The ID of whatever you want to attach comments to – Post, product, image, video, etc…
timestamp The time when the comment is posted.
message The comment itself.

 

ADDING REPLIES

If you want to allow “reply to comment”:

  • Add a parent_id field to the comments table.
  • Comments with parent_id=0 is a “main comment”, comments with parent_id>0 is a reply to another comment.
  • Check out this post on categories and sub-categories on how to get all the comments recursively.
  • Be warned though, the complexity can go out of control – It will be difficult to do pagination, you may want to limit the number of levels.

 

 

LIBRARY REFERENCE

Lastly, the list of library functions and API endpoints.

 

COMMENTS LIBRARY FUNCTIONS

save($id, $message, $cid)

Save a comment.

  • $id The post/product/video/image ID.
  • $message Comment message itself.
  • $cid Comment ID – If left blank, will add a new entry, if not, update this entry.
echo $_CORE->Comments->save(999, "Testing")
 ? "OK" : $_CORE->error;
del($cid)

Deletes the specified comment ID.

echo $_CORE->Comments->del(999)
 ? "OK" : $_CORE->error}
get($cid)

Get comment with the specified ID.

$comment = $_CORE->Comments->get(999);
getAll($id)

Get all comments for the specified ID.

$comments = $_CORE->Comments->getAll(999);

 

COMMENTS API FUNCTIONS

api/comments/save/

Save a comment.

  • $_POST["id"] – INT, the post/product/video/image ID.
  • $_POST["message"] – STRING, comment.
  • $_POST["cid"] – INT, comment ID. Only if updating a comment.
api/comments/del/

Delete a comment.

  • $_POST["cid"] – INT, the comment ID.
api/comments/getAll/

Get comments.

  • $_POST["id"] – INT, “item ID”.

 

Leave a Comment

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