X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=template.php;h=5d35ff7731aa1d095808d03fd33b3fa44789fd8c;hb=40d0d4fdb5270bebf7754da661dcd2a0c5d03a68;hp=85132c31a0172a5791c1d32499872eee3348520f;hpb=23c5e0913ba24aa1c689dc75577de581661858e6;p=wfpl.git diff --git a/template.php b/template.php index 85132c3..5d35ff7 100644 --- a/template.php +++ b/template.php @@ -37,9 +37,9 @@ # tem_auto_* function to munge the data, automating certain common use # cases. See the comments on the tem_auto functions for more details. -require_once('code/wfpl/encode.php'); -require_once('code/wfpl/file.php'); -require_once('code/wfpl/misc.php'); +require_once(__DIR__ . '/encode.php'); +require_once(__DIR__ . '/file.php'); +require_once(__DIR__ . '/misc.php'); # Top-Level Functions @@ -53,7 +53,7 @@ function template_file($filename, $data) { return fill_template(parse_template_file($filename), $data); } -function parse_template_file($filename) { +function &parse_template_file($filename) { return parse_template(file_get_contents($filename)); } @@ -61,11 +61,10 @@ function parse_template_file($filename) { # A template is a hash with a name string, a pieces array, and possibly # an args array. -function parse_template($string) { +function &parse_template($string) { $tem =& tem_push(); $tem['pieces'] = array(); - # note: for some reason this captures ''. - $matches = preg_split("/()/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); + $matches = preg_split('/()/', preg_replace('//', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); foreach($matches as $match) { if($match == '~~') $match = '~'; if(substr($match,0,1) == '~' and strlen($match) > 2) { @@ -91,7 +90,7 @@ function parse_template($string) { } else { # value slot $tem['pieces'][] = array('name' => $name, 'args' => $args); } - } elseif($match and $match != '