| 1 |
<?php |
| 2 |
|
| 3 |
class FrmFormsController { |
| 4 |
|
| 5 |
public static function menu() { |
| 6 |
$menu_label = __( 'Forms', 'formidable' ); |
| 7 |
if ( ! FrmAppHelper::pro_is_installed() ) { |
| 8 |
$menu_label .= ' (Lite)'; |
| 9 |
} |
| 10 |
add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
| 11 |
|
| 12 |
self::maybe_load_listing_hooks(); |
| 13 |
} |
| 14 |
|
| 15 |
public static function maybe_load_listing_hooks() { |
| 16 |
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 17 |
if ( ! empty( $action ) && ! in_array( $action, array( 'list', 'trash', 'untrash', 'destroy' ) ) ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' ); |
| 22 |
|
| 23 |
add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 ); |
| 24 |
add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
| 25 |
} |
| 26 |
|
| 27 |
public static function head() { |
| 28 |
wp_enqueue_script( 'formidable-editinplace' ); |
| 29 |
|
| 30 |
if ( wp_is_mobile() ) { |
| 31 |
wp_enqueue_script( 'jquery-touch-punch' ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public static function register_widgets() { |
| 36 |
require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' ); |
| 37 |
register_widget( 'FrmShowForm' ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* By default, Divi processes form shortcodes on the edit post page. |
| 42 |
* Now that won't do. |
| 43 |
* |
| 44 |
* @since 3.01 |
| 45 |
*/ |
| 46 |
public static function prevent_divi_conflict( $shortcodes ) { |
| 47 |
$shortcodes[] = 'formidable'; |
| 48 |
return $shortcodes; |
| 49 |
} |
| 50 |
|
| 51 |
public static function list_form() { |
| 52 |
FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 53 |
|
| 54 |
$message = ''; |
| 55 |
$params = FrmForm::list_page_params(); |
| 56 |
$errors = self::process_bulk_form_actions( array() ); |
| 57 |
if ( isset( $errors['message'] ) ) { |
| 58 |
$message = $errors['message']; |
| 59 |
unset( $errors['message'] ); |
| 60 |
} |
| 61 |
$errors = apply_filters( 'frm_admin_list_form_action', $errors ); |
| 62 |
|
| 63 |
return self::display_forms_list( $params, $message, $errors ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Choose which type of form to create |
| 68 |
* |
| 69 |
* @since 3.06 |
| 70 |
*/ |
| 71 |
public static function add_new() { |
| 72 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add-new.php' ); |
| 73 |
} |
| 74 |
|
| 75 |
public static function new_form( $values = array() ) { |
| 76 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 77 |
|
| 78 |
global $frm_vars; |
| 79 |
|
| 80 |
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 81 |
$action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ]; |
| 82 |
|
| 83 |
if ( $action == 'create' ) { |
| 84 |
self::create( $values ); |
| 85 |
return; |
| 86 |
} else if ( $action == 'new' ) { |
| 87 |
$frm_field_selection = FrmField::field_selection(); |
| 88 |
$values = FrmFormsHelper::setup_new_vars( $values ); |
| 89 |
$id = FrmForm::create( $values ); |
| 90 |
$form = FrmForm::getOne( $id ); |
| 91 |
|
| 92 |
self::create_default_email_action( $form ); |
| 93 |
|
| 94 |
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 95 |
|
| 96 |
$values['id'] = $id; |
| 97 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Create the default email action |
| 103 |
* |
| 104 |
* @since 2.02.11 |
| 105 |
* |
| 106 |
* @param object $form |
| 107 |
*/ |
| 108 |
private static function create_default_email_action( $form ) { |
| 109 |
$create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
| 110 |
|
| 111 |
if ( $create_email ) { |
| 112 |
$action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 113 |
$action_control->create( $form->id ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
public static function create( $values = array() ) { |
| 118 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 119 |
|
| 120 |
global $frm_vars; |
| 121 |
if ( empty( $values ) ) { |
| 122 |
$values = $_POST; |
| 123 |
} |
| 124 |
|
| 125 |
//Set radio button and checkbox meta equal to "other" value |
| 126 |
if ( FrmAppHelper::pro_is_installed() ) { |
| 127 |
$values = FrmProEntry::mod_other_vals( $values, 'back' ); |
| 128 |
} |
| 129 |
|
| 130 |
$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 131 |
|
| 132 |
if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
| 133 |
$frm_settings = FrmAppHelper::get_settings(); |
| 134 |
$errors = array( 'form' => $frm_settings->admin_permission ); |
| 135 |
} else { |
| 136 |
$errors = FrmForm::validate( $values ); |
| 137 |
} |
| 138 |
|
| 139 |
if ( count( $errors ) > 0 ) { |
| 140 |
$hide_preview = true; |
| 141 |
$frm_field_selection = FrmField::field_selection(); |
| 142 |
$form = FrmForm::getOne( $id ); |
| 143 |
$fields = FrmField::get_all_for_form( $id ); |
| 144 |
|
| 145 |
$values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true ); |
| 146 |
$values['fields'] = $fields; |
| 147 |
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 148 |
|
| 149 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 150 |
} else { |
| 151 |
FrmForm::update( $id, $values, true ); |
| 152 |
$url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id ); |
| 153 |
die( FrmAppHelper::js_redirect( $url ) ); // WPCS: XSS ok. |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
public static function edit( $values = false ) { |
| 158 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 159 |
|
| 160 |
$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 161 |
return self::get_edit_vars( $id ); |
| 162 |
} |
| 163 |
|
| 164 |
public static function settings( $id = false, $message = '' ) { |
| 165 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 166 |
|
| 167 |
if ( ! $id || ! is_numeric( $id ) ) { |
| 168 |
$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 169 |
} |
| 170 |
return self::get_settings_vars( $id, array(), $message ); |
| 171 |
} |
| 172 |
|
| 173 |
public static function update_settings() { |
| 174 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 175 |
|
| 176 |
$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 177 |
|
| 178 |
$errors = FrmForm::validate( $_POST ); |
| 179 |
if ( count( $errors ) > 0 ) { |
| 180 |
return self::get_settings_vars( $id, $errors ); |
| 181 |
} |
| 182 |
|
| 183 |
do_action( 'frm_before_update_form_settings', $id ); |
| 184 |
|
| 185 |
FrmForm::update( $id, $_POST ); |
| 186 |
|
| 187 |
$message = __( 'Settings Successfully Updated', 'formidable' ); |
| 188 |
return self::get_settings_vars( $id, array(), $message ); |
| 189 |
} |
| 190 |
|
| 191 |
public static function update( $values = array() ) { |
| 192 |
if ( empty( $values ) ) { |
| 193 |
$values = $_POST; |
| 194 |
} |
| 195 |
|
| 196 |
//Set radio button and checkbox meta equal to "other" value |
| 197 |
if ( FrmAppHelper::pro_is_installed() ) { |
| 198 |
$values = FrmProEntry::mod_other_vals( $values, 'back' ); |
| 199 |
} |
| 200 |
|
| 201 |
$errors = FrmForm::validate( $values ); |
| 202 |
$permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
| 203 |
if ( $permission_error !== false ) { |
| 204 |
$errors['form'] = $permission_error; |
| 205 |
} |
| 206 |
|
| 207 |
$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 208 |
|
| 209 |
if ( count( $errors ) > 0 ) { |
| 210 |
return self::get_edit_vars( $id, $errors ); |
| 211 |
} else { |
| 212 |
FrmForm::update( $id, $values ); |
| 213 |
$message = __( 'Form was Successfully Updated', 'formidable' ); |
| 214 |
|
| 215 |
if ( self::is_too_long( $values ) ) { |
| 216 |
$message .= '<br/> ' . sprintf( |
| 217 |
/* translators: %1$s: Start link HTML, %2$s: end link HTML */ |
| 218 |
__( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), |
| 219 |
'<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">', |
| 220 |
'</a>' |
| 221 |
); |
| 222 |
} |
| 223 |
|
| 224 |
if ( defined( 'DOING_AJAX' ) ) { |
| 225 |
wp_die( esc_html( $message ) ); |
| 226 |
} |
| 227 |
return self::get_edit_vars( $id, array(), $message ); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Check if the value at the end of the form was included. |
| 233 |
* If it's missing, it means other values at the end of the form |
| 234 |
* were likely not saved either. |
| 235 |
* |
| 236 |
* @since 3.06.01 |
| 237 |
*/ |
| 238 |
private static function is_too_long( $values ) { |
| 239 |
return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Redirect to the url for creating from a template |
| 244 |
* Also delete the current form |
| 245 |
* |
| 246 |
* @since 2.0 |
| 247 |
* @deprecated 3.06 |
| 248 |
*/ |
| 249 |
public static function _create_from_template() { |
| 250 |
_deprecated_function( __FUNCTION__, '3.06' ); |
| 251 |
|
| 252 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 253 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 254 |
|
| 255 |
$current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' ); |
| 256 |
$template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 257 |
|
| 258 |
if ( $current_form ) { |
| 259 |
FrmForm::destroy( $current_form ); |
| 260 |
} |
| 261 |
|
| 262 |
echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) ); |
| 263 |
wp_die(); |
| 264 |
} |
| 265 |
|
| 266 |
public static function duplicate() { |
| 267 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 268 |
|
| 269 |
$params = FrmForm::list_page_params(); |
| 270 |
$form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
| 271 |
$message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
| 272 |
if ( $form ) { |
| 273 |
return self::get_edit_vars( $form, array(), $message, true ); |
| 274 |
} else { |
| 275 |
return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) ); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
public static function page_preview() { |
| 280 |
$params = FrmForm::list_page_params(); |
| 281 |
if ( ! $params['form'] ) { |
| 282 |
return; |
| 283 |
} |
| 284 |
|
| 285 |
$form = FrmForm::getOne( $params['form'] ); |
| 286 |
if ( $form ) { |
| 287 |
return self::show_form( $form->id, '', true, true ); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* @since 3.0 |
| 293 |
*/ |
| 294 |
public static function show_page_preview() { |
| 295 |
echo self::page_preview(); // WPCS: XSS ok. |
| 296 |
} |
| 297 |
|
| 298 |
public static function preview() { |
| 299 |
do_action( 'frm_wp' ); |
| 300 |
|
| 301 |
global $frm_vars; |
| 302 |
$frm_vars['preview'] = true; |
| 303 |
|
| 304 |
self::load_wp(); |
| 305 |
|
| 306 |
$include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' ); |
| 307 |
if ( $include_theme ) { |
| 308 |
self::set_preview_query(); |
| 309 |
self::load_theme_preview(); |
| 310 |
} else { |
| 311 |
self::load_direct_preview(); |
| 312 |
} |
| 313 |
|
| 314 |
wp_die(); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* @since 3.0 |
| 319 |
*/ |
| 320 |
private static function load_wp() { |
| 321 |
if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) { |
| 322 |
global $wp; |
| 323 |
$root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
| 324 |
include_once( $root . '/wp-config.php' ); |
| 325 |
$wp->init(); |
| 326 |
$wp->register_globals(); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
private static function set_preview_query() { |
| 331 |
$random_page = get_posts( |
| 332 |
array( |
| 333 |
'numberposts' => 1, |
| 334 |
'orderby' => 'date', |
| 335 |
'order' => 'ASC', |
| 336 |
'post_type' => 'page', |
| 337 |
) |
| 338 |
); |
| 339 |
|
| 340 |
if ( ! empty( $random_page ) ) { |
| 341 |
$random_page = reset( $random_page ); |
| 342 |
query_posts( |
| 343 |
array( |
| 344 |
'post_type' => 'page', |
| 345 |
'page_id' => $random_page->ID, |
| 346 |
) |
| 347 |
); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* @since 3.0 |
| 353 |
*/ |
| 354 |
private static function load_theme_preview() { |
| 355 |
add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
| 356 |
add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
| 357 |
add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 358 |
add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' ); |
| 359 |
add_filter( 'is_active_sidebar', '__return_false' ); |
| 360 |
get_template_part( 'page' ); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
/** |
| 365 |
* Set the page title for the theme preview page |
| 366 |
* |
| 367 |
* @since 3.0 |
| 368 |
*/ |
| 369 |
public static function preview_page_title( $title ) { |
| 370 |
if ( in_the_loop() ) { |
| 371 |
$title = self::preview_title( $title ); |
| 372 |
} |
| 373 |
return $title; |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* Set the page title for the theme preview page |
| 378 |
* |
| 379 |
* @since 3.0 |
| 380 |
*/ |
| 381 |
public static function preview_title( $title ) { |
| 382 |
return __( 'Form Preview', 'formidable' ); |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Set the page content for the theme preview page |
| 387 |
* |
| 388 |
* @since 3.0 |
| 389 |
*/ |
| 390 |
public static function preview_content( $content ) { |
| 391 |
if ( in_the_loop() ) { |
| 392 |
$content = self::show_page_preview(); |
| 393 |
} |
| 394 |
return $content; |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* @since 3.0 |
| 399 |
*/ |
| 400 |
private static function load_direct_preview() { |
| 401 |
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
| 402 |
|
| 403 |
$key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
| 404 |
if ( $key == '' ) { |
| 405 |
$key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
| 406 |
} |
| 407 |
|
| 408 |
$form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 ); |
| 409 |
if ( empty( $form ) ) { |
| 410 |
$form = FrmForm::getAll( array(), '', 1 ); |
| 411 |
} |
| 412 |
|
| 413 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); |
| 414 |
} |
| 415 |
|
| 416 |
public static function untrash() { |
| 417 |
self::change_form_status( 'untrash' ); |
| 418 |
} |
| 419 |
|
| 420 |
public static function bulk_untrash( $ids ) { |
| 421 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 422 |
|
| 423 |
$count = FrmForm::set_status( $ids, 'published' ); |
| 424 |
|
| 425 |
$message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
| 426 |
return $message; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* @since 3.06 |
| 431 |
*/ |
| 432 |
public static function ajax_trash() { |
| 433 |
FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 434 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 435 |
$form_id = FrmAppHelper::get_param( 'id', '', 'post', 'absint' ); |
| 436 |
FrmForm::set_status( $form_id, 'trash' ); |
| 437 |
wp_die(); |
| 438 |
} |
| 439 |
|
| 440 |
public static function trash() { |
| 441 |
self::change_form_status( 'trash' ); |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* @param string $status |
| 446 |
* |
| 447 |
* @return int The number of forms changed |
| 448 |
*/ |
| 449 |
public static function change_form_status( $status ) { |
| 450 |
$available_status = array( |
| 451 |
'untrash' => array( |
| 452 |
'permission' => 'frm_edit_forms', |
| 453 |
'new_status' => 'published', |
| 454 |
), |
| 455 |
'trash' => array( |
| 456 |
'permission' => 'frm_delete_forms', |
| 457 |
'new_status' => 'trash', |
| 458 |
), |
| 459 |
); |
| 460 |
|
| 461 |
if ( ! isset( $available_status[ $status ] ) ) { |
| 462 |
return; |
| 463 |
} |
| 464 |
|
| 465 |
FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 466 |
|
| 467 |
$params = FrmForm::list_page_params(); |
| 468 |
|
| 469 |
//check nonce url |
| 470 |
check_admin_referer( $status . '_form_' . $params['id'] ); |
| 471 |
|
| 472 |
$count = 0; |
| 473 |
if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| 474 |
$count++; |
| 475 |
} |
| 476 |
|
| 477 |
$form_type = FrmAppHelper::get_simple_request( |
| 478 |
array( |
| 479 |
'param' => 'form_type', |
| 480 |
'type' => 'request', |
| 481 |
) |
| 482 |
); |
| 483 |
|
| 484 |
$available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 485 |
$available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); |
| 486 |
|
| 487 |
$message = $available_status[ $status ]['message']; |
| 488 |
|
| 489 |
self::display_forms_list( $params, $message ); |
| 490 |
} |
| 491 |
|
| 492 |
public static function bulk_trash( $ids ) { |
| 493 |
FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 494 |
|
| 495 |
$count = 0; |
| 496 |
foreach ( $ids as $id ) { |
| 497 |
if ( FrmForm::trash( $id ) ) { |
| 498 |
$count++; |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
$current_page = FrmAppHelper::get_simple_request( |
| 503 |
array( |
| 504 |
'param' => 'form_type', |
| 505 |
'type' => 'request', |
| 506 |
) |
| 507 |
); |
| 508 |
$message = sprintf( |
| 509 |
_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), |
| 510 |
$count, |
| 511 |
'<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', |
| 512 |
'</a>' |
| 513 |
); |
| 514 |
|
| 515 |
return $message; |
| 516 |
} |
| 517 |
|
| 518 |
public static function destroy() { |
| 519 |
FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 520 |
|
| 521 |
$params = FrmForm::list_page_params(); |
| 522 |
|
| 523 |
//check nonce url |
| 524 |
check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 525 |
|
| 526 |
$count = 0; |
| 527 |
if ( FrmForm::destroy( $params['id'] ) ) { |
| 528 |
$count++; |
| 529 |
} |
| 530 |
|
| 531 |
$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 532 |
|
| 533 |
self::display_forms_list( $params, $message ); |
| 534 |
} |
| 535 |
|
| 536 |
public static function bulk_destroy( $ids ) { |
| 537 |
FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 538 |
|
| 539 |
$count = 0; |
| 540 |
foreach ( $ids as $id ) { |
| 541 |
$d = FrmForm::destroy( $id ); |
| 542 |
if ( $d ) { |
| 543 |
$count++; |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 548 |
|
| 549 |
return $message; |
| 550 |
} |
| 551 |
|
| 552 |
private static function delete_all() { |
| 553 |
//check nonce url |
| 554 |
$permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 555 |
if ( $permission_error !== false ) { |
| 556 |
self::display_forms_list( array(), '', array( $permission_error ) ); |
| 557 |
return; |
| 558 |
} |
| 559 |
|
| 560 |
$count = FrmForm::scheduled_delete( time() ); |
| 561 |
$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 562 |
|
| 563 |
self::display_forms_list( array(), $message ); |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* Create a custom template from a form |
| 568 |
* |
| 569 |
* @since 3.06 |
| 570 |
*/ |
| 571 |
public static function build_template() { |
| 572 |
global $wpdb; |
| 573 |
|
| 574 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 575 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 576 |
|
| 577 |
$form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); |
| 578 |
$new_form_id = FrmForm::duplicate( $form_id, 1, true ); |
| 579 |
if ( empty( $new_form_id ) ) { |
| 580 |
$response = array( |
| 581 |
'message' => __( 'There was an error creating a template.', 'formidable' ), |
| 582 |
); |
| 583 |
} else { |
| 584 |
// Update the new form name and description. |
| 585 |
$name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 586 |
$desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 587 |
|
| 588 |
$new_values = array( |
| 589 |
'name' => $name, |
| 590 |
'description' => $desc, |
| 591 |
); |
| 592 |
$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); |
| 593 |
if ( $query_results ) { |
| 594 |
FrmForm::clear_form_cache(); |
| 595 |
} |
| 596 |
|
| 597 |
$response = array( |
| 598 |
'redirect' => admin_url( 'admin.php?page=formidable&frm_action=list_templates' ), |
| 599 |
); |
| 600 |
} |
| 601 |
|
| 602 |
echo wp_json_encode( $response ); |
| 603 |
wp_die(); |
| 604 |
} |
| 605 |
|
| 606 |
/** |
| 607 |
* Inserts Formidable button |
| 608 |
* Hook exists since 2.5.0 |
| 609 |
* |
| 610 |
* @since 2.0.15 |
| 611 |
*/ |
| 612 |
public static function insert_form_button() { |
| 613 |
if ( current_user_can( 'frm_view_forms' ) ) { |
| 614 |
$menu_name = FrmAppHelper::get_menu_name(); |
| 615 |
$icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); |
| 616 |
echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . |
| 617 |
FrmAppHelper::kses( $icon, 'all' ) . |
| 618 |
' ' . esc_html( $menu_name ) . '</a>'; // WPCS: XSS ok. |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
public static function insert_form_popup() { |
| 623 |
$page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) ); |
| 624 |
if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) { |
| 625 |
return; |
| 626 |
} |
| 627 |
|
| 628 |
FrmAppHelper::load_admin_wide_js(); |
| 629 |
|
| 630 |
$shortcodes = array( |
| 631 |
'formidable' => array( |
| 632 |
'name' => __( 'Form', 'formidable' ), |
| 633 |
'label' => __( 'Insert a Form', 'formidable' ), |
| 634 |
), |
| 635 |
); |
| 636 |
|
| 637 |
$shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes ); |
| 638 |
|
| 639 |
include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' ); |
| 640 |
} |
| 641 |
|
| 642 |
public static function get_shortcode_opts() { |
| 643 |
FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 644 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 645 |
|
| 646 |
$shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' ); |
| 647 |
if ( empty( $shortcode ) ) { |
| 648 |
wp_die(); |
| 649 |
} |
| 650 |
|
| 651 |
echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">'; |
| 652 |
echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />'; |
| 653 |
|
| 654 |
$form_id = ''; |
| 655 |
$opts = array(); |
| 656 |
switch ( $shortcode ) { |
| 657 |
case 'formidable': |
| 658 |
$opts = array( |
| 659 |
'form_id' => 'id', |
| 660 |
//'key' => ', |
| 661 |
'title' => array( |
| 662 |
'val' => 1, |
| 663 |
'label' => __( 'Display form title', 'formidable' ), |
| 664 |
), |
| 665 |
'description' => array( |
| 666 |
'val' => 1, |
| 667 |
'label' => __( 'Display form description', 'formidable' ), |
| 668 |
), |
| 669 |
'minimize' => array( |
| 670 |
'val' => 1, |
| 671 |
'label' => __( 'Minimize form HTML', 'formidable' ), |
| 672 |
), |
| 673 |
); |
| 674 |
} |
| 675 |
$opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode ); |
| 676 |
|
| 677 |
if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) { |
| 678 |
// allow other shortcodes to use the required form id option |
| 679 |
$form_id = $opts['form_id']; |
| 680 |
unset( $opts['form_id'] ); |
| 681 |
} |
| 682 |
|
| 683 |
include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); |
| 684 |
|
| 685 |
echo '</div>'; |
| 686 |
|
| 687 |
wp_die(); |
| 688 |
} |
| 689 |
|
| 690 |
public static function display_forms_list( $params = array(), $message = '', $errors = array() ) { |
| 691 |
FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 692 |
|
| 693 |
global $wpdb, $frm_vars; |
| 694 |
|
| 695 |
if ( empty( $params ) ) { |
| 696 |
$params = FrmForm::list_page_params(); |
| 697 |
} |
| 698 |
|
| 699 |
$wp_list_table = new FrmFormsListHelper( compact( 'params' ) ); |
| 700 |
|
| 701 |
$pagenum = $wp_list_table->get_pagenum(); |
| 702 |
|
| 703 |
$wp_list_table->prepare_items(); |
| 704 |
|
| 705 |
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
| 706 |
if ( $pagenum > $total_pages && $total_pages > 0 ) { |
| 707 |
wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) ); |
| 708 |
die(); |
| 709 |
} |
| 710 |
|
| 711 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' ); |
| 712 |
} |
| 713 |
|
| 714 |
public static function get_columns( $columns ) { |
| 715 |
$columns['cb'] = '<input type="checkbox" />'; |
| 716 |
$columns['id'] = 'ID'; |
| 717 |
|
| 718 |
$type = FrmAppHelper::get_simple_request( |
| 719 |
array( |
| 720 |
'param' => 'form_type', |
| 721 |
'type' => 'request', |
| 722 |
'default' => 'published', |
| 723 |
) |
| 724 |
); |
| 725 |
|
| 726 |
if ( 'template' == $type ) { |
| 727 |
$columns['name'] = __( 'Template Name', 'formidable' ); |
| 728 |
$columns['type'] = __( 'Type', 'formidable' ); |
| 729 |
$columns['form_key'] = __( 'Key', 'formidable' ); |
| 730 |
} else { |
| 731 |
$columns['name'] = __( 'Form Title', 'formidable' ); |
| 732 |
$columns['entries'] = __( 'Entries', 'formidable' ); |
| 733 |
$columns['form_key'] = __( 'Key', 'formidable' ); |
| 734 |
$columns['shortcode'] = __( 'Shortcodes', 'formidable' ); |
| 735 |
} |
| 736 |
|
| 737 |
$columns['created_at'] = __( 'Date', 'formidable' ); |
| 738 |
|
| 739 |
add_screen_option( |
| 740 |
'per_page', |
| 741 |
array( |
| 742 |
'label' => __( 'Forms', 'formidable' ), |
| 743 |
'default' => 20, |
| 744 |
'option' => 'formidable_page_formidable_per_page', |
| 745 |
) |
| 746 |
); |
| 747 |
|
| 748 |
return $columns; |
| 749 |
} |
| 750 |
|
| 751 |
public static function get_sortable_columns() { |
| 752 |
return array( |
| 753 |
'id' => 'id', |
| 754 |
'name' => 'name', |
| 755 |
'description' => 'description', |
| 756 |
'form_key' => 'form_key', |
| 757 |
'created_at' => 'created_at', |
| 758 |
); |
| 759 |
} |
| 760 |
|
| 761 |
public static function hidden_columns( $hidden_columns ) { |
| 762 |
$type = FrmAppHelper::get_simple_request( |
| 763 |
array( |
| 764 |
'param' => 'form_type', |
| 765 |
'type' => 'request', |
| 766 |
) |
| 767 |
); |
| 768 |
|
| 769 |
if ( $type === 'template' ) { |
| 770 |
$hidden_columns[] = 'id'; |
| 771 |
$hidden_columns[] = 'form_key'; |
| 772 |
} |
| 773 |
|
| 774 |
return $hidden_columns; |
| 775 |
} |
| 776 |
|
| 777 |
public static function save_per_page( $save, $option, $value ) { |
| 778 |
if ( $option == 'formidable_page_formidable_per_page' ) { |
| 779 |
$save = (int) $value; |
| 780 |
} |
| 781 |
return $save; |
| 782 |
} |
| 783 |
|
| 784 |
/** |
| 785 |
* Show the template listing page |
| 786 |
* |
| 787 |
* @since 3.06 |
| 788 |
*/ |
| 789 |
private static function list_templates() { |
| 790 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 791 |
wp_enqueue_style( 'jquery-ui-dialog' ); |
| 792 |
|
| 793 |
$where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 794 |
$forms = FrmForm::get_published_forms( $where ); |
| 795 |
|
| 796 |
$api = new FrmFormTemplateApi(); |
| 797 |
$templates = $api->get_api_info(); |
| 798 |
self::add_user_templates( $templates ); |
| 799 |
|
| 800 |
$error = ''; |
| 801 |
$expired = false; |
| 802 |
if ( isset( $templates['error'] ) ) { |
| 803 |
$error = $templates['error']['message']; |
| 804 |
$error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); |
| 805 |
$expired = ( $templates['error']['code'] === 'expired' ); |
| 806 |
unset( $templates['error'] ); |
| 807 |
} |
| 808 |
|
| 809 |
$pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); |
| 810 |
$plans = array( 'free', 'Personal', 'Business', 'Elite' ); |
| 811 |
|
| 812 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list-templates.php' ); |
| 813 |
} |
| 814 |
|
| 815 |
private static function add_user_templates( &$templates ) { |
| 816 |
$user_templates = array( |
| 817 |
'is_template' => 1, |
| 818 |
'default_template' => 0, |
| 819 |
); |
| 820 |
$user_templates = FrmForm::getAll( $user_templates, 'name' ); |
| 821 |
foreach ( $user_templates as $template ) { |
| 822 |
$template = array( |
| 823 |
'id' => $template->id, |
| 824 |
'name' => $template->name, |
| 825 |
'key' => $template->form_key, |
| 826 |
'description' => $template->description, |
| 827 |
'url' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ), |
| 828 |
'released' => $template->created_at, |
| 829 |
'installed' => 1, |
| 830 |
); |
| 831 |
array_unshift( $templates, $template ); |
| 832 |
unset( $template ); |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { |
| 837 |
global $frm_vars; |
| 838 |
|
| 839 |
$form = FrmForm::getOne( $id ); |
| 840 |
if ( ! $form ) { |
| 841 |
wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
| 842 |
} |
| 843 |
|
| 844 |
if ( $form->parent_form_id ) { |
| 845 |
wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ) ); |
| 846 |
} |
| 847 |
|
| 848 |
$frm_field_selection = FrmField::field_selection(); |
| 849 |
$fields = FrmField::get_all_for_form( $form->id ); |
| 850 |
|
| 851 |
// Automatically add end section fields if they don't exist (2.0 migration) |
| 852 |
$reset_fields = false; |
| 853 |
FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
| 854 |
|
| 855 |
if ( $reset_fields ) { |
| 856 |
$fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
| 857 |
} |
| 858 |
|
| 859 |
unset( $end_section_values, $last_order, $open, $reset_fields ); |
| 860 |
|
| 861 |
$args = array( 'parent_form_id' => $form->id ); |
| 862 |
$values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args ); |
| 863 |
$values['fields'] = $fields; |
| 864 |
|
| 865 |
$edit_message = __( 'Form was Successfully Updated', 'formidable' ); |
| 866 |
if ( $form->is_template && $message == $edit_message ) { |
| 867 |
$message = __( 'Template was Successfully Updated', 'formidable' ); |
| 868 |
} |
| 869 |
|
| 870 |
$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 871 |
|
| 872 |
if ( defined( 'DOING_AJAX' ) ) { |
| 873 |
wp_die(); |
| 874 |
} else if ( $create_link ) { |
| 875 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 876 |
} else { |
| 877 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
public static function get_settings_vars( $id, $errors = array(), $message = '' ) { |
| 882 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 883 |
|
| 884 |
global $frm_vars; |
| 885 |
|
| 886 |
$form = FrmForm::getOne( $id ); |
| 887 |
|
| 888 |
$fields = FrmField::get_all_for_form( $id ); |
| 889 |
$values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true ); |
| 890 |
|
| 891 |
self::clean_submit_html( $values ); |
| 892 |
|
| 893 |
$action_controls = FrmFormActionsController::get_form_actions(); |
| 894 |
|
| 895 |
$sections = apply_filters( 'frm_add_form_settings_section', array(), $values ); |
| 896 |
$pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
| 897 |
|
| 898 |
$styles = apply_filters( 'frm_get_style_opts', array() ); |
| 899 |
|
| 900 |
$first_h3 = 'frm_first_h3'; |
| 901 |
|
| 902 |
FrmAppController::include_upgrade_overlay(); |
| 903 |
|
| 904 |
require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); |
| 905 |
} |
| 906 |
|
| 907 |
/** |
| 908 |
* Replace old Submit Button href with new href to avoid errors in Chrome |
| 909 |
* |
| 910 |
* @since 2.03.08 |
| 911 |
* |
| 912 |
* @param array|boolean $values |
| 913 |
*/ |
| 914 |
private static function clean_submit_html( &$values ) { |
| 915 |
if ( is_array( $values ) && isset( $values['submit_html'] ) ) { |
| 916 |
$values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] ); |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
public static function mb_tags_box( $form_id, $class = '' ) { |
| 921 |
$fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 922 |
$linked_forms = array(); |
| 923 |
$col = 'one'; |
| 924 |
$settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; |
| 925 |
|
| 926 |
$cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
| 927 |
$entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 928 |
|
| 929 |
$advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) ); |
| 930 |
|
| 931 |
include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); |
| 932 |
} |
| 933 |
|
| 934 |
/** |
| 935 |
* @since 3.04.01 |
| 936 |
*/ |
| 937 |
private static function advanced_helpers( $atts ) { |
| 938 |
$advanced_helpers = array( |
| 939 |
'default' => array( |
| 940 |
'heading' => __( 'Customize the field values with the following parameters. Click to see a sample.', 'formidable' ), |
| 941 |
'codes' => self::get_advanced_shortcodes(), |
| 942 |
), |
| 943 |
); |
| 944 |
|
| 945 |
$user_fields = self::user_shortcodes(); |
| 946 |
if ( ! empty( $user_fields ) ) { |
| 947 |
$user_helpers = array(); |
| 948 |
foreach ( $user_fields as $uk => $uf ) { |
| 949 |
$user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; |
| 950 |
unset( $uk, $uf ); |
| 951 |
} |
| 952 |
|
| 953 |
$advanced_helpers['user_id'] = array( |
| 954 |
'heading' => __( 'Insert user information', 'formidable' ), |
| 955 |
'codes' => $user_helpers, |
| 956 |
); |
| 957 |
} |
| 958 |
|
| 959 |
/** |
| 960 |
* Add extra helper shortcodes on the Advanced tab in form settings and views |
| 961 |
* |
| 962 |
* @since 3.04.01 |
| 963 |
* @param array $atts - Includes fields and form_id |
| 964 |
*/ |
| 965 |
return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts ); |
| 966 |
} |
| 967 |
|
| 968 |
/** |
| 969 |
* Get an array of the options to display in the advanced tab |
| 970 |
* of the customization panel |
| 971 |
* |
| 972 |
* @since 2.0.6 |
| 973 |
*/ |
| 974 |
private static function get_advanced_shortcodes() { |
| 975 |
$adv_shortcodes = array( |
| 976 |
'x sep=", "' => array( |
| 977 |
'label' => __( 'Separator', 'formidable' ), |
| 978 |
'title' => __( 'Use a different separator for checkbox fields', 'formidable' ), |
| 979 |
), |
| 980 |
'x format="d-m-Y"' => __( 'Date Format', 'formidable' ), |
| 981 |
'x show="field_label"' => __( 'Field Label', 'formidable' ), |
| 982 |
'x wpautop=0' => array( |
| 983 |
'label' => __( 'No Auto P', 'formidable' ), |
| 984 |
'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ), |
| 985 |
), |
| 986 |
); |
| 987 |
$adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes ); |
| 988 |
// __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1 |
| 989 |
|
| 990 |
return $adv_shortcodes; |
| 991 |
} |
| 992 |
|
| 993 |
/** |
| 994 |
* @since 3.04.01 |
| 995 |
*/ |
| 996 |
private static function user_shortcodes() { |
| 997 |
$options = array( |
| 998 |
'ID' => __( 'User ID', 'formidable' ), |
| 999 |
'first_name' => __( 'First Name', 'formidable' ), |
| 1000 |
'last_name' => __( 'Last Name', 'formidable' ), |
| 1001 |
'display_name' => __( 'Display Name', 'formidable' ), |
| 1002 |
'user_login' => __( 'User Login', 'formidable' ), |
| 1003 |
'user_email' => __( 'Email', 'formidable' ), |
| 1004 |
'avatar' => __( 'Avatar', 'formidable' ), |
| 1005 |
'author_link' => __( 'Author Link', 'formidable' ), |
| 1006 |
); |
| 1007 |
return apply_filters( 'frm_user_shortcodes', $options ); |
| 1008 |
} |
| 1009 |
|
| 1010 |
/** |
| 1011 |
* Get an array of the helper shortcodes to display in the customization panel |
| 1012 |
* |
| 1013 |
* @since 2.0.6 |
| 1014 |
*/ |
| 1015 |
private static function get_shortcode_helpers( $settings_tab ) { |
| 1016 |
$entry_shortcodes = array( |
| 1017 |
'id' => __( 'Entry ID', 'formidable' ), |
| 1018 |
'key' => __( 'Entry Key', 'formidable' ), |
| 1019 |
'post_id' => __( 'Post ID', 'formidable' ), |
| 1020 |
'ip' => __( 'User IP', 'formidable' ), |
| 1021 |
'created-at' => __( 'Entry created', 'formidable' ), |
| 1022 |
'updated-at' => __( 'Entry updated', 'formidable' ), |
| 1023 |
'' => '', |
| 1024 |
'siteurl' => __( 'Site URL', 'formidable' ), |
| 1025 |
'sitename' => __( 'Site Name', 'formidable' ), |
| 1026 |
); |
| 1027 |
|
| 1028 |
if ( ! FrmAppHelper::pro_is_installed() ) { |
| 1029 |
unset( $entry_shortcodes['post_id'] ); |
| 1030 |
} |
| 1031 |
|
| 1032 |
if ( $settings_tab ) { |
| 1033 |
$entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' ); |
| 1034 |
$entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' ); |
| 1035 |
$entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' ); |
| 1036 |
} |
| 1037 |
|
| 1038 |
/** |
| 1039 |
* Use this hook to add or remove buttons in the helpers section |
| 1040 |
* in the customization panel |
| 1041 |
* |
| 1042 |
* @since 2.0.6 |
| 1043 |
*/ |
| 1044 |
$entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab ); |
| 1045 |
|
| 1046 |
return $entry_shortcodes; |
| 1047 |
} |
| 1048 |
|
| 1049 |
/** |
| 1050 |
* Insert the form class setting into the form |
| 1051 |
*/ |
| 1052 |
public static function form_classes( $form ) { |
| 1053 |
if ( isset( $form->options['form_class'] ) ) { |
| 1054 |
echo esc_attr( sanitize_text_field( $form->options['form_class'] ) ); |
| 1055 |
} |
| 1056 |
|
| 1057 |
if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) { |
| 1058 |
echo ' frm_js_validate '; |
| 1059 |
} |
| 1060 |
} |
| 1061 |
|
| 1062 |
public static function get_email_html() { |
| 1063 |
FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 1064 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1065 |
|
| 1066 |
echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok. |
| 1067 |
array( |
| 1068 |
'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), |
| 1069 |
'default_email' => true, |
| 1070 |
'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), |
| 1071 |
) |
| 1072 |
); |
| 1073 |
wp_die(); |
| 1074 |
} |
| 1075 |
|
| 1076 |
public static function filter_content( $content, $form, $entry = false ) { |
| 1077 |
self::get_entry_by_param( $entry ); |
| 1078 |
if ( ! $entry ) { |
| 1079 |
return $content; |
| 1080 |
} |
| 1081 |
|
| 1082 |
if ( is_object( $form ) ) { |
| 1083 |
$form = $form->id; |
| 1084 |
} |
| 1085 |
|
| 1086 |
$shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
| 1087 |
$content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
| 1088 |
|
| 1089 |
return $content; |
| 1090 |
} |
| 1091 |
|
| 1092 |
private static function get_entry_by_param( &$entry ) { |
| 1093 |
if ( ! $entry || ! is_object( $entry ) ) { |
| 1094 |
if ( ! $entry || ! is_numeric( $entry ) ) { |
| 1095 |
$entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' ); |
| 1096 |
} |
| 1097 |
|
| 1098 |
FrmEntry::maybe_get_entry( $entry ); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1103 |
return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
| 1104 |
} |
| 1105 |
|
| 1106 |
public static function process_bulk_form_actions( $errors ) { |
| 1107 |
if ( ! $_REQUEST ) { |
| 1108 |
return $errors; |
| 1109 |
} |
| 1110 |
|
| 1111 |
$bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
| 1112 |
if ( $bulkaction == -1 ) { |
| 1113 |
$bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
| 1114 |
} |
| 1115 |
|
| 1116 |
if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) { |
| 1117 |
FrmAppHelper::remove_get_action(); |
| 1118 |
|
| 1119 |
$bulkaction = str_replace( 'bulk_', '', $bulkaction ); |
| 1120 |
} |
| 1121 |
|
| 1122 |
$ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' ); |
| 1123 |
if ( empty( $ids ) ) { |
| 1124 |
$errors[] = __( 'No forms were specified', 'formidable' ); |
| 1125 |
return $errors; |
| 1126 |
} |
| 1127 |
|
| 1128 |
$permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 1129 |
if ( $permission_error !== false ) { |
| 1130 |
$errors[] = $permission_error; |
| 1131 |
return $errors; |
| 1132 |
} |
| 1133 |
|
| 1134 |
if ( ! is_array( $ids ) ) { |
| 1135 |
$ids = explode( ',', $ids ); |
| 1136 |
} |
| 1137 |
|
| 1138 |
switch ( $bulkaction ) { |
| 1139 |
case 'delete': |
| 1140 |
$message = self::bulk_destroy( $ids ); |
| 1141 |
break; |
| 1142 |
case 'trash': |
| 1143 |
$message = self::bulk_trash( $ids ); |
| 1144 |
break; |
| 1145 |
case 'untrash': |
| 1146 |
$message = self::bulk_untrash( $ids ); |
| 1147 |
} |
| 1148 |
|
| 1149 |
if ( isset( $message ) && ! empty( $message ) ) { |
| 1150 |
$errors['message'] = $message; |
| 1151 |
} |
| 1152 |
|
| 1153 |
return $errors; |
| 1154 |
} |
| 1155 |
|
| 1156 |
public static function route() { |
| 1157 |
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 1158 |
$vars = array(); |
| 1159 |
if ( isset( $_POST['frm_compact_fields'] ) ) { |
| 1160 |
FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1161 |
|
| 1162 |
$json_vars = htmlspecialchars_decode( nl2br( stripslashes( str_replace( '"', '\\\"', $_POST['frm_compact_fields'] ) ) ) ); |
| 1163 |
$json_vars = json_decode( $json_vars, true ); |
| 1164 |
if ( empty( $json_vars ) ) { |
| 1165 |
// json decoding failed so we should return an error message |
| 1166 |
$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1167 |
if ( 'edit' == $action ) { |
| 1168 |
$action = 'update'; |
| 1169 |
} |
| 1170 |
|
| 1171 |
add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| 1172 |
} else { |
| 1173 |
$vars = FrmAppHelper::json_to_array( $json_vars ); |
| 1174 |
$action = $vars[ $action ]; |
| 1175 |
unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); |
| 1176 |
$_REQUEST = array_merge( $_REQUEST, $vars ); |
| 1177 |
$_POST = array_merge( $_POST, $_REQUEST ); |
| 1178 |
} |
| 1179 |
} else { |
| 1180 |
$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1181 |
if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1182 |
// override the action for this page |
| 1183 |
$action = 'delete_all'; |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1188 |
FrmAppHelper::trigger_hook_load( 'form' ); |
| 1189 |
|
| 1190 |
switch ( $action ) { |
| 1191 |
case 'new': |
| 1192 |
return self::new_form( $vars ); |
| 1193 |
case 'add_new': |
| 1194 |
case 'list_templates': |
| 1195 |
case 'create': |
| 1196 |
case 'edit': |
| 1197 |
case 'update': |
| 1198 |
case 'duplicate': |
| 1199 |
case 'trash': |
| 1200 |
case 'untrash': |
| 1201 |
case 'destroy': |
| 1202 |
case 'delete_all': |
| 1203 |
case 'settings': |
| 1204 |
case 'update_settings': |
| 1205 |
return self::$action( $vars ); |
| 1206 |
default: |
| 1207 |
do_action( 'frm_form_action_' . $action ); |
| 1208 |
if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 1209 |
return; |
| 1210 |
} |
| 1211 |
|
| 1212 |
$action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
| 1213 |
if ( $action == -1 ) { |
| 1214 |
$action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
| 1215 |
} |
| 1216 |
|
| 1217 |
if ( strpos( $action, 'bulk_' ) === 0 ) { |
| 1218 |
FrmAppHelper::remove_get_action(); |
| 1219 |
return self::list_form(); |
| 1220 |
} |
| 1221 |
|
| 1222 |
return self::display_forms_list(); |
| 1223 |
} |
| 1224 |
} |
| 1225 |
|
| 1226 |
public static function json_error( $errors ) { |
| 1227 |
$errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1228 |
return $errors; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
/* FRONT-END FORMS */ |
| 1233 |
public static function admin_bar_css() { |
| 1234 |
if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1235 |
return; |
| 1236 |
} |
| 1237 |
|
| 1238 |
add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' ); |
| 1239 |
FrmAppHelper::load_font_style(); |
| 1240 |
} |
| 1241 |
|
| 1242 |
public static function admin_bar_configure() { |
| 1243 |
global $frm_vars; |
| 1244 |
if ( empty( $frm_vars['forms_loaded'] ) ) { |
| 1245 |
return; |
| 1246 |
} |
| 1247 |
|
| 1248 |
$actions = array(); |
| 1249 |
foreach ( $frm_vars['forms_loaded'] as $form ) { |
| 1250 |
if ( is_object( $form ) ) { |
| 1251 |
$actions[ $form->id ] = $form->name; |
| 1252 |
} |
| 1253 |
unset( $form ); |
| 1254 |
} |
| 1255 |
|
| 1256 |
if ( empty( $actions ) ) { |
| 1257 |
return; |
| 1258 |
} |
| 1259 |
|
| 1260 |
self::add_menu_to_admin_bar(); |
| 1261 |
self::add_forms_to_admin_bar( $actions ); |
| 1262 |
} |
| 1263 |
|
| 1264 |
/** |
| 1265 |
* @since 2.05.07 |
| 1266 |
*/ |
| 1267 |
public static function add_menu_to_admin_bar() { |
| 1268 |
global $wp_admin_bar; |
| 1269 |
|
| 1270 |
$wp_admin_bar->add_node( |
| 1271 |
array( |
| 1272 |
'id' => 'frm-forms', |
| 1273 |
'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>', |
| 1274 |
'href' => admin_url( 'admin.php?page=formidable' ), |
| 1275 |
'meta' => array( |
| 1276 |
'title' => FrmAppHelper::get_menu_name(), |
| 1277 |
), |
| 1278 |
) |
| 1279 |
); |
| 1280 |
} |
| 1281 |
|
| 1282 |
/** |
| 1283 |
* @since 2.05.07 |
| 1284 |
*/ |
| 1285 |
private static function add_forms_to_admin_bar( $actions ) { |
| 1286 |
global $wp_admin_bar; |
| 1287 |
|
| 1288 |
asort( $actions ); |
| 1289 |
|
| 1290 |
foreach ( $actions as $form_id => $name ) { |
| 1291 |
|
| 1292 |
$wp_admin_bar->add_node( |
| 1293 |
array( |
| 1294 |
'parent' => 'frm-forms', |
| 1295 |
'id' => 'edit_form_' . $form_id, |
| 1296 |
'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name, |
| 1297 |
'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ), |
| 1298 |
) |
| 1299 |
); |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
//formidable shortcode |
| 1304 |
public static function get_form_shortcode( $atts ) { |
| 1305 |
global $frm_vars; |
| 1306 |
if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { |
| 1307 |
$sc = '[formidable'; |
| 1308 |
if ( ! empty( $atts ) ) { |
| 1309 |
foreach ( $atts as $k => $v ) { |
| 1310 |
$sc .= ' ' . $k . '="' . esc_attr( $v ) . '"'; |
| 1311 |
} |
| 1312 |
} |
| 1313 |
return $sc . ']'; |
| 1314 |
} |
| 1315 |
|
| 1316 |
$shortcode_atts = shortcode_atts( |
| 1317 |
array( |
| 1318 |
'id' => '', |
| 1319 |
'key' => '', |
| 1320 |
'title' => false, |
| 1321 |
'description' => false, |
| 1322 |
'readonly' => false, |
| 1323 |
'entry_id' => false, |
| 1324 |
'fields' => array(), |
| 1325 |
'exclude_fields' => array(), |
| 1326 |
'minimize' => false, |
| 1327 |
), |
| 1328 |
$atts |
| 1329 |
); |
| 1330 |
do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts ); |
| 1331 |
|
| 1332 |
return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts ); |
| 1333 |
} |
| 1334 |
|
| 1335 |
public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
| 1336 |
if ( empty( $id ) ) { |
| 1337 |
$id = $key; |
| 1338 |
} |
| 1339 |
|
| 1340 |
$form = self::maybe_get_form_to_show( $id ); |
| 1341 |
if ( ! $form ) { |
| 1342 |
return __( 'Please select a valid form', 'formidable' ); |
| 1343 |
} |
| 1344 |
|
| 1345 |
FrmAppController::maybe_update_styles(); |
| 1346 |
|
| 1347 |
add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1348 |
FrmAppHelper::trigger_hook_load( 'form', $form ); |
| 1349 |
|
| 1350 |
$form = apply_filters( 'frm_pre_display_form', $form ); |
| 1351 |
|
| 1352 |
$frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) ); |
| 1353 |
|
| 1354 |
if ( self::is_viewable_draft_form( $form ) ) { |
| 1355 |
// don't show a draft form on a page |
| 1356 |
$form = __( 'Please select a valid form', 'formidable' ); |
| 1357 |
} else if ( self::user_should_login( $form ) ) { |
| 1358 |
$form = do_shortcode( $frm_settings->login_msg ); |
| 1359 |
} else if ( self::user_has_permission_to_view( $form ) ) { |
| 1360 |
$form = do_shortcode( $frm_settings->login_msg ); |
| 1361 |
} else { |
| 1362 |
do_action( 'frm_pre_get_form', $form ); |
| 1363 |
$form = self::get_form( $form, $title, $description, $atts ); |
| 1364 |
|
| 1365 |
/** |
| 1366 |
* Use this shortcode to check for external shortcodes that may span |
| 1367 |
* across multiple fields in the customizable HTML |
| 1368 |
* |
| 1369 |
* @since 2.0.8 |
| 1370 |
*/ |
| 1371 |
$form = apply_filters( 'frm_filter_final_form', $form ); |
| 1372 |
} |
| 1373 |
|
| 1374 |
return $form; |
| 1375 |
} |
| 1376 |
|
| 1377 |
private static function maybe_get_form_to_show( $id ) { |
| 1378 |
$form = false; |
| 1379 |
|
| 1380 |
if ( ! empty( $id ) ) { // no form id or key set |
| 1381 |
$form = FrmForm::getOne( $id ); |
| 1382 |
if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) { |
| 1383 |
$form = false; |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
return $form; |
| 1388 |
} |
| 1389 |
|
| 1390 |
private static function is_viewable_draft_form( $form ) { |
| 1391 |
global $post; |
| 1392 |
$frm_settings = FrmAppHelper::get_settings(); |
| 1393 |
return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page(); |
| 1394 |
} |
| 1395 |
|
| 1396 |
private static function user_should_login( $form ) { |
| 1397 |
return $form->logged_in && ! is_user_logged_in(); |
| 1398 |
} |
| 1399 |
|
| 1400 |
private static function user_has_permission_to_view( $form ) { |
| 1401 |
return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ); |
| 1402 |
} |
| 1403 |
|
| 1404 |
public static function get_form( $form, $title, $description, $atts = array() ) { |
| 1405 |
ob_start(); |
| 1406 |
|
| 1407 |
do_action( 'frm_before_get_form', $atts ); |
| 1408 |
|
| 1409 |
self::get_form_contents( $form, $title, $description, $atts ); |
| 1410 |
self::enqueue_scripts( FrmForm::get_params( $form ) ); |
| 1411 |
|
| 1412 |
$contents = ob_get_contents(); |
| 1413 |
ob_end_clean(); |
| 1414 |
|
| 1415 |
self::maybe_minimize_form( $atts, $contents ); |
| 1416 |
|
| 1417 |
return $contents; |
| 1418 |
} |
| 1419 |
|
| 1420 |
public static function enqueue_scripts( $params ) { |
| 1421 |
do_action( 'frm_enqueue_form_scripts', $params ); |
| 1422 |
} |
| 1423 |
|
| 1424 |
public static function get_form_contents( $form, $title, $description, $atts ) { |
| 1425 |
$params = FrmForm::get_params( $form ); |
| 1426 |
$errors = self::get_saved_errors( $form, $params ); |
| 1427 |
$fields = FrmFieldsHelper::get_form_fields( $form->id, $errors ); |
| 1428 |
$reset = false; |
| 1429 |
$pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' ); |
| 1430 |
|
| 1431 |
$handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST; |
| 1432 |
|
| 1433 |
if ( ! $handle_process_here ) { |
| 1434 |
do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description ); |
| 1435 |
if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) { |
| 1436 |
self::show_form_after_submit( $pass_args ); |
| 1437 |
} |
| 1438 |
} elseif ( ! empty( $errors ) ) { |
| 1439 |
self::show_form_after_submit( $pass_args ); |
| 1440 |
|
| 1441 |
} else { |
| 1442 |
|
| 1443 |
do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
| 1444 |
|
| 1445 |
if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) { |
| 1446 |
$entry_id = self::just_created_entry( $form->id ); |
| 1447 |
$pass_args['entry_id'] = $entry_id; |
| 1448 |
$pass_args['reset'] = true; |
| 1449 |
$pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) ); |
| 1450 |
|
| 1451 |
self::run_success_action( $pass_args ); |
| 1452 |
|
| 1453 |
do_action( |
| 1454 |
'frm_after_entry_processed', |
| 1455 |
array( |
| 1456 |
'entry_id' => $entry_id, |
| 1457 |
'form' => $form, |
| 1458 |
) |
| 1459 |
); |
| 1460 |
} |
| 1461 |
} |
| 1462 |
} |
| 1463 |
|
| 1464 |
/** |
| 1465 |
* If the form was processed earlier (init), get the generated errors |
| 1466 |
* |
| 1467 |
* @since 2.05 |
| 1468 |
*/ |
| 1469 |
private static function get_saved_errors( $form, $params ) { |
| 1470 |
global $frm_vars; |
| 1471 |
|
| 1472 |
if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) { |
| 1473 |
$errors = $frm_vars['created_entries'][ $form->id ]['errors']; |
| 1474 |
} else { |
| 1475 |
$errors = array(); |
| 1476 |
} |
| 1477 |
return $errors; |
| 1478 |
} |
| 1479 |
|
| 1480 |
/** |
| 1481 |
* @since 2.2.7 |
| 1482 |
*/ |
| 1483 |
public static function just_created_entry( $form_id ) { |
| 1484 |
global $frm_vars; |
| 1485 |
return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; |
| 1486 |
} |
| 1487 |
|
| 1488 |
/** |
| 1489 |
* @since 3.0 |
| 1490 |
*/ |
| 1491 |
private static function get_confirmation_method( $atts ) { |
| 1492 |
$opt = 'success_action'; |
| 1493 |
$method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; |
| 1494 |
$method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' ); |
| 1495 |
|
| 1496 |
if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { |
| 1497 |
$method = 'message'; |
| 1498 |
} |
| 1499 |
|
| 1500 |
return $method; |
| 1501 |
} |
| 1502 |
|
| 1503 |
public static function maybe_trigger_redirect( $form, $params, $args ) { |
| 1504 |
if ( ! isset( $params['id'] ) ) { |
| 1505 |
global $frm_vars; |
| 1506 |
$params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id']; |
| 1507 |
} |
| 1508 |
|
| 1509 |
$conf_method = self::get_confirmation_method( |
| 1510 |
array( |
| 1511 |
'form' => $form, |
| 1512 |
'entry_id' => $params['id'], |
| 1513 |
) |
| 1514 |
); |
| 1515 |
|
| 1516 |
if ( 'redirect' === $conf_method ) { |
| 1517 |
self::trigger_redirect( $form, $params, $args ); |
| 1518 |
} |
| 1519 |
} |
| 1520 |
|
| 1521 |
public static function trigger_redirect( $form, $params, $args ) { |
| 1522 |
$success_args = array( |
| 1523 |
'action' => $params['action'], |
| 1524 |
'conf_method' => 'redirect', |
| 1525 |
'form' => $form, |
| 1526 |
'entry_id' => $params['id'], |
| 1527 |
); |
| 1528 |
|
| 1529 |
if ( isset( $args['ajax'] ) ) { |
| 1530 |
$success_args['ajax'] = $args['ajax']; |
| 1531 |
} |
| 1532 |
|
| 1533 |
self::run_success_action( $success_args ); |
| 1534 |
} |
| 1535 |
|
| 1536 |
/** |
| 1537 |
* Used when the success action is not 'message' |
| 1538 |
* |
| 1539 |
* @since 2.05 |
| 1540 |
*/ |
| 1541 |
public static function run_success_action( $args ) { |
| 1542 |
$extra_args = $args; |
| 1543 |
unset( $extra_args['form'] ); |
| 1544 |
|
| 1545 |
do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args ); |
| 1546 |
|
| 1547 |
$opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit'; |
| 1548 |
$args['success_opt'] = $opt; |
| 1549 |
if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) { |
| 1550 |
self::load_page_after_submit( $args ); |
| 1551 |
} elseif ( $args['conf_method'] == 'redirect' ) { |
| 1552 |
self::redirect_after_submit( $args ); |
| 1553 |
} else { |
| 1554 |
self::show_message_after_save( $args ); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
/** |
| 1559 |
* @since 3.0 |
| 1560 |
*/ |
| 1561 |
private static function load_page_after_submit( $args ) { |
| 1562 |
global $post; |
| 1563 |
$opt = $args['success_opt']; |
| 1564 |
if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) { |
| 1565 |
$page = get_post( $args['form']->options[ $opt . '_page_id' ] ); |
| 1566 |
$old_post = $post; |
| 1567 |
$post = $page; |
| 1568 |
$content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] ); |
| 1569 |
echo apply_filters( 'the_content', $content ); // WPCS: XSS ok. |
| 1570 |
$post = $old_post; |
| 1571 |
} |
| 1572 |
} |
| 1573 |
|
| 1574 |
/** |
| 1575 |
* @since 3.0 |
| 1576 |
*/ |
| 1577 |
private static function redirect_after_submit( $args ) { |
| 1578 |
global $frm_vars; |
| 1579 |
|
| 1580 |
add_filter( 'frm_use_wpautop', '__return_false' ); |
| 1581 |
|
| 1582 |
$opt = $args['success_opt']; |
| 1583 |
$success_url = trim( $args['form']->options[ $opt . '_url' ] ); |
| 1584 |
$success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] ); |
| 1585 |
$success_url = do_shortcode( $success_url ); |
| 1586 |
|
| 1587 |
$success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' ); |
| 1588 |
|
| 1589 |
$redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args ); |
| 1590 |
|
| 1591 |
$args['id'] = $args['entry_id']; |
| 1592 |
FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args ); |
| 1593 |
|
| 1594 |
add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' ); |
| 1595 |
$success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 1596 |
|
| 1597 |
$doing_ajax = FrmAppHelper::doing_ajax(); |
| 1598 |
|
| 1599 |
if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) { |
| 1600 |
echo json_encode( array( 'redirect' => $success_url ) ); |
| 1601 |
wp_die(); |
| 1602 |
} elseif ( ! headers_sent() ) { |
| 1603 |
wp_redirect( esc_url_raw( $success_url ) ); |
| 1604 |
die(); // do not use wp_die or redirect fails |
| 1605 |
} else { |
| 1606 |
add_filter( 'frm_use_wpautop', '__return_true' ); |
| 1607 |
|
| 1608 |
echo $redirect_msg; // WPCS: XSS ok. |
| 1609 |
echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>"; |
| 1610 |
} |
| 1611 |
} |
| 1612 |
|
| 1613 |
/** |
| 1614 |
* @since 3.0 |
| 1615 |
* @param string $success_url |
| 1616 |
* @param string $success_msg |
| 1617 |
* @param array $args |
| 1618 |
*/ |
| 1619 |
private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 1620 |
$redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' . |
| 1621 |
sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) . |
| 1622 |
'</div></div>'; |
| 1623 |
|
| 1624 |
$redirect_args = array( |
| 1625 |
'entry_id' => $args['entry_id'], |
| 1626 |
'form_id' => $args['form']->id, |
| 1627 |
'form' => $args['form'], |
| 1628 |
); |
| 1629 |
return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args ); |
| 1630 |
} |
| 1631 |
|
| 1632 |
/** |
| 1633 |
* Prepare to show the success message and empty form after submit |
| 1634 |
* |
| 1635 |
* @since 2.05 |
| 1636 |
*/ |
| 1637 |
public static function show_message_after_save( $atts ) { |
| 1638 |
$atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] ); |
| 1639 |
|
| 1640 |
if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) { |
| 1641 |
self::show_form_after_submit( $atts ); |
| 1642 |
} else { |
| 1643 |
self::show_lone_success_messsage( $atts ); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
|
| 1647 |
/** |
| 1648 |
* Show an empty form |
| 1649 |
* |
| 1650 |
* @since 2.05 |
| 1651 |
*/ |
| 1652 |
private static function show_form_after_submit( $args ) { |
| 1653 |
self::fill_atts_for_form_display( $args ); |
| 1654 |
|
| 1655 |
$errors = $args['errors']; |
| 1656 |
$message = $args['message']; |
| 1657 |
$form = $args['form']; |
| 1658 |
$title = $args['title']; |
| 1659 |
$description = $args['description']; |
| 1660 |
|
| 1661 |
if ( empty( $args['fields'] ) ) { |
| 1662 |
$values = array(); |
| 1663 |
} else { |
| 1664 |
$values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] ); |
| 1665 |
} |
| 1666 |
unset( $args ); |
| 1667 |
|
| 1668 |
$include_form_tag = apply_filters( 'frm_include_form_tag', true, $form ); |
| 1669 |
|
| 1670 |
$frm_settings = FrmAppHelper::get_settings(); |
| 1671 |
$submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value; |
| 1672 |
|
| 1673 |
include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
| 1674 |
} |
| 1675 |
|
| 1676 |
/** |
| 1677 |
* Get all the values needed on the new.php entry page |
| 1678 |
* |
| 1679 |
* @since 2.05 |
| 1680 |
*/ |
| 1681 |
private static function fill_atts_for_form_display( &$args ) { |
| 1682 |
$defaults = array( |
| 1683 |
'errors' => array(), |
| 1684 |
'message' => '', |
| 1685 |
'fields' => array(), |
| 1686 |
'form' => array(), |
| 1687 |
'title' => true, |
| 1688 |
'description' => false, |
| 1689 |
'reset' => false, |
| 1690 |
); |
| 1691 |
$args = wp_parse_args( $args, $defaults ); |
| 1692 |
} |
| 1693 |
|
| 1694 |
/** |
| 1695 |
* Show the success message without the form |
| 1696 |
* |
| 1697 |
* @since 2.05 |
| 1698 |
*/ |
| 1699 |
private static function show_lone_success_messsage( $atts ) { |
| 1700 |
global $frm_vars; |
| 1701 |
$values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true ); |
| 1702 |
self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] ); |
| 1703 |
|
| 1704 |
$include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values ); |
| 1705 |
$errors = array(); |
| 1706 |
$form = $atts['form']; |
| 1707 |
$message = $atts['message']; |
| 1708 |
|
| 1709 |
include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); |
| 1710 |
} |
| 1711 |
|
| 1712 |
/** |
| 1713 |
* Prepare the success message before it's shown |
| 1714 |
* |
| 1715 |
* @since 2.05 |
| 1716 |
*/ |
| 1717 |
private static function prepare_submit_message( $form, $entry_id ) { |
| 1718 |
$frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) ); |
| 1719 |
|
| 1720 |
if ( $entry_id && is_numeric( $entry_id ) ) { |
| 1721 |
$message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg; |
| 1722 |
$class = 'frm_message'; |
| 1723 |
} else { |
| 1724 |
$message = $frm_settings->failed_msg; |
| 1725 |
$class = FrmFormsHelper::form_error_class(); |
| 1726 |
} |
| 1727 |
|
| 1728 |
$message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) ); |
| 1729 |
return apply_filters( 'frm_main_feedback', $message, $form, $entry_id ); |
| 1730 |
} |
| 1731 |
|
| 1732 |
public static function front_head() { |
| 1733 |
$version = FrmAppHelper::plugin_version(); |
| 1734 |
$suffix = FrmAppHelper::js_suffix(); |
| 1735 |
|
| 1736 |
if ( ! empty( $suffix ) && self::has_combo_js_file() ) { |
| 1737 |
wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true ); |
| 1738 |
} else { |
| 1739 |
wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true ); |
| 1740 |
} |
| 1741 |
|
| 1742 |
add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 ); |
| 1743 |
|
| 1744 |
if ( FrmAppHelper::is_admin() ) { |
| 1745 |
// don't load this in back-end |
| 1746 |
return; |
| 1747 |
} |
| 1748 |
|
| 1749 |
FrmAppHelper::localize_script( 'front' ); |
| 1750 |
FrmStylesController::enqueue_css( 'register' ); |
| 1751 |
} |
| 1752 |
|
| 1753 |
/** |
| 1754 |
* @since 3.0 |
| 1755 |
*/ |
| 1756 |
public static function has_combo_js_file() { |
| 1757 |
return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' ); |
| 1758 |
} |
| 1759 |
|
| 1760 |
public static function maybe_load_css( $form, $this_load, $global_load ) { |
| 1761 |
$load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load ); |
| 1762 |
|
| 1763 |
if ( $load_css ) { |
| 1764 |
global $frm_vars; |
| 1765 |
self::footer_js( 'header' ); |
| 1766 |
$frm_vars['css_loaded'] = true; |
| 1767 |
} |
| 1768 |
} |
| 1769 |
|
| 1770 |
public static function defer_script_loading( $tag, $handle ) { |
| 1771 |
if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) { |
| 1772 |
$tag = str_replace( ' src', ' defer="defer" async="async" src', $tag ); |
| 1773 |
} |
| 1774 |
return $tag; |
| 1775 |
} |
| 1776 |
|
| 1777 |
public static function footer_js( $location = 'footer' ) { |
| 1778 |
global $frm_vars; |
| 1779 |
|
| 1780 |
FrmStylesController::enqueue_css(); |
| 1781 |
|
| 1782 |
if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { |
| 1783 |
//load formidable js |
| 1784 |
wp_enqueue_script( 'formidable' ); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
|
| 1788 |
/** |
| 1789 |
* @since 2.0.8 |
| 1790 |
*/ |
| 1791 |
private static function maybe_minimize_form( $atts, &$content ) { |
| 1792 |
// check if minimizing is turned on |
| 1793 |
if ( self::is_minification_on( $atts ) ) { |
| 1794 |
$content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content ); |
| 1795 |
} |
| 1796 |
} |
| 1797 |
|
| 1798 |
/** |
| 1799 |
* @since 2.0.8 |
| 1800 |
* @return boolean |
| 1801 |
*/ |
| 1802 |
private static function is_minification_on( $atts ) { |
| 1803 |
return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ); |
| 1804 |
} |
| 1805 |
|
| 1806 |
/** |
| 1807 |
* @deprecated 1.07.05 |
| 1808 |
* @codeCoverageIgnore |
| 1809 |
*/ |
| 1810 |
public static function add_default_templates( $path, $default = true, $template = true ) { |
| 1811 |
FrmDeprecated::add_default_templates( $path, $default, $template ); |
| 1812 |
} |
| 1813 |
|
| 1814 |
/** |
| 1815 |
* @deprecated 3.0 |
| 1816 |
* @codeCoverageIgnore |
| 1817 |
*/ |
| 1818 |
public static function bulk_create_template( $ids ) { |
| 1819 |
return FrmDeprecated::bulk_create_template( $ids ); |
| 1820 |
} |
| 1821 |
|
| 1822 |
/** |
| 1823 |
* @deprecated 2.03 |
| 1824 |
* @codeCoverageIgnore |
| 1825 |
*/ |
| 1826 |
public static function register_pro_scripts() { |
| 1827 |
FrmDeprecated::register_pro_scripts(); |
| 1828 |
} |
| 1829 |
|
| 1830 |
/** |
| 1831 |
* @deprecated 3.0 |
| 1832 |
* @codeCoverageIgnore |
| 1833 |
*/ |
| 1834 |
public static function edit_key() { |
| 1835 |
FrmDeprecated::edit_key(); |
| 1836 |
} |
| 1837 |
|
| 1838 |
/** |
| 1839 |
* @deprecated 3.0 |
| 1840 |
* @codeCoverageIgnore |
| 1841 |
*/ |
| 1842 |
public static function edit_description() { |
| 1843 |
FrmDeprecated::edit_description(); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
|