| 1 |
<?php |
| 2 |
/** |
| 3 |
* UserAccessManager.php |
| 4 |
* |
| 5 |
* The UserAccessManager 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; |
| 16 |
|
| 17 |
use UserAccessManager\Access\AccessHandler; |
| 18 |
use UserAccessManager\Cache\Cache; |
| 19 |
use UserAccessManager\Cache\CacheProviderFactory; |
| 20 |
use UserAccessManager\Config\ConfigFactory; |
| 21 |
use UserAccessManager\Config\MainConfig; |
| 22 |
use UserAccessManager\Config\ConfigParameterFactory; |
| 23 |
use UserAccessManager\Controller\Backend\DynamicGroupsController; |
| 24 |
use UserAccessManager\Controller\Backend\PostObjectController; |
| 25 |
use UserAccessManager\Controller\Backend\SetupController; |
| 26 |
use UserAccessManager\Controller\Backend\TermObjectController; |
| 27 |
use UserAccessManager\Controller\Backend\UserObjectController; |
| 28 |
use UserAccessManager\Controller\ControllerFactory; |
| 29 |
use UserAccessManager\Database\Database; |
| 30 |
use UserAccessManager\File\FileHandler; |
| 31 |
use UserAccessManager\File\FileObjectFactory; |
| 32 |
use UserAccessManager\File\FileProtectionFactory; |
| 33 |
use UserAccessManager\Object\ObjectHandler; |
| 34 |
use UserAccessManager\ObjectMembership\ObjectMembershipHandlerFactory; |
| 35 |
use UserAccessManager\Setup\SetupHandler; |
| 36 |
use UserAccessManager\UserGroup\UserGroupFactory; |
| 37 |
use UserAccessManager\User\UserHandler; |
| 38 |
use UserAccessManager\Util\Util; |
| 39 |
use UserAccessManager\Widget\WidgetFactory; |
| 40 |
use UserAccessManager\Wrapper\Php; |
| 41 |
use UserAccessManager\Wrapper\Wordpress; |
| 42 |
|
| 43 |
/** |
| 44 |
* Class UserAccessManager |
| 45 |
* |
| 46 |
* @package UserAccessManager |
| 47 |
*/ |
| 48 |
class UserAccessManager |
| 49 |
{ |
| 50 |
const VERSION = '2.1.0'; |
| 51 |
const DB_VERSION = '1.6.0'; |
| 52 |
|
| 53 |
/** |
| 54 |
* @var Php |
| 55 |
*/ |
| 56 |
private $php; |
| 57 |
|
| 58 |
/** |
| 59 |
* @var Wordpress |
| 60 |
*/ |
| 61 |
private $wordpress; |
| 62 |
|
| 63 |
/** |
| 64 |
* @var Util |
| 65 |
*/ |
| 66 |
private $util; |
| 67 |
|
| 68 |
/** |
| 69 |
* @var Cache |
| 70 |
*/ |
| 71 |
private $cache; |
| 72 |
|
| 73 |
/** |
| 74 |
* @var MainConfig |
| 75 |
*/ |
| 76 |
private $config; |
| 77 |
|
| 78 |
/** |
| 79 |
* @var Database |
| 80 |
*/ |
| 81 |
private $database; |
| 82 |
|
| 83 |
/** |
| 84 |
* @var ObjectHandler |
| 85 |
*/ |
| 86 |
private $objectHandler; |
| 87 |
|
| 88 |
/** |
| 89 |
* @var UserHandler |
| 90 |
*/ |
| 91 |
private $userHandler; |
| 92 |
|
| 93 |
/** |
| 94 |
* @var AccessHandler |
| 95 |
*/ |
| 96 |
private $accessHandler; |
| 97 |
|
| 98 |
/** |
| 99 |
* @var FileHandler |
| 100 |
*/ |
| 101 |
private $fileHandler; |
| 102 |
|
| 103 |
/** |
| 104 |
* @var SetupHandler |
| 105 |
*/ |
| 106 |
private $setupHandler; |
| 107 |
|
| 108 |
/** |
| 109 |
* @var UserGroupFactory |
| 110 |
*/ |
| 111 |
private $userGroupFactory; |
| 112 |
|
| 113 |
/** |
| 114 |
* @var ObjectMembershipHandlerFactory |
| 115 |
*/ |
| 116 |
private $membershipHandlerFactory; |
| 117 |
|
| 118 |
/** |
| 119 |
* @var ControllerFactory |
| 120 |
*/ |
| 121 |
private $controllerFactory; |
| 122 |
|
| 123 |
/** |
| 124 |
* @var WidgetFactory |
| 125 |
*/ |
| 126 |
private $widgetFactory; |
| 127 |
|
| 128 |
/** |
| 129 |
* @var CacheProviderFactory |
| 130 |
*/ |
| 131 |
private $cacheProviderFactory; |
| 132 |
|
| 133 |
/** |
| 134 |
* @var ConfigFactory |
| 135 |
*/ |
| 136 |
private $configFactory; |
| 137 |
|
| 138 |
/** |
| 139 |
* @var ConfigParameterFactory |
| 140 |
*/ |
| 141 |
private $configParameterFactory; |
| 142 |
|
| 143 |
/** |
| 144 |
* @var FileProtectionFactory |
| 145 |
*/ |
| 146 |
private $fileProtectionFactory; |
| 147 |
|
| 148 |
/** |
| 149 |
* @var FileObjectFactory |
| 150 |
*/ |
| 151 |
private $fileObjectFactory; |
| 152 |
|
| 153 |
/** |
| 154 |
* UserAccessManager constructor. |
| 155 |
* |
| 156 |
* @param Php $php |
| 157 |
* @param Wordpress $wordpress |
| 158 |
* @param Util $util |
| 159 |
* @param Cache $cache |
| 160 |
* @param MainConfig $config |
| 161 |
* @param Database $database |
| 162 |
* @param ObjectHandler $objectHandler |
| 163 |
* @param UserHandler $userHandler |
| 164 |
* @param AccessHandler $accessHandler |
| 165 |
* @param FileHandler $fileHandler |
| 166 |
* @param SetupHandler $setupHandler |
| 167 |
* @param UserGroupFactory $userGroupFactory |
| 168 |
* @param ObjectMembershipHandlerFactory $membershipHandlerFactory |
| 169 |
* @param ControllerFactory $controllerFactory |
| 170 |
* @param WidgetFactory $widgetFactory |
| 171 |
* @param CacheProviderFactory $cacheProviderFactory |
| 172 |
* @param ConfigFactory $configFactory |
| 173 |
* @param ConfigParameterFactory $configParameterFactory |
| 174 |
* @param FileProtectionFactory $fileProtectionFactory |
| 175 |
* @param FileObjectFactory $fileObjectFactory |
| 176 |
*/ |
| 177 |
public function __construct( |
| 178 |
Php $php, |
| 179 |
Wordpress $wordpress, |
| 180 |
Util $util, |
| 181 |
Cache $cache, |
| 182 |
MainConfig $config, |
| 183 |
Database $database, |
| 184 |
ObjectHandler $objectHandler, |
| 185 |
UserHandler $userHandler, |
| 186 |
AccessHandler $accessHandler, |
| 187 |
FileHandler $fileHandler, |
| 188 |
SetupHandler $setupHandler, |
| 189 |
UserGroupFactory $userGroupFactory, |
| 190 |
ObjectMembershipHandlerFactory $membershipHandlerFactory, |
| 191 |
ControllerFactory $controllerFactory, |
| 192 |
WidgetFactory $widgetFactory, |
| 193 |
CacheProviderFactory $cacheProviderFactory, |
| 194 |
ConfigFactory $configFactory, |
| 195 |
ConfigParameterFactory $configParameterFactory, |
| 196 |
FileProtectionFactory $fileProtectionFactory, |
| 197 |
FileObjectFactory $fileObjectFactory |
| 198 |
) { |
| 199 |
$this->php = $php; |
| 200 |
$this->wordpress = $wordpress; |
| 201 |
$this->util = $util; |
| 202 |
$this->cache = $cache; |
| 203 |
$this->config = $config; |
| 204 |
$this->database = $database; |
| 205 |
$this->objectHandler = $objectHandler; |
| 206 |
$this->userHandler = $userHandler; |
| 207 |
$this->accessHandler = $accessHandler; |
| 208 |
$this->fileHandler = $fileHandler; |
| 209 |
$this->setupHandler = $setupHandler; |
| 210 |
$this->userGroupFactory = $userGroupFactory; |
| 211 |
$this->membershipHandlerFactory = $membershipHandlerFactory; |
| 212 |
$this->controllerFactory = $controllerFactory; |
| 213 |
$this->widgetFactory = $widgetFactory; |
| 214 |
$this->cacheProviderFactory = $cacheProviderFactory; |
| 215 |
$this->configFactory = $configFactory; |
| 216 |
$this->configParameterFactory = $configParameterFactory; |
| 217 |
$this->fileProtectionFactory = $fileProtectionFactory; |
| 218 |
$this->fileObjectFactory = $fileObjectFactory; |
| 219 |
|
| 220 |
$this->cache->setActiveCacheProvider($this->config->getActiveCacheProvider()); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* @return Php |
| 225 |
*/ |
| 226 |
public function getPhp() |
| 227 |
{ |
| 228 |
return $this->php; |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* @return Wordpress |
| 233 |
*/ |
| 234 |
public function getWordpress() |
| 235 |
{ |
| 236 |
return $this->wordpress; |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* @return Util |
| 241 |
*/ |
| 242 |
public function getUtil() |
| 243 |
{ |
| 244 |
return $this->util; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* @return Cache |
| 249 |
*/ |
| 250 |
public function getCache() |
| 251 |
{ |
| 252 |
return $this->cache; |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* @return MainConfig |
| 257 |
*/ |
| 258 |
public function getConfig() |
| 259 |
{ |
| 260 |
return $this->config; |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* @return Database |
| 265 |
*/ |
| 266 |
public function getDatabase() |
| 267 |
{ |
| 268 |
return $this->database; |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* @return ObjectHandler |
| 273 |
*/ |
| 274 |
public function getObjectHandler() |
| 275 |
{ |
| 276 |
return $this->objectHandler; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* @return UserHandler |
| 281 |
*/ |
| 282 |
public function getUserHandler() |
| 283 |
{ |
| 284 |
return $this->userHandler; |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* @return AccessHandler |
| 289 |
*/ |
| 290 |
public function getAccessHandler() |
| 291 |
{ |
| 292 |
return $this->accessHandler; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* @return FileHandler |
| 297 |
*/ |
| 298 |
public function getFileHandler() |
| 299 |
{ |
| 300 |
return $this->fileHandler; |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* @return SetupHandler |
| 305 |
*/ |
| 306 |
public function getSetupHandler() |
| 307 |
{ |
| 308 |
return $this->setupHandler; |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* @return UserGroupFactory |
| 313 |
*/ |
| 314 |
public function getUserGroupFactory() |
| 315 |
{ |
| 316 |
return $this->userGroupFactory; |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* @return ObjectMembershipHandlerFactory |
| 321 |
*/ |
| 322 |
public function getObjectMembershipHandlerFactory() |
| 323 |
{ |
| 324 |
return $this->membershipHandlerFactory; |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* @return ControllerFactory |
| 329 |
*/ |
| 330 |
public function getControllerFactory() |
| 331 |
{ |
| 332 |
return $this->controllerFactory; |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* @return WidgetFactory |
| 337 |
*/ |
| 338 |
public function getWidgetFactory() |
| 339 |
{ |
| 340 |
return $this->widgetFactory; |
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* @return CacheProviderFactory |
| 345 |
*/ |
| 346 |
public function getCacheProviderFactory() |
| 347 |
{ |
| 348 |
return $this->cacheProviderFactory; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* @return ConfigFactory |
| 353 |
*/ |
| 354 |
public function getConfigFactory() |
| 355 |
{ |
| 356 |
return $this->configFactory; |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* @return ConfigParameterFactory |
| 361 |
*/ |
| 362 |
public function getConfigParameterFactory() |
| 363 |
{ |
| 364 |
return $this->configParameterFactory; |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* @return FileProtectionFactory |
| 369 |
*/ |
| 370 |
public function getFileProtectionFactory() |
| 371 |
{ |
| 372 |
return $this->fileProtectionFactory; |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* @return FileObjectFactory |
| 377 |
*/ |
| 378 |
public function getFileObjectFactory() |
| 379 |
{ |
| 380 |
return $this->fileObjectFactory; |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Resister the administration menu. |
| 385 |
*/ |
| 386 |
public function registerAdminMenu() |
| 387 |
{ |
| 388 |
if ($this->userHandler->checkUserAccess() === true) { |
| 389 |
//TODO |
| 390 |
/** |
| 391 |
* --- BOF --- |
| 392 |
* Not the best way to handle full user access. Capabilities seems |
| 393 |
* to be the right way, but it is way difficult. |
| 394 |
*/ |
| 395 |
//Admin main menu |
| 396 |
$this->wordpress->addMenuPage( |
| 397 |
'User Access Manager', |
| 398 |
'UAM', |
| 399 |
'manage_options', |
| 400 |
'uam_user_group', |
| 401 |
null, |
| 402 |
'div' |
| 403 |
); |
| 404 |
|
| 405 |
//Admin sub menus |
| 406 |
$backendUserGroupController = $this->controllerFactory->createBackendUserGroupController(); |
| 407 |
$this->wordpress->addSubmenuPage( |
| 408 |
'uam_user_group', |
| 409 |
TXT_UAM_MANAGE_GROUP, |
| 410 |
TXT_UAM_MANAGE_GROUP, |
| 411 |
'read', |
| 412 |
'uam_user_group', |
| 413 |
[$backendUserGroupController, 'render'] |
| 414 |
); |
| 415 |
|
| 416 |
$backendSettingsController = $this->controllerFactory->createBackendSettingsController(); |
| 417 |
$this->wordpress->addSubmenuPage( |
| 418 |
'uam_user_group', |
| 419 |
TXT_UAM_SETTINGS, |
| 420 |
TXT_UAM_SETTINGS, |
| 421 |
'read', |
| 422 |
'uam_settings', |
| 423 |
[$backendSettingsController, 'render'] |
| 424 |
); |
| 425 |
|
| 426 |
$backendSetupController = $this->controllerFactory->createBackendSetupController(); |
| 427 |
$this->wordpress->addSubmenuPage( |
| 428 |
'uam_user_group', |
| 429 |
TXT_UAM_SETUP, |
| 430 |
TXT_UAM_SETUP, |
| 431 |
'read', |
| 432 |
'uam_setup', |
| 433 |
[$backendSetupController, 'render'] |
| 434 |
); |
| 435 |
|
| 436 |
$backendAboutController = $this->controllerFactory->createBackendAboutController(); |
| 437 |
$this->wordpress->addSubmenuPage( |
| 438 |
'uam_user_group', |
| 439 |
TXT_UAM_ABOUT, |
| 440 |
TXT_UAM_ABOUT, |
| 441 |
'read', |
| 442 |
'uam_about', |
| 443 |
[$backendAboutController, 'render'] |
| 444 |
); |
| 445 |
|
| 446 |
$this->wordpress->doAction('uam_add_sub_menu'); |
| 447 |
|
| 448 |
/** |
| 449 |
* --- EOF --- |
| 450 |
*/ |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
/** |
| 455 |
* Adds the backend filters. |
| 456 |
* |
| 457 |
* @param DynamicGroupsController $dynamicGroupController |
| 458 |
* @param PostObjectController $postObjectController |
| 459 |
* @param TermObjectController $termObjectController |
| 460 |
* @param UserObjectController $userObjectController |
| 461 |
* @param array $taxonomies |
| 462 |
*/ |
| 463 |
private function addAdminActions( |
| 464 |
DynamicGroupsController $dynamicGroupController, |
| 465 |
PostObjectController $postObjectController, |
| 466 |
TermObjectController $termObjectController, |
| 467 |
UserObjectController $userObjectController, |
| 468 |
array $taxonomies |
| 469 |
) { |
| 470 |
$this->wordpress->addAction( |
| 471 |
'manage_posts_custom_column', |
| 472 |
[$postObjectController, 'addPostColumn'], |
| 473 |
10, |
| 474 |
2 |
| 475 |
); |
| 476 |
$this->wordpress->addAction( |
| 477 |
'manage_pages_custom_column', |
| 478 |
[$postObjectController, 'addPostColumn'], |
| 479 |
10, |
| 480 |
2 |
| 481 |
); |
| 482 |
$this->wordpress->addAction('save_post', [$postObjectController, 'savePostData']); |
| 483 |
$this->wordpress->addAction('edit_user_profile', [$userObjectController, 'showUserProfile']); |
| 484 |
$this->wordpress->addAction('user_new_form', [$userObjectController, 'showUserProfile']); |
| 485 |
$this->wordpress->addAction('profile_update', [$userObjectController, 'saveUserData']); |
| 486 |
|
| 487 |
$this->wordpress->addAction('bulk_edit_custom_box', [$postObjectController, 'addBulkAction']); |
| 488 |
$this->wordpress->addAction('create_term', [$termObjectController, 'saveTermData']); |
| 489 |
$this->wordpress->addAction('edit_term', [$termObjectController, 'saveTermData']); |
| 490 |
|
| 491 |
//Taxonomies |
| 492 |
foreach ($taxonomies as $taxonomy) { |
| 493 |
$this->wordpress->addAction( |
| 494 |
'manage_'.$taxonomy.'_custom_column', |
| 495 |
[$termObjectController, 'addTermColumn'], |
| 496 |
10, |
| 497 |
3 |
| 498 |
); |
| 499 |
$this->wordpress->addAction( |
| 500 |
$taxonomy.'_add_form_fields', |
| 501 |
[$termObjectController, 'showTermEditForm'] |
| 502 |
); |
| 503 |
$this->wordpress->addAction( |
| 504 |
$taxonomy.'_edit_form_fields', |
| 505 |
[$termObjectController, 'showTermEditForm'] |
| 506 |
); |
| 507 |
} |
| 508 |
|
| 509 |
if ($this->config->lockFile() === true) { |
| 510 |
$this->wordpress->addAction( |
| 511 |
'manage_media_custom_column', |
| 512 |
[$postObjectController, 'addPostColumn'], |
| 513 |
10, |
| 514 |
2 |
| 515 |
); |
| 516 |
$this->wordpress->addAction( |
| 517 |
'attachment_fields_to_edit', |
| 518 |
[$postObjectController, 'showMediaFile'], |
| 519 |
10, |
| 520 |
2 |
| 521 |
); |
| 522 |
$this->wordpress->addAction( |
| 523 |
'wp_ajax_save-attachment-compat', |
| 524 |
[$postObjectController, 'saveAjaxAttachmentData'], |
| 525 |
1, |
| 526 |
9 |
| 527 |
); |
| 528 |
} |
| 529 |
|
| 530 |
//Admin ajax actions |
| 531 |
$this->wordpress->addAction( |
| 532 |
'wp_ajax_uam-get-dynamic-group', |
| 533 |
[$dynamicGroupController, 'getDynamicGroupsForAjax'] |
| 534 |
); |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* Adds the admin filters. |
| 539 |
* |
| 540 |
* @param PostObjectController $postObjectController |
| 541 |
* @param TermObjectController $termObjectController |
| 542 |
* @param UserObjectController $userObjectController |
| 543 |
* @param array $taxonomies |
| 544 |
*/ |
| 545 |
private function addAdminFilters( |
| 546 |
PostObjectController $postObjectController, |
| 547 |
TermObjectController $termObjectController, |
| 548 |
UserObjectController $userObjectController, |
| 549 |
array $taxonomies |
| 550 |
) { |
| 551 |
//The filter we use instead of add|edit_attachment action, reason see top |
| 552 |
$this->wordpress->addFilter('attachment_fields_to_save', [$postObjectController, 'saveAttachmentData']); |
| 553 |
|
| 554 |
$this->wordpress->addFilter('manage_posts_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 555 |
$this->wordpress->addFilter('manage_pages_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 556 |
|
| 557 |
$this->wordpress->addFilter('manage_users_columns', [$userObjectController, 'addUserColumnsHeader'], 10); |
| 558 |
$this->wordpress->addFilter( |
| 559 |
'manage_users_custom_column', |
| 560 |
[$userObjectController, 'addUserColumn'], |
| 561 |
10, |
| 562 |
3 |
| 563 |
); |
| 564 |
|
| 565 |
foreach ($taxonomies as $taxonomy) { |
| 566 |
$this->wordpress->addFilter( |
| 567 |
'manage_edit-'.$taxonomy.'_columns', |
| 568 |
[$termObjectController, 'addTermColumnsHeader'] |
| 569 |
); |
| 570 |
} |
| 571 |
|
| 572 |
if ($this->config->lockFile() === true) { |
| 573 |
$this->wordpress->addFilter('manage_media_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
/** |
| 578 |
* Adds the admin meta boxes. |
| 579 |
* |
| 580 |
* @param PostObjectController $postObjectController |
| 581 |
*/ |
| 582 |
private function addAdminMetaBoxes(PostObjectController $postObjectController) |
| 583 |
{ |
| 584 |
$postTypes = $this->objectHandler->getPostTypes(); |
| 585 |
|
| 586 |
foreach ($postTypes as $postType) { |
| 587 |
// there is no need for a meta box for attachments if files are locked |
| 588 |
if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE && $this->config->lockFile() !== true) { |
| 589 |
continue; |
| 590 |
} |
| 591 |
|
| 592 |
$this->wordpress->addMetaBox( |
| 593 |
'uam_post_access', |
| 594 |
TXT_UAM_COLUMN_ACCESS, |
| 595 |
[$postObjectController, 'editPostContent'], |
| 596 |
$postType, |
| 597 |
'side' |
| 598 |
); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Register the admin actions and filters |
| 604 |
*/ |
| 605 |
public function registerAdminActionsAndFilters() |
| 606 |
{ |
| 607 |
$backendController = $this->controllerFactory->createBackendController(); |
| 608 |
$this->wordpress->addAction('admin_enqueue_scripts', [$backendController, 'enqueueStylesAndScripts']); |
| 609 |
$this->wordpress->addAction('wp_dashboard_setup', [$backendController, 'setupAdminDashboard']); |
| 610 |
$updateAction = $backendController->getRequestParameter('uam_update_db'); |
| 611 |
|
| 612 |
if ($this->setupHandler->isDatabaseUpdateNecessary() === true |
| 613 |
&& $updateAction !== SetupController::UPDATE_BLOG |
| 614 |
&& $updateAction !== SetupController::UPDATE_NETWORK |
| 615 |
) { |
| 616 |
$this->wordpress->addAction('admin_notices', [$backendController, 'showDatabaseNotice']); |
| 617 |
} |
| 618 |
|
| 619 |
$taxonomies = $this->objectHandler->getTaxonomies(); |
| 620 |
$taxonomy = $backendController->getRequestParameter('taxonomy'); |
| 621 |
|
| 622 |
if ($taxonomy !== null) { |
| 623 |
$taxonomies[$taxonomy] = $taxonomy; |
| 624 |
} |
| 625 |
|
| 626 |
$objectController = $this->controllerFactory->createBackendObjectController(); |
| 627 |
$postObjectController = $this->controllerFactory->createBackendPostObjectController(); |
| 628 |
$termObjectController = $this->controllerFactory->createBackendTermObjectController(); |
| 629 |
$userObjectController = $this->controllerFactory->createBackendUserObjectController(); |
| 630 |
$dynamicGroupController = $this->controllerFactory->createBackendDynamicGroupsController(); |
| 631 |
|
| 632 |
if ($this->userHandler->checkUserAccess() === true |
| 633 |
|| $this->config->authorsCanAddPostsToGroups() === true |
| 634 |
) { |
| 635 |
//Admin actions |
| 636 |
$this->addAdminActions( |
| 637 |
$dynamicGroupController, |
| 638 |
$postObjectController, |
| 639 |
$termObjectController, |
| 640 |
$userObjectController, |
| 641 |
$taxonomies |
| 642 |
); |
| 643 |
|
| 644 |
//Admin filters |
| 645 |
$this->addAdminFilters( |
| 646 |
$postObjectController, |
| 647 |
$termObjectController, |
| 648 |
$userObjectController, |
| 649 |
$taxonomies |
| 650 |
); |
| 651 |
|
| 652 |
//Admin meta boxes |
| 653 |
$this->addAdminMetaBoxes($postObjectController); |
| 654 |
} |
| 655 |
|
| 656 |
//Clean up at deleting should always be done. |
| 657 |
$this->wordpress->addAction('update_option_permalink_structure', [$objectController, 'updatePermalink']); |
| 658 |
$this->wordpress->addAction('delete_post', [$postObjectController, 'removePostData']); |
| 659 |
$this->wordpress->addAction('delete_attachment', [$postObjectController, 'removePostData']); |
| 660 |
$this->wordpress->addAction('delete_user', [$userObjectController, 'removeUserData']); |
| 661 |
$this->wordpress->addAction('delete_term', [$termObjectController, 'removeTermData']); |
| 662 |
|
| 663 |
$objectController->checkRightsToEditContent(); |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* Adds the actions and filers. |
| 668 |
*/ |
| 669 |
public function addActionsAndFilters() |
| 670 |
{ |
| 671 |
//Actions |
| 672 |
$this->wordpress->addAction('admin_menu', [$this, 'registerAdminMenu']); |
| 673 |
$this->wordpress->addAction('admin_init', [$this, 'registerAdminActionsAndFilters']); |
| 674 |
$this->wordpress->addAction('registered_post_type', [$this->objectHandler, 'registeredPostType'], 10, 2); |
| 675 |
$this->wordpress->addAction('registered_taxonomy', [$this->objectHandler, 'registeredTaxonomy'], 10, 3); |
| 676 |
$this->wordpress->addAction('registered_post_type', [$this->config, 'flushConfigParameters']); |
| 677 |
$this->wordpress->addAction('registered_taxonomy', [$this->config, 'flushConfigParameters']); |
| 678 |
|
| 679 |
// General frontend controller |
| 680 |
$frontendController = $this->controllerFactory->createFrontendController(); |
| 681 |
|
| 682 |
$this->wordpress->addAction('wp_enqueue_scripts', [$frontendController, 'enqueueStylesAndScripts']); |
| 683 |
$this->wordpress->addFilter('get_ancestors', [$frontendController, 'showAncestors'], 20, 4); |
| 684 |
$this->wordpress->addFilter('wpseo_sitemap_entry', [$frontendController, 'getWpSeoUrl'], 1, 3); |
| 685 |
|
| 686 |
// Post controller |
| 687 |
$frontendPostController = $this->controllerFactory->createFrontendPostController(); |
| 688 |
|
| 689 |
$this->wordpress->addFilter('posts_pre_query', [$frontendPostController, 'postsPreQuery'], 10, 2); |
| 690 |
$this->wordpress->addFilter('the_posts', [$frontendPostController, 'showPosts'], 9); |
| 691 |
$this->wordpress->addFilter('get_attached_file', [$frontendPostController, 'getAttachedFile'], 10, 2); |
| 692 |
$this->wordpress->addFilter('posts_where_paged', [$frontendPostController, 'showPostSql']); |
| 693 |
$this->wordpress->addFilter('comments_array', [$frontendPostController, 'showComment']); |
| 694 |
$this->wordpress->addFilter('the_comments', [$frontendPostController, 'showComment']); |
| 695 |
$this->wordpress->addFilter('get_pages', [$frontendPostController, 'showPages'], 20); |
| 696 |
$this->wordpress->addFilter('get_next_post_where', [$frontendPostController, 'showNextPreviousPost']); |
| 697 |
$this->wordpress->addFilter('get_previous_post_where', [$frontendPostController, 'showNextPreviousPost']); |
| 698 |
$this->wordpress->addFilter('edit_post_link', [$frontendPostController, 'showGroupMembership'], 10, 2); |
| 699 |
$this->wordpress->addFilter('parse_query', [$frontendPostController, 'parseQuery']); |
| 700 |
$this->wordpress->addFilter('getarchives_where', [$frontendPostController, 'showPostSql']); |
| 701 |
$this->wordpress->addFilter('wp_count_posts', [$frontendPostController, 'showPostCount'], 10, 3); |
| 702 |
|
| 703 |
// Short code controller |
| 704 |
$frontendShortCodeController = $this->controllerFactory->createFrontendShortCodeController(); |
| 705 |
|
| 706 |
$this->wordpress->addShortCode('LOGIN_FORM', [$frontendShortCodeController, 'loginFormShortCode']); // Legacy |
| 707 |
$this->wordpress->addShortCode('uam_login_form', [$frontendShortCodeController, 'loginFormShortCode']); |
| 708 |
$this->wordpress->addShortCode('uam_public', [$frontendShortCodeController, 'publicShortCode']); |
| 709 |
$this->wordpress->addShortCode('uam_private', [$frontendShortCodeController, 'privateShortCode']); |
| 710 |
|
| 711 |
// Term controller |
| 712 |
$frontendTermController = $this->controllerFactory->createFrontendTermController(); |
| 713 |
|
| 714 |
$this->wordpress->addFilter('get_terms_args', [$frontendTermController, 'getTermArguments']); |
| 715 |
$this->wordpress->addFilter('get_terms', [$frontendTermController, 'showTerms'], 20); |
| 716 |
$this->wordpress->addFilter('get_term', [$frontendTermController, 'showTerm'], 20, 2); |
| 717 |
$this->wordpress->addFilter('wp_get_nav_menu_items', [$frontendTermController, 'showCustomMenu']); |
| 718 |
|
| 719 |
// Redirect controller |
| 720 |
$frontendRedirectController = $this->controllerFactory->createFrontendRedirectController(); |
| 721 |
|
| 722 |
$this->wordpress->addFilter('wp_get_attachment_thumb_url', [$frontendRedirectController, 'getFileUrl'], 10, 2); |
| 723 |
$this->wordpress->addFilter('wp_get_attachment_url', [$frontendRedirectController, 'getFileUrl'], 10, 2); |
| 724 |
$this->wordpress->addFilter('post_link', [$frontendRedirectController, 'cachePostLinks'], 10, 2); |
| 725 |
|
| 726 |
$getFile = $frontendController->getRequestParameter('uamgetfile'); |
| 727 |
|
| 728 |
if ($this->config->getRedirect() !== false || $getFile !== null) { |
| 729 |
$this->wordpress->addFilter('wp_headers', [$frontendRedirectController, 'redirect'], 10, 2); |
| 730 |
} |
| 731 |
|
| 732 |
// Admin object controller |
| 733 |
$backendCacheController = $this->controllerFactory->createBackendCacheController(); |
| 734 |
|
| 735 |
$this->wordpress->addFilter('clean_term_cache', [$backendCacheController, 'invalidateTermCache']); |
| 736 |
$this->wordpress->addFilter('clean_object_term_cache', [$backendCacheController, 'invalidateTermCache']); |
| 737 |
$this->wordpress->addFilter('clean_post_cache', [$backendCacheController, 'invalidatePostCache']); |
| 738 |
$this->wordpress->addFilter('clean_attachment_cache', [$backendCacheController, 'invalidatePostCache']); |
| 739 |
|
| 740 |
// Widgets |
| 741 |
$this->wordpress->addAction('widgets_init', function () { |
| 742 |
$this->wordpress->registerWidget($this->widgetFactory->createLoginWidget()); |
| 743 |
}); |
| 744 |
} |
| 745 |
} |
| 746 |
|