PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.0
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.0
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 2 years ago
banner.php
244 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( $content->data->notice_body );
81
82 if ( $content->data->notice_image != '' ) {
83 $instance->set_logo( $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' => $content->data->button_text,
91 'url' => $content->data->button_link,
92 )
93 );
94 }
95 $instance->call();
96 }
97
98 private function init_banner( $content, $instance) {
99
100 $html = '<a target="_blank" class="wpmet-jhanda-href" href="' . $content->data->banner_link . '"><img style="display: block;margin: 0 auto;" src="' . $content->data->banner_image . '" /></a>';
101
102 $instance->set_gutter( false )
103 ->set_html( $html )
104 ->call();
105 }
106
107 private function in_whitelist( $conf, $list ) {
108
109 $match = $conf->data->whitelist;
110
111 if ( empty( $match ) ) {
112 return true;
113 };
114
115 $match_arr = explode( ',', $match );
116
117 foreach ( $list as $word ) {
118 if ( in_array( $word, $match_arr ) ) {
119 return true;
120 }
121 }
122
123 return false;
124 }
125
126 private function in_blacklist( $conf, $list ) {
127
128 $match = $conf->data->blacklist;
129
130 if ( empty( $match ) ) {
131 return false;
132 };
133
134 $match_arr = explode( ',', $match );
135
136 foreach ( $match_arr as $idx => $item ) {
137
138 $match_arr[ $idx ] = trim( $item );
139 }
140
141 foreach ( $list as $word ) {
142 if ( in_array( $word, $match_arr ) ) {
143 return true;
144 }
145 }
146
147 return false;
148 }
149
150 public function is_test( $is_test = false ) {
151 if ( $is_test === true ) {
152 $this->check_interval = 1;
153 }
154
155 return $this;
156 }
157
158 public function set_text_domain( $text_domain ) {
159 $this->text_domain = $text_domain;
160
161 return $this;
162 }
163
164 public function set_filter( $filter_string ) {
165 $this->filter_string = $filter_string;
166 if ( ! empty( $filter_string ) ) {
167
168 $filter = explode( ',', $this->filter_string );
169
170 foreach ( $filter as $id => $item ) {
171 $this->filter_array[ $id ] = trim( $item );
172 }
173 }
174
175 return $this;
176 }
177
178 public function set_api_url( $url ) {
179 $this->api_url = $url;
180
181 return $this;
182 }
183
184 public function set_plugin_screens( $screen ) {
185 $this->plugin_screens[] = $screen;
186
187 return $this;
188 }
189
190 private function get_data() {
191 $this->data = get_option( $this->text_domain . '__banner_data' );
192 $this->data = $this->data == '' ? array() : $this->data;
193
194 $this->last_check = get_option( $this->text_domain . '__banner_last_check' );
195 $this->last_check = $this->last_check == '' ? 0 : $this->last_check;
196
197 if ( ( $this->check_interval + $this->last_check ) < time() ) {
198 $response = wp_remote_get(
199 $this->api_url . '/cache/' . $this->text_domain . '.json?nocache=' . time(),
200 array(
201 'timeout' => 10,
202 'httpversion' => '1.1',
203 )
204 );
205
206 if ( ! is_wp_error( $response ) && isset( $response['body'] ) && $response['body'] != '' ) {
207
208 $response = json_decode( $response['body'] );
209
210 if ( ! empty( $response ) ) {
211 $this->data = $response;
212 update_option( $this->text_domain . '__banner_last_check', time() );
213 update_option( $this->text_domain . '__banner_data', $this->data );
214 }
215
216 return;
217 }
218 }
219 }
220
221 public function is_correct_screen_to_show( $b_screen, $screen_id ) {
222
223 if ( in_array( $b_screen, array( $screen_id, 'all_page' ) ) ) {
224 return true;
225 }
226
227 if ( $b_screen == 'plugin_page' ) {
228 return in_array( $screen_id, $this->plugin_screens );
229 }
230
231 return false;
232 }
233
234 private static $instance;
235
236 public static function instance( $text_domain = '' ) {
237
238 self::$instance = new static();
239 return self::$instance->set_text_domain( $text_domain );
240 }
241 }
242
243 endif;
244