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
16/*
17define ("PROFILE_FRAME_PERFORM_SUCCESS", 1);
18define ("PROFILE_FRAME_PERFORM_FAIL", 2);
19define ("PROFILE_FRAME_INIT_SUCCESS", 3);
20
21define ("PROFILE_FRAME_VIEW_NONE", 1);
22define ("PROFILE_FRAME_VIEW_SUCCESS", 2);
23define ("PROFILE_FRAME_VIEW_ERROR", 3);
24define ("PROFILE_FRAME_VIEW_INDEX", 4);
25define ("PROFILE_FRAME_VIEW_INPUT", 5);
26define ("PROFILE_FRAME_VIEW_PREVIEW", 6);
27define ("PROFILE_FRAME_VIEW_CANCEL", 7);
28*/
29
31{
32 public $mActionName = null;
33 public $mAction = null;
34 public $mAdminFlag = null;
35
39 public $mCreateAction = null;
40
41 public function __construct($admin)
42 {
43 $this->mAdminFlag = $admin;
44 $this->mCreateAction =new XCube_Delegate();
45 $this->mCreateAction->register('Profile_ActionFrame.CreateAction');
46 $this->mCreateAction->add([&$this, '_createAction']);
47 }
48
49 public function setActionName($name)
50 {
51 $this->mActionName = $name;
52
53 //
54 // Temp FIXME!
55 //
56 $root =& XCube_Root::getSingleton();
57 $root->mContext->setAttribute('actionName', $name);
58 $root->mContext->mModule->setAttribute('actionName', $name);
59 }
60
61 public function _createAction(&$actionFrame)
62 {
63 if (is_object($this->mAction)) {
64 return;
65 }
66
67 //
68 // Create action object by mActionName
69 //
70 $className = 'Profile_' . ucfirst($actionFrame->mActionName) . 'Action';
71 $fileName = ucfirst($actionFrame->mActionName) . 'Action';
72 if ($actionFrame->mAdminFlag) {
73 $fileName = XOOPS_MODULE_PATH . "/profile/admin/actions/{$fileName}.class.php";
74 } else {
75 $fileName = XOOPS_MODULE_PATH . "/profile/actions/{$fileName}.class.php";
76 }
77
78 if (!file_exists($fileName)) {
79 die('file_exists on _createAction');
80 }
81
82 require_once $fileName;
83
84 if (XC_CLASS_EXISTS($className)) {
85 $actionFrame->mAction =new $className($actionFrame->mAdminFlag);
86 }
87 }
88
89 public function execute(&$controller)
90 {
91 if (!preg_match("/^\w+$/", $this->mActionName)) {
92 die();
93 }
94
95 //
96 // Create action object by mActionName
97 //
98 $this->mCreateAction->call(new XCube_Ref($this));
99
100 if (!(is_object($this->mAction) && $this->mAction instanceof \Profile_Action)) {
101 die(); //< TODO
102 }
103
104 if ($this->mAction->isSecure() && !is_object($controller->mRoot->mContext->mXoopsUser)) {
105 //
106 // TODO error redirect
107 //
108
109 $controller->executeForward(XOOPS_URL . '/');
110 }
111
112 $this->mAction->prepare($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModuleConfig);
113
114 if (!$this->mAction->hasPermission($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModuleConfig)) {
115 //
116 // TODO error redirect
117 //
118
119 $controller->executeForward(XOOPS_URL . '/');
120 }
121
122 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
123 $viewStatus = $this->mAction->execute($controller, $controller->mRoot->mContext->mXoopsUser);
124 } else {
125 $viewStatus = $this->mAction->getDefaultView($controller, $controller->mRoot->mContext->mXoopsUser);
126 }
127
128 $render = $controller->mRoot->mContext->mModule->getRenderTarget();
129 $render->setAttribute('xoops_pagetitle', $this->mAction->getPagetitle());
130 echo($viewStatus);
131 die;
132 switch ($viewStatus) {
133 case PROFILE_FRAME_VIEW_SUCCESS:
134 $this->mAction->executeViewSuccess($render);
135 break;
136
137 case PROFILE_FRAME_VIEW_ERROR:
138 $this->mAction->executeViewError($controller);
139 break;
140
141 case PROFILE_FRAME_VIEW_INDEX:
142 $this->mAction->executeViewIndex($controller, $controller->mRoot->mContext->mXoopsUser, $render);
143 break;
144
145 case PROFILE_FRAME_VIEW_INPUT:
146 $this->mAction->executeViewInput($controller);
147 break;
148
149 case PROFILE_FRAME_VIEW_PREVIEW:
150 $this->mAction->executeViewPreview($controller);
151 break;
152
153 case PROFILE_FRAME_VIEW_CANCEL:
154 $this->mAction->executeViewCancel($controller);
155 break;
156 }
157 }
158}
159
161{
162 public function __construct()
163 {
164 }
165
166 public function isSecure()
167 {
168 return false;
169 }
170
178 protected function _getPageAction()
179 {
180 return null;
181 }
182
190 protected function _getPagetitle()
191 {
192 return null;
193 }
194
195 public function getPageTitle()
196 {
197 return Legacy_Utils::formatPagetitle(XCube_Root::getSingleton()->mContext->mModule->mXoopsModule->get('name'), $this->_getPagetitle(), $this->_getPageAction());
198 }
199
200 public function hasPermission(&$controller, &$xoopsUser, $moduleConfig)
201 {
202 return true;
203 }
204
205 public function prepare(&$controller, &$xoopsUser, &$moduleConfig)
206 {
207 }
208
209 public function getDefaultView(&$controller, &$xoopsUser)
210 {
211 return PROFILE_FRAME_VIEW_NONE;
212 }
213
214 public function execute(&$controller, &$xoopsUser)
215 {
216 return PROFILE_FRAME_VIEW_NONE;
217 }
218
219 public function executeViewSuccess(&$render)
220 {
221 }
222
223 public function executeViewError(&$render)
224 {
225 }
226
227 public function executeViewInde(&$render)
228 {
229 }
230
231 public function executeViewInput(&$render)
232 {
233 }
234
235 public function executeViewPreview(&$render)
236 {
237 }
238
239 public function executeViewCancel(&$render)
240 {
241 }
242}
static formatPagetitle( $modulename, $pagetitle, $action)
[Final] Used for the simple mechanism for common delegation in XCube.