XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ThemeSelect.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
22{
26 public $mIsSelectableTheme = null;
27
28 public function __construct(&$controller)
29 {
30 //
31 // TODO remove
32 //
33 parent::__construct($controller);
34 $this->mIsSelectableTheme =new XCube_Delegate();
35 $this->mIsSelectableTheme->register('Legacy_ThemeSelect.IsSelectableTheme');
36
37 $controller->mSetupUser->add([&$this, 'doChangeTheme']);
38 }
39
40 public function preBlockFilter()
41 {
42 $this->mController->mRoot->mDelegateManager->add('Site.CheckLogin.Success', [&$this, 'callbackCheckLoginSuccess']);
43 }
44
53 public function doChangeTheme(&$principal, &$controller, &$context)
54 {
55 if (!empty($_POST['xoops_theme_select'])) {
56 $xoops_theme_select = explode('!-!', $_POST['xoops_theme_select']);
57 if ($this->_isSelectableTheme($xoops_theme_select[0])) {
58 $this->mRoot->mContext->setThemeName($xoops_theme_select[0]);
59 $_SESSION['xoopsUserTheme'] = $xoops_theme_select[0];
60 $controller->executeForward($GLOBALS['xoopsRequestUri']);
61 }
62 } elseif (!empty($_SESSION['xoopsUserTheme']) && $this->_isSelectableTheme($_SESSION['xoopsUserTheme'])) {
63 $this->mRoot->mContext->setThemeName($_SESSION['xoopsUserTheme']);
64 }
65 }
66
67 public function callbackCheckLoginSuccess(&$xoopsUser)
68 {
69 //
70 // Check Theme and set it to session.
71 //
72 $userTheme = $xoopsUser->get('theme');
73 if (in_array($userTheme, $this->mRoot->mContext->getXoopsConfig('theme_set_allowed'), true)) {
74 $_SESSION['xoopsUserTheme'] = $userTheme;
75 $this->mRoot->mContext->setThemeName($userTheme);
76 }
77 }
78
79 public function _isSelectableTheme($theme_name)
80 {
81 return in_array($theme_name, $this->mRoot->mContext->getXoopsConfig('theme_set_allowed'), true);
82 }
83}
preBlockFilter()
[Abstract] Executes the logic, when the controller executes preBlockFilter().
__construct(&$controller)
Constructor.
doChangeTheme(&$principal, &$controller, &$context)
[Final] Used for the simple mechanism for common delegation in XCube.