mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-08 07:54:26 +02:00
arrays and simple conditional blocks in template, template for nav, load templates from themes
This commit is contained in:
parent
f70dd1ee92
commit
0afef6b17e
4 changed files with 158 additions and 60 deletions
50
include/template_processor.php
Normal file
50
include/template_processor.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
|
||||
class Template {
|
||||
var $s;
|
||||
var $r;
|
||||
var $search;
|
||||
var $replace;
|
||||
|
||||
private function _build_replace($r, $prefix){
|
||||
|
||||
if(is_array($r) && count($r)) {
|
||||
foreach ($r as $k => $v ) {
|
||||
if (is_array($v))
|
||||
$this->_build_replace($v, "$prefix$k.");
|
||||
|
||||
$this->search[] = $prefix . $k;
|
||||
$this->replace[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _replcb_if($m){
|
||||
//echo "<pre>"; var_dump($m);
|
||||
$keys = explode(".",$m[1]);
|
||||
$val = $this->r;
|
||||
foreach($keys as $k) {
|
||||
$val = $val[$k];
|
||||
}
|
||||
|
||||
//echo $val;
|
||||
return ($val?$m[2]:"");
|
||||
}
|
||||
|
||||
public function replace($s, $r) {
|
||||
$this->s = $s;
|
||||
$this->r = $r;
|
||||
$this->search = array();
|
||||
$this->replace = array();
|
||||
|
||||
$this->_build_replace($r, "");
|
||||
|
||||
|
||||
$s = preg_replace_callback("|{{ *if *([^ }]*) *}}([^{]*){{ *endif *}}|", array($this, "_replcb_if"), $s);
|
||||
|
||||
return str_replace($this->search,$this->replace,$s);
|
||||
}
|
||||
|
||||
}
|
||||
$t = new Template;
|
Loading…
Add table
Add a link
Reference in a new issue