Cache.php
6 years ago
Capability.php
6 years ago
LoginRedirect.php
6 years ago
LogoutRedirect.php
6 years ago
Menu.php
6 years ago
Metabox.php
6 years ago
Policy.php
6 years ago
Post.php
6 years ago
Redirect.php
6 years ago
Route.php
6 years ago
Toolbar.php
6 years ago
Uri.php
6 years ago
Visibility.php
6 years ago
Route.php
114 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 | * API route object |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Core_Object_Route 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 = AAM_Core_Compatibility::convertRoute( |
| 31 | $this->getSubject()->readOption('route') |
| 32 | ); |
| 33 | |
| 34 | if (!empty($option)) { |
| 35 | $this->setOverwritten(true); |
| 36 | } |
| 37 | |
| 38 | // Load settings from Access & Security Policy |
| 39 | if (empty($option)) { |
| 40 | $stms = AAM_Core_Policy_Factory::get($subject)->find("/^Route:/i"); |
| 41 | |
| 42 | foreach($stms as $key => $stm) { |
| 43 | $chunks = explode(':', $key); |
| 44 | $method = (isset($chunks[3]) ? $chunks[3] : 'post'); |
| 45 | $id = "{$chunks[1]}|{$chunks[2]}|{$method}"; |
| 46 | |
| 47 | $option[$id] = ($stm['Effect'] === 'deny' ? 1 : 0); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (empty($option)) { |
| 52 | $option = $this->getSubject()->inheritFromParent('route'); |
| 53 | } |
| 54 | |
| 55 | $this->setOption($option); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Check if route is denied |
| 60 | * |
| 61 | * @param string $type REST or XMLRPC |
| 62 | * @param string $route |
| 63 | * @param string $method |
| 64 | * |
| 65 | * @return boolean |
| 66 | * |
| 67 | * @access public |
| 68 | */ |
| 69 | public function has($type, $route, $method = 'POST') { |
| 70 | $options = $this->getOption(); |
| 71 | $id = strtolower("{$type}|{$route}|{$method}"); |
| 72 | |
| 73 | return !empty($options[$id]); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Save menu option |
| 78 | * |
| 79 | * @return bool |
| 80 | * |
| 81 | * @access public |
| 82 | */ |
| 83 | public function save($type, $route, $method, $value) { |
| 84 | $option = $this->getOption(); |
| 85 | |
| 86 | $id = strtolower("{$type}|{$route}|{$method}"); |
| 87 | $option[$id] = $value; |
| 88 | |
| 89 | $this->setOption($option); |
| 90 | |
| 91 | return $this->getSubject()->updateOption($this->getOption(), 'route'); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Reset default settings |
| 96 | * |
| 97 | * @return bool |
| 98 | * |
| 99 | * @access public |
| 100 | */ |
| 101 | public function reset() { |
| 102 | return $this->getSubject()->deleteOption('route'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * |
| 107 | * @param type $external |
| 108 | * @return type |
| 109 | */ |
| 110 | public function mergeOption($external) { |
| 111 | return AAM::api()->mergeSettings($external, $this->getOption(), 'route'); |
| 112 | } |
| 113 | |
| 114 | } |