Cache.php
8 years ago
Capability.php
8 years ago
LoginRedirect.php
8 years ago
LogoutRedirect.php
8 years ago
Menu.php
8 years ago
Metabox.php
8 years ago
Post.php
8 years ago
Redirect.php
8 years ago
Route.php
8 years ago
Toolbar.php
8 years ago
Visibility.php
8 years ago
Toolbar.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Admin toolbar object |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Core_Object_Toolbar extends AAM_Core_Object { |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | * |
| 21 | * @param AAM_Core_Subject $subject |
| 22 | * |
| 23 | * @return void |
| 24 | * |
| 25 | * @access public |
| 26 | */ |
| 27 | public function __construct(AAM_Core_Subject $subject) { |
| 28 | parent::__construct($subject); |
| 29 | |
| 30 | $option = $this->getSubject()->readOption('toolbar'); |
| 31 | |
| 32 | if (empty($option)) { |
| 33 | $option = $this->getSubject()->inheritFromParent('toolbar'); |
| 34 | } else { |
| 35 | $this->setOverwritten(true); |
| 36 | } |
| 37 | |
| 38 | $this->setOption($option); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Check is item defined |
| 43 | * |
| 44 | * Check if toolbar item defined in options based on the id |
| 45 | * |
| 46 | * @param string $item |
| 47 | * |
| 48 | * @return boolean |
| 49 | * |
| 50 | * @access public |
| 51 | */ |
| 52 | public function has($item, $both = false) { |
| 53 | $options = $this->getOption(); |
| 54 | |
| 55 | // Step #1. Check if toolbar item is directly restricted |
| 56 | $direct = !empty($options[$item]); |
| 57 | |
| 58 | // Step #2. Check if whole branch is restricted |
| 59 | $branch = ($both && !empty($options['toolbar-' . $item])); |
| 60 | |
| 61 | return $direct || $branch; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Allow access to a specific menu |
| 66 | * |
| 67 | * @param string $menu |
| 68 | * |
| 69 | * @return boolean |
| 70 | * |
| 71 | * @access public |
| 72 | */ |
| 73 | public function allow($menu) { |
| 74 | return $this->save($menu, 0); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Deny access to a specific menu |
| 79 | * |
| 80 | * @param string $menu |
| 81 | * |
| 82 | * @return boolean |
| 83 | * |
| 84 | * @access public |
| 85 | */ |
| 86 | public function deny($menu) { |
| 87 | return $this->save($menu, 1); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Save menu option |
| 92 | * |
| 93 | * @return bool |
| 94 | * |
| 95 | * @access public |
| 96 | */ |
| 97 | public function save($item = null, $value = null) { |
| 98 | if (!is_null($item)) { // keep it compatible with main Manager.save |
| 99 | $this->updateOptionItem($item, $value); |
| 100 | } |
| 101 | |
| 102 | return $this->getSubject()->updateOption($this->getOption(), 'toolbar'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Reset default settings |
| 107 | * |
| 108 | * @return bool |
| 109 | * |
| 110 | * @access public |
| 111 | */ |
| 112 | public function reset() { |
| 113 | return $this->getSubject()->deleteOption('toolbar'); |
| 114 | } |
| 115 | |
| 116 | } |