1: <?php
2: /*************************************************************************************/
3: /* */
4: /* Thelia */
5: /* */
6: /* Copyright (c) OpenStudio */
7: /* email : info@thelia.net */
8: /* web : http://www.thelia.net */
9: /* */
10: /* This program is free software; you can redistribute it and/or modify */
11: /* it under the terms of the GNU General Public License as published by */
12: /* the Free Software Foundation; either version 3 of the License */
13: /* */
14: /* This program is distributed in the hope that it will be useful, */
15: /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16: /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17: /* GNU General Public License for more details. */
18: /* */
19: /* You should have received a copy of the GNU General Public License */
20: /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
21: /* */
22: /*************************************************************************************/
23:
24: namespace Thelia\Tpex\Element;
25:
26: use Thelia\Tpex\Element;
27:
28: abstract class BaseElement
29: {
30:
31: public $content;
32:
33: /**
34: *
35: *
36: *
37: * @param mixed $content
38: * @return mixed
39: */
40: abstract public function addContent($content);
41: abstract public function exec($substitutions = array());
42:
43: /**
44: *
45: * type must return the code of this element.
46: *
47: * ex : return Thelia\Tpex\TpexToken::TpexText
48: *
49: * @return int
50: */
51: abstract public function type();
52:
53: /**
54: *
55: * try to replace substitution contained by $substitution into $text.
56: *
57: * It's here where #GET #SET are executed.
58: *
59: * @param $substitution array containing the substitution to replace in $text ex : array("#SUB1" =>
60: * "substitution");
61: * @param $text the text to analyse and where substitution must be replace
62: * @return string
63: */
64: public function replace($substitution, $text)
65: {
66: if(trim($text) == '') return $text;
67:
68: $text = str_replace(array_keys($substitution), array_values($substitution), $text);
69: // Traiter les variables de template s'il y en a
70: if (
71: strpos($text, '#SET') !== false ||
72: strpos($text, '#GET') !== false ||
73: strpos($text, '#ENV') !== false ||
74: strpos($text, '#SESSION') !== false ||
75: strpos($text, '#FILTER_') !== false
76: )
77: {
78: $text = VariablesTemplate::analyser($text);
79: }
80:
81: return $text;
82: }
83: }
84: