8 if(!defined('XOOPS_ROOT_PATH'))
13 require_once SD2ND_TRUST_PATH . '/class/AbstractAction.class.php';
15 define('SD2ND_FRAME_PERFORM_SUCCESS', 1);
16 define('SD2ND_FRAME_PERFORM_FAIL', 2);
17 define('SD2ND_FRAME_INIT_SUCCESS', 3);
19 define('SD2ND_FRAME_VIEW_NONE','none');
20 define('SD2ND_FRAME_VIEW_SUCCESS','success');
21 define('SD2ND_FRAME_VIEW_ERROR','error');
22 define('SD2ND_FRAME_VIEW_INDEX','index');
23 define('SD2ND_FRAME_VIEW_INPUT','input');
24 define('SD2ND_FRAME_VIEW_PREVIEW','preview');
25 define('SD2ND_FRAME_VIEW_CANCEL','cancel');
30 class Sd2nd_Module extends Legacy_ModuleAdapter
35 public $mActionName = null;
38 * @brief Sd2nd_AbstractAction
40 public $mAction = null;
45 public $mAdminFlag = false;
48 * @brief Sd2nd_AssetManager
50 public $mAssetManager = null;
55 protected $_mPreferenceEditUrl = null;
60 protected $_mHelpViewUrl = null;
65 protected $_mAllowViewNames = array(
66 SD2ND_FRAME_VIEW_NONE,
67 SD2ND_FRAME_VIEW_SUCCESS,
68 SD2ND_FRAME_VIEW_ERROR,
69 SD2ND_FRAME_VIEW_INDEX,
70 SD2ND_FRAME_VIEW_INPUT,
71 SD2ND_FRAME_VIEW_PREVIEW,
72 SD2ND_FRAME_VIEW_CANCEL
82 public function startup()
86 XCube_DelegateUtils::call('Module.sd2nd.Global.Event.GetAssetManager',new XCube_Ref($this->mAssetManager),$this->mXoopsModule->get('dirname'));
88 $root =& XCube_Root::getSingleton();
89 $root->mController->mExecute->add(array(&$this, 'execute'));
92 // TODO/Insert your initialization code.
103 public function setAdminMode(/*** bool ***/ $flag)
105 $this->mAdminFlag = $flag;
109 * _getDefaultActionName
115 private function _getDefaultActionName()
117 // TODO insert your default action name
124 * @param string $name
128 public function setActionName(/*** string ***/ $name)
130 $this->mActionName = $name;
134 * getRenderSystemName
140 public function getRenderSystemName()
142 if(!$this->mAdminFlag)
144 return parent::getRenderSystemName();
147 // TODO will be use site config
148 if(!defined('SD2ND_ADMIN_RENDER_REGISTED'))
150 define('SD2ND_ADMIN_RENDER_REGISTED',true);
151 $root =& XCube_Root::getSingleton();
152 $root->overrideSiteConfig(
154 'RenderSystems' => array(
155 'Sd2nd_AdminRenderSystem' => 'Sd2nd_AdminRenderSystem'
157 'Sd2nd_AdminRenderSystem' => array(
158 'root' => SD2ND_TRUST_PATH,
159 'path' => '/admin/class/Sd2ndAdminRenderSystem.class.php',
160 'class' => 'Sd2nd_AdminRenderSystem'
166 return 'Sd2nd_AdminRenderSystem';
174 * @return {string 'title',string 'link',string 'keywords',bool 'show',bool 'absolute'}[]
176 public function getAdminMenu()
178 if(is_array($this->mAdminMenu))
180 return $this->mAdminMenu;
183 $root =& XCube_Root::getSingleton();
186 $adminMenu = $this->mXoopsModule->getInfo('adminmenu');
187 if(!is_array($adminMenu))
189 $adminMenu = array();
192 // add preference menu
193 if($url = $this->getPreferenceEditUrl())
195 $adminMenu[] = array(
196 'title' => _PREFERENCES,
203 if($url = $this->getHelpViewUrl())
205 $adminMenu[] = array(
212 $this->mAdminMenu = array();
213 foreach($adminMenu as $menu)
215 if(!(isset($menu['absolute']) && $menu['absolute']))
217 $menu['link'] = XOOPS_MODULE_URL . '/' . $this->mXoopsModule->get('dirname') . '/' . $menu['link'];
219 $this->mAdminMenu[] = $menu;
222 return $this->mAdminMenu;
226 * getPreferenceEditUrl
232 public function getPreferenceEditUrl()
234 if($this->_mPreferenceEditUrl === null)
236 if(is_array($this->mXoopsModule->getInfo('config')) && count($this->mXoopsModule->getInfo('config')) > 0)
238 $root =& XCube_Root::getSingleton();
239 $this->_mPreferenceEditUrl = $root->mController->getPreferenceEditUrl($this->mXoopsModule);
243 $this->_mPreferenceEditUrl = false;
247 return $this->_mPreferenceEditUrl;
257 public function getHelpViewUrl()
259 if($this->_mHelpViewUrl === null)
261 if($this->mXoopsModule->hasHelp())
263 $root =& XCube_Root::getSingleton();
264 $this->_mHelpViewUrl = $root->mController->getHelpViewUrl($this->mXoopsModule);
268 $this->_mHelpViewUrl = false;
272 return $this->_mHelpViewUrl;
278 * @param XCube_Controller &$controller
282 public function execute(/*** XCube_Controller ***/ &$controller)
284 if($this->_createAction() === false)
286 $this->doActionNotFoundError();
290 if($this->mAction->prepare() === false)
292 $this->doPreparationError();
296 if($this->mAction->hasPermission() === false)
298 $this->doPermissionError();
302 $viewStatus = (Sd2nd_Utils::getEnv('REQUEST_METHOD') == 'POST') ?
303 $this->mAction->execute() :
304 $this->mAction->getDefaultView();
306 if(in_array($viewStatus,$this->_mAllowViewNames))
308 $methodName = 'executeView' . ucfirst($viewStatus);
309 if(is_callable(array($this->mAction,$methodName)))
311 $this->mAction->$methodName($this->getRenderTarget());
323 private function _createAction()
325 $root =& XCube_Root::getSingleton();
327 if($this->mActionName == null)
329 $this->mActionName = $root->mContext->mRequest->getRequest('action');
330 if($this->mActionName == null)
332 $this->mActionName = $this->_getDefaultActionName();
336 if(!ctype_alnum($this->mActionName))
341 $fileName = ($this->mAdminFlag ? '/admin' : '')
342 . '/actions/' . ucfirst($this->mActionName) . 'Action.class.php';
346 $path = XOOPS_MODULE_PATH . '/' . $this->mXoopsModule->get('dirname') . $fileName
350 $path = SD2ND_TRUST_PATH . '/' . $fileName
359 $className = 'Sd2nd_' . ($this->mAdminFlag ? 'Admin_' : '')
360 . ucfirst($this->mActionName) . 'Action';
361 if(class_exists($className))
363 $this->mAction =& new $className();
365 if(!$this->mAction instanceof Sd2nd_AbstractAction)
374 * doActionNotFoundError
380 private function doActionNotFoundError()
383 * Module.sd2nd.Global.Event.Exception.ActionNotFound
385 * @param string $dirname
389 XCube_DelegateUtils::call('Module.sd2nd.Global.Event.Exception.ActionNotFound',$this->mAssetManager->mDirname);
391 * Module.{dirname}.Event.Exception.ActionNotFound
397 XCube_DelegateUtils::call('Module.' . $this->mXoopsModule->get('dirname') . '.Event.Exception.ActionNotFound');
398 $root =& XCube_Root::getSingleton();
399 $root->mController->executeForward(XOOPS_URL);
409 private function doPreparationError()
412 * Module.sd2nd.Global.Event.Exception.Preparation
414 * @param string $dirname
418 XCube_DelegateUtils::call('Module.sd2nd.Global.Event.Exception.Preparation',$this->mAssetManager->mDirname);
420 * Module.{dirname}.Event.Exception.Preparation
426 XCube_DelegateUtils::call('Module.' . $this->mXoopsModule->get('dirname') . '.Event.Exception.Preparation');
427 $root =& XCube_Root::getSingleton();
428 $root->mController->executeForward(XOOPS_URL);
438 private function doPermissionError()
441 * Module.sd2nd.Global.Event.Exception.Permission
443 * @param string $dirname
447 XCube_DelegateUtils::call('Module.sd2nd.Global.Event.Exception.Permission',$this->mAssetManager->mDirname);
449 * Module.{dirname}.Event.Exception.Permission
455 XCube_DelegateUtils::call('Module.' . $this->mXoopsModule->get('dirname') . '.Event.Exception.Permission');
456 $root =& XCube_Root::getSingleton();
457 $root->mController->executeForward(XOOPS_URL);