PluginProbe ʕ •ᴥ•ʔ
W2S – Migrate WooCommerce to Shopify / 1.3.2
W2S – Migrate WooCommerce to Shopify v1.3.2
trunk 1.3.2
w2s-migrate-woo-to-shopify / includes / support.php
w2s-migrate-woo-to-shopify / includes Last commit date
class-vi-w2s-activator.php 5 months ago class-vi-w2s-deactivator.php 5 months ago class-vi-w2s-i18n.php 5 months ago class-vi-w2s-loader.php 5 months ago class-vi-w2s.php 5 months ago data.php 5 months ago support.php 5 months ago
support.php
1021 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 if ( ! class_exists( 'VillaTheme_Support' ) ) {
7 /**
8 * Class VillaTheme_Support
9 * 1.1.19
10 */
11 class VillaTheme_Support {
12 protected $plugin_base_name;
13 protected $ads_data;
14 protected $version = '1.1.19';
15 protected $data = [];
16
17 public function __construct( $data ) {
18 $this->data = array();
19 $this->data['support'] = $data['support'] ?? '';
20 $this->data['docs'] = $data['docs'] ?? '';
21 $this->data['review'] = $data['review'] ?? '';
22 $this->data['css_url'] = $data['css'] ?? '';
23 $this->data['images_url'] = $data['image'] ?? '';
24 $this->data['slug'] = $data['slug'] ?? '';
25 $this->data['deactivate_id'] = $data['deactivate_id'] ?? '';
26 $this->data['menu_slug'] = $data['menu_slug'] ?? '';
27 $this->data['version'] = isset( $data['version'] ) ? $data['version'] : '1.0.0';
28 $this->data['pro_url'] = isset( $data['pro_url'] ) ? $data['pro_url'] : '';
29 $this->data['survey_url'] = isset( $data['survey_url'] ) ? $data['survey_url'] : '';
30 $this->plugin_base_name = "{$this->data['slug']}/{$this->data['slug']}.php";
31 add_action( 'villatheme_support_' . $this->data['slug'], array( $this, 'villatheme_support' ) );
32 add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
33 add_action( 'admin_notices', array( $this, 'review_notice' ) );
34 add_action( 'admin_init', array( $this, 'hide_review_notice' ) );
35 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9999 );
36 add_filter( 'plugin_action_links_' . $this->plugin_base_name, array( $this, 'link_to_pro' ) );
37 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
38 /*Admin ads notices*/
39 add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
40 /*Add toolbar*/
41 add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 );
42 }
43
44 public function admin_init() {
45 $this->hide_notices();
46 $villatheme_call = get_transient( 'villatheme_call' );
47 if ( ! $villatheme_call || ! is_plugin_active( "{$villatheme_call}/{$villatheme_call}.php" ) ) {
48 /*Make sure ads and dashboard widget show only once when multiple VillaTheme plugins are installed*/
49 set_transient( 'villatheme_call', $this->data['slug'], DAY_IN_SECONDS );
50 }
51 // if ( get_transient( 'villatheme_call' ) == $this->data['slug'] ) {
52 add_action( 'admin_notices', array( $this, 'form_ads' ) );
53 // }
54 }
55
56 /**Add link to Documentation, Support and Reviews
57 *
58 * @param $links
59 * @param $file
60 *
61 * @return array
62 */
63 public function plugin_row_meta( $links, $file ) {
64 if ( $this->plugin_base_name === $file ) {
65 $row_meta = array(
66 'support' => '<a href="' . esc_url( $this->data['support'] ) . '" target="_blank" title="' . esc_attr( 'VillaTheme Support' ) . '">' . esc_html( 'Support' ) . '</a>',
67 'review' => '<a href="' . esc_url( $this->data['review'] ) . '" target="_blank" title="' . esc_attr( 'Rate this plugin' ) . '">' . esc_html( 'Reviews' ) . '</a>',
68 );
69 if ( ! empty( $this->data['docs'] ) ) {
70 $row_meta['docs'] = '<a href="' . esc_url( $this->data['docs'] ) . '" target="_blank" title="' . esc_attr( 'Plugin Documentation' ) . '">' . esc_html( 'Docs' ) . '</a>';
71 }
72
73 return array_merge( $links, $row_meta );
74 }
75
76 return (array) $links;
77 }
78
79 /**
80 * @param $links
81 *
82 * @return mixed
83 */
84 public function link_to_pro( $links ) {
85 if ( ! empty( $this->data['pro_url'] ) ) {
86 $link = '<a class="villatheme-button-upgrade" href="' . esc_url( $this->data['pro_url'] ) . '" target="_blank" title="' . esc_attr( 'Upgrade plugin to premium version' ) . '">' . esc_html( 'Upgrade' ) . '</a>';
87 array_unshift( $links, $link );
88 }
89
90 return $links;
91 }
92
93 /**
94 * Get latest VillaTheme plugins and ads
95 * Available information is appended to changelog of some plugins, which is available with plugins_api()
96 *
97 * @param $is_ads
98 *
99 * @return array
100 */
101 public function remote_get( $is_ads = false ) {
102 $return = array(
103 'status' => 'error',
104 'data' => '',
105 );
106 foreach (
107 array(
108 'woo-multi-currency',
109 'email-template-customizer-for-woo',
110 ) as $slug
111 ) {
112 $api = $this->plugin_information( array(
113 'slug' => $slug,
114 'locale' => 'en_US',
115 ) );
116 if ( ! is_wp_error( $api ) ) {
117 if ( isset( $api->sections, $api->sections['changelog'] ) ) {
118 $changelog = $api->sections['changelog'];
119 if ( $changelog ) {
120 if ( $is_ads ) {
121 preg_match( '/VillaThemeCampaign:{(.*)}/', $changelog, $match );
122 } else {
123 preg_match( '/VillaThemePlugins:\[(.*)]/sm', $changelog, $match );
124 }
125 if ( $match ) {
126 $json = html_entity_decode( str_replace( array(
127 '&#8222;',
128 '&#8221;',
129 '&#8220;',
130 '&#8243;',
131 '',
132 ), '"', $match[1] ) );
133 if ( $is_ads ) {
134 $json = '{' . $json . '}';
135 } else {
136 $json = '[' . $json . ']';
137 }
138 $return['data'] = $json;
139 $return['status'] = 'success';
140 break;
141 }
142 }
143 }
144 }
145 }
146
147 return $return;
148 }
149
150 public function plugin_information( $args = array() ) {
151 global $wp_version;
152 $wp_version1 = $wp_version;
153 if ( ! $wp_version ) {
154 $wp_version1 = '5.0';
155 }
156 if ( is_array( $args ) ) {
157 $args = (object) $args;
158 }
159 if ( ! isset( $args->locale ) ) {
160 $args->locale = get_user_locale();
161 }
162
163 if ( ! isset( $args->wp_version ) ) {
164 $args->wp_version = substr( $wp_version1, 0, 3 ); // x.y
165 }
166 $url = 'https://api.wordpress.org/plugins/info/1.2/';
167 $url = add_query_arg(
168 array(
169 'action' => 'plugin_information',
170 'request' => $args,
171 ),
172 $url
173 );
174 $http_url = $url;
175 $ssl = wp_http_supports( array( 'ssl' ) );
176 if ( $ssl ) {
177 $url = set_url_scheme( $url, 'https' );
178 }
179 $http_args = array(
180 'timeout' => 15,
181 'user-agent' => 'WordPress/' . $wp_version1 . '; ' . home_url( '/' ),
182 );
183 $request = wp_remote_get( $url, $http_args );
184 if ( $ssl && is_wp_error( $request ) ) {
185 $request = wp_remote_get( $http_url, $http_args );
186 }
187 if ( is_wp_error( $request ) ) {
188 $res = new WP_Error(
189 'plugins_api_failed',
190 esc_html( 'Error' ),
191 $request->get_error_message()
192 );
193 } else {
194 $res = json_decode( wp_remote_retrieve_body( $request ), true );
195 if ( is_array( $res ) ) {
196 // Object casting is required in order to match the info/1.0 format.
197 $res = (object) $res;
198 } elseif ( null === $res ) {
199 $res = new WP_Error(
200 'plugins_api_failed',
201 esc_html( 'Error' ),
202 wp_remote_retrieve_body( $request )
203 );
204 }
205
206 if ( isset( $res->error ) ) {
207 $res = new WP_Error( 'plugins_api_failed', $res->error );
208 }
209 }
210
211 return $res;
212 }
213
214 /**
215 * Add Extensions page
216 */
217 public function admin_menu() {
218 if ( $this->data['menu_slug'] ) {
219 add_submenu_page(
220 $this->data['menu_slug'],
221 esc_html( 'Extensions' ),
222 esc_html( 'Extensions' ),
223 'manage_options',
224 'villatheme-' . $this->data['slug'] . '-extensions',
225 array( $this, 'page_callback' )
226 );
227
228 if ( $this->data['pro_url'] ) {
229 add_submenu_page(
230 $this->data['menu_slug'],
231 esc_html( 'Try Premium Version' ),
232 esc_html( 'Try Premium Version' ),
233 'manage_options',
234 $this->data['pro_url'],
235 ''
236 );
237 }
238 }
239 }
240
241 /**
242 * Extensions page
243 */
244 public function page_callback() { ?>
245 <div class="villatheme-extension-page">
246 <div class="villatheme-extension-top">
247 <h2><?php echo esc_html( 'THE BEST PLUGINS FOR WOOCOMMERCE' ) ?></h2>
248 <p><?php echo esc_html( 'Our plugins are constantly updated and thanks to your feedback. We add new features on a daily basis. Try our live demo and start increasing the conversions on your ecommerce right away.' ) ?></p>
249 </div>
250 <div class="villatheme-extension-content">
251 <?php
252 $ads = $this->get_data();
253 if ( is_array( $ads ) && !empty( $ads ) ) {
254 foreach ( $ads as $ad ) {
255 if ( empty( $ad ) ) {
256 continue;
257 }
258 ?>
259 <div class="villatheme-col-3">
260 <?php
261 if ( $ad->image ) { ?>
262 <div class="villatheme-item-image">
263 <img src="<?php echo esc_url( $ad->image ) // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>">
264 </div>
265 <?php
266 }
267 if ( $ad->title ) {
268 ?>
269 <div class="villatheme-item-title">
270 <?php if ( $ad->link ) { ?>
271 <a target="_blank"
272 href="<?php echo esc_url( $ad->link ) ?>">
273 <?php } ?>
274 <?php echo esc_html( $ad->title ) ?>
275 <?php if ( $ad->link ) { ?>
276 </a>
277 <?php
278 }
279 ?>
280 </div>
281 <?php
282 }
283 ?>
284 <div class="villatheme-item-controls">
285 <div class="villatheme-item-controls-inner">
286 <?php
287 if ( $ad->link ) {
288 ?>
289 <a class="villatheme-item-controls-inner-button active" target="_blank"
290 href="<?php echo esc_url( $ad->link ) ?>"><?php echo esc_html( 'Download' ) ?></a>
291 <?php
292 }
293 if ( $ad->demo_url ) {
294 ?>
295 <a class="villatheme-item-controls-inner-button" target="_blank"
296 href="<?php echo esc_url( $ad->demo_url ) ?>"><?php echo esc_html( 'Demo' ) ?></a>
297 <?php
298 }
299 if ( $ad->free_url ) {
300 ?>
301 <a class="villatheme-item-controls-inner-button" target="_blank"
302 href="<?php echo esc_url( $ad->free_url ) ?>"><?php echo esc_html( 'Free download' ) ?></a>
303 <?php
304 }
305 ?>
306 </div>
307 </div>
308 </div>
309 <?php
310 }
311 }
312 ?>
313 </div>
314 </div>
315 <?php
316 }
317
318 /**
319 * Hide notices
320 */
321 public function hide_review_notice() {
322 if ( ! current_user_can( 'manage_options' ) ) {
323 return;
324 }
325 $_villatheme_nonce = isset( $_GET['_villatheme_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_villatheme_nonce'] ) ) : '';
326
327 if ( empty( $_villatheme_nonce ) ) {
328 return;
329 }
330
331 if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_dismiss_notices' ) ) {
332 update_option( 'villatheme_' . $this->data['slug'] . '_dismiss_notices', 1 );
333 }
334 if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_hide_notices' ) ) {
335 set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 );
336 }
337 if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_wp_reviewed' ) ) {
338 set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 );
339 update_option( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', 1 );
340 wp_safe_redirect( esc_url_raw( $this->data['review'] ) );
341 exit();
342 }
343 }
344
345 /**
346 * Show review WordPress
347 */
348 public function review_notice() {
349 if ( get_option( 'villatheme_' . $this->data['slug'] . '_dismiss_notices', 0 ) ) {
350 return;
351 }
352 if ( get_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices' ) ) {
353 return;
354 }
355 $name = $this->get_plugin_name();
356 $check_review = get_option( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', 0 );
357 $check_start = get_option( 'villatheme_' . $this->data['slug'] . '_start_use', 0 );
358 if ( ! $check_start ) {
359 update_option( 'villatheme_' . $this->data['slug'] . '_start_use', 1 );
360 set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 259200 );
361
362 return;
363 }
364 if ( $check_review && ! $this->data['pro_url'] ) {
365 return;
366 }
367 ?>
368
369 <div class="villatheme-dashboard updated" style="border-left: 4px solid #ffba00">
370 <div class="villatheme-content">
371 <form action="" method="get">
372 <?php if ( ! $check_review ) { ?>
373 <p><?php echo esc_html( 'Hi there! You\'ve been using ' ) . '<strong>' . esc_html( $name ) . '</strong>' . esc_html( ' on your site for a few days - I hope it\'s been helpful. If you\'re enjoying my plugin, would you mind rating it 5-stars to help spread the word?' ) ?></p>
374 <?php } else { ?>
375 <p><?php echo esc_html( 'Hi there! You\'ve been using ' ) . '<strong>' . esc_html( $name ) . '</strong>' . esc_html( ' on your site for a few days - I hope it\'s been helpful. Would you want get more features?' ) ?></p>
376 <?php } ?>
377 <p>
378 <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array() ), 'villatheme_' . $this->data['slug'] . '_hide_notices', '_villatheme_nonce' ) ); ?>"
379 class="button"><?php echo esc_html( 'Thanks, later' ) ?></a>
380 <?php if ( ! $check_review ) { ?>
381 <button class="button button-primary"><?php echo esc_html( 'Rate Now' ) ?></button>
382 <?php wp_nonce_field( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', '_villatheme_nonce' ) ?>
383 <?php } ?>
384 <?php if ( $this->data['pro_url'] ) { ?>
385 <a target="_blank" href="<?php echo esc_url( $this->data['pro_url'] ); ?>"
386 class="button button-primary"><?php echo esc_html( 'Try Premium Version' ) ?></a>
387 <?php } ?>
388 <a target="_self"
389 href="<?php echo esc_url( wp_nonce_url( add_query_arg( array() ), 'villatheme_' . $this->data['slug'] . '_dismiss_notices', '_villatheme_nonce' ) ); ?>"
390 class="button notice-dismiss vi-button-dismiss"><?php echo esc_html( 'Dismiss' ) ?></a>
391 </p>
392 </form>
393 </div>
394 </div>
395 <?php
396 }
397
398
399 public function widget() {
400 ?>
401 <div class="villatheme-dashboard">
402 <div class="villatheme-content">
403 <?php
404 if ( $this->ads_data['heading'] ) { ?>
405 <h3><?php echo esc_html( $this->ads_data['heading'] ) ?></h3>
406 <?php
407 }
408 if ( $this->ads_data['description'] ) { ?>
409 <p><?php echo esc_html( $this->ads_data['description'] ) ?></p>
410 <?php
411 }
412 ?>
413 <p>
414 <?php
415 if ( $this->ads_data['link'] ) {
416 ?>
417 <a target="_blank" href="<?php echo esc_url( $this->ads_data['link'] ); ?>"
418 class="button button-primary"><?php echo esc_html( 'Get Your Gift' ) ?></a>
419 <?php
420 }
421 ?>
422 </p>
423 </div>
424 </div>
425 <?php
426 }
427
428 /**
429 * Hide notices
430 */
431 public function hide_notices() {
432 if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_villatheme_nonce'] ?? '' ) ), 'villatheme_hide_toolbar' ) ) {
433 update_option( 'villatheme_hide_admin_toolbar', time() );
434 wp_safe_redirect( ( esc_url_raw( remove_query_arg( array( '_villatheme_nonce' ) ) ) ) );
435 exit();
436 }
437 if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_villatheme_nonce'] ?? '' ) ), 'villatheme_show_toolbar' ) ) {
438 delete_option( 'villatheme_hide_admin_toolbar' );
439 wp_safe_redirect( ( esc_url_raw( remove_query_arg( array( '_villatheme_nonce' ) ) ) ) );
440 exit();
441 }
442
443 if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_villatheme_nonce'] ?? '' ) ), 'hide_notices' ) ) {
444 $hide_notice = isset( $_GET['villatheme-hide-notice'] ) ? sanitize_text_field( wp_unslash( $_GET['villatheme-hide-notice'] ) ) : '';
445 $ads_id = isset( $_GET['ads_id'] ) ? sanitize_text_field( wp_unslash( $_GET['ads_id'] ) ) : '';
446 global $current_user;
447 if ( $hide_notice == 1 ) {
448 if ( $ads_id ) {
449 update_option( 'villatheme_hide_notices_' . $ads_id, time() + DAY_IN_SECONDS );
450 } else {
451 set_transient( 'villatheme_hide_notices_' . $current_user->ID, 1, DAY_IN_SECONDS );
452 }
453 } else {
454 if ( $ads_id ) {
455 update_option( 'villatheme_hide_notices_' . $ads_id, $ads_id );
456 } else {
457 set_transient( 'villatheme_hide_notices_' . $current_user->ID, 1, DAY_IN_SECONDS * 30 );
458 }
459 }
460 }
461 }
462
463 /**
464 * Show Notices
465 */
466 public function form_ads() {
467 global $current_screen;
468 $page = $current_screen->parent_base ?? $current_screen->parent_file ?? '';
469 if ( ! in_array( $page, [ 'plugins', $this->data['menu_slug'] ] ) || ($page === 'plugins' && get_transient( 'villatheme_call' ) !== $this->data['slug']) ) {
470 return;
471 }
472 $this->get_ads_data();
473 if ( $this->ads_data === false ) {
474 return;
475 }
476 ob_start(); ?>
477 <div class="villatheme-dashboard updated">
478 <div class="villatheme-content">
479 <?php
480 if ( ! empty( $this->ads_data['heading'] ) ) { ?>
481 <h3><?php echo esc_html( $this->ads_data['heading'] ) ?></h3>
482 <?php
483 }
484 if ( ! empty( $this->ads_data['description'] ) ) { ?>
485 <p><?php echo esc_html( $this->ads_data['description'] ) ?></p>
486 <?php
487 }
488 ?>
489 <p>
490 <a target="_self"
491 href="<?php echo esc_url( wp_nonce_url( add_query_arg( array(
492 'villatheme-hide-notice' => '2',
493 'ads_id' => $this->ads_data['id'],
494 ) ), 'hide_notices', '_villatheme_nonce' ) ); ?>"
495 class="button notice-dismiss vi-button-dismiss"><?php echo esc_html( 'Dismiss' ) ?></a>
496 <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array(
497 'villatheme-hide-notice' => '1',
498 'ads_id' => $this->ads_data['id'],
499 ) ), 'hide_notices', '_villatheme_nonce' ) ); ?>"
500 class="button"><?php echo esc_html( 'Thanks, later.' ) ?></a>
501 <?php
502 if ( ! empty( $this->ads_data['link'] ) ) { ?>
503 <a target="_blank" href="<?php echo esc_url( $this->ads_data['link'] ); ?>"
504 class="button button-primary"><?php echo esc_html( 'Get Your Gift' ) ?></a>
505 <?php
506 }
507 ?>
508 </p>
509 </div>
510 </div>
511 <?php
512 echo wp_kses_post( apply_filters( 'villatheme_form_ads_data', ob_get_clean() ) );
513 }
514
515 public function get_ads_data() {
516 global $current_user;
517 if ( $this->ads_data !== null ) {
518 return;
519 }
520 $this->ads_data = false;
521 if ( get_transient( 'villatheme_hide_notices_' . $current_user->ID ) ) {
522 return;
523 }
524 $data = get_transient( 'villatheme_notices' );
525 $called = get_transient( 'villatheme_called' );
526 if ( ! $data && ! $called ) {
527 $request_data = $this->remote_get( true );
528 if ( isset( $request_data['status'] ) && $request_data['status'] === 'success' ) {
529 $data = json_decode( $request_data['data'], true );
530 }
531 set_transient( 'villatheme_notices', $data, DAY_IN_SECONDS );
532 }
533
534 if ( ! $called ) {
535 set_transient( 'villatheme_called', 1, DAY_IN_SECONDS );
536 }
537
538 if ( ! is_array( $data ) ) {
539 return;
540 }
541 $data = wp_parse_args( $data, array(
542 'heading' => '',
543 'description' => '',
544 'link' => '',
545 'id' => '',
546 ) );
547 if ( ! $data['heading'] && ! $data['description'] ) {
548 return;
549 }
550 $getdate = getdate();
551 $current_time = $getdate[0];
552 if ( isset( $data['start'] ) && strtotime( $data['start'] ) > $current_time ) {
553 return;
554 }
555 if ( isset( $data['end'] ) && strtotime( $data['end'] ) < $current_time ) {
556 return;
557 }
558 // if ( isset( $data['loop'] ) && $data['loop'] ) {
559 // if ( ! in_array( $getdate['wday'], explode( ',', $data['loop'] ) ) ) {
560 // return;
561 // }
562 // }
563 if ( $data['id'] ) {
564 $hide = get_option( 'villatheme_hide_notices_' . $data['id'] );
565 if ( $hide === $data['id'] || time() < intval( $hide ) ) {
566 return;
567 }
568 }
569 $this->ads_data = $data;
570 }
571
572 /**
573 * Init script
574 */
575 public function scripts() {
576 if ( ! wp_style_is( 'villatheme-support' ) ) {
577 wp_enqueue_style( 'villatheme-support', $this->data['css_url'] . 'villatheme-support.min.css', '', $this->version );
578 wp_register_script( 'villatheme-support', false, [ 'jquery' ], $this->version, false );
579 wp_enqueue_script( 'villatheme-support' );
580 wp_add_inline_script( 'villatheme-support', "(function ($) {
581 $(function () {
582 $(document).on('click','#wp-admin-bar-villatheme_hide_toolbar',function(e){
583 if (!confirm('VillaTheme toolbar helps you access all VillaTheme items quickly, do you want to hide it anyway?')){
584 e.preventDefault();
585 e.stopPropagation();
586 return false;
587 }
588 });
589 });
590 }(jQuery));" );
591 }
592 global $pagenow;
593 if ( $this->data['survey_url'] && ( 'plugins.php' === $pagenow ) ) {
594 $support_basic = ! wp_style_is( 'villatheme-support-basic' );
595 if ( $support_basic ) {
596 wp_register_style( 'villatheme-support-basic', false, '', $this->version, false );
597 wp_enqueue_style( 'villatheme-support-basic' );
598 wp_add_inline_style( 'villatheme-support-basic', '.villatheme-deactivate-modal{position: fixed;z-index: 99999;top: 0;right: 0;bottom: 0;left: 0;background: rgba(0, 0, 0, 0.5);display: none}.villatheme-deactivate-modal.modal-active{display: block}.villatheme-deactivate-modal-wrap{width: 50%;position: relative;margin: 10% auto;background: #fff}.villatheme-deactivate-modal-header{border-bottom: 1px solid #eee;padding: 8px 20px}.villatheme-deactivate-modal-header h3{line-height: 150%;margin: 0}.villatheme-deactivate-modal-body{padding: 5px 20px 20px 20px}.villatheme-deactivate-modal-body .input-text,.villatheme-deactivate-modal-body textarea{width: 75%}.villatheme-deactivate-modal-body .reason-input{margin-top: 5px;margin-left: 20px}.villatheme-deactivate-modal-footer{border-top: 1px solid #eee;padding: 12px 20px;text-align: right}' );
599 wp_add_inline_script( 'villatheme-support', "var ViDeactivate = {deactivateLink: '', surveyUrl: ''};
600 (function ($) {
601 $(function () {
602 let modal = $('#villatheme-deactivate-survey-modal');
603 ViDeactivate.modal = modal;
604
605 modal.on('click', 'button.villatheme-model-cancel', function (e) {
606 e.preventDefault();
607 modal.removeClass('modal-active');
608 });
609
610 modal.on('click', 'input[type=\"radio\"]', function () {
611 $('button.villatheme-deactivate-submit').removeClass('disabled');
612 var parent = $(this).parents('li:first');
613 modal.find('.reason-input').remove();
614 var inputType = parent.data('type'),
615 inputPlaceholder = parent.data('placeholder'),
616 reasonInputHtml = '<div class=\"reason-input\">' + (('text' === inputType) ? '<input type=\"text\" class=\"input-text\" size=\"40\" />' : '<textarea rows=\"5\" cols=\"45\"></textarea>') + '</div>';
617
618 if (inputType !== '') {
619 parent.append($(reasonInputHtml));
620 parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
621 }
622 });
623
624 modal.on('click', 'button.villatheme-deactivate-submit', function (e) {
625 e.preventDefault();
626 let button = $(this);
627
628 if (button.hasClass('disabled')) return;
629
630 let radio = $('input[type=\"radio\"]:checked', modal);
631 let selected_reason = radio.parents('li:first'),
632 input = selected_reason.find('textarea, input[type=\"text\"]');
633 let reason_id = (0 === radio.length) ? '' : radio.val();
634 let reason_info = (0 !== input.length) ? input.val().trim() : '';
635 let date = new Date(Date.now()).toLocaleString().split(',')[0];
636
637 if ((reason_id === 'other' && !reason_info) || !reason_id) {
638 window.location.href = ViDeactivate.deactivateLink;
639 return;
640 }
641
642 $.ajax({
643 url: ViDeactivate.surveyUrl+'?date='+date+'&'+reason_id+'=1&reason_info='+reason_info,
644 type: 'GET',
645 beforeSend: function () {
646 button.addClass('disabled');
647 button.text('Processing...');
648 },
649 complete: function () {
650 window.location.href = ViDeactivate.deactivateLink;
651 }
652 });
653
654 });
655 });
656 }(jQuery));" );
657 }
658 wp_add_inline_script( 'villatheme-support', "(function ($) {
659 $(function () {
660 $(document).on('click', '#the-list a#deactivate-" . esc_html( $this->data['deactivate_id'] ?: $this->data['slug'] ) . "', function (e) {
661 e.preventDefault();
662 ViDeactivate.modal.addClass('modal-active');
663 ViDeactivate.deactivateLink = $(this).attr('href');
664 ViDeactivate.surveyUrl = '" . esc_html( $this->data['survey_url'] ) . "';
665 ViDeactivate.modal.find('a.dont-bother-me').attr('href', ViDeactivate.deactivateLink).css('float', 'left');
666 });
667 });
668 }(jQuery));" );
669 add_action( 'admin_footer', array( $this, 'deactivate_scripts' ) );
670 }
671 }
672
673 /**
674 *
675 */
676 public function villatheme_support() {
677 ?>
678 <div id="villatheme-support" class="vi-ui form segment">
679
680 <div class="villatheme-support-head">
681 <span class="villatheme-support-title"><?php echo esc_html( 'MAYBE YOU LIKE' ) ?></span>
682 <div class="villatheme-support-action">
683 <a class="vi-ui button labeled inverted icon min document" target="_blank"
684 href="<?php echo esc_attr( esc_url( $this->data['docs'] ) ) ?>">
685 <i class="file alternate icon"></i>
686 <?php echo esc_html( 'Documentation' ) ?>
687 </a>
688 <a class="vi-ui button inverted labeled review icon mini" target="_blank"
689 href="<?php echo esc_attr( esc_url( $this->data['review'] ) ) ?>">
690 <i class="star icon"></i>
691 <?php echo esc_html( 'Review' ) ?>
692 </a>
693 <a class="vi-ui button labeled icon request-support green min" target="_blank"
694 href="<?php echo esc_attr( esc_url( $this->data['support'] ) ) ?>">
695 <i class="users icon"></i>
696 <?php echo esc_html( 'Request Support' ) ?>
697 </a>
698 <?php
699 if ( get_option( 'villatheme_hide_admin_toolbar' ) ) {
700 ?>
701 <a class="vi-ui button labeled icon blue inverted admin-toolbar mini" target="_self"
702 title="<?php echo esc_attr( 'VillaTheme toolbar helps you access all VillaTheme items quickly' ) ?>"
703 href="<?php echo esc_url( add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_show_toolbar' ) ) ) ) ?>">
704 <i class="eye icon"></i>
705 <?php echo esc_html( 'Show Toolbar' ) ?>
706 </a>
707 <?php
708 }
709 ?>
710 </div>
711 </div>
712 <div class="villatheme-items">
713 <?php
714 $items = $this->get_data( $this->data['slug'] );
715 if ( is_array( $items ) && !empty( $items ) ) {
716 shuffle( $items );
717 $items = array_slice( $items, 0, 12 );
718 foreach ( $items as $k => $item ) {
719 ?>
720 <div class="villatheme-item">
721 <a target="_blank" href="<?php echo esc_url( $item->link ) ?>">
722 <img src="<?php echo esc_url( $item->image ) // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>"/>
723 </a>
724 </div>
725 <?php
726 }
727 }
728 ?>
729 </div>
730 </div>
731 <?php
732 }
733
734 /**
735 * @param bool $slug
736 *
737 * @return array
738 */
739 protected function get_data( $slug = false ) {
740 $feeds = get_transient( 'villatheme_ads' );
741 $ads = null;
742
743 if ( ! $feeds ) {
744 try {
745 $request_data = $this->remote_get( false );
746 if ( isset( $request_data['status'] ) && $request_data['status'] === 'success' ) {
747 $ads = $request_data['data'];
748 }
749 set_transient( 'villatheme_ads', $ads, DAY_IN_SECONDS );
750 } catch ( Exception $e ) {
751 }
752 } else {
753 $ads = $feeds;
754 }
755
756 $results = array();
757
758 if ( $ads ) {
759 $ads = json_decode( $ads );
760 if ( is_array( $ads ) ) {
761 $ads = array_filter( $ads );
762 foreach ( $ads as $ad ) {
763 if ( $slug ) {
764 if ( $ad->slug == $slug ) {
765 continue;
766 }
767 }
768 if (empty($ad->link)|| empty($ad->image)){
769 continue;
770 }
771 $item = new stdClass();
772 $item->title = $ad->title;
773 $item->link = $ad->link;
774 $item->thumb = $ad->thumb;
775 $item->image = $ad->image;
776 $item->desc = $ad->description;
777 $item->free_url = $ad->free_url ?? '';
778 $item->demo_url = $ad->demo_url ?? '';
779 $results[] = $item;
780 }
781 }
782 }
783
784 return $results;
785 }
786
787 /**
788 * Add toolbar in WordPress Dashboard
789 */
790 public function add_toolbar() {
791 /**
792 * @var $wp_admin_bar WP_Admin_Bar
793 */
794 global $wp_admin_bar;
795 if ( get_option( 'villatheme_hide_admin_toolbar' ) ) {
796 return;
797 }
798 if ( ! $wp_admin_bar->get_node( 'villatheme' ) ) {
799 $wp_admin_bar->add_node( array(
800 'id' => 'villatheme',
801 'title' => '<span class="ab-icon dashicons-star-filled villatheme-rotating"></span>' . 'VillaTheme',
802 'href' => '',
803 'meta' => array(
804 'class' => 'villatheme-toolbar'
805 ),
806 ) );
807 add_action( 'admin_bar_menu', array( $this, 'hide_toolbar_button' ), 200 );
808 }
809 if ( $this->data['menu_slug'] ) {
810 $wp_admin_bar->add_node( array(
811 'id' => $this->data['slug'],
812 'title' => $this->get_plugin_name(),
813 'parent' => 'villatheme',
814 'href' => strpos( $this->data['menu_slug'], '.php' ) === false ? admin_url( 'admin.php?page=' . $this->data['menu_slug'] ) : admin_url( $this->data['menu_slug'] ),
815 ) );
816 }
817 }
818
819 public function hide_toolbar_button() {
820 global $wp_admin_bar;
821 /**
822 * @var $wp_admin_bar WP_Admin_Bar
823 */
824 $wp_admin_bar->add_node( array(
825 'id' => 'villatheme_hide_toolbar',
826 'title' => '<span class="dashicons dashicons-dismiss"></span><span class="villatheme-hide-toolbar-button-title">Hide VillaTheme toolbar</span>',
827 'parent' => 'villatheme',
828 'href' => add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_hide_toolbar' ) ) ),
829 ) );
830 }
831
832 private function get_plugin_name() {
833 $plugins = get_plugins();
834
835 return isset( $plugins[ $this->plugin_base_name ]['Title'] ) ? $plugins[ $this->plugin_base_name ]['Title'] : ucwords( str_replace( '-', ' ', $this->data['slug'] ) );
836 }
837
838 private function get_uninstall_reasons() {
839 $reasons = array(
840 array(
841 'id' => 'could_not_understand',
842 'text' => 'I couldn\'t understand how to make it work',
843 'type' => 'textarea',
844 'placeholder' => 'Would you like us to assist you?'
845 ),
846 array(
847 'id' => 'found_better_plugin',
848 'text' => 'I found a better plugin',
849 'type' => 'text',
850 'placeholder' => 'Which plugin?'
851 ),
852 array(
853 'id' => 'not_have_that_feature',
854 'text' => 'The plugin is great, but I need specific feature that you don\'t support',
855 'type' => 'textarea',
856 'placeholder' => 'Could you tell us more about that feature?'
857 ),
858 array(
859 'id' => 'is_not_working',
860 'text' => 'The plugin is not working',
861 'type' => 'textarea',
862 'placeholder' => 'Could you tell us a bit more whats not working?'
863 ),
864 array(
865 'id' => 'looking_for_other',
866 'text' => 'It\'s not what I was looking for',
867 'type' => 'textarea',
868 'placeholder' => 'Could you tell us a bit more?'
869 ),
870 array(
871 'id' => 'did_not_work_as_expected',
872 'text' => 'The plugin didn\'t work as expected',
873 'type' => 'textarea',
874 'placeholder' => 'What did you expect?'
875 ),
876 array(
877 'id' => 'other',
878 'text' => 'Other',
879 'type' => 'textarea',
880 'placeholder' => 'Could you tell us a bit more?'
881 ),
882 );
883
884 return $reasons;
885 }
886
887 public function deactivate_scripts() {
888 global $pagenow;
889 if ( 'plugins.php' != $pagenow ) {
890 return;
891 }
892
893 static $modal = false;
894
895 if ( ! $modal ) {
896 $reasons = $this->get_uninstall_reasons();
897 ?>
898 <div class="villatheme-deactivate-modal" id="villatheme-deactivate-survey-modal">
899 <div class="villatheme-deactivate-modal-wrap">
900 <div class="villatheme-deactivate-modal-header">
901 <h3><?php echo esc_html( 'If you have a moment, please let us know why you are deactivating:' ); ?></h3>
902 </div>
903 <div class="villatheme-deactivate-modal-body">
904 <ul class="reasons">
905 <?php foreach ( $reasons as $reason ) { ?>
906 <li data-type="<?php echo esc_attr( $reason['type'] ); ?>" data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>">
907 <label>
908 <input type="radio" name="selected-reason" value="<?php echo esc_attr( $reason['id'] ); ?>">
909 <?php echo esc_html( $reason['text'] ); ?>
910 </label>
911 </li>
912 <?php } ?>
913 </ul>
914 </div>
915 <div class="villatheme-deactivate-modal-footer">
916 <a href="#" class="dont-bother-me"><?php echo esc_html( 'I rather wouldn\'t say' ); ?></a>
917 <button class="button-primary villatheme-deactivate-submit disabled"><?php echo esc_html( 'Submit & Deactivate' ); ?></button>
918 <button class="button-secondary villatheme-model-cancel"><?php echo esc_html( 'Cancel' ); ?></button>
919 </div>
920 </div>
921 </div>
922 <?php
923 $modal = true;
924 }
925 }
926 }
927 }
928
929 if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) {
930 class VillaTheme_Require_Environment {
931
932 protected $args;
933 protected $plugin_name;
934 protected $notices = [];
935
936 public function __construct( $args ) {
937 if ( ! did_action( 'plugins_loaded' ) ) {
938 _doing_it_wrong( 'VillaTheme_Require_Environment', wp_kses_post( 'VillaTheme_Require_Environment should not be run before the <code>plugins_loaded</code> hook.' ), '1.1.9' );
939 }
940
941 $args = apply_filters( 'villatheme_check_requires', wp_parse_args( $args, [
942 'plugin_name' => '',
943 'php_version' => '',
944 'wp_version' => '',
945 'wc_version' => '',
946 'require_plugins' => [],
947 ] ) );
948
949 $this->plugin_name = $args['plugin_name'];
950
951 $this->check( $args );
952
953 add_action( 'admin_notices', [ $this, 'notice' ] );
954 }
955
956 protected function check( $args ) {
957 if ( ! empty( $args['php_version'] ) && ! is_php_version_compatible( $args['php_version'] ) ) {
958 $this->notices[] = sprintf( "PHP version at least %s.", esc_html( $args['php_version'] ) );
959 }
960
961 if ( ! empty( $args['wp_version'] ) && ! is_wp_version_compatible( $args['wp_version'] ) ) {
962 $this->notices[] = sprintf( "WordPress version at least %s.", esc_html( $args['wp_version'] ) );
963 }
964 if ( ! empty( $args['require_plugins'] ) ) {
965 foreach ( $args['require_plugins'] as $plugin ) {
966 if ( ! is_array( $plugin ) || empty( $plugin ) || empty( $plugin['defined_version'] ) ) {
967 continue;
968 }
969 $plugin_name = $plugin['name'] ?? '';
970 $plugin_slug = $plugin['slug'] ?? '';
971 $plugin_version = $plugin['version'] ?? $plugin['required_version'] ?? '';
972 if ( ! $plugin_version && $plugin_slug === 'woocommerce' ) {
973 $plugin_version = $args['wc_version'] ?? '';
974 }
975 $plugin['version'] = $plugin_version;
976 if ( ! defined( $plugin['defined_version'] ) ) {
977 $msg = sprintf( '%s is <a href="%s" target="_blank">installed and activated.</a>', esc_html( $plugin_name ), network_admin_url( "plugin-install.php?s={$plugin_slug}&tab=search&type=term" ) );
978 $this->notices[] = $msg;
979 } elseif ( $plugin_version && ! version_compare( constant( $plugin['defined_version'] ), $plugin_version, '>=' ) ) {
980 $this->notices[] = sprintf( "%s version at least %s.", esc_html( $plugin_name ), esc_html( $plugin_version ) );
981 }
982 }
983 }
984 }
985
986 public function notice() {
987 $screen = get_current_screen();
988
989 if ( ! current_user_can( 'manage_options' ) || $screen->id === 'update' ) {
990 return;
991 }
992
993 if ( ! empty( $this->notices ) ) {
994 ?>
995 <div class="error">
996 <?php
997 if ( count( $this->notices ) > 1 ) {
998 printf( "<p>%s requires:</p>", esc_html( $this->plugin_name ) );
999 ?>
1000 <ol>
1001 <?php
1002 foreach ( $this->notices as $notice ) {
1003 printf( "<li>%s</li>", wp_kses_post( $notice ) );
1004 }
1005 ?>
1006 </ol>
1007 <?php
1008 } else {
1009 printf( "<p>%s requires %s</p>", esc_html( $this->plugin_name ), wp_kses_post( current( $this->notices ) ) );
1010 }
1011 ?>
1012 </div>
1013 <?php
1014 }
1015 }
1016
1017 public function has_error() {
1018 return ! empty( $this->notices );
1019 }
1020 }
1021 }