1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xmf\Template;
13: use Xoops\Core\XoopsTpl;
14:
15: /**
16: * AbstractTemplate
17: *
18: * @category Xmf\Template\AbstractTemplate
19: * @package Xmf
20: * @author trabis <lusopoemas@gmail.com>
21: * @author The SmartFactory <www.smartfactory.ca>
22: * @copyright 2011-2013 XOOPS Project (http://xoops.org)
23: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24: * @version Release: 1.0
25: * @link http://xoops.org
26: * @since 1.0
27: */
28: abstract class AbstractTemplate
29: {
30: /**
31: * @var XoopsTpl
32: */
33: protected $tpl;
34:
35: /**
36: * @var string
37: */
38: private $template;
39:
40: /**
41: * Constructor
42: */
43: public function __construct()
44: {
45: $this->tpl = new XoopsTpl();
46: $this->template = "module:system/system_dummy.tpl";
47: $this->init();
48: }
49:
50: /**
51: * Classes must implement this method instead of using constructors
52: *
53: * @return void
54: */
55: abstract protected function init();
56:
57: /**
58: * Classes must implement this method for assigning content to $tpl
59: *
60: * @return void
61: */
62: abstract protected function render();
63:
64: /**
65: * Used in init methods to set the template used by $tpl
66: *
67: * @param string $template Path to the template file
68: *
69: * @return void
70: */
71: protected function setTemplate($template = '')
72: {
73: $this->template = $template;
74: }
75:
76: /**
77: * Use this method to disable XoopsLogger
78: *
79: * @return void
80: */
81: protected function disableLogger()
82: {
83: \Xoops::getInstance()->logger()->quiet();
84: }
85:
86: /**
87: * Returns the rendered template
88: *
89: * @return bool|mixed|string
90: */
91: public function fetch()
92: {
93: $this->render();
94:
95: return $this->tpl->fetch($this->template);
96: }
97:
98: /**
99: * Echo/Display the rendered template
100: *
101: * @return void
102: */
103: public function display()
104: {
105: echo $this->fetch();
106: }
107: }
108: