From 2a40eb87c8c679a25ddb42587a1934e02312cb4a Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 4 Oct 2012 16:04:55 +0200 Subject: improved and fixed docu. * can now also convert line breaks to
, if parameter lines is true. * now uses PHP's htmlspecialchars instead of htmlentities since it only escapes the minimal neccessary chars which should work, if encoding is handled correctly. * Fixed 2 markup bugs in docu/language_definition.html --- docu/language_definition.html | 7 +++++-- stupid_template_engine.php | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docu/language_definition.html b/docu/language_definition.html index e311907..2c809bc 100644 --- a/docu/language_definition.html +++ b/docu/language_definition.html @@ -113,7 +113,7 @@ Just like their XML counterparts, they can wrap other elements (<ste:foo>bar<ste:baz>herpdederp</ste:baz></ste:foo>) or can be self-closing (<ste:foo />). And they can have additional parameters (or "attributes", using the XML terminology): <ste:foo bar="baz" />

-

A Tag is wrapped in < and >. The tag's name always start with ste: and can then consist of letters, numbers and underscores (Regex: [a-zA-Z0-9_]+).

+

A Tag is wrapped in < and >. The tag's name always start with ste: and can then consist of letters, numbers and underscores (Regex: [a-zA-Z0-9_]+).

If the tag is self-closing, the last char is a / (e.g.: <ste:foo />).

If the tag is a closing one, the first char is a /. An opening Tag does not have a /.An example of an opening-closing Tag pair wrapping the text bar: <ste:foo>bar</ste:foo>

@@ -474,13 +474,16 @@

Standard Library

The Standard Library contains some useful tags, which are not builtin but still always available.

ste:escape

-

Escapes characters that are reserved for HTML (e.g. <, >, ", &). The text to escape is the tag's content. +

Escapes characters that are reserved for HTML (e.g. <, >, ", &). The text to escape is the tag's content.

Example:

<ste:escape>Foo & bar...</ste:escape>
Result:
Foo &amp; bar...

+

+ If the optional parameter lines is true (i.e. not empty), then additionally line breaks are converted to <br />. +

ste:strlen

Returns the length of then content.

diff --git a/stupid_template_engine.php b/stupid_template_engine.php index b231e12..81a7688 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -1360,7 +1360,10 @@ class STEStandardLibrary static public function escape($ste, $params, $sub) { - return htmlentities($sub($ste), ENT_QUOTES, "UTF-8"); + if($ste->evalbool($params["lines"])) + return nl2br(htmlspecialchars(str_replace("\r\n", "\n", $sub($ste)))); + else + return htmlspecialchars($sub($ste)); } static public function strlen($ste, $params, $sub) -- cgit v1.2.3-70-g09d2