PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / includes / eoi-tour-pointer.php

eoi-tour-pointer.php in GetResponse Forms by Optin Cat 2.0.2, at includes/eoi-tour-pointer.php

328 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package thuantp
4 */
5
6 /**
7 * This class handles the pointers used in the introduction tour.
8 *
9 * @todo Add an introductory pointer on the edit post page too.
10 */
11 class EOITourPointer {
12
13 // get all infor of plugin
14 private $plugin_data;
15
16 // the option fca_eoi_take_the_tour
17 private $options;
18
19 // the post_type
20 private $post_type;
21
22 private $settings;
23
24 public function __construct( $settings=null ) {
25
26 $this->settings = $settings;
27 $this->post_type = $settings['post_type'];
28 $this->options = get_option( 'fca_eoi_take_the_tour' );
29
30 if ( ! in_array( $this->options, array( 'closed' ) ) ) {
31
32 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
33
34 add_filter( 'admin_url', array( $this, 'add_fca_eoi_tour_item_param' ) );
35 add_action( 'wp_ajax_fca_eoi_take_the_tour', array( $this, 'fca_eoi_take_the_tour_pointer_ajax' ) );
36 }
37 }
38
39 /**
40 * Loads CSS and JS elements for pointer popup
41 */
42 public function enqueue_assets() {
43
44 wp_enqueue_style( 'wp-pointer' );
45 wp_enqueue_script( 'wp-pointer' );
46 add_action( 'admin_print_footer_scripts', array( $this, 'intro_tour' ) );
47 }
48
49 /*
50 * re-write the url after saving post via tour pointer
51 */
52 function add_fca_eoi_tour_item_param ( $link ) {
53
54 $tour_item = K::get_var( 'fca-eoi-tour-item', $_REQUEST );
55 if ( ! empty( $tour_item ) ) {
56 $link = add_query_arg( array( 'fca-eoi-tour-item' => urlencode( $tour_item ) ), $link );
57 }
58 return $link;
59 }
60
61 /*
62 * Update option fca_eoi_take_the_tour
63 */
64 function fca_eoi_take_the_tour_pointer_ajax () {
65
66 // Verify nonce
67 if ( ! wp_verify_nonce( $_POST['nonce'], 'fca_eoi_take_the_tour' ) ) {
68 die( __( 'An error occurred, please try again.' ) );
69 }
70
71 // Check status
72 update_option( 'fca_eoi_take_the_tour', 'closed' );
73 exit;
74 }
75
76 /**
77 * Load the introduction tour
78 */
79 function intro_tour() {
80
81 global $pagenow;
82
83 $this->plugin_data = get_plugin_data( FCA_EOI_PLUGIN_DIR . 'easy-opt-ins.php' );
84
85 // Ajax request template
86
87 $ajax = '
88 jQuery.ajax( {
89 type: "POST",
90 url: "' . admin_url( 'admin-ajax.php' ) . '",
91 data: {
92 action: "fca_eoi_take_the_tour",
93 nonce: "' . wp_create_nonce( 'fca_eoi_take_the_tour' ) . '"
94 }
95 } );
96 ';
97
98 // if there is more than 1 layout the number will be 6 , otherwise 5
99 $init_pointer_number = 5;
100 if ( count( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) ) > 1 ) {
101 $init_pointer_number += 1;
102 };
103
104 $page_items = array(
105 'fca_eoi_form_integration' => array(
106 'target' => '#fca_eoi_fieldset_form_integration',
107 'options' => array(
108 'content' => sprintf( '<h3>%s</h3><p>%s</p>'
109 , __( 'Mailing List Integration' )
110 , __( 'First, integrate '. $this->plugin_data[ 'Name' ] .' with your mailing list.' )
111 ),
112 'position' => array(
113 'edge' => 'bottom',
114 'align' => 'middle'
115 ),
116 'pointerClass' => 'fca_eoi_tour_pointer_style',
117 ),
118 'button1' => __( 'Close' ),
119 'button2' => __( 'Next' ),
120 'button3' => __( 'Previous' ),
121 'button1_function' => $ajax
122
123 ),
124 'fca_eoi_fieldset_thank_you_page' => array(
125 'target' => '#fca_eoi_fieldset_thank_you_page',
126 'options' => array(
127 'content' => sprintf( '<h3>%s</h3><p>%s</p>'
128 , __( 'Thank you page' )
129 , __( 'Next, select a thank you page <em>(selecting a thank you page is required)</em>.' )
130 ),
131 'position' => array(
132 'edge' => 'bottom',
133 'align' => 'center'
134 ),
135 'pointerClass' => 'fca_eoi_tour_pointer_style'
136 ),
137 'button1' => __( 'Close' ),
138 'button2' => __( 'Next' ),
139 'button3' => __( 'Previous' ),
140 'button1_function' => $ajax
141 ),
142 'fca_eoi_design_and_content_headline' => array(
143 'target' => '#fca_eoi_design_and_content_headline',
144 'options' => array(
145 'content' => '<h3>' . __( 'Design & Content' ) . '</h3>' . '<p>' . __( 'You can customize your opt-in form in this area. You can click anywhere on your form to change the text, colors, etc...' ) . '</p>'
146 ,
147 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
148 'pointerClass' => 'fca_eoi_tour_pointer_style'
149 ),
150 'button1' => __( 'Close' ),
151 'button2' => __( 'Next' ),
152 'button3' => __( 'Previous' ),
153 'button1_function' => $ajax,
154 ),
155 'fca_eoi_save' => array(
156 'target' => '#publish',
157 'options' => array(
158 'content' => '<h3>' . __( 'Save' ) . '</h3>'. '<p>' . __( 'Make sure to hit ‘Save Form’ now that you’ve set up your form.' ) . '</p>'
159 ,
160 'position' => array( 'edge' => 'bottom', 'align' => 'left' ),
161 'pointerClass' => 'fca_eoi_tour_pointer_style',
162 ),
163 'button1' => __( 'Close' ),
164 'button2' => __( 'Save Now' ),
165 'button3' => __( 'Previous' ),
166 'button1_function' => $ajax,
167 'button2_function' => "$( '#publish' ).click()",
168 'extra_function' => "var form = $(pointer.target).closest( 'form' );$(pointer.target).after( '<input type=\"hidden\" name=\"fca-eoi-tour-item\" value=\"$init_pointer_number\"/>' );"
169 ),
170 );
171
172 if( $init_pointer_number == 6 ) {
173
174 $fca_eoi_choose_layout = array(
175 'target' => 'a[href="#fca_eoi_meta_box_setup"]',
176 'options' => array(
177 'content' => '<h3>' . __( 'Choose Layout' ) . '</h3>' . '<p>' . __( 'Choose a Layout to get started.' ) . '</p>',
178 'position' => array( 'edge' => 'bottom', 'align' => 'left' ),
179 'pointerClass' => 'fca_eoi_tour_pointer_style'
180 ),
181 'button1' => __( 'Close' ),
182 'button2' => __( 'Next' ),
183 'button3' => __( 'Previous' ),
184 'button1_function' => $ajax,
185 'extra_function' => "$( '[href=\"#fca_eoi_meta_box_setup\"]' ).click();",
186 );
187 // push this array to the beginning of $page_items array
188 array_unshift( $page_items, $fca_eoi_choose_layout );
189 }
190
191 $fca_eoi_dashboard_tour_item = array(
192 'target' => '#menu-posts-easy-opt-ins',
193 'options' => array(
194 'content' => '<h3>' . __( 'Getting started' ) . '</h3>' . '<p>' . __( 'Thanks for installing '. $this->plugin_data['Name'] .'. Click “Start Tour” to view a quick introduction of how to use this plugin.' ) . '</p>'
195 ,
196 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
197 'pointerClass' => 'fca_eoi_tour_dashboard'
198 ),
199 'button1' => __( 'Close' ),
200 'button2' => __( 'Start tour' ),
201 'button1_function' => $ajax,
202 'button2_function' => ''
203 );
204
205 $fca_eoi_index_tour_item = 1;
206
207 if ( ! isset( $_GET[ 'fca-eoi-tour-item' ] ) ) {
208 if ( FALSE
209 || 'easy-opt-ins' !== $this->post_type
210 || ( $pagenow == 'edit.php' && 'easy-opt-ins' == $this->post_type )
211 ) {
212 $fca_eoi_dashboard_tour_item = array(
213 'target' => '#menu-posts-easy-opt-ins',
214 'options' => array(
215 'content' => '<h3>' . __( 'Getting started' ) . '</h3>' . '<p>' . __( 'Thanks for installing '. $this->plugin_data['Name'] .'. Click “Start Tour” to view a quick introduction of how to use this plugin.' ) . '</p>',
216 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
217 'pointerClass' => 'fca_eoi_tour_dashboard'
218 ),
219 'button1' => __( 'Close' ),
220 'button2' => __( 'Start tour' ),
221 'button2_function' => "document.location='" . admin_url( 'post-new.php?post_type=easy-opt-ins&fca-eoi-tour-item=1' )."'",
222 );
223 }
224
225 $fca_eoi_index_tour_item = 0;
226 } else {
227 if ( K::get_var( 'fca-eoi-tour-item', $_GET ) == $init_pointer_number ) {
228
229 $fca_eoi_index_tour_item = $init_pointer_number;
230 $fca_eoi_publish_tour_item = array(
231 'target' => '#menu-appearance',
232 'options' => array(
233 'content' => '<h3> Publish </h3>' . '<p>' . __( 'You can publish your opt-in widget by going to “Appearance -> Widgets” and choosing the “Optin Cat Sidebar Widget”.' ) . '</p>'
234 ,
235 'position' => array( 'edge' => 'top', 'align' => 'center' ),
236 'pointerClass' => 'fca_eoi_tour_pointer_style'
237 ),
238 'button1' => __( 'Close' ),
239 'button3' => __( 'Previous' ),
240 'button1_function' => $ajax,
241 );
242 $page_items['fca_eoi_publish'] = $fca_eoi_publish_tour_item;
243 }
244 }
245 // push this array to the beginning of $page_items array
246 array_unshift( $page_items, $fca_eoi_dashboard_tour_item );
247
248 $this->print_scripts( $fca_eoi_index_tour_item ,$page_items );
249 }
250
251 /**
252 * Prints the pointer script
253 *
254 * @param string $selector The CSS selector the pointer is attached to.
255 * @param array $options The options for the pointer.
256 * @param string $button1 Text for button 1
257 * @param string|bool $button2 Text for button 2 (or false to not show it, defaults to false)
258 * @param string $button2_function The JavaScript function to attach to button 2
259 * @param string $button1_function The JavaScript function to attach to button 1
260 */
261 function print_scripts( $fca_eoi_tour_index, $options) {
262 ?><script>
263 jQuery( document ).ready( function( $ ) {
264 var fca_eoi_tour_pointer_options_json = <?php echo json_encode( $options ); ?>;
265 var fca_eoi_tour_pointer_options = [];
266 for ( elem in fca_eoi_tour_pointer_options_json ) {
267 fca_eoi_tour_pointer_options.push( fca_eoi_tour_pointer_options_json[ elem ] );
268 }
269
270 $( window ).load( function( $ ) {
271 setTimeout( function() {
272 fca_eoi_open_pointer( <?php echo $fca_eoi_tour_index ?> );
273 }, 500 );
274 } );
275
276 function fca_eoi_open_pointer( i ) {
277
278 $( '[href="#fca_eoi_meta_box_build"]' ).click();
279 var pointer = fca_eoi_tour_pointer_options[ i ];
280 var button2_function_text = pointer.button2_function;
281 var button1_function_text = pointer.button1_function;
282 var extra_function_text = pointer.extra_function;
283
284 // excute the extra function
285 if ( extra_function_text ) {
286 eval( extra_function_text );
287 }
288
289 options = $.extend( pointer.options, {
290 buttons:function ( event, t ) {
291 button = jQuery( '<a id="fca-eoi-tour-pointer-close-'+ i +'" style="margin-left:5px" class="button-secondary">' + pointer.button1 + '</a>' );
292 button.bind( 'click.pointer', function () {
293 t.element.pointer( 'close' );
294 if( pointer.button1_function ) {
295 eval( button1_function_text );
296 }
297 } );
298 return button;
299 },
300 close: function() {}
301 });
302 $( pointer.target +':not(.expanded) legend' ).click();
303 $( pointer.target ).pointer( options ).pointer( 'open' );
304
305 if ( pointer.button2 ) {
306
307 jQuery( '#fca-eoi-tour-pointer-close-'+i ).after( '<a id="fca-eoi-tour-pointer-primary-'+ i +'" class="button-primary">' + pointer.button2 + '</a>' );
308 jQuery( '#fca-eoi-tour-pointer-primary-' + i ).click( function ( e ) {
309 e.preventDefault();
310 $( pointer.target ).pointer( 'close' );
311 eval( button2_function_text );
312 fca_eoi_open_pointer( i + 1 );
313 } );
314 }
315
316 if ( pointer.button3 ) {
317 jQuery( '#fca-eoi-tour-pointer-close-'+i ).after( '<a id="fca-eoi-tour-pointer-previous-'+ i +'" class="button-secondary">' + pointer.button3 + '</a>' );
318 jQuery( '#fca-eoi-tour-pointer-previous-'+i ).click( function () {
319 $( pointer.target ).pointer( 'close' );
320 fca_eoi_open_pointer( i - 1 );
321 } );
322 }
323 }
324 } );
325 </script><?php
326 }
327 }
328