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