Sven Eichler - 2004-05-02

Logged In: YES
user_id=253680

--- /CVS/php-lib-stable/php/template.inc 2004-04-22
23:17:01.000000000 +0200
+++ /CVS/mylib/template.inc.php 2004-05-02 19:31:16.000000000
+0200
@@ -52,6 +52,13 @@
*
*/

+/*
+ * Change log by Koala 02.05.2004
+ *
+ * new function delete_comment($str)
+ *
+ */
+
/**
* The template class allows you to keep your HTML code in some external
files
* which are completely free of PHP code, but contain replacement fields.
@@ -170,6 +177,24 @@
*/
var $last_error = "";

+ /**
+ * Comments in templates can begin with this.
+ *
+ * @var string
+ * @access public
+ */
+ var $left_delimiter = '{*';
+
+ /**
+ * Comments in templates can end with this.
+ *
+ * @var string
+ * @access public
+ */
+ var $right_delimiter = '*}';
+
+
+
/
******************************************************************************
* Class constructor. May be called with two optional parameters.
* The first parameter sets the template directory the second parameter
@@ -777,14 +802,17 @@
function finish($str) {
switch ($this->unknowns) {
case "keep":
+ $str = $this->delete_comment($str);
break;

case "remove":
$str = preg_replace('/{[^ \t\r\n}]+}/', "", $str);
+ $str = $this->delete_comment($str);
break;

case "comment":
$str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template variable \\1
undefined -->", $str);
+ $str = $this->delete_comment($str);
break;
}

@@ -986,5 +1014,29 @@
printf("<b>Template Error:</b> %s<br>\n", $msg);
}

+
+ /
******************************************************************************
+ * This function strip comments from templates.
+ *
+ * Returns:
+ *
+ * @param $str
+ * @access public
+ * @return string
+ */
+ function delete_comment($str) {
+ if ($this->debug & 1) {
+ print("<b>Varname:</b> $str<br>\n");
+ }
+
+ // Quote regular expression characters
+ $ldq = preg_quote($this->left_delimiter, '!');
+ $rdq = preg_quote($this->right_delimiter, '!');
+
+ $str = preg_replace("!$ldq(.*?)$rdq!se", "", $str);
+
+ return $str;
+ }
+
}
?>