XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Module.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/profile/class/AbstractAction.class.php';
17
18define('PROFILE_FRAME_PERFORM_SUCCESS', 1);
19define('PROFILE_FRAME_PERFORM_FAIL', 2);
20define('PROFILE_FRAME_INIT_SUCCESS', 3);
21
22define('PROFILE_FRAME_VIEW_NONE', 'none');
23define('PROFILE_FRAME_VIEW_SUCCESS', 'success');
24define('PROFILE_FRAME_VIEW_ERROR', 'error');
25define('PROFILE_FRAME_VIEW_INDEX', 'index');
26define('PROFILE_FRAME_VIEW_INPUT', 'input');
27define('PROFILE_FRAME_VIEW_PREVIEW', 'preview');
28define('PROFILE_FRAME_VIEW_CANCEL', 'cancel');
29
31{
32 public $mActionName = null;
33 public $mAction = null;
34 public $mAdminFlag = false;
35 public $mAssetManager = null;
36
40 public function startup()
41 {
42 parent::startup();
43
44 XCube_DelegateUtils::call('Module.profile.Event.GetAssetManager', new XCube_Ref($this->mAssetManager));
45
46 $root =& XCube_Root::getSingleton();
47 $root->mController->mExecute->add([&$this, 'execute']);
48
49 //
50 // TODO/Insert your initialization code.
51 //
52 }
53
58 public function setAdminMode($flag)
59 {
60 $this->mAdminFlag = $flag;
61 }
62
67 public function setActionName($name)
68 {
69 $this->mActionName = $name;
70 }
71
76 public function execute(&$controller)
77 {
78 if (null == $this->mActionName) {
79 $this->mActionName = xoops_getrequest('action');
80 if (null == $this->mActionName) {
81 $this->mActionName = 'DataEdit';
82 }
83 }
84
85 if (!preg_match("/^\w+$/", $this->mActionName)) {
86 $this->doActionNotFoundError();
87 die();
88 }
89
90 //
91 // Create action object by mActionName
92 //
93 $fileName = ucfirst($this->mActionName) . 'Action';
94 if ($this->mAdminFlag) {
95 $className = 'Profile_Admin_' . ucfirst($this->mActionName) . 'Action';
96 $fileName = XOOPS_MODULE_PATH . "/profile/admin/actions/{$fileName}.class.php";
97 } else {
98 $className = 'Profile_' . ucfirst($this->mActionName) . 'Action';
99 $fileName = XOOPS_MODULE_PATH . "/profile/actions/{$fileName}.class.php";
100 }
101
102 if (!file_exists($fileName)) {
103 $this->doActionNotFoundError();
104 die();
105 }
106
107 require_once $fileName;
108
109 if (class_exists($className)) {
110 $this->mAction =new $className();
111 }
112
113 if (!is_object($this->mAction)) {
114 $this->doActionNotFoundError();
115 die();
116 }
117
118 if ($this->mAction->isMemberOnly() && !$controller->mRoot->mContext->mUser->isInRole('Site.RegisteredUser')) {
119 $this->doPermissionError();
120 die();
121 }
122
123 if ($this->mAction->isAdminOnly() && !$controller->mRoot->mContext->mUser->isInRole('Module.profile.Admin')) {
124 $this->doPermissionError();
125 die();
126 }
127
128 if (false === $this->mAction->prepare()) {
129 $this->doPreparationError();
130 die();
131 }
132
133 if (!$this->mAction->hasPermission()) {
134 $this->doPermissionError();
135 die();
136 }
137
138 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
139 $viewStatus = $this->mAction->execute();
140 } else {
141 $viewStatus = $this->mAction->getDefaultView();
142 }
143
144 switch ($viewStatus) {
145 case PROFILE_FRAME_VIEW_SUCCESS:
146 $this->mAction->executeViewSuccess($controller, $controller->mRoot->mContext->mModule->getRenderTarget());
147 break;
148 case PROFILE_FRAME_VIEW_ERROR:
149 $this->mAction->executeViewError($controller->mRoot->mContext->mModule->getRenderTarget());
150 break;
151 case PROFILE_FRAME_VIEW_INDEX:
152 $this->mAction->executeViewIndex($controller->mRoot->mContext->mModule->getRenderTarget());
153 break;
154 case PROFILE_FRAME_VIEW_INPUT:
155 $this->mAction->executeViewInput($controller->mRoot->mContext->mModule->getRenderTarget());
156 break;
157 case PROFILE_FRAME_VIEW_PREVIEW:
158 $this->mAction->executeViewPreview($controller->mRoot->mContext->mModule->getRenderTarget());
159 break;
160 case PROFILE_FRAME_VIEW_CANCEL:
161 $this->mAction->executeViewCancel($controller->mRoot->mContext->mModule->getRenderTarget());
162 break;
163 }
164 }
165
169 public function doPermissionError()
170 {
171 XCube_DelegateUtils::call('Module.Profile.Event.Exception.Permission');
172 $root =& XCube_Root::getSingleton();
173 $root->mController->executeForward(XOOPS_URL);
174 return;
175 }
176
180 public function doActionNotFoundError()
181 {
182 XCube_DelegateUtils::call('Module.Profile.Event.Exception.ActionNotFound');
183 $root =& XCube_Root::getSingleton();
184 $root->mController->executeForward(XOOPS_URL);
185 return;
186 }
187
191 public function doPreparationError()
192 {
193 XCube_DelegateUtils::call('Module.Profile.Event.Exception.Preparation');
194 $root =& XCube_Root::getSingleton();
195 $root->mController->executeForward(XOOPS_URL);
196 return;
197 }
198}
Used for adapting $xoopsModule to imitate XOOPS2 responses.
execute(&$controller)
startup()
[Abstract] This method is called by the controller strategy, if this module is the current module.