This site operates through "rules" defined in an INI encoded file,
RULES.INI. Here is an excerpt:
default = read [read] displayhtml open displayentries displayhtml close [post] displayhtml open displayentry displayhtml close
A "rule" is simply ?rule in the URL. (Internally a rule is known as
op, actually converted to
The end of
INDEX.PHP reads the
$_GET variable which is then handed off to the function that runs the site:
getvar() replaces the assignment "is set GET variable ? GET variable : null", which may seem odd but it reduces over all code size and complexity (something that is fun to do).
A rule is made up of functions. A rule of:
would run the PHP function
phpinfo() and exit with a URL of ?phpinfo. (And, NO, that is NOT a rule here, so don't bother trying it.)
A rule can be assigned an argument, ?post=1, and is internally stored as
$_GET['id'], which is read by
Rule functions can be conditional. If a function returns a value it is stored. A following function can have an indicator to base it's execution on. The post rule is actually preceded by:
[post] validate !notfound
validate() (a function in
RULES.PHP) checks the value of
getvar('id') for being numerical and existing in the database. If it returns FALSE, the function
notfound() will be executed. The other conditionals are ? and :. The ? is for functions that return TRUE, and : is for an "else" construct:
[test] is_numeric $a ?display $a is a number :display $a is not a number
print() are not functions they cannot be used as rules;
display() is a defined function that prints all of it's arguments and so does the equivalent.
RULES.PHP file is only 250 lines long, and the rules algorithm is only 60 lines, and this is the best introduction to this code: small and efficient, simple and versatile. And we try real hard to make it so.
- A possible change may be to enclose arguments in quotes: display "this is a string" (but it is just a semantic thing).
- Though it probably ain't perfect.