PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 2.05.09
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v2.05.09
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmPointers.php

FrmPointers.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 2.05.09, at classes/models/FrmPointers.php

366 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This class handles the pointers used in the introduction tour.
5 */
6 class FrmPointers {
7
8 /**
9 * @var object Instance of this class
10 */
11 public static $instance;
12
13 /**
14 * @var array Holds the buttons to be put out
15 */
16 private $button_array;
17
18 /**
19 * @var array Holds the admin pages we have pointers for and the callback that generates the pointers content
20 */
21 private $admin_pages = array(
22 '' => 'forms_pointer',
23 'entries' => 'entries_pointer',
24 'styles' => 'styles_pointer',
25 'import' => 'import_pointer',
26 'settings' => 'settings_pointer',
27 'addons' => 'addons_pointer',
28 );
29
30 /**
31 * Class constructor.
32 */
33 private function __construct() {
34 if ( current_user_can( 'manage_options' ) ) {
35
36 if ( ! get_user_meta( get_current_user_id(), 'frm_ignore_tour' ) ) {
37 wp_enqueue_style( 'wp-pointer' );
38 wp_enqueue_script( 'jquery-ui' );
39 wp_enqueue_script( 'wp-pointer' );
40 add_action( 'admin_print_footer_scripts', array( $this, 'intro_tour' ) );
41 }
42 }
43 }
44
45 /**
46 * Get the singleton instance of this class
47 *
48 * @return object
49 */
50 public static function get_instance() {
51 if ( ! ( self::$instance instanceof self ) ) {
52 self::$instance = new self();
53 }
54
55 return self::$instance;
56 }
57
58 /**
59 * Load the introduction tour
60 */
61 public function intro_tour() {
62 global $pagenow;
63
64 $page = preg_replace( '/^(formidable[-]?)/', '', filter_input( INPUT_GET, 'page' ) );
65
66 if ( 'admin.php' === $pagenow && array_key_exists( $page, $this->admin_pages ) ) {
67 $this->do_page_pointer( $page );
68 } else {
69 $this->start_tour_pointer();
70 }
71 }
72
73 /**
74 * Prints the pointer script
75 *
76 * @param string $selector The CSS selector the pointer is attached to.
77 * @param array $options The options for the pointer.
78 */
79 public function print_scripts( $selector, $options ) {
80 // Button1 is the close button, which always exists.
81 $default_button = array(
82 'text' => false,
83 'function' => '',
84 );
85 $button_array_defaults = array(
86 'button2' => $default_button,
87 'button3' => $default_button,
88 );
89 $this->button_array = wp_parse_args( $this->button_array, $button_array_defaults );
90 ?>
91 <script type="text/javascript">
92 //<![CDATA[
93 (function ($) {
94 // Don't show the tour on screens with an effective width smaller than 1024px or an effective height smaller than 768px.
95 if (jQuery(window).width() < 1024 || jQuery(window).availWidth < 1024) {
96 return;
97 }
98
99 var frm_pointer_options = <?php echo json_encode( $options ); ?>, setup;
100
101 frm_pointer_options = $.extend(frm_pointer_options, {
102 buttons: function (event, t) {
103 var button = jQuery('<a href="<?php echo esc_url( $this->get_ignore_url() ); ?>" id="pointer-close" style="margin:0 5px;" class="button-secondary">' + '<?php esc_html_e( 'Close', 'formidable' ) ?>' + '</a>');
104 button.bind('click.pointer', function () {
105 t.element.pointer('close');
106 });
107 return button;
108 },
109 close: function () {
110 }
111 });
112
113 setup = function () {
114 $('<?php echo esc_attr( $selector ); ?>').pointer(frm_pointer_options).pointer('open');
115 var lastOpenedPointer = jQuery( '.wp-pointer').slice( -1 );
116 <?php
117 $this->button2();
118 $this->button3();
119 ?>
120 };
121
122 if (frm_pointer_options.position && frm_pointer_options.position.defer_loading)
123 $(window).bind('load.wp-pointers', setup);
124 else
125 $(document).ready(setup);
126 })(jQuery);
127 //]]>
128 </script>
129 <?php
130 }
131
132 /**
133 * Render button 2, if needed
134 */
135 private function button2() {
136 if ( $this->button_array['button2']['text'] ) {
137 ?>
138 lastOpenedPointer.find( '#pointer-close' ).after('<a id="pointer-primary" class="button-primary">' +
139 '<?php echo esc_attr( $this->button_array['button2']['text'] ); ?>' + '</a>');
140 lastOpenedPointer.find('#pointer-primary').click(function () {
141 <?php echo $this->button_array['button2']['function']; ?>
142 });
143 <?php
144 }
145 }
146
147 /**
148 * Render button 3, if needed. This is the previous button in most cases
149 */
150 private function button3() {
151 if ( $this->button_array['button3']['text'] ) {
152 ?>
153 lastOpenedPointer.find('#pointer-primary').after('<a id="pointer-ternary" style="float: left;" class="button-secondary">' +
154 '<?php echo esc_attr( $this->button_array['button3']['text'] ); ?>' + '</a>');
155 lastOpenedPointer.find('#pointer-ternary').click(function () {
156 <?php echo $this->button_array['button3']['function']; ?>
157 });
158 <?php
159 }
160 }
161
162 /**
163 * Show a pointer that starts the tour
164 */
165 private function start_tour_pointer() {
166 $selector = 'li.toplevel_page_formidable';
167
168 $content = '<h3>' . __( 'Congratulations!', 'formidable' ) . '</h3>'
169 . '<p>' . $this->opening_line() . ' ' . __( 'Click &#8220;Start Tour&#8221; to view a quick introduction of this plugin&#8217;s core functionality.', 'formidable' ) . '</p>';
170 $opt_arr = array(
171 'content' => $content,
172 'position' => array(
173 'edge' => 'top',
174 'align' => 'center',
175 ),
176 );
177
178 $this->button_array['button2']['text'] = __( 'Start Tour', 'formidable' );
179 $this->button_array['button2']['function'] = sprintf( 'document.location="%s";', admin_url( 'admin.php?page=formidable' ) );
180
181 $this->print_scripts( $selector, $opt_arr );
182 }
183
184 private function opening_line() {
185 $opening = __( 'You&#8217;ve just installed a new form builder plugin!', 'formidable' );
186 return $opening;
187 }
188
189 /**
190 * Shows a pointer on the proper pages
191 *
192 * @param string $page Admin page key.
193 */
194 private function do_page_pointer( $page ) {
195 $pointer = call_user_func( array( $this, $this->admin_pages[ $page ] ) );
196
197 $opt_arr = array(
198 'content' => $pointer['content'],
199 'position' => array(
200 'edge' => 'top',
201 'align' => ( is_rtl() ) ? 'right' : 'left',
202 ),
203 'pointerWidth' => 450,
204 );
205
206 $selector = 'h2';
207 if ( isset( $pointer['selector'] ) ) {
208 $selector = $pointer['selector'];
209 }
210
211 if ( isset( $pointer['position'] ) ) {
212 $opt_arr['position'] = $pointer['position'];
213 }
214
215 if ( isset( $pointer['next_page'] ) ) {
216 if ( ! empty( $pointer['next_page'] ) ) {
217 $pointer['next_page'] = '-' . $pointer['next_page'];
218 }
219 $this->button_array['button2'] = array(
220 'text' => __( 'Next', 'formidable' ),
221 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=formidable' . $pointer['next_page'] ) ) . '";',
222 );
223 }
224 if ( isset( $pointer['prev_page'] ) ) {
225 if ( ! empty( $pointer['prev_page'] ) ) {
226 $pointer['prev_page'] = '-' . $pointer['prev_page'];
227 }
228 $this->button_array['button3'] = array(
229 'text' => __( 'Previous', 'formidable' ),
230 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=formidable' . $pointer['prev_page'] ) ) . '";',
231 );
232 }
233 $this->print_scripts( $selector, $opt_arr );
234 }
235
236 /**
237 * Returns the content of the Forms listing page pointer
238 *
239 * @return array
240 */
241 private function forms_pointer() {
242 global $current_user;
243
244 return array(
245 'content' => '<h3>' . __( 'Forms', 'formidable' ) . '</h3>'
246 . '<p>' . __( 'All your forms will be listed on this page. Create your first form by clicking on the "Add New" button.', 'formidable' ) . '</p>'
247 . '<p><strong>' . __( 'Subscribe to our Newsletter', 'formidable' ) . '</strong><br/>'
248 . sprintf( __( 'If you would like to hear about new features and updates for %1$s, subscribe to our newsletter:', 'formidable' ), 'Formidable' ) . '</p>'
249 . '<form target="_blank" action="//formidablepro.us1.list-manage.com/subscribe/post?u=a4a913790ffb892daacc6f271&amp;id=7e7df15967" method="post" selector="newsletter-form" accept-charset="' . esc_attr( get_bloginfo( 'charset' ) ) . '">'
250 . '<p>'
251 . '<input style="margin: 5px; color:#666" name="EMAIL" value="' . esc_attr( $current_user->user_email ) . '" selector="newsletter-email" placeholder="' . esc_attr__( 'Email', 'formidable' ) . '"/>'
252 . '<input type="hidden" name="group[4505]" value="4" />'
253 . '<button type="submit" class="button-primary">' . esc_html__( 'Subscribe', 'formidable' ) . '</button>'
254 . '</p>'
255 . '</form>',
256 'next_page' => 'entries',
257 );
258 }
259
260 /**
261 * Returns the content of the Entries listing page pointer
262 *
263 * @return array
264 */
265 private function entries_pointer() {
266 return array(
267 'content' => '<h3>' . __( 'Entries', 'formidable' ) . '</h3>'
268 . '<p>' . __( 'Each time one of your forms is submitted, an entry is created. You will find every form submission listed here so you will always have a backup if an email fails.', 'formidable' ) . '</p>',
269 'prev_page' => '',
270 'next_page' => 'styles',
271 'selector' => '.wp-list-table',
272 'position' => array(
273 'edge' => 'bottom',
274 'align' => 'center',
275 ),
276 );
277 }
278
279 /**
280 * Returns the content of the Styles page pointer
281 *
282 * @return array
283 */
284 private function styles_pointer() {
285 return array(
286 'content' => '<h3>' . __( 'Styles', 'formidable' ) . '</h3>'
287 . '<p>' . __( 'Want to make changes to the way your forms look? Make all the changes you would like right here, and watch the sample form change before your eyes.', 'formidable' ) . '</p>',
288 'prev_page' => 'entries',
289 'next_page' => 'import',
290 'selector' => '.general-style',
291 'position' => array(
292 'edge' => 'left',
293 'align' => 'right',
294 ),
295 );
296 }
297
298 /**
299 * Returns the content of the Import/Export page pointer
300 *
301 * @return array
302 */
303 private function import_pointer() {
304 return array(
305 'content' => '<h3>' . __( 'Import/Export', 'formidable' ) . '</h3>'
306 . '<p>' . __( 'Import and export forms and styles when copying from one site to another or sharing with someone else. Your entries can be exported to a CSV as well. The Premium version also includes the option to import entries to your site from a CSV.', 'formidable' ) . '</p>',
307 'prev_page' => 'styles',
308 'next_page' => 'settings',
309 'selector' => '.inside.with_frm_style',
310 'position' => array(
311 'edge' => 'bottom',
312 'align' => 'top',
313 ),
314 );
315 }
316
317 /**
318 * Returns the content of the advanced page pointer
319 *
320 * @return array
321 */
322 private function settings_pointer() {
323 return array(
324 'content' => '<h3>' . __( 'Global Settings', 'formidable' ) . '</h3>'
325 . '<p><strong>' . __( 'General', 'formidable' ) . '</strong><br/>'
326 . __( 'Turn stylesheets and scripts off, set which user roles have access to change and create forms, setup your reCaptcha, and set default messages for new forms and fields.', 'formidable' )
327 . '<p><strong>' . __( 'Plugin Licenses', 'formidable' ) . '</strong><br/>'
328 . sprintf( __( 'Once you&#8217;ve purchased %1$s or any addons, you&#8217;ll have to enter a license key to get access to all of their powerful features. A Plugin Licenses tab will appear here for you to enter your license key.', 'formidable' ), 'Formidable Pro' )
329 . '</p>',
330 'prev_page' => 'import',
331 'next_page' => 'addons',
332 );
333 }
334
335 /**
336 * Returns the content of the extensions and licenses page pointer
337 *
338 * @return array
339 */
340 private function addons_pointer() {
341 return array(
342 'content' => '<h3>' . __( 'Addons', 'formidable' ) . '</h3>'
343 . '<p>' . sprintf( __( 'The powerful functions of %1$s can be extended with %2$spremium plugins%3$s. You can read all about the Formidable Premium Plugins %2$shere%3$s.', 'formidable' ), 'Formidable', '<a target="_blank" href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/' ) ) . '">', '</a>' )
344 . '</p>'
345 . '<p><strong>' . __( 'Like this plugin?', 'formidable' ) . '</strong><br/>' . sprintf( __( 'So, we&#8217;ve come to the end of the tour. If you like the plugin, please %1$srate it 5 stars on WordPress.org%2$s!', 'formidable' ), '<a target="_blank" href="https://wordpress.org/plugins/formidable/">', '</a>' ) . '</p>'
346 . '<p>' . sprintf( __( 'Thank you for using our plugin and good luck with your forms!<br/><br/>Best,<br/>Team Formidable - %1$sformidableforms.com%2$s', 'formidable' ), '<a target="_blank" href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/' ) ) . '">', '</a>' ) . '</p>',
347 'prev_page' => 'settings',
348 );
349 }
350
351 /**
352 * Extending the current page URL with two params to be able to ignore the tour.
353 *
354 * @return mixed
355 */
356 private function get_ignore_url() {
357 $arr_params = array(
358 'frm_restart_tour' => false,
359 'frm_ignore_tour' => '1',
360 'nonce' => wp_create_nonce( 'frm-ignore-tour' ),
361 );
362
363 return add_query_arg( $arr_params );
364 }
365 }
366