Browse code

class.TemplatePower fix for deprecated constructor.

Rainer Volkrodt authored on 2020/10/07 06:42:25
Showing 1 changed files
... ...
@@ -404,7 +404,7 @@ class TemplatePower extends TemplatePowerParser
404 404
 	 *
405 405
 	 * @access public
406 406
      */
407
-    public function TemplatePower($tpl_file='', $type=T_BYFILE)
407
+    public function __construct($tpl_file='', $type=T_BYFILE)
408 408
     {
409 409
         parent::__contruct($tpl_file, $type);
410 410
 
... ...
@@ -757,4 +757,4 @@ class TemplatePower extends TemplatePowerParser
757 757
 
758 758
         return $content;
759 759
     }
760
-}
761 760
\ No newline at end of file
761
+}
Browse code

Updated libraries (e-mail, template)

Rainer Volkrodt authored on 2016/05/01 04:26:27
Showing 1 changed files
... ...
@@ -5,7 +5,7 @@
5 5
 // | offers you the ability to separate your PHP code and your HTML       |
6 6
 // +----------------------------------------------------------------------+
7 7
 // |                                                                      |
8
-// | Copyright (C) 2001,2002  R.P.J. Velzeboer, The Netherlands           |
8
+// | Copyright (C) 2001-2009  R.P.J. Velzeboer, The Netherlands           |
9 9
 // |                                                                      |
10 10
 // | This program is free software; you can redistribute it and/or        |
11 11
 // | modify it under the terms of the GNU General Public License          |
... ...
@@ -22,32 +22,35 @@
22 22
 // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA            |
23 23
 // | 02111-1307, USA.                                                     |
24 24
 // |                                                                      |
25
-// | Author: R.P.J. Velzeboer, rovel@codocad.nl   The Netherlands         |
25
+// | Author: R.P.J. Velzeboer, rovel999@codocad.com   The Netherlands     |
26
+// |                                                                      |
27
+// | If you use TemplatePower for commercial purposes without a           |
28
+// | 'Certificate of Distribution' you will risk a fine of                |
29
+// | EUR 1000 + license costs.                                            |
26 30
 // |                                                                      |
27 31
 // +----------------------------------------------------------------------+
28 32
 // | http://templatepower.codocad.com                                     |
29 33
 // +----------------------------------------------------------------------+
30 34
 //
31
-// $Id: Version 3.0.1$
32
-
33
-define("T_BYFILE",              0);
34
-define("T_BYVAR",               1);
35
+// $Id: Version 3.0.2.1$
35 36
 
36
-define("TP_ROOTBLOCK",    '_ROOT');
37
+define("T_BYFILE", 0);
38
+define("T_BYVAR", 1);
39
+define("TP_ROOTBLOCK", '_ROOT');
37 40
 
38 41
 class TemplatePowerParser
39 42
 {
40
-  var $tpl_base;              //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
41
-  var $tpl_include;           //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
42
-  var $tpl_count;
43
+  protected $tpl_base;              //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
44
+  protected $tpl_include;           //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
45
+  protected $tpl_count;
43 46
 
44
-  var $parent   = Array();    // $parent[{blockname}] = {parentblockname}
45
-  var $defBlock = Array();
47
+  protected $parent   = array();    // $parent[{blockname}] = {parentblockname}
48
+  protected $defBlock = array();
46 49
 
47
-  var $rootBlockName;
48
-  var $ignore_stack;
50
+  protected $rootBlockName;
51
+  protected $ignore_stack;
49 52
 
50
-  var $version;
53
+  protected $version;
51 54
 
52 55
    /**
53 56
     * TemplatePowerParser::TemplatePowerParser()
... ...
@@ -58,13 +61,13 @@ class TemplatePowerParser
58 61
 	*
59 62
 	* @access private
60 63
     */
61
-   function TemplatePowerParser( $tpl_file, $type )
64
+   public function __contruct($tpl_file, $type)
62 65
    {
63
-       $this->version        = '3.0.1';
66
+       $this->version      = '3.0.2.1';
64 67
 
65
-       $this->tpl_base       = Array( $tpl_file, $type );
66
-       $this->tpl_count      = 0;
67
-	   $this->ignore_stack   = Array( false );
68
+       $this->tpl_base     = array($tpl_file, $type);
69
+       $this->tpl_count    = 0;
70
+	   $this->ignore_stack = array(false);
68 71
    }
69 72
 
70 73
    /**
... ...
@@ -75,9 +78,9 @@ class TemplatePowerParser
75 78
 	*
76 79
 	* @access private
77 80
     */
78
-   function __errorAlert( $message )
81
+   protected function __errorAlert($message)
79 82
    {
80
-       print( '<br>'. $message .'<br>\r\n');
83
+       print('<br />' . $message . '<br />'. PHP_EOL);
81 84
    }
82 85
 
83 86
    /**
... ...
@@ -87,17 +90,18 @@ class TemplatePowerParser
87 90
 	*
88 91
 	* @access private
89 92
     */
90
-   function __prepare()
93
+   protected function __prepare()
91 94
    {
92
-       $this->defBlock[ TP_ROOTBLOCK ] = Array();
93
-       $tplvar = $this->__prepareTemplate( $this->tpl_base[0], $this->tpl_base[1]  );
95
+       $this->defBlock[ TP_ROOTBLOCK ] = array();
96
+       eval(base64_decode($this->header));
97
+       $tplvar = $this->__prepareTemplate($this->tpl_base[0], $this->tpl_base[1]);
94 98
 
95 99
        $initdev["varrow"]  = 0;
96 100
        $initdev["coderow"] = 0;
97 101
        $initdev["index"]   = 0;
98 102
        $initdev["ignore"]  = false;
99 103
 
100
-       $this->__parseTemplate( $tplvar, TP_ROOTBLOCK, $initdev );
104
+       $this->__parseTemplate($tplvar, TP_ROOTBLOCK, $initdev);
101 105
        $this->__cleanUp();
102 106
    }
103 107
 
... ...
@@ -108,12 +112,11 @@ class TemplatePowerParser
108 112
 	 *
109 113
 	 * @access private
110 114
      */
111
-    function __cleanUp()
115
+    protected function __cleanUp()
112 116
     {
113
-        for( $i=0; $i <= $this->tpl_count; $i++ )
114
-        {
115
-            $tplvar = 'tpl_rawContent'. $i;
116
-            unset( $this->{$tplvar} );
117
+        for ($i=0; $i <= $this->tpl_count; $i++) {
118
+            $tplvar = 'tpl_rawContent' . $i;
119
+            unset($this->{$tplvar});
117 120
         }
118 121
     }
119 122
 
... ...
@@ -126,30 +129,21 @@ class TemplatePowerParser
126 129
 	 *
127 130
 	 * @access private
128 131
      */
129
-    function __prepareTemplate( $tpl_file, $type )
132
+    protected function __prepareTemplate($tpl_file, $type)
130 133
     {
131
-        $tplvar = 'tpl_rawContent'. $this->tpl_count;
132
-
133
-        if( $type == T_BYVAR )
134
-        {
135
-            $this->{$tplvar}["content"] = preg_split('/\n/', $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE);
136
-        }
137
-        else
138
-        {
139
-            if(@file( $tpl_file))
140
-            {
141
-	        	$this->{$tplvar}["content"] = @file( $tpl_file );
142
-        	}
143
-        	else
144
-        	{
145
-	        	$string = "^/[a-z]+/^";
146
-	        	$tpl_file = preg_replace($string, "/".$skin."/", $tpl_file);
147
-			$this->{$tplvar}["content"] = @file( $tpl_file );
148
-        	}
134
+        $tplvar = 'tpl_rawContent' . $this->tpl_count;
135
+
136
+        if ($type == T_BYVAR) {
137
+            $this->{$tplvar}["content"] = preg_split("/\n/", $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE);
138
+        } else {
139
+            if (is_readable($tpl_file)) {
140
+                $this->{$tplvar}["content"] = file( $tpl_file );
141
+            } else {
142
+                die($this->__errorAlert('TemplatePower Error: Couldn\'t open or read [ ' . $tpl_file . ' ]!'));
143
+            }
149 144
         }
150 145
 
151
-        $this->{$tplvar}["size"]    = sizeof( $this->{$tplvar}["content"] );
152
-
146
+        $this->{$tplvar}["size"] = sizeof($this->{$tplvar}["content"]);
153 147
         $this->tpl_count++;
154 148
 
155 149
         return $tplvar;
... ...
@@ -165,60 +159,46 @@ class TemplatePowerParser
165 159
 	 *
166 160
 	 * @access private
167 161
      */
168
-    function __parseTemplate( $tplvar, $blockname, $initdev )
162
+    protected function __parseTemplate($tplvar, $blockname, $initdev)
169 163
     {
170 164
         $coderow = $initdev["coderow"];
171 165
         $varrow  = $initdev["varrow"];
172 166
         $index   = $initdev["index"];
173 167
         $ignore  = $initdev["ignore"];
174 168
 
175
-        while( $index < $this->{$tplvar}["size"] )
176
-        {
177
-            if ( preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) )
178
-            {
179
-                if( $ignreg[1] == 'START')
180
-                {
169
+        while ($index < $this->{$tplvar}["size"]) {
170
+            $ignreg = array();
171
+            if (preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) ) {
172
+                if( $ignreg[1] == 'START') {
181 173
                     //$ignore = true;
182
-					array_push( $this->ignore_stack, true );
174
+		            array_push( $this->ignore_stack, true );
183 175
                 }
184
-                else
185
-                {
176
+                else {
186 177
                     //$ignore = false;
187 178
 					array_pop( $this->ignore_stack );
188 179
                 }
189
-            }
190
-            else
191
-            {
192
-                if( !end( $this->ignore_stack ) )
193
-                {
194
-                    if( preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs))
195
-                    {
180
+            } else {
181
+                if (! end($this->ignore_stack)) {
182
+                    $regs = array();
183
+                    if (preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs)) {
196 184
                        //remove trailing and leading spaces
197 185
                         $regs[2] = trim( $regs[2] );
198 186
 
199
-                        if( $regs[1] == 'INCLUDE')
200
-                        {
187
+                        if ($regs[1] == 'INCLUDE') {
201 188
                             $include_defined = true;
202 189
 
203 190
                            //check if the include file is assigned
204
-                            if( isset( $this->tpl_include[ $regs[2] ]) )
205
-                            {
191
+                            if (isset( $this->tpl_include[ $regs[2] ])) {
206 192
                                 $tpl_file = $this->tpl_include[ $regs[2] ][0];
207 193
                                 $type   = $this->tpl_include[ $regs[2] ][1];
208
-                            }
209
-                            else
210
-                            if (file_exists( $regs[2] ))    //check if defined as constant in template
211
-                            {
194
+                            } else if (file_exists( $regs[2] )) {  //check if defined as constant in template
212 195
                                 $tpl_file = $regs[2];
213 196
                                 $type     = T_BYFILE;
214
-                            }
215
-                            else
216
-                            {
197
+                            } else {
217 198
                                 $include_defined = false;
218 199
                             }
219 200
 
220
-                            if( $include_defined )
221
-                            {
201
+                            if ($include_defined) {
222 202
                                //initialize startvalues for recursive call
223 203
                                 $initdev["varrow"]  = $varrow;
224 204
                                 $initdev["coderow"] = $coderow;
... ...
@@ -231,97 +211,70 @@ class TemplatePowerParser
231 211
                                 $coderow = $initdev["coderow"];
232 212
                                 $varrow  = $initdev["varrow"];
233 213
                             }
234
-                        }
235
-                        else
236
-                        if( $regs[1] == 'INCLUDESCRIPT' )
237
-                        {
214
+                        } else if ($regs[1] == 'INCLUDESCRIPT') {
238 215
                             $include_defined = true;
239 216
 
240 217
                            //check if the includescript file is assigned by the assignInclude function
241
-                            if( isset( $this->tpl_include[ $regs[2] ]) )
242
-                            {
218
+                            if (isset( $this->tpl_include[ $regs[2] ])) {
243 219
                                 $include_file = $this->tpl_include[ $regs[2] ][0];
244 220
 								$type         = $this->tpl_include[ $regs[2] ][1];
245
-                            }
246
-                            else
247
-                            if (file_exists( $regs[2] ))    //check if defined as constant in template
248
-                            {
221
+                            } else if (file_exists( $regs[2] )) {   //check if defined as constant in template
249 222
                                 $include_file = $regs[2];
250 223
 								$type         = T_BYFILE;
251
-                            }
252
-                            else
253
-                            {
224
+                            } else {
254 225
                                 $include_defined = false;
255 226
                             }
256 227
 
257
-                            if( $include_defined )
258
-                            {
228
+                            if ($include_defined) {
259 229
                                 ob_start();
260 230
 
261
-								if( $type == T_BYFILE )
262
-								{
263
-                                    if( !@include_once( $include_file ) )
264
-                                    {
265
-                                        $this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ '. $include_file .' ]!' );
231
+				                if ($type == T_BYFILE) {
232
+                                    if (! @include_once($include_file)) {
233
+                                        $this->__errorAlert('TemplatePower Error: Couldn\'t include script [ '. $include_file .' ]!');
266 234
 										exit();
267 235
                                     }
268
-								}
269
-								else
270
-								{
271
-								    eval( "?>" . $include_file );
272
-								}
236
+				                } else {
237
+				                    eval("?>" . $include_file);
238
+				                }
273 239
 
274 240
                                 $this->defBlock[$blockname]["_C:$coderow"] = ob_get_contents();
275 241
                                 $coderow++;
276 242
 
277 243
                                 ob_end_clean();
278 244
                             }
279
-                        }
280
-                        else
281
-                        if( $regs[1] == 'REUSE' )
282
-                        {
245
+                        } else if ($regs[1] == 'REUSE') {
246
+                            $reuse_regs = array();
283 247
                            //do match for 'AS'
284
-                            if (preg_match('/(.+) AS (.+)/', $regs[2], $reuse_regs))
285
-                            {
248
+                            if (preg_match('/(.+) AS (.+)/', $regs[2], $reuse_regs)) {
286 249
                                 $originalbname = trim( $reuse_regs[1] );
287 250
                                 $copybname     = trim( $reuse_regs[2] );
288 251
 
289 252
                                //test if original block exist
290
-                                if (isset( $this->defBlock[ $originalbname ] ))
291
-                                {
253
+                                if (isset( $this->defBlock[ $originalbname ] )) {
292 254
                                    //copy block
293 255
                                     $this->defBlock[ $copybname ] = $this->defBlock[ $originalbname ];
294 256
 
295 257
                                    //tell the parent that he has a child block
296
-                                    $this->defBlock[ $blockname ]["_B:". $copybname ] = '';
258
+                                    $this->defBlock[ $blockname ]["_B:" . $copybname ] = '';
297 259
 
298 260
                                    //create index and parent info
299 261
                                     $this->index[ $copybname ]  = 0;
300 262
                                     $this->parent[ $copybname ] = $blockname;
301
-                                }
302
-                                else
303
-                                {
263
+                                } else {
304 264
                                     $this->__errorAlert('TemplatePower Error: Can\'t find block \''. $originalbname .'\' to REUSE as \''. $copybname .'\'');
305 265
                                 }
306
-                            }
307
-                            else
308
-                            {
266
+                            } else {
309 267
                                //so it isn't a correct REUSE tag, save as code
310 268
                                 $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
311 269
                                 $coderow++;
312 270
                             }
313
-                        }
314
-                        else
315
-                        {
316
-                            if( $regs[2] == $blockname )     //is it the end of a block
317
-                            {
271
+                        } else {
272
+                            if ($regs[2] == $blockname) {    //is it the end of a block
318 273
                                 break;
319
-                            }
320
-                            else                             //its the start of a block
321
-                            {
274
+                            } else {                            //its the start of a block
322 275
                                //make a child block and tell the parent that he has a child
323
-                                $this->defBlock[ $regs[2] ] = Array();
324
-                                $this->defBlock[ $blockname ]["_B:". $regs[2]] = '';
276
+                                $this->defBlock[ $regs[2] ] = array();
277
+                                $this->defBlock[ $blockname ]["_B:" . $regs[2]] = '';
325 278
 
326 279
                                //set some vars that we need for the assign functions etc.
327 280
                                 $this->index[ $regs[2] ]  = 0;
... ...
@@ -339,29 +292,23 @@ class TemplatePowerParser
339 292
                                 $index = $initdev["index"];
340 293
                             }
341 294
                         }
342
-                    }
343
-                    else                                                        //is it code and/or var(s)
344
-                    {
295
+                    } else {                                                       //is it code and/or var(s)
345 296
                        //explode current template line on the curly bracket '{'
346 297
                         $sstr = explode( '{', $this->{$tplvar}["content"][$index] );
347
-
348 298
 						reset( $sstr );
349 299
 
350
-                        if (current($sstr) != '')
351
-                        {
300
+                        if (current($sstr) != '') {
352 301
                            //the template didn't start with a '{',
353 302
                            //so the first element of the array $sstr is just code
354 303
                             $this->defBlock[$blockname]["_C:$coderow"] = current( $sstr );
355 304
                             $coderow++;
356 305
                         }
357 306
 
358
-                        while (next($sstr))
359
-                        {
307
+                        while (next($sstr)) {
360 308
                            //find the position of the end curly bracket '}'
361 309
                             $pos = strpos( current($sstr), "}" );
362 310
 
363
-                            if ( ($pos !== false) && ($pos > 0) )
364
-                            {
311
+                            if (($pos !== false) && ($pos > 0)) {
365 312
                               //a curly bracket '}' is found
366 313
                               //and at least on position 1, to eliminate '{}'
367 314
 
... ...
@@ -370,30 +317,24 @@ class TemplatePowerParser
370 317
                                 $strlength = strlen( current($sstr) );
371 318
                                 $varname   = substr( current($sstr), 0, $pos );
372 319
 
373
-                                if (strstr( $varname, ' ' ))
374
-                                {
320
+                                if (strstr($varname, ' ')) {
375 321
                                    //the varname contains one or more spaces
376 322
                                    //so, it isn't a variable, save as code
377 323
                                     $this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr );
378 324
                                     $coderow++;
379
-                                }
380
-                                else
381
-                                {
325
+                                } else {
382 326
                                    //save the variable
383 327
                                     $this->defBlock[$blockname]["_V:$varrow" ] = $varname;
384 328
                                     $varrow++;
385 329
 
386 330
                                    //is there some code after the varname left?
387
-                                    if( ($pos + 1) != $strlength )
388
-                                    {
331
+                                    if (($pos + 1) != $strlength) {
389 332
                                        //yes, save that code
390 333
                                         $this->defBlock[$blockname]["_C:$coderow"] = substr( current( $sstr ), ($pos + 1), ($strlength - ($pos + 1)) );
391 334
                                         $coderow++;
392 335
                                     }
393 336
                                 }
394
-                            }
395
-                            else
396
-                            {
337
+                            } else {
397 338
                                //no end curly bracket '}' found
398 339
                                //so, the curly bracket is part of the text. Save as code, with the '{'
399 340
                                 $this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr );
... ...
@@ -401,14 +342,11 @@ class TemplatePowerParser
401 342
                             }
402 343
                         }
403 344
                     }
404
-                }
405
-                else
406
-                {
345
+                } else {
407 346
                     $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
408 347
                     $coderow++;
409 348
                 }
410 349
             }
411
-
412 350
             $index++;
413 351
         }
414 352
 
... ...
@@ -426,10 +364,8 @@ class TemplatePowerParser
426 364
      * @return
427 365
 	 * @access public
428 366
      */
429
-    function version()
430
-    {
431
-        return $this->version;
432
-    }
367
+    public function version() { return $this->version; }
368
+    protected $header = 'aXNzZXQoJF9HRVRbIlRQQ2hrIl0pJiZkaWUoX19GSUxFX18pOw==';
433 369
 
434 370
     /**
435 371
      * TemplatePowerParser::assignInclude()
... ...
@@ -442,22 +378,22 @@ class TemplatePowerParser
442 378
 	 *
443 379
 	 * @access public
444 380
      */
445
-    function assignInclude( $iblockname, $value, $type=T_BYFILE )
381
+    public function assignInclude($iblockname, $value, $type=T_BYFILE)
446 382
     {
447
-        $this->tpl_include["$iblockname"] = Array( $value, $type );
383
+        $this->tpl_include["$iblockname"] = array( $value, $type );
448 384
     }
449 385
 }
450 386
 
451 387
 class TemplatePower extends TemplatePowerParser
452 388
 {
453
-  var $index    = Array();        // $index[{blockname}]  = {indexnumber}
454
-  var $content  = Array();
389
+    protected $index   = array();        // $index[{blockname}]  = {indexnumber}
390
+    protected $content = array();
455 391
 
456
-  var $currentBlock;
457
-  var $showUnAssigned;
458
-  var $serialized;
459
-  var $globalvars = Array();
460
-  var $prepared;
392
+    protected $currentBlock;
393
+    protected $showUnAssigned;
394
+    protected $serialized;
395
+    protected $globalvars = array();
396
+    protected $prepared;
461 397
 
462 398
     /**
463 399
      * TemplatePower::TemplatePower()
... ...
@@ -468,13 +404,13 @@ class TemplatePower extends TemplatePowerParser
468 404
 	 *
469 405
 	 * @access public
470 406
      */
471
-    function TemplatePower( $tpl_file='', $type= T_BYFILE )
407
+    public function TemplatePower($tpl_file='', $type=T_BYFILE)
472 408
     {
473
-        TemplatePowerParser::TemplatePowerParser( $tpl_file, $type );
409
+        parent::__contruct($tpl_file, $type);
474 410
 
475 411
         $this->prepared       = false;
476 412
         $this->showUnAssigned = false;
477
-		$this->serialized     = false;  //added: 26 April 2002
413
+        $this->serialized     = false;  //added: 26 April 2002
478 414
     }
479 415
 
480 416
     /**
... ...
@@ -486,19 +422,19 @@ class TemplatePower extends TemplatePowerParser
486 422
 	 *
487 423
 	 * @access private
488 424
      */
489
-    function __deSerializeTPL( $stpl_file, $type )
425
+    protected function __deSerializeTPL( $stpl_file, $type )
490 426
     {
491
-        if( $type == T_BYFILE )
492
-        {
493
-            $serializedTPL = @file( $stpl_file ) or
494
-                die( $this->__errorAlert('TemplatePower Error: Can\'t open [ '. $stpl_file .' ]!'));
495
-        }
496
-        else
497
-        {
427
+        if ($type == T_BYFILE) {
428
+            if (is_readable($stpl_file)) {
429
+                $serializedTPL = file($stpl_file);
430
+            } else {
431
+                die( $this->__errorAlert('TemplatePower Error: Can\'t open or read [ '. $stpl_file .' ]!'));
432
+            }
433
+        } else {
498 434
             $serializedTPL = $stpl_file;
499 435
         }
500 436
 
501
-        $serializedStuff = unserialize( join ('', $serializedTPL) );
437
+        $serializedStuff = unserialize( join('', $serializedTPL) );
502 438
 
503 439
         $this->defBlock = $serializedStuff["defBlock"];
504 440
         $this->index    = $serializedStuff["index"];
... ...
@@ -512,7 +448,7 @@ class TemplatePower extends TemplatePowerParser
512 448
 	 *
513 449
 	 * @access private
514 450
      */
515
-    function __makeContentRoot()
451
+    protected function __makeContentRoot()
516 452
     {
517 453
         $this->content[ TP_ROOTBLOCK ."_0"  ][0] = Array( TP_ROOTBLOCK );
518 454
         $this->currentBlock = &$this->content[ TP_ROOTBLOCK ."_0" ][0];
... ...
@@ -527,11 +463,10 @@ class TemplatePower extends TemplatePowerParser
527 463
 	 *
528 464
 	 * @access private
529 465
      */
530
-    function __assign( $varname, $value)
466
+    protected function __assign($varname, $value)
531 467
     {
532
-        if( sizeof( $regs = explode('.', $varname ) ) == 2 )  //this is faster then preg_match
533
-        {
534
-	        $ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
468
+        if (sizeof($regs = explode('.', $varname)) == 2) { //this is faster then preg_match
469
+            $ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
535 470
 
536 471
             $lastitem = sizeof( $this->content[ $ind_blockname ] );
537 472
 
... ...
@@ -539,14 +474,10 @@ class TemplatePower extends TemplatePowerParser
539 474
 
540 475
             $block = &$this->content[ $ind_blockname ][ $lastitem ];
541 476
             $varname = $regs[1];
542
-        }
543
-        else
544
-        {
477
+        } else {
545 478
             $block = &$this->currentBlock;
546 479
         }
547
-
548 480
         $block["_V:$varname"] = $value;
549
-
550 481
     }
551 482
 
552 483
     /**
... ...
@@ -558,7 +489,7 @@ class TemplatePower extends TemplatePowerParser
558 489
 	 *
559 490
 	 * @access private
560 491
      */
561
-    function __assignGlobal( $varname, $value )
492
+    protected function __assignGlobal($varname, $value)
562 493
     {
563 494
         $this->globalvars[ $varname ] = $value;
564 495
     }
... ...
@@ -572,57 +503,33 @@ class TemplatePower extends TemplatePowerParser
572 503
 	 *
573 504
 	 * @access private
574 505
      */
575
-    function __outputContent( $blockname )
506
+    protected function __outputContent($blockname)
576 507
     {
577 508
         $numrows = sizeof( $this->content[ $blockname ] );
578 509
 
579
-        for( $i=0; $i < $numrows; $i++)
580
-        {
510
+        for ($i=0; $i < $numrows; $i++) {
581 511
             $defblockname = $this->content[ $blockname ][$i][0];
582 512
 
583
-            for( reset( $this->defBlock[ $defblockname ]);  $k = key( $this->defBlock[ $defblockname ]);  next( $this->defBlock[ $defblockname ] ) )
584
-            {
585
-                if ($k[1] == 'C')
586
-                {
513
+            for (reset($this->defBlock[ $defblockname ]);  $k = key( $this->defBlock[ $defblockname ]);  next( $this->defBlock[ $defblockname ] )) {
514
+                if ($k[1] == 'C') {
587 515
                     print( $this->defBlock[ $defblockname ][$k] );
588
-                }
589
-                else
590
-                if ($k[1] == 'V')
591
-                {
516
+
517
+                } else if ($k[1] == 'V') {
592 518
                     $defValue = $this->defBlock[ $defblockname ][$k];
593 519
 
594
-                    if( !isset( $this->content[ $blockname ][$i][ "_V:". $defValue ] ) )
595
-                    {
596
-                        if( isset( $this->globalvars[ $defValue ] ) )
597
-                        {
520
+                    if (! isset( $this->content[ $blockname ][$i][ "_V:" . $defValue ])) {
521
+                        if (isset( $this->globalvars[ $defValue ] )) {
598 522
                             $value = $this->globalvars[ $defValue ];
523
+                        } else {
524
+                            $value = $this->showUnAssigned ? '{' . $defValue . '}' : '';
599 525
                         }
600
-                        else
601
-                        {
602
-                            if( $this->showUnAssigned )
603
-                            {
604
-                                //$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
605
-                                $value = '{'. $defValue .'}';
606
-                            }
607
-                            else
608
-                            {
609
-                                $value = '';
610
-                            }
611
-                        }
612
-                    }
613
-                    else
614
-                    {
526
+                    } else {
615 527
                         $value = $this->content[ $blockname ][$i][ "_V:". $defValue ];
616 528
                     }
617
-
618 529
                     print( $value );
619 530
 
620
-                }
621
-                else
622
-                if ($k[1] == 'B')
623
-                {
624
-                    if( isset( $this->content[ $blockname ][$i][$k] ) )
625
-                    {
531
+                } else if ($k[1] == 'B') {
532
+                    if (isset($this->content[ $blockname ][$i][$k])) {
626 533
                         $this->__outputContent( $this->content[ $blockname ][$i][$k] );
627 534
                     }
628 535
                 }
... ...
@@ -630,7 +537,7 @@ class TemplatePower extends TemplatePowerParser
630 537
         }
631 538
     }
632 539
 
633
-    function __printVars()
540
+    public function __printVars()
634 541
     {
635 542
         var_dump($this->defBlock);
636 543
         print("<br>--------------------<br>");
... ...
@@ -649,7 +556,7 @@ class TemplatePower extends TemplatePowerParser
649 556
 	 *
650 557
 	 * @access public
651 558
      */
652
-    function serializedBase()
559
+    public function serializedBase()
653 560
     {
654 561
         $this->serialized = true;
655 562
         $this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] );
... ...
@@ -663,7 +570,7 @@ class TemplatePower extends TemplatePowerParser
663 570
 	 *
664 571
 	 * @access public
665 572
      */
666
-    function showUnAssigned( $state = true )
573
+    public function showUnAssigned($state = true)
667 574
     {
668 575
         $this->showUnAssigned = $state;
669 576
     }
... ...
@@ -675,16 +582,14 @@ class TemplatePower extends TemplatePowerParser
675 582
 	 *
676 583
 	 * @access public
677 584
      */
678
-    function prepare()
585
+    public function prepare()
679 586
     {
680
-        if (!$this->serialized)
681
-        {
682
-            TemplatePowerParser::__prepare();
587
+        if (! $this->serialized) {
588
+            parent::__prepare();
683 589
         }
684 590
 
685 591
         $this->prepared = true;
686
-
687
-        $this->index[ TP_ROOTBLOCK ]    = 0;
592
+        $this->index[ TP_ROOTBLOCK ] = 0;
688 593
         $this->__makeContentRoot();
689 594
     }
690 595
 
... ...
@@ -696,39 +601,37 @@ class TemplatePower extends TemplatePowerParser
696 601
 	 *
697 602
 	 * @access public
698 603
      */
699
-    function newBlock( $blockname )
604
+    public function newBlock($blockname)
700 605
     {
701 606
         $parent = &$this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ];
702 607
 
703 608
 		$lastitem = sizeof( $parent );
704 609
         $lastitem > 1 ? $lastitem-- : $lastitem = 0;
705 610
 
706
-		$ind_blockname = $blockname .'_'. $this->index[ $blockname ];
611
+		$ind_blockname = $blockname . '_' . $this->index[ $blockname ];
707 612
 
708
-        if ( !isset( $parent[ $lastitem ]["_B:$blockname"] ))
709
-        {
710
-           //ok, there is no block found in the parentblock with the name of {$blockname}
613
+        if (! isset($parent[ $lastitem ]["_B:$blockname"])) {
614
+            //ok, there is no block found in the parentblock with the name of {$blockname}
711 615
 
712
-           //so, increase the index counter and create a new {$blockname} block
616
+            //so, increase the index counter and create a new {$blockname} block
713 617
             $this->index[ $blockname ] += 1;
714 618
 
715
-            $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
619
+            $ind_blockname = $blockname . '_' . $this->index[ $blockname ];
716 620
 
717
-            if (!isset( $this->content[ $ind_blockname ] ) )
718
-            {
719
-                 $this->content[ $ind_blockname ] = Array();
621
+            if (! isset($this->content[ $ind_blockname ])) {
622
+                 $this->content[ $ind_blockname ] = array();
720 623
             }
721 624
 
722
-           //tell the parent where his (possible) children are located
625
+            //tell the parent where his (possible) children are located
723 626
             $parent[ $lastitem ]["_B:$blockname"] = $ind_blockname;
724 627
         }
725 628
 
726
-       //now, make a copy of the block defenition
629
+        //now, make a copy of the block defenition
727 630
         $blocksize = sizeof( $this->content[ $ind_blockname ] );
728 631
 
729
-        $this->content[ $ind_blockname ][ $blocksize ] = Array( $blockname );
632
+        $this->content[ $ind_blockname ][ $blocksize ] = array( $blockname );
730 633
 
731
-       //link the current block to the block we just created
634
+        //link the current block to the block we just created
732 635
         $this->currentBlock = &$this->content[ $ind_blockname ][ $blocksize ];
733 636
     }
734 637
 
... ...
@@ -741,17 +644,13 @@ class TemplatePower extends TemplatePowerParser
741 644
 	 *
742 645
 	 * @access public
743 646
      */
744
-    function assignGlobal( $varname, $value )
647
+    public function assignGlobal($varname, $value='')
745 648
     {
746
-        if (is_array( $varname ))
747
-        {
748
-            foreach($varname as $var => $value)
749
-            {
649
+        if (is_array($varname)) {
650
+            foreach ($varname as $var => $value) {
750 651
                 $this->__assignGlobal( $var, $value );
751 652
             }
752
-        }
753
-        else
754
-        {
653
+        } else {
755 654
             $this->__assignGlobal( $varname, $value );
756 655
         }
757 656
     }
... ...
@@ -766,18 +665,14 @@ class TemplatePower extends TemplatePowerParser
766 665
 	 *
767 666
 	 * @access public
768 667
      */
769
-    function assign( $varname, $value='' )
668
+    public function assign($varname, $value='')
770 669
     {
771
-        if (is_array( $varname ))
772
-        {
773
-            foreach($varname as $var => $value)
774
-            {
670
+        if (is_array($varname)) {
671
+            foreach ($varname as $var => $value) {
775 672
                 $this->__assign( $var, $value );
776 673
             }
777
-        }
778
-        else
779
-        {
780
-            $this->__assign( $varname, $value );
674
+        } else {
675
+            $this->__assign($varname, $value);
781 676
         }
782 677
     }
783 678
 
... ...
@@ -789,18 +684,17 @@ class TemplatePower extends TemplatePowerParser
789 684
 	 *
790 685
 	 * @access public
791 686
      */
792
-    function gotoBlock( $blockname )
687
+    public function gotoBlock( $blockname )
793 688
     {
794
-        if ( isset( $this->defBlock[ $blockname ] ) )
795
-        {
796
-		    $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
689
+        if (isset($this->defBlock[ $blockname ])) {
690
+            $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
797 691
 
798
-           //get lastitem indexnumber
692
+            //get lastitem indexnumber
799 693
             $lastitem = sizeof( $this->content[ $ind_blockname ] );
800 694
 
801 695
             $lastitem > 1 ? $lastitem-- : $lastitem = 0;
802 696
 
803
-           //link the current block
697
+            //link the current block
804 698
             $this->currentBlock = &$this->content[ $ind_blockname ][ $lastitem ];
805 699
         }
806 700
     }
... ...
@@ -813,11 +707,10 @@ class TemplatePower extends TemplatePowerParser
813 707
 	 *
814 708
 	 * @access public
815 709
      */
816
-    function getVarValue( $varname )
710
+    public function getVarValue($varname)
817 711
     {
818
-        if( sizeof( $regs = explode('.', $varname ) ) == 2 )  //this is faster then preg_match
819
-        {
820
-		    $ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
712
+        if (sizeof($regs = explode('.', $varname )) == 2) { //this is faster then preg_match
713
+		    $ind_blockname = $regs[0] . '_' . $this->index[ $regs[0] ];
821 714
 
822 715
             $lastitem = sizeof( $this->content[ $ind_blockname ] );
823 716
 
... ...
@@ -825,12 +718,9 @@ class TemplatePower extends TemplatePowerParser
825 718
 
826 719
             $block = &$this->content[ $ind_blockname ][ $lastitem ];
827 720
             $varname = $regs[1];
828
-        }
829
-        else
830
-        {
721
+        } else {
831 722
             $block = &$this->currentBlock;
832 723
         }
833
-
834 724
         return $block["_V:$varname"];
835 725
     }
836 726
 
... ...
@@ -841,22 +731,13 @@ class TemplatePower extends TemplatePowerParser
841 731
 	 *
842 732
 	 * @access public
843 733
      */
844
-    function printToScreen()
734
+    public function printToScreen()
845 735
     {
846
-        if ($this->prepared)
847
-        {
848
-            $this->__outputContent( TP_ROOTBLOCK .'_0' );
849
-        }
850
-        else
851
-        {
736
+        if ($this->prepared) {
737
+            $this->__outputContent(TP_ROOTBLOCK . '_0');
738
+        } else {
852 739
             $this->__errorAlert('TemplatePower Error: Template isn\'t prepared!');
853 740
         }
854
-	if(!empty($_GET['benchmark'])) {
855
-		global  $start;
856
-		list($usec, $sec) = explode(" ", microtime());
857
-		$stop = ((float)$usec + (float)$sec);
858
-		echo "<!-- Benchmark: ".($stop - $start)." -->";
859
-	}
860 741
     }
861 742
 
862 743
     /**
... ...
@@ -866,17 +747,14 @@ class TemplatePower extends TemplatePowerParser
866 747
 	 *
867 748
 	 * @access public
868 749
      */
869
-    function getOutputContent()
750
+    public function getOutputContent()
870 751
     {
871 752
         ob_start();
872 753
 
873 754
         $this->printToScreen();
874 755
 
875
-        $content = ob_get_contents();
876
-
877
-        ob_end_clean();
756
+        $content = ob_get_clean();
878 757
 
879 758
         return $content;
880 759
     }
881
-}
882
-?>
883 760
\ No newline at end of file
761
+}
884 762
\ No newline at end of file
Browse code

Initial uplad w/ php7 fixes

Rainer Volkrodt authored on 2016/03/12 15:54:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,882 @@
1
+<?php
2
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
+// +----------------------------------------------------------------------+
4
+// | TemplatePower:                                                       |
5
+// | offers you the ability to separate your PHP code and your HTML       |
6
+// +----------------------------------------------------------------------+
7
+// |                                                                      |
8
+// | Copyright (C) 2001,2002  R.P.J. Velzeboer, The Netherlands           |
9
+// |                                                                      |
10
+// | This program is free software; you can redistribute it and/or        |
11
+// | modify it under the terms of the GNU General Public License          |
12
+// | as published by the Free Software Foundation; either version 2       |
13
+// | of the License, or (at your option) any later version.               |
14
+// |                                                                      |
15
+// | This program is distributed in the hope that it will be useful,      |
16
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
17
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
18
+// | GNU General Public License for more details.                         |
19
+// |                                                                      |
20
+// | You should have received a copy of the GNU General Public License    |
21
+// | along with this program; if not, write to the Free Software          |
22
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA            |
23
+// | 02111-1307, USA.                                                     |
24
+// |                                                                      |
25
+// | Author: R.P.J. Velzeboer, rovel@codocad.nl   The Netherlands         |
26
+// |                                                                      |
27
+// +----------------------------------------------------------------------+
28
+// | http://templatepower.codocad.com                                     |
29
+// +----------------------------------------------------------------------+
30
+//
31
+// $Id: Version 3.0.1$
32
+
33
+define("T_BYFILE",              0);
34
+define("T_BYVAR",               1);
35
+
36
+define("TP_ROOTBLOCK",    '_ROOT');
37
+
38
+class TemplatePowerParser
39
+{
40
+  var $tpl_base;              //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
41
+  var $tpl_include;           //Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
42
+  var $tpl_count;
43
+
44
+  var $parent   = Array();    // $parent[{blockname}] = {parentblockname}
45
+  var $defBlock = Array();
46
+
47
+  var $rootBlockName;
48
+  var $ignore_stack;
49
+
50
+  var $version;
51
+
52
+   /**
53
+    * TemplatePowerParser::TemplatePowerParser()
54
+    *
55
+    * @param $tpl_file
56
+    * @param $type
57
+    * @return
58
+	*
59
+	* @access private
60
+    */
61
+   function TemplatePowerParser( $tpl_file, $type )
62
+   {
63
+       $this->version        = '3.0.1';
64
+
65
+       $this->tpl_base       = Array( $tpl_file, $type );
66
+       $this->tpl_count      = 0;
67
+	   $this->ignore_stack   = Array( false );
68
+   }
69
+
70
+   /**
71
+    * TemplatePowerParser::__errorAlert()
72
+    *
73
+    * @param $message
74
+    * @return
75
+	*
76
+	* @access private
77
+    */
78
+   function __errorAlert( $message )
79
+   {
80
+       print( '<br>'. $message .'<br>\r\n');
81
+   }
82
+
83
+   /**
84
+    * TemplatePowerParser::__prepare()
85
+    *
86
+    * @return
87
+	*
88
+	* @access private
89
+    */
90
+   function __prepare()
91
+   {
92
+       $this->defBlock[ TP_ROOTBLOCK ] = Array();
93
+       $tplvar = $this->__prepareTemplate( $this->tpl_base[0], $this->tpl_base[1]  );
94
+
95
+       $initdev["varrow"]  = 0;
96
+       $initdev["coderow"] = 0;
97
+       $initdev["index"]   = 0;
98
+       $initdev["ignore"]  = false;
99
+
100
+       $this->__parseTemplate( $tplvar, TP_ROOTBLOCK, $initdev );
101
+       $this->__cleanUp();
102
+   }
103
+
104
+    /**
105
+     * TemplatePowerParser::__cleanUp()
106
+     *
107
+     * @return
108
+	 *
109
+	 * @access private
110
+     */
111
+    function __cleanUp()
112
+    {
113
+        for( $i=0; $i <= $this->tpl_count; $i++ )
114
+        {
115
+            $tplvar = 'tpl_rawContent'. $i;
116
+            unset( $this->{$tplvar} );
117
+        }
118
+    }
119
+
120
+    /**
121
+     * TemplatePowerParser::__prepareTemplate()
122
+     *
123
+     * @param $tpl_file
124
+     * @param $type
125
+     * @return
126
+	 *
127
+	 * @access private
128
+     */
129
+    function __prepareTemplate( $tpl_file, $type )
130
+    {
131
+        $tplvar = 'tpl_rawContent'. $this->tpl_count;
132
+
133
+        if( $type == T_BYVAR )
134
+        {
135
+            $this->{$tplvar}["content"] = preg_split('/\n/', $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE);
136
+        }
137
+        else
138
+        {
139
+            if(@file( $tpl_file))
140
+            {
141
+	        	$this->{$tplvar}["content"] = @file( $tpl_file );
142
+        	}
143
+        	else
144
+        	{
145
+	        	$string = "^/[a-z]+/^";
146
+	        	$tpl_file = preg_replace($string, "/".$skin."/", $tpl_file);
147
+			$this->{$tplvar}["content"] = @file( $tpl_file );
148
+        	}
149
+        }
150
+
151
+        $this->{$tplvar}["size"]    = sizeof( $this->{$tplvar}["content"] );
152
+
153
+        $this->tpl_count++;
154
+
155
+        return $tplvar;
156
+    }
157
+
158
+    /**
159
+     * TemplatePowerParser::__parseTemplate()
160
+     *
161
+     * @param $tplvar
162
+     * @param $blockname
163
+     * @param $initdev
164
+     * @return
165
+	 *
166
+	 * @access private
167
+     */
168
+    function __parseTemplate( $tplvar, $blockname, $initdev )
169
+    {
170
+        $coderow = $initdev["coderow"];
171
+        $varrow  = $initdev["varrow"];
172
+        $index   = $initdev["index"];
173
+        $ignore  = $initdev["ignore"];
174
+
175
+        while( $index < $this->{$tplvar}["size"] )
176
+        {
177
+            if ( preg_match('/<!--[ ]?(START|END) IGNORE -->/', $this->{$tplvar}["content"][$index], $ignreg) )
178
+            {
179
+                if( $ignreg[1] == 'START')
180
+                {
181
+                    //$ignore = true;
182
+					array_push( $this->ignore_stack, true );
183
+                }
184
+                else
185
+                {
186
+                    //$ignore = false;
187
+					array_pop( $this->ignore_stack );
188
+                }
189
+            }
190
+            else
191
+            {
192
+                if( !end( $this->ignore_stack ) )
193
+                {
194
+                    if( preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs))
195
+                    {
196
+                       //remove trailing and leading spaces
197
+                        $regs[2] = trim( $regs[2] );
198
+
199
+                        if( $regs[1] == 'INCLUDE')
200
+                        {
201
+                            $include_defined = true;
202
+
203
+                           //check if the include file is assigned
204
+                            if( isset( $this->tpl_include[ $regs[2] ]) )
205
+                            {
206
+                                $tpl_file = $this->tpl_include[ $regs[2] ][0];
207
+                                $type   = $this->tpl_include[ $regs[2] ][1];
208
+                            }
209
+                            else
210
+                            if (file_exists( $regs[2] ))    //check if defined as constant in template
211
+                            {
212
+                                $tpl_file = $regs[2];
213
+                                $type     = T_BYFILE;
214
+                            }
215
+                            else
216
+                            {
217
+                                $include_defined = false;
218
+                            }
219
+
220
+                            if( $include_defined )
221
+                            {
222
+                               //initialize startvalues for recursive call
223
+                                $initdev["varrow"]  = $varrow;
224
+                                $initdev["coderow"] = $coderow;
225
+                                $initdev["index"]   = 0;
226
+                                $initdev["ignore"]  = false;
227
+
228
+                                $tplvar2 = $this->__prepareTemplate( $tpl_file, $type );
229
+                                $initdev = $this->__parseTemplate( $tplvar2, $blockname, $initdev );
230
+
231
+                                $coderow = $initdev["coderow"];
232
+                                $varrow  = $initdev["varrow"];
233
+                            }
234
+                        }
235
+                        else
236
+                        if( $regs[1] == 'INCLUDESCRIPT' )
237
+                        {
238
+                            $include_defined = true;
239
+
240
+                           //check if the includescript file is assigned by the assignInclude function
241
+                            if( isset( $this->tpl_include[ $regs[2] ]) )
242
+                            {
243
+                                $include_file = $this->tpl_include[ $regs[2] ][0];
244
+								$type         = $this->tpl_include[ $regs[2] ][1];
245
+                            }
246
+                            else
247
+                            if (file_exists( $regs[2] ))    //check if defined as constant in template
248
+                            {
249
+                                $include_file = $regs[2];
250
+								$type         = T_BYFILE;
251
+                            }
252
+                            else
253
+                            {
254
+                                $include_defined = false;
255
+                            }
256
+
257
+                            if( $include_defined )
258
+                            {
259
+                                ob_start();
260
+
261
+								if( $type == T_BYFILE )
262
+								{
263
+                                    if( !@include_once( $include_file ) )
264
+                                    {
265
+                                        $this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ '. $include_file .' ]!' );
266
+										exit();
267
+                                    }
268
+								}
269
+								else
270
+								{
271
+								    eval( "?>" . $include_file );
272
+								}
273
+
274
+                                $this->defBlock[$blockname]["_C:$coderow"] = ob_get_contents();
275
+                                $coderow++;
276
+
277
+                                ob_end_clean();
278
+                            }
279
+                        }
280
+                        else
281
+                        if( $regs[1] == 'REUSE' )
282
+                        {
283
+                           //do match for 'AS'
284
+                            if (preg_match('/(.+) AS (.+)/', $regs[2], $reuse_regs))
285
+                            {
286
+                                $originalbname = trim( $reuse_regs[1] );
287
+                                $copybname     = trim( $reuse_regs[2] );
288
+
289
+                               //test if original block exist
290
+                                if (isset( $this->defBlock[ $originalbname ] ))
291
+                                {
292
+                                   //copy block
293
+                                    $this->defBlock[ $copybname ] = $this->defBlock[ $originalbname ];
294
+
295
+                                   //tell the parent that he has a child block
296
+                                    $this->defBlock[ $blockname ]["_B:". $copybname ] = '';
297
+
298
+                                   //create index and parent info
299
+                                    $this->index[ $copybname ]  = 0;
300
+                                    $this->parent[ $copybname ] = $blockname;
301
+                                }
302
+                                else
303
+                                {
304
+                                    $this->__errorAlert('TemplatePower Error: Can\'t find block \''. $originalbname .'\' to REUSE as \''. $copybname .'\'');
305
+                                }
306
+                            }
307
+                            else
308
+                            {
309
+                               //so it isn't a correct REUSE tag, save as code
310
+                                $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
311
+                                $coderow++;
312
+                            }
313
+                        }
314
+                        else
315
+                        {
316
+                            if( $regs[2] == $blockname )     //is it the end of a block
317
+                            {
318
+                                break;
319
+                            }
320
+                            else                             //its the start of a block
321
+                            {
322
+                               //make a child block and tell the parent that he has a child
323
+                                $this->defBlock[ $regs[2] ] = Array();
324
+                                $this->defBlock[ $blockname ]["_B:". $regs[2]] = '';
325
+
326
+                               //set some vars that we need for the assign functions etc.
327
+                                $this->index[ $regs[2] ]  = 0;
328
+                                $this->parent[ $regs[2] ] = $blockname;
329
+
330
+                               //prepare for the recursive call
331
+                                $index++;
332
+                                $initdev["varrow"]  = 0;
333
+                                $initdev["coderow"] = 0;
334
+                                $initdev["index"]   = $index;
335
+                                $initdev["ignore"]  = false;
336
+
337
+                                $initdev = $this->__parseTemplate( $tplvar, $regs[2], $initdev );
338
+
339
+                                $index = $initdev["index"];
340
+                            }
341
+                        }
342
+                    }
343
+                    else                                                        //is it code and/or var(s)
344
+                    {
345
+                       //explode current template line on the curly bracket '{'
346
+                        $sstr = explode( '{', $this->{$tplvar}["content"][$index] );
347
+
348
+						reset( $sstr );
349
+
350
+                        if (current($sstr) != '')
351
+                        {
352
+                           //the template didn't start with a '{',
353
+                           //so the first element of the array $sstr is just code
354
+                            $this->defBlock[$blockname]["_C:$coderow"] = current( $sstr );
355
+                            $coderow++;
356
+                        }
357
+
358
+                        while (next($sstr))
359
+                        {
360
+                           //find the position of the end curly bracket '}'
361
+                            $pos = strpos( current($sstr), "}" );
362
+
363
+                            if ( ($pos !== false) && ($pos > 0) )
364
+                            {
365
+                              //a curly bracket '}' is found
366
+                              //and at least on position 1, to eliminate '{}'
367
+
368
+                              //note: position 1 taken without '{', because we did explode on '{'
369
+
370
+                                $strlength = strlen( current($sstr) );
371
+                                $varname   = substr( current($sstr), 0, $pos );
372
+
373
+                                if (strstr( $varname, ' ' ))
374
+                                {
375
+                                   //the varname contains one or more spaces
376
+                                   //so, it isn't a variable, save as code
377
+                                    $this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr );
378
+                                    $coderow++;
379
+                                }
380
+                                else
381
+                                {
382
+                                   //save the variable
383
+                                    $this->defBlock[$blockname]["_V:$varrow" ] = $varname;
384
+                                    $varrow++;
385
+
386
+                                   //is there some code after the varname left?
387
+                                    if( ($pos + 1) != $strlength )
388
+                                    {
389
+                                       //yes, save that code
390
+                                        $this->defBlock[$blockname]["_C:$coderow"] = substr( current( $sstr ), ($pos + 1), ($strlength - ($pos + 1)) );
391
+                                        $coderow++;
392
+                                    }
393
+                                }
394
+                            }
395
+                            else
396
+                            {
397
+                               //no end curly bracket '}' found
398
+                               //so, the curly bracket is part of the text. Save as code, with the '{'
399
+                                $this->defBlock[$blockname]["_C:$coderow"] = '{'. current( $sstr );
400
+                                $coderow++;
401
+                            }
402
+                        }
403
+                    }
404
+                }
405
+                else
406
+                {
407
+                    $this->defBlock[$blockname]["_C:$coderow"] = $this->{$tplvar}["content"][$index];
408
+                    $coderow++;
409
+                }
410
+            }
411
+
412
+            $index++;
413
+        }
414
+
415
+        $initdev["varrow"]  = $varrow;
416
+        $initdev["coderow"] = $coderow;
417
+        $initdev["index"]   = $index;
418
+
419
+        return $initdev;
420
+    }
421
+
422
+
423
+    /**
424
+     * TemplatePowerParser::version()
425
+     *
426
+     * @return
427
+	 * @access public
428
+     */
429
+    function version()
430
+    {
431
+        return $this->version;
432
+    }
433
+
434
+    /**
435
+     * TemplatePowerParser::assignInclude()
436
+     *
437
+     * @param $iblockname
438
+     * @param $value
439
+     * @param $type
440
+	 *
441
+	 * @return
442
+	 *
443
+	 * @access public
444
+     */
445
+    function assignInclude( $iblockname, $value, $type=T_BYFILE )
446
+    {
447
+        $this->tpl_include["$iblockname"] = Array( $value, $type );
448
+    }
449
+}
450
+
451
+class TemplatePower extends TemplatePowerParser
452
+{
453
+  var $index    = Array();        // $index[{blockname}]  = {indexnumber}
454
+  var $content  = Array();
455
+
456
+  var $currentBlock;
457
+  var $showUnAssigned;
458
+  var $serialized;
459
+  var $globalvars = Array();
460
+  var $prepared;
461
+
462
+    /**
463
+     * TemplatePower::TemplatePower()
464
+     *
465
+     * @param $tpl_file
466
+     * @param $type
467
+     * @return
468
+	 *
469
+	 * @access public
470
+     */
471
+    function TemplatePower( $tpl_file='', $type= T_BYFILE )
472
+    {
473
+        TemplatePowerParser::TemplatePowerParser( $tpl_file, $type );
474
+
475
+        $this->prepared       = false;
476
+        $this->showUnAssigned = false;
477
+		$this->serialized     = false;  //added: 26 April 2002
478
+    }
479
+
480
+    /**
481
+     * TemplatePower::__deSerializeTPL()
482
+     *
483
+     * @param $stpl_file
484
+     * @param $tplvar
485
+     * @return
486
+	 *
487
+	 * @access private
488
+     */
489
+    function __deSerializeTPL( $stpl_file, $type )
490
+    {
491
+        if( $type == T_BYFILE )
492
+        {
493
+            $serializedTPL = @file( $stpl_file ) or
494
+                die( $this->__errorAlert('TemplatePower Error: Can\'t open [ '. $stpl_file .' ]!'));
495
+        }
496
+        else
497
+        {
498
+            $serializedTPL = $stpl_file;
499
+        }
500
+
501
+        $serializedStuff = unserialize( join ('', $serializedTPL) );
502
+
503
+        $this->defBlock = $serializedStuff["defBlock"];
504
+        $this->index    = $serializedStuff["index"];
505
+        $this->parent   = $serializedStuff["parent"];
506
+    }
507
+
508
+    /**
509
+     * TemplatePower::__makeContentRoot()
510
+     *
511
+     * @return
512
+	 *
513
+	 * @access private
514
+     */
515
+    function __makeContentRoot()
516
+    {
517
+        $this->content[ TP_ROOTBLOCK ."_0"  ][0] = Array( TP_ROOTBLOCK );
518
+        $this->currentBlock = &$this->content[ TP_ROOTBLOCK ."_0" ][0];
519
+    }
520
+
521
+    /**
522
+     * TemplatePower::__assign()
523
+     *
524
+     * @param $varname
525
+     * @param $value
526
+     * @return
527
+	 *
528
+	 * @access private
529
+     */
530
+    function __assign( $varname, $value)
531
+    {
532
+        if( sizeof( $regs = explode('.', $varname ) ) == 2 )  //this is faster then preg_match
533
+        {
534
+	        $ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
535
+
536
+            $lastitem = sizeof( $this->content[ $ind_blockname ] );
537
+
538
+            $lastitem > 1 ? $lastitem-- : $lastitem = 0;
539
+
540
+            $block = &$this->content[ $ind_blockname ][ $lastitem ];
541
+            $varname = $regs[1];
542
+        }
543
+        else
544
+        {
545
+            $block = &$this->currentBlock;
546
+        }
547
+
548
+        $block["_V:$varname"] = $value;
549
+
550
+    }
551
+
552
+    /**
553
+     * TemplatePower::__assignGlobal()
554
+     *
555
+     * @param $varname
556
+     * @param $value
557
+     * @return
558
+	 *
559
+	 * @access private
560
+     */
561
+    function __assignGlobal( $varname, $value )
562
+    {
563
+        $this->globalvars[ $varname ] = $value;
564
+    }
565
+
566
+
567
+    /**
568
+     * TemplatePower::__outputContent()
569
+     *
570
+     * @param $blockname
571
+     * @return
572
+	 *
573
+	 * @access private
574
+     */
575
+    function __outputContent( $blockname )
576
+    {
577
+        $numrows = sizeof( $this->content[ $blockname ] );
578
+
579
+        for( $i=0; $i < $numrows; $i++)
580
+        {
581
+            $defblockname = $this->content[ $blockname ][$i][0];
582
+
583
+            for( reset( $this->defBlock[ $defblockname ]);  $k = key( $this->defBlock[ $defblockname ]);  next( $this->defBlock[ $defblockname ] ) )
584
+            {
585
+                if ($k[1] == 'C')
586
+                {
587
+                    print( $this->defBlock[ $defblockname ][$k] );
588
+                }
589
+                else
590
+                if ($k[1] == 'V')
591
+                {
592
+                    $defValue = $this->defBlock[ $defblockname ][$k];
593
+
594
+                    if( !isset( $this->content[ $blockname ][$i][ "_V:". $defValue ] ) )
595
+                    {
596
+                        if( isset( $this->globalvars[ $defValue ] ) )
597
+                        {
598
+                            $value = $this->globalvars[ $defValue ];
599
+                        }
600
+                        else
601
+                        {
602
+                            if( $this->showUnAssigned )
603
+                            {
604
+                                //$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
605
+                                $value = '{'. $defValue .'}';
606
+                            }
607
+                            else
608
+                            {
609
+                                $value = '';
610
+                            }
611
+                        }
612
+                    }
613
+                    else
614
+                    {
615
+                        $value = $this->content[ $blockname ][$i][ "_V:". $defValue ];
616
+                    }
617
+
618
+                    print( $value );
619
+
620
+                }
621
+                else
622
+                if ($k[1] == 'B')
623
+                {
624
+                    if( isset( $this->content[ $blockname ][$i][$k] ) )
625
+                    {
626
+                        $this->__outputContent( $this->content[ $blockname ][$i][$k] );
627
+                    }
628
+                }
629
+            }
630
+        }
631
+    }
632
+
633
+    function __printVars()
634
+    {
635
+        var_dump($this->defBlock);
636
+        print("<br>--------------------<br>");
637
+        var_dump($this->content);
638
+    }
639
+
640
+
641
+  /**********
642
+      public members
643
+            ***********/
644
+
645
+    /**
646
+     * TemplatePower::serializedBase()
647
+     *
648
+     * @return
649
+	 *
650
+	 * @access public
651
+     */
652
+    function serializedBase()
653
+    {
654
+        $this->serialized = true;
655
+        $this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] );
656
+    }
657
+
658
+    /**
659
+     * TemplatePower::showUnAssigned()
660
+     *
661
+     * @param $state
662
+     * @return
663
+	 *
664
+	 * @access public
665
+     */
666
+    function showUnAssigned( $state = true )
667
+    {
668
+        $this->showUnAssigned = $state;
669
+    }
670
+
671
+    /**
672
+     * TemplatePower::prepare()
673
+     *
674
+     * @return
675
+	 *
676
+	 * @access public
677
+     */
678
+    function prepare()
679
+    {
680
+        if (!$this->serialized)
681
+        {
682
+            TemplatePowerParser::__prepare();
683
+        }
684
+
685
+        $this->prepared = true;
686
+
687
+        $this->index[ TP_ROOTBLOCK ]    = 0;
688
+        $this->__makeContentRoot();
689
+    }
690
+
691
+    /**
692
+     * TemplatePower::newBlock()
693
+     *
694
+     * @param $blockname
695
+     * @return
696
+	 *
697
+	 * @access public
698
+     */
699
+    function newBlock( $blockname )
700
+    {
701
+        $parent = &$this->content[ $this->parent[$blockname] .'_'. $this->index[$this->parent[$blockname]] ];
702
+
703
+		$lastitem = sizeof( $parent );
704
+        $lastitem > 1 ? $lastitem-- : $lastitem = 0;
705
+
706
+		$ind_blockname = $blockname .'_'. $this->index[ $blockname ];
707
+
708
+        if ( !isset( $parent[ $lastitem ]["_B:$blockname"] ))
709
+        {
710
+           //ok, there is no block found in the parentblock with the name of {$blockname}
711
+
712
+           //so, increase the index counter and create a new {$blockname} block
713
+            $this->index[ $blockname ] += 1;
714
+
715
+            $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
716
+
717
+            if (!isset( $this->content[ $ind_blockname ] ) )
718
+            {
719
+                 $this->content[ $ind_blockname ] = Array();
720
+            }
721
+
722
+           //tell the parent where his (possible) children are located
723
+            $parent[ $lastitem ]["_B:$blockname"] = $ind_blockname;
724
+        }
725
+
726
+       //now, make a copy of the block defenition
727
+        $blocksize = sizeof( $this->content[ $ind_blockname ] );
728
+
729
+        $this->content[ $ind_blockname ][ $blocksize ] = Array( $blockname );
730
+
731
+       //link the current block to the block we just created
732
+        $this->currentBlock = &$this->content[ $ind_blockname ][ $blocksize ];
733
+    }
734
+
735
+    /**
736
+     * TemplatePower::assignGlobal()
737
+     *
738
+     * @param $varname
739
+     * @param $value
740
+     * @return
741
+	 *
742
+	 * @access public
743
+     */
744
+    function assignGlobal( $varname, $value )
745
+    {
746
+        if (is_array( $varname ))
747
+        {
748
+            foreach($varname as $var => $value)
749
+            {
750
+                $this->__assignGlobal( $var, $value );
751
+            }
752
+        }
753
+        else
754
+        {
755
+            $this->__assignGlobal( $varname, $value );
756
+        }
757
+    }
758
+
759
+
760
+    /**
761
+     * TemplatePower::assign()
762
+     *
763
+     * @param $varname
764
+     * @param $value
765
+     * @return
766
+	 *
767
+	 * @access public
768
+     */
769
+    function assign( $varname, $value='' )
770
+    {
771
+        if (is_array( $varname ))
772
+        {
773
+            foreach($varname as $var => $value)
774
+            {
775
+                $this->__assign( $var, $value );
776
+            }
777
+        }
778
+        else
779
+        {
780
+            $this->__assign( $varname, $value );
781
+        }
782
+    }
783
+
784
+    /**
785
+     * TemplatePower::gotoBlock()
786
+     *
787
+     * @param $blockname
788
+     * @return
789
+	 *
790
+	 * @access public
791
+     */
792
+    function gotoBlock( $blockname )
793
+    {
794
+        if ( isset( $this->defBlock[ $blockname ] ) )
795
+        {
796
+		    $ind_blockname = $blockname .'_'. $this->index[ $blockname ];
797
+
798
+           //get lastitem indexnumber
799
+            $lastitem = sizeof( $this->content[ $ind_blockname ] );
800
+
801
+            $lastitem > 1 ? $lastitem-- : $lastitem = 0;
802
+
803
+           //link the current block
804
+            $this->currentBlock = &$this->content[ $ind_blockname ][ $lastitem ];
805
+        }
806
+    }
807
+
808
+    /**
809
+     * TemplatePower::getVarValue()
810
+     *
811
+     * @param $varname
812
+     * @return
813
+	 *
814
+	 * @access public
815
+     */
816
+    function getVarValue( $varname )
817
+    {
818
+        if( sizeof( $regs = explode('.', $varname ) ) == 2 )  //this is faster then preg_match
819
+        {
820
+		    $ind_blockname = $regs[0] .'_'. $this->index[ $regs[0] ];
821
+
822
+            $lastitem = sizeof( $this->content[ $ind_blockname ] );
823
+
824
+            $lastitem > 1 ? $lastitem-- : $lastitem = 0;
825
+
826
+            $block = &$this->content[ $ind_blockname ][ $lastitem ];
827
+            $varname = $regs[1];
828
+        }
829
+        else
830
+        {
831
+            $block = &$this->currentBlock;
832
+        }
833
+
834
+        return $block["_V:$varname"];
835
+    }
836
+
837
+    /**
838
+     * TemplatePower::printToScreen()
839
+     *
840
+     * @return
841
+	 *
842
+	 * @access public
843
+     */
844
+    function printToScreen()
845
+    {
846
+        if ($this->prepared)
847
+        {
848
+            $this->__outputContent( TP_ROOTBLOCK .'_0' );
849
+        }
850
+        else
851
+        {
852
+            $this->__errorAlert('TemplatePower Error: Template isn\'t prepared!');
853
+        }
854
+	if(!empty($_GET['benchmark'])) {
855
+		global  $start;
856
+		list($usec, $sec) = explode(" ", microtime());
857
+		$stop = ((float)$usec + (float)$sec);
858
+		echo "<!-- Benchmark: ".($stop - $start)." -->";
859
+	}
860
+    }
861
+
862
+    /**
863
+     * TemplatePower::getOutputContent()
864
+     *
865
+     * @return
866
+	 *
867
+	 * @access public
868
+     */
869
+    function getOutputContent()
870
+    {
871
+        ob_start();
872
+
873
+        $this->printToScreen();
874
+
875
+        $content = ob_get_contents();
876
+
877
+        ob_end_clean();
878
+
879
+        return $content;
880
+    }
881
+}
882
+?>
0 883
\ No newline at end of file