Site Rules
Rules
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
[submit] displaysubmit
That data, parsed by a really small algorithm, is the PHP equivalent of:
$op = (isset($_GET['op'])) ? $_GET['op'] : 'read';
if ($op == 'read') {
displayhtml('open');
displayentries();
displayhtml('close');
}
elseif ($op == 'post') {
displayhtml('open');
displayentry();
displayhtml('close');
}
elseif ($op == 'submit') {
displaysubmit();
}
Internally a rule is known as op
, actually converted to $_GET['op']
, and read throughout the code by getvar('op')
. This is a backward compatible, or "legacy" thing explained in the code.
Changing The Rules
Rules are just functions. By adding this to RULES.INI
:
[phpinfo] phpinfo
You have now modified the site to call phpinfo()
with a URL of ?phpinfo
.
Currently, function arguments are stringized; i.e:
[vars] var_dump a b c
with ?vars
, would result in:
string(1) "a" string(1) "b" string(1) "c"
Arguments with PHP like variables are compared against GET variables and set it them if they exist, else are set to empty strings. For example:
[vars] var_dump $a $b $c
with ?vars&a=1&c=foo
, would result in:
string(1) "1" string(0) "" string(3) "foo"
Arguments can reference super globals within {}. This is a version of the logout
rule, where the logout form has a hidden input of a redirect URL:
[logout] cookie_unset from redirect {$_POST['redirect']}
Rule Conditionals
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
where validate()
checks the value of ?post
and if it returns FALSE notfound()
will be executed else it will not. The other conditionals are ? and :. The ? is for functions that return TRUE, and : is for an "if else" construct:
[test] is_numeric $a ?display $a is a number :display $a is not a number
Since echo()
and 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.
Summary
The 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: short and sweet, small and efficient, simple yet versatile. And I try real hard to make it so.
- A possible change may be to enclose arguments in quotes: display "this is a string".