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