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 / controllers / FrmAppController.php

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

437 lines 14.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmAppController {
4
5 public static function menu() {
6 FrmAppHelper::maybe_add_permissions();
7 if ( ! current_user_can( 'frm_view_forms' ) ) {
8 return;
9 }
10
11 $menu_name = FrmAppHelper::get_menu_name();
12 add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', '', self::get_menu_position() );
13 }
14
15 private static function get_menu_position() {
16 $count = count( get_post_types( array(
17 'show_ui' => true,
18 '_builtin' => false,
19 'show_in_menu' => true,
20 ) ) );
21 $pos = $count ? '22.7' : '29.3';
22 $pos = apply_filters( 'frm_menu_position', $pos );
23 return $pos;
24 }
25
26 public static function load_wp_admin_style() {
27 FrmAppHelper::load_font_style();
28 }
29
30 public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
31 $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
32 if ( empty( $show_nav ) || ! $form ) {
33 return;
34 }
35
36 FrmForm::maybe_get_form( $form );
37 if ( ! is_object( $form ) ) {
38 return;
39 }
40
41 $id = $form->id;
42 $current_page = self::get_current_page();
43 $nav_items = self::get_form_nav_items( $form );
44
45 include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
46 }
47
48 private static function get_current_page() {
49 global $pagenow;
50
51 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
52 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
53 $current_page = isset( $_GET['page'] ) ? $page : $post_type;
54 if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
55 $current_page = 'frm_display';
56 }
57
58 return $current_page;
59 }
60
61 private static function get_form_nav_items( $form ) {
62 $id = $form->parent_form_id ? $form->parent_form_id : $form->id;
63
64 $nav_items = array(
65 array(
66 'link' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $id ) ),
67 'label' => __( 'Build', 'formidable' ),
68 'current' => array( 'edit', 'new', 'duplicate' ),
69 'page' => 'formidable',
70 'permission' => 'frm_edit_forms',
71 ),
72 array(
73 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ),
74 'label' => __( 'Settings', 'formidable' ),
75 'current' => array( 'settings' ),
76 'page' => 'formidable',
77 'permission' => 'frm_edit_forms',
78 ),
79 array(
80 'link' => admin_url( 'admin.php?page=formidable-entries&frm_action=list&form=' . absint( $id ) ),
81 'label' => __( 'Entries', 'formidable' ),
82 'current' => array(),
83 'page' => 'formidable-entries',
84 'permission' => 'frm_view_entries',
85 ),
86 );
87
88 $nav_items = apply_filters( 'frm_form_nav_list', $nav_items, array(
89 'form_id' => $id,
90 'form' => $form,
91 ) );
92 return $nav_items;
93 }
94
95 // Adds a settings link to the plugins page
96 public static function settings_link( $links ) {
97 $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
98 array_unshift( $links, $settings );
99
100 return $links;
101 }
102
103 public static function pro_get_started_headline() {
104 self::maybe_show_upgrade_bar();
105
106 // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message
107 if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) {
108 return;
109 }
110
111 if ( get_site_option( 'frmpro-authorized' ) && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
112 FrmAppHelper::load_admin_wide_js();
113
114 // user is authorized, but running free version
115 $inst_install_url = 'https://formidableforms.com/knowledgebase/install-formidable-forms/';
116 ?>
117 <div class="error" class="frm_previous_install">
118 <?php
119 echo wp_kses_post( apply_filters( 'frm_pro_update_msg',
120 sprintf(
121 __( 'This site has been previously authorized to run Formidable Forms.<br/>%1$sInstall Formidable Pro%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
122 '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
123 '<a href="#" class="frm_deauthorize_link">', '</a>'
124 ), esc_url( $inst_install_url )
125 ) );
126 ?>
127 </div>
128 <?php
129 }
130 }
131
132 private static function maybe_show_upgrade_bar() {
133 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
134 if ( strpos( $page, 'formidable' ) !== 0 ) {
135 return;
136 }
137
138 if ( FrmAppHelper::pro_is_installed() ) {
139 return;
140 }
141
142 $affiliate = FrmAppHelper::get_affiliate();
143 if ( ! empty( $affiliate ) ) {
144 $tip = FrmTipsHelper::get_banner_tip();
145 ?>
146 <div class="update-nag frm-update-to-pro">
147 <?php echo FrmAppHelper::kses( $tip['tip'] ); ?>
148 <span><?php echo FrmAppHelper::kses( $tip['call'] ); ?></span>
149 <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com?banner=1&tip=' . absint( $tip['num'] ) ) ); ?>" class="button">Upgrade to Pro</a>
150 </div>
151 <?php
152 }
153 }
154
155 /**
156 * If there are CURL problems on this server, wp_remote_post won't work for installing
157 * Use a javascript fallback instead.
158 *
159 * @since 2.0.3
160 */
161 public static function install_js_fallback() {
162 FrmAppHelper::load_admin_wide_js();
163 echo '<div id="hidden frm_install_message"></div><script type="text/javascript">jQuery(document).ready(function(){frm_install_now();});</script>';
164 }
165
166 /**
167 * Check if the database is outdated
168 *
169 * @since 2.0.1
170 * @return boolean
171 */
172 public static function needs_update() {
173 $db_version = (int) get_option( 'frm_db_version' );
174 $needs_upgrade = ( (int) $db_version < (int) FrmAppHelper::$db_version );
175 if ( ! $needs_upgrade ) {
176 $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
177 }
178 return $needs_upgrade;
179 }
180
181 /**
182 * Check for database update and trigger js loading
183 *
184 * @since 2.0.1
185 */
186 public static function admin_init() {
187 if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) {
188 self::network_upgrade_site();
189 }
190
191 $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
192 if ( ! FrmAppHelper::doing_ajax() || $action == 'frm_import_choices' ) {
193 // don't continue during ajax calls
194 self::load_tour();
195 self::admin_js();
196 }
197 }
198
199 /**
200 * See if we should start our tour.
201 * @since 2.0.20
202 */
203 private static function load_tour() {
204 $restart_tour = filter_input( INPUT_GET, 'frm_restart_tour' );
205 if ( $restart_tour ) {
206 delete_user_meta( get_current_user_id(), 'frm_ignore_tour' );
207 }
208 self::ignore_tour();
209
210 if ( ! self::has_ignored_tour() ) {
211 add_action( 'admin_enqueue_scripts', array( 'FrmPointers', 'get_instance' ) );
212 }
213 }
214
215 /**
216 * Returns the value of the ignore tour.
217 *
218 * @return bool
219 */
220 private static function has_ignored_tour() {
221 $user_meta = get_user_meta( get_current_user_id(), 'frm_ignore_tour' );
222
223 return ! empty( $user_meta );
224 }
225
226 /**
227 * Listener for the ignore tour GET value. If this one is set, just set the user meta to true.
228 */
229 private static function ignore_tour() {
230 if ( filter_input( INPUT_GET, 'frm_ignore_tour' ) && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), 'frm-ignore-tour' ) ) {
231 update_user_meta( get_current_user_id(), 'frm_ignore_tour', true );
232 }
233 }
234
235 public static function admin_js() {
236 $version = FrmAppHelper::plugin_version();
237 FrmAppHelper::load_admin_wide_js( false );
238
239 wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
240 'formidable_admin_global',
241 'formidable',
242 'jquery',
243 'jquery-ui-core',
244 'jquery-ui-draggable',
245 'jquery-ui-sortable',
246 'bootstrap_tooltip',
247 'bootstrap-multiselect',
248 ), $version, true );
249 wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
250 wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
251 wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
252
253 // load multselect js
254 wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
255
256 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
257 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
258
259 global $pagenow;
260 if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
261
262 wp_enqueue_script( 'admin-widgets' );
263 wp_enqueue_style( 'widgets' );
264 wp_enqueue_script( 'formidable' );
265 wp_enqueue_script( 'formidable_admin' );
266 FrmAppHelper::localize_script( 'admin' );
267
268 wp_enqueue_style( 'formidable-admin' );
269 wp_enqueue_style( 'formidable-grids' );
270 wp_enqueue_style( 'formidable-dropzone' );
271 add_thickbox();
272
273 wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() . '/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
274
275 } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
276 if ( isset( $_REQUEST['post_type'] ) ) {
277 $post_type = sanitize_title( $_REQUEST['post_type'] );
278 } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
279 $post = get_post( absint( $_REQUEST['post'] ) );
280 if ( ! $post ) {
281 return;
282 }
283 $post_type = $post->post_type;
284 } else {
285 return;
286 }
287
288 if ( $post_type == 'frm_display' ) {
289 wp_enqueue_script( 'jquery-ui-draggable' );
290 wp_enqueue_script( 'formidable_admin' );
291 wp_enqueue_style( 'formidable-admin' );
292 FrmAppHelper::localize_script( 'admin' );
293 }
294 } else if ( $pagenow == 'widgets.php' ) {
295 FrmAppHelper::load_admin_wide_js();
296 }
297 }
298
299 public static function load_lang() {
300 load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
301 }
302
303 /**
304 * Filter shortcodes in text widgets
305 */
306 public static function widget_text_filter( $content ) {
307 _deprecated_function( __METHOD__, '2.5.4' );
308 $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
309 return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
310 }
311
312 /**
313 * Deprecated in favor of wpmu_upgrade_site
314 */
315 public static function front_head() {
316 _deprecated_function( __FUNCTION__, '2.3' );
317 if ( is_multisite() && self::needs_update() ) {
318 self::install();
319 }
320 }
321
322 public static function localize_script( $location ) {
323 _deprecated_function( __FUNCTION__, '2.0.9', 'FrmAppHelper::localize_script' );
324 return FrmAppHelper::localize_script( $location );
325 }
326
327 public static function custom_stylesheet() {
328 _deprecated_function( __FUNCTION__, '2.0.9', 'FrmStylesController::custom_stylesheet' );
329 return FrmStylesController::custom_stylesheet();
330 }
331
332 public static function load_css() {
333 _deprecated_function( __FUNCTION__, '2.0.9', 'FrmStylesController::load_saved_css' );
334 return FrmStylesController::load_saved_css();
335 }
336
337 /**
338 * Run silent upgrade on each site in the network during a network upgrade.
339 * Update database settings for all sites in a network during network upgrade process.
340 *
341 * @since 2.0.1
342 *
343 * @param int $blog_id Blog ID.
344 */
345 public static function network_upgrade_site( $blog_id = 0 ) {
346 if ( $blog_id ) {
347 switch_to_blog( $blog_id );
348 $upgrade_url = admin_url( 'admin-ajax.php' );
349 restore_current_blog();
350 } else {
351 $upgrade_url = admin_url( 'admin-ajax.php' );
352 }
353
354 $upgrade_url = add_query_arg( array( 'action' => 'frm_silent_upgrade' ), $upgrade_url );
355 $r = wp_remote_get( esc_url_raw( $upgrade_url ) );
356 if ( is_wp_error( $r ) || ! is_array( $r ) || ! empty( $r['body'] ) ) {
357 // if the remove post fails, use javascript instead
358 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
359 }
360 }
361
362 /**
363 * Silent database upgrade (no redirect).
364 * Called via ajax request during network upgrade process.
365 *
366 * @since 2.0.1
367 */
368 public static function ajax_install() {
369 if ( self::needs_update() ) {
370 self::install();
371 }
372 wp_die();
373 }
374
375 public static function activation_install() {
376 FrmDb::delete_cache_and_transient( 'frm_plugin_version' );
377 FrmFormActionsController::actions_init();
378 self::install();
379 }
380
381 public static function install( $old_db_version = false ) {
382 $frmdb = new FrmMigrate();
383 $frmdb->upgrade( $old_db_version );
384 }
385
386 public static function uninstall() {
387 FrmAppHelper::permission_check('administrator');
388 check_ajax_referer( 'frm_ajax', 'nonce' );
389
390 $frmdb = new FrmMigrate();
391 $frmdb->uninstall();
392
393 //disable the plugin and redirect after uninstall so the tables don't get added right back
394 deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
395 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
396
397 wp_die();
398 }
399
400 public static function drop_tables( $tables ) {
401 global $wpdb;
402 $tables[] = $wpdb->prefix . 'frm_fields';
403 $tables[] = $wpdb->prefix . 'frm_forms';
404 $tables[] = $wpdb->prefix . 'frm_items';
405 $tables[] = $wpdb->prefix . 'frm_item_metas';
406 return $tables;
407 }
408
409 // Routes for wordpress pages -- we're just replacing content here folks.
410 public static function page_route( $content ) {
411 global $post;
412
413 $frm_settings = FrmAppHelper::get_settings();
414 if ( $post && $post->ID == $frm_settings->preview_page_id && isset( $_GET['form'] ) ) {
415 $content = FrmFormsController::page_preview();
416 }
417
418 return $content;
419 }
420
421 public static function deauthorize() {
422 FrmAppHelper::permission_check('frm_change_settings');
423 check_ajax_referer( 'frm_ajax', 'nonce' );
424
425 delete_option( 'frmpro-credentials' );
426 delete_option( 'frmpro-authorized' );
427 delete_site_option( 'frmpro-credentials' );
428 delete_site_option( 'frmpro-authorized' );
429 wp_die();
430 }
431
432 public static function get_form_shortcode( $atts ) {
433 _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
434 return FrmFormsController::get_form_shortcode( $atts );
435 }
436 }
437