Api
6 years ago
ConfigPress
6 years ago
Jwt
6 years ago
Object
6 years ago
Policy
6 years ago
Subject
6 years ago
API.php
6 years ago
Cache.php
6 years ago
Compatibility.php
6 years ago
Config.php
6 years ago
ConfigPress.php
6 years ago
Console.php
6 years ago
Exporter.php
6 years ago
Gateway.php
6 years ago
Importer.php
6 years ago
Login.php
6 years ago
Media.php
6 years ago
Object.php
6 years ago
Request.php
6 years ago
Server.php
6 years ago
Subject.php
6 years ago
Compatibility.php
398 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 | * Core compatibility with older versions |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Core_Compatibility { |
| 17 | |
| 18 | /** |
| 19 | * Undocumented variable |
| 20 | * |
| 21 | * @var [type] |
| 22 | */ |
| 23 | protected static $instance = null; |
| 24 | |
| 25 | /** |
| 26 | * Compatibility between post actions and policy actions |
| 27 | * |
| 28 | * @param string $action |
| 29 | * @param bool|int $effect |
| 30 | * @param string $prefix |
| 31 | * @param array $meta |
| 32 | * @param array $args |
| 33 | * |
| 34 | * @return array |
| 35 | */ |
| 36 | public static function convertPolicyAction($action, $effect, $prefix = '', $meta = array(), $args = array()) { |
| 37 | $result = array(); |
| 38 | |
| 39 | if (!empty($meta['Password']['Value'])) { |
| 40 | $result = array( |
| 41 | "{$prefix}frontend.password" => $meta['Password']['Value'], |
| 42 | "{$prefix}api.password" => $meta['Password']['Value'], |
| 43 | "{$prefix}frontend.protected" => true, |
| 44 | "{$prefix}api.protected" => true |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | if (!empty($meta['Teaser']['Value'])) { |
| 49 | if (preg_match_all('/(\$\{[^}]+\})/', $meta['Teaser']['Value'], $match)) { |
| 50 | $res = AAM_Core_Policy_Token::evaluate($meta['Teaser']['Value'], $match[1], $args); |
| 51 | } else { |
| 52 | $res = $meta['Teaser']['Value']; |
| 53 | } |
| 54 | |
| 55 | $result = array_merge($result, array( |
| 56 | "{$prefix}frontend.teaser" => $res, |
| 57 | "{$prefix}api.teaser" => $res, |
| 58 | "{$prefix}frontend.limit" => true, |
| 59 | "{$prefix}api.limit" => true |
| 60 | )); |
| 61 | } |
| 62 | |
| 63 | if (!empty($meta['Redirect'])) { |
| 64 | // Build the redirect location |
| 65 | $type = (isset($meta['Redirect']['Type']) ? $meta['Redirect']['Type'] : 'message'); |
| 66 | switch($type) { |
| 67 | case 'page': |
| 68 | if (isset($meta['Redirect']['Id'])) { |
| 69 | $destination = intval($meta['Redirect']['Id']); |
| 70 | } elseif (isset($meta['Redirect']['Slug'])) { |
| 71 | $page = get_page_by_path( |
| 72 | $meta['Redirect']['Slug'], OBJECT |
| 73 | ); |
| 74 | $destination = (is_a($page, 'WP_Post') ? $page->ID : 0); |
| 75 | } |
| 76 | if (isset($meta['Redirect']['Code'])) { |
| 77 | $destination .= "|{$meta['Redirect']['Code']}"; |
| 78 | } else { |
| 79 | $destination .= "|307"; |
| 80 | } |
| 81 | break; |
| 82 | |
| 83 | case 'url': |
| 84 | $destination = filter_var( |
| 85 | $meta['Redirect']['URL'], |
| 86 | FILTER_VALIDATE_URL |
| 87 | ); |
| 88 | if (empty($destination)) { |
| 89 | $type = 'message'; |
| 90 | $destination = "Invalid URL: [{$meta['Redirect']['URL']}]"; |
| 91 | } |
| 92 | if (isset($meta['Redirect']['Code'])) { |
| 93 | $destination .= "|{$meta['Redirect']['Code']}"; |
| 94 | } else { |
| 95 | $destination .= "|307"; |
| 96 | } |
| 97 | break; |
| 98 | |
| 99 | case 'callback': |
| 100 | $destination = $meta['Redirect']['Callback']; |
| 101 | break; |
| 102 | |
| 103 | case 'login': |
| 104 | $destination = null; |
| 105 | break; |
| 106 | |
| 107 | default: |
| 108 | $destination = $meta['Redirect']['Message']; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | $result = array_merge($result, array( |
| 113 | "{$prefix}frontend.redirect" => true, |
| 114 | "{$prefix}frontend.location" => $type . (!empty($destination) ? "|{$destination}" : '') |
| 115 | )); |
| 116 | } |
| 117 | |
| 118 | if (empty($meta)){ |
| 119 | $action = apply_filters('aam-policy-post-resource-action-filter', $action); |
| 120 | |
| 121 | $result = array_merge($result, array( |
| 122 | "{$prefix}frontend.{$action}" => $effect, |
| 123 | "{$prefix}backend.{$action}" => $effect, |
| 124 | "{$prefix}api.{$action}" => $effect |
| 125 | )); |
| 126 | } |
| 127 | |
| 128 | return $result; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Convert config to the Policy Config |
| 133 | * |
| 134 | * @param string $option |
| 135 | * @param mixed $value |
| 136 | * |
| 137 | * @return mixed |
| 138 | * |
| 139 | * @access public |
| 140 | * @static |
| 141 | * @since v5.9 |
| 142 | */ |
| 143 | public static function convertConfig($option, $value) { |
| 144 | if (strpos($option, '.defaultTerm.') !== false && empty($value)) { |
| 145 | $param = AAM_Core_Policy_Factory::get()->getParam( |
| 146 | 'post:default:category' |
| 147 | ); |
| 148 | if (!empty($param)) { |
| 149 | if (!is_numeric($param)) { |
| 150 | $term = get_term_by('slug', $param, 'category'); |
| 151 | $param = (is_wp_error($term) || empty($term) ? null : $term->term_id); |
| 152 | } |
| 153 | } |
| 154 | $value = (is_null($param) ? $value : $param); |
| 155 | } |
| 156 | |
| 157 | return $value; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * |
| 162 | */ |
| 163 | public static function checkConfigPressCompatibility($key) { |
| 164 | if (strpos($key, 'htpasswd') === 0) { |
| 165 | $key = str_replace('htpasswd', 'feature.metabox.htpasswd', $key); |
| 166 | } elseif (strpos($key, 'export') === 0) { |
| 167 | $key = str_replace('export', 'feature.export', $key); |
| 168 | } elseif (strpos($key, 'default.category') === 0) { |
| 169 | $key = str_replace('default.category', 'feature.post.defaultTerm', $key); |
| 170 | } elseif (strpos($key, 'extention') === 0) { |
| 171 | $key = str_replace('extention', 'core.extention', $key); |
| 172 | } elseif (strpos($key, 'login') === 0) { |
| 173 | $key = str_replace('login', 'feature.secureLogin', $key); |
| 174 | } |
| 175 | |
| 176 | return $key; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Converting metabox options from 2 dimensional to 1 |
| 181 | * |
| 182 | * @param array $metaboxes |
| 183 | * |
| 184 | * @return array |
| 185 | * @todo Remove in 2021 |
| 186 | */ |
| 187 | public static function convertMetaboxes($metaboxes) { |
| 188 | $response = array(); |
| 189 | |
| 190 | if (is_array($metaboxes)) { |
| 191 | foreach($metaboxes as $key => $value) { |
| 192 | if (is_array($value)) { |
| 193 | foreach($value as $id => $grand) { |
| 194 | $response["{$key}|{$id}"] = $grand; |
| 195 | } |
| 196 | } else { |
| 197 | $response[$key] = $value; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return $response; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * |
| 207 | * @param type $list |
| 208 | * @return type |
| 209 | * @todo Remove in 2021 |
| 210 | */ |
| 211 | public static function convertRoute($list) { |
| 212 | $response = array(); |
| 213 | |
| 214 | if (is_array($list)) { |
| 215 | foreach($list as $type => $routes) { |
| 216 | if (is_array($routes)) { |
| 217 | foreach($routes as $route => $methods) { |
| 218 | foreach($methods as $method => $grand) { |
| 219 | $response[strtolower("{$type}|{$route}|{$method}")] = $grand; |
| 220 | } |
| 221 | } |
| 222 | } else { |
| 223 | $response[$type] = $routes; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return $response; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Convert all-style AAM settings to standard ConfigPress style settings |
| 233 | * |
| 234 | * @param array $config |
| 235 | * |
| 236 | * @return array |
| 237 | * @since AAM 5.3.1 |
| 238 | * @todo Remove June 1st 2019 |
| 239 | */ |
| 240 | public static function normalizeConfigOptions($config) { |
| 241 | if (is_array($config)) { |
| 242 | $changes = 0; |
| 243 | $changes += self::normalizeOption('manage-capability', 'core.settings.editCapabilities', $config); |
| 244 | $changes += self::normalizeOption('backend-access-control', 'core.settings.backendAccessControl', $config); |
| 245 | $changes += self::normalizeOption('frontend-access-control', 'core.settings.frontendAccessControl', $config); |
| 246 | $changes += self::normalizeOption('api-access-control', 'core.settings.apiAccessControl', $config); |
| 247 | $changes += self::normalizeOption('render-access-metabox', 'ui.settings.renderAccessMetabox', $config); |
| 248 | $changes += self::normalizeOption('show-access-link', 'ui.settings.renderAccessActionLink', $config); |
| 249 | $changes += self::normalizeOption('secure-login', 'core.settings.secureLogin', $config); |
| 250 | $changes += self::normalizeOption('core.xmlrpc', 'core.settings.xmlrpc', $config); |
| 251 | $changes += self::normalizeOption('core.restful', 'core.settings.restful', $config); |
| 252 | $changes += self::normalizeOption('jwt-authentication', 'core.settings.jwtAuthentication', $config); |
| 253 | $changes += self::normalizeOption('ms-member-access', 'core.settings.multisiteMemberAccessControl', $config); |
| 254 | $changes += self::normalizeOption('media-access-control', 'core.settings.mediaAccessControl', $config); |
| 255 | $changes += self::normalizeOption('manage-hidden-post-types', 'core.settings.manageHiddenPostTypes', $config); |
| 256 | $changes += self::normalizeOption('page-category', 'core.settings.pageCategory', $config); |
| 257 | $changes += self::normalizeOption('media-category', 'core.settings.mediaCategory', $config); |
| 258 | $changes += self::normalizeOption('multi-category', 'core.settings.multiCategory', $config); |
| 259 | $changes += self::normalizeOption('login-timeout', 'core.settings.loginTimeout', $config); |
| 260 | $changes += self::normalizeOption('single-session', 'core.settings.singleSession', $config); |
| 261 | $changes += self::normalizeOption('brute-force-lockout', 'core.settings.bruteForceLockout', $config); |
| 262 | $changes += self::normalizeOption('inherit-parent-post', 'core.settings.inheritParentPost', $config); |
| 263 | |
| 264 | if ($changes > 0) { |
| 265 | if (is_multisite()) { |
| 266 | AAM_Core_API::updateOption('aam-utilities', $config, 'site'); |
| 267 | } else { |
| 268 | AAM_Core_API::updateOption('aam-utilities', $config); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return $config; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * |
| 278 | * @param type $option |
| 279 | * @param type $normalizedName |
| 280 | * @param array &$config |
| 281 | * @return int |
| 282 | */ |
| 283 | protected static function normalizeOption($option, $normalizedName, &$config) { |
| 284 | $changed = 0; |
| 285 | |
| 286 | if (array_key_exists($option, $config)) { |
| 287 | $value = $config[$option]; |
| 288 | unset($config[$option]); |
| 289 | $config[$normalizedName] = $value; |
| 290 | $changed = 1; |
| 291 | } |
| 292 | |
| 293 | return $changed; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Get config |
| 298 | * @return type |
| 299 | */ |
| 300 | public static function getConfig() { |
| 301 | $config = AAM_Core_API::getOption('aam-utilities', array(), 'site'); |
| 302 | |
| 303 | foreach(array_keys((is_array($config) ? $config : array())) as $option) { |
| 304 | if (strpos($option, 'frontend.redirect') !== false) { |
| 305 | self::convertConfigOption('redirect', $config, $option); |
| 306 | } elseif (strpos($option, 'backend.redirect') !== false) { |
| 307 | self::convertConfigOption('redirect', $config, $option); |
| 308 | } elseif (strpos($option, 'login.redirect') !== false) { |
| 309 | self::convertConfigOption('loginRedirect', $config, $option); |
| 310 | } elseif (strpos($option, 'frontend.teaser') !== false) { |
| 311 | self::convertConfigOption('teaser', $config, $option); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return self::normalizeConfigOptions($config); |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * |
| 320 | */ |
| 321 | public static function initExtensions() { |
| 322 | //block deprecated extensions from loading |
| 323 | define('AAM_UTILITIES', '99'); |
| 324 | define('AAM_ROLE_FILTER', '99'); |
| 325 | define('AAM_POST_FILTER', '99'); |
| 326 | define('AAM_REDIRECT', '99'); |
| 327 | define('AAM_CONTENT_TEASER', '99'); |
| 328 | define('AAM_LOGIN_REDIRECT', '99'); |
| 329 | define('AAM_CONFIGPRESS', '99'); |
| 330 | //TODO - Remove this in Jul 2019 |
| 331 | |
| 332 | //utilities option |
| 333 | add_filter('aam-utility-property', 'AAM_Core_Config::get', 10, 2); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * |
| 338 | * @return type |
| 339 | */ |
| 340 | public static function getLicenseList() { |
| 341 | $list = AAM_Core_API::getOption('aam-extensions', array(), 'site'); |
| 342 | |
| 343 | if (empty($list)) { |
| 344 | $list = AAM_Core_API::getOption('aam-extension-license', array(), 'site'); |
| 345 | if (!empty($list)) { |
| 346 | $converted = array(); |
| 347 | |
| 348 | foreach($list as $title => $license) { |
| 349 | $id = strtoupper(str_replace(' ', '_', $title)); |
| 350 | $converted[$id] = array('license' => $license); |
| 351 | } |
| 352 | |
| 353 | AAM_Core_API::updateOption('aam-extensions', $converted); |
| 354 | AAM_Core_API::deleteOption('aam-extension-license'); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | return $list; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * |
| 363 | * @staticvar type $subject |
| 364 | * @param type $oid |
| 365 | * @param type &$config |
| 366 | * @param type $option |
| 367 | * |
| 368 | * @todo Legacy remove Jul 2018 |
| 369 | */ |
| 370 | protected static function convertConfigOption($oid, &$config, $option) { |
| 371 | static $subject = null; |
| 372 | |
| 373 | if (is_null($subject)) { |
| 374 | $subject = new AAM_Core_Subject_Default; |
| 375 | } |
| 376 | |
| 377 | $object = $subject->getObject($oid); |
| 378 | |
| 379 | if (is_a($object, 'AAM_Core_Subject')) { |
| 380 | $object->save($option, $config[$option]); |
| 381 | unset($config[$option]); |
| 382 | AAM_Core_API::updateOption('aam-utilities', $config); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Undocumented function |
| 388 | * |
| 389 | * @return void |
| 390 | */ |
| 391 | public static function getInstance() { |
| 392 | if (is_null(self::$instance)) { |
| 393 | self::$instance = new self; |
| 394 | } |
| 395 | |
| 396 | return self::$instance; |
| 397 | } |
| 398 | } |