- Chainsaw Bike
- STM32F429 LCD Example
- My PHP Content Managing System
- PHP image handler
- Flyback-transformer driver
- Atari Punk Console
- Teensy - ESP8266 - Interface
- Charging station
- 4-bit Adder
The Content Managing System of my homepageDec 2015
In this article I want to present to you the content managing system of this site. As everything here is a product of my coding, I have the urge to show what I have created. The thing with web development is that the magic happens behind the scenes. The only thing the website visitor sees is the output.
For that reason, I have created this article; to show & tell my code. The entire content managing system is written in PHP only.
Overview on how the CMS works
Compared to other free CMS systems you can install on your server, this CMS is tiny. But it's all I need for my homepage and it was fun programming it.
When you request a page by typing in the URL (for example monoclecat.de/?l=etching), then you are performing a GET-request with the variable l set to the value "etching". Then the code searches the database of pages for the one with the name "etching" and loads its content into a skeleton which contains the basic structure all pages have (banner on top, horizontal menu bar, sidebar and footer). The result is what you see, for example on this page right here.
The table "CMS" in the website's database contains all the script needs to build a fully functional page. Here is an example with two pages where you can see the structure: (Scroll horizontally to see the entire table)
|10||4-bit-adder||project||48||2014-06||4-bit Adder||no||4-Bit-Adder Monoclecat.de||4-Bit-Adder made only with logic gates||A 4-bit adder I built in 10th grade.||In 10th grade computer-science...|
|4||about||about||2015-12||About me||no||About Me Monoclecat.de||About me||About me and the history of this site||Hi, my name is Andrew Delay and...|
As you can see, there is much more to a page than just a title (seen on the label of the tab in your browser), a name (which is what the l-variable must be set to) and the content. As an example, the links on the sidebar are also built with a php script. To have a nice name to display, the script needs the "showname".
On the welcome page of the site, the newsfeed is also built via a script. Here it need even more additional information. The database supplies it with the primary image of the page, a headline and an abstract, which is a short summary of the page content.
Adding a new page / modifying an existing one
To create or edit a page, one must log in first so the website knows who the visitor is and can give him the necessary permissions. After logging in, when visiting a page, it builds it as if you were a normal visitor. Under the content though, at the bottom of the page, the php script will add a form and fill it with the content from the database. Then you can edit it, press "Save" and the script updates the database content at that place.
Here is an example of the editing mode:
The code for the CMS is made up of two php files, io.php and cmsstuff.php. io.php is the "page skeleton" mentioned above. It is a body which is filled with content every time you load a page. You are actually on it right now; it is just not necessarily visible in the URL. Instead of "monoclecat.de/?l=CMS" you could also write "monoclecat.de/io.php?l=CMS". cmsstuff.php represents the backend with the crucial scripts, handling database updates and parsing database content.
The code for my CMS is open-source and available on my Github profile here. If you want to use the code you will have to delete some parts of it, as it contains function calls to scripts that are not included.