Page Generation
NOTE: Used square brackets ([ ]) to indicate data inserted into SQL statements.
> indicates SQL statement.
>> indicates table structure of reply.
RESULT is the final outputed page.
"SELECT * FROM ..." is used instead of specifing only the colums we need
to show the whole table for reference.
Path = (eg /path/to/directory/or/file.htm)
// 1. Get data for page.
> SELECT * FROM `page` WHERE `path` = '[Path]';
>> id, parentid, path, title, timestamp
IF a row was returned THEN
PageID = id
PageParentID = parentid
PageTitle = title
Continue
ELSE
RESULT = Error page + HTTP Error(404 Not Found)
// 2. check cache.
> SELECT * FROM `page_cache` WHERE `pageid` = '[PageID]';
>> id, pageid, cache
IF a row was returned THEN
RESULT = cache
ELSE
Continue
// 3. Need to find template ID now.
> SELECT * FROM `rel_page_template` WHERE `pageid` = '[PageID]';
>> id, pageid, templateid
IF a row was returned THEN
TemplateID = templateid
GOTO step 6
ELSE
CheckPageID = PageParentID
Continue
// 4. Check CheckPageID (PageParentID).
> SELECT * FROM `rel_page_template` WHERE `pageid` = '[CheckPageID]';
>> id, pageid, templateid
IF a row was returned THEN
TemplateID = templateid
GOTO step 6
ELSE
Continue
// 5. Get the PageParentID of CheckPageID.
> SELECT * FROM `page` WHERE `id` = '[CheckPageID]';
>> id, parentid, path, title, timestamp
IF a row was returned THEN
CheckPageID = parentid
GOTO step 4
ELSE
RESULT = Error page (maybe 404)
// 6. Get template.
> SELECT * FROM `template_text` WHERE `templateid` = '[TemplateID]';
>> id, templateid, template
Template = template
// 7. Get template section data.
> SELECT * FROM `template_section` WHERE `templateid` = '[TemplateID]';
>> id, templateid, sectionid, replacetext, title (multiple rows)
ARRAY SectionReplaceTextArray[sectionid] = replacetext
// 8. Review of variables we have so far (variables that are not needed are not listed).
PageID // ID of the page.
PageParentID // ID of the pages parent.
PageTitle // Title of the page (PageTitle).
Template // The template.
SectionReplaceTextArray[SectionID] // Array of text we neet to replace
// in the template with the ID of the section as the key.
// 9. Get content data.
> SELECT * FROM `content` WHERE `pageid` = '[PageID]';
>> id, pageid, sectionid, isphp, isdynamic (multiple rows)
ARRAY ContentArray[id]['sectionid'] = sectionid
ARRAY ContentArray[id]['isphp'] = isphp
ARRAY ContentArray[id]['isdynamic'] = isdynamic
(NOTE id will now be called ContentID from now on)
// 10. Loop through each ContentArray[ContentID] to find content
// in a simular way to steps 3 to 5.
// I wont write all the pseudocode this time
Looking for ContentArray[ContentID]['content'].
> SELECT * FROM `content_cache` WHERE `contentid` = '[ContentID]';
>> id, contentid, cache
IF a row was returned THEN
ContentArray[ContentID]['content'] = cache
GOTO step 11
> SELECT * FROM `content_text` WHERE `contentid` = '[ContentID]';
>> id, contentid, content
IF a row was returned THEN
IF ContentArray[ContentID]['isphp'] is TRUE
content = RenderPHP(content)
ContentArray[ContentID]['content'] = content
IF ContentArray[ContentID]['isdynamic'] is FALSE
> INSERT INTO `content_cache` (`contentid`, `cache`)
> VALUES ('[ContentID]', '[ContentArray[ContentID]['content']]');
ELSE
PageIsDynamic = TRUE
GOTO step 11
ELSE
Try getting content from Parent....
// 11. Loop through ContentArray[ContentID] and replace
// SectionReplaceTextArray[ContentArray[ContentID]['sectionid']]
// with ContentArray[ContentID]['content'] in the put in variable RESULT.
// 12. Save cached page
IF NOT PageIsDynamic = TRUE
> INSERT INTO `page_cache` (`pageid`, `cache`)
> VALUES ('[PageID]', '[RESULT]');