Merge pull request #1 from Zigazou/master

Now delete unused blocks
This commit is contained in:
Gnieark 2018-03-20 08:29:01 +01:00 committed by GitHub
commit d02867eb5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ class TplBlock {
public $name = '';
private $vars = array();
private $subBlocs = array();
private $unusedRegex = "";
/*
* Initialise TplBlock
@ -29,6 +30,18 @@ class TplBlock {
public function __construct($name = NULL){
$this->name = $name;
$this->unusedRegex = '/'
. self::blockStartStart
. ' *([a-z][a-z.]*) *'
. self::blockStartEnd
. '(.*?)'
. self::blockEndStart
. ' *\1 *'
. self::blockEndEnd
. '/is'
;
}
/*
@ -52,6 +65,18 @@ class TplBlock {
$this->subBlocs[$bloc->name][] = $bloc;
}
private function subBlockRegex($prefix, $blocName) {
return '/'
. self::blockStartStart
. preg_quote($prefix . $blocName)
. self::blockStartEnd
. '(.*?)'
. self::blockEndStart
. preg_quote($prefix . $blocName)
. self::blockEndEnd
. '/is';
}
/*
* Shake template and input vars and returns the text
* Input:
@ -75,10 +100,7 @@ class TplBlock {
//parse blocs
foreach($this->subBlocs as $blocName => $blocsArr){
$str = preg_replace_callback(
'/' . self::blockStartStart . preg_quote($prefix . $blocName) . self::blockStartEnd .
'(.*?)'.
self::blockEndStart . preg_quote($prefix . $blocName). self::blockEndEnd.
'/is',
$this->subBlockRegex($prefix, $blocName),
function($m) use($blocName,$blocsArr,$prefix, $trim) {
$out = "";
foreach($blocsArr as $bloc){
@ -86,14 +108,13 @@ class TplBlock {
$out.=$bloc->apply_tpl_str( $m[1] , $prefix . $blocName , $trim );
}
return $out;
},
$str
}
,$str
);
}
//delete unused blocs
// TODO
// Delete unused blocs
$str = preg_replace($this->unusedRegex, "", $str);
if($trim){
return trim($str,"\n");