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
- Copy/unzip this module into your existing Core Boxx project folder.
- Access
http://your-site.com/install/content
, this will automatically:- Import
lib/SQL-Contents.sql
into your database. - Add a new
$wild = [ "post/" => "POST-load.php" ]
route toHOOK-Routes.php
. - Delete
PAGE-install-content.php
itself.
- Import
- Open
http://your-site.com/post/hello
for the demo. - Feel free to use
$_CORE->Contents->save(SLUG, TITLE, TEXT)
to create more posts. - Or if you have installed the admin module –
http://your-site.com/admin/content
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-Contents.php
The contents library.lib/SQL-Contents.php
Contents database table.
API
lib/API-contents.php
Contents API endpoint.
ASSETS & PAGES
assets/tinymce
TinyMCE WYSIWYG editor.assets/ADM-content.js
Contents admin page JS.pages/ADM-content.php
Contents admin page.pages/ADM-content-form.php
Add/edit content page. Loaded via AJAX.pages/ADM-content-list.php
Contents list. Loaded via AJAX.pages/POST-load.php
Allhttp://your-site.com/post/SLUG
will route here. Loads content from the database and generates the page.
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()
inLIB-Contents.php
– Generate a flat HTML file (or whatever file you may want to offer for download). - Change
save()
inLIB-Contents.php
to runtoFile()
after saving.
- Complete
- Protect the API endpoint! All of these are admin functions.
DATABASE REFERENCE
There is only one table to store the content. Feel free to expand on it – Maybe add categories and tags.
CONTENT TABLE
Function | Description & Quick Example |
content_id |
Primary key, the content ID. |
content_slug |
Content URL slug, unique. |
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. |
LIBRARY REFERENCE
Lastly, the list of library functions and API endpoints.
CONTENT LIBRARY FUNCTIONS
Add or update content.
$slug
String, the URL slug.$title
String, the content title/description.$text
String, the content body.$id
Int, provide the content ID to update. Leave asnull
to add a new one.
echo $_CORE->Contents->save(
"SLUG", "TITLE", "CONTENT"
) ? "OK" : $_CORE->error ;
Delete a piece of content.
$id
Int, the content ID.
echo $_CORE->Contents->del(1)
? "OK" : $_CORE->error ;
Get a piece of content.
$id
Int/string, the content ID or URL slug.
$content = $_CORE->Contents->get(1);
Get all or search for content.
$search
String, optional search term.$page
Int, optional current page.
$entries = $_CORE->Contents->getAll("search", 2);
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/String, content ID or URL slug.
CONTENTS API
Add or update content.
$_POST["slug"]
String, URL slug.$_POST["title"]
String, content title or description.$_POST["text"]
String, content body.$_POST["id"]
Int, optional content ID.
Delete a piece of content.
$_POST["id"]
The content ID.
Get a piece of content.
$_POST["id"]
The content ID or URL slug.
Search for a piece of content.
$_POST["search"]
The search term.$_POST["page"]
The current page.