PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.2
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.2
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 / stories / stories.php
elementskit-lite / libs / stories Last commit date
views 1 week ago stories.php 1 week ago
stories.php
323 lines
1 <?php
2 namespace Wpmet\Libs;
3
4 defined( 'ABSPATH' ) || exit;
5
6 if ( ! class_exists( '\Wpmet\Libs\Stories' ) ) :
7
8 class Stories {
9
10 protected $script_version = '1.1.1';
11
12 protected $key = 'wpmet_stories';
13 protected $data;
14 protected $title;
15 protected $plugin_link = array();
16 protected $last_check;
17 protected $check_interval = ( 3600 * 6 );
18
19 protected $plugin_screens;
20
21 protected $text_domain;
22 protected $filter_string;
23 protected $api_url;
24
25 private $stories;
26
27 /**
28 * Get version of this script
29 *
30 * @return string Version name
31 */
32 public function get_version() {
33 return $this->script_version;
34 }
35
36 /**
37 * Get current directory path
38 *
39 * @return string
40 */
41 public function get_script_location() {
42 return __FILE__;
43 }
44
45 public function set_plugin( $link_title, $weblink = 'https://wpmet.com/' ) {
46 $this->plugin_link[] = array( $link_title, $weblink );
47
48 return $this;
49 }
50
51 public function call() {
52 add_action( 'wp_dashboard_setup', array( $this, 'show_story_widget' ), 111 );
53 }
54
55 private function in_whitelist( $conf, $list ) {
56
57 $match = $conf->data->whitelist;
58
59 if ( empty( $match ) ) {
60
61 return true;
62 };
63
64 $match_arr = explode( ',', $match );
65
66 foreach ( $list as $word ) {
67 if ( in_array( $word, $match_arr ) ) {
68
69 return true;
70 }
71 }
72
73 return false;
74 }
75
76 private function in_blacklist( $conf, $list ) {
77
78 $match = $conf->data->blacklist;
79
80 if ( empty( $match ) ) {
81
82 return false;
83 };
84
85 $match_arr = explode( ',', $match );
86
87 foreach ( $match_arr as $idx => $item ) {
88
89 $match_arr[ $idx ] = trim( $item );
90 }
91
92 foreach ( $list as $word ) {
93 if ( in_array( $word, $match_arr ) ) {
94
95 return true;
96 }
97 }
98
99 return false;
100 }
101
102 public function set_title( $title = '' ) {
103 $this->title = $title;
104
105 return $this;
106 }
107
108 public function is_test( $is_test = false ) {
109
110 if ( $is_test === true ) {
111 $this->check_interval = 1;
112 }
113
114 return $this;
115 }
116
117 public function set_text_domain( $text_domain ) {
118
119 $this->text_domain = $text_domain;
120
121 return $this;
122 }
123
124 public function set_filter( $filter_string ) {
125
126 $this->filter_string = $filter_string;
127
128 return $this;
129 }
130
131 public function set_api_url( $url ) {
132
133 $this->api_url = $url;
134
135 return $this;
136 }
137
138 public function set_plugin_screens( $screen ) {
139
140 $this->plugin_screens[] = $screen;
141
142 return $this;
143 }
144
145 private function set_stories( $story ) {
146 $filter = array( $this->text_domain );
147 foreach ( get_option( 'active_plugins' ) as $plugin ) {
148 $temp = pathinfo( $plugin );
149 if ( ! empty( $temp ) ) {
150 $filter[] = trim( $temp['filename'] );
151 }
152 }
153
154 if ( isset( $this->stories[ $story->id ] ) ) {
155 return;
156 }
157
158 // if start and endtime is set, check current time is inside the timeframe
159 if ( ( ! empty( $story->start ) && ! empty( $story->end ) ) && ( intval( $story->start ) > time() || intval( $story->end ) < time() ) ) {
160 return;
161 }
162
163 if ( empty( array_intersect( $filter, $story->plugins ) ) ) {
164 return;
165 }
166
167 $this->stories[ $story->id ] = array(
168 'id' => $story->id,
169 'title' => $story->title,
170 'description' => $story->description,
171 'type' => $story->type,
172 'priority' => $story->priority,
173 'story_link' => $story->data->story_link,
174 'story_image' => $story->data->story_image,
175 );
176 }
177
178 private function get_stories() {
179 $this->data = get_option( $this->text_domain . '__stories_data' );
180 $this->data = $this->data == '' ? array() : $this->data;
181
182 $this->last_check = get_option( $this->text_domain . '__stories_last_check' );
183
184 $this->last_check = empty( $this->last_check ) ? 0 : $this->last_check;
185
186 if ( ( $this->check_interval + $this->last_check ) < time() ) {
187 $response = wp_remote_get(
188 $this->api_url . 'cache/stories.json?nocache=' . time(),
189 array(
190 'timeout' => 10,
191 'httpversion' => '1.1',
192 'limit_response_size' => 1024 * 1024,
193 )
194 );
195
196 if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) && '' !== wp_remote_retrieve_body( $response ) ) {
197
198 $response = json_decode( wp_remote_retrieve_body( $response ) );
199
200 if ( ! empty( $response ) ) {
201 $this->data = $response;
202
203 update_option( $this->text_domain . '__stories_last_check', time() );
204 update_option( $this->text_domain . '__stories_data', $this->data );
205 }
206
207 return;
208 }
209 }
210 }
211
212 public function show_story_widget() {
213 $this->get_stories();
214
215 if ( ! empty( $this->data->error ) ) {
216
217 return;
218 }
219
220 if ( empty( $this->data ) ) {
221
222 return;
223 }
224
225 $list = array();
226
227 if ( ! empty( $this->filter_string ) ) {
228
229 $list = explode( ',', $this->filter_string );
230
231 foreach ( $list as $idx => $item ) {
232 $list[ $idx ] = trim( $item );
233 }
234 $list = array_filter( $list );
235 }
236
237 foreach ( $this->data as $story ) {
238
239 if ( ! empty( $list ) && $this->in_blacklist( $story, $list ) ) {
240
241 continue;
242 }
243
244 $this->set_stories( $story );
245 }
246
247 if ( empty( $this->stories ) ) {
248 return;
249 }
250
251 $this->title = ( isset( $this->title ) && ! empty( $this->title ) ? $this->title . ' ' : '' ) . 'Stories';
252
253 wp_add_dashboard_widget( 'wpmet-stories', __( 'Wpmet Stories', 'elementskit-lite' ), array( $this, 'show' ) );
254
255 // Move our widget to top.
256 global $wp_meta_boxes;
257
258 $dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
259 $ours = [];
260 if(isset($dashboard['wpmet-stories'])) {
261 $ours = array(
262 'wpmet-stories' => $dashboard['wpmet-stories'],
263 );
264 }
265
266 $wp_meta_boxes['dashboard']['normal']['core'] = array_merge( $ours, $dashboard );
267 }
268
269 public function show() {
270 usort(
271 $this->stories,
272 function ( $a, $b ) {
273 if ( $a['priority'] == $b['priority'] ) {
274 return 0;
275 }
276 return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
277 }
278 );
279 include_once 'views/template.php';
280 }
281
282 /**
283 * Crosscheck if Story library will be shown at current WP admin page or not
284 *
285 * @param string $b_screen
286 * @param string $screen_id
287 *
288 * @return boolean
289 */
290 public function is_correct_screen_to_show( $b_screen, $screen_id ) {
291
292 if ( in_array( $b_screen, array( $screen_id, 'all_page' ) ) ) {
293
294 return true;
295 }
296
297 if ( $b_screen == 'plugin_page' ) {
298
299 return in_array( $screen_id, $this->plugin_screens );
300 }
301
302 return false;
303 }
304
305 /**
306 * Define singleton instance
307 *
308 * @var [type]
309 */
310 private static $instance;
311
312 public static function instance( $text_domain = '' ) {
313
314 if ( ! self::$instance ) {
315 self::$instance = new static();
316 }
317
318 return self::$instance->set_text_domain( $text_domain );
319 }
320 }
321
322 endif;
323