/var/www/html_us/wp-content/plugins/elementor/includes/conditions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Elementor;

if ( ! 
defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly.
}

/**
 * Elementor conditions.
 *
 * Elementor conditions handler class introduce the compare conditions and the
 * check conditions methods.
 *
 * @since 1.0.0
 */
class Conditions {

    
/**
     * Compare conditions.
     *
     * Whether the two values comply the comparison operator.
     *
     * @since 1.0.0
     * @access public
     * @static
     *
     * @param mixed  $left_value  First value to compare.
     * @param mixed  $right_value Second value to compare.
     * @param string $operator    Comparison operator.
     *
     * @return bool Whether the two values complies the comparison operator.
     */
    
public static function compare$left_value$right_value$operator ) {
        switch ( 
$operator ) {
            case 
'==':
                return 
$left_value == $right_value;
            case 
'!=':
                return 
$left_value != $right_value;
            case 
'!==':
                return 
$left_value !== $right_value;
            case 
'in':
                return 
in_array$left_value$right_valuetrue );
            case 
'!in':
                return ! 
in_array$left_value$right_valuetrue );
            case 
'contains':
                return 
in_array$right_value$left_valuetrue );
            case 
'!contains':
                return ! 
in_array$right_value$left_valuetrue );
            case 
'<':
                return 
$left_value $right_value;
            case 
'<=':
                return 
$left_value <= $right_value;
            case 
'>':
                return 
$left_value $right_value;
            case 
'>=':
                return 
$left_value >= $right_value;
            default:
                return 
$left_value === $right_value;
        }
    }

    
/**
     * Check conditions.
     *
     * Whether the comparison conditions comply.
     *
     * @since 1.0.0
     * @access public
     * @static
     *
     * @param array $conditions The conditions to check.
     * @param array $comparison The comparison parameter.
     *
     * @return bool Whether the comparison conditions comply.
     */
    
public static function check( array $conditions, array $comparison ) {
        
$is_or_condition = isset( $conditions['relation'] ) && 'or' === $conditions['relation'];

        
$condition_succeed = ! $is_or_condition;

        foreach ( 
$conditions['terms'] as $term ) {
            if ( ! empty( 
$term['terms'] ) ) {
                
$comparison_result self::check$term$comparison );
            } else {
                
preg_match'/(\w+)(?:\[(\w+)])?/'$term['name'], $parsed_name );

                
$value $comparison$parsed_name[1] ];

                if ( ! empty( 
$parsed_name[2] ) ) {
                    
$value $value$parsed_name[2] ];
                }

                
$operator null;

                if ( ! empty( 
$term['operator'] ) ) {
                    
$operator $term['operator'];
                }

                
$comparison_result self::compare$value$term['value'], $operator );
            }

            if ( 
$is_or_condition ) {
                if ( 
$comparison_result ) {
                    return 
true;
                }
            } elseif ( ! 
$comparison_result ) {
                return 
false;
            }
        }

        return 
$condition_succeed;
    }
}