From 31a21ac24cd5cbe19e40ab3838fcc179d812da13 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 8 May 2013 03:51:38 -0400 Subject: use smarty3 as default template engine. add pluggable template system --- include/text.php | 63 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) mode change 100644 => 100755 include/text.php (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php old mode 100644 new mode 100755 index c7210010c..3b3620f33 --- a/include/text.php +++ b/include/text.php @@ -1,44 +1,23 @@ replace) -// returns substituted string. - require_once("include/template_processor.php"); +require_once("include/friendica_smarty.php"); - +/** + * This is our template processor + * + * @param string|FriendicaSmarty $s the string requiring macro substitution, + * or an instance of FriendicaSmarty + * @param array $r key value pairs (search => replace) + * @return string substituted string + */ function replace_macros($s,$r) { - global $t; - -// $ts = microtime(); $a = get_app(); - if($a->get_template_engine() === 'smarty3') { - $output = ''; - if(gettype($s) !== 'NULL') { - $template = ''; - if(gettype($s) === 'string') { - $template = $s; - $s = new FriendicaSmarty(); - } - foreach($r as $key=>$value) { - if($key[0] === '$') { - $key = substr($key, 1); - } - $s->assign($key, $value); - } - $output = $s->parsed($template); - } - } - else { - $r = $t->replace($s,$r); + $t = $a->template_engine(); + $output = $t->replace_macros($s,$r); - $output = template_unescape($r); - } -// $tt = microtime() - $ts; -// $a->page['debug'] .= "$tt
\n"; return $output; } @@ -71,6 +50,8 @@ function random_string($size = 64,$type = RANDOM_STRING_HEX) { * They will be replaced with safer brackets. This may be filtered further * if these are not allowed either. * + * @param string $string Input string + * @return string Filtered string */ @@ -86,6 +67,13 @@ function notags($string) { // and allow them to be safely displayed. + +/** + * use this on "body" or "content" input where angle chars shouldn't be removed, + * and allow them to be safely displayed. + * @param string $string + * @return string + */ function escape_tags($string) { return(htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false)); @@ -97,6 +85,12 @@ function escape_tags($string) { // used to generate initial passwords +/** + * generate a string that's random, but usually pronounceable. + * used to generate initial passwords + * @param int $len + * @return string + */ function autoname($len) { if($len <= 0) @@ -172,6 +166,11 @@ function autoname($len) { // returns escaped text. +/** + * escape text ($str) for XML transport + * @param string $str + * @return string Escaped text. + */ function xmlify($str) { $buffer = ''; -- cgit v1.2.3