Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/AJAX/Controll...
File: Submission.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller
[2] Fix | Delete
{
[3] Fix | Delete
protected $_form_data = array();
[4] Fix | Delete
[5] Fix | Delete
protected $_form_cache = array();
[6] Fix | Delete
[7] Fix | Delete
protected $_preview_data = array();
[8] Fix | Delete
[9] Fix | Delete
protected $_form_id = '';
[10] Fix | Delete
[11] Fix | Delete
public function __construct()
[12] Fix | Delete
{
[13] Fix | Delete
if( isset( $_POST[ 'nf_resume' ] ) && isset( $_COOKIE[ 'nf_wp_session' ] ) ){
[14] Fix | Delete
add_action( 'init', array( $this, 'resume' ) );
[15] Fix | Delete
return;
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
if( isset( $_POST['formData'] ) ) {
[19] Fix | Delete
$this->_form_data = json_decode( $_POST['formData'], TRUE );
[20] Fix | Delete
[21] Fix | Delete
// php5.2 fallback
[22] Fix | Delete
if( ! $this->_form_data ) $this->_form_data = json_decode( stripslashes( $_POST['formData'] ), TRUE );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
// Ajax calls here are both handled by 'submit' in this file
[27] Fix | Delete
add_action( 'wp_ajax_nf_ajax_submit', array( $this, 'submit' ) );
[28] Fix | Delete
add_action( 'wp_ajax_nopriv_nf_ajax_submit', array( $this, 'submit' ) );
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Ajax calls here are handled by 'resume' in this file. These calls
[32] Fix | Delete
* are normally made by the application when returning from 'PayPal' or
[33] Fix | Delete
* 'Stripe'.
[34] Fix | Delete
*/
[35] Fix | Delete
add_action( 'wp_ajax_nf_ajax_resume', array( $this, 'resume' ) );
[36] Fix | Delete
add_action( 'wp_ajax_nopriv_nf_ajax_resume', array( $this, 'resume' ) );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function submit()
[40] Fix | Delete
{
[41] Fix | Delete
$nonce_name = 'ninja_forms_display_nonce';
[42] Fix | Delete
/**
[43] Fix | Delete
* We've got to get the 'nonce_ts' to append to the nonce name to get
[44] Fix | Delete
* the unique nonce we created
[45] Fix | Delete
* */
[46] Fix | Delete
if( isset( $_REQUEST[ 'nonce_ts' ] ) && 0 < strlen( $_REQUEST[ 'nonce_ts' ] ) ) {
[47] Fix | Delete
$nonce_name = $nonce_name . "_" . $_REQUEST[ 'nonce_ts' ];
[48] Fix | Delete
}
[49] Fix | Delete
$check_ajax_referer = check_ajax_referer( $nonce_name, 'security', $die = false );
[50] Fix | Delete
if(!$check_ajax_referer){
[51] Fix | Delete
/**
[52] Fix | Delete
* "Just in Time Nonce".
[53] Fix | Delete
* If the nonce fails, then send back a new nonce for the form to resubmit.
[54] Fix | Delete
* This supports the edge-case of 11:59:59 form submissions, while avoiding the form load nonce request.
[55] Fix | Delete
*/
[56] Fix | Delete
[57] Fix | Delete
$current_time_stamp = time();
[58] Fix | Delete
$new_nonce_name = 'ninja_forms_display_nonce_' . $current_time_stamp;
[59] Fix | Delete
$this->_errors['nonce'] = array(
[60] Fix | Delete
'new_nonce' => wp_create_nonce( $new_nonce_name ),
[61] Fix | Delete
'nonce_ts' => $current_time_stamp
[62] Fix | Delete
);
[63] Fix | Delete
$this->_respond();
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
register_shutdown_function( array( $this, 'shutdown' ) );
[67] Fix | Delete
[68] Fix | Delete
$this->form_data_check();
[69] Fix | Delete
[70] Fix | Delete
$this->_form_id = $this->_form_data['id'];
[71] Fix | Delete
[72] Fix | Delete
/* Render Instance Fix */
[73] Fix | Delete
if(strpos($this->_form_id, '_')){
[74] Fix | Delete
$this->_form_instance_id = $this->_form_id;
[75] Fix | Delete
list($this->_form_id, $this->_instance_id) = explode('_', $this->_form_id);
[76] Fix | Delete
$updated_fields = array();
[77] Fix | Delete
foreach($this->_form_data['fields'] as $field_id => $field ){
[78] Fix | Delete
list($field_id) = explode('_', $field_id);
[79] Fix | Delete
list($field['id']) = explode('_', $field['id']);
[80] Fix | Delete
$updated_fields[$field_id] = $field;
[81] Fix | Delete
}
[82] Fix | Delete
$this->_form_data['fields'] = $updated_fields;
[83] Fix | Delete
}
[84] Fix | Delete
/* END Render Instance Fix */
[85] Fix | Delete
[86] Fix | Delete
// If we don't have a numeric form ID...
[87] Fix | Delete
if ( ! is_numeric( $this->_form_id ) ) {
[88] Fix | Delete
// Kick the request out without processing.
[89] Fix | Delete
$this->_errors[] = esc_html__( 'Form does not exist.', 'ninja-forms' );
[90] Fix | Delete
$this->_respond();
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
// Check to see if our form is maintenance mode.
[94] Fix | Delete
$is_maintenance = WPN_Helper::form_in_maintenance( $this->_form_id );
[95] Fix | Delete
[96] Fix | Delete
/*
[97] Fix | Delete
* If our form is in maintenance mode then, stop processing and throw an error with a link
[98] Fix | Delete
* back to the form.
[99] Fix | Delete
*/
[100] Fix | Delete
if ( $is_maintenance ) {
[101] Fix | Delete
$message = sprintf(
[102] Fix | Delete
esc_html__( 'This form is currently undergoing maintenance. Please %sclick here%s to reload the form and try again.', 'ninja-forms' )
[103] Fix | Delete
,'<a href="' . $_SERVER[ 'HTTP_REFERER' ] . '">', '</a>'
[104] Fix | Delete
);
[105] Fix | Delete
$this->_errors[ 'form' ][] = apply_filters( 'nf_maintenance_message', $message ) ;
[106] Fix | Delete
$this->_respond();
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
if( $this->is_preview() ) {
[110] Fix | Delete
[111] Fix | Delete
$this->_form_cache = get_user_option( 'nf_form_preview_' . $this->_form_id );
[112] Fix | Delete
[113] Fix | Delete
if( ! $this->_form_cache ){
[114] Fix | Delete
$this->_errors[ 'preview' ] = esc_html__( 'Preview does not exist.', 'ninja-forms' );
[115] Fix | Delete
$this->_respond();
[116] Fix | Delete
}
[117] Fix | Delete
} else {
[118] Fix | Delete
if( WPN_Helper::use_cache() ) {
[119] Fix | Delete
$this->_form_cache = WPN_Helper::get_nf_cache( $this->_form_id );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
// Add Field Keys to _form_data
[125] Fix | Delete
if(! $this->is_preview()){
[126] Fix | Delete
[127] Fix | Delete
// Make sure we don't have any field ID mismatches.
[128] Fix | Delete
foreach( $this->_form_data[ 'fields' ] as $id => $settings ){
[129] Fix | Delete
if( $id != $settings[ 'id' ] ){
[130] Fix | Delete
$this->_errors[ 'fields' ][ $id ] = esc_html__( 'The submitted data is invalid.', 'ninja-forms' );
[131] Fix | Delete
$this->_respond();
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
$form_fields = Ninja_Forms()->form($this->_form_id)->get_fields();
[136] Fix | Delete
foreach ($form_fields as $id => $field) {
[137] Fix | Delete
$this->_form_data['fields'][$id]['key'] = $field->get_setting('key');
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
// TODO: Update Conditional Logic to preserve field ID => [ Settings, ID ] structure.
[142] Fix | Delete
$this->_form_data = apply_filters( 'ninja_forms_submit_data', $this->_form_data );
[143] Fix | Delete
[144] Fix | Delete
$this->process();
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
public function resume()
[148] Fix | Delete
{
[149] Fix | Delete
$this->_form_data = Ninja_Forms()->session()->get( 'nf_processing_form_data' );
[150] Fix | Delete
$this->_form_cache = Ninja_Forms()->session()->get( 'nf_processing_form_cache' );
[151] Fix | Delete
$this->_data = Ninja_Forms()->session()->get( 'nf_processing_data' );
[152] Fix | Delete
$this->_data[ 'resume' ] = WPN_Helper::sanitize_text_field($_POST[ 'nf_resume' ]);
[153] Fix | Delete
[154] Fix | Delete
$this->_form_id = $this->_data[ 'form_id' ];
[155] Fix | Delete
[156] Fix | Delete
unset( $this->_data[ 'halt' ] );
[157] Fix | Delete
unset( $this->_data[ 'actions' ][ 'redirect' ] );
[158] Fix | Delete
[159] Fix | Delete
$this->process();
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
protected function process()
[163] Fix | Delete
{
[164] Fix | Delete
// Init Field Merge Tags.
[165] Fix | Delete
$field_merge_tags = Ninja_Forms()->merge_tags[ 'fields' ];
[166] Fix | Delete
$field_merge_tags->set_form_id( $this->_form_id );
[167] Fix | Delete
[168] Fix | Delete
// Init Calc Merge Tags.
[169] Fix | Delete
$calcs_merge_tags = Ninja_Forms()->merge_tags[ 'calcs' ];
[170] Fix | Delete
[171] Fix | Delete
if(isset($this->_form_cache[ 'settings' ] ) ) {
[172] Fix | Delete
$form_settings = $this->_form_cache[ 'settings' ];
[173] Fix | Delete
} else {
[174] Fix | Delete
$form_settings = false;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
if( ! $form_settings ){
[178] Fix | Delete
$form = Ninja_Forms()->form( $this->_form_id )->get();
[179] Fix | Delete
$form_settings = $form->get_settings();
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// Init Form Merge Tags.
[183] Fix | Delete
$form_merge_tags = Ninja_Forms()->merge_tags[ 'form' ];
[184] Fix | Delete
$form_merge_tags->set_form_id( $this->_form_id );
[185] Fix | Delete
$form_merge_tags->set_form_title( $form_settings['title'] );
[186] Fix | Delete
[187] Fix | Delete
$this->_data[ 'form_id' ] = $this->_form_data[ 'form_id' ] = $this->_form_id;
[188] Fix | Delete
$this->_data[ 'settings' ] = $form_settings;
[189] Fix | Delete
$this->_data[ 'settings' ][ 'is_preview' ] = $this->is_preview();
[190] Fix | Delete
[191] Fix | Delete
$this->maybePreserveExtraData();
[192] Fix | Delete
$this->_data[ 'extra' ] = $this->_form_data[ 'extra' ];
[193] Fix | Delete
[194] Fix | Delete
/*
[195] Fix | Delete
|--------------------------------------------------------------------------
[196] Fix | Delete
| Fields
[197] Fix | Delete
|--------------------------------------------------------------------------
[198] Fix | Delete
*/
[199] Fix | Delete
[200] Fix | Delete
if( $this->is_preview() ){
[201] Fix | Delete
$form_fields = $this->_form_cache[ 'fields' ];
[202] Fix | Delete
} else {
[203] Fix | Delete
$form_fields = Ninja_Forms()->form($this->_form_id)->get_fields();
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* The Field Processing Loop.
[208] Fix | Delete
*
[209] Fix | Delete
* There can only be one!
[210] Fix | Delete
* For performance reasons, this should be the only time that the fields array is traversed.
[211] Fix | Delete
* Anything needing to loop through fields should integrate here.
[212] Fix | Delete
*/
[213] Fix | Delete
$validate_fields = apply_filters( 'ninja_forms_validate_fields', true, $this->_data );
[214] Fix | Delete
foreach( $form_fields as $key => $field ){
[215] Fix | Delete
[216] Fix | Delete
if( is_object( $field ) ) {
[217] Fix | Delete
[218] Fix | Delete
//Process Merge tags on Repeater fields values
[219] Fix | Delete
if( $field->get_setting('type' )=== "repeater" ){
[220] Fix | Delete
$this->process_repeater_fields_merge_tags( $field );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
$field = array(
[224] Fix | Delete
'id' => $field->get_id(),
[225] Fix | Delete
'settings' => $field->get_settings()
[226] Fix | Delete
);
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/** Get the field ID */
[230] Fix | Delete
/*
[231] Fix | Delete
* TODO: Refactor data structures to match.
[232] Fix | Delete
* Preview: Field IDs are stored as the associated array key.
[233] Fix | Delete
* Publish: Field IDs are stored as an array key=>value pair.
[234] Fix | Delete
*/
[235] Fix | Delete
if( $this->is_preview() ){
[236] Fix | Delete
$field[ 'id' ] = $key;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
// Duplicate field ID as single variable for more readable array access.
[240] Fix | Delete
$field_id = $field[ 'id' ];
[241] Fix | Delete
[242] Fix | Delete
// Check that the field ID exists in the submitted for data and has a submitted value.
[243] Fix | Delete
if( isset( $this->_form_data[ 'fields' ][ $field_id ] ) && isset( $this->_form_data[ 'fields' ][ $field_id ][ 'value' ] ) ){
[244] Fix | Delete
$field[ 'value' ] = $this->_form_data[ 'fields' ][ $field_id ][ 'value' ];
[245] Fix | Delete
} else {
[246] Fix | Delete
$field[ 'value' ] = '';
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
// Duplicate field value to settings and top level array item for backwards compatible access (ie Save Action).
[250] Fix | Delete
$field[ 'settings' ][ 'value' ] = $field[ 'value' ];
[251] Fix | Delete
[252] Fix | Delete
// Duplicate field value to form cache for passing to the action filter.
[253] Fix | Delete
$this->_form_cache[ 'fields' ][ $key ][ 'settings' ][ 'value' ] = $this->_form_data[ 'fields' ][ $field_id ][ 'value' ];
[254] Fix | Delete
[255] Fix | Delete
// Duplicate the Field ID for access as a setting.
[256] Fix | Delete
$field[ 'settings' ][ 'id' ] = $field[ 'id' ];
[257] Fix | Delete
[258] Fix | Delete
// Combine with submitted data.
[259] Fix | Delete
$field = array_merge( $field, $this->_form_data[ 'fields' ][ $field_id ] );
[260] Fix | Delete
[261] Fix | Delete
// Flatten the field array.
[262] Fix | Delete
$field = array_merge( $field, $field[ 'settings' ] );
[263] Fix | Delete
[264] Fix | Delete
/** Prepare Fields in repeater for Validation and Process */
[265] Fix | Delete
if( $field["type"] === "repeater" ){
[266] Fix | Delete
foreach( $field["value"] as $index => $child_field_value ){
[267] Fix | Delete
foreach( $field['fields'] as $i => $child_field ) {
[268] Fix | Delete
if(strpos($index, $child_field['id']) !== false){
[269] Fix | Delete
$field['value'][$index] = array_merge($child_field, $child_field_value);
[270] Fix | Delete
}
[271] Fix | Delete
}
[272] Fix | Delete
}
[273] Fix | Delete
}
[274] Fix | Delete
/** Validate the Field */
[275] Fix | Delete
if( $validate_fields && ! isset( $this->_data[ 'resume' ] ) ){
[276] Fix | Delete
if( $field["type"] === "repeater" ){
[277] Fix | Delete
foreach( $field["value"] as $index => $child_field ){
[278] Fix | Delete
$this->validate_field( $field["value"][$index] );
[279] Fix | Delete
}
[280] Fix | Delete
} else {
[281] Fix | Delete
$this->validate_field( $field );
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/** Process the Field */
[287] Fix | Delete
if( ! isset( $this->_data[ 'resume' ] ) ) {
[288] Fix | Delete
if( $field["type"] === "repeater" ){
[289] Fix | Delete
foreach( $field["value"] as $index => $child_field ){
[290] Fix | Delete
$this->process_field( $field["value"][$index] );
[291] Fix | Delete
}
[292] Fix | Delete
} else {
[293] Fix | Delete
$this->process_field($field);
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
$field = array_merge( $field, $this->_form_data[ 'fields' ][ $field_id ] );
[297] Fix | Delete
[298] Fix | Delete
// Check for field errors after processing.
[299] Fix | Delete
if ( isset( $this->_form_data['errors']['fields'][ $field_id ] ) ) {
[300] Fix | Delete
$this->_errors['fields'][ $field_id ] = $this->_form_data['errors']['fields'][ $field_id ];
[301] Fix | Delete
$this->_respond();
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/** Populate Field Merge Tag */
[305] Fix | Delete
$field_merge_tags->add_field( $field );
[306] Fix | Delete
[307] Fix | Delete
$this->_data[ 'fields' ][ $field_id ] = $field;
[308] Fix | Delete
$this->_data[ 'fields_by_key' ][ $field[ 'key' ] ] = $field;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
/*
[312] Fix | Delete
|--------------------------------------------------------------------------
[313] Fix | Delete
| Check for unique field settings.
[314] Fix | Delete
|--------------------------------------------------------------------------
[315] Fix | Delete
*/
[316] Fix | Delete
if ( isset( $this->_data[ 'resume' ] ) && $this->_data[ 'resume' ] ){
[317] Fix | Delete
// On Resume Submission, we don't need to run this check again.
[318] Fix | Delete
// This section intentionally left blank.
[319] Fix | Delete
} elseif ( isset ( $this->_data[ 'settings' ][ 'unique_field' ] ) && ! empty( $this->_data[ 'settings' ][ 'unique_field' ] ) ) {
[320] Fix | Delete
/*
[321] Fix | Delete
* Get our unique field
[322] Fix | Delete
*/
[323] Fix | Delete
$unique_field_key = $this->_data[ 'settings' ][ 'unique_field' ];
[324] Fix | Delete
$unique_field_error = $this->_data[ 'settings' ][ 'unique_field_error' ];
[325] Fix | Delete
$unique_field_id = $this->_data[ 'fields_by_key' ][ $unique_field_key ][ 'id' ];
[326] Fix | Delete
$unique_field_value = $this->_data[ 'fields_by_key' ][ $unique_field_key ][ 'value' ];
[327] Fix | Delete
if ( is_array( $unique_field_value ) ) {
[328] Fix | Delete
$unique_field_value = serialize( $unique_field_value );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
if ( ! empty($unique_field_value) ) {
[332] Fix | Delete
/*
[333] Fix | Delete
* Check our db for the value submitted.
[334] Fix | Delete
*/
[335] Fix | Delete
[336] Fix | Delete
global $wpdb;
[337] Fix | Delete
// @TODO: Rewrite this to use our submissions API.
[338] Fix | Delete
$sql = $wpdb->prepare( "SELECT COUNT(m.meta_id) FROM `" . $wpdb->prefix . "postmeta` AS m LEFT JOIN `" . $wpdb->prefix . "posts` AS p ON p.id = m.post_id WHERE m.meta_key = '_field_%d' AND m.meta_value = '%s' AND p.post_status = 'publish'", $unique_field_id, $unique_field_value );
[339] Fix | Delete
$result = $wpdb->get_results( $sql, 'ARRAY_N' );
[340] Fix | Delete
if ( intval( $result[ 0 ][ 0 ] ) > 0 ) {
[341] Fix | Delete
$this->_errors['fields'][ $unique_field_id ] = array( 'slug' => 'unique_field', 'message' => $unique_field_error );
[342] Fix | Delete
$this->_respond();
[343] Fix | Delete
}
[344] Fix | Delete
}
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/*
[348] Fix | Delete
|--------------------------------------------------------------------------
[349] Fix | Delete
| Verify the submission limit.
[350] Fix | Delete
|--------------------------------------------------------------------------
[351] Fix | Delete
*/
[352] Fix | Delete
if ( isset( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) && ! empty( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) ) {
[353] Fix | Delete
global $wpdb;
[354] Fix | Delete
$result = $wpdb->get_row( "SELECT COUNT(DISTINCT(p.ID)) AS count FROM `$wpdb->posts` AS p
[355] Fix | Delete
LEFT JOIN `$wpdb->postmeta` AS m
[356] Fix | Delete
ON p.ID = m.post_id
[357] Fix | Delete
WHERE m.meta_key = '_form_id'
[358] Fix | Delete
AND m.meta_value = $this->_form_id
[359] Fix | Delete
AND p.post_status = 'publish'");
[360] Fix | Delete
if ( intval( $result->count ) >= intval( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) ) {
[361] Fix | Delete
$this->_errors[ 'form' ][] = $this->_data[ 'settings' ][ 'sub_limit_msg' ];
[362] Fix | Delete
$this->_respond();
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
/*
[367] Fix | Delete
|--------------------------------------------------------------------------
[368] Fix | Delete
| Calculations
[369] Fix | Delete
|--------------------------------------------------------------------------
[370] Fix | Delete
*/
[371] Fix | Delete
[372] Fix | Delete
if( isset( $this->_form_cache[ 'settings' ][ 'calculations' ] ) ) {
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* The Calculation Processing Loop
[376] Fix | Delete
*/
[377] Fix | Delete
foreach( $this->_form_cache[ 'settings' ][ 'calculations' ] as $calc ){
[378] Fix | Delete
$eq = apply_filters( 'ninja_forms_calc_setting', $calc[ 'eq' ] );
[379] Fix | Delete
[380] Fix | Delete
// Scrub unmerged tags (ie deleted/non-existent fields/calcs, etc).
[381] Fix | Delete
$eq = preg_replace( '/{([a-zA-Z0-9]|:|_|-)*}/', 0, $eq);
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* PHP doesn't evaluate empty strings to numbers. So check
[385] Fix | Delete
* for any string for the decimal place
[386] Fix | Delete
**/
[387] Fix | Delete
$dec = ( isset( $calc[ 'dec' ] ) && '' != $calc[ 'dec' ] ) ?
[388] Fix | Delete
$calc[ 'dec' ] : 2;
[389] Fix | Delete
[390] Fix | Delete
$calcs_merge_tags->set_merge_tags( $calc[ 'name' ], $eq, $dec, $this->_form_data['settings']['decimal_point'], $this->_form_data['settings']['thousands_sep'] );
[391] Fix | Delete
$this->_data[ 'extra' ][ 'calculations' ][ $calc[ 'name' ] ] = array(
[392] Fix | Delete
'raw' => $calc[ 'eq' ],
[393] Fix | Delete
'parsed' => $eq,
[394] Fix | Delete
'value' => $calcs_merge_tags->get_formatted_calc_value( $calc[ 'name' ], $dec, $this->_form_data['settings']['decimal_point'], $this->_form_data['settings']['thousands_sep'] ),
[395] Fix | Delete
);
[396] Fix | Delete
}
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
[400] Fix | Delete
/*
[401] Fix | Delete
|--------------------------------------------------------------------------
[402] Fix | Delete
| Actions
[403] Fix | Delete
|--------------------------------------------------------------------------
[404] Fix | Delete
*/
[405] Fix | Delete
[406] Fix | Delete
/*
[407] Fix | Delete
* TODO: This section has become convoluted, but will be refactored along with the submission controller.
[408] Fix | Delete
*/
[409] Fix | Delete
[410] Fix | Delete
if( isset( $this->_data[ 'resume' ] ) && $this->_data[ 'resume' ] ){
[411] Fix | Delete
// On Resume Submission, the action data is loaded form the session.
[412] Fix | Delete
// This section intentionally left blank.
[413] Fix | Delete
} elseif( ! $this->is_preview() ) {
[414] Fix | Delete
// Published forms rely on the Database for the "truth" about Actions.
[415] Fix | Delete
$actions = Ninja_Forms()->form($this->_form_id)->get_actions();
[416] Fix | Delete
$this->_form_cache[ 'actions' ] = array();
[417] Fix | Delete
foreach( $actions as $action ){
[418] Fix | Delete
$action_id = $action->get_id();
[419] Fix | Delete
$this->_form_cache[ 'actions' ][ $action_id ] = array(
[420] Fix | Delete
'id' => $action_id,
[421] Fix | Delete
'settings' => $action->get_settings()
[422] Fix | Delete
);
[423] Fix | Delete
}
[424] Fix | Delete
} else {
[425] Fix | Delete
// Previews uses user option for stored data.
[426] Fix | Delete
$preview_data = get_user_option( 'nf_form_preview_' . $this->_form_id );
[427] Fix | Delete
$this->_form_cache[ 'actions' ] = $preview_data[ 'actions' ];
[428] Fix | Delete
}
[429] Fix | Delete
/* END form cache bypass. */
[430] Fix | Delete
[431] Fix | Delete
// Sort Actions by Timing Order, then by Priority Order.
[432] Fix | Delete
usort( $this->_form_cache[ 'actions' ], array( $this, 'sort_form_actions' ) );
[433] Fix | Delete
[434] Fix | Delete
/*
[435] Fix | Delete
* Filter Actions so that they can be pragmatically disabled by add-ons.
[436] Fix | Delete
*
[437] Fix | Delete
* ninja_forms_submission_actions
[438] Fix | Delete
* ninja_forms_submission_actions_preview
[439] Fix | Delete
*/
[440] Fix | Delete
$this->_form_cache[ 'actions' ] = apply_filters( 'ninja_forms_submission_actions', $this->_form_cache[ 'actions' ], $this->_form_cache, $this->_form_data );
[441] Fix | Delete
if( $this->is_preview() ) {
[442] Fix | Delete
$this->_form_cache['actions'] = apply_filters('ninja_forms_submission_actions_preview', $this->_form_cache['actions'], $this->_form_cache);
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
// Initialize the process actions log.
[446] Fix | Delete
if( ! isset( $this->_data[ 'processed_actions' ] ) ) $this->_data[ 'processed_actions' ] = array();
[447] Fix | Delete
[448] Fix | Delete
/*
[449] Fix | Delete
* Merging extra data that may have been added by fields during processing so that the values aren't lost when we enter the action loop.
[450] Fix | Delete
*/
[451] Fix | Delete
$this->_data[ 'extra' ] = array_merge( $this->_data[ 'extra' ], $this->_form_data[ 'extra' ] );
[452] Fix | Delete
[453] Fix | Delete
/**
[454] Fix | Delete
* The Action Processing Loop
[455] Fix | Delete
*/
[456] Fix | Delete
foreach( $this->_form_cache[ 'actions' ] as $key => $action ){
[457] Fix | Delete
[458] Fix | Delete
/** Get the action ID */
[459] Fix | Delete
/*
[460] Fix | Delete
* TODO: Refactor data structures to match.
[461] Fix | Delete
* Preview: Action IDs are stored as the associated array key.
[462] Fix | Delete
* Publish: Action IDs are stored as an array key=>value pair.
[463] Fix | Delete
*/
[464] Fix | Delete
if( $this->is_preview() ){
[465] Fix | Delete
$action[ 'id' ] = $key;
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
// Duplicate the Action ID for access as a setting.
[469] Fix | Delete
$action[ 'settings' ][ 'id' ] = $action[ 'id' ];
[470] Fix | Delete
[471] Fix | Delete
// Duplicate action ID as single variable for more readable array access.
[472] Fix | Delete
$action_id = $action[ 'id' ];
[473] Fix | Delete
[474] Fix | Delete
// If an action has already run (ie resume submission), do not re-process.
[475] Fix | Delete
if( in_array( $action[ 'id' ], $this->_data[ 'processed_actions' ] ) ) continue;
[476] Fix | Delete
[477] Fix | Delete
$action[ 'settings' ] = apply_filters( 'ninja_forms_run_action_settings', $action[ 'settings' ], $this->_form_id, $action[ 'id' ], $this->_form_data['settings'] );
[478] Fix | Delete
if( $this->is_preview() ){
[479] Fix | Delete
$action[ 'settings' ] = apply_filters( 'ninja_forms_run_action_settings_preview', $action[ 'settings' ], $this->_form_id, $action[ 'id' ], $this->_form_data['settings'] );
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
if( ! $action[ 'settings' ][ 'active' ] ) continue;
[483] Fix | Delete
[484] Fix | Delete
if( ! apply_filters( 'ninja_forms_run_action_type_' . $action[ 'settings' ][ 'type' ], TRUE ) ) continue;
[485] Fix | Delete
[486] Fix | Delete
$type = $action[ 'settings' ][ 'type' ];
[487] Fix | Delete
[488] Fix | Delete
if( ! is_string( $type ) ) continue;
[489] Fix | Delete
[490] Fix | Delete
/*
[491] Fix | Delete
* test if Ninja_Forms()->actions[ $type ] is not empty
[492] Fix | Delete
*/
[493] Fix | Delete
if(isset(Ninja_Forms()->actions[ $type ]))
[494] Fix | Delete
{
[495] Fix | Delete
$action_class = Ninja_Forms()->actions[ $type ];
[496] Fix | Delete
[497] Fix | Delete
if( ! method_exists( $action_class, 'process' ) ) continue;
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function