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: * View property setter.
118: * @param object $oView
119: */
120: public function setView($oView) {
121: if (is_object($oView)) {
122: $this->_oView = $oView;
123: }
124: }
125:
126: /**
127: * View property getter.
128: * @return object
129: */
130: public function getView() {
131: return $this->_oView;
132: }
133:
134: /**
135: * Property setter.
136: * @param string $key
137: * @param mixed $value
138: */
139: public function setProperty($key, $value) {
140: $this->_properties[$key] = $value;
141: }
142:
143: /**
144: * Property getter.
145: * @param string $key
146: * @param mixed $default
147: * @return mixed
148: */
149: public function getProperty($key, $default = NULL) {
150: return (isset($this->_properties[$key])) ? $this->_properties[$key] : $default;
151: }
152:
153: /**
154: * Template setter.
155: * @param string $sTemplate Either full path and name of template file or a template string.
156: */
157: public function setTemplate($sTemplate) {
158: $this->_template = $sTemplate;
159: }
160:
161: /**
162: * Template getter.
163: * @return string
164: */
165: public function getTemplate() {
166: return $this->_template;
167: }
168:
169: /**
170: * Renders template by replacing all view variables in template.
171: * @param string $template Either full path and name of template file or a template string.
172: * If not passed, previous set template will be used.
173: * @throws cException if no template is set
174: * @return string
175: */
176: public function render($template = NULL) {
177: if ($template == NULL) {
178: $template = $this->_template;
179: }
180:
181: if ($template == NULL) {
182: throw new cException('Missing template to render.');
183: }
184:
185: $oTpl = new cTemplate();
186: foreach ($this->_oView as $k => $v) {
187: $oTpl->set('s', cString::toUpperCase($k), $v);
188: }
189: $oTpl->generate($template, 0, 0);
190: }
191:
192: /**
193: * Returns parameter from request, the order is:
194: * - Return from $_GET, if found
195: * - Return from $_POST, if found
196: *
197: * @param string $key
198: * @param mixed $default The default value
199: * @return mixed
200: */
201: protected function _getParam($key, $default = NULL) {
202: if (isset($_GET[$key])) {
203: return $_GET[$key];
204: } elseif (isset($_POST[$key])) {
205: return $_POST[$key];
206: } else {
207: return $default;
208: }
209: }
210:
211: /**
212: * Returns rendered notification markup by using global $notification variable.
213: * @param string $type One of cGuiNotification::LEVEL_* constants
214: * @param string $msg The message to display
215: * @return string
216: */
217: protected function _notifyBox($type, $msg) {
218: global $notification;
219: return $notification->returnNotification($type, $msg) . '<br>';
220: }
221:
222: }
223: