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