Commit 829b3cb6 authored by Eric Windham's avatar Eric Windham

resolve merge conflicts

parents 928611ea baa4021b
......@@ -138,7 +138,9 @@ define( ['views/app/drawer/optionRepeaterError'], function( ErrorView ) {
fields.each( function( field ){
var option = document.createElement( 'option' );
option.selected = ( value == field.get( 'key' ) );
if ( value == field.get( 'key' ) ) {
option.setAttribute( 'selected', 'selected' );
}
option.value = field.get( 'key' );
option.label = field.get( 'label' );
select.appendChild( option );
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -81,6 +81,18 @@ define( [ 'views/sections/widgets.js', 'views/sections/apps.js', 'views/sections
var childView = new WidgetView();
}
this.showChildView('content', childView );
// If form telemetry is defined...
// AND if we should run it...
if ( 'undefined' !== typeof nfAdmin.formTelemetry && 1 == nfAdmin.formTelemetry ) {
console.log( 'got here' );
// Make our AJAX call.
var data = {
action: 'nf_form_telemetry',
security: nfAdmin.ajaxNonce
}
// Make our AJAX call.
jQuery.post( ajaxurl, data );
}
},
templateContext: function() {
......
......@@ -9,10 +9,13 @@ class NF_AJAX_Controllers_DispatchPoints
{
// Add out ajax end points.
add_action( 'wp_ajax_nf_undo_click', array( $this, 'undo_click' ) );
add_action( 'wp_ajax_nf_form_telemetry', array( $this, 'form_telemetry' ) );
}
/*
* Function called when the undo manager is used in the builder.
*
* @since 3.2
*/
public function undo_click() {
// Make sure we have a valid nonce.
......@@ -22,4 +25,18 @@ class NF_AJAX_Controllers_DispatchPoints
// Exit.
die( 1 );
}
/*
* Function to startup our form data telemtry.
*
* @since 3.2
*/
public function form_telemetry() {
// Make sure we have a valid nonce.
check_ajax_referer( 'ninja_forms_dashboard_nonce', 'security' );
// Send the action to our dispatcher.
Ninja_Forms()->dispatcher()->form_data();
// Exit.
die( 1 );
}
}
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
exit;
}
/**
* Class NF_Actions_Akismet
*/
final class NF_Actions_Akismet extends NF_Abstracts_Action {
/**
* @var string
*/
protected $_name = 'akismet';
/**
* @var array
*/
protected $_tags = array( 'spam', 'filtering', 'akismet' );
/**
* @var string
*/
protected $_timing = 'normal';
/**
* @var int
*/
protected $_priority = '10';
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->_nicename = __( 'Akismet Anti-Spam', 'ninja-forms' );
$settings = Ninja_Forms::config( 'ActionAkismetSettings' );
$this->_settings = array_merge( $this->_settings, $settings );
add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) );
}
/**
* Remove the action registration if Akismet functions not available.
*
* @param array $action_type_settings
*
* @return array
*/
public function maybe_remove_action( $action_type_settings ) {
if ( ! $this->akismet_available() ) {
unset( $action_type_settings[ $this->_name ] );
}
return $action_type_settings;
}
/**
* Is Akismet installed and connected with a valid key?
*
* @return bool
*/
protected function akismet_available() {
if ( ! is_callable( array( 'Akismet', 'get_api_key' ) ) ) {
// Not installed and activated
return false;
}
$akismet_key = Akismet::get_api_key();
if ( empty( $akismet_key ) ) {
// No key entered
return false;
}
return 'valid' === Akismet::verify_key( $akismet_key );
}
/**
* Process the action
*
* @param array $action_settings
* @param int $form_id
* @param array $data
*
* @return array
*/
public function process( $action_settings, $form_id, $data ) {
if ( ! $this->akismet_available() ) {
return $data;
}
if ( $this->is_submission_spam( $action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'] ) ) {
$data['errors']['form']['spam'] = __( 'There was an error trying to send your message. Please try again later', 'ninja-forms' );
}
return $data;
}
/**
* Verify submission
*
* @param $name
* @param $email
* @param $url
* @param $message
*
* @return bool
*/
protected function is_submission_spam( $name, $email, $url, $message ) {
$body_request = array(
'blog' => get_option( 'home' ),
'blog_lang' => get_locale(),
'permalink' => get_permalink(),
'comment_type' => 'contact-form',
'comment_author' => $name,
'comment_author_email' => $email,
'comment_author_url' => $url,
'comment_content' => $message,
'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null ),
);
if ( method_exists( 'Akismet', 'http_post' ) ) {
$body_request['user_ip'] = Akismet::get_ip_address();
$response = Akismet::http_post( build_query( $body_request ), 'comment-check' );
} else {
global $akismet_api_host, $akismet_api_port;
$body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null );
$response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
}
if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] ) ) {
// Spam!
return true;
}
return false;
}
}
\ No newline at end of file
......@@ -128,6 +128,10 @@ final class NF_Admin_Menus_Forms extends NF_Abstracts_Menu
wp_enqueue_script( 'nf-dashboard', Ninja_Forms::$url . 'assets/js/min/dashboard.min.js', array( 'backbone-radio', 'backbone-marionette-3' ) );
wp_localize_script( 'nf-dashboard', 'nfi18n', Ninja_Forms::config( 'i18nDashboard' ) );
wp_localize_script( 'nf-dashboard', 'nfAdmin', array(
'ajaxNonce' => wp_create_nonce( 'ninja_forms_dashboard_nonce' ),
'formTelemetry' => ( get_option( 'nf_form_tel_sent' ) ) ? 0 : 1
) );
wp_enqueue_style( 'nf-builder', Ninja_Forms::$url . 'assets/css/builder.css' );
wp_enqueue_style( 'nf-dashboard', Ninja_Forms::$url . 'assets/css/dashboard.min.css' );
......
<?php if ( ! defined( 'ABSPATH' ) ) {
exit;
}
return apply_filters( 'ninja_forms_action_akismet_settings', array(
'name' => array(
'name' => 'name',
'type' => 'textbox',
'group' => 'primary',
'label' => __( 'Name', 'ninja-forms' ),
'placeholder' => __( 'Name field', 'ninja-forms' ),
'width' => 'one-half',
'use_merge_tags' => true,
),
'email' => array(
'name' => 'email',
'type' => 'textbox',
'group' => 'primary',
'label' => __( 'Email', 'ninja-forms' ),
'placeholder' => __( 'Email address field', 'ninja-forms' ),
'width' => 'one-half',
'use_merge_tags' => true,
),
'url' => array(
'name' => 'url',
'type' => 'textbox',
'group' => 'primary',
'label' => __( 'URL', 'ninja-forms' ),
'placeholder' => __( 'Field for a URL', 'ninja-forms' ),
'width' => 'one-half',
'use_merge_tags' => true,
),
'message' => array(
'name' => 'message',
'type' => 'textbox',
'group' => 'primary',
'label' => __( 'Message', 'ninja-forms' ),
'placeholder' => __( 'Field for the message', 'ninja-forms' ),
'width' => 'one-half',
'use_merge_tags' => true,
),
) );
\ No newline at end of file
......@@ -91,6 +91,83 @@ final class NF_Dispatcher
$this->send( 'update_environment_vars', $environment );
}
/**
* Package up our form data and send it to our API endpoint.
*
* @since 3.2
* @return void
*/
public function form_data() {
global $wpdb;
// If we have not finished the process...
if ( ! get_option( 'nf_form_tel_sent' ) || 'false' == get_option( 'nf_form_tel_sent' ) ) {
// Get our list of already processed forms (if it exists).
$forms_ref = get_option( 'nf_form_tel_data' );
// Get a list of Forms on this site.
$sql = "SELECT id FROM `" . $wpdb->prefix . "nf3_forms`";
$forms = $wpdb->get_results( $sql, 'ARRAY_A' );
// If our list of processed forms already exists...
if ( ! empty( $forms_ref ) ) {
// Break those into an array.
$forms_ref = explode( ',', $forms_ref );
} // Otherwise...
else {
// Make sure we have an array.
$forms_ref = array();
}
$match_found = false;
// For each form...
foreach ( $forms as $form ) {
// If the current form is not in our list of sent values...
if ( ! in_array( $form[ 'id' ], $forms_ref ) ) {
// Set our target ID.
$id = $form[ 'id' ];
// Record that we found a match.
$match_found = true;
}
}
// If we didn't find a match.
if ( ! $match_found ) {
// Record that we're done.
update_option( 'nf_form_tel_sent', 'true', false );
// Exit.
return false;
}// Otherwise... (We did find a match.)
// Get our form.
$form_data = Ninja_Forms()->form( intval( $id ) )->get();
// Setup our data value.
$data = array();
// Set the form title.
$data[ 'title' ] = $form_data->get_setting( 'title' );
$sql = "SELECT COUNT(meta_id) AS total FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = '_form_id' AND meta_value = '" . intval( $id ) . "'";
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
// Set the number of submissions.
$data[ 'subs' ] = $result[ 0 ][ 'total' ];
// Get our fields.
$field_data = Ninja_Forms()->form( intval( $id ) )->get_fields();
$data[ 'fields' ] = array();
// For each field on the form...
foreach ( $field_data as $field ) {
// Add that data to our array.
$data[ 'fields' ][] = $field->get_setting( 'type' );
}
// Get our actions.
$action_data = Ninja_Forms()->form( intval( $id ) )->get_actions();
$data[ 'actions' ] = array();
// For each action on the form...
foreach ( $action_data as $action ) {
// Add that data to our array.
$data[ 'actions' ][] = $action->get_setting( 'type' );
}
// Add this form ID to our option.
$forms_ref[] = $id;
// Update our option.
update_option( 'nf_form_tel_data', implode( ',', $forms_ref ), false );
$this->send( 'form_data', $data );
}
}
/**
* Sends a campaign slug and data to our API endpoint.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment