Core Boxx – Dynamic Content Module

This is a simple dynamic content module for Core Boxx. Articles, posts, code snippets, descriptions – Save whatever content you need into the database and retrieve it dynamically.

 

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 Contents Module | GitHub | Source 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.
  • To “install”, simply import the lib/SQL-contents.sql file, and delete it afterward.

 

MORE DEVELOPMENT NOTES

This module will work “as-it-is”. Just save your content in the database and use get() to retrieve them. But an alternative for possibly better performance is to:

  • Complete toFile() in LIB-Contents.php – Generate a flat HTML file (or whatever file you may want to offer for download).
  • Change save() in LIB-Contents to run toFile() at the end.
  • Protect API-contents.php – Check if the user has access permission before processing.

 

QUICK REFERENCE

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

 

CONTENT DATABASE TABLE

Function Description & Quick Example
content_id Primary key, the content ID.
content_title Title or short description of the content.
content_text Text or body of the content.
date_created Date when the content is created.
date_modified Last modified timestamp.

 

CONTENT LIBRARY FUNCTIONS

save($title, $text, $id)

Add or update content.

  • $title String, the content title/description.
  • $text String, the content body.
  • $id Int, provide the content ID to update. Leave as null to add a new one.
echo $_CORE->Contents->save(
  "TITLE", "CONTENT"
) ? "OK" : $_CORE->error ;
del($id)

Delete a piece of content.

  • $id Int, the content ID.
echo $_CORE->Contents->del(1) 
  ? "OK" : $_CORE->error ;
get($id)

Get a piece of content.

  • $id Int, the content ID.
$content = $_CORE->Contents->get(1);
count($search)

Count the total entries of contents.

  • $search String, optional search term.
$entries = $_CORE->Contents->count("search");
getAll($search, $page)

Get all or search for content.

  • $search String, optional search term.
  • $page Int, optional current page.
$entries = $_CORE->Contents->getAll("search", 2);
toFile($id)

An incomplete support function for save(), generate a static file. Complete it if you want, good for HTML, CSS, Javascript, or maybe files that you want to offer for download.

  • $id Int, content ID.

 

 

CONTENTS API

Accessible at http://yoursite.com/api/contents/REQUEST/. These are pretty much a replica of the above library functions, except in REST API format. Feel free to delete api/API-contents.php if you don’t intend to integrate an API.

api/contents/save/

Add or update content.

  • $_POST['title'] String, content title or description.
  • $_POST['text'] String, content body.
  • $_POST['id'] Int, optional content ID.
api/contents/del/

Delete a piece of content.

  • $_POST['id'] The content ID.
api/contents/get/

Get a piece of content.

  • $_POST['id'] The content ID.
api/contents/getAll/

Search for a piece of content.

  • $_POST['search'] The search term.
  • $_POST['page'] The current page.

Leave a Comment

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