XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ActionFrame.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16const LEGACY_FRAME_PERFORM_SUCCESS = 1;
17const LEGACY_FRAME_PERFORM_FAIL = 2;
18const LEGACY_FRAME_INIT_SUCCESS = 3;
19
20const LEGACY_FRAME_VIEW_NONE = 1;
21const LEGACY_FRAME_VIEW_SUCCESS = 2;
22const LEGACY_FRAME_VIEW_ERROR = 3;
23const LEGACY_FRAME_VIEW_INDEX = 4;
24const LEGACY_FRAME_VIEW_INPUT = 5;
25const LEGACY_FRAME_VIEW_PREVIEW = 6;
26const LEGACY_FRAME_VIEW_CANCEL = 7;
27//
28// Constants for the mode of the frame.
29//
30const LEGACY_FRAME_MODE_MISC = 'Misc';
31const LEGACY_FRAME_MODE_NOTIFY = 'Notify';
32const LEGACY_FRAME_MODE_IMAGE = 'Image';
33const LEGACY_FRAME_MODE_SEARCH = 'Search';
34
35
36class Legacy_ActionFrame
37{
38 public $mActionName = null;
39 public $mAction = null;
40 public $mAdminFlag = null;
41
48 public $mMode = null;
49
53 public $mCreateAction = null;
54
55 public function Legacy_ActionFrame($admin)
56 {
57 self::__construct($admin);
58 }
59
60 public function __construct($admin)
61 {
62 $this->mAdminFlag = $admin;
63 $this->mCreateAction =new XCube_Delegate();
64 $this->mCreateAction->register('Legacy_ActionFrame.CreateAction');
65 $this->mCreateAction->add([&$this, '_createAction']);
66 }
67
68 public function setActionName($name)
69 {
70 $this->mActionName = $name;
71
72 //
73 // Temp FIXME!
74 //
75 $root =& XCube_Root::getSingleton();
76 $root->mContext->setAttribute('actionName', $name);
77 $root->mContext->mModule->setAttribute('actionName', $name);
78 }
79
85 public function setMode($mode)
86 {
87 $this->mMode = $mode;
88 }
89
90 public function _createAction(&$actionFrame)
91 {
92 if (is_object($actionFrame->mAction)) {
93 return;
94 }
95
96 //
97 // Create action object by mActionName
98 //
99 $className = 'Legacy_' . ucfirst($actionFrame->mActionName) . 'Action';
100 $fileName = ucfirst($actionFrame->mActionName) . 'Action';
101 if ($actionFrame->mAdminFlag) {
102 $fileName = XOOPS_MODULE_PATH . "/legacy/admin/actions/{$fileName}.class.php";
103 } else {
104 $fileName = XOOPS_MODULE_PATH . "/legacy/actions/{$fileName}.class.php";
105 }
106
107 if (!file_exists($fileName)) {
108 die();
109 }
110
111 require_once $fileName;
112
113 if (XC_CLASS_EXISTS($className)) {
114 $actionFrame->mAction =new $className($actionFrame->mAdminFlag);
115 }
116 }
117
118 public function execute(&$controller)
119 {
120 if (strlen($this->mActionName) > 0 && !preg_match("/^\w+$/", $this->mActionName)) {
121 die();
122 }
123
124 //
125 // Actions of the public side in this module are hook type. So it's
126 // necessary to load catalog here.
127 //
128 if (!$this->mAdminFlag) {
129 $controller->mRoot->mLanguageManager->loadModuleMessageCatalog('legacy');
130 }
131
132 //
133 // Add mode.
134 //
135 $this->setActionName($this->mMode . $this->mActionName);
136
137 //
138 // Create action object by mActionName
139 //
140 $this->mCreateAction->call(new XCube_Ref($this));
141
142 if (!(is_object($this->mAction) && $this->mAction instanceof \Legacy_Action)) {
143 die(); //< TODO
144 }
145
146 if ($this->mAction->prepare($controller, $controller->mRoot->mContext->mXoopsUser) === false) {
147 die(); //< TODO
148 }
149
150 if (!$this->mAction->hasPermission($controller, $controller->mRoot->mContext->mXoopsUser)) {
151 if ($this->mAdminFlag) {
152 $controller->executeForward(XOOPS_URL . '/admin.php');
153 } else {
154 $controller->executeForward(XOOPS_URL);
155 }
156 }
157
158 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
159 $viewStatus = $this->mAction->execute($controller, $controller->mRoot->mContext->mXoopsUser);
160 } else {
161 $viewStatus = $this->mAction->getDefaultView($controller, $controller->mRoot->mContext->mXoopsUser);
162 }
163
164 switch ($viewStatus) {
165 case LEGACY_FRAME_VIEW_SUCCESS:
166 $this->mAction->executeViewSuccess($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
167 break;
168
169 case LEGACY_FRAME_VIEW_ERROR:
170 $this->mAction->executeViewError($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
171 break;
172
173 case LEGACY_FRAME_VIEW_INDEX:
174 $this->mAction->executeViewIndex($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
175 break;
176
177 case LEGACY_FRAME_VIEW_INPUT:
178 $this->mAction->executeViewInput($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
179 break;
180
181 case LEGACY_FRAME_VIEW_PREVIEW:
182 $this->mAction->executeViewPreview($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
183 break;
184
185 case LEGACY_FRAME_VIEW_CANCEL:
186 $this->mAction->executeViewCancel($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
187 break;
188 }
189 }
190}
191
192
193class Legacy_Action
194{
198 public $_mAdminFlag = false;
199
200 public function Legacy_Action($adminFlag = false)
201 {
202 self::__construct($adminFlag);
203 }
204
205 public function __construct($adminFlag = false)
206 {
207 $this->_mAdminFlag = $adminFlag;
208 }
209
210 public function hasPermission(&$controller, &$xoopsUser)
211 {
212 if ($this->_mAdminFlag) {
213 return $controller->mRoot->mContext->mUser->isInRole('Module.legacy.Admin');
214 } else {
215 //
216 // TODO Really?
217 //
218 return true;
219 }
220 }
221
222 public function prepare(&$controller, &$xoopsUser)
223 {
224 }
225
226 public function getDefaultView(&$controller, &$xoopsUser)
227 {
228 return LEGACY_FRAME_VIEW_NONE;
229 }
230
231 public function execute(&$controller, &$xoopsUser)
232 {
233 return LEGACY_FRAME_VIEW_NONE;
234 }
235
236 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
237 {
238 }
239
240 public function executeViewError(&$controller, &$xoopsUser, &$render)
241 {
242 }
243
244 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
245 {
246 }
247
248 public function executeViewInput(&$controller, &$xoopsUser, &$render)
249 {
250 }
251
252 public function executeViewPreview(&$controller, &$xoopsUser, &$render)
253 {
254 }
255
256 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
257 {
258 }
259}
[Final] Used for the simple mechanism for common delegation in XCube.