ToDo
20 Mar 2016
I haven't quite finished yet

ToDo

I still have a list of things I would like to complete, including the following:

Removal of the ?

  • Login / Users (OAuth?)
  • Set param template
  • Saving data
  • Uploading
  • Refactoring
  • More..?
Error Pages
19 Mar 2016
Tidying up

Error pages

We have everything we need to display custom error pages, for example a custom 404 when the user hits a page they either don't have access to, or does not exist:

config entry

This also requires a redirect in the .htaccess file:

And voila! Custom 404 pages!
function is_localhost()
{
    $whitelist = array( '127.0.0.1', '::1' );
    if( in_array( $_SERVER['REMOTE_ADDR'], $whitelist) )
        return true;
}
Params
18 Mar 2016
Dynamic content!

Params

At times, it is useful to have the user enter a value, or to have a page change what it is displaying based on a parameter passed in. We can update our page evaluation to collect parameters past the end of known locations:

Parameter stripping

And then use these parameters in our HTML pages when displaying our content:

Param usage

This allows us to easily add additional data to page navigation. For example, when displaying blog posts. We could have a single blog page accepting a parameter for which post to display:

Blog page example TODO: mark pages as accepting/declining parameters
Partial data and Loops
17 Mar 2016
Dynamic content!

Partial data / Loops

Now that we're able to loop through our entries and output them in a template, we won't always want all of them. Consider a list of recent blog entries, you may only want to display 5, or 10.

The following code will restrict the number of entries returned:

foreach with restrict

We may also want an offset, so perhaps the most recent 5 entries, starting from entry 10:

foreach with restrict and offset

These two numbers default to 999 and 0, so you will by default collect 999 entries starting at 0

It will also be useful to reverse the order of these entries, placing the most recent at the top (assuming you are adding the most recent to the end of your entries list in your data)

foreach reverse

This tells the CMS to reverse the list of entries before selecting the entries out.

Some examples of how this would look with dataset

Partial subdata
16 Mar 2016
Dynamic content!

Partial subdata

Imagine we are setting up a blog. We may want a list of blog posts. For this we could add in separate pages for each post, or link each post individually into a list, but that's pretty clunky.

As we have the ability to load data from a file, and also to load a template, we could combine the two into a loop, and read out a list of entries and apply our template to each one:

foreach

This will allow us to create a single template for a list of items, and output them all to our page. This should save us a lot of time and hassle in the future.

Base href
15 Mar 2016

Base href

So now that we are redirecting to different pages, some of our assets are going to be in those folders. As we are constructing our pages at the root level (at index.php), we cannot currently use relative paths to link our assets.

There is a solution to this:

base href

It's nice and simple, and allows us to set the base location of our html file. For example if we have a blog page at www.website.com/pages/blog, we can set that as our base and link to all of our CSS and images in the blog folder without having to prepend /pages/blog to everything.

Paths
14 Mar 2016

Paths

The setup we have at the moment is all very nice, for a single page. But we're not always going to stick with a single page website.

Using our top level config file, I have added in support for multiple pages:

Example

This allows us to display specific pages for each url that is passed in. We also need some updates to the .htaccess file, so that we are redirecting properly for all pages. As we have it, everything will be redirected to index.php, and we will evaluate everything there and display pages as required.

Whilst we're here, we should restrict access to all files that we don't want the user to have access to.

.htaccess TODO: Remove ? from url
Subdata
13 Mar 2016

Subdata

So our JSON files are currently flat. We have no nested data. Consider the following:

Some nested data

We need to be able to access any level of data, so I've introduced the following:

Nested accessor

This allows us to get data at any level

TODO: don't use : use . and allow multiple ..
If Blocks
12 Mar 2016

If Blocks

Now that we're substituting data into our templates, it would be good to also not include data or sections where we don't want them.

Introducing conditional substitution!

We have a new tag

if tag

Which checks if the data exists, and is not set to false. Obviously we may want to show or hide an entire section, so I've added the functionality to strip out any content between the tags if it is not matched. For this, we also need the following end if tag:

fi tag

Explanation of double looping to capture multiple/nested if statements

Adding Data
11 Mar 2016

Adding Data

Variable substitution is cool, but we're going to need another level of replacement for larger sections of HTML. For example a header may be displayed across all pages, so we would want to split that out into a seperate file and manage that on it's own.

Cue file substitution!

Substitution code

Cool, now we're loading and displaying our file, with variable substitution from config. Easy!

Example of how this is useful. - Header

Simple beginnings
10 Mar 2016

Simple Beginnings

To start, I needed a template. I'm a big fan of HTML5 UP, they make some great looking templates, and they're free to use.

Now we have something to show, the first step is to create our index.php, load in our HTML file and then output it. Easy!

Some PHP Code example here

This is a good first step, but to make it actually useful, we're going to need some way of substituting some of these values with data we have in a config file. For now I'm going to create a JSON config file, and we can grow it from there.

Initial JSON config vars

So we have an HTML file, we have some data, now we need to somehow mark where we're going to substitute that data into our file. I'm thinking a simple string substitution in PHP, but I'll need a marker to tell me what to substitute where.

~ $('var_name')

I've chosen the tilde-dollar (~$) as my marker, along with the variable name, single quoted, in brackets afterwards. This may change later if there's some standard that I've overlooked, and I'll almost certainly need to compare double quotes as well, but for now it's a good place to begin.

For substitution, let's try the following

Substitution code

Cool, now we're loading and displaying our file, with variable substitution from config. Easy!

Example of how this is useful.

Starting Development
09 Mar 2016

Starting Development

I've chosen PHP, mostly because it's a technology that I'm comfortable using and is widely supported. This should let me rapidly build the system with minimum fuss.

In the future, when development has reached a point that I'm happy with, I'll be looking at poorting it to other languages, probably starting with Ruby, as I've seen some interesting things happening over there. Of course that doesn't rule out other languages, I'm up for learning all that I can!

For templating I think I'll keep it simple and start with some standard HTML files. I love the templates over at HTML5Up.net, so I'll grab one of those to build around.

In terms of data, JSON is my weapon of choice, due to its human readability and the libraries available. As I'm trying to keep things nice and simple, I'll probably be sticking with storing data in text files on the server for now, but perhaps I'll look into SQLite or something similar in the later, depending on how things go. I would rather not add in the hassle of database management though, as I would like deployment to be as easy as dropping some files into a folder.


Whilst I talk about just dropping files into a folder and having a site, I would like some clever things to happen, such as showing most recent blog posts, or dynamic links, which will make the CMS worth the development, rather than just being an elaborate way of creating static sites.

Introduction to My CMS
08 Mar 2016

Introduction to My CMS

As a developer, I enjoy a challenge, and an opportunity to expand my skillset.

I've used a few Content Management Systems in my time, I've dabbled with WordPress, fiddled with Concrete5 and nosed around SimpleCMS, to name a few. Whilst these all have their benefits and their uses, they've never really grabbed me and excited me in the way that I want.

So I decided to create my own...

This website is driven by my custom CMS (as of yet unnamed), and the following blog posts will attempt to lead you through my journey and document the rise of my little project!

To start, I set some simple goals to drive the first stage of development:

  • Templates - I want to be able to quickly and easily put content together based on pre-built templates or pages. Just pop in some content and go.
  • Custom Data / dynamic pages
  • No Database setup/management required
  • Simple to use, easy to setup
  • And more things

Eventually this project will make it's way over to GitHub. If you have any questions, requests or suggestions, or would like to contribute in any way, just head over to my Contact page and give me shout.

My First CMS
08 Feb 2016

Blog Content 1

This is clearly filler material.

Stay tuned
06 Feb 2016

Blog Content 2

It's not finished!