Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #320 from Codeinwp/development
Browse files Browse the repository at this point in the history
New Gutenberg block for the default Pirate Forms form
Made the checkbox field to store in the database for GDPR compliance
New option to disable tracking of the IP for GDPR compliance
Replaced subscription form with Sendinblue form
  • Loading branch information
rodica-andronache authored Jun 25, 2018
2 parents b4fd815 + 2a3487c commit 296b649
Show file tree
Hide file tree
Showing 33 changed files with 1,692 additions and 314 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module.exports = function (grunt) {
config = config();
config.files.php.push( '!inc/PhpFormBuilder.php' );
config.files.php.push( '!mailin.php' );
config.files.js.push( '!gutenberg/**/*.js' );
config.files.js.push( '!webpack.config.js' );
config.taskMap.faq_builder = 'grunt-helpscout-faq';
loader( grunt, config ).init();
};
22 changes: 21 additions & 1 deletion admin/class-pirateforms-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@ function get_plugin_options() {
'options' => array( 'yes' => __( 'Yes', 'pirate-forms' ) ),
'title' => __( 'According to GDPR, we recommend you to ask for consent in order to store user data.', 'pirate-forms' ),
),
array(
'id' => 'pirateformsopt_store_ip',
'type' => 'checkbox',
'label' => array(
'value' => __( 'Track and store IP of user', 'pirate-forms' ),
'html' => '<span class="dashicons dashicons-editor-help"></span>',
'desc' => array(
'value' => sprintf( '%s<br>%s<br>%s', __( 'Should the IP of the customer be tracked, stored and displayed in the email content?', 'pirate-forms' ), __( 'According to GDPR we recommend you to ask for consent in order to store user data', 'pirate-forms' ), __( 'If this option is not selected, we may not be able to determine whether this is a spam message.', 'pirate-forms' ) ),
'class' => 'pirate_forms_option_description',
),
),
'default' => 'no',
'value' => PirateForms_Util::get_option( 'pirateformsopt_store_ip' ),
'wrap' => array(
'type' => 'div',
'class' => 'pirate-forms-grouped',
),
'options' => array( 'yes' => __( 'Yes', 'pirate-forms' ) ),
'title' => __( 'According to GDPR, we recommend you to ask for consent in order to store user data.', 'pirate-forms' ),
),
array(
'id' => 'pirateformsopt_nonce',
'type' => 'checkbox',
Expand Down Expand Up @@ -678,7 +698,7 @@ function get_plugin_options() {
'type' => 'wysiwyg',
'label' => array(
'value' => __( 'Email content', 'pirate-forms' ),
'html' => '<br/><br/>' . esc_attr( __( 'You can use the next magic tags:', 'pirate-forms' ) ) . '<br/>' . PirateForms_Util::get_magic_tags(),
'html' => '<br/><br/>' . esc_attr( __( 'You can use the following magic tags:', 'pirate-forms' ) ) . '<br/>' . PirateForms_Util::get_magic_tags(),
),
'default' => PirateForms_Util::get_default_email_content( true, null, true ),
'value' => PirateForms_Util::get_option( 'pirateformsopt_email_content' ),
Expand Down
3 changes: 3 additions & 0 deletions admin/css/wp-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,6 @@ input#save.pirate-forms-save-button {
color: #fff;
background: #333;
}
#sib_embed_signup .message_area {
padding: 8px;
}
10 changes: 7 additions & 3 deletions admin/js/scripts-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ function initAll(){
},
error: function (MLHttpRequest, textStatus, errorThrown) {
console.log('There was an error: ' + errorThrown);
},
complete: function() {
endAjaxIntro();
}
});
endAjaxIntro();
return false;
}

Expand Down Expand Up @@ -86,10 +88,12 @@ function initAll(){
},
error: function (MLHttpRequest, textStatus, errorThrown) {
console.log('There was an error: ' + errorThrown);
},
complete: function(){
endAjaxIntro();
}
});

endAjaxIntro();

return false;
}

Expand Down
32 changes: 1 addition & 31 deletions admin/partials/pirateforms-settings-sidebar-subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,7 @@ class="btn"><?php esc_html_e( 'View more features', 'pirate-forms' ); ?></a>
endif;
?>
<div class="pirate-subscribe postbox card">
<h3 class="title"><?php esc_html_e( 'Get Our Free Email Course', 'pirate-forms' ); ?></h3>
<div class="pirate-forms-subscribe-content">
<?php
if ( ! empty( $_POST['pirate_forms_mail'] ) ) {
if ( ! class_exists( 'Mailin' ) ) {
require_once PIRATEFORMS_DIR . 'vendor/mailin-api/mailin-api-php/V2.0/Mailin.php';
}
$user_info = get_userdata( 1 );
$mailin = new Mailin( 'https://api.sendinblue.com/v2.0', 'cHW5sxZnzE7mhaYb' );
$data = array(
'email' => $_POST['pirate_forms_mail'],
'attributes' => array(
'NAME' => $user_info->first_name,
'SURNAME' => $user_info->last_name,
),
'blacklisted' => 0,
'listid' => array( 51 ),
'blacklisted_sms' => 0,
);
$status = $mailin->create_update_user( $data );
if ( $status['code'] == 'success' ) {
update_option( 'pirate_forms_subscribe', true );
}
}
$was_submited = get_option( 'pirate_forms_subscribe', false );
if ( $was_submited == false ) {
echo sprintf( '<p> %s </p><form class="pirate-forms-submit-mail" method="post"><input name="pirate_forms_mail" type="email" value="' . get_option( 'admin_email' ) . '" /><input class="button" type="submit" value="Submit"></form>', esc_html__( 'Ready to learn how to reduce your website loading times by half? Come and join the 1st lesson here!', 'pirate-forms' ) );
} else {
echo sprintf( '<p> %s </p>', esc_html__( 'Thank you for subscribing! You have been added to the mailing list and will receive the next email information in the coming weeks. If you ever wish to unsubscribe, simply use the "Unsubscribe" link included in each newsletter.', 'pirate-forms' ) );
}
?>
<!-- SendinBlue Signup Form HTML Code --><link rel="stylesheet" href="https://my.sendinblue.com/public/theme/version4/assets/styles/style.css" /> <div id="sib_embed_signup"> <div class="forms-builder-wrapper" style="position:relative;margin-left: auto;margin-right: auto;"> <input type="hidden" id="sib_embed_signup_lang" value="en"> <input type="hidden" id="sib_embed_invalid_email_message" value="That email address is not valid. Please try again."> <input type="hidden" name="primary_type" id="primary_type" value="email"> <div id="sib_loading_gif_area" style="position: absolute;z-index: 9999;display: none;"> <img src="https://my.sendinblue.com/public/theme/version4/assets/images/loader_sblue.gif" style="display: block;margin-left: auto;margin-right: auto;position: relative;top: 40%;"> </div> <form class="description" id="theform" name="theform" action="https://my.sendinblue.com/users/subscribeembed/js_id/1s344/id/3" onsubmit="return false;"> <input type="hidden" name="js_id" id="js_id" value="1s344"><input type="hidden" name="listid" id="listid" value="51"><input type="hidden" name="from_url" id="from_url" value="yes"><input type="hidden" name="hdn_email_txt" id="hdn_email_txt" value=""> <div class="sib-container rounded ui-sortable"> <input type="hidden" name="req_hid" id="req_hid" value="" style="font-size: 13px;"> <div class="header"> <h3 class="title">Get Our Free Email Course</h3> <p>Ready to learn how to reduce your website loading times by half? Come and join the 1st lesson here!</p> <div class="view-messages" style=" margin:5px 0;"> </div> <!-- an email as primary --> <div class="primary-group email-group forms-builder-group ui-sortable" style=""> <div class="row mandatory-email"> <p>Enter your email to subscribe. <span style="color:#ff0000;">*</span></p> <input type="text" name="email" id="email" value="<?php echo get_option( 'admin_email' ); ?>" style="padding: 4px; font-size: 13px; width: 80%; min-width: auto;"><input class="button" type="submit" data-editfield="subscribe" value="Submit"> <div style="clear:both;"></div> <div class="hidden-btns"> <a class="btn move" href="#"><i class="fa fa-arrows"></i></a><br> <!--<a class="btn btn-danger delete" href="#"><i class="fa fa-trash-o fa-inverse"></i></a>--> </div> </div> </div> <div class="captcha forms-builder-group" style="display: none;"><div class="row" style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; color: rgb(52, 52, 52); font-size: 10px; padding: 5px;"><div id="gcaptcha" style="transform: scale(0.47); margin-left: -57px;"></div></div></div> <!-- end of primary --><div style="clear:both;"></div> </div> </form> </div> </div> <script type="text/javascript"> var sib_prefix = 'sib'; var sib_dateformat = 'mm-dd-yyyy'; </script> <script type='text/javascript' src='https://my.sendinblue.com/public/theme/version4/assets/js/src/subscribe-validate.js?v=1526904274'></script> <!-- End : SendinBlue Signup Form HTML Code -->
</div>
</div>

216 changes: 216 additions & 0 deletions gutenberg/class-pirateforms-gutenberg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php

/**
* The gutenberg functionality of the plugin.
*
* @link http://example.com
* @since 1.0.0
*
* @package PirateForms
* @subpackage PirateForms/gutenberg
*/

/**
* The gutenberg functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package PirateForms
* @subpackage PirateForms/gutenberg
* @author Your Name <[email protected]>
*/
class PirateForms_Gutenberg {

/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;

/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;

/**
* Initialize the class and set its properties.
*
* @since 1.0.0
*
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;

}

/**
* Load block assets for the editor.
*/
public function enqueue_block_editor_assets() {
wp_enqueue_script(
'pirate-forms-block',
PIRATEFORMS_URL . 'gutenberg/js/block.build.js',
array( 'wp-i18n', 'wp-blocks', 'wp-components' ),
filemtime( PIRATEFORMS_DIR . '/gutenberg/js/block.build.js' )
);

wp_localize_script(
'pirate-forms-block', 'pfjs', array(
'url' => PIRATEFORMS_SLUG . '/v' . intval( PIRATEFORMS_API_VERSION ) . '/get_form/#/',
'forms' => $this->get_forms( true ),
'settings' => array(
'default' => admin_url( 'admin.php?page=pirateforms-admin' ),
'form' => admin_url( 'post.php?post=#&action=edit' ),
),
'i10n' => array(
'captcha' => __( 'Save and reload the page to see the CAPTCHA', 'pirate-forms' ),
'reload' => __( 'Some forms have changed since the last time this post was saved. We have reloaded those forms. You may need to save the post again.', 'pirate-forms' ),
'settings' => __( 'Modify Settings', 'pirate-forms' ),
'select_form' => __( 'Select Form', 'pirate-forms' ),
'select_ajax' => __( 'Use Ajax to submit form', 'pirate-forms' ),
'plugin' => PIRATEFORMS_NAME,
),
)
);

wp_enqueue_script( 'pirate-forms-custom-spam', PIRATEFORMS_URL . 'public/js/custom-spam.js', array( 'jquery' ) );
wp_localize_script(
'pirate-forms-custom-spam', 'pf', array(
'spam' => array(
'label' => apply_filters( 'pirate_forms_custom_spam_label', __( 'I\'m human!', 'pirate-forms' ) ),
'value' => wp_create_nonce( PIRATEFORMS_NAME ),
'gutenberg' => 1,
),
)
);

$language = get_locale();
if ( defined( 'POLYLANG_VERSION' ) && function_exists( 'pll_current_language' ) ) {
$language = pll_current_language();
}
wp_enqueue_script( 'recaptcha', "https://www.google.com/recaptcha/api.js?hl=$language" );

wp_enqueue_style( 'pirate-forms-front-css', PIRATEFORMS_URL . 'public/css/front.css' );
wp_enqueue_style( 'pirate-forms-block-css', PIRATEFORMS_URL . 'gutenberg/css/block.css' );
}

/**
* Register the block.
*/
public function register_block() {
register_block_type(
'pirate-forms/form', array(
'render_callback' => array( $this, 'render_block' ),
)
);
}

/**
* Render the pirate form block.
*/
function render_block( $atts = null ) {
$arributes = array();
if ( is_array( $atts ) && $atts ) {
if ( array_key_exists( 'form_id', $atts ) ) {
$attributes['id'] = $atts['form_id'];
}
if ( array_key_exists( 'ajax', $atts ) ) {
$attributes['ajax'] = $atts['ajax'];
}
} else {
$attributes['id'] = $atts;
}

$params = '';
if ( $attributes ) {
foreach ( $attributes as $key => $value ) {
$params .= " $key=$value";
}
}

return do_shortcode( "[pirate_forms $params]" );
}

/**
* Register the REST endpoints.
*/
public function register_endpoints() {
register_rest_route(
PIRATEFORMS_SLUG, '/v' . intval( PIRATEFORMS_API_VERSION ) . '/get_form/(?P<id>\d+)/',
array(
'methods' => 'GET',
'callback' => array( $this, 'get_form_html' ),
)
);
}

/**
* Get the requested form's HTML content.
*/
function get_form_html( WP_REST_Request $request ) {
$return = $this->validate_params( $request, array( 'id' ) );
if ( is_wp_error( $return ) ) {
return $return;
}

return new WP_REST_Response( array( 'html' => $this->render_block( $request->get_param( 'id' ) ) ) );
}

/**
* Validate REST params.
*/
private function validate_params( WP_REST_Request $request, $params = array() ) {
$return = array();
foreach ( $params as $param ) {
$value = $request->get_param( $param );
if ( ! is_numeric( $value ) && empty( $value ) ) {
return new WP_Error( $param . '_invalid', sprintf( __( 'Invalid %s', 'pirate-forms' ), $param ), array( 'status' => 403 ) );
} else {
$return[] = $value;
}
}

return $return;
}

/**
* Get all the forms.
*/
private function get_forms( $include_default = false ) {
$forms = array();
if ( $include_default ) {
$forms[] = array( 'label' => __( 'Default', 'pirate-forms' ), 'value' => 0 );
}
if ( defined( 'PIRATEFORMSPRO_NAME' ) ) {
$query = new WP_Query(
apply_filters(
'pirate_forms_get_forms_attributes', array(
'post_type' => 'pf_form',
'numberposts' => 300,
'post_status' => 'publish',
), basename( __FILE__ )
)
);

if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$forms[] = array( 'label' => get_the_title(), 'value' => get_the_ID() );
}
}
}
return $forms;
}

}
11 changes: 11 additions & 0 deletions gutenberg/css/block.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.pf-form-spinner {
display: none;
}

.pf-form-spinner.pf-form-loading {
display: block;
}

.pirate-forms-maps-custom input {
display: inline-block !important;
}
Loading

0 comments on commit 296b649

Please sign in to comment.