acf-boolean.php
7 months ago
acf-choice.php
7 months ago
acf-text.php
7 months ago
browser.php
7 months ago
condition.php
7 months ago
date-range.php
7 months ago
date.php
7 months ago
day.php
7 months ago
device.php
7 months ago
ip-location.php
7 months ago
lang.php
7 months ago
login-status.php
7 months ago
operating-system.php
7 months ago
page.php
7 months ago
post-category.php
7 months ago
post-format.php
7 months ago
post-type.php
7 months ago
post.php
7 months ago
return-visitor.php
7 months ago
shortcode.php
7 months ago
static-page.php
7 months ago
time-range.php
7 months ago
url-referer.php
7 months ago
url-string.php
7 months ago
user-role.php
7 months ago
woo-cart-products.php
7 months ago
woo-cat-page.php
7 months ago
woo-category.php
7 months ago
woo-last-purchase.php
7 months ago
woo-orders.php
7 months ago
woo-product-cat.php
7 months ago
woo-product-price.php
7 months ago
woo-product-stock.php
7 months ago
woo-purchase-products.php
7 months ago
woo-total-price.php
7 months ago
operating-system.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Operating System Condition Handler. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes\PA_Display_Conditions\Conditions; |
| 7 | |
| 8 | // Elementor Classes. |
| 9 | use Elementor\Controls_Manager; |
| 10 | |
| 11 | // PA Classes. |
| 12 | use PremiumAddons\Includes\Helper_Functions; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly. |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Operating System |
| 20 | */ |
| 21 | class Operating_System extends Condition { |
| 22 | |
| 23 | /** |
| 24 | * Get Controls Options. |
| 25 | * |
| 26 | * @access public |
| 27 | * @since 4.7.0 |
| 28 | * |
| 29 | * @return array|void controls options |
| 30 | */ |
| 31 | public function get_control_options() { |
| 32 | |
| 33 | return array( |
| 34 | 'label' => __( 'Value', 'premium-addons-for-elementor' ), |
| 35 | 'type' => Controls_Manager::SELECT2, |
| 36 | 'default' => array( 'windows' ), |
| 37 | 'label_block' => true, |
| 38 | 'options' => array( |
| 39 | 'windows' => __( 'Windows', 'premium-addons-for-elementor' ), |
| 40 | 'mac_os' => __( 'Mac OS', 'premium-addons-for-elementor' ), |
| 41 | 'linux' => __( 'Linux', 'premium-addons-for-elementor' ), |
| 42 | 'iphone' => __( 'iPhone', 'premium-addons-for-elementor' ), |
| 43 | 'android' => __( 'Android', 'premium-addons-for-elementor' ), |
| 44 | 'blackberry' => __( 'BlackBerry', 'premium-addons-for-elementor' ), |
| 45 | 'open_bsd' => __( 'OpenBSD', 'premium-addons-for-elementor' ), |
| 46 | 'sun_os' => __( 'SunOS', 'premium-addons-for-elementor' ), |
| 47 | 'qnx' => __( 'QNX', 'premium-addons-for-elementor' ), |
| 48 | 'beos' => __( 'BeOS', 'premium-addons-for-elementor' ), |
| 49 | 'os2' => __( 'OS/2', 'premium-addons-for-elementor' ), |
| 50 | ), |
| 51 | 'multiple' => true, |
| 52 | 'condition' => array( |
| 53 | 'pa_condition_key' => 'operating_system', |
| 54 | ), |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Compare Condition Value. |
| 60 | * |
| 61 | * @access public |
| 62 | * @since 4.7.0 |
| 63 | * |
| 64 | * @param array $settings element settings. |
| 65 | * @param string $operator condition operator. |
| 66 | * @param string $value condition value. |
| 67 | * @param string $compare_val compare value. |
| 68 | * @param string|bool $tz time zone. |
| 69 | * |
| 70 | * @return bool|void |
| 71 | */ |
| 72 | public function compare_value( $settings, $operator, $value, $compare_val, $tz ) { |
| 73 | |
| 74 | $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; |
| 75 | |
| 76 | $os_list = array( |
| 77 | 'windows' => '(Win16)|(Windows 95)|(Win95)|(Windows_95)|(Windows 98)|(Win98)|(Windows NT 5.0)|(Windows 2000)|(Windows NT 5.1)|(Windows XP)|(Windows NT 5.2)|(Windows NT 6.0)|(Windows Vista)|(Windows NT 6.1)|(Windows 7)|(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)|(Windows ME)', |
| 78 | 'mac_os' => '(Mac_PowerPC)|(Macintosh)|(mac os x)', |
| 79 | 'linux' => '(Linux)|(X11)', |
| 80 | 'iphone' => 'iPhone', |
| 81 | 'android' => '(Android)', |
| 82 | 'blackberry' => 'BlackBerry', |
| 83 | 'open_bsd' => 'OpenBSD', |
| 84 | 'sun_os' => 'SunOS', |
| 85 | 'qnx' => 'QNX', |
| 86 | 'beos' => 'BeOS', |
| 87 | ); |
| 88 | |
| 89 | $current_os = array(); |
| 90 | |
| 91 | foreach ( $os_list as $key => $key_val ) { |
| 92 | |
| 93 | $match = preg_match( '/' . $key_val . '/i', $user_agent ); |
| 94 | |
| 95 | if ( $match ) { |
| 96 | array_push( $current_os, $key ); |
| 97 | |
| 98 | // We need to remove mac_os if iPhone is the current OS, and Linux if Android is the current OS |
| 99 | if ( 'iphone' === $key ) { |
| 100 | array_shift( $current_os ); |
| 101 | } elseif ( 'android' === $key ) { |
| 102 | array_shift( $current_os ); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | $result = ! empty( array_intersect( $value, $current_os ) ) ? true : false; |
| 108 | |
| 109 | return Helper_Functions::get_final_result( $result, $operator ); |
| 110 | } |
| 111 | } |
| 112 |