PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.1
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.1
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / libs / banner / banner.php
elementskit-lite / libs / banner Last commit date
banner.php 3 weeks ago
banner.php
250 lines
1 <?php
2 namespace Wpmet\Libs;
3
4 defined( 'ABSPATH' ) || exit;
5
6 if ( ! class_exists( '\Wpmet\Libs\Banner' ) ) :
7
8 class Banner {
9
10 protected $script_version = '2.2.0';
11
12 protected $key = 'wpmet_banner';
13 protected $data;
14 protected $last_check;
15 protected $check_interval = ( 3600 * 6 );
16
17 protected $plugin_screens;
18
19 protected $text_domain;
20 protected $filter_string;
21 protected $filter_array = array();
22 protected $api_url;
23
24 public function get_version() {
25 return $this->script_version;
26 }
27
28 public function get_script_location() {
29 return __FILE__;
30 }
31
32 public function call() {
33 add_action( 'admin_head', array( $this, 'display_content' ) );
34 }
35
36 public function display_content() {
37 $this->get_data();
38
39 if ( ! empty( $this->data->error ) ) {
40 return;
41 }
42
43 if ( empty( $this->data ) ) {
44 return;
45 }
46
47 foreach ( $this->data as $content ) {
48
49 if ( ! empty( $this->filter_array ) && $this->in_blacklist( $content, $this->filter_array ) ) {
50 continue;
51 }
52
53 if ( $content->start <= time() && time() <= $content->end ) {
54 $screen = get_current_screen();
55 if ( $this->is_correct_screen_to_show( $content->screen, $screen->id ) && class_exists( '\Oxaim\Libs\Notice' ) ) {
56
57 $banner_unique_id = ( ( isset( $content->data->unique_key ) && $content->data->unique_key != '' ) ? $content->data->unique_key : $content->id );
58
59 $instance = \Oxaim\Libs\Notice::instance( 'wpmet-jhanda', $banner_unique_id )
60 ->set_dismiss( 'global', ( 3600 * 24 * 15 ) );
61
62 if ( method_exists( $instance, 'set_style_css' ) && ! empty( $content->data->style_css ) ) {
63 $instance->set_style_css( $content->data->style_css );
64 }
65
66 if ( $content->type == 'banner' ) {
67 $this->init_banner( $content, $instance);
68 }
69
70 if ( $content->type == 'notice' ) {
71 $this->init_notice( $content, $instance);
72 }
73 }
74 }
75 }
76 }
77
78 private function init_notice( $content, $instance) {
79
80 $instance->set_message( \ElementsKit_Lite\Utils::kses( $content->data->notice_body ) );
81
82 if ( $content->data->notice_image != '' ) {
83 $instance->set_logo( esc_url_raw( $content->data->notice_image ) );
84 }
85 if ( $content->data->button_text != '' ) {
86 $instance->set_button(
87 array(
88 'default_class' => 'button',
89 'class' => 'button-secondary button-small', // button-primary button-secondary button-small button-large button-link
90 'text' => sanitize_text_field( $content->data->button_text ),
91 'url' => esc_url_raw( $content->data->button_link ),
92 )
93 );
94 }
95 $instance->call();
96 }
97
98 private function init_banner( $content, $instance) {
99
100 $html = sprintf(
101 '<a target="_blank" rel="noopener noreferrer" class="wpmet-jhanda-href" href="%1$s"><img style="display: block;margin: 0 auto;" src="%2$s" alt=" %3$s " /></a>',
102 esc_url( $content->data->banner_link ),
103 esc_url( $content->data->banner_image ),
104 esc_attr( 'Public Jhanda' )
105 );
106
107 $instance->set_gutter( false )
108 ->set_html( \ElementsKit_Lite\Utils::kses( $html ) )
109 ->call();
110 }
111
112 private function in_whitelist( $conf, $list ) {
113
114 $match = $conf->data->whitelist;
115
116 if ( empty( $match ) ) {
117 return true;
118 };
119
120 $match_arr = explode( ',', $match );
121
122 foreach ( $list as $word ) {
123 if ( in_array( $word, $match_arr ) ) {
124 return true;
125 }
126 }
127
128 return false;
129 }
130
131 private function in_blacklist( $conf, $list ) {
132
133 $match = $conf->data->blacklist;
134
135 if ( empty( $match ) ) {
136 return false;
137 };
138
139 $match_arr = explode( ',', $match );
140
141 foreach ( $match_arr as $idx => $item ) {
142
143 $match_arr[ $idx ] = trim( $item );
144 }
145
146 foreach ( $list as $word ) {
147 if ( in_array( $word, $match_arr ) ) {
148 return true;
149 }
150 }
151
152 return false;
153 }
154
155 public function is_test( $is_test = false ) {
156 if ( $is_test === true ) {
157 $this->check_interval = 1;
158 }
159
160 return $this;
161 }
162
163 public function set_text_domain( $text_domain ) {
164 $this->text_domain = $text_domain;
165
166 return $this;
167 }
168
169 public function set_filter( $filter_string ) {
170 $this->filter_string = $filter_string;
171 if ( ! empty( $filter_string ) ) {
172
173 $filter = explode( ',', $this->filter_string );
174
175 foreach ( $filter as $id => $item ) {
176 $this->filter_array[ $id ] = trim( $item );
177 }
178 }
179
180 return $this;
181 }
182
183 public function set_api_url( $url ) {
184 $this->api_url = $url;
185
186 return $this;
187 }
188
189 public function set_plugin_screens( $screen ) {
190 $this->plugin_screens[] = $screen;
191
192 return $this;
193 }
194
195 private function get_data() {
196 $this->data = get_option( $this->text_domain . '__banner_data' );
197 $this->data = $this->data == '' ? array() : $this->data;
198
199 $this->last_check = get_option( $this->text_domain . '__banner_last_check' );
200 $this->last_check = $this->last_check == '' ? 0 : $this->last_check;
201
202 if ( ( $this->check_interval + $this->last_check ) < time() ) {
203 $response = wp_remote_get(
204 $this->api_url . '/cache/' . $this->text_domain . '.json?nocache=' . time(),
205 array(
206 'timeout' => 10,
207 'httpversion' => '1.1',
208 'limit_response_size' => 1024 * 1024,
209 )
210 );
211
212 if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) && '' !== wp_remote_retrieve_body( $response ) ) {
213
214 $response = json_decode( wp_remote_retrieve_body( $response ) );
215
216 if ( ! empty( $response ) ) {
217 $this->data = $response;
218 update_option( $this->text_domain . '__banner_last_check', time() );
219 update_option( $this->text_domain . '__banner_data', $this->data );
220 }
221
222 return;
223 }
224 }
225 }
226
227 public function is_correct_screen_to_show( $b_screen, $screen_id ) {
228
229 if ( in_array( $b_screen, array( $screen_id, 'all_page' ) ) ) {
230 return true;
231 }
232
233 if ( $b_screen == 'plugin_page' ) {
234 return in_array( $screen_id, $this->plugin_screens );
235 }
236
237 return false;
238 }
239
240 private static $instance;
241
242 public static function instance( $text_domain = '' ) {
243
244 self::$instance = new static();
245 return self::$instance->set_text_domain( $text_domain );
246 }
247 }
248
249 endif;
250