Page generating algorithm
Let us consider what making Smereka, when the client receives a page request.
1. First it loading file customsettings.php and apple all its settings. This file is typically located in the same directory as file index.php. So many sites can simultaneously use the same Smereka base code with their own application settings.
2. It loading main Smereka file, which has called – main.php. This file makes the following:
2.1. It sets the database connection to be used until the end of the program.
2.2. It checks whether the Cmd=Redirect input parameter is present. If it is set – the redirect occurs and processing finished.
2.3. It activates PHP session.
2.4. It checks whether the Cmd=Logout input parameter is present. If it is set then "User" object stored in the session is discarded, also some of the other objects stored in session discarded too.
2.5. It checks whether the "User" object is present in current session and if not – creates a new "User" object with anonymous user rights (which allowed to view public pages).
2.6. It determines the page language; if the language specified by Lang input parameter is not in a language set, then error message appears. If the input parameter Lang not set, language set to default value.
2.7. It checks whether the Cmd=Error input parameter is present. If it is set then error page displayed, specified by the SubCmd input parameter.
2.8. It checks whether it is possible to apply Smerecash. If any – attempt to send cached page to user. If the Smerecash disabled, or page is not cached or it is outdated – processing continues.
2.9. It determines the node id: either from the Node input parameter or by parsing the Path input parameter. If these parameters are not set – root node of domain selected.
2.10. It pass control to the dispatch.php module, which provides handlers for most of the Smereka commands.
2.11. The result of this module may be an error (page with the message displayed), a new node id (this id replace the id as defined in paragraph 2.9 – internal Smereka redirect), and the new address – is an external http redirects, or prolonged generation (eg, if no command specified at all).
2.12. It loading from the database target node, analyse its class attribute and invoke polymorphic constructor. This constructor creates a PHP object in memory, defined by metaclass for the node class. Then it load all the language-neutral node attributes and those language-specific attributes that match a given language.
2.13. It loading module page.php and control is passed polymorphic Smereka pages constructor.
3. Module page.php makes the following:
3.1. It verifies the user can access to the required node, and if it do not have rights to see it, an error page displayed.
3.2. It checks whether the Cmd=Edit input parameter is present. If it is set – displays a page in edit mode (essentially performed the same operation as in view mode, but using the editor template). We consider the view mode processing.
3.3. It perform link dereferencing and attributes collecting for given node.
3.4. It determines the page template based on Template attribute.
3.5. It invoke polymorphic pages constructor, which creates a PHP "Page" object in memory. Its class defined by metatemplate for this template. If the metatemplate have link attribute, which points to ancestor template, then it makes a compilation of templates.
3.6. It performs a page compilation by consequent finding of all smeretags present in the template, and calculate them in the context of current node. Result of the calculation replace the smeretag in HTML code. The result of smeretag calculation can be HTML code, which again contains some smeretags; so compilation process is repeated cyclically until all smeretags have been replaced. To prevent possible infinite loop (for example, if the result of smeretag calculation is the same smeretag code) cycle bursts force after a certain number of passes.
3.7. It attempts to save the compiled HTML code of the page in Smerecash for future use.
3.8. It updates the page load counter.
3.9. It performs page post-processing.
3.10. It sends a page to the client.
Understanding the sequence of page generation should help programmer to manage this process.
Previous section | Table of content | Next section