/var/www/html_us/wp-content/plugins/elementor/modules/notifications/api.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
namespace Elementor\Modules\Notifications;

use 
Elementor\User;

class 
API {

    const 
NOTIFICATIONS_URL 'https://assets.elementor.com/notifications/v1/notifications.json';

    public static function 
get_notifications_by_conditions$force_request false ) {
        
$notifications = static::get_notifications$force_request );

        
$filtered_notifications = [];

        foreach ( 
$notifications as $notification ) {
            if ( empty( 
$notification['conditions'] ) ) {
                
$filtered_notifications = static::add_to_array$filtered_notifications$notification );

                continue;
            }

            if ( ! static::
check_conditions$notification['conditions'] ) ) {
                continue;
            }

            
$filtered_notifications = static::add_to_array$filtered_notifications$notification );
        }

        return 
$filtered_notifications;
    }

    private static function 
get_notifications$force_request false ) {
        
$notifications self::get_transient'_elementor_notifications_data' );

        if ( 
$force_request || false === $notifications ) {
            
$notifications = static::fetch_data();

            static::
set_transient'_elementor_notifications_data'$notifications'+1 hour' );
        }

        
$notifications apply_filters'elementor/core/admin/notifications'$notifications );

        return 
$notifications;
    }

    private static function 
fetch_data() : array {
        
$response wp_remote_getself::NOTIFICATIONS_URL );

        if ( 
is_wp_error$response ) ) {
            return [];
        }

        
$data json_decodewp_remote_retrieve_body$response ), true );

        if ( empty( 
$data['notifications'] ) || ! is_array$data['notifications'] ) ) {
            return [];
        }

        return 
$data['notifications'];
    }

    private static function 
add_to_array$filtered_notifications$notification ) {
        foreach ( 
$filtered_notifications as $filtered_notification ) {
            if ( 
$filtered_notification['id'] === $notification['id'] ) {
                return 
$filtered_notifications;
            }
        }

        
$filtered_notifications[] = $notification;

        return 
$filtered_notifications;
    }

    private static function 
check_conditions$groups ) {
        foreach ( 
$groups as $group ) {
            if ( static::
check_group$group ) ) {
                return 
true;
            }
        }

        return 
false;
    }

    private static function 
check_group$group ) {
        
$is_or_relation = ! empty( $group['relation'] ) && 'OR' === $group['relation'];
        unset( 
$group['relation'] );
        
$result false;

        foreach ( 
$group as $condition ) {
            
// Reset results for each condition.
            
$result false;
            switch ( 
$condition['type'] ) {
                case 
'wordpress'// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
                    // include an unmodified $wp_version
                    
include ABSPATH WPINC '/version.php';
                    
$result version_compare$wp_version$condition['version'], $condition['operator'] );
                    break;
                case 
'multisite':
                    
$result is_multisite() === $condition['multisite'];
                    break;
                case 
'language':
                    
$in_array in_arrayget_locale(), $condition['languages'], true );
                    
$result 'in' === $condition['operator'] ? $in_array : ! $in_array;
                    break;
                case 
'plugin':
                    if ( ! 
function_exists'is_plugin_active' ) ) {
                        require_once( 
ABSPATH 'wp-admin/includes/plugin.php' );
                    }

                    
$is_plugin_active is_plugin_active$condition['plugin'] );

                    if ( empty( 
$condition['operator'] ) ) {
                        
$condition['operator'] = '==';
                    }

                    
$result '==' === $condition['operator'] ? $is_plugin_active : ! $is_plugin_active;
                    break;
                case 
'theme':
                    
$theme wp_get_theme();
                    if ( 
wp_get_theme()->parent() ) {
                        
$theme wp_get_theme()->parent();
                    }

                    if ( 
$theme->get_template() === $condition['theme'] ) {
                        
$version $theme->version;
                    } else {
                        
$version '';
                    }

                    
$result version_compare$version$condition['version'], $condition['operator'] );
                    break;
                case 
'introduction_meta':
                    
$result User::get_introduction_meta$condition['meta'] );
                    break;

                default:
                    
/**
                     * Filters the notification condition, whether to check the group or not.
                     *
                     * The dynamic portion of the hook name, `$condition['type']`, refers to the condition type.
                     *
                     * @since 3.19.0
                     *
                     * @param bool  $result    Whether to check the group.
                     * @param array $condition Notification condition.
                     */
                    
$result apply_filters"elementor/notifications/condition/{$condition['type']}"$result$condition );
                    break;
            }

            if ( ( 
$is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) {
                return 
$result;
            }
        }

        return 
$result;
    }

    private static function 
get_transient$cache_key ) {
        
$cache get_option$cache_key );

        if ( empty( 
$cache['timeout'] ) ) {
            return 
false;
        }

        if ( 
current_time'timestamp' ) > $cache['timeout'] ) {
            return 
false;
        }

        return 
json_decode$cache['value'], true );
    }

    private static function 
set_transient$cache_key$value$expiration '+12 hours' ) {
        
$data = [
            
'timeout' => strtotime$expirationcurrent_time'timestamp' ) ),
            
'value' => json_encode$value ),
        ];

        return 
update_option$cache_key$datafalse );
    }
}