| 1 |
<?php |
| 2 |
/** |
| 3 |
* AdminController.php |
| 4 |
* |
| 5 |
* The AdminController 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 |
namespace UserAccessManager\Controller; |
| 16 |
|
| 17 |
use UserAccessManager\AccessHandler\AccessHandler; |
| 18 |
use UserAccessManager\Config\Config; |
| 19 |
use UserAccessManager\FileHandler\FileHandler; |
| 20 |
use UserAccessManager\UserAccessManager; |
| 21 |
use UserAccessManager\Wrapper\Php; |
| 22 |
use UserAccessManager\Wrapper\Wordpress; |
| 23 |
|
| 24 |
/** |
| 25 |
* Class AdminController |
| 26 |
* |
| 27 |
* @package UserAccessManager\Controller |
| 28 |
*/ |
| 29 |
class AdminController extends Controller |
| 30 |
{ |
| 31 |
const HANDLE_STYLE_ADMIN = 'UserAccessManagerAdmin'; |
| 32 |
const HANDLE_SCRIPT_ADMIN = 'UserAccessManagerFunctions'; |
| 33 |
|
| 34 |
/** |
| 35 |
* @var AccessHandler |
| 36 |
*/ |
| 37 |
private $accessHandler; |
| 38 |
|
| 39 |
/** |
| 40 |
* @var FileHandler |
| 41 |
*/ |
| 42 |
private $fileHandler; |
| 43 |
|
| 44 |
/** |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
private $notice = ''; |
| 48 |
|
| 49 |
/** |
| 50 |
* AdminController constructor. |
| 51 |
* |
| 52 |
* |
| 53 |
* @param Php $php |
| 54 |
* @param Wordpress $wordpress |
| 55 |
* @param Config $config |
| 56 |
* @param AccessHandler $accessHandler |
| 57 |
* @param FileHandler $fileHandler |
| 58 |
*/ |
| 59 |
public function __construct( |
| 60 |
Php $php, |
| 61 |
Wordpress $wordpress, |
| 62 |
Config $config, |
| 63 |
AccessHandler $accessHandler, |
| 64 |
FileHandler $fileHandler |
| 65 |
) { |
| 66 |
parent::__construct($php, $wordpress, $config); |
| 67 |
$this->accessHandler = $accessHandler; |
| 68 |
$this->fileHandler = $fileHandler; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Shows the database notice. |
| 73 |
*/ |
| 74 |
public function showDatabaseNotice() |
| 75 |
{ |
| 76 |
$this->notice = sprintf(TXT_UAM_NEED_DATABASE_UPDATE, 'admin.php?page=uam_setup'); |
| 77 |
echo $this->getIncludeContents('AdminNotice.php'); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Returns the set notice. |
| 82 |
* |
| 83 |
* @return string |
| 84 |
*/ |
| 85 |
public function getNotice() |
| 86 |
{ |
| 87 |
return $this->notice; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Register styles and scripts with handle for admin panel. |
| 92 |
*/ |
| 93 |
private function registerStylesAndScripts() |
| 94 |
{ |
| 95 |
$urlPath = $this->config->getUrlPath(); |
| 96 |
|
| 97 |
$this->wordpress->registerStyle( |
| 98 |
self::HANDLE_STYLE_ADMIN, |
| 99 |
$urlPath.'assets/css/uamAdmin.css', |
| 100 |
[], |
| 101 |
UserAccessManager::VERSION, |
| 102 |
'screen' |
| 103 |
); |
| 104 |
|
| 105 |
$this->wordpress->registerScript( |
| 106 |
self::HANDLE_SCRIPT_ADMIN, |
| 107 |
$urlPath.'assets/js/functions.js', |
| 108 |
['jquery'], |
| 109 |
UserAccessManager::VERSION |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* The function for the admin_enqueue_scripts action for styles and scripts. |
| 115 |
* |
| 116 |
* @param string $hook |
| 117 |
*/ |
| 118 |
public function enqueueStylesAndScripts($hook) |
| 119 |
{ |
| 120 |
$this->registerStylesAndScripts(); |
| 121 |
$this->wordpress->enqueueStyle(self::HANDLE_STYLE_ADMIN); |
| 122 |
|
| 123 |
if ($hook === 'uam_page_uam_settings' || $hook === 'uam_page_uam_setup') { |
| 124 |
$this->wordpress->enqueueScript(self::HANDLE_SCRIPT_ADMIN); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
/** |
| 130 |
* The function for the wp_dashboard_setup action. |
| 131 |
* Removes widgets to which a user should not have access. |
| 132 |
*/ |
| 133 |
public function setupAdminDashboard() |
| 134 |
{ |
| 135 |
if ($this->accessHandler->checkUserAccess('manage_user_groups') === false) { |
| 136 |
$metaBoxes = $this->wordpress->getMetaBoxes(); |
| 137 |
unset($metaBoxes['dashboard']['normal']['core']['dashboard_recent_comments']); |
| 138 |
$this->wordpress->setMetaBoxes($metaBoxes); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* The function for the update_option_permalink_structure action. |
| 144 |
*/ |
| 145 |
public function updatePermalink() |
| 146 |
{ |
| 147 |
$this->fileHandler->createFileProtection(); |
| 148 |
} |
| 149 |
} |
| 150 |
|