In this third article of the series, I’ll show you how the database and directories should be set up. I’ll also talk about the how to create, install, and use a content block, which mostly relies on arrays and array functions. I'll cover proper authentication methods for such a project so that multiple sites can run off the same users table in the database, while not barring a username from being used on a site because it is being use on another, all the while keeping the authentication accurate and secure from break-ins. (For part 2, see here.)
The file system is very important to the site engine. If a directory isn’t named right, the engine won’t know it’s there, in which case it won’t load the files from the directory. So I’ll explain the files system to the best of my ability (since I designed it, my ability should be pretty good). With the help of my friends “Windows Explorer” and “Adobe Photoshop”, I made this little diagram to help explain it all.
The “ROOT_DIR” directory can be named whatever you would like to be named as long as the server is set up to know where the site engine files are, configure it accordingly to your operating system’s and server’s specifications.
The “inc” folder should always be named “inc”. This is where all the engine files reside.
The “plug-ins” directory should always be named “plug-ins”. This is the directory that we’ll be putting all our plug-ins into.
The “plug-in_name” directory should be named accordingly, based on what plug-in is contained in it. This is also known to the engine as the name of the plug-in. That’s because all the actual plug-in files are named “main.plug.php” so the engine knows the difference by the name of the directory it is in. There needs to be one directory for each plug-in.
The “blocks” directory should always be named “blocks”. This is where all the blocks that depend on the plug-in, whose directory they are in, reside. Each plug-in directory contains one of these.
The “modules” block directory should always be named “modules”. This is where all the modules that depend on the plug-in, whose directory they're in, reside. Each plug-in directory contains one of these.
The “templates” directory should always be named “templates”. This is where all the files that define the templates for each site reside.
The “site_name” directory should be the same as the host that is defined for the particular site. If your site is hosted at subdomian.url.com the host of the site would be “subdomain”, therefore the directory’s name should be “subdomain” if the site is hosted at www.url.com the host would be "url", therefore the directory’s name would be “url”. There needs to be one directory for each site.
The “template_name” directory should be named the same as the name of the template. If your template is named “Default” the directory should be named “Default”. There can be multiple templates for each site, but at least one per site.
Here is an example of what the directory would look like for the engine running 2 sites, one of the sites having two templates, and five plug-ins, each with a few modules and blocks.
Note. The two directories that are marked with an asterisk (Fig. 1) can actually be renamed to anything you want, although that’s a rather advanced topic that involves a deeper look into the database, the file system, and the plug-ins and module systems
That sums it all up for the file system. It’s actually pretty straight forward and painless when you actually start to work with it.