Adding if statement in templates
parent
9c56b73db9
commit
69e3b85516
|
@ -86,6 +86,7 @@ class LogController extends AbstractServerController {
|
||||||
'server_log_entries',
|
'server_log_entries',
|
||||||
array(
|
array(
|
||||||
'logtitle' => $key,
|
'logtitle' => $key,
|
||||||
|
'has_users' => ($key == 'status') ? false : true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
|
|
|
@ -118,6 +118,10 @@ class Template {
|
||||||
}
|
}
|
||||||
$source = $this->addTemplateData($source, $subdata, true);
|
$source = $this->addTemplateData($source, $subdata, true);
|
||||||
} else {
|
} else {
|
||||||
|
// replace if statements
|
||||||
|
$if_replacement = empty($value) ? '' : '$1';
|
||||||
|
$source = preg_replace('{<!--\?'.$key.'-->(.*?)<!--\?\?'.$key.'-->}is', $if_replacement, $source);
|
||||||
|
|
||||||
$source = str_replace('{'.$key.'}', $value, $source);
|
$source = str_replace('{'.$key.'}', $value, $source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,10 +206,18 @@ class Template {
|
||||||
$tmp_string = str_replace('{'.$k.'}', $repeat_html, $tmp_string);
|
$tmp_string = str_replace('{'.$k.'}', $repeat_html, $tmp_string);
|
||||||
} else {
|
} else {
|
||||||
foreach($v as $vk => $vv) {
|
foreach($v as $vk => $vv) {
|
||||||
|
// replace if statements
|
||||||
|
$if_replacement = empty($vv) ? '' : '$1';
|
||||||
|
$tmp_string = preg_replace('{<!--\?'.$k.'_'.$vk.'-->(.*?)<!--\?\?'.$k.'_'.$vk.'-->}is', $if_replacement, $tmp_string);
|
||||||
|
|
||||||
$tmp_string = str_replace('{'.$k.'_'.$vk.'}', $vv, $tmp_string);
|
$tmp_string = str_replace('{'.$k.'_'.$vk.'}', $vv, $tmp_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// replace if statements
|
||||||
|
$if_replacement = empty($v) ? '' : '$1';
|
||||||
|
$tmp_string = preg_replace('{<!--\?'.$k.'-->(.*?)<!--\?\?'.$k.'-->}is', $if_replacement, $tmp_string);
|
||||||
|
|
||||||
$tmp_string = str_replace('{'.$k.'}', $v, $tmp_string);
|
$tmp_string = str_replace('{'.$k.'}', $v, $tmp_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,6 +237,9 @@ class Template {
|
||||||
// check if there are any unused tpl_repeat templates, and if there are remove them
|
// check if there are any unused tpl_repeat templates, and if there are remove them
|
||||||
$result = preg_replace('{<!--%(.+?)-->(.*?)<!--%%\\1-->}is', '', $this->templates[$id]);
|
$result = preg_replace('{<!--%(.+?)-->(.*?)<!--%%\\1-->}is', '', $this->templates[$id]);
|
||||||
|
|
||||||
|
// check if there are any unused if, and if there are remove them
|
||||||
|
$result = preg_replace('{<!--\?(.+?)-->(.*?)<!--\?\?\\1-->}is', '', $result);
|
||||||
|
|
||||||
// check for tpl variables that have not been replaced. ie: {name}. ignore literal stuff, though. ie: {{name}} is {name} and should not be removed
|
// check for tpl variables that have not been replaced. ie: {name}. ignore literal stuff, though. ie: {{name}} is {name} and should not be removed
|
||||||
preg_match_all('~{?{(\w+?)}}?~', $result, $matches);
|
preg_match_all('~{?{(\w+?)}}?~', $result, $matches);
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,14 @@
|
||||||
<col />
|
<col />
|
||||||
<col />
|
<col />
|
||||||
<col style="width: 135px" />
|
<col style="width: 135px" />
|
||||||
<col />
|
<!--?has_users--><col /><!--??has_users-->
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{label_server}</th>
|
<th>{label_server}</th>
|
||||||
<th>{label_message}</th>
|
<th>{label_message}</th>
|
||||||
<th>{label_date}</th>
|
<th>{label_date}</th>
|
||||||
<th>{label_users}</th>
|
<!--?has_users--><th>{label_users}</th><!--??has_users-->
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
<td>{server}</td>
|
<td>{server}</td>
|
||||||
<td>{message}</td>
|
<td>{message}</td>
|
||||||
<td>{datetime_format}</td>
|
<td>{datetime_format}</td>
|
||||||
<td>{users}</td>
|
<!--?has_users--><td>{users}</td><!--??has_users-->
|
||||||
</tr>
|
</tr>
|
||||||
<!--%%tpl_repeat_entries-->
|
<!--%%tpl_repeat_entries-->
|
||||||
{entries}
|
{entries}
|
||||||
|
|
Loading…
Reference in New Issue