PluginProbe
User Access Manager / 2.2.22
User Access Manager v2.2.22
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Backend / BackendController.php

BackendController.php in User Access Manager 2.2.22, at src/Controller/Backend/BackendController.php

170 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * BackendController.php
4 *
5 * The BackendController class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Backend;
19
20 use UserAccessManager\Config\WordpressConfig;
21 use UserAccessManager\Controller\Controller;
22 use UserAccessManager\File\FileHandler;
23 use UserAccessManager\Setup\SetupHandler;
24 use UserAccessManager\User\UserHandler;
25 use UserAccessManager\UserAccessManager;
26 use UserAccessManager\Wrapper\Php;
27 use UserAccessManager\Wrapper\Wordpress;
28
29 /**
30 * Class BackendController
31 *
32 * @package UserAccessManager\Controller
33 */
34 class BackendController extends Controller
35 {
36 public const HANDLE_STYLE_ADMIN = 'UserAccessManagerAdmin';
37 public const HANDLE_SCRIPT_GROUP_SUGGEST = 'UserAccessManagerGroupSuggest';
38 public const HANDLE_SCRIPT_TIME_INPUT = 'UserAccessManagerTimeInput';
39 public const HANDLE_SCRIPT_ADMIN = 'UserAccessManagerFunctions';
40 public const UAM_ERRORS = 'UAM_ERRORS';
41
42 /**
43 * @var UserHandler
44 */
45 private $userHandler;
46
47 /**
48 * @var SetupHandler
49 */
50 private $setupHandler;
51
52 /**
53 * @var string
54 */
55 private $notice = '';
56
57 /**
58 * BackendController constructor.
59 * @param Php $php
60 * @param Wordpress $wordpress
61 * @param WordpressConfig $wordpressConfig
62 * @param UserHandler $userHandler
63 * @param SetupHandler $setupHandler
64 */
65 public function __construct(
66 Php $php,
67 Wordpress $wordpress,
68 WordpressConfig $wordpressConfig,
69 UserHandler $userHandler,
70 SetupHandler $setupHandler
71 ) {
72 parent::__construct($php, $wordpress, $wordpressConfig);
73 $this->userHandler = $userHandler;
74 $this->setupHandler = $setupHandler;
75 }
76
77 /**
78 * Shows the admin notices.
79 */
80 public function showAdminNotice()
81 {
82 $messages = isset($_SESSION[self::UAM_ERRORS]) === true ? $_SESSION[self::UAM_ERRORS] : [];
83 $updateAction = $this->getRequestParameter('uam_update_db');
84
85 if ($this->setupHandler->getDatabaseHandler()->isDatabaseUpdateNecessary() === true
86 && $updateAction !== SetupController::UPDATE_BLOG
87 && $updateAction !== SetupController::UPDATE_NETWORK
88 ) {
89 $messages[] = sprintf(TXT_UAM_NEED_DATABASE_UPDATE, 'admin.php?page=uam_setup');
90 }
91
92 if ($messages !== []) {
93 $this->notice = implode('<br>', $messages);
94 echo $this->getIncludeContents('AdminNotice.php');
95 }
96 }
97
98 /**
99 * Returns the set notice.
100 * @return string
101 */
102 public function getNotice(): string
103 {
104 return $this->notice;
105 }
106
107 /**
108 * Register styles and scripts with handle for admin panel.
109 */
110 private function registerStylesAndScripts()
111 {
112 $urlPath = $this->wordpressConfig->getUrlPath();
113
114 $this->wordpress->registerStyle(
115 self::HANDLE_STYLE_ADMIN,
116 $urlPath . 'assets/css/uamAdmin.css',
117 [],
118 UserAccessManager::VERSION,
119 'screen'
120 );
121
122 $this->wordpress->registerScript(
123 self::HANDLE_SCRIPT_GROUP_SUGGEST,
124 $urlPath . 'assets/js/jquery.uam-group-suggest.js',
125 ['jquery'],
126 UserAccessManager::VERSION
127 );
128
129 $this->wordpress->registerScript(
130 self::HANDLE_SCRIPT_TIME_INPUT,
131 $urlPath . 'assets/js/jquery.uam-time-input.js',
132 ['jquery'],
133 UserAccessManager::VERSION
134 );
135
136 $this->wordpress->registerScript(
137 self::HANDLE_SCRIPT_ADMIN,
138 $urlPath . 'assets/js/functions.js',
139 ['jquery'],
140 UserAccessManager::VERSION
141 );
142 }
143
144 /**
145 * The function for the admin_enqueue_scripts action for styles and scripts.
146 */
147 public function enqueueStylesAndScripts()
148 {
149 $this->registerStylesAndScripts();
150 $this->wordpress->enqueueStyle(self::HANDLE_STYLE_ADMIN);
151 $this->wordpress->enqueueScript(self::HANDLE_SCRIPT_GROUP_SUGGEST);
152 $this->wordpress->enqueueScript(self::HANDLE_SCRIPT_TIME_INPUT);
153 $this->wordpress->enqueueScript(self::HANDLE_SCRIPT_ADMIN);
154 }
155
156
157 /**
158 * The function for the wp_dashboard_setup action.
159 * Removes widgets to which a user should not have access.
160 */
161 public function setupAdminDashboard()
162 {
163 if ($this->userHandler->checkUserAccess(UserHandler::MANAGE_USER_GROUPS_CAPABILITY) === false) {
164 $metaBoxes = $this->wordpress->getMetaBoxes();
165 unset($metaBoxes['dashboard']['normal']['core']['dashboard_recent_comments']);
166 $this->wordpress->setMetaBoxes($metaBoxes);
167 }
168 }
169 }
170