| @@ -1,1110 +1,482 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 2 | +/** | |
| 3 | + * @package Formidable | |
| 4 | + */ | |
| 5 | +if(!defined('ABSPATH')) die('You are not allowed to call this page directly.'); | |
| 5 | 6 | |
| 6 | -class FrmAppController { | |
| 7 | +if(class_exists('FrmAppController')) | |
| 8 | + return; | |
| 7 | 9 | |
| 8 | - /** | |
| 9 | - * @return void | |
| 10 | - */ | |
| 11 | - public static function menu() { | |
| 12 | - FrmAppHelper::maybe_add_permissions(); | |
| 13 | - if ( ! current_user_can( 'frm_view_forms' ) ) { | |
| 14 | - return; | |
| 15 | - } | |
| 10 | +class FrmAppController{ | |
| 11 | + public static function load_hooks(){ | |
| 12 | + add_action('admin_menu', 'FrmAppController::menu', 1); | |
| 13 | + add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); | |
| 14 | + add_filter('plugin_action_links_formidable/formidable.php', 'FrmAppController::settings_link', 10, 2 ); | |
| 15 | + add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 ); | |
| 16 | + add_action('admin_notices', 'FrmAppController::pro_get_started_headline'); | |
| 17 | + add_filter('the_content', 'FrmAppController::page_route', 10); | |
| 18 | + add_action('plugins_loaded', 'FrmAppController::load_lang'); | |
| 19 | + add_action('init', 'FrmAppController::front_head'); | |
| 20 | + add_action('wp_footer', 'FrmAppController::footer_js', 1, 0); | |
| 21 | + add_action('admin_init', 'FrmAppController::admin_js', 11); | |
| 22 | + register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::install'); | |
| 23 | + add_action('wp_ajax_frm_install', 'FrmAppController::install'); | |
| 24 | + add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall'); | |
| 25 | + add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize'); | |
| 16 | 26 | |
| 17 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 18 | - add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); | |
| 19 | - } | |
| 27 | + // Used to process standalone requests | |
| 28 | + add_action('init', 'FrmAppController::parse_standalone_request', 40); | |
| 29 | + // Update the session data | |
| 30 | + add_action('init', 'FrmAppController::referer_session', 1); | |
| 31 | + } | |
| 32 | + | |
| 33 | + public static function menu(){ | |
| 34 | + global $frm_vars, $frm_settings; | |
| 35 | + | |
| 36 | + if ( current_user_can('administrator') && !current_user_can('frm_view_forms') ) { | |
| 37 | + global $current_user; | |
| 38 | + $frm_roles = FrmAppHelper::frm_capabilities(); | |
| 39 | + foreach($frm_roles as $frm_role => $frm_role_description) | |
| 40 | + $current_user->add_cap( $frm_role ); | |
| 41 | + unset($frm_roles); | |
| 42 | + unset($frm_role); | |
| 43 | + unset($frm_role_description); | |
| 44 | + } | |
| 45 | + | |
| 46 | + $count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) )); | |
| 47 | + $pos = ((int)$count > 0) ? '22.7' : '29.3'; | |
| 48 | + $pos = apply_filters('frm_menu_position', $pos); | |
| 49 | + | |
| 50 | + if(current_user_can('frm_view_forms')){ | |
| 51 | + add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos); | |
| 52 | + }else if(current_user_can('frm_view_entries') and $frm_vars['pro_is_installed']){ | |
| 53 | + add_menu_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', 'FrmProEntriesController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos); | |
| 54 | + } | |
| 55 | + | |
| 56 | + add_filter('admin_body_class', 'FrmAppController::wp_admin_body_class'); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public static function load_wp_admin_style(){ | |
| 60 | + wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version()); | |
| 61 | + } | |
| 62 | + | |
| 63 | + public static function get_form_nav($id, $show_nav=false){ | |
| 64 | + global $pagenow, $frm_vars; | |
| 65 | + | |
| 66 | + $show_nav = FrmAppHelper::get_param('show_nav', $show_nav); | |
| 67 | + if(!$show_nav) | |
| 68 | + return; | |
| 69 | + | |
| 70 | + $current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None'); | |
| 71 | + if($id and is_numeric($id)){ | |
| 72 | + $frm_form = new FrmForm(); | |
| 73 | + $form = $frm_form->getOne($id); | |
| 74 | + unset($frm_form); | |
| 75 | + }else{ | |
| 76 | + $form = false; | |
| 77 | + } | |
| 78 | + | |
| 79 | + include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php'); | |
| 80 | + } | |
| 20 | 81 | |
| 21 | - /** | |
| 22 | - * @return int | |
| 23 | - */ | |
| 24 | - private static function get_menu_position() { | |
| 25 | - return (int) apply_filters( 'frm_menu_position', 29 ); | |
| 26 | - } | |
| 82 | + // Adds a settings link to the plugins page | |
| 83 | + public static function settings_link($links, $file){ | |
| 84 | + $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>'; | |
| 85 | + array_unshift($links, $settings); | |
| 86 | + | |
| 87 | + return $links; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public static function update_action_links( $actions, $plugin ) { | |
| 91 | + | |
| 92 | + if ( 'formidable/formidable.php' != $plugin ) | |
| 93 | + return $actions; | |
| 94 | + | |
| 95 | + global $frm_vars; | |
| 96 | + | |
| 97 | + $db_version = get_option('frm_db_version'); | |
| 98 | + $pro_db_version = $frm_vars['pro_is_installed'] ? get_option('frmpro_db_version') : false; | |
| 99 | + | |
| 100 | + if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) || | |
| 101 | + ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) { | |
| 102 | + | |
| 103 | + return sprintf( '<a href="%s">%s</a>', add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )), __( 'Click here to complete the upgrade', 'formidable' ) ); | |
| 104 | + | |
| 105 | + } else { | |
| 106 | + return $actions; | |
| 107 | + } | |
| 108 | + } | |
| 27 | 109 | |
| 28 | - /** | |
| 29 | - * @since 3.05 | |
| 30 | - */ | |
| 31 | - private static function menu_icon() { | |
| 32 | - $icon = FrmAppHelper::svg_logo( | |
| 33 | - array( | |
| 34 | - 'fill' => '#a0a5aa', | |
| 35 | - 'orange' => '#a0a5aa', | |
| 36 | - ) | |
| 37 | - ); | |
| 38 | - $icon = 'data:image/svg+xml;base64,' . base64_encode( $icon ); | |
| 110 | + public static function pro_get_started_headline(){ | |
| 111 | + if ( isset($_GET['page']) && 'formidable' == $_GET['page'] && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) { | |
| 112 | + self::install(); | |
| 113 | + ?> | |
| 114 | +<div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div> | |
| 115 | +<?php | |
| 116 | + return; | |
| 117 | + } | |
| 118 | + | |
| 119 | + // Don't display this error as we're upgrading the thing... cmon | |
| 120 | + if(isset($_GET['action']) and $_GET['action'] == 'upgrade-plugin') | |
| 121 | + return; | |
| 122 | + | |
| 123 | + if ( is_multisite() && !current_user_can('administrator') ) { | |
| 124 | + return; | |
| 125 | + } | |
| 126 | + | |
| 127 | + if(!isset($_GET['activate'])){ | |
| 128 | + global $frm_vars; | |
| 129 | + $db_version = get_option('frm_db_version'); | |
| 130 | + $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false; | |
| 131 | + if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) || | |
| 132 | + ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) { | |
| 133 | + ?> | |
| 134 | +<div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or', 'formidable'); ?> <a id="frm_install_link" href="javascript:void(0)"><?php _e('Update Now', 'formidable') ?></a></div> | |
| 135 | +<script type="text/javascript"> | |
| 136 | +jQuery(document).ready(function($){ $('#frm_install_link').click(frm_install_now); }); | |
| 137 | +function frm_install_now(){ | |
| 138 | + jQuery('#frm_install_message').html('<div style="line-height:24px;"><?php _e("Please wait while your site updates.", "formidable") ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>'); | |
| 139 | + jQuery.ajax({ | |
| 140 | + type:"POST",url:ajaxurl,data:"action=frm_install", | |
| 141 | + success:function(msg){jQuery("#frm_install_message").fadeOut("slow");} | |
| 142 | + }); | |
| 143 | +} | |
| 144 | +</script> | |
| 145 | +<?php | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + if ( self::pro_is_authorized() && !self::pro_is_installed()) { | |
| 150 | + // user is authorized, but running free version | |
| 151 | + $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/'; | |
| 152 | + ?> | |
| 153 | + <div class="error" style="padding:7px;"><?php echo apply_filters('frm_pro_update_msg', sprintf(__('This site has been previously authorized to run Formidable Pro.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable'), '<a href="'. $inst_install_url .'" target="_blank">', '</a>', '<a href="javascript:void(0)" onclick="frm_deauthorize_now()" class="frm_deauthorize_link">', '</a>'), $inst_install_url); ?></div> | |
| 154 | +<script type="text/javascript"> | |
| 155 | +function frm_deauthorize_now(){ | |
| 156 | +if(!confirm("<?php esc_attr_e('Are you sure you want to deauthorize Formidable Pro on this site?', 'formidable') ?>")) | |
| 157 | + return false; | |
| 158 | +jQuery('.frm_deauthorize_link').html('<span class="spinner" style="display:inline-block;margin-top:0;float:none;"></span>'); | |
| 159 | +jQuery.ajax({type:'POST',url:ajaxurl,data:'action=frm_deauthorize&nonce='+wp_create_nonce('frm_ajax'), | |
| 160 | +success:function(msg){jQuery('.error').fadeOut('slow');} | |
| 161 | +}); | |
| 162 | +return false; | |
| 163 | +} | |
| 164 | +</script> | |
| 165 | + <?php | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + public static function admin_js(){ | |
| 170 | + global $pagenow; | |
| 171 | + | |
| 172 | + if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) { | |
| 173 | + return; | |
| 174 | + } | |
| 175 | + | |
| 176 | + wp_enqueue_script('jquery'); | |
| 177 | + wp_enqueue_script('jquery-ui-core'); | |
| 178 | + wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.0.3'); | |
| 179 | + | |
| 180 | + if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) || | |
| 181 | + ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display')) | |
| 182 | + ) { | |
| 183 | + $version = FrmAppHelper::plugin_version(); | |
| 184 | + add_filter('admin_body_class', 'FrmAppController::admin_body_class'); | |
| 185 | + | |
| 186 | + wp_enqueue_script('jquery-ui-sortable'); | |
| 187 | + wp_enqueue_script('jquery-ui-draggable'); | |
| 188 | + wp_enqueue_script('admin-widgets'); | |
| 189 | + wp_enqueue_style('widgets'); | |
| 190 | + wp_enqueue_script('formidable'); | |
| 191 | + wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true); | |
| 192 | + self::localize_script('admin'); | |
| 193 | + | |
| 194 | + wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version); | |
| 195 | + add_thickbox(); | |
| 196 | + | |
| 197 | + wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0'); | |
| 198 | + wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version); | |
| 199 | + | |
| 200 | + | |
| 201 | + }else if($pagenow == 'post.php' or ($pagenow == 'post-new.php' and isset($_REQUEST['post_type']) and $_REQUEST['post_type'] == 'frm_display')){ | |
| 202 | + if(isset($_REQUEST['post_type'])){ | |
| 203 | + $post_type = $_REQUEST['post_type']; | |
| 204 | + }else if(isset($_REQUEST['post']) and !empty($_REQUEST['post'])){ | |
| 205 | + $post = get_post($_REQUEST['post']); | |
| 206 | + if(!$post) | |
| 207 | + return; | |
| 208 | + $post_type = $post->post_type; | |
| 209 | + }else{ | |
| 210 | + return; | |
| 211 | + } | |
| 212 | + | |
| 213 | + if($post_type == 'frm_display'){ | |
| 214 | + $version = FrmAppHelper::plugin_version(); | |
| 215 | + wp_enqueue_script('jquery-ui-draggable'); | |
| 216 | + wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version); | |
| 217 | + wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css', array(), $version); | |
| 218 | + self::localize_script('admin'); | |
| 219 | + } | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + public static function admin_body_class($classes){ | |
| 224 | + global $wp_version; | |
| 225 | + | |
| 226 | + //we only need this class on Formidable pages | |
| 227 | + if(version_compare( $wp_version, '3.4.9', '>')) | |
| 228 | + $classes .= ' frm_35_trigger'; | |
| 229 | + | |
| 230 | + return $classes; | |
| 231 | + } | |
| 232 | + | |
| 233 | + public static function wp_admin_body_class($classes){ | |
| 234 | + global $wp_version; | |
| 235 | + //we need this class everywhere in the admin for the menu | |
| 236 | + if(version_compare( $wp_version, '3.7.2', '>')) | |
| 237 | + $classes .= ' frm_38_trigger'; | |
| 238 | + | |
| 239 | + return $classes; | |
| 240 | + } | |
| 241 | + | |
| 242 | + public static function load_lang(){ | |
| 243 | + load_plugin_textdomain('formidable', false, 'formidable/languages/' ); | |
| 244 | + } | |
| 245 | + | |
| 246 | + public static function front_head(){ | |
| 247 | + global $frm_settings; | |
| 39 | 248 | |
| 40 | - return apply_filters( 'frm_icon', $icon ); | |
| 41 | - } | |
| 249 | + if (is_multisite()){ | |
| 250 | + global $frm_vars; | |
| 251 | + $old_db_version = get_option('frm_db_version'); | |
| 252 | + $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false; | |
| 253 | + if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) || | |
| 254 | + ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) { | |
| 255 | + self::install($old_db_version); | |
| 256 | + } | |
| 257 | + } | |
| 258 | + | |
| 259 | + $version = FrmAppHelper::plugin_version(); | |
| 260 | + wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true); | |
| 261 | + wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true); | |
| 262 | + wp_register_script('recaptcha-ajax', 'http'. (is_ssl() ? 's' : '').'://www.google.com/recaptcha/api/js/recaptcha_ajax.js', '', true); | |
| 263 | + | |
| 264 | + if ( is_admin() && !defined('DOING_AJAX') ) { | |
| 265 | + // don't load this in back-end | |
| 266 | + return; | |
| 267 | + } | |
| 268 | + | |
| 269 | + self::localize_script('front'); | |
| 270 | + | |
| 271 | + wp_enqueue_script('jquery'); | |
| 272 | + | |
| 273 | + $style = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css')); | |
| 274 | + if($style){ | |
| 275 | + foreach((array)$style as $k => $file){ | |
| 276 | + wp_register_style($k, $file, array(), $version); | |
| 277 | + if ( 'all' == $frm_settings->load_style ) { | |
| 278 | + wp_enqueue_style($k); | |
| 279 | + } | |
| 280 | + unset($k, $file); | |
| 281 | + } | |
| 282 | + } | |
| 283 | + unset($style); | |
| 284 | + | |
| 285 | + if ( $frm_settings->load_style == 'all' ) { | |
| 286 | + global $frm_vars; | |
| 287 | + $frm_vars['css_loaded'] = true; | |
| 288 | + } | |
| 289 | + } | |
| 290 | + | |
| 291 | + public static function localize_script($location){ | |
| 292 | + wp_localize_script('formidable', 'frm_js', array( | |
| 293 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 294 | + 'images_url' => FrmAppHelper::plugin_url() .'/images', | |
| 295 | + 'loading' => __('Loading…'), | |
| 296 | + 'remove' => __('Remove', 'formidable'), | |
| 297 | + 'offset' => apply_filters('frm_scroll_offset', 4), | |
| 298 | + )); | |
| 299 | + | |
| 300 | + if($location == 'admin'){ | |
| 301 | + global $frm_settings; | |
| 302 | + wp_localize_script('formidable_admin', 'frm_admin_js', array( | |
| 303 | + 'confirm_uninstall' => __('Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable'), | |
| 304 | + 'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '', | |
| 305 | + 'desc' => __('(Click here to add a description or instructions)', 'formidable'), | |
| 306 | + 'blank' => __('(Blank)', 'formidable'), | |
| 307 | + 'saving' => esc_attr(__('Saving', 'formidable')), | |
| 308 | + 'saved' => esc_attr(__('Saved', 'formidable')), | |
| 309 | + 'ok' => __('OK'), | |
| 310 | + 'cancel' => __('Cancel', 'formidable'), | |
| 311 | + 'clear_default' => __('Clear default value when typing', 'formidable'), | |
| 312 | + 'no_clear_default' => __('Do not clear default value when typing', 'formidable'), | |
| 313 | + 'valid_default' => __('Default value will pass form validation', 'formidable'), | |
| 314 | + 'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'), | |
| 315 | + 'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'), | |
| 316 | + 'confirm' => __('Are you sure?', 'formidable'), | |
| 317 | + 'default_unique' => $frm_settings->unique_msg, | |
| 318 | + 'import_complete' => __('Import Complete', 'formidable'), | |
| 319 | + 'updating' => __('Please wait while your site updates.', 'formidable'), | |
| 320 | + 'nonce' => wp_create_nonce('frm_ajax'), | |
| 321 | + )); | |
| 322 | + } | |
| 323 | + } | |
| 324 | + | |
| 325 | + public static function footer_js($location='footer'){ | |
| 326 | + global $frm_settings, $frm_vars; | |
| 42 | 327 | |
| 43 | - /** | |
| 44 | - * @since 3.0 | |
| 45 | - */ | |
| 46 | - public static function add_admin_class( $classes ) { | |
| 47 | - if ( self::is_white_page() ) { | |
| 48 | - $classes .= ' frm-white-body '; | |
| 49 | - $classes .= self::get_os(); | |
| 328 | + if($frm_vars['load_css'] and (!is_admin() or defined('DOING_AJAX')) and ($frm_settings->load_style != 'none')){ | |
| 329 | + if(isset($frm_vars['css_loaded']) && $frm_vars['css_loaded']) | |
| 330 | + $css = apply_filters('get_frm_stylesheet', array()); | |
| 331 | + else | |
| 332 | + $css = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css')); | |
| 333 | + | |
| 334 | + if(!empty($css)){ | |
| 335 | + echo "\n".'<script type="text/javascript">'; | |
| 336 | + foreach((array)$css as $css_key => $file){ | |
| 337 | + echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\''. ($css_key + (isset($frm_vars['css_loaded']) ? $frm_vars['css_loaded'] : false)) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));'; | |
| 338 | + //wp_enqueue_style($css_key); | |
| 339 | + unset($css_key); | |
| 340 | + unset($file); | |
| 341 | + } | |
| 342 | + unset($css); | |
| 50 | 343 | |
| 51 | - $page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ); | |
| 52 | - if ( empty( $page ) || $page === 'formidable' ) { | |
| 53 | - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 54 | - if ( in_array( $action, array( 'settings', 'edit', 'list' ) ) ) { | |
| 55 | - $page .= $action; | |
| 56 | - } else { | |
| 57 | - $page = $action; | |
| 58 | - } | |
| 59 | - } | |
| 60 | - if ( ! empty( $page ) ) { | |
| 61 | - $classes .= ' frm-admin-page-' . $page; | |
| 62 | - } | |
| 63 | - } | |
| 344 | + echo '</script>'."\n"; | |
| 345 | + } | |
| 346 | + } | |
| 64 | 347 | |
| 65 | - if ( FrmAppHelper::is_full_screen() ) { | |
| 66 | - $full_screen_on = self::get_full_screen_setting(); | |
| 67 | - $add_class = ''; | |
| 68 | - if ( $full_screen_on ) { | |
| 69 | - $add_class = ' frm-full-screen is-fullscreen-mode'; | |
| 70 | - wp_enqueue_style( 'wp-edit-post' ); // Load the CSS for .is-fullscreen-mode. | |
| 71 | - } | |
| 72 | - $classes .= apply_filters( 'frm_admin_full_screen_class', $add_class ); | |
| 73 | - } | |
| 348 | + if((!is_admin() or defined('DOING_AJAX')) and $location != 'header' and !empty($frm_vars['forms_loaded'])) //load formidable js | |
| 349 | + FrmAppHelper::load_scripts(array('formidable')); | |
| 350 | + } | |
| 351 | + | |
| 352 | + public static function install($old_db_version=false){ | |
| 353 | + global $frmdb; | |
| 354 | + $frmdb->upgrade($old_db_version); | |
| 355 | + } | |
| 356 | + | |
| 357 | + public static function uninstall(){ | |
| 358 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 359 | + | |
| 360 | + if ( current_user_can('administrator') ) { | |
| 361 | + global $frmdb; | |
| 362 | + $frmdb->uninstall(); | |
| 363 | + echo true; | |
| 364 | + } else { | |
| 365 | + global $frm_settings; | |
| 366 | + wp_die($frm_settings->admin_permission); | |
| 367 | + } | |
| 368 | + die(); | |
| 369 | + } | |
| 370 | + | |
| 371 | + // Routes for wordpress pages -- we're just replacing content here folks. | |
| 372 | + public static function page_route($content){ | |
| 373 | + global $post, $frm_settings; | |
| 74 | 374 | |
| 75 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 76 | - $classes .= ' frm-lite '; | |
| 77 | - } | |
| 375 | + if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){ | |
| 376 | + $content = FrmFormsController::page_preview(); | |
| 377 | + } | |
| 78 | 378 | |
| 79 | - return $classes; | |
| 80 | - } | |
| 379 | + return $content; | |
| 380 | + } | |
| 381 | + | |
| 382 | + public static function referer_session() { | |
| 383 | + global $frm_settings; | |
| 384 | + | |
| 385 | + if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) { | |
| 386 | + return; | |
| 387 | + } | |
| 388 | + | |
| 389 | + // keep the page history below 100 | |
| 390 | + $max = 100; | |
| 391 | + | |
| 392 | + if ( !isset($_SESSION) ) | |
| 393 | + session_start(); | |
| 394 | + | |
| 395 | + if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) ) | |
| 396 | + $_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']); | |
| 397 | + | |
| 398 | + if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) ) | |
| 399 | + $_SESSION['frm_http_referer'] = array(); | |
| 400 | + | |
| 401 | + if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) { | |
| 402 | + if (! isset($_SERVER['HTTP_REFERER'])){ | |
| 403 | + $direct = __('Type-in or bookmark', 'formidable'); | |
| 404 | + if(!in_array($direct, $_SESSION['frm_http_referer'])) | |
| 405 | + $_SESSION['frm_http_referer'][] = $direct; | |
| 406 | + }else{ | |
| 407 | + $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER']; | |
| 408 | + } | |
| 409 | + } | |
| 410 | + | |
| 411 | + if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'])) | |
| 412 | + $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']; | |
| 413 | + | |
| 414 | + //keep the page history below the max | |
| 415 | + if(count($_SESSION['frm_http_pages']) > $max){ | |
| 416 | + foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){ | |
| 417 | + if(count($_SESSION['frm_http_pages']) <= $max) | |
| 418 | + break; | |
| 419 | + | |
| 420 | + unset($_SESSION['frm_http_pages'][$pkey]); | |
| 421 | + } | |
| 422 | + } | |
| 423 | + } | |
| 81 | 424 | |
| 82 | - /** | |
| 83 | - * Get the full screen mode setting from the block editor. | |
| 84 | - * | |
| 85 | - * @since 6.1 | |
| 86 | - * | |
| 87 | - * @return bool | |
| 88 | - */ | |
| 89 | - private static function get_full_screen_setting() { | |
| 90 | - global $wpdb; | |
| 91 | - $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; | |
| 425 | + public static function parse_standalone_request(){ | |
| 426 | + $plugin = FrmAppHelper::get_param('plugin'); | |
| 427 | + $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; | |
| 428 | + $action = FrmAppHelper::get_param($action); | |
| 429 | + $controller = FrmAppHelper::get_param('controller'); | |
| 430 | + | |
| 431 | + if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){ | |
| 432 | + _deprecated_function( __FUNCTION__, '1.07.02', 'wp_ajax_nopriv()' ); | |
| 433 | + | |
| 434 | + if($controller == 'forms') | |
| 435 | + FrmFormsController::preview(FrmAppHelper::get_param('form')); | |
| 436 | + else | |
| 437 | + do_action('frm_standalone_route', $controller, $action); | |
| 92 | 438 | |
| 93 | - $prefs = get_user_meta( get_current_user_id(), $meta_key, true ); | |
| 94 | - if ( $prefs && isset( $prefs['core/edit-post']['fullscreenMode'] ) ) { | |
| 95 | - return $prefs['core/edit-post']['fullscreenMode']; | |
| 96 | - } | |
| 439 | + do_action('frm_ajax_'. $controller .'_'. $action); | |
| 440 | + die(); | |
| 441 | + } | |
| 442 | + } | |
| 443 | + | |
| 444 | + //formidable shortcode | |
| 445 | + public static function get_form_shortcode($atts){ | |
| 446 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' ); | |
| 447 | + return FrmFormsController::get_form_shortcode($atts); | |
| 448 | + } | |
| 97 | 449 | |
| 98 | - return true; | |
| 99 | - } | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * @since 4.0 | |
| 103 | - * | |
| 104 | - * @return string | |
| 105 | - */ | |
| 106 | - private static function get_os() { | |
| 107 | - $agent = strtolower( FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ) ); | |
| 108 | - $os = ''; | |
| 109 | - if ( strpos( $agent, 'mac' ) !== false ) { | |
| 110 | - $os = ' osx'; | |
| 111 | - } elseif ( strpos( $agent, 'linux' ) !== false ) { | |
| 112 | - $os = ' linux'; | |
| 113 | - } elseif ( strpos( $agent, 'windows' ) !== false ) { | |
| 114 | - $os = ' windows'; | |
| 115 | - } | |
| 116 | - return $os; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * @since 3.0 | |
| 121 | - */ | |
| 122 | - private static function is_white_page() { | |
| 123 | - $white_pages = array( | |
| 124 | - 'formidable', | |
| 125 | - 'formidable-entries', | |
| 126 | - 'formidable-views', | |
| 127 | - 'formidable-views-editor', | |
| 128 | - 'formidable-pro-upgrade', | |
| 129 | - 'formidable-addons', | |
| 130 | - 'formidable-import', | |
| 131 | - 'formidable-settings', | |
| 132 | - 'formidable-styles', | |
| 133 | - 'formidable-styles2', | |
| 134 | - 'formidable-inbox', | |
| 135 | - 'formidable-welcome', | |
| 136 | - 'formidable-applications', | |
| 137 | - ); | |
| 138 | - | |
| 139 | - $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 140 | - $is_white_page = in_array( $get_page, $white_pages, true ); | |
| 141 | - | |
| 142 | - if ( ! $is_white_page ) { | |
| 143 | - $screen = get_current_screen(); | |
| 144 | - $is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * Allow another add on to style a page as a Formidable "white page", which adds a white background color. | |
| 149 | - * | |
| 150 | - * @since 5.3 | |
| 151 | - * | |
| 152 | - * @param bool $is_white_page | |
| 153 | - */ | |
| 154 | - $is_white_page = apply_filters( 'frm_is_white_page', $is_white_page ); | |
| 155 | - | |
| 156 | - return $is_white_page; | |
| 157 | - } | |
| 158 | - | |
| 159 | - /** | |
| 160 | - * @return void | |
| 161 | - */ | |
| 162 | - public static function load_wp_admin_style() { | |
| 163 | - FrmAppHelper::load_font_style(); | |
| 164 | - } | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * @param bool $show_nav | |
| 168 | - * @param string $title | |
| 169 | - * | |
| 170 | - * @psalm-param 'hide'|'show' $title | |
| 171 | - * | |
| 172 | - * @return void | |
| 173 | - */ | |
| 174 | - public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) { | |
| 175 | - $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' ); | |
| 176 | - if ( empty( $show_nav ) || ! $form ) { | |
| 177 | - return; | |
| 178 | - } | |
| 179 | - | |
| 180 | - FrmForm::maybe_get_form( $form ); | |
| 181 | - if ( ! is_object( $form ) ) { | |
| 182 | - return; | |
| 183 | - } | |
| 184 | - | |
| 185 | - $id = $form->id; | |
| 186 | - $current_page = self::get_current_page(); | |
| 187 | - $nav_items = self::get_form_nav_items( $form ); | |
| 188 | - | |
| 189 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' ); | |
| 190 | - } | |
| 191 | - | |
| 192 | - /** | |
| 193 | - * @return string | |
| 194 | - */ | |
| 195 | - private static function get_current_page() { | |
| 196 | - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 197 | - $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' ); | |
| 198 | - $current_page = isset( $_GET['page'] ) ? $page : $post_type; | |
| 199 | - | |
| 200 | - if ( FrmAppHelper::is_view_builder_page() ) { | |
| 201 | - $current_page = 'frm_display'; | |
| 202 | - } | |
| 203 | - | |
| 204 | - return $current_page; | |
| 205 | - } | |
| 206 | - | |
| 207 | - /** | |
| 208 | - * @param object $form | |
| 209 | - * @return array | |
| 210 | - */ | |
| 211 | - private static function get_form_nav_items( $form ) { | |
| 212 | - $id = $form->parent_form_id ? $form->parent_form_id : $form->id; | |
| 213 | - | |
| 214 | - $nav_items = array( | |
| 215 | - array( | |
| 216 | - 'link' => FrmForm::get_edit_link( $id ), | |
| 217 | - 'label' => __( 'Build', 'formidable' ), | |
| 218 | - 'current' => array( 'edit', 'new', 'duplicate' ), | |
| 219 | - 'page' => 'formidable', | |
| 220 | - 'permission' => 'frm_edit_forms', | |
| 221 | - ), | |
| 222 | - array( | |
| 223 | - 'link' => FrmStylesHelper::get_list_url( $id ), | |
| 224 | - 'label' => __( 'Style', 'formidable' ), | |
| 225 | - 'current' => array(), | |
| 226 | - 'page' => 'formidable-styles', | |
| 227 | - 'permission' => 'frm_edit_forms', | |
| 228 | - ), | |
| 229 | - array( | |
| 230 | - 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ), | |
| 231 | - 'label' => __( 'Settings', 'formidable' ), | |
| 232 | - 'current' => array( 'settings' ), | |
| 233 | - 'page' => 'formidable', | |
| 234 | - 'permission' => 'frm_edit_forms', | |
| 235 | - ), | |
| 236 | - array( | |
| 237 | - 'link' => admin_url( 'admin.php?page=formidable-entries&frm_action=list&form=' . absint( $id ) ), | |
| 238 | - 'label' => __( 'Entries', 'formidable' ), | |
| 239 | - 'current' => array(), | |
| 240 | - 'page' => 'formidable-entries', | |
| 241 | - 'permission' => 'frm_view_entries', | |
| 242 | - ), | |
| 243 | - ); | |
| 244 | - | |
| 245 | - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); | |
| 246 | - | |
| 247 | - if ( ! $views_installed ) { | |
| 248 | - $nav_items[] = array( | |
| 249 | - 'link' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $id ) ), | |
| 250 | - 'label' => __( 'Views', 'formidable' ), | |
| 251 | - 'current' => array(), | |
| 252 | - 'page' => 'formidable-views', | |
| 253 | - 'permission' => 'frm_view_entries', | |
| 254 | - 'atts' => array( | |
| 255 | - 'class' => 'frm_noallow', | |
| 256 | - ), | |
| 257 | - ); | |
| 258 | - } | |
| 259 | - | |
| 260 | - // Let people know reports and views exist. | |
| 261 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 262 | - $nav_items[] = array( | |
| 263 | - 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&form=' . absint( $id ) ), | |
| 264 | - 'label' => __( 'Reports', 'formidable' ), | |
| 265 | - 'current' => array( 'reports' ), | |
| 266 | - 'page' => 'formidable', | |
| 267 | - 'permission' => 'frm_view_entries', | |
| 268 | - 'atts' => array( | |
| 269 | - 'class' => 'frm_noallow', | |
| 270 | - ), | |
| 271 | - ); | |
| 272 | - } | |
| 273 | - | |
| 274 | - $nav_args = array( | |
| 275 | - 'form_id' => $id, | |
| 276 | - 'form' => $form, | |
| 277 | - ); | |
| 278 | - | |
| 279 | - return (array) apply_filters( 'frm_form_nav_list', $nav_items, $nav_args ); | |
| 280 | - } | |
| 281 | - | |
| 282 | - // Adds a settings link to the plugins page | |
| 283 | - /** | |
| 284 | - * @return array | |
| 285 | - */ | |
| 286 | - public static function settings_link( $links ) { | |
| 287 | - $settings = array(); | |
| 288 | - | |
| 289 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 290 | - $settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b>' . esc_html__( 'Upgrade to Pro', 'formidable' ) . '</b></a>'; | |
| 291 | - } | |
| 292 | - | |
| 293 | - $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>'; | |
| 294 | - | |
| 295 | - return array_merge( $settings, $links ); | |
| 296 | - } | |
| 297 | - | |
| 298 | - /** | |
| 299 | - * @return void | |
| 300 | - */ | |
| 301 | - public static function pro_get_started_headline() { | |
| 302 | - self::review_request(); | |
| 303 | - FrmAppHelper::min_pro_version_notice( '4.0' ); | |
| 304 | - } | |
| 305 | - | |
| 306 | - /** | |
| 307 | - * Add admin notices as needed for reviews | |
| 308 | - * | |
| 309 | - * @since 3.04.03 | |
| 310 | - * | |
| 311 | - * @return void | |
| 312 | - */ | |
| 313 | - private static function review_request() { | |
| 314 | - $reviews = new FrmReviews(); | |
| 315 | - $reviews->review_request(); | |
| 316 | - } | |
| 317 | - | |
| 318 | - /** | |
| 319 | - * Save the request to hide the review | |
| 320 | - * | |
| 321 | - * @since 3.04.03 | |
| 322 | - * | |
| 323 | - * @return void | |
| 324 | - */ | |
| 325 | - public static function dismiss_review() { | |
| 326 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 327 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 328 | - | |
| 329 | - $reviews = new FrmReviews(); | |
| 330 | - $reviews->dismiss_review(); | |
| 331 | - } | |
| 332 | - | |
| 333 | - /** | |
| 334 | - * @since 3.04.02 | |
| 335 | - * | |
| 336 | - * @return void | |
| 337 | - */ | |
| 338 | - public static function include_upgrade_overlay() { | |
| 339 | - self::enqueue_dialog_assets(); | |
| 340 | - add_action( 'admin_footer', 'FrmAppController::upgrade_overlay_html' ); | |
| 341 | - } | |
| 342 | - | |
| 343 | - /** | |
| 344 | - * Enqueue scripts and styles required for modals. | |
| 345 | - * | |
| 346 | - * @since 5.3 | |
| 347 | - * | |
| 348 | - * @return void | |
| 349 | - */ | |
| 350 | - public static function enqueue_dialog_assets() { | |
| 351 | - wp_enqueue_script( 'jquery-ui-dialog' ); | |
| 352 | - wp_enqueue_style( 'jquery-ui-dialog' ); | |
| 353 | - } | |
| 354 | - | |
| 355 | - /** | |
| 356 | - * @since 3.06.03 | |
| 357 | - * | |
| 358 | - * @return void | |
| 359 | - */ | |
| 360 | - public static function upgrade_overlay_html() { | |
| 361 | - $is_pro = FrmAppHelper::pro_is_installed(); | |
| 362 | - $upgrade_link = array( | |
| 363 | - 'medium' => 'builder', | |
| 364 | - 'content' => 'upgrade', | |
| 365 | - ); | |
| 366 | - $default_link = FrmAppHelper::admin_upgrade_link( $upgrade_link ); | |
| 367 | - $plugin_path = FrmAppHelper::plugin_path(); | |
| 368 | - $shared_path = $plugin_path . '/classes/views/shared/'; | |
| 369 | - | |
| 370 | - include $shared_path . 'upgrade_overlay.php'; | |
| 371 | - include $shared_path . 'confirm-overlay.php'; | |
| 372 | - | |
| 373 | - if ( FrmAppHelper::is_admin_page( 'formidable-welcome' ) || FrmAppHelper::on_form_listing_page() ) { | |
| 374 | - self::new_form_overlay_html(); | |
| 375 | - } | |
| 376 | - } | |
| 377 | - | |
| 378 | - /** | |
| 379 | - * @return void | |
| 380 | - */ | |
| 381 | - private static function new_form_overlay_html() { | |
| 382 | - FrmFormsController::before_list_templates(); | |
| 383 | - | |
| 384 | - $plugin_path = FrmAppHelper::plugin_path(); | |
| 385 | - $path = $plugin_path . '/classes/views/frm-forms/'; | |
| 386 | - $expired = FrmFormsController::expired(); | |
| 387 | - $expiring = FrmAddonsController::is_license_expiring(); | |
| 388 | - $user = wp_get_current_user(); // $user used in leave-email.php to determine a default value for field | |
| 389 | - $view_path = $path . 'new-form-overlay/'; | |
| 390 | - $modal_class = ''; | |
| 391 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( | |
| 392 | - array( | |
| 393 | - 'medium' => 'new-template', | |
| 394 | - 'content' => 'upgrade', | |
| 395 | - ) | |
| 396 | - ); | |
| 397 | - $renew_link = FrmAppHelper::admin_upgrade_link( | |
| 398 | - array( | |
| 399 | - 'medium' => 'new-template', | |
| 400 | - 'content' => 'renew', | |
| 401 | - ) | |
| 402 | - ); | |
| 403 | - $blocks_to_render = array(); | |
| 404 | - | |
| 405 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 406 | - // avoid rendering the email and code blocks for users who have upgraded or have a free license already | |
| 407 | - $api = new FrmFormTemplateApi(); | |
| 408 | - if ( ! $api->has_free_access() ) { | |
| 409 | - array_push( $blocks_to_render, 'email', 'code' ); | |
| 410 | - } | |
| 411 | - } | |
| 412 | - | |
| 413 | - // avoid rendering the upgrade block for users with elite | |
| 414 | - if ( 'elite' !== FrmAddonsController::license_type() ) { | |
| 415 | - $blocks_to_render[] = 'upgrade'; | |
| 416 | - } | |
| 417 | - | |
| 418 | - // avoid rendering the renew block for users who are not currently expired | |
| 419 | - if ( $expired ) { | |
| 420 | - $blocks_to_render[] = 'renew'; | |
| 421 | - $modal_class = 'frm-expired'; | |
| 422 | - } elseif ( $expiring ) { | |
| 423 | - $modal_class = 'frm-expiring'; | |
| 424 | - } | |
| 425 | - | |
| 426 | - include $path . 'new-form-overlay.php'; | |
| 427 | - } | |
| 428 | - | |
| 429 | - /** | |
| 430 | - * @return void | |
| 431 | - */ | |
| 432 | - public static function include_info_overlay() { | |
| 433 | - self::enqueue_dialog_assets(); | |
| 434 | - add_action( 'admin_footer', 'FrmAppController::info_overlay_html' ); | |
| 435 | - } | |
| 436 | - | |
| 437 | - /** | |
| 438 | - * @return void | |
| 439 | - */ | |
| 440 | - public static function info_overlay_html() { | |
| 441 | - include FrmAppHelper::plugin_path() . '/classes/views/shared/info-overlay.php'; | |
| 442 | - } | |
| 443 | - | |
| 444 | - /** | |
| 445 | - * @since 3.04.02 | |
| 446 | - * | |
| 447 | - * @return void | |
| 448 | - */ | |
| 449 | - public static function remove_upsells() { | |
| 450 | - remove_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); | |
| 451 | - remove_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' ); | |
| 452 | - remove_action( 'frm_add_form_style_tab_options', 'FrmFormsController::add_form_style_tab_options' ); | |
| 453 | - remove_action( 'frm_after_field_options', 'FrmFormsController::logic_tip' ); | |
| 454 | - } | |
| 455 | - | |
| 456 | - /** | |
| 457 | - * If there are CURL problems on this server, wp_remote_post won't work for installing | |
| 458 | - * Use a javascript fallback instead. | |
| 459 | - * | |
| 460 | - * @since 2.0.3 | |
| 461 | - * | |
| 462 | - * @return void | |
| 463 | - */ | |
| 464 | - public static function install_js_fallback() { | |
| 465 | - FrmAppHelper::load_admin_wide_js(); | |
| 466 | - ?> | |
| 467 | - <div id="frm_install_message"></div> | |
| 468 | - <script>jQuery(document).ready( frm_install_now );</script> | |
| 469 | - <?php | |
| 470 | - } | |
| 471 | - | |
| 472 | - /** | |
| 473 | - * Check if the database is outdated | |
| 474 | - * | |
| 475 | - * @since 2.0.1 | |
| 476 | - * @return boolean | |
| 477 | - */ | |
| 478 | - public static function needs_update() { | |
| 479 | - $needs_upgrade = self::compare_for_update( | |
| 480 | - array( | |
| 481 | - 'option' => 'frm_db_version', | |
| 482 | - 'new_db_version' => FrmAppHelper::$db_version, | |
| 483 | - 'new_plugin_version' => FrmAppHelper::plugin_version(), | |
| 484 | - ) | |
| 485 | - ); | |
| 486 | - | |
| 487 | - if ( ! $needs_upgrade ) { | |
| 488 | - $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade ); | |
| 489 | - } | |
| 490 | - | |
| 491 | - return $needs_upgrade; | |
| 492 | - } | |
| 493 | - | |
| 494 | - /** | |
| 495 | - * Check both version number and DB number for changes | |
| 496 | - * | |
| 497 | - * @since 3.0.04 | |
| 498 | - * | |
| 499 | - * @param array $atts | |
| 500 | - * @return bool | |
| 501 | - */ | |
| 502 | - public static function compare_for_update( $atts ) { | |
| 503 | - $db_version = get_option( $atts['option'] ); | |
| 504 | - | |
| 505 | - if ( strpos( $db_version, '-' ) === false ) { | |
| 506 | - $needs_upgrade = true; | |
| 507 | - } else { | |
| 508 | - $last_upgrade = explode( '-', $db_version ); | |
| 509 | - $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version']; | |
| 510 | - $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' ); | |
| 511 | - $needs_upgrade = $needs_db_upgrade || $new_version; | |
| 512 | - } | |
| 513 | - | |
| 514 | - return $needs_upgrade; | |
| 515 | - } | |
| 516 | - | |
| 517 | - /** | |
| 518 | - * Check for database update and trigger js loading | |
| 519 | - * | |
| 520 | - * @since 2.0.1 | |
| 521 | - * | |
| 522 | - * @return void | |
| 523 | - */ | |
| 524 | - public static function admin_init() { | |
| 525 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) && 'duplicate' === FrmAppHelper::get_param( 'frm_action' ) ) { | |
| 526 | - FrmFormsController::duplicate(); | |
| 527 | - } | |
| 528 | - | |
| 529 | - if ( FrmAppHelper::is_style_editor_page() && 'save' === FrmAppHelper::get_param( 'frm_action' ) ) { | |
| 530 | - // Hook in earlier than FrmStylesController::route so we can redirect before the headers have been sent. | |
| 531 | - FrmStylesController::save_style(); | |
| 532 | - } | |
| 533 | - | |
| 534 | - new FrmPersonalData(); // register personal data hooks | |
| 535 | - | |
| 536 | - if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) { | |
| 537 | - self::network_upgrade_site(); | |
| 538 | - } | |
| 539 | - | |
| 540 | - if ( ! FrmAppHelper::doing_ajax() ) { | |
| 541 | - // don't continue during ajax calls | |
| 542 | - self::admin_js(); | |
| 543 | - } | |
| 544 | - | |
| 545 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 546 | - $action = FrmAppHelper::get_param( 'frm_action' ); | |
| 547 | - | |
| 548 | - if ( in_array( $action, array( 'add_new', 'list_templates' ), true ) ) { | |
| 549 | - wp_safe_redirect( admin_url( 'admin.php?page=formidable&triggerNewFormModal=1' ) ); | |
| 550 | - exit; | |
| 551 | - } | |
| 552 | - | |
| 553 | - FrmInbox::maybe_disable_screen_options(); | |
| 554 | - } | |
| 555 | - | |
| 556 | - self::maybe_add_ip_warning(); | |
| 557 | - } | |
| 558 | - | |
| 559 | - /** | |
| 560 | - * Show a warning for the IP address setting if it hasn't been set. | |
| 561 | - * | |
| 562 | - * @since 6.1 | |
| 563 | - * | |
| 564 | - * @return void | |
| 565 | - */ | |
| 566 | - private static function maybe_add_ip_warning() { | |
| 567 | - $settings = FrmAppHelper::get_settings(); | |
| 568 | - if ( false !== $settings->custom_header_ip ) { | |
| 569 | - // The setting has been changed from the false default (to either 1 or 0), so stop showing the message. | |
| 570 | - return; | |
| 571 | - } | |
| 572 | - | |
| 573 | - if ( ! self::is_behind_proxy() ) { | |
| 574 | - // This message is only applicable when using a reverse proxy. | |
| 575 | - return; | |
| 576 | - } | |
| 577 | - | |
| 578 | - if ( FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_text_field' ) ) { | |
| 579 | - // Avoid the message on a POST action. We don't want to show the message if we're saving global settings. | |
| 580 | - return; | |
| 581 | - } | |
| 582 | - | |
| 583 | - $global_settings_link = admin_url( 'admin.php?page=formidable-settings' ) . '#frm_custom_header_ip'; | |
| 584 | - $message = sprintf( | |
| 585 | - // Translators: 1: Global Settings Link | |
| 586 | - __( 'IP addresses in form submissions may no longer be accurate! If you are experiencing issues, we recommend going to %1$s and enabling the "Use custom headers when retrieving IPs with form submissions." setting.', 'formidable' ), | |
| 587 | - '<a href="' . esc_url( $global_settings_link ) . '">Global Settings</a>' | |
| 588 | - ); | |
| 589 | - $option_name = 'frm_dismiss_ip_address_notice'; | |
| 590 | - FrmAppHelper::add_dismissable_warning_message( $message, $option_name ); | |
| 591 | - } | |
| 592 | - | |
| 593 | - /** | |
| 594 | - * Check if any reverse proxy headers are set. | |
| 595 | - * | |
| 596 | - * @since 6.1 | |
| 597 | - * | |
| 598 | - * @return bool | |
| 599 | - */ | |
| 600 | - private static function is_behind_proxy() { | |
| 601 | - $custom_headers = FrmAppHelper::get_custom_header_keys_for_ip(); | |
| 602 | - foreach ( $custom_headers as $header ) { | |
| 603 | - if ( 'REMOTE_ADDR' === $header ) { | |
| 604 | - // We want to check every key but REMOTE_ADDR. REMOTE_ATTR is not unique to reverse proxy servers. | |
| 605 | - continue; | |
| 606 | - } | |
| 607 | - | |
| 608 | - $ip = trim( FrmAppHelper::get_server_value( $header ) ); | |
| 609 | - // Return true for anything that isn't empty but ignoring values like ::1. | |
| 610 | - if ( $ip && 0 !== strpos( $ip, '::' ) ) { | |
| 611 | - return true; | |
| 612 | - } | |
| 613 | - } | |
| 614 | - | |
| 615 | - return false; | |
| 616 | - } | |
| 617 | - | |
| 618 | - /** | |
| 619 | - * @return void | |
| 620 | - */ | |
| 621 | - public static function admin_js() { | |
| 622 | - $plugin_url = FrmAppHelper::plugin_url(); | |
| 623 | - $version = FrmAppHelper::plugin_version(); | |
| 624 | - | |
| 625 | - FrmAppHelper::load_admin_wide_js(); | |
| 626 | - | |
| 627 | - wp_register_style( 'formidable_admin_global', $plugin_url . '/css/admin/frm_admin_global.css', array(), $version ); | |
| 628 | - wp_enqueue_style( 'formidable_admin_global' ); | |
| 629 | - | |
| 630 | - wp_register_style( 'formidable-admin', $plugin_url . '/css/frm_admin.css', array(), $version ); | |
| 631 | - wp_register_style( 'formidable-grids', $plugin_url . '/css/frm_grids.css', array(), $version ); | |
| 632 | - | |
| 633 | - wp_register_script( 'formidable_dom', $plugin_url . '/js/admin/dom.js', array( 'jquery', 'jquery-ui-dialog', 'wp-i18n' ), $version, true ); | |
| 634 | - wp_register_script( 'formidable_embed', $plugin_url . '/js/admin/embed.js', array( 'formidable_dom', 'jquery-ui-autocomplete' ), $version, true ); | |
| 635 | - self::register_popper1(); | |
| 636 | - wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true ); | |
| 637 | - wp_register_script( 'formidable_settings', $plugin_url . '/js/admin/settings.js', array(), $version, true ); | |
| 638 | - | |
| 639 | - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 640 | - | |
| 641 | - // Enqueue Floating Links. | |
| 642 | - $is_valid_page = | |
| 643 | - FrmAppHelper::is_formidable_admin() && | |
| 644 | - ! FrmAppHelper::is_style_editor_page() && | |
| 645 | - ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) && | |
| 646 | - ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 647 | - if ( $is_valid_page ) { | |
| 648 | - self::enqueue_floating_links( $plugin_url, $version ); | |
| 649 | - } | |
| 650 | - unset( $is_valid_page ); | |
| 651 | - | |
| 652 | - if ( 'formidable-applications' === $page ) { | |
| 653 | - FrmApplicationsController::load_assets(); | |
| 654 | - return; | |
| 655 | - } | |
| 656 | - | |
| 657 | - $dependencies = array( | |
| 658 | - 'formidable_admin_global', | |
| 659 | - 'jquery', | |
| 660 | - 'jquery-ui-core', | |
| 661 | - 'jquery-ui-draggable', | |
| 662 | - 'jquery-ui-sortable', | |
| 663 | - 'bootstrap_tooltip', | |
| 664 | - 'bootstrap-multiselect', | |
| 665 | - 'wp-i18n', | |
| 666 | - 'wp-hooks', // Required in WP versions older than 5.7 | |
| 667 | - 'formidable_dom', | |
| 668 | - 'formidable_embed', | |
| 669 | - ); | |
| 670 | - | |
| 671 | - if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) { | |
| 672 | - // We only need to load the color picker when editing styles. | |
| 673 | - $dependencies[] = 'wp-color-picker'; | |
| 674 | - } | |
| 675 | - | |
| 676 | - wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', $dependencies, $version, true ); | |
| 677 | - | |
| 678 | - if ( FrmAppHelper::on_form_listing_page() ) { | |
| 679 | - // For the existing page dropdown in the Form embed modal. | |
| 680 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); | |
| 681 | - } | |
| 682 | - | |
| 683 | - wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true ); | |
| 684 | - | |
| 685 | - $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); | |
| 686 | - | |
| 687 | - global $pagenow; | |
| 688 | - if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) { | |
| 689 | - | |
| 690 | - wp_enqueue_script( 'admin-widgets' ); | |
| 691 | - wp_enqueue_style( 'widgets' ); | |
| 692 | - self::maybe_deregister_popper2(); | |
| 693 | - wp_enqueue_script( 'formidable_admin' ); | |
| 694 | - wp_enqueue_script( 'formidable_embed' ); | |
| 695 | - FrmAppHelper::localize_script( 'admin' ); | |
| 696 | - | |
| 697 | - wp_enqueue_style( 'formidable-admin' ); | |
| 698 | - if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) { | |
| 699 | - wp_enqueue_style( 'formidable-grids' ); | |
| 700 | - wp_enqueue_style( 'formidable-dropzone' ); | |
| 701 | - } else { | |
| 702 | - wp_enqueue_style( 'formidable-grids' ); | |
| 703 | - } | |
| 704 | - | |
| 705 | - if ( 'formidable-entries' === $page ) { | |
| 706 | - // Load front end js for entries. | |
| 707 | - wp_enqueue_script( 'formidable' ); | |
| 708 | - } | |
| 709 | - | |
| 710 | - do_action( 'frm_enqueue_builder_scripts' ); | |
| 711 | - self::include_upgrade_overlay(); | |
| 712 | - self::include_info_overlay(); | |
| 713 | - } elseif ( FrmAppHelper::is_view_builder_page() ) { | |
| 714 | - if ( isset( $_REQUEST['post_type'] ) ) { | |
| 715 | - $post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) ); | |
| 716 | - } elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) { | |
| 717 | - $post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) ); | |
| 718 | - if ( ! $post ) { | |
| 719 | - return; | |
| 720 | - } | |
| 721 | - $post_type = $post->post_type; | |
| 722 | - } else { | |
| 723 | - return; | |
| 724 | - } | |
| 725 | - | |
| 726 | - if ( $post_type === 'frm_display' ) { | |
| 727 | - self::enqueue_legacy_views_assets(); | |
| 728 | - } | |
| 729 | - } | |
| 730 | - | |
| 731 | - } | |
| 732 | - | |
| 733 | - /** | |
| 734 | - * @since 6.3.2 | |
| 735 | - * | |
| 736 | - * @return void | |
| 737 | - */ | |
| 738 | - public static function admin_enqueue_scripts() { | |
| 739 | - self::load_wp_admin_style(); | |
| 740 | - self::maybe_force_formidable_block_on_gutenberg_page(); | |
| 741 | - } | |
| 742 | - | |
| 743 | - /** | |
| 744 | - * Enqueue required assets for the Legacy Views editor (Views v4.x). | |
| 745 | - * | |
| 746 | - * @since 6.1.2 | |
| 747 | - * | |
| 748 | - * @return void | |
| 749 | - */ | |
| 750 | - private static function enqueue_legacy_views_assets() { | |
| 751 | - wp_enqueue_style( 'formidable-grids' ); | |
| 752 | - wp_enqueue_script( 'jquery-ui-draggable' ); | |
| 753 | - self::maybe_deregister_popper2(); | |
| 754 | - wp_enqueue_script( 'formidable_admin' ); | |
| 755 | - wp_add_inline_style( | |
| 756 | - 'formidable-admin', | |
| 757 | - ' | |
| 758 | - .frm-white-body.post-type-frm_display .columns-2 { | |
| 759 | - display: block; | |
| 760 | - overflow: visible; | |
| 761 | - } | |
| 762 | - | |
| 763 | - .frm-white-body.post-type-frm_display .columns-2 > div { | |
| 764 | - overflow-y: hidden; | |
| 765 | - } | |
| 766 | - | |
| 767 | - .frm-white-body.post-type-frm_display #titlediv #title-prompt-text { | |
| 768 | - padding: 3px 0 0 10px; | |
| 769 | - } | |
| 770 | - | |
| 771 | - .post-type-frm_display #field-search-input, | |
| 772 | - .post-type-frm_display #advanced-search-input { | |
| 773 | - flex: 1; | |
| 774 | - } | |
| 775 | - ' | |
| 776 | - ); | |
| 777 | - wp_enqueue_style( 'formidable-admin' ); | |
| 778 | - FrmAppHelper::localize_script( 'admin' ); | |
| 779 | - self::include_info_overlay(); | |
| 780 | - } | |
| 781 | - | |
| 782 | - /** | |
| 783 | - * Fix a Duplicator Pro conflict because it uses Popper 2. See issue #3459. | |
| 784 | - * | |
| 785 | - * @since 5.2.02.01 | |
| 786 | - * | |
| 787 | - * @return void | |
| 788 | - */ | |
| 789 | - private static function maybe_deregister_popper2() { | |
| 790 | - global $wp_scripts; | |
| 791 | - | |
| 792 | - if ( ! array_key_exists( 'popper', $wp_scripts->registered ) ) { | |
| 793 | - return; | |
| 794 | - } | |
| 795 | - | |
| 796 | - $popper = $wp_scripts->registered['popper']; | |
| 797 | - if ( version_compare( $popper->ver, '2.0', '>=' ) ) { | |
| 798 | - wp_deregister_script( 'popper' ); | |
| 799 | - self::register_popper1(); | |
| 800 | - } | |
| 801 | - } | |
| 802 | - | |
| 803 | - /** | |
| 804 | - * Register Popper required for Bootstrap 4. | |
| 805 | - * | |
| 806 | - * @since 5.2.02.01 | |
| 807 | - * | |
| 808 | - * @return void | |
| 809 | - */ | |
| 810 | - private static function register_popper1() { | |
| 811 | - wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true ); | |
| 812 | - } | |
| 813 | - | |
| 814 | - /** | |
| 815 | - * Automatically insert a Formidable block when loading Gutenberg when $_GET['frmForm' is set. | |
| 816 | - * | |
| 817 | - * @since 5.2 | |
| 818 | - * | |
| 819 | - * @return void | |
| 820 | - */ | |
| 821 | - private static function maybe_force_formidable_block_on_gutenberg_page() { | |
| 822 | - global $pagenow; | |
| 823 | - if ( 'post.php' !== $pagenow ) { | |
| 824 | - return; | |
| 825 | - } | |
| 826 | - | |
| 827 | - $form_id = FrmAppHelper::simple_get( 'frmForm', 'absint' ); | |
| 828 | - if ( ! $form_id ) { | |
| 829 | - return; | |
| 830 | - } | |
| 831 | - | |
| 832 | - self::add_js_to_inject_gutenberg_block( 'formidable/simple-form', 'formId', $form_id ); | |
| 833 | - } | |
| 834 | - | |
| 835 | - /** | |
| 836 | - * @since 5.3 | |
| 837 | - * | |
| 838 | - * @param string $block_name | |
| 839 | - * @param string $object_key | |
| 840 | - * @param array|string $object_id | |
| 841 | - * | |
| 842 | - * @return void | |
| 843 | - */ | |
| 844 | - public static function add_js_to_inject_gutenberg_block( $block_name, $object_key, $object_id ) { | |
| 845 | - require FrmAppHelper::plugin_path() . '/classes/views/shared/edit-page-js.php'; | |
| 846 | - } | |
| 847 | - | |
| 848 | - /** | |
| 849 | - * @return void | |
| 850 | - */ | |
| 851 | - public static function load_lang() { | |
| 852 | - load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' ); | |
| 853 | - } | |
| 854 | - | |
| 855 | - /** | |
| 856 | - * Check if the styles are updated when a form is loaded on the front-end | |
| 857 | - * | |
| 858 | - * @since 3.0.1 | |
| 859 | - * | |
| 860 | - * @return void | |
| 861 | - */ | |
| 862 | - public static function maybe_update_styles() { | |
| 863 | - if ( self::needs_update() ) { | |
| 864 | - self::network_upgrade_site(); | |
| 865 | - } | |
| 866 | - } | |
| 867 | - | |
| 868 | - /** | |
| 869 | - * @since 3.0 | |
| 870 | - * | |
| 871 | - * @return void | |
| 872 | - */ | |
| 873 | - public static function create_rest_routes() { | |
| 874 | - $args = array( | |
| 875 | - 'methods' => 'GET', | |
| 876 | - 'callback' => 'FrmAppController::api_install', | |
| 877 | - 'permission_callback' => __CLASS__ . '::can_update_db', | |
| 878 | - ); | |
| 879 | - | |
| 880 | - register_rest_route( 'frm-admin/v1', '/install', $args ); | |
| 881 | - | |
| 882 | - $args = array( | |
| 883 | - 'methods' => 'GET', | |
| 884 | - 'callback' => 'FrmAddonsController::install_addon_api', | |
| 885 | - 'permission_callback' => 'FrmAddonsController::can_install_addon_api', | |
| 886 | - ); | |
| 887 | - | |
| 888 | - register_rest_route( 'frm-admin/v1', '/install-addon', $args ); | |
| 889 | - } | |
| 890 | - | |
| 891 | - /** | |
| 892 | - * Make sure the install is only being run when we tell it to. | |
| 893 | - * We don't want to run manually by people calling the API. | |
| 894 | - * | |
| 895 | - * @since 4.06.02 | |
| 896 | - */ | |
| 897 | - public static function can_update_db() { | |
| 898 | - return get_transient( 'frm_updating_api' ); | |
| 899 | - } | |
| 900 | - | |
| 901 | - /** | |
| 902 | - * Run silent upgrade on each site in the network during a network upgrade. | |
| 903 | - * Update database settings for all sites in a network during network upgrade process. | |
| 904 | - * | |
| 905 | - * @since 2.0.1 | |
| 906 | - * | |
| 907 | - * @param int $blog_id Blog ID. | |
| 908 | - * | |
| 909 | - * @return void | |
| 910 | - */ | |
| 911 | - public static function network_upgrade_site( $blog_id = 0 ) { | |
| 912 | - // Flag to check if install is happening as intended. | |
| 913 | - set_transient( 'frm_updating_api', true, MINUTE_IN_SECONDS ); | |
| 914 | - $request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' ); | |
| 915 | - | |
| 916 | - self::maybe_add_wp_site_health(); | |
| 917 | - | |
| 918 | - if ( $blog_id ) { | |
| 919 | - switch_to_blog( $blog_id ); | |
| 920 | - $response = rest_do_request( $request ); | |
| 921 | - restore_current_blog(); | |
| 922 | - } else { | |
| 923 | - $response = rest_do_request( $request ); | |
| 924 | - } | |
| 925 | - | |
| 926 | - if ( $response->is_error() ) { | |
| 927 | - // if the remove post fails, use javascript instead | |
| 928 | - add_action( 'admin_notices', 'FrmAppController::install_js_fallback' ); | |
| 929 | - } | |
| 930 | - } | |
| 931 | - | |
| 932 | - /** | |
| 933 | - * Make sure WP_Site_Health has been included because it is required when calling rest_do_request. | |
| 934 | - * Check first that the file exists because WP_Site_Health was only introduced in WordPress 5.2. | |
| 935 | - * | |
| 936 | - * @return void | |
| 937 | - */ | |
| 938 | - private static function maybe_add_wp_site_health() { | |
| 939 | - if ( ! class_exists( 'WP_Site_Health' ) ) { | |
| 940 | - $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; | |
| 941 | - if ( file_exists( $wp_site_health_path ) ) { | |
| 942 | - require_once $wp_site_health_path; | |
| 943 | - } | |
| 944 | - } | |
| 945 | - } | |
| 946 | - | |
| 947 | - /** | |
| 948 | - * @since 3.0 | |
| 949 | - * | |
| 950 | - * @return true | |
| 951 | - */ | |
| 952 | - public static function api_install() { | |
| 953 | - delete_transient( 'frm_updating_api' ); | |
| 954 | - if ( self::needs_update() ) { | |
| 955 | - $running = get_option( 'frm_install_running' ); | |
| 956 | - if ( false === $running || $running < strtotime( '-5 minutes' ) ) { | |
| 957 | - update_option( 'frm_install_running', time(), 'no' ); | |
| 958 | - self::install(); | |
| 959 | - delete_option( 'frm_install_running' ); | |
| 960 | - } | |
| 961 | - } | |
| 962 | - | |
| 963 | - return true; | |
| 964 | - } | |
| 965 | - | |
| 966 | - /** | |
| 967 | - * Silent database upgrade (no redirect). | |
| 968 | - * Called via ajax request during network upgrade process. | |
| 969 | - * | |
| 970 | - * @since 2.0.1 | |
| 971 | - * | |
| 972 | - * @return void | |
| 973 | - */ | |
| 974 | - public static function ajax_install() { | |
| 975 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 976 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 977 | - self::api_install(); | |
| 978 | - wp_die(); | |
| 979 | - } | |
| 980 | - | |
| 981 | - /** | |
| 982 | - * @return void | |
| 983 | - */ | |
| 984 | - public static function install() { | |
| 985 | - $frmdb = new FrmMigrate(); | |
| 986 | - $frmdb->upgrade(); | |
| 987 | - } | |
| 988 | - | |
| 989 | - /** | |
| 990 | - * @return void | |
| 991 | - */ | |
| 992 | - public static function uninstall() { | |
| 993 | - FrmAppHelper::permission_check( 'administrator' ); | |
| 994 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 995 | - | |
| 996 | - $frmdb = new FrmMigrate(); | |
| 997 | - $frmdb->uninstall(); | |
| 998 | - | |
| 999 | - //disable the plugin and redirect after uninstall so the tables don't get added right back | |
| 1000 | - $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' ); | |
| 1001 | - deactivate_plugins( $plugins, false, false ); | |
| 1002 | - echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) ); | |
| 1003 | - | |
| 1004 | - wp_die(); | |
| 1005 | - } | |
| 1006 | - | |
| 1007 | - public static function drop_tables( $tables ) { | |
| 1008 | - global $wpdb; | |
| 1009 | - $tables[] = $wpdb->prefix . 'frm_fields'; | |
| 1010 | - $tables[] = $wpdb->prefix . 'frm_forms'; | |
| 1011 | - $tables[] = $wpdb->prefix . 'frm_items'; | |
| 1012 | - $tables[] = $wpdb->prefix . 'frm_item_metas'; | |
| 1013 | - | |
| 1014 | - return $tables; | |
| 1015 | - } | |
| 1016 | - | |
| 1017 | - /** | |
| 1018 | - * @return void | |
| 1019 | - */ | |
| 1020 | - public static function deauthorize() { | |
| 1021 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 1022 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1023 | - | |
| 1024 | - delete_option( 'frmpro-credentials' ); | |
| 1025 | - delete_option( 'frmpro-authorized' ); | |
| 1026 | - delete_site_option( 'frmpro-credentials' ); | |
| 1027 | - delete_site_option( 'frmpro-authorized' ); | |
| 1028 | - wp_die(); | |
| 1029 | - } | |
| 1030 | - | |
| 1031 | - public static function set_footer_text( $text ) { | |
| 1032 | - if ( FrmAppHelper::is_formidable_admin() ) { | |
| 1033 | - $text = ''; | |
| 1034 | - } | |
| 1035 | - | |
| 1036 | - return $text; | |
| 1037 | - } | |
| 1038 | - | |
| 1039 | - /** | |
| 1040 | - * @deprecated 3.0.04 | |
| 1041 | - * | |
| 1042 | - * @codeCoverageIgnore | |
| 1043 | - * | |
| 1044 | - * @return void | |
| 1045 | - */ | |
| 1046 | - public static function activation_install() { | |
| 1047 | - FrmDeprecated::activation_install(); | |
| 1048 | - } | |
| 1049 | - | |
| 1050 | - /** | |
| 1051 | - * @deprecated 3.0 | |
| 1052 | - * @codeCoverageIgnore | |
| 1053 | - */ | |
| 1054 | - public static function page_route( $content ) { | |
| 1055 | - return FrmDeprecated::page_route( $content ); | |
| 1056 | - } | |
| 1057 | - | |
| 1058 | - /** | |
| 1059 | - * Include icons on page for Embed Form modal. | |
| 1060 | - * | |
| 1061 | - * @since 5.2 | |
| 1062 | - * | |
| 1063 | - * @return void | |
| 1064 | - */ | |
| 1065 | - public static function include_embed_form_icons() { | |
| 1066 | - _deprecated_function( __METHOD__, '5.3' ); | |
| 1067 | - } | |
| 1068 | - | |
| 1069 | - /** | |
| 1070 | - * @deprecated 1.07.05 This is still referenced in the API add on as of v1.13. | |
| 1071 | - * @codeCoverageIgnore | |
| 1072 | - * | |
| 1073 | - * @param array $atts | |
| 1074 | - * @return string | |
| 1075 | - */ | |
| 1076 | - public static function get_form_shortcode( $atts ) { | |
| 1077 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode' ); | |
| 1078 | - return FrmFormsController::get_form_shortcode( $atts ); | |
| 1079 | - } | |
| 1080 | - | |
| 1081 | - /** | |
| 1082 | - * Handles Floating Links' scripts and styles enqueueing. | |
| 1083 | - * | |
| 1084 | - * @since x.x | |
| 1085 | - * | |
| 1086 | - * @param string $plugin_url URL of the plugin. | |
| 1087 | - * @param string $version Current version of the plugin. | |
| 1088 | - * @return void | |
| 1089 | - */ | |
| 1090 | - private static function enqueue_floating_links( $plugin_url, $version ) { | |
| 1091 | - if ( ! $plugin_url || ! $version ) { | |
| 1092 | - // If any required parameters are missing, exit early. | |
| 1093 | - return; | |
| 1094 | - } | |
| 1095 | - | |
| 1096 | - // Enqueue the Floating Links styles. | |
| 1097 | - wp_enqueue_style( 's11-floating-links', $plugin_url . '/css/packages/s11-floating-links.css', array(), $version ); | |
| 1098 | - | |
| 1099 | - // Enqueue the Floating Links script. | |
| 1100 | - wp_enqueue_script( 's11-floating-links', $plugin_url . '/js/packages/floating-links/s11-floating-links.js', array(), $version, true ); | |
| 1101 | - | |
| 1102 | - // Enqueue the config script. | |
| 1103 | - wp_enqueue_script( 's11-floating-links-config', $plugin_url . '/js/packages/floating-links/config.js', array( 'wp-i18n' ), $version, true ); | |
| 1104 | - wp_set_script_translations( 's11-floating-links-config', 's11-' ); | |
| 1105 | - $floating_links_data = array( | |
| 1106 | - 'proIsInstalled' => FrmAppHelper::pro_is_installed(), | |
| 1107 | - ); | |
| 1108 | - wp_localize_script( 's11-floating-links-config', 's11FloatingLinksData', $floating_links_data ); | |
| 1109 | - } | |
| 450 | + public static function widget_text_filter_callback( $matches ) { | |
| 451 | + return do_shortcode( $matches[0] ); | |
| 452 | + } | |
| 453 | + | |
| 454 | + public static function update_message($features){ | |
| 455 | + include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php'); | |
| 456 | + } | |
| 457 | + | |
| 458 | + public static function get_postbox_class(){ | |
| 459 | + if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>')) | |
| 460 | + return 'postbox-container'; | |
| 461 | + else | |
| 462 | + return 'inner-sidebar'; | |
| 463 | + } | |
| 464 | + | |
| 465 | + public static function pro_is_installed(){ | |
| 466 | + return file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php'); | |
| 467 | + } | |
| 468 | + | |
| 469 | + public static function pro_is_authorized(){ | |
| 470 | + return get_site_option('frmpro-authorized'); | |
| 471 | + } | |
| 472 | + | |
| 473 | + public static function deauthorize(){ | |
| 474 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 475 | + | |
| 476 | + delete_option('frmpro-credentials'); | |
| 477 | + delete_option('frmpro-authorized'); | |
| 478 | + delete_site_option('frmpro-credentials'); | |
| 479 | + delete_site_option('frmpro-authorized'); | |
| 480 | + die(); | |
| 481 | + } | |
| 1110 | 482 | } |