acf-boolean.php
4 years ago
acf-choice.php
4 years ago
acf-text.php
4 years ago
browser.php
4 years ago
condition.php
4 years ago
date-range.php
4 years ago
date.php
4 years ago
day.php
4 years ago
device.php
4 years ago
ip-location.php
4 years ago
lang.php
4 years ago
login-status.php
4 years ago
operating-system.php
4 years ago
page.php
4 years ago
post-type.php
4 years ago
post.php
4 years ago
time-range.php
4 years ago
url-referer.php
4 years ago
user-role.php
4 years ago
woo-cat-page.php
4 years ago
woo-category.php
4 years ago
woo-last-purchase.php
4 years ago
woo-orders.php
4 years ago
woo-product-cat.php
4 years ago
woo-product-price.php
4 years ago
woo-product-stock.php
4 years ago
woo-total-price.php
4 years ago
browser.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Browser 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 Browser |
| 20 | */ |
| 21 | class Browser 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' => 'chrome', |
| 37 | 'label_block' => true, |
| 38 | 'options' => array( |
| 39 | 'opera' => __( 'Opera', 'premium-addons-for-elementor' ), |
| 40 | 'edge' => __( 'Microsoft Edge', 'premium-addons-for-elementor' ), |
| 41 | 'chrome' => __( 'Google Chrome', 'premium-addons-for-elementor' ), |
| 42 | 'safari' => __( 'Safari', 'premium-addons-for-elementor' ), |
| 43 | 'firefox' => __( 'Mozilla Firefox', 'premium-addons-for-elementor' ), |
| 44 | 'ie' => __( 'Internet Explorer', 'premium-addons-for-elementor' ), |
| 45 | ), |
| 46 | 'multiple' => true, |
| 47 | 'condition' => array( |
| 48 | 'pa_condition_key' => 'browser', |
| 49 | ), |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Compare Condition Value. |
| 55 | * |
| 56 | * @access public |
| 57 | * @since 4.7.0 |
| 58 | * |
| 59 | * @param array $settings element settings. |
| 60 | * @param string $operator condition operator. |
| 61 | * @param string $value condition value. |
| 62 | * @param string $compare_val compare value. |
| 63 | * @param string|bool $tz time zone. |
| 64 | * |
| 65 | * @return bool|void |
| 66 | */ |
| 67 | public function compare_value( $settings, $operator, $value, $compare_val, $tz ) { |
| 68 | |
| 69 | $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ), FILTER_SANITIZE_STRING ) : ''; |
| 70 | |
| 71 | $user_agent = $this->get_browser_name( $user_agent ); |
| 72 | |
| 73 | $condition_result = is_array( $value ) && ! empty( $value ) ? in_array( $user_agent, $value, true ) : $value === $user_agent; |
| 74 | |
| 75 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 76 | |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get Browser Name. |
| 81 | * |
| 82 | * @since 4.4.8 |
| 83 | * @access private |
| 84 | * |
| 85 | * @param string $user_agent user agent. |
| 86 | * |
| 87 | * @return array browser name. |
| 88 | */ |
| 89 | private static function get_browser_name( $user_agent ) { |
| 90 | |
| 91 | if ( strpos( $user_agent, 'Opera' ) || strpos( $user_agent, 'OPR/' ) ) { |
| 92 | return 'opera'; |
| 93 | } elseif ( strpos( $user_agent, 'Edg' ) || strpos( $user_agent, 'Edge' ) ) { |
| 94 | return 'edge'; |
| 95 | } elseif ( strpos( $user_agent, 'Chrome' ) ) { |
| 96 | return 'chrome'; |
| 97 | } elseif ( strpos( $user_agent, 'Safari' ) ) { |
| 98 | return 'safari'; |
| 99 | } elseif ( strpos( $user_agent, 'Firefox' ) ) { |
| 100 | return 'firefox'; |
| 101 | } elseif ( strpos( $user_agent, 'MSIE' ) || strpos( $user_agent, 'Trident/7' ) ) { |
| 102 | return 'ie'; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | } |
| 107 |