1: <?php
2: /**
3: * AMR abstract controller class
4: *
5: * @package Plugin
6: * @subpackage ModRewrite
7: * @version SVN Revision $Rev:$
8: * @id $Id: class.modrewrite_controller_abstract.php 6077 2013-12-07 23:40:41Z dominik.ziegler $:
9: * @author Murat Purc <murat@purc.de>
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Abstract controller for all concrete mod_rewrite controller implementations.
20: *
21: * @author Murat Purc <murat@purc.de>
22: * @package Plugin
23: * @subpackage ModRewrite
24: */
25: abstract class ModRewrite_ControllerAbstract {
26:
27: /**
28: * View object, holds all view variables
29: * @var stdClass
30: */
31: protected $_oView;
32:
33: /**
34: * Global CONTENIDO $cfg variable
35: * @var array
36: */
37: protected $_cfg;
38:
39: /**
40: * Global CONTENIDO $client variable (client id)
41: * @var int
42: */
43: protected $_client;
44:
45: /**
46: * Global CONTENIDO $area variable (area name/id)
47: * @var int|string
48: */
49: protected $_area;
50:
51: /**
52: * Global CONTENIDO $action variable (send by request)
53: * @var string
54: */
55: protected $_action;
56:
57: /**
58: * Global CONTENIDO $frame variable (current frame in backend)
59: * @var int
60: */
61: protected $_frame;
62:
63: /**
64: * Global CONTENIDO $contenido variable (session id)
65: * @var string
66: */
67: protected $_contenido;
68:
69: /**
70: * Template file or template string to render
71: * @var string
72: */
73: protected $_template = NULL;
74:
75: /**
76: * Additional properties list
77: * @var array
78: */
79: protected $_properties = array();
80:
81: /**
82: * Debug flag
83: * @var bool
84: */
85: protected $_debug = false;
86:
87: /**
88: * Constructor, sets some properties by assigning global variables to them.
89: */
90: public function __construct() {
91: global $cfg, $client, $area, $action, $frame, $contenido, $sess;
92:
93: $this->_oView = new stdClass();
94: $this->_cfg = $cfg;
95: $this->_area = $area;
96: $this->_action = $action;
97: $this->_frame = $frame;
98: $this->_client = $client;
99: $this->_contenido = $contenido;
100:
101: $this->_oView->area = $this->_area;
102: $this->_oView->frame = $this->_frame;
103: $this->_oView->contenido = $this->_contenido;
104: $this->_oView->sessid = $sess->id;
105: $this->_oView->lng_more_informations = i18n('More informations', 'mod_rewrite');
106:
107: $this->init();
108: }
109:
110: /**
111: * Initializer method, could be overwritten by childs.
112: * This method will be invoked in constructor of ModRewrite_ControllerAbstract.
113: */
114: public function init() {
115:
116: }
117:
118: /**
119: * View property setter.
120: * @param object $oView
121: */
122: public function setView($oView) {
123: if (is_object($oView)) {
124: $this->_oView = $oView;
125: }
126: }
127:
128: /**
129: * View property getter.
130: * @return object
131: */
132: public function getView() {
133: return $this->_oView;
134: }
135:
136: /**
137: * Property setter.
138: * @param string $key
139: * @param mixed $value
140: */
141: public function setProperty($key, $value) {
142: $this->_properties[$key] = $value;
143: }
144:
145: /**
146: * Property getter.
147: * @param string $key
148: * @param mixed $default
149: * @return mixed
150: */
151: public function getProperty($key, $default = NULL) {
152: return (isset($this->_properties[$key])) ? $this->_properties[$key] : $default;
153: }
154:
155: /**
156: * Template setter.
157: * @param string $sTemplate Either full path and name of template file or a template string.
158: */
159: public function setTemplate($sTemplate) {
160: $this->_template = $sTemplate;
161: }
162:
163: /**
164: * Template getter.
165: * @return string
166: */
167: public function getTemplate() {
168: return $this->_template;
169: }
170:
171: /**
172: * Renders template by replacing all view variables in template.
173: * @param string $template Either full path and name of template file or a template string.
174: * If not passed, previous set template will be used.
175: * @throws cException if no template is set
176: * @return string
177: */
178: public function render($template = NULL) {
179: if ($template == NULL) {
180: $template = $this->_template;
181: }
182:
183: if ($template == NULL) {
184: throw new cException('Missing template to render.');
185: }
186:
187: $oTpl = new cTemplate();
188: foreach ($this->_oView as $k => $v) {
189: $oTpl->set('s', strtoupper($k), $v);
190: }
191: $oTpl->generate($template, 0, 0);
192: }
193:
194: /**
195: * Returns parameter from request, the order is:
196: * - Return from $_GET, if found
197: * - Return from $_POST, if found
198: *
199: * @param string $key
200: * @param mixed $default The default value
201: * @return mixed
202: */
203: protected function _getParam($key, $default = NULL) {
204: if (isset($_GET[$key])) {
205: return $_GET[$key];
206: } elseif (isset($_POST[$key])) {
207: return $_POST[$key];
208: } else {
209: return $default;
210: }
211: }
212:
213: /**
214: * Returns rendered notification markup by using global $notification variable.
215: * @param string $type One of cGuiNotification::LEVEL_* constants
216: * @param string $msg The message to display
217: * @return string
218: */
219: protected function _notifyBox($type, $msg) {
220: global $notification;
221: return $notification->returnNotification($type, $msg) . '<br>';
222: }
223:
224: }
225: