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