XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ActionFrame.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7define('USER_FRAME_PERFORM_SUCCESS', 1);
8define('USER_FRAME_PERFORM_FAIL', 2);
9define('USER_FRAME_INIT_SUCCESS', 3);
10
11define('USER_FRAME_VIEW_NONE', 1);
12define('USER_FRAME_VIEW_SUCCESS', 2);
13define('USER_FRAME_VIEW_ERROR', 3);
14define('USER_FRAME_VIEW_INDEX', 4);
15define('USER_FRAME_VIEW_INPUT', 5);
16define('USER_FRAME_VIEW_PREVIEW', 6);
17define('USER_FRAME_VIEW_CANCEL', 7);
18
20{
21 public $mActionName = null;
22 public $mAction = null;
23 public $mAdminFlag = null;
24
28 public $mCreateAction = null;
29
30// public function User_ActionFrame($admin)
31// {
32// self::__construct($admin);
33// }
34
35 public function __construct($admin)
36 {
37 $this->mAdminFlag = $admin;
38 $this->mCreateAction = new XCube_Delegate();
39 $this->mCreateAction->register('User_ActionFrame.CreateAction');
40 $this->mCreateAction->add([&$this, '_createAction']);
41 }
42
43 public function setActionName($name)
44 {
45 $this->mActionName = $name;
46
47 //
48 // Temp FIXME!
49 //
50 $root = &XCube_Root::getSingleton();
51 $root->mContext->setAttribute('actionName', $name);
52 $root->mContext->mModule->setAttribute('actionName', $name);
53 }
54
55 public function _createAction(&$actionFrame)
56 {
57 if (is_object($this->mAction)) {
58 return;
59 }
60
61 //
62 // Create action object by mActionName
63 //
64 $className = 'User_' . ucfirst($actionFrame->mActionName) . 'Action';
65 $fileName = ucfirst($actionFrame->mActionName) . 'Action';
66 if ($actionFrame->mAdminFlag) {
67 $fileName = XOOPS_MODULE_PATH . "/user/admin/actions/{$fileName}.class.php";
68 } else {
69 $fileName = XOOPS_MODULE_PATH . "/user/actions/{$fileName}.class.php";
70 }
71
72 if (!file_exists($fileName)) {
73 die();
74 }
75
76 require_once $fileName;
77
78 if (XC_CLASS_EXISTS($className)) {
79 $actionFrame->mAction = new $className($actionFrame->mAdminFlag);
80 }
81 }
82
83 public function execute(&$controller)
84 {
85 if (!preg_match("/^\w+$/", $this->mActionName)) {
86 die();
87 }
88
89 //
90 // Create action object by mActionName
91 //
92 $this->mCreateAction->call(new XCube_Ref($this));
93
94 if (!(is_object($this->mAction) && $this->mAction instanceof \User_Action)) {
95 die(); //< TODO
96 }
97
98 if ($this->mAction->isSecure() && !is_object($controller->mRoot->mContext->mXoopsUser)) {
99 //
100 // error
101 //
102
103 $controller->executeForward(XOOPS_URL . '/');
104 }
105
106 $this->mAction->prepare($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModuleConfig);
107
108 if (!$this->mAction->hasPermission($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModuleConfig)) {
109 //
110 // error
111 //
112
113 $controller->executeForward(XOOPS_URL . '/');
114 }
115
116 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
117 $viewStatus = $this->mAction->execute($controller, $controller->mRoot->mContext->mXoopsUser);
118 } else {
119 $viewStatus = $this->mAction->getDefaultView($controller, $controller->mRoot->mContext->mXoopsUser);
120 }
121
122 $render = $controller->mRoot->mContext->mModule->getRenderTarget();
123 $render->setAttribute('xoops_pagetitle', $this->mAction->getPagetitle());
124
125 switch ($viewStatus) {
126 case USER_FRAME_VIEW_SUCCESS:
127 $this->mAction->executeViewSuccess($controller, $controller->mRoot->mContext->mXoopsUser, $render);
128 break;
129
130 case USER_FRAME_VIEW_ERROR:
131 $this->mAction->executeViewError($controller, $controller->mRoot->mContext->mXoopsUser, $render);
132 break;
133
134 case USER_FRAME_VIEW_INDEX:
135 $this->mAction->executeViewIndex($controller, $controller->mRoot->mContext->mXoopsUser, $render);
136 break;
137
138 case USER_FRAME_VIEW_INPUT:
139 $this->mAction->executeViewInput($controller, $controller->mRoot->mContext->mXoopsUser, $render);
140 break;
141
142 case USER_FRAME_VIEW_PREVIEW:
143 $this->mAction->executeViewPreview($controller, $controller->mRoot->mContext->mXoopsUser, $render);
144 break;
145
146 case USER_FRAME_VIEW_CANCEL:
147 $this->mAction->executeViewCancel($controller, $controller->mRoot->mContext->mXoopsUser, $render);
148 break;
149 }
150 }
151}
152
153class User_Action
154{
155 public function User_Action()
156 {
157 self::__construct();
158 }
159
160 public function __construct()
161 { }
162
163 public function isSecure()
164 {
165 return false;
166 }
167
175 protected function _getPageAction()
176 {
177 return null;
178 }
179
187 protected function _getPagetitle()
188 {
189 return null;
190 }
191
192 public function getPageTitle()
193 {
194 return Legacy_Utils::formatPagetitle(XCube_Root::getSingleton()->mContext->mModule->mXoopsModule->get('name'), $this->_getPagetitle(), $this->_getPageAction());
195 }
196
197 public function hasPermission(&$controller, &$xoopsUser, $moduleConfig)
198 {
199 return true;
200 }
201
202 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
203 { }
204
205 public function getDefaultView(&$controller, &$xoopsUser)
206 {
207 return USER_FRAME_VIEW_NONE;
208 }
209
210 public function execute(&$controller, &$xoopsUser)
211 {
212 return USER_FRAME_VIEW_NONE;
213 }
214
215 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
216 { }
217
218 public function executeViewError(&$controller, &$xoopsUser, &$render)
219 { }
220
221 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
222 { }
223
224 public function executeViewInput(&$controller, &$xoopsUser, &$render)
225 { }
226
227 public function executeViewPreview(&$controller, &$xoopsUser, &$render)
228 { }
229//@todo @gigamaster
230 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
231 { return USER_FRAME_VIEW_CANCEL; }
232}
static formatPagetitle( $modulename, $pagetitle, $action)
[Final] Used for the simple mechanism for common delegation in XCube.