PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.1
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.1
4.3.2 4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 All 165 releases
← All changes | Inc/Classes/Pro_Upgrade.php +383 -413 4.1.17 → 3.2.4.1 View file →
@@ -3,154 +3,182 @@
3 3 namespace WPAdminify\Inc\Classes;
4 4
5 5 use WPAdminify\Inc\Classes\Helper;
6 6 use WPAdminify\Inc\Classes\Notifications\Base\Date;
7 +
8 +
7 9 // No, Direct access Sir !!!
8 -if ( !defined( 'ABSPATH' ) ) {
9 - exit;
10 +if (!defined('ABSPATH')) {
11 + exit;
10 12 }
13 +
11 14 /**
12 15 * Upgrade to Pro Class
13 16 *
14 17 * Jewel Theme <[email protected]>
15 18 */
16 -class Pro_Upgrade {
17 - use Date;
18 - public $slug;
19 +class Pro_Upgrade
20 +{
19 21
20 - protected $data = array();
22 + use Date;
21 23
22 - /**
23 - * Construct method
24 - */
25 - public function __construct() {
26 - $this->slug = Helper::jltwp_adminify_slug_cleanup();
27 - $this->maybe_sync_remote_data();
28 - $this->register_sync_hook();
29 - $this->set_data();
30 - add_action( 'admin_footer', array($this, 'display_popup') );
31 - add_action( 'wp_dashboard_setup', array($this, 'dashboard_widget') );
32 - add_action( 'wp_network_dashboard_setup', array($this, 'dashboard_widget') );
33 - }
24 + public $slug;
34 25
35 - /**
36 - * Register Dashboard widget
37 - *
38 - * @return void
39 - * @author Jewel Theme <[email protected]>
40 - */
41 - public function dashboard_widget() {
42 - wp_add_dashboard_widget(
43 - 'jltwp_adminify_dashboard_widget',
44 - // Widget slug.
45 - esc_html__( 'Adminify News & Updates', 'adminify' ),
46 - // Title.
47 - array($this, 'dashboard_widget_render')
48 - );
49 - // Globalize the metaboxes array, this holds all the widgets for wp-admin.
50 - global $wp_meta_boxes;
51 - // Get the regular dashboard widgets array
52 - // (which already has our new widget but appended at the end).
53 - if ( is_network_admin() ) {
54 - $default_dashboard = $wp_meta_boxes['dashboard-network']['normal']['core'];
55 - } else {
56 - $default_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
57 - }
58 - // Backup and delete our new dashboard widget from the end of the array.
59 - $example_widget_backup = array(
60 - 'jltwp_adminify_dashboard_widget' => $default_dashboard['jltwp_adminify_dashboard_widget'],
61 - );
62 - unset($default_dashboard['jltwp_adminify_dashboard_widget']);
63 - // Merge the two arrays together so our widget is at the beginning.
64 - $sorted_dashboard = array_merge( $example_widget_backup, $default_dashboard );
65 - // Save the sorted array back into the original metaboxes .
66 - if ( is_network_admin() ) {
67 - $wp_meta_boxes['dashboard-network']['normal']['core'] = $sorted_dashboard;
68 - } else {
69 - $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
70 - }
71 - }
26 + protected $data = array();
72 27
73 - /**
74 - * Render dashboard widget
75 - *
76 - * @author Jewel Theme <[email protected]>
77 - */
78 - public function dashboard_widget_render() {
79 - include_once ABSPATH . WPINC . '/feed.php';
80 - $feed_url = 'https://jeweltheme.com/feed.xml';
81 - // Get a SimplePie feed object from the specified feed source .
82 - $rss = fetch_feed( $feed_url );
83 - $maxitems = 0;
84 - if ( !is_wp_error( $rss ) ) {
85 - // Checks that the object is created correctly .
86 - // Figure out how many total items there are, and choose a limit .
87 - $maxitems = $rss->get_item_quantity( 5 );
88 - // Build an array of all the items, starting with element 0 (first element).
89 - $rss_items = $rss->get_items( 0, $maxitems );
90 - // Get RSS title .
91 - $rss_title = '<a href="' . $rss->get_permalink() . '" target="_blank">' . strtoupper( $rss->get_title() ) . '</a>';
92 - }
93 - // Display the container .
94 - echo '<div class="wp-adminify-rss-widget">';
95 - if ( wp_validate_boolean( $this->get_content( 'is_live' ) ) ) {
96 - ?>
28 + protected $modes = array(
29 + 'development' => array(
30 + 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q',
31 + 'tab_id' => 0,
32 + ),
33 + 'production' => array(
34 + 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q',
35 + 'tab_id' => 0,
36 + ),
37 + );
97 38
98 - <div class="wp-adminify-dashboard-promo" style="--wp-adminify-popup-color: <?php
99 - echo esc_attr( $this->get_content( 'btn_color' ) );
100 - ?>;">
101 - <a target="_blank" href="<?php
102 - echo esc_url( $this->get_content( 'button_url' ) );
103 - ?>">
104 - <img src="<?php
105 - echo esc_url( $this->get_content( 'image_url' ) );
106 - ?>" alt="Adminify Promo Image" style="width: 100%; height: auto;">
39 + /**
40 + * Construct method
41 + */
42 + public function __construct()
43 + {
44 + $this->slug = Helper::jltwp_adminify_slug_cleanup();
45 +
46 + $this->maybe_sync_remote_data();
47 + $this->register_sync_hook();
48 + $this->set_data();
49 +
50 + add_action('admin_footer', array($this, 'display_popup'));
51 +
52 + add_action('wp_dashboard_setup', array($this, 'dashboard_widget'));
53 + add_action('wp_network_dashboard_setup', array($this, 'dashboard_widget'));
54 + }
55 +
56 + /**
57 + * Register Dashboard widget
58 + *
59 + * @return void
60 + * @author Jewel Theme <[email protected]>
61 + */
62 + public function dashboard_widget()
63 + {
64 + wp_add_dashboard_widget(
65 + 'jltwp_adminify_dashboard_widget', // Widget slug.
66 + esc_html__('WP Adminify News & Updates', 'adminify'), // Title.
67 + array($this, 'dashboard_widget_render') // Display function.
68 + );
69 +
70 + // Globalize the metaboxes array, this holds all the widgets for wp-admin.
71 + global $wp_meta_boxes;
72 +
73 + // Get the regular dashboard widgets array
74 + // (which already has our new widget but appended at the end).
75 +
76 + if (is_network_admin()) {
77 + $default_dashboard = $wp_meta_boxes['dashboard-network']['normal']['core'];
78 + } else {
79 + $default_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
80 + }
81 +
82 + // Backup and delete our new dashboard widget from the end of the array.
83 + $example_widget_backup = array('jltwp_adminify_dashboard_widget' => $default_dashboard['jltwp_adminify_dashboard_widget']);
84 + unset($default_dashboard['jltwp_adminify_dashboard_widget']);
85 +
86 + // Merge the two arrays together so our widget is at the beginning.
87 + $sorted_dashboard = array_merge($example_widget_backup, $default_dashboard);
88 +
89 + // Save the sorted array back into the original metaboxes .
90 + if (is_network_admin()) {
91 + $wp_meta_boxes['dashboard-network']['normal']['core'] = $sorted_dashboard;
92 + } else {
93 + $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
94 + }
95 + }
96 +
97 + /**
98 + * Render dashboard widget
99 + *
100 + * @author Jewel Theme <[email protected]>
101 + */
102 + public function dashboard_widget_render()
103 + {
104 + include_once ABSPATH . WPINC . '/feed.php';
105 +
106 + $feed_url = 'https://jeweltheme.com/feed.xml';
107 +
108 + // Get a SimplePie feed object from the specified feed source .
109 + $rss = fetch_feed($feed_url);
110 + $maxitems = 0;
111 +
112 + if (!is_wp_error($rss)) { // Checks that the object is created correctly .
113 + // Figure out how many total items there are, and choose a limit .
114 + $maxitems = $rss->get_item_quantity(5);
115 +
116 + // Build an array of all the items, starting with element 0 (first element).
117 + $rss_items = $rss->get_items(0, $maxitems);
118 +
119 + // Get RSS title .
120 + $rss_title = '<a href="' . $rss->get_permalink() . '" target="_blank">' . strtoupper($rss->get_title()) . '</a>';
121 + }
122 +
123 + // Display the container .
124 + echo '<div class="wp-adminify-rss-widget">';
125 +
126 + if (wp_validate_boolean($this->get_content('is_campaign'))) { ?>
127 +
128 + <div class="wp-adminify-dashboard-promo" style="--wp-adminify-popup-color: <?php echo esc_attr($this->get_content('btn_color')); ?>;">
129 + <a target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>">
130 + <img src="<?php echo esc_url($this->get_content('image_url')); ?>" alt="WP Adminify Promo Image" style="width: 100%; height: auto;">
107 131 </a>
108 132
109 - <a class="wp-adminify-popup-button" style="color: #fff!important;" target="_blank" href="<?php
110 - echo esc_url( $this->get_content( 'button_url' ) );
111 - ?>">
112 - <?php
113 - echo esc_html( $this->get_content( 'button_text' ) );
114 - ?>
133 + <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>">
134 + <?php
135 + if (jltwp_adminify()->can_use_premium_code()) {
136 + echo esc_html__('Upgrade Now', 'adminify');
137 + } else {
138 + echo esc_html($this->get_content('button_text'));
139 + } ?>
115 140 </a>
116 141 </div>
117 142
118 - <?php
119 - }
120 - // Starts items listing within <ul> tag
121 - // Check items .
122 - if ( !empty( $maxitems ) ) {
123 - echo '<ul>';
124 - // Loop through each feed item and display each item as a hyperlink.
125 - foreach ( $rss_items as $item ) {
126 - // Uncomment line below to display non human date
127 - // $item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); .
128 - // Get human date (comment if you want to use non human date) .
129 - // $item_date = human_time_diff( $item->get_date( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'adminify' );
130 - // Start displaying item content within a <li> tag .
131 - echo '<li>';
132 - // create item link .
133 - echo '<a href="' . esc_url( $item->get_permalink() ) . '" title="' . esc_attr( $item->get_title() ) . '" target="_blank">';
134 - // Get item title .
135 - echo esc_html( $item->get_title() );
136 - echo '</a>';
137 - // Display date .
138 - // echo ' <span class="rss-date">' . esc_html( $item_date ) . '</span><br />';
139 - // Get item content .
140 - $content = $item->get_content();
141 - // Shorten content .
142 - $content = wp_html_excerpt( $content, 120 ) . ' ';
143 - // Display content .
144 - echo esc_html( $content );
145 - // End <li> tag .
146 - echo '</li>';
147 - }
148 - echo '</ul>';
149 - // End <ul> tag .
150 - }
151 - ?>
143 + <?php
144 + }
152 145
146 + // Starts items listing within <ul> tag
147 + // Check items .
148 + if (!empty($maxitems)) {
149 + echo '<ul>';
150 + // Loop through each feed item and display each item as a hyperlink.
151 + foreach ($rss_items as $item) {
152 + // Uncomment line below to display non human date
153 + // $item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); .
154 +
155 + // Get human date (comment if you want to use non human date) .
156 + // $item_date = human_time_diff( $item->get_date( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'adminify' );
157 +
158 + // Start displaying item content within a <li> tag .
159 + echo '<li>';
160 + // create item link .
161 + echo '<a href="' . esc_url($item->get_permalink()) . '" title="' . esc_attr($item->get_title()) . '" target="_blank">';
162 + // Get item title .
163 + echo esc_html($item->get_title());
164 + echo '</a>';
165 + // Display date .
166 + // echo ' <span class="rss-date">' . esc_html( $item_date ) . '</span><br />';
167 + // Get item content .
168 + $content = $item->get_content();
169 + // Shorten content .
170 + $content = wp_html_excerpt($content, 120) . ' ';
171 + // Display content .
172 + echo esc_html($content);
173 + // End <li> tag .
174 + echo '</li>';
175 + }
176 + echo '</ul>';
177 + // End <ul> tag .
178 + }
179 + ?>
180 +
153 181 <div class="wp-adminify-dashboard_footer">
154 182 <ul>
155 183 <li class="wp-adminify-overview__blog">
156 184 <a href="https://wpadminify.com/blog" target="_blank">
@@ -155,11 +183,9 @@
155 183 <li class="wp-adminify-overview__blog">
156 184 <a href="https://wpadminify.com/blog" target="_blank">
157 185 Blog
158 186 <span class="screen-reader-text">
159 - <?php
160 - echo esc_html__( '(opens in a new window)', 'adminify' );
161 - ?>
187 + <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
162 188 </span>
163 189 <span aria-hidden="true" class="dashicons dashicons-external"></span>
164 190 </a>
165 191 </li>
@@ -166,11 +192,9 @@
166 192 <li class="wp-adminify-overview__help">
167 193 <a href="https://wpadminify.com/docs" target="_blank">
168 194 Help
169 195 <span class="screen-reader-text">
170 - <?php
171 - echo esc_html__( '(opens in a new window)', 'adminify' );
172 - ?>
196 + <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
173 197 </span>
174 198 <span aria-hidden="true" class="dashicons dashicons-external"></span>
175 199 </a>
176 200 </li>
@@ -177,11 +201,9 @@
177 201 <li class="wp-adminify-overview__upgrade">
178 202 <a href="https://wpadminify.com/pricing" target="_blank">
179 203 Upgrade
180 204 <span class="screen-reader-text">
181 - <?php
182 - echo esc_html__( '(opens in a new window)', 'adminify' );
183 - ?>
205 + <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
184 206 </span>
185 207 <span aria-hidden="true" class="dashicons dashicons-external"></span>
186 208 </a>
187 209 </li>
@@ -221,248 +243,214 @@
221 243 font-weight: 500;
222 244 }
223 245 </style>
224 246
225 - <?php
226 - echo '</div>';
227 - }
247 + <?php
248 + echo '</div>';
249 + }
228 250
229 - /**
230 - * Set merged data
231 - *
232 - * @return void
233 - * @author Jewel Theme <[email protected]>
234 - */
235 - public function set_data() {
236 - $this->data = Helper::get_merged_data( self::get_data() );
237 - }
238 251
239 - /**
240 - * Get Sheet data
241 - *
242 - * @author Jewel Theme <[email protected]>
243 - */
244 - public static function get_data() {
245 - return get_option( 'jltwp_adminify_sheet_promo_data' );
246 - }
252 + /**
253 + * Set merged data
254 + *
255 + * @return void
256 + * @author Jewel Theme <[email protected]>
257 + */
258 + public function set_data()
259 + {
260 + $this->data = Helper::get_merged_data(self::get_data());
261 + }
247 262
248 - /**
249 - * Get Contents
250 - *
251 - * @param [type] $key .
252 - *
253 - * @author Jewel Theme <[email protected]>
254 - */
255 - public function get_content( $key ) {
256 - if ( empty( $this->data ) ) {
257 - return;
258 - }
259 - return $this->data[$key];
260 - }
263 + /**
264 + * Get Sheet data
265 + *
266 + * @author Jewel Theme <[email protected]>
267 + */
268 + public static function get_data()
269 + {
270 + return get_option('jltwp_adminify_sheet_promo_data');
271 + }
261 272
262 - /**
263 - * Get Option has data
264 - *
265 - * @author Jewel Theme <[email protected]>
266 - */
267 - public function get_data_hash() {
268 - return get_option( 'jltwp_adminify_sheet_promo_data_hash' );
269 - }
273 + /**
274 + * Get Contents
275 + *
276 + * @param [type] $key .
277 + *
278 + * @author Jewel Theme <[email protected]>
279 + */
280 + public function get_content($key)
281 + {
282 + return $this->data[$key];
283 + }
270 284
271 - /**
272 - * Sync to remote data
273 - *
274 - * @author Jewel Theme <[email protected]>
275 - */
276 - public function maybe_sync_remote_data() {
277 - $data = self::get_data();
278 - if ( empty( $data ) ) {
279 - $this->sheet_data_remote_sync();
280 - }
281 - }
285 + /**
286 + * Get Option has data
287 + *
288 + * @author Jewel Theme <[email protected]>
289 + */
290 + public function get_data_hash()
291 + {
292 + return get_option('jltwp_adminify_sheet_promo_data_hash');
293 + }
282 294
283 - /**
284 - * Register Sync hook
285 - *
286 - * @return void
287 - * @author Jewel Theme <[email protected]>
288 - */
289 - public function register_sync_hook() {
290 - $hook_action = 'jltwp_adminify_sheet_promo_data_remote_sync';
291 - add_action( $hook_action, array($this, 'sheet_data_remote_sync') );
292 - if ( !wp_next_scheduled( $hook_action ) ) {
293 - wp_schedule_event( time(), 'daily', $hook_action );
294 - }
295 - register_deactivation_hook( WP_ADMINIFY_FILE, array($this, 'clear_register_sync_hook') );
296 - }
295 + /**
296 + * Sync to remote data
297 + *
298 + * @author Jewel Theme <[email protected]>
299 + */
300 + public function maybe_sync_remote_data()
301 + {
302 + $data = self::get_data();
297 303
298 - /**
299 - * Clear register sync hook
300 - *
301 - * @return void
302 - * @author Jewel Theme <[email protected]>
303 - */
304 - public function clear_register_sync_hook() {
305 - wp_clear_scheduled_hook( 'jltwp_adminify_sheet_promo_data_remote_sync' );
306 - }
304 + if (empty($data)) {
305 + $this->sheet_data_remote_sync();
306 + }
307 + }
307 308
308 - /**
309 - * Data sync with remote
310 - *
311 - * @return void
312 - * @author Jewel Theme <[email protected]>
313 - */
314 - public function sheet_data_remote_sync() {
315 - $data = self::get_data();
316 - $force = empty( $data );
317 - $remote_data = $this->get_update_remote_data();
318 - // Don't clobber stored data when the API is unreachable / returned nothing.
319 - if ( false === $remote_data ) {
320 - return;
321 - }
322 - $stored_hash = $this->get_data_hash();
323 - $remote_hash = base64_encode( json_encode( $remote_data ) );
324 - if ( $force || $stored_hash !== $remote_hash ) {
325 - update_option( 'jltwp_adminify_sheet_promo_data', $remote_data );
326 - update_option( 'jltwp_adminify_sheet_promo_data_hash', $remote_hash );
327 - do_action( 'jltwp_adminify_sheet_promo_data_reset' );
328 - }
329 - }
309 + /**
310 + * Register Sync hook
311 + *
312 + * @return void
313 + * @author Jewel Theme <[email protected]>
314 + */
315 + public function register_sync_hook()
316 + {
317 + $hook_action = 'jltwp_adminify_sheet_promo_data_remote_sync';
318 + add_action($hook_action, array($this, 'sheet_data_remote_sync'));
330 319
331 - /**
332 - * Update REST API base URL
333 - *
334 - * Development points to the local update service; production uses the
335 - * Jewel Theme API endpoint. Override either with the `jltwp_adminify_endpoint` filter.
336 - *
337 - * @author Jewel Theme <[email protected]>
338 - */
339 - public function get_api_base() {
340 - $base = 'https://pixarlabs.com/';
341 - return trailingslashit( apply_filters( 'jltwp_adminify_endpoint', $base ) );
342 - }
320 + if (!wp_next_scheduled($hook_action)) {
321 + wp_schedule_event(time(), 'daily', $hook_action);
322 + }
343 323
344 - /**
345 - * Update endpoint URL for this plugin
346 - *
347 - * @author Jewel Theme <[email protected]>
348 - */
349 - public function get_update_url() {
350 - return esc_url( $this->get_api_base() . 'api/plugin/update/' . Helper::jltwp_adminify_slug_cleanup() );
351 - }
324 + register_deactivation_hook(WP_ADMINIFY_FILE, array($this, 'clear_register_sync_hook'));
325 + }
352 326
353 - /**
354 - * Promotional remote data (REST API)
355 - *
356 - * Expects a single JSON object describing the update, e.g.
357 - * { product_name, product_slug, image_url, start_date, end_date,
358 - * button_text, button_url, btn_color, notice, show_for_premium, is_live }
359 - *
360 - * @return array|false
361 - * @author Jewel Theme <[email protected]>
362 - */
363 - public function get_update_remote_data() {
364 - $response = wp_remote_get( $this->get_update_url(), array(
365 - 'timeout' => 15,
366 - 'headers' => array(
367 - 'Accept' => 'application/json',
368 - ),
369 - ) );
370 - if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
371 - return false;
372 - }
373 - $body = wp_remote_retrieve_body( $response );
374 - if ( !$body ) {
375 - return false;
376 - }
377 - $data = json_decode( $body, true );
378 - if ( !is_array( $data ) || JSON_ERROR_NONE !== json_last_error() ) {
379 - return false;
380 - }
381 - // API may return the update directly, or wrapped (e.g. { data: {...} }) / as a list.
382 - if ( isset( $data['data'] ) && is_array( $data['data'] ) ) {
383 - $data = $data['data'];
384 - }
385 - if ( isset( $data[0] ) && is_array( $data[0] ) ) {
386 - $data = wp_list_filter( $data, array(
387 - 'product_slug' => Helper::jltwp_adminify_slug_cleanup(),
388 - ) );
389 - $data = ( $data ? array_values( $data )[0] : array() );
390 - }
391 - if ( empty( $data ) || empty( $data['product_slug'] ) ) {
392 - return false;
393 - }
394 - // Only accept a update that targets this plugin.
395 - if ( Helper::jltwp_adminify_slug_cleanup() !== $data['product_slug'] ) {
396 - return false;
397 - }
398 - // API sends dates as "d/m/Y h:i a" — normalise so PHP/JS date parsers don't choke.
399 - foreach ( array('start_date', 'end_date') as $key ) {
400 - if ( !empty( $data[$key] ) ) {
401 - $data[$key] = $this->normalize_date( $data[$key] );
402 - }
403 - }
404 - return $data;
405 - }
327 + /**
328 + * Clear register sync hook
329 + *
330 + * @return void
331 + * @author Jewel Theme <[email protected]>
332 + */
333 + public function clear_register_sync_hook()
334 + {
335 + wp_clear_scheduled_hook('jltwp_adminify_sheet_promo_data_remote_sync');
336 + }
406 337
407 - /**
408 - * Normalise a update date string to 'Y-m-d H:i:s'
409 - *
410 - * Accepts d/m/Y (optionally with 12h time) and a few common fallbacks.
411 - * Returns the original value untouched if it cannot be parsed.
412 - *
413 - * @param string $value .
414 - * @author Jewel Theme <[email protected]>
415 - */
416 - public function normalize_date( $value ) {
417 - $value = trim( (string) $value );
418 - $formats = array(
419 - 'd/m/Y h:i a',
420 - 'd/m/Y H:i',
421 - 'd/m/Y',
422 - 'd-m-Y H:i:s',
423 - 'd-m-Y'
424 - );
425 - foreach ( $formats as $format ) {
426 - $dt = \DateTime::createFromFormat( $format, $value );
427 - if ( $dt instanceof \DateTime ) {
428 - return $dt->format( 'Y-m-d H:i:s' );
429 - }
430 - }
431 - $ts = strtotime( $value );
432 - return ( $ts ? gmdate( 'Y-m-d H:i:s', $ts ) : $value );
433 - }
338 + /**
339 + * Data sync with remote
340 + *
341 + * @return void
342 + * @author Jewel Theme <[email protected]>
343 + */
344 + public function sheet_data_remote_sync()
345 + {
346 + $data = self::get_data();
347 + $force = false;
434 348
435 - /**
436 - * Display popup contents
437 - *
438 - * @author Jewel Theme <[email protected]>
439 - */
440 - public function display_popup() {
441 - if ( empty( $this->get_content( 'is_live' ) ) ) {
442 - $image_url = WP_ADMINIFY_ASSETS_IMAGE . 'promo-image.png';
443 - $notice = 'Use "SPECIAL40" to Get Flat 40% OFF';
444 - $btn_url = 'https://wpadminify.com/pricing/';
445 - $btn_text = 'GET THE DEAL';
446 - } else {
447 - $image_url = $this->get_content( 'image_url' );
448 - $notice = $this->get_content( 'notice' );
449 - $btn_url = $this->get_content( 'button_url' );
450 - $btn_text = $this->get_content( 'button_text' );
451 - }
452 - ?>
349 + if (empty($data)) {
350 + $force = true;
351 + }
453 352
454 - <div class="wp-adminify-popup wp-adminify-upgrade-popup" id="wp-adminify-popup" data-plugin="<?php
455 - echo esc_attr( $this->slug );
456 - ?>" tabindex="1" style="display: none;">
353 + $sheet_hash_data = $this->get_data_hash();
354 + $remote_data = $this->get_sheet_promo_remote_data();
355 + $sheet_data_hash = base64_encode(json_encode($remote_data));
457 356
357 + if ($force || $sheet_hash_data !== $sheet_data_hash) {
358 + update_option('jltwp_adminify_sheet_promo_data', $remote_data);
359 + update_option('jltwp_adminify_sheet_promo_data_hash', $sheet_data_hash);
360 + do_action('jltwp_adminify_sheet_promo_data_reset');
361 + }
362 + }
363 +
364 + /**
365 + * Get Environment mode
366 + *
367 + * @author Jewel Theme <[email protected]>
368 + */
369 + public function get_mode()
370 + {
371 + return defined('WP_DEBUG') && WP_DEBUG ? 'development' : 'production';
372 + }
373 +
374 + /**
375 + * Get Sheet URL
376 + *
377 + * @author Jewel Theme <[email protected]>
378 + */
379 + public function get_sheet_url()
380 + {
381 + $sheet_id = $this->modes[$this->get_mode()]['sheet_id'];
382 + $tab_id = $this->modes[$this->get_mode()]['tab_id'];
383 +
384 + return "https://docs.google.com/spreadsheets/export?format=csv&id={$sheet_id}&gid={$tab_id}";
385 + }
386 +
387 + /**
388 + * Promotional remote data
389 + *
390 + * @author Jewel Theme <[email protected]>
391 + */
392 + public function get_sheet_promo_remote_data()
393 + {
394 + $transient_key = $this->slug . '_sheet_promo_data';
395 +
396 + $data = get_transient($transient_key);
397 + if ($data !== false) return $data;
398 +
399 + $url = $this->get_sheet_url();
400 +
401 + $response = wp_remote_get($url);
402 +
403 + if (is_wp_error($response)) {
404 + return false;
405 + }
406 +
407 + $response = wp_remote_retrieve_body($response);
408 +
409 + if (!$response) {
410 + return false;
411 + }
412 +
413 + $data = array_map('str_getcsv', explode("\n", $response));
414 +
415 + $header = array_shift($data);
416 +
417 + $data = array_map(function (array $row) use ($header) {
418 + return array_combine($header, $row);
419 + }, $data);
420 +
421 + // filter plugin is not empty .
422 + $data = array_filter($data, function ($row) {
423 + return !empty($row['name']);
424 + });
425 +
426 + $plugin_slug = Helper::jltwp_adminify_slug_cleanup();
427 + $data = wp_list_filter($data, array('product_slug' => $plugin_slug));
428 +
429 + if (!empty($data)) {
430 + $data = array_values($data)[0];
431 + }
432 +
433 + set_transient($transient_key, $data, HOUR_IN_SECONDS);
434 +
435 + return $data;
436 + }
437 +
438 + /**
439 + * Display popup contents
440 + *
441 + * @author Jewel Theme <[email protected]>
442 + */
443 + public function display_popup()
444 + {
445 + $image_url = $this->get_content('image_url');
446 + ?>
447 +
448 + <div class="wp-adminify-popup wp-adminify-upgrade-popup" id="wp-adminify-popup" data-plugin="<?php echo esc_attr($this->slug); ?>" tabindex="1" style="display: none;">
449 +
458 450 <div class="wp-adminify-popup-overlay"></div>
459 451
460 - <div class="wp-adminify-popup-modal" style="background-image: url('<?php
461 - echo esc_url( $image_url );
462 - ?>'); --wp-adminify-popup-color: <?php
463 - echo esc_attr( $this->get_content( 'btn_color' ) );
464 - ?>;">
452 + <div class="wp-adminify-popup-modal" style="background-image: url('<?php echo esc_url($image_url); ?>'); --wp-adminify-popup-color: <?php echo esc_attr($this->get_content('btn_color')); ?>;">
465 453
466 454 <!-- close -->
467 455 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
468 456
@@ -470,69 +458,50 @@
470 458 <div class="wp-adminify-popup-modal-footer">
471 459 <!-- countdown -->
472 460 <div class="wp-adminify-popup-countdown" style="display: none;">
473 461
474 - <?php
475 - if ( !empty( $notice ) ) {
476 - ?>
477 - <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;"><?php
478 - echo esc_html__( 'Notice:', 'adminify' );
479 - ?> <?php
480 - echo wp_kses_post( $notice );
481 - ?></span>
482 - <?php
483 - }
484 - ?>
462 + <?php if (!empty($this->get_content('notice'))) { ?>
463 + <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;"><?php echo esc_html__('Notice:', 'adminify'); ?> <?php echo $this->get_content('notice'); ?></span>
464 + <?php } ?>
485 465
486 - <span class="wp-adminify-popup-countdown-text"><?php
487 - echo esc_html__( 'Deal Ends In', 'adminify' );
488 - ?></span>
466 + <span class="wp-adminify-popup-countdown-text"><?php echo esc_html__('Deal Ends In', 'adminify'); ?></span>
489 467 <div class="wp-adminify-popup-countdown-time">
490 468 <div>
491 469 <span data-counter="days">00</span>
492 - <span><?php
493 - echo esc_html__( 'Days', 'adminify' );
494 - ?></span>
470 + <span><?php echo esc_html__('Days', 'adminify'); ?></span>
495 471 </div>
496 472 <span>:</span>
497 473 <div>
498 474 <span data-counter="hours">00</span>
499 - <span><?php
500 - echo esc_html__( 'Hours', 'adminify' );
501 - ?></span>
475 + <span><?php echo esc_html__('Hours', 'adminify'); ?></span>
502 476 </div>
503 477 <span>:</span>
504 478 <div>
505 479 <span data-counter="minutes">00</span>
506 - <span><?php
507 - echo esc_html__( 'Minutes', 'adminify' );
508 - ?></span>
480 + <span><?php echo esc_html__('Minutes', 'adminify'); ?></span>
509 481 </div>
510 482 <span>:</span>
511 483 <div>
512 484 <span data-counter="seconds">00</span>
513 - <span><?php
514 - echo esc_html__( 'Seconds', 'adminify' );
515 - ?></span>
485 + <span><?php echo esc_html__('Seconds', 'adminify'); ?></span>
516 486 </div>
517 487 </div>
518 488 </div>
519 489
520 490 <!-- button -->
521 - <a class="wp-adminify-popup-button" style="color: #fff!important;" target="_blank" href="<?php
522 - echo esc_url( $btn_url );
523 - ?>"><?php
524 - echo esc_html( $btn_text );
525 - ?></a>
491 + <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>"><?php
492 + if (jltwp_adminify()->can_use_premium_code()) {
493 + echo esc_html__('Upgrade Now', 'adminify');
494 + } else {
495 + echo esc_html($this->get_content('button_text'));
496 + } ?></a>
497 + </div>
526 498 </div>
527 - </div>
528 499 </div>
529 500
530 501 <script>
531 502 var $container = jQuery('#wp-adminify-popup'),
532 - plugin_data = <?php
533 - echo wp_json_encode( $this->data );
534 - ?>,
503 + plugin_data = <?php echo json_encode($this->get_sheet_promo_remote_data(), true); ?>,
535 504 events = {}; //Events
536 505
537 506 // Update Counter
538 507 function updateCounter(seconds) {
@@ -613,27 +582,28 @@
613 582
614 583 }, 1000);
615 584 }
616 585
617 - initCounter('<?php
618 - echo esc_attr( $this->counter_date() );
619 - ?>');
586 + initCounter('<?php echo esc_attr($this->counter_date()); ?>');
620 587 </script>
621 588
622 - <?php
623 - }
589 +<?php
590 + }
624 591
625 - /**
626 - * Counter Date
627 - *
628 - * @author Jewel Theme <[email protected]>
629 - */
630 - public function counter_date() {
631 - $endDate = $this->get_content( 'end_date' );
632 - $is_active = $this->date_is_current_or_next( $endDate );
633 - if ( $is_active ) {
634 - return $endDate;
635 - }
636 - return $this->date_increment( $this->current_time(), 3 );
637 - }
592 + /**
593 + * Counter Date
594 + *
595 + * @author Jewel Theme <[email protected]>
596 + */
597 + public function counter_date()
598 + {
599 + $endDate = $this->get_content('end_date');
638 600
601 + $is_active = $this->date_is_current_or_next($endDate);
602 +
603 + if ($is_active) {
604 + return $endDate;
605 + }
606 +
607 + return $this->date_increment($this->current_time(), 3);
608 + }
639 609 }