Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../includes
File: Dispatcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Handles sending information to our api.ninjaforms.com endpoint.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 3.2
[5] Fix | Delete
*/
[6] Fix | Delete
final class NF_Dispatcher
[7] Fix | Delete
{
[8] Fix | Delete
private $api_url = 'http://api.ninjaforms.com/';
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Returns bool true if we are opted-in or have a premium add-on.
[12] Fix | Delete
* If a premium add-on is installed, then users have opted into tracked via our terms and conditions.
[13] Fix | Delete
* If no premium add-ons are installed, check to see if the user has opted in or out of anonymous usage tracking.
[14] Fix | Delete
*
[15] Fix | Delete
* @since version
[16] Fix | Delete
* @return bool
[17] Fix | Delete
*/
[18] Fix | Delete
public function should_we_send() {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* TODO:
[22] Fix | Delete
* Prevent certain URLS or IPs from submitting. i.e. staging, 127.0.0.1, localhost, etc.
[23] Fix | Delete
*/
[24] Fix | Delete
[25] Fix | Delete
if ( ! has_filter( 'ninja_forms_settings_licenses_addons' ) && ( ! Ninja_Forms()->tracking->is_opted_in() || Ninja_Forms()->tracking->is_opted_out() ) ) {
[26] Fix | Delete
return false;
[27] Fix | Delete
}
[28] Fix | Delete
return true;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Package up our environment variables and send those to our API endpoint.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 3.2
[35] Fix | Delete
* @return void
[36] Fix | Delete
*
[37] Fix | Delete
* @updated 3.3.17
[38] Fix | Delete
*/
[39] Fix | Delete
public function update_environment_vars() {
[40] Fix | Delete
global $wpdb;
[41] Fix | Delete
[42] Fix | Delete
// Plugins
[43] Fix | Delete
$active_plugins = (array) get_option( 'active_plugins', array() );
[44] Fix | Delete
[45] Fix | Delete
//WP_DEBUG
[46] Fix | Delete
if ( defined('WP_DEBUG') && WP_DEBUG ){
[47] Fix | Delete
$debug = 1;
[48] Fix | Delete
} else {
[49] Fix | Delete
$debug = 0;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
//WPLANG
[53] Fix | Delete
if ( defined( 'WPLANG' ) && WPLANG ) {
[54] Fix | Delete
$lang = WPLANG;
[55] Fix | Delete
} else {
[56] Fix | Delete
$lang = 'default';
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
$ip_address = '';
[60] Fix | Delete
if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
[61] Fix | Delete
$ip_address = $_SERVER[ 'SERVER_ADDR' ];
[62] Fix | Delete
} else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
[63] Fix | Delete
$ip_address = $_SERVER[ 'LOCAL_ADDR' ];
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
// If we have a valid IP Address...
[67] Fix | Delete
if ( filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
[68] Fix | Delete
// Get the hostname.
[69] Fix | Delete
$host_name = gethostbyaddr( $ip_address );
[70] Fix | Delete
} else {
[71] Fix | Delete
$host_name = 'unknown';
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
if ( is_multisite() ) {
[75] Fix | Delete
$multisite_enabled = 1;
[76] Fix | Delete
} else {
[77] Fix | Delete
$multisite_enabled = 0;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$environment = array(
[81] Fix | Delete
'nf_version' => Ninja_Forms::VERSION,
[82] Fix | Delete
'nf_db_version' => get_option( 'ninja_forms_db_version', '1.0' ),
[83] Fix | Delete
'wp_version' => get_bloginfo('version'),
[84] Fix | Delete
'multisite_enabled' => $multisite_enabled,
[85] Fix | Delete
'server_type' => $_SERVER['SERVER_SOFTWARE'],
[86] Fix | Delete
'php_version' => phpversion(),
[87] Fix | Delete
'mysql_version' => $wpdb->db_version(),
[88] Fix | Delete
'wp_memory_limit' => WP_MEMORY_LIMIT,
[89] Fix | Delete
'wp_debug_mode' => $debug,
[90] Fix | Delete
'wp_lang' => $lang,
[91] Fix | Delete
'wp_max_upload_size' => size_format( wp_max_upload_size() ),
[92] Fix | Delete
'php_max_post_size' => ini_get( 'post_max_size' ),
[93] Fix | Delete
'hostname' => $host_name,
[94] Fix | Delete
'smtp' => ini_get('SMTP'),
[95] Fix | Delete
'smtp_port' => ini_get('smtp_port'),
[96] Fix | Delete
'active_plugins' => $active_plugins,
[97] Fix | Delete
);
[98] Fix | Delete
[99] Fix | Delete
$this->send( 'update_environment_vars', $environment );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Package up our form data and send it to our API endpoint.
[104] Fix | Delete
*
[105] Fix | Delete
* @since 3.2
[106] Fix | Delete
* @return void
[107] Fix | Delete
*/
[108] Fix | Delete
public function form_data() {
[109] Fix | Delete
global $wpdb;
[110] Fix | Delete
[111] Fix | Delete
// If we have not finished the process...
[112] Fix | Delete
if ( ! get_option( 'nf_form_tel_sent' ) || 'false' == get_option( 'nf_form_tel_sent' ) ) {
[113] Fix | Delete
// Get our list of already processed forms (if it exists).
[114] Fix | Delete
$forms_ref = get_option( 'nf_form_tel_data' );
[115] Fix | Delete
// Get a list of Forms on this site.
[116] Fix | Delete
$sql = "SELECT id FROM `" . $wpdb->prefix . "nf3_forms`";
[117] Fix | Delete
$forms = $wpdb->get_results( $sql, 'ARRAY_A' );
[118] Fix | Delete
// If our list of processed forms already exists...
[119] Fix | Delete
if ( ! empty( $forms_ref ) ) {
[120] Fix | Delete
// Break those into an array.
[121] Fix | Delete
$forms_ref = explode( ',', $forms_ref );
[122] Fix | Delete
} // Otherwise...
[123] Fix | Delete
else {
[124] Fix | Delete
// Make sure we have an array.
[125] Fix | Delete
$forms_ref = array();
[126] Fix | Delete
}
[127] Fix | Delete
$match_found = false;
[128] Fix | Delete
// For each form...
[129] Fix | Delete
foreach ( $forms as $form ) {
[130] Fix | Delete
// If the current form is not in our list of sent values...
[131] Fix | Delete
if ( ! in_array( $form[ 'id' ], $forms_ref ) ) {
[132] Fix | Delete
// Set our target ID.
[133] Fix | Delete
$id = $form[ 'id' ];
[134] Fix | Delete
// Record that we found a match.
[135] Fix | Delete
$match_found = true;
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
// If we didn't find a match.
[139] Fix | Delete
if ( ! $match_found ) {
[140] Fix | Delete
// Record that we're done.
[141] Fix | Delete
update_option( 'nf_form_tel_sent', 'true', false );
[142] Fix | Delete
// Exit.
[143] Fix | Delete
return false;
[144] Fix | Delete
}// Otherwise... (We did find a match.)
[145] Fix | Delete
// Get our form.
[146] Fix | Delete
$form_data = Ninja_Forms()->form( intval( $id ) )->get();
[147] Fix | Delete
// Setup our data value.
[148] Fix | Delete
$data = array();
[149] Fix | Delete
// Set the form title.
[150] Fix | Delete
$data[ 'title' ] = $form_data->get_setting( 'title' );
[151] Fix | Delete
$sql = "SELECT COUNT(meta_id) AS total FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_form_id' AND meta_value = '" . intval( $id ) . "'";
[152] Fix | Delete
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
[153] Fix | Delete
// Set the number of submissions.
[154] Fix | Delete
$data[ 'subs' ] = $result[ 0 ][ 'total' ];
[155] Fix | Delete
// Get our fields.
[156] Fix | Delete
$field_data = Ninja_Forms()->form( intval( $id ) )->get_fields();
[157] Fix | Delete
$data[ 'fields' ] = array();
[158] Fix | Delete
// For each field on the form...
[159] Fix | Delete
foreach ( $field_data as $field ) {
[160] Fix | Delete
// Add that data to our array.
[161] Fix | Delete
$data[ 'fields' ][] = $field->get_setting( 'type' );
[162] Fix | Delete
}
[163] Fix | Delete
// Get our actions.
[164] Fix | Delete
$action_data = Ninja_Forms()->form( intval( $id ) )->get_actions();
[165] Fix | Delete
$data[ 'actions' ] = array();
[166] Fix | Delete
// For each action on the form...
[167] Fix | Delete
foreach ( $action_data as $action ) {
[168] Fix | Delete
// Add that data to our array.
[169] Fix | Delete
$data[ 'actions' ][] = $action->get_setting( 'type' );
[170] Fix | Delete
}
[171] Fix | Delete
// Add this form ID to our option.
[172] Fix | Delete
$forms_ref[] = $id;
[173] Fix | Delete
// Update our option.
[174] Fix | Delete
update_option( 'nf_form_tel_data', implode( ',', $forms_ref ), false );
[175] Fix | Delete
$this->send( 'form_data', $data );
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Sends a campaign slug and data to our API endpoint.
[181] Fix | Delete
* Checks to ensure that the user has 1) opted into tracking or 2) they have a premium add-on installed.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 3.2
[184] Fix | Delete
* @param string $slug Campaign slug
[185] Fix | Delete
* @param array $data Array of data being sent. Should NOT already be a JSON string.
[186] Fix | Delete
* @return void
[187] Fix | Delete
*/
[188] Fix | Delete
public function send( $slug, $data = array() ) {
[189] Fix | Delete
[190] Fix | Delete
if ( ! $this->should_we_send() ) {
[191] Fix | Delete
return false;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Gather site data before we send.
[196] Fix | Delete
*
[197] Fix | Delete
* We send the following site data with our passed data:
[198] Fix | Delete
* IP Address
[199] Fix | Delete
* Email
[200] Fix | Delete
* Site Url
[201] Fix | Delete
*/
[202] Fix | Delete
[203] Fix | Delete
$ip_address = '';
[204] Fix | Delete
if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
[205] Fix | Delete
$ip_address = $_SERVER[ 'SERVER_ADDR' ];
[206] Fix | Delete
} else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
[207] Fix | Delete
$ip_address = $_SERVER[ 'LOCAL_ADDR' ];
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Email address of the current user.
[212] Fix | Delete
* (if one was provided)
[213] Fix | Delete
*/
[214] Fix | Delete
$email = isset( $data[ 'user_email' ] ) ? $data[ 'user_email' ] : '';
[215] Fix | Delete
[216] Fix | Delete
$site_data = array(
[217] Fix | Delete
'url' => site_url(),
[218] Fix | Delete
'ip_address' => $ip_address,
[219] Fix | Delete
'email' => $email,
[220] Fix | Delete
);
[221] Fix | Delete
[222] Fix | Delete
/*
[223] Fix | Delete
* Send our data using wp_remote_post.
[224] Fix | Delete
*/
[225] Fix | Delete
$response = wp_remote_post(
[226] Fix | Delete
$this->api_url,
[227] Fix | Delete
array(
[228] Fix | Delete
'body' => array(
[229] Fix | Delete
'slug' => $slug,
[230] Fix | Delete
'data' => wp_json_encode( $data ),
[231] Fix | Delete
'site_data' => wp_json_encode( $site_data ),
[232] Fix | Delete
),
[233] Fix | Delete
)
[234] Fix | Delete
);
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function