Commit fb7f9e08 authored by KR Moorhouse's avatar KR Moorhouse Committed by Eric Windham

Migrated public link key generation to centralized controller. Added load...

Migrated public link key generation to centralized controller. Added load controller to reset the public link if it wasn't generated properly (in the builder).
parent bcf1adbe
/**
* Handles changing our public link when we request a new one or when it's set improperly.
*
* @package Ninja Forms builder
* @subpackage Fields
* @copyright (c) 2019 WP Ninjas
* @since UPDATE_VERSION_ON_MERGE
*/
define( [], function() {
var controller = Marionette.Object.extend( {
initialize: function() {
this.listenTo( nfRadio.channel( 'app' ), 'after:appStart', this.validatePublicLink, this );
nfRadio.channel( 'app' ).reply( 'generate:publicLinkKey', this.newPublicLinkKey, this );
},
newPublicLinkKey: function() {
var formSettingsDataModel = nfRadio.channel( 'settings' ).request( 'get:settings' );
var public_link_key = nfRadio.channel('app').request('get:formModel').get('id');
for (var i = 0; i < 4; i++) {
var char = Math.random().toString(36).slice(-1);
public_link_key += char;
};
// Apply the public link key to form settings
formSettingsDataModel.set('public_link_key', public_link_key);
return public_link_key;
},
validatePublicLink: function() {
var formID = nfRadio.channel('app').request('get:formModel').get('id');
var formSettingsDataModel = nfRadio.channel( 'settings' ).request( 'get:settings' );
if ( 'undefined' === typeof formSettingsDataModel.get('public_link_key') ) return false;
if ( 0 === formSettingsDataModel.get( 'public_link_key' ).indexOf( formID ) ) return false;
var public_link_key = this.newPublicLinkKey();
var publicLink = nfAdmin.publicLinkStructure.replace('[FORM_ID]', public_link_key);
formSettingsDataModel.set('public_link', publicLink);
}
});
return controller;
} );
\ No newline at end of file
......@@ -58,6 +58,7 @@ define(
'controllers/app/perfectScroll',
'controllers/app/getNewSettingGroupCollection',
'controllers/app/settingMedia',
'controllers/app/publicLink',
/*
* Fields domain controllers
*/
......@@ -165,6 +166,7 @@ define(
PerfectScroll,
GetNewSettingGroupCollection,
SettingMedia,
PublicLink,
/*
* Fields domain controllers
*/
......@@ -260,6 +262,7 @@ define(
new TrackKeyDown();
new PerfectScroll();
new GetNewSettingGroupCollection();
new PublicLink();
// new Pushstate();
/*
* Fields domain controllers
......
......@@ -37,13 +37,7 @@ define( ['views/app/drawer/itemSetting'], function( itemSettingView) {
* Form Id + 4 consecutive base 36 numbers
*/
if (!public_link_key) {
var public_link_key = formModel.get('id');
for (var i = 0; i < 4; i++) {
var char = Math.random().toString(36).slice(-1);
public_link_key += char;
};
// Apply the public link key to form settings
formSettingsDataModel.set('public_link_key', public_link_key);
public_link_key = nfRadio.channel('app').request('generate:publicLinkKey');
}
// apply public link url to settings (ending with key)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -279,7 +279,16 @@ class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
{
$insert_values = '';
$blacklist = array(
'embed_form',
'public_link',
'public_link_key',
'allow_public_link',
);
$blacklist = apply_filters( 'ninja_forms_excluded_import_form_settings', $blacklist );
foreach( $this->form[ 'settings' ] as $meta_key => $meta_value ) {
if ( in_array( $meta_key, $blacklist ) ) continue;
$meta_value = maybe_serialize( $meta_value );
$this->_db->escape_by_ref( $meta_value );
$insert_values .= "( {$this->form[ 'ID' ]}, '{$meta_key}', '{$meta_value}'";
......
......@@ -282,6 +282,16 @@ final class NF_Database_Models_Form extends NF_Abstracts_Model
) );
$new_form_id = $wpdb->insert_id;
$blacklist = array(
'_seq_num',
'embed_form',
'public_link',
'public_link_key',
'allow_public_link',
);
$blacklist = apply_filters( 'ninja_forms_excluded_duplicate_form_settings', $blacklist );
$blacklist = "'" . implode( "','", $blacklist ) . "'";
// Duplicate the Form Meta.
$wpdb->query( $wpdb->prepare(
"
......@@ -289,7 +299,7 @@ final class NF_Database_Models_Form extends NF_Abstracts_Model
SELECT %d, `key`, `value`
FROM {$wpdb->prefix}nf3_form_meta
WHERE parent_id = %d
AND `key` != '_seq_num';
AND `key` NOT IN({$blacklist});
", $new_form_id, $form_id
));
......
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