PluginProbe ʕ •ᴥ•ʔ
Catalog Booster & Product Catalog Mode for WooCommerce / 1.2.8
Catalog Booster & Product Catalog Mode for WooCommerce v1.2.8
trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8
catalog-booster-for-woocommerce / includes / tooltips.php
catalog-booster-for-woocommerce / includes Last commit date
pluggable 2 years ago index.php 2 years ago tooltips.php 1 year ago woocat_activation_wizard.php 2 years ago woocat_admin_disabler.php 2 years ago woocat_button.php 1 year ago woocat_cart.php 1 year ago woocat_catalog.php 1 year ago woocat_disabler.php 2 years ago woocat_ic_cart.php 5 years ago woocat_listing.php 9 months ago woocat_page.php 9 months ago woocat_settings.php 9 months ago
tooltips.php
371 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5 /*
6 *
7 * @version 1.0.0
8 * @package
9 * @author impleCode
10 *
11 */
12
13 if ( ! function_exists( 'implecode_enable_wp_tooltips' ) ) {
14 add_action( 'admin_enqueue_scripts', 'implecode_enable_wp_tooltips' );
15
16 function implecode_enable_wp_tooltips() {
17 wp_enqueue_style( 'wp-pointer' );
18 wp_enqueue_script( 'wp-pointer' );
19 //hook the pointer
20 add_action( 'admin_print_footer_scripts', 'implecode_show_wp_tooltips' );
21 }
22
23 }
24
25 if ( ! function_exists( 'implecode_show_wp_tooltips' ) ) {
26
27 function implecode_show_wp_tooltips() {
28 $tooltips = apply_filters( 'implecode_wp_tooltips', implecode_wp_tooltip_get() );
29 if ( empty( $tooltips ) || ! is_array( $tooltips ) ) {
30 return;
31 }
32 foreach ( $tooltips as $key => $tooltip ) {
33 foreach ( $tooltip as $key_t => $tool ) {
34 $tooltips[ $key ][ $key_t ] = htmlspecialchars( $tool );
35 }
36 }
37 $json_tooltips = json_encode( $tooltips, JSON_HEX_QUOT );
38 /*
39 $tooltip_content = '';
40 foreach ( $tooltips as $tooltip ) {
41 $tooltip_content .= '<h3>' . $tooltip[ 'title' ] . '</h3>';
42 $tooltip_content .= '<p>' . $tooltip[ 'text' ] . '</p>';
43 $tooltip_selector = $tooltip[ 'selector' ];
44 break;
45 }
46 if ( empty( $tooltip_selector ) ) {
47 return;
48 }
49 *
50 */
51 ?>
52 <script type="text/javascript">
53 jQuery(document).ready(function ($) {
54 if (jQuery(".ic_cat-activation-wizard").length > 0) {
55 return false;
56 }
57 setTimeout(function () {
58 var tooltips = JSON.parse('<?php echo $json_tooltips ?>');
59 console.log(tooltips);
60 ic_show_next_pointer(tooltips, 1);
61 }, 5000);
62
63 function ic_show_next_pointer(tooltips, do_not_scroll) {
64 jQuery.each(tooltips, function (index, value) {
65 var selector = value.selector.replace(/&quot;/g, '"');
66 var last_selector = 0;
67 if (selector === '') {
68 if (jQuery(".ic-settings-search .button-secondary").length !== 0) {
69 selector = 'implecode_settings .ic-settings-search .button-secondary';
70 } else {
71 selector = 'help';
72 }
73 last_selector = 1;
74 }
75 if (jQuery("#" + selector).length > 0) {
76 var position = 'top';
77 if (jQuery("#al_product_desc").length > 0) {
78 position = 'bottom';
79 }
80 if (jQuery(".nav-tab-wrapper").find("#" + selector).length > 0) {
81 position = {'edge': 'left', 'align': 'middle'};
82 }
83 if (selector.includes("implecode_settings")) {
84 position = {'edge': 'right', 'align': 'left'};
85 }
86 var pointer_selector = jQuery('#' + selector);
87 var original_selector = pointer_selector;
88 /*
89 var selected_selector = jQuery( '#' + selector + ":checked" );
90 if ( selected_selector.length !== 0 ) {
91 pointer_selector = selected_selector;
92 } else {
93 pointer_selector = pointer_selector.first();
94 }
95 */
96 pointer_selector = pointer_selector.first();
97
98 var selector_label = pointer_selector.closest("tr");
99 if (selector_label.length !== 0) {
100 pointer_selector = selector_label;
101 }
102 var open_pointer = pointer_selector.first();
103 open_pointer.addClass("ic-pointer-opened");
104 if (do_not_scroll === 0) {
105 ic_pointer_out_of_screen(open_pointer);
106 }
107 open_pointer.pointer({
108 pointerClass: "ic_pointer_" + index + " wp-pointer",
109 content: "<h3>" + value.title + "</h3>" + "<p>" + value.text + "</p>",
110 /* position: { 'edge': 'top', 'align': 'middle' },*/
111 position: position,
112 close: function () {
113 open_pointer.removeClass("ic-pointer-opened");
114 },
115 buttons: function (event, t) {
116 if (last_selector === 1) {
117 return ic_pointer_default_buttons(t);
118 } else {
119 return ic_pointer_buttons(t, selector);
120 }
121 },
122 }).pointer('open');
123 var change_action = 'change';
124 original_selector.on(change_action, function () {
125 var active_pointer = jQuery(".ic_pointer_" + index);
126 if (active_pointer.is(":visible")) {
127 active_pointer.find(".close").click();
128 ic_hide_pointer(selector);
129 }
130 });
131 return false;
132 }
133 });
134 }
135
136 function ic_hide_pointer(selector) {
137 var data = {
138 'action': 'implecode_wp_tooltip_hide',
139 'selector': selector
140 };
141 jQuery.post(ajaxurl, data, function (response) {
142 if (response !== undefined) {
143 var tooltips = JSON.parse(response);
144 ic_show_next_pointer(tooltips, 0);
145 }
146 });
147 }
148
149 function ic_dismiss_all_pointers() {
150 var data = {
151 'action': 'implecode_wp_tooltip_dismiss_all',
152 };
153 jQuery.post(ajaxurl, data);
154 }
155
156 function ic_pointer_out_of_screen(element) {
157 var top_of_element = element.offset().top;
158 var bottom_of_element = top_of_element + element.outerHeight();
159 var bottom_of_screen = jQuery(window).scrollTop() + jQuery(window).innerHeight();
160 var top_of_screen = jQuery(window).scrollTop();
161
162 if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)) {
163 return false;
164 } else {
165 jQuery([document.documentElement, document.body]).animate({
166 scrollTop: top_of_element - 220
167 }, 2000);
168 return true;
169 }
170 }
171
172 function ic_pointer_buttons(t, selector) {
173 var button1 = jQuery('<a class="close ic-pointer-dismiss" href="#"></a>').text("<?php _e( 'Cancel Tutorial', 'ecommerce-product-catalog' ) ?>");
174 var button2 = jQuery('<a class="button-primary" href="#"></a>').text("<?php _e( 'Next', 'ecommerce-product-catalog' ) ?>");
175 var wrapper = jQuery('<div class=\"wc-pointer-buttons\" />');
176 button1.bind('click.pointer', function (e) {
177 e.preventDefault();
178 if (confirm("<?php _e( 'Are you sure? This will disable all tutorial boxes on all screens.', 'ecommerce-product-catalog' ) ?>") == true) {
179 t.element.pointer('close');
180 ic_dismiss_all_pointers();
181 }
182 });
183 button2.bind('click.pointer', function (e) {
184 e.preventDefault();
185 t.element.pointer('close');
186 ic_hide_pointer(selector);
187 });
188 wrapper.append(button2);
189 wrapper.append(button1);
190 return wrapper;
191 }
192
193 function ic_pointer_default_buttons(t) {
194 var button = jQuery('<a class="close" href="#"></a>').text(wp.i18n.__('Dismiss'));
195
196 return button.bind('click.pointer', function (e) {
197 e.preventDefault();
198 t.element.pointer('close');
199 });
200 }
201 }
202 );
203 </script>
204 <?php
205 }
206
207 }
208 if ( ! function_exists( 'implecode_wp_tooltip_hide' ) ) {
209 add_action( 'wp_ajax_implecode_wp_tooltip_hide', 'implecode_ajax_wp_tooltip_hide' );
210
211 function implecode_ajax_wp_tooltip_hide() {
212 $selector = isset( $_POST['selector'] ) ? stripslashes( $_POST['selector'] ) : '';
213 implecode_wp_tooltip_hide( $selector );
214 $tooltips = implecode_wp_tooltip_get();
215 //if ( empty( $tooltips ) ) {
216 $tooltips[] = implecode_wp_tooltip_default();
217 // }
218 echo json_encode( $tooltips );
219 wp_die();
220 }
221
222 }
223
224 if ( ! function_exists( 'implecode_wp_tooltip_dismiss_all' ) ) {
225 add_action( 'wp_ajax_implecode_wp_tooltip_dismiss_all', 'implecode_wp_tooltip_dismiss_all' );
226
227 function implecode_wp_tooltip_dismiss_all() {
228 update_option( 'implecode_wp_tooltips', 'disabled' );
229 wp_die();
230 }
231
232 }
233 if ( ! function_exists( 'implecode_wp_tooltip_hide' ) ) {
234
235 function implecode_wp_tooltip_hide( $selector ) {
236 if ( empty( $selector ) ) {
237 return;
238 }
239 $tooltips = implecode_wp_tooltip_get();
240 if ( ! is_array( $tooltips ) ) {
241 return;
242 }
243 foreach ( $tooltips as $key => $tooltip ) {
244 if ( $tooltip['selector'] === $selector ) {
245 unset( $tooltips[ $key ] );
246 }
247 }
248 update_option( 'implecode_wp_tooltips', $tooltips );
249 implecode_wp_tooltip_hidden_update( $selector );
250 }
251
252 }
253
254 if ( ! function_exists( 'implecode_wp_tooltip_get' ) ) {
255
256 function implecode_wp_tooltip_get() {
257 $tooltips = get_option( 'implecode_wp_tooltips', array() );
258 if ( ! is_array( $tooltips ) && $tooltips !== 'disabled' ) {
259 $tooltips = array();
260 }
261
262 return $tooltips;
263 }
264
265 }
266
267 if ( ! function_exists( 'implecode_wp_tooltip_hidden_get' ) ) {
268
269 function implecode_wp_tooltip_hidden_get() {
270 $tooltips = get_option( 'implecode_wp_hidden_tooltips', array() );
271
272 return $tooltips;
273 }
274
275 }
276
277 if ( ! function_exists( 'implecode_wp_tooltip_hidden_update' ) ) {
278
279 function implecode_wp_tooltip_hidden_update( $selector ) {
280 $hidden_tooltips = implecode_wp_tooltip_hidden_get();
281 $hidden_tooltips[] = $selector;
282 update_option( 'implecode_wp_hidden_tooltips', $hidden_tooltips );
283 }
284
285 }
286
287 if ( ! function_exists( 'implecode_is_wp_tooltip_hidden' ) ) {
288
289 function implecode_is_wp_tooltip_hidden( $selector ) {
290 $tooltips = implecode_wp_tooltip_get();
291 if ( $tooltips === 'disabled' ) {
292 return true;
293 }
294 $hidden_tooltips = implecode_wp_tooltip_hidden_get();
295 if ( in_array( $selector, $hidden_tooltips ) ) {
296 return true;
297 }
298
299 return false;
300 }
301
302 }
303
304 if ( ! function_exists( 'implecode_wp_tooltip_exists' ) ) {
305
306 function implecode_wp_tooltip_exists( $selector ) {
307 $tooltips = implecode_wp_tooltip_get();
308 if ( ! is_array( $tooltips ) ) {
309 return false;
310 }
311 foreach ( $tooltips as $tooltip ) {
312 if ( $tooltip['selector'] === $selector ) {
313 return true;
314 }
315 }
316
317 return false;
318 }
319
320 }
321
322 if ( ! function_exists( 'implecode_wp_tooltip_add' ) ) {
323
324 function implecode_wp_tooltip_add( $title, $text, $selector, $on_top = false ) {
325 if ( empty( $title ) || empty( $text ) || empty( $selector ) ) {
326 return false;
327 }
328 if ( implecode_wp_tooltip_exists( $selector ) ) {
329 return false;
330 }
331
332 if ( implecode_is_wp_tooltip_hidden( $selector ) ) {
333 return false;
334 }
335
336 $tooltips = implecode_wp_tooltip_get();
337 if ( ! is_array( $tooltips ) ) {
338 $tooltips = array();
339 }
340 $tooltip = array(
341 'title' => $title,
342 'text' => $text,
343 'selector' => $selector
344 );
345 if ( $on_top ) {
346 $tooltips = array_merge( array( $tooltip ), $tooltips );
347 } else {
348 $tooltips[] = $tooltip;
349 }
350 update_option( 'implecode_wp_tooltips', $tooltips );
351
352 return true;
353 }
354
355 }
356
357 if ( ! function_exists( 'implecode_wp_tooltip_default' ) ) {
358
359 function implecode_wp_tooltip_default() {
360 $tooltip = array(
361 'title' => __( 'Screen Tutorial Complete', 'ecommerce-product-catalog' ),
362 'text' => __( 'Congratulations! You finished the tutorial on this screen. Check all the options here and go to another screen to continue.', 'ecommerce-product-catalog' ) . '<br><br>' . sprintf( __( 'If you have any questions or issues you can reach the developers on the %1$ssupport forum%2$s.', 'ecommerce-product-catalog' ), '<a href="https://wordpress.org/support/plugin/ecommerce-product-catalog/">', '</a>' ),
363 'selector' => ''
364 );
365
366 return $tooltip;
367 }
368
369 }
370
371