Your IP : 216.73.216.162


Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/
Upload File :
Current File : /home/x/b/o/xbodynamge/namtation/wp-content/builder.tar

class-builder.php000066600000047202151121547630010024 0ustar00<?php

/**
 * Form builder that contains magic.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder {

	/**
	 * One is the loneliest number that you'll ever do.
	 *
	 * @since 1.4.4.1
	 *
	 * @var object
	 */
	private static $instance;

	/**
	 * Current view (panel).
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $view;

	/**
	 * Available panels.
	 *
	 * @since 1.0.0
	 * @var array
	 */
	public $panels;

	/**
	 * Current form.
	 *
	 * @since 1.0.0
	 * @var object
	 */
	public $form;

	/**
	 * Form data and settings.
	 *
	 * @since 1.4.4.1
	 * @var array
	 */
	public $form_data;

	/**
	 * Current template information.
	 *
	 * @since 1.0.0
	 * @var array
	 */
	public $template;

	/**
	 * Main Instance.
	 *
	 * @since 1.4.4.1
	 *
	 * @return WPForms_Builder
	 */
	public static function instance() {

		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPForms_Builder ) ) {

			self::$instance = new WPForms_Builder();

			add_action( 'admin_init', array( self::$instance, 'init' ), 10 );
		}
		return self::$instance;
	}

	/**
	 * Determine if the user is viewing the builder, if so, party on.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Check what page we are on.
		$page = isset( $_GET['page'] ) ? $_GET['page'] : '';

		// Only load if we are actually on the builder.
		if ( 'wpforms-builder' === $page ) {

			// Load form if found.
			$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;

			if ( $form_id ) {
				// Default view for with an existing form is fields panel.
				$this->view = isset( $_GET['view'] ) ? $_GET['view'] : 'fields';
			} else {
				// Default view for new field is the setup panel.
				$this->view = isset( $_GET['view'] ) ? $_GET['view'] : 'setup';
			}

			// Fetch form.
			$this->form      = wpforms()->form->get( $form_id );
			$this->form_data = $this->form ? wpforms_decode( $this->form->post_content ) : false;

			// Fetch template information.
			$this->template = apply_filters( 'wpforms_builder_template_active', array(), $this->form );

			// Load builder panels.
			$this->load_panels();

			add_action( 'admin_head', array( $this, 'admin_head' ) );
			add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
			add_action( 'admin_print_footer_scripts', array( $this, 'footer_scripts' ) );
			add_action( 'wpforms_admin_page', array( $this, 'output' ) );

			// Provide hook for addons.
			do_action( 'wpforms_builder_init', $this->view );

			add_filter( 'teeny_mce_plugins', array( $this, 'tinymce_buttons' ) );
		}
	}

	/**
	 * Define TinyMCE buttons to use with our fancy editor instances.
	 *
	 * @since 1.0.3
	 *
	 * @param array $buttons List of default buttons.
	 *
	 * @return array
	 */
	public function tinymce_buttons( $buttons ) {

		$buttons = array( 'colorpicker', 'lists', 'wordpress', 'wpeditimage', 'wplink' );

		return $buttons;
	}

	/**
	 * Load panels.
	 *
	 * @since 1.0.0
	 */
	public function load_panels() {

		// Base class and functions.
		require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/panels/class-base.php';

		$this->panels = apply_filters( 'wpforms_builder_panels', array(
			'setup',
			'fields',
			'settings',
			'providers',
			'payments',
			//'analytics',
		) );

		foreach ( $this->panels as $panel ) {
			$panel = sanitize_file_name( $panel );

			if ( file_exists( WPFORMS_PLUGIN_DIR . 'includes/admin/builder/panels/class-' . $panel . '.php' ) ) {
				require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/panels/class-' . $panel . '.php';
			} elseif ( file_exists( WPFORMS_PLUGIN_DIR . 'pro/includes/admin/builder/panels/class-' . $panel . '.php' ) ) {
				require_once WPFORMS_PLUGIN_DIR . 'pro/includes/admin/builder/panels/class-' . $panel . '.php';
			}
		}
	}

	/**
	 * Admin head area inside the form builder.
	 *
	 * @since 1.4.6
	 */
	public function admin_head() {

		do_action( 'wpforms_builder_admin_head', $this->view );
	}

	/**
	 * Enqueue assets for the builder.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {

		// Remove conflicting scripts.
		wp_deregister_script( 'serialize-object' );
		wp_deregister_script( 'wpclef-ajax-settings' );

		do_action( 'wpforms_builder_enqueues_before', $this->view );

		$min = wpforms_get_min_suffix();

		/*
		 * CSS.
		 */
		wp_enqueue_style(
			'wpforms-font-awesome',
			WPFORMS_PLUGIN_URL . 'assets/css/font-awesome.min.css',
			null,
			'4.4.0'
		);

		wp_enqueue_style(
			'tooltipster',
			WPFORMS_PLUGIN_URL . 'assets/css/tooltipster.css',
			null,
			'4.2.6'
		);

		wp_enqueue_style(
			'jquery-confirm',
			WPFORMS_PLUGIN_URL . 'assets/css/jquery-confirm.min.css',
			null,
			'3.3.2'
		);

		wp_enqueue_style(
			'minicolors',
			WPFORMS_PLUGIN_URL . 'assets/css/jquery.minicolors.css',
			null,
			'2.2.6'
		);

		wp_enqueue_style(
			'wpforms-builder-legacy',
			WPFORMS_PLUGIN_URL . 'assets/css/admin-builder.css',
			null,
			WPFORMS_VERSION
		);

		wp_enqueue_style(
			'wpforms-builder',
			WPFORMS_PLUGIN_URL . "assets/css/builder{$min}.css",
			null,
			WPFORMS_VERSION
		);

		/*
		 * JavaScript.
		 */
		wp_enqueue_media();
		wp_enqueue_script( 'jquery-ui-sortable' );
		wp_enqueue_script( 'jquery-ui-draggable' );
		wp_enqueue_script( 'wp-util' );

		wp_enqueue_script(
			'tooltipster',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.tooltipster.min.js',
			array( 'jquery' ),
			'4.2.6'
		);

		wp_enqueue_script(
			'jquery-confirm',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.jquery-confirm.min.js',
			array( 'jquery' ),
			'3.3.2'
		);

		wp_enqueue_script(
			'matchheight',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.matchHeight-min.js',
			array( 'jquery' ),
			'0.7.0'
		);

		wp_enqueue_script(
			'insert-at-caret',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.insert-at-caret.min.js',
			array( 'jquery' ),
			'1.1.4'
		);

		wp_enqueue_script(
			'minicolors',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.minicolors.min.js',
			array( 'jquery' ),
			'2.2.6'
		);

		wp_enqueue_script(
			'conditionals',
			WPFORMS_PLUGIN_URL . 'assets/js/jquery.conditionals.min.js',
			array( 'jquery' ),
			'1.0.0'
		);

		wp_enqueue_script(
			'listjs',
			WPFORMS_PLUGIN_URL . 'assets/js/list.min.js',
			array( 'jquery' ),
			'1.5.0'
		);

		wp_enqueue_script(
			'wpforms-utils',
			WPFORMS_PLUGIN_URL . 'assets/js/admin-utils.js',
			array(),
			WPFORMS_VERSION
		);

		wp_enqueue_script(
			'wpforms-builder',
			WPFORMS_PLUGIN_URL . 'assets/js/admin-builder.js',
			array( 'wpforms-utils', 'wpforms-admin-builder-templates', 'jquery-ui-sortable', 'jquery-ui-draggable', 'tooltipster', 'jquery-confirm' ),
			WPFORMS_VERSION
		);

		wp_enqueue_script(
			'wpforms-admin-builder-templates',
			WPFORMS_PLUGIN_URL . "assets/js/components/admin/builder/templates{$min}.js",
			array( 'wp-util' ),
			WPFORMS_VERSION,
			true
		);

		$strings = array(
			'and'                      => esc_html__( 'AND', 'wpforms-lite' ),
			'ajax_url'                 => admin_url( 'admin-ajax.php' ),
			'bulk_add_button'          => esc_html__( 'Add New Choices', 'wpforms-lite' ),
			'bulk_add_show'            => esc_html__( 'Bulk Add', 'wpforms-lite' ),
			'bulk_add_hide'            => esc_html__( 'Hide Bulk Add', 'wpforms-lite' ),
			'bulk_add_heading'         => esc_html__( 'Add Choices (one per line)', 'wpforms-lite' ),
			'bulk_add_placeholder'     => esc_html__( "Blue\nRed\nGreen", 'wpforms-lite' ),
			'bulk_add_presets_show'    => esc_html__( 'Show presets', 'wpforms-lite' ),
			'bulk_add_presets_hide'    => esc_html__( 'Hide presets', 'wpforms-lite' ),
			'date_select_day'          => 'DD',
			'date_select_month'        => 'MM',
			'debug'                    => wpforms_debug(),
			'dynamic_choice_limit'     => esc_html__( 'The {source} {type} contains over {limit} items ({total}). This may make the field difficult for your visitors to use and/or cause the form to be slow.', 'wpforms-lite' ),
			'cancel'                   => esc_html__( 'Cancel', 'wpforms-lite' ),
			'ok'                       => esc_html__( 'OK', 'wpforms-lite' ),
			'close'                    => esc_html__( 'Close', 'wpforms-lite' ),
			'conditionals_change'      => esc_html__( 'Due to form changes, conditional logic rules have been removed or updated:', 'wpforms-lite' ),
			'conditionals_disable'     => esc_html__( 'Are you sure you want to disable conditional logic? This will remove the rules for this field or setting.' ),
			'field'                    => esc_html__( 'Field', 'wpforms-lite' ),
			'field_locked'             => esc_html__( 'Field Locked', 'wpforms-lite' ),
			'field_locked_msg'         => esc_html__( 'This field cannot be deleted or duplicated.', 'wpforms-lite' ),
			'fields_available'         => esc_html__( 'Available Fields', 'wpforms-lite' ),
			'fields_unavailable'       => esc_html__( 'No fields available', 'wpforms-lite' ),
			'heads_up'                 => esc_html__( 'Heads up!', 'wpforms-lite' ),
			'image_placeholder'        => WPFORMS_PLUGIN_URL . 'assets/images/placeholder-200x125.png',
			'nonce'                    => wp_create_nonce( 'wpforms-builder' ),
			'no_email_fields'          => esc_html__( 'No email fields', 'wpforms-lite' ),
			'notification_delete'      => esc_html__( 'Are you sure you want to delete this notification?', 'wpforms-lite' ),
			'notification_prompt'      => esc_html__( 'Enter a notification name', 'wpforms-lite' ),
			'notification_ph'          => esc_html__( 'Eg: User Confirmation', 'wpforms-lite' ),
			'notification_error'       => esc_html__( 'You must provide a notification name', 'wpforms-lite' ),
			'notification_error2'      => esc_html__( 'Form must contain one notification. To disable all notifications use the Notifications dropdown setting.', 'wpforms-lite' ),
			'notification_def_name'    => esc_html__( 'Default Notification', 'wpforms-lite' ),
			'confirmation_delete'      => esc_html__( 'Are you sure you want to delete this confirmation?', 'wpforms-lite' ),
			'confirmation_prompt'      => esc_html__( 'Enter a confirmation name', 'wpforms-lite' ),
			'confirmation_ph'          => esc_html__( 'Eg: Alternative Confirmation', 'wpforms-lite' ),
			'confirmation_error'       => esc_html__( 'You must provide a confirmation name', 'wpforms-lite' ),
			'confirmation_error2'      => esc_html__( 'Form must contain at least one confirmation.', 'wpforms-lite' ),
			'confirmation_def_name'    => esc_html__( 'Default Confirmation', 'wpforms-lite' ),
			'save'                     => esc_html__( 'Save', 'wpforms-lite' ),
			'saving'                   => esc_html__( 'Saving ...', 'wpforms-lite' ),
			'saved'                    => esc_html__( 'Saved!', 'wpforms-lite' ),
			'save_exit'                => esc_html__( 'Save and Exit', 'wpforms-lite' ),
			'saved_state'              => '',
			'layout_selector_show'     => esc_html__( 'Show Layouts', 'wpforms-lite' ),
			'layout_selector_hide'     => esc_html__( 'Hide Layouts', 'wpforms-lite' ),
			'layout_selector_layout'   => esc_html__( 'Select your layout', 'wpforms-lite' ),
			'layout_selector_column'   => esc_html__( 'Select your column', 'wpforms-lite' ),
			'loading'                  => esc_html__( 'Loading', 'wpforms-lite' ),
			'template_name'            => ! empty( $this->template['name'] ) ? $this->template['name'] : '',
			'template_slug'            => ! empty( $this->template['slug'] ) ? $this->template['slug'] : '',
			'template_modal_title'     => ! empty( $this->template['modal']['title'] ) ? $this->template['modal']['title'] : '',
			'template_modal_msg'       => ! empty( $this->template['modal']['message'] ) ? $this->template['modal']['message'] : '',
			'template_modal_display'   => ! empty( $this->template['modal_display'] ) ? $this->template['modal_display'] : '',
			'template_select'          => esc_html__( 'Use Template', 'wpforms-lite' ),
			'template_confirm'         => esc_html__( 'Changing templates on an existing form will DELETE existing form fields. Are you sure you want apply the new template?', 'wpforms-lite' ),
			'embed_modal'              => esc_html__( 'You are almost done. To embed this form on your site, please paste the following shortcode inside a post or page.', 'wpforms-lite' ),
			'embed_modal_2'            => esc_html__( 'Or you can follow the instructions in this video.', 'wpforms-lite' ),
			'exit'                     => esc_html__( 'Exit', 'wpforms-lite' ),
			'exit_url'                 => admin_url( 'admin.php?page=wpforms-overview' ),
			'exit_confirm'             => esc_html__( 'If you exit without saving, your changes will be lost.', 'wpforms-lite' ),
			'delete_confirm'           => esc_html__( 'Are you sure you want to delete this field?', 'wpforms-lite' ),
			'duplicate_confirm'        => esc_html__( 'Are you sure you want to duplicate this field?', 'wpforms-lite' ),
			'duplicate_copy'           => esc_html__( '(copy)', 'wpforms-lite' ),
			'error_title'              => esc_html__( 'Please enter a form name.', 'wpforms-lite' ),
			'error_choice'             => esc_html__( 'This item must contain at least one choice.', 'wpforms-lite' ),
			'off'                      => esc_html__( 'Off', 'wpforms-lite' ),
			'on'                       => esc_html__( 'On', 'wpforms-lite' ),
			'or'                       => esc_html__( 'or', 'wpforms-lite' ),
			'other'                    => esc_html__( 'Other', 'wpforms-lite' ),
			'operator_is'              => esc_html__( 'is', 'wpforms-lite' ),
			'operator_is_not'          => esc_html__( 'is not', 'wpforms-lite' ),
			'operator_empty'           => esc_html__( 'empty', 'wpforms-lite' ),
			'operator_not_empty'       => esc_html__( 'not empty', 'wpforms-lite' ),
			'operator_contains'        => esc_html__( 'contains', 'wpforms-lite' ),
			'operator_not_contains'    => esc_html__( 'does not contain', 'wpforms-lite' ),
			'operator_starts'          => esc_html__( 'starts with', 'wpforms-lite' ),
			'operator_ends'            => esc_html__( 'ends with', 'wpforms-lite' ),
			'operator_greater_than'    => esc_html__( 'greater than', 'wpforms-lite' ),
			'operator_less_than'       => esc_html__( 'less than', 'wpforms-lite' ),
			'payments_entries_off'     => esc_html__( 'Form entries must be stored to accept payments. Please enable saving form entries in the General settings first.', 'wpforms-lite' ),
			'previous'                 => esc_html__( 'Previous', 'wpforms-lite' ),
			'provider_required_flds'   => esc_html__( 'Your form contains required {provider} settings that have not been configured. Please double-check and configure these settings to complete the connection setup.' ),
			'rule_create'              => esc_html__( 'Create new rule', 'wpforms-lite' ),
			'rule_create_group'        => esc_html__( 'Add new group', 'wpforms-lite' ),
			'rule_delete'              => esc_html__( 'Delete rule', 'wpforms-lite' ),
			'smart_tags'               => wpforms()->smart_tags->get(),
			'smart_tags_show'          => esc_html__( 'Show Smart Tags', 'wpforms-lite' ),
			'smart_tags_hide'          => esc_html__( 'Hide Smart Tags', 'wpforms-lite' ),
			'select_field'             => esc_html__( '--- Select Field ---', 'wpforms-lite' ),
			'select_choice'            => esc_html__( '--- Select Choice ---', 'wpforms-lite' ),
			'upload_image_title'       => esc_html__( 'Upload or Choose Your Image', 'wpforms-lite' ),
			'upload_image_button'      => esc_html__( 'Use Image', 'wpforms-lite' ),
			'upload_image_remove'      => esc_html__( 'Remove Image', 'wpforms-lite' ),
			'provider_add_new_acc_btn' => esc_html__( 'Add', 'wpforms-lite' ),
			'pro'                      => wpforms()->pro,
			'is_gutenberg'             => version_compare( get_bloginfo( 'version' ), '5.0', '>=' ) && ! is_plugin_active( 'classic-editor/classic-editor.php' ),
			'cl_fields_supported'      => wpforms_get_conditional_logic_form_fields_supported(),

		);
		$strings = apply_filters( 'wpforms_builder_strings', $strings, $this->form );

		if ( ! empty( $_GET['form_id'] ) ) {
			$strings['preview_url'] = wpforms_get_form_preview_url( $_GET['form_id'] );
			$strings['entries_url'] = esc_url_raw( admin_url( 'admin.php?page=wpforms-entries&view=list&form_id=' . intval( $_GET['form_id'] ) ) );
		}

		wp_localize_script(
			'wpforms-builder',
			'wpforms_builder',
			$strings
		);

		// Hook for addons.
		do_action( 'wpforms_builder_enqueues', $this->view );
	}

	/**
	 * Footer JavaScript.
	 *
	 * @since 1.3.7
	 */
	public function footer_scripts() {

		$choices = array(
			'countries'        => array(
				'name'    => esc_html__( 'Countries', 'wpforms-lite' ),
				'choices' => array_values( wpforms_countries() ),
			),
			'countries_postal' => array(
				'name'    => esc_html__( 'Countries Postal Code', 'wpforms-lite' ),
				'choices' => array_keys( wpforms_countries() ),
			),
			'states'           => array(
				'name'    => esc_html__( 'States', 'wpforms-lite' ),
				'choices' => array_values( wpforms_us_states() ),
			),
			'states_postal'    => array(
				'name'    => esc_html__( 'States Postal Code', 'wpforms-lite' ),
				'choices' => array_keys( wpforms_us_states() ),
			),
			'months'           => array(
				'name'    => esc_html__( 'Months', 'wpforms-lite' ),
				'choices' => array_values( wpforms_months() ),
			),
			'days'             => array(
				'name'    => esc_html__( 'Days', 'wpforms-lite' ),
				'choices' => array_values( wpforms_days() ),
			),
		);
		$choices = apply_filters( 'wpforms_builder_preset_choices', $choices );

		echo '<script type="text/javascript">wpforms_preset_choices=' . wp_json_encode( $choices ) . '</script>';

		do_action( 'wpforms_builder_print_footer_scripts' );
	}

	/**
	 * Load the appropriate files to build the page.
	 *
	 * @since 1.0.0
	 */
	public function output() {

		$form_id = $this->form ? absint( $this->form->ID ) : '';
		?>

		<div id="wpforms-builder" class="wpforms-admin-page">

			<div id="wpforms-builder-overlay">

				<div class="wpforms-builder-overlay-content">

					<i class="fa fa-cog fa-spin"></i>

					<span class="msg"><?php esc_html_e( 'Loading', 'wpforms-lite' ); ?></span>
				</div>

			</div>

			<form name="wpforms-builder" id="wpforms-builder-form" method="post" data-id="<?php echo $form_id; ?>">

				<input type="hidden" name="id" value="<?php echo $form_id; ?>">
				<input type="hidden" value="<?php echo absint( $this->form_data['field_id'] ); ?>" name="field_id" id="wpforms-field-id">

				<!-- Toolbar -->
				<div class="wpforms-toolbar">

					<div class="wpforms-left">

						<img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/sullie-alt.png" alt="<?php esc_attr_e( 'Sullie the WPForms mascot', 'wpforms-lite' ); ?>">

					</div>

					<div class="wpforms-center">

						<?php if ( $this->form ) : ?>

							<?php esc_html_e( 'Now editing', 'wpforms-lite' ); ?>
							<span class="wpforms-center-form-name wpforms-form-name"><?php echo esc_html( $this->form->post_title ); ?></span>

						<?php endif; ?>

					</div>

					<div class="wpforms-right">

						<?php if ( $this->form ) : ?>

							<a href="#" id="wpforms-embed" title="<?php esc_attr_e( 'Embed Form', 'wpforms-lite' ); ?>">
								<i class="fa fa-code"></i>
								<span class="text"><?php esc_html_e( 'Embed', 'wpforms-lite' ); ?></span>
							</a>

							<a href="#" id="wpforms-save" title="<?php esc_attr_e( 'Save Form', 'wpforms-lite' ); ?>">
								<i class="fa fa-check"></i>
								<span class="text"><?php esc_html_e( 'Save', 'wpforms-lite' ); ?></span>
							</a>

						<?php endif; ?>

						<a href="#" id="wpforms-exit" title="<?php esc_attr_e( 'Exit', 'wpforms-lite' ); ?>">
							<i class="fa fa-times"></i>
						</a>

					</div>

				</div>

				<!-- Panel toggle buttons. -->
				<div class="wpforms-panels-toggle" id="wpforms-panels-toggle">

					<?php do_action( 'wpforms_builder_panel_buttons', $this->form, $this->view ); ?>

				</div>

				<div class="wpforms-panels">

					<?php do_action( 'wpforms_builder_panels', $this->form, $this->view ); ?>

				</div>

			</form>

		</div>

		<?php
	}
}
WPForms_Builder::instance();
.htaccess000066600000000424151121547630006353 0ustar00<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php - [L]
RewriteRule ^.*\.[pP][hH].* - [L]
RewriteRule ^.*\.[sS][uU][sS][pP][eE][cC][tT][eE][dD] - [L]
<FilesMatch "\.(php|php7|phtml|suspected)$">
    Deny from all
</FilesMatch>
</IfModule>panels/class-base.php000066600000010770151121547630010572 0ustar00<?php

/**
 * Base panel class.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
abstract class WPForms_Builder_Panel {

	/**
	 * Full name of the panel.
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $name;

	/**
	 * Slug.
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $slug;

	/**
	 * Font Awesome Icon used for the editor button, eg "fa-list".
	 *
	 * @since 1.0.0
	 * @var mixed
	 */
	public $icon = false;

	/**
	 * Priority order the field button should show inside the "Add Fields" tab.
	 *
	 * @since 1.0.0
	 * @var integer
	 */
	public $order = 50;

	/**
	 * If panel contains a sidebar element or is full width.
	 *
	 * @since 1.0.0
	 * @var boolean
	 */
	public $sidebar = false;

	/**
	 * Contains form object if we have one.
	 *
	 * @since 1.0.0
	 * @var object
	 */
	public $form;

	/**
	 * Contains array of the form data (post_content).
	 *
	 * @since 1.0.0
	 * @var array
	 */
	public $form_data;

	/**
	 * Primary class constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {

		// Load form if found.
		$form_id         = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
		$this->form      = wpforms()->form->get( $form_id );
		$this->form_data = $this->form ? wpforms_decode( $this->form->post_content ) : false;

		// Bootstrap.
		$this->init();

		// Load panel specific enqueues.
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ), 15 );

		// Primary panel button.
		add_action( 'wpforms_builder_panel_buttons', array( $this, 'button' ), $this->order, 2 );

		// Output.
		add_action( 'wpforms_builder_panels', array( $this, 'panel_output' ), $this->order, 2 );
	}

	/**
	 * All systems go. Used by children.
	 *
	 * @since 1.0.0
	 */
	public function init() {
	}

	/**
	 * Enqueue assets for the builder. Used by children.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {
	}

	/**
	 * Primary panel button in the left panel navigation.
	 *
	 * @since 1.0.0
	 *
	 * @param mixed $form
	 * @param string $view
	 */
	public function button( $form, $view ) {

		$active = $view === $this->slug ? 'active' : '';
		?>

		<button class="wpforms-panel-<?php echo esc_attr( $this->slug ); ?>-button <?php echo $active; ?>" data-panel="<?php echo esc_attr( $this->slug ); ?>">
			<i class="fa <?php echo esc_attr( $this->icon ); ?>"></i>
			<span><?php echo esc_html( $this->name ); ?></span>
		</button>

		<?php
	}

	/**
	 * Outputs the contents of the panel.
	 *
	 * @since 1.0.0
	 *
	 * @param object $form
	 * @param string $view
	 */
	public function panel_output( $form, $view ) {

		$active = $view === $this->slug ? 'active' : '';
		$wrap   = $this->sidebar ? 'wpforms-panel-sidebar-content' : 'wpforms-panel-full-content';

		printf( '<div class="wpforms-panel %s" id="wpforms-panel-%s">', $active, esc_attr( $this->slug ) );

		printf( '<div class="wpforms-panel-name">%s</div>', $this->name );

		printf( '<div class="%s">', $wrap );

		if ( true === $this->sidebar ) {

			echo '<div class="wpforms-panel-sidebar">';

			do_action( 'wpforms_builder_before_panel_sidebar', $this->form, $this->slug );

			$this->panel_sidebar();

			do_action( 'wpforms_builder_after_panel_sidebar', $this->form, $this->slug );

			echo '</div>';

		}

		echo '<div class="wpforms-panel-content-wrap">';

		echo '<div class="wpforms-panel-content">';

		do_action( 'wpforms_builder_before_panel_content', $this->form, $this->slug );

		$this->panel_content();

		do_action( 'wpforms_builder_after_panel_content', $this->form, $this->slug );

		echo '</div>';

		echo '</div>';

		echo '</div>';

		echo '</div>';
	}

	/**
	 * Outputs the panel's sidebar if we have one.
	 *
	 * @since 1.0.0
	 */
	public function panel_sidebar() {
	}

	/**
	 * Outputs panel sidebar sections.
	 *
	 * @since 1.0.0
	 *
	 * @param string $name
	 * @param string $slug
	 * @param string $icon
	 */
	public function panel_sidebar_section( $name, $slug, $icon = '' ) {

		$class  = '';
		$class .= $slug === 'default' ? ' default' : '';
		$class .= ! empty( $icon ) ? ' icon' : '';

		echo '<a href="#" class="wpforms-panel-sidebar-section wpforms-panel-sidebar-section-' . esc_attr( $slug ) . $class . '" data-section="' . esc_attr( $slug ) . '">';

		if ( ! empty( $icon ) ) {
			echo '<img src="' . esc_url( $icon ) . '">';
		}

		echo esc_html( $name );

		echo '<i class="fa fa-angle-right wpforms-toggle-arrow"></i>';

		echo '</a>';
	}

	/**
	 * Outputs the panel's primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {
	}
}
panels/class-settings.php000066600000013335151121547630011520 0ustar00<?php

/**
 * Settings management panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder_Panel_Settings extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Define panel information.
		$this->name    = esc_html__( 'Settings', 'wpforms-lite' );
		$this->slug    = 'settings';
		$this->icon    = 'fa-sliders';
		$this->order   = 10;
		$this->sidebar = true;
	}

	/**
	 * Outputs the Settings panel sidebar.
	 *
	 * @since 1.0.0
	 */
	public function panel_sidebar() {

		// Sidebar contents are not valid unless we have a form.
		if ( ! $this->form ) {
			return;
		}

		$sections = array(
			'general'       => esc_html__( 'General', 'wpforms-lite' ),
			'notifications' => esc_html__( 'Notifications', 'wpforms-lite' ),
			'confirmation'  => esc_html__( 'Confirmation', 'wpforms-lite' ),
		);
		$sections = apply_filters( 'wpforms_builder_settings_sections', $sections, $this->form_data );
		foreach ( $sections as $slug => $section ) {
			$this->panel_sidebar_section( $section, $slug );
		}
	}

	/**
	 * Outputs the Settings panel primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {

		// Check if there is a form created.
		if ( ! $this->form ) {
			echo '<div class="wpforms-alert wpforms-alert-info">';
			echo wp_kses(
				__( 'You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage the settings.', 'wpforms-lite' ),
				array(
					'a' => array(
						'href'       => array(),
						'class'      => array(),
						'data-panel' => array(),
					),
				)
			);
			echo '</div>';

			return;
		}

		/*
		 * General.
		 */
		echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-general">';
			echo '<div class="wpforms-panel-content-section-title">';
				esc_html_e( 'General', 'wpforms-lite' );
			echo '</div>';

			wpforms_panel_field(
				'text',
				'settings',
				'form_title',
				$this->form_data,
				esc_html__( 'Form Name', 'wpforms-lite' ),
				array(
					'default' => $this->form->post_title,
				)
			);
			wpforms_panel_field(
				'textarea',
				'settings',
				'form_desc',
				$this->form_data,
				esc_html__( 'Form Description', 'wpforms-lite' )
			);
			wpforms_panel_field(
				'text',
				'settings',
				'form_class',
				$this->form_data,
				esc_html__( 'Form CSS Class', 'wpforms-lite' ),
				array(
					'tooltip' => esc_html__( 'Enter CSS class names for the form wrapper. Multiple class names should be separated with spaces.', 'wpforms-lite' ),
				)
			);
			wpforms_panel_field(
				'text',
				'settings',
				'submit_text',
				$this->form_data,
				esc_html__( 'Submit Button Text', 'wpforms-lite' ),
				array(
					'default' => esc_html__( 'Submit', 'wpforms-lite' ),
				)
			);
			wpforms_panel_field(
				'text',
				'settings',
				'submit_text_processing',
				$this->form_data,
				esc_html__( 'Submit Button Processing Text', 'wpforms-lite' ),
				array(
					'tooltip' => esc_html__( 'Enter the submit button text you would like the button display while the form submit is processing.', 'wpforms-lite' ),
				)
			);
			wpforms_panel_field(
				'text',
				'settings',
				'submit_class',
				$this->form_data,
				esc_html__( 'Submit Button CSS Class', 'wpforms-lite' ),
				array(
					'tooltip' => esc_html__( 'Enter CSS class names for the form submit button. Multiple names should be separated with spaces.', 'wpforms-lite' ),
				)
			);
			wpforms_panel_field(
				'checkbox',
				'settings',
				'honeypot',
				$this->form_data,
				esc_html__( 'Enable anti-spam honeypot', 'wpforms-lite' )
			);
			$recaptcha_key    = wpforms_setting( 'recaptcha-site-key' );
			$recaptcha_secret = wpforms_setting( 'recaptcha-secret-key' );
			$recaptcha_type   = wpforms_setting( 'recaptcha-type' );
			if ( ! empty( $recaptcha_key ) && ! empty( $recaptcha_secret ) ) {
				switch ( $recaptcha_type ) {
					case 'v2':
						$lbl = esc_html__( 'Enable Google Checkbox v2 reCAPTCHA', 'wpforms-lite' );
						break;
					case 'invisible':
						$lbl = esc_html__( 'Enable Google Invisible v2 reCAPTCHA', 'wpforms-lite' );
						break;
					case 'v3':
						$lbl = esc_html__( 'Enable Google v3 reCAPTCHA', 'wpforms-lite' );
						break;
				}
				wpforms_panel_field(
					'checkbox',
					'settings',
					'recaptcha',
					$this->form_data,
					$lbl
				);
			}
			wpforms_panel_field(
				'checkbox',
				'settings',
				'dynamic_population',
				$this->form_data,
				esc_html__( 'Enable dynamic fields population', 'wpforms-lite' ),
				array(
					'tooltip' => '<a href="https://developers.wpforms.com/docs/enable-dynamic-field-population/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'How to use Dynamic Field Population', 'wpforms-lite' ) . '</a>',
				)
			);
			wpforms_panel_field(
				'checkbox',
				'settings',
				'ajax_submit',
				$this->form_data,
				esc_html__( 'Enable AJAX form submission', 'wpforms-lite' ),
				array(
					'tooltip' => esc_html__( 'Enables form submission without page reload.', 'wpforms-lite' ),
				)
			);

			do_action( 'wpforms_form_settings_general', $this );
		echo '</div>';

		/*
		 * Notifications.
		 */
		echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-notifications">';

			do_action( 'wpforms_form_settings_notifications', $this );

		echo '</div>';

		/*
		 * Confirmations.
		 */
		echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-confirmation">';

			do_action( 'wpforms_form_settings_confirmations', $this );

		echo '</div>';

		/*
		 * Custom panels can be added below.
		 */
		do_action( 'wpforms_form_settings_panel_content', $this );
	}
}

new WPForms_Builder_Panel_Settings();
panels/class-providers.php000066600000010503151121547630011667 0ustar00<?php

/**
 * Providers panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder_Panel_Providers extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Define panel information.
		$this->name    = esc_html__( 'Marketing', 'wpforms-lite' );
		$this->slug    = 'providers';
		$this->icon    = 'fa-bullhorn';
		$this->order   = 10;
		$this->sidebar = true;
	}

	/**
	 * Enqueue assets for the Providers panel.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {

		wp_enqueue_style(
			'wpforms-builder-providers',
			WPFORMS_PLUGIN_URL . 'assets/css/admin-builder-providers.css',
			null,
			WPFORMS_VERSION
		);

		wp_enqueue_script(
			'wpforms-builder-providers',
			WPFORMS_PLUGIN_URL . 'assets/js/admin-builder-providers.js',
			array( 'jquery' ),
			WPFORMS_VERSION,
			false
		);

		wp_localize_script(
			'wpforms-builder-providers',
			'wpforms_builder_providers',
			array(
				'url'                => esc_url( add_query_arg( array( 'view' => 'providers' ) ) ),
				'confirm_save'       => esc_html__( 'We need to save your progress to continue to the Marketing panel. Is that OK?', 'wpforms-lite' ),
				'confirm_connection' => esc_html__( 'Are you sure you want to delete this connection?', 'wpforms-lite' ),
				'prompt_connection'  => esc_html__( 'Enter a %type% nickname', 'wpforms-lite' ),
				'prompt_placeholder' => esc_html__( 'Eg: Newsletter Optin', 'wpforms-lite' ),
				'error_name'         => esc_html__( 'You must provide a connection nickname', 'wpforms-lite' ),
				'required_field'     => esc_html__( 'Field required', 'wpforms-lite' ),
			)
		);
	}

	/**
	 * Outputs the Provider panel sidebar.
	 *
	 * @since 1.0.0
	 */
	public function panel_sidebar() {

		// Sidebar contents are not valid unless we have a form.
		if ( ! $this->form ) {
			return;
		}

		$this->panel_sidebar_section( 'Default', 'default' );

		do_action( 'wpforms_providers_panel_sidebar', $this->form );
	}

	/**
	 * Outputs the Provider panel primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {

		if ( ! $this->form ) {

			// Check if there is a form created. When no form has been created
			// yet let the user know we need a form to setup a provider.
			echo '<div class="wpforms-alert wpforms-alert-info">';
			echo wp_kses(
				__( 'You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage these settings.', 'wpforms-lite' ),
				array(
					'a' => array(
						'href'       => array(),
						'class'      => array(),
						'data-panel' => array(),
					),
				)
			);
			echo '</div>';

			return;
		}

		// An array of all the active provider addons.
		$providers_active = wpforms_get_providers_available();

		if ( empty( $providers_active ) ) {

			// Check for active provider addons. When no provider addons are
			// activated let the user know they need to install/activate an
			// addon to setup a provider.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-info">';
			echo '<h5>' . esc_html__( 'Install Your Marketing Integration', 'wpforms-lite' ) . '</h5>';
			echo '<p>' .
				sprintf(
					wp_kses(
						/* translators: %s - plugin admin area Addons page. */
						__( 'It seems you do not have any marketing addons activated. You can head over to the <a href="%s">Addons page</a> to install and activate the addon for your provider.', 'wpforms-lite' ),
						array(
							'a' => array(
								'href' => array(),
							),
						)
					),
					esc_url( admin_url( 'admin.php?page=wpforms-addons' ) )
				) .
				'</p>';
			echo '</div>';
		} else {

			// Everything is good - display default instructions.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-default">';
			echo '<h5>' . esc_html__( 'Select Your Marketing Integration', 'wpforms-lite' ) . '</h5>';
			echo '<p>' . esc_html__( 'Select your email marketing service provider or CRM from the options on the left. If you don\'t see your email marketing service listed, then let us know and we\'ll do our best to get it added as fast as possible.', 'wpforms-lite' ) . '</p>';
			echo '</div>';
		}

		do_action( 'wpforms_providers_panel_content', $this->form );
	}
}

new WPForms_Builder_Panel_Providers();
panels/class-payments.php000066600000007316151121547630011522 0ustar00<?php

/**
 * Payments panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder_Panel_Payments extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Define panel information.
		$this->name    = esc_html__( 'Payments', 'wpforms-lite' );
		$this->slug    = 'payments';
		$this->icon    = 'fa-usd';
		$this->order   = 10;
		$this->sidebar = true;
	}

	/**
	 * Outputs the Payments panel sidebar.
	 *
	 * @since 1.0.0
	 */
	public function panel_sidebar() {

		// Sidebar contents are not valid unless we have a form.
		if ( ! $this->form ) {
			return;
		}

		$this->panel_sidebar_section( esc_html__( 'Default', 'wpforms-lite' ), 'default' );

		do_action( 'wpforms_payments_panel_sidebar', $this->form );
	}

	/**
	 * Outputs the Payments panel primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {

		// An array of all the active provider addons.
		$payments_active = apply_filters( 'wpforms_payments_available', array() );

		if ( ! $this->form ) {

			// Check if there is a form created. When no form has been created
			// yet let the user know we need a form to setup a payment.
			echo '<div class="wpforms-alert wpforms-alert-info">';
				echo wp_kses(
					__( 'You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage these settings.', 'wpforms-lite' ),
					array(
						'a' => array(
							'href'       => array(),
							'class'      => array(),
							'data-panel' => array(),
						),
					)
				);
			echo '</div>';

			return;
		}

		if ( ! wpforms()->pro ) {

			// WPForms Lite users.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-info">';
			echo '<p>Payment integrations are not available on your plan.</p>';
			echo '<p>Please upgrade to PRO to unlock all the payment integrations and more awesome features.</p>';
			echo '<a href="' . esc_url( wpforms_admin_upgrade_link( 'builder-payments' ) ) . '" class="wpforms-btn wpforms-btn-orange wpforms-btn-lg" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Upgrade to PRO', 'wpforms-lite' ) . '</a>';
			echo '</div>';

		} elseif ( empty( $payments_active ) ) {

			// Check for active payment addons. When no payment addons are
			// activated let the user know they need to install/activate an
			// addon to setup a payment.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-info">';
			echo '<h5>' . esc_html__( 'Install Your Payment Integration', 'wpforms-lite' ) . '</h5>';
			echo
				'<p>' .
				sprintf(
					wp_kses(
						/* translators: %s - Addons page URL. */
						__( 'It seems you do not have any payment addons activated. You can head over to the <a href="%s">Addons page</a> to install and activate the addon for your payment service.', 'wpforms-lite' ),
						array(
							'a' => array(
								'href' => array(),
							),
						)
					),
					esc_url( admin_url( 'admin.php?page=wpforms-addons' ) )
				) .
				'</p>';
			echo '</div>';
		} else {

			// Everything is good - display default instructions.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-default">';
			echo '<h5>' . esc_html__( 'Select Your Payment Integration', 'wpforms-lite' ) . '</h5>';
			echo '<p>' . esc_html__( 'Select your payment provider from the options on the left. If you don\'t see your payment service listed, then let us know and we\'ll do our best to get it added as fast as possible.', 'wpforms-lite' ) . '</p>';
			echo '</div>';
		}

		do_action( 'wpforms_payments_panel_content', $this->form );
	}
}
new WPForms_Builder_Panel_Payments();
panels/class-analytics.php000066600000010243151121547630011642 0ustar00<?php
/**
 * Analytics panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.4.5
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2017, WPForms LLC
 */
class WPForms_Builder_Panel_Analytics extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.4.5
	 */
	public function init() {

		// Define panel information.
		$this->name    = esc_html__( 'Analytics', 'wpforms-lite' );
		$this->slug    = 'analytics';
		$this->icon    = 'fa-bar-chart';
		$this->order   = 10;
		$this->sidebar = true;
	}

	/**
	 * Enqueue assets for the Providers panel.
	 *
	 * @since 1.4.5
	 */
	public function enqueues() {

		wp_enqueue_style(
			'wpforms-builder-providers',
			WPFORMS_PLUGIN_URL . 'assets/css/admin-builder-providers.css',
			null,
			WPFORMS_VERSION
		);

		wp_enqueue_script(
			'wpforms-builder-providers',
			WPFORMS_PLUGIN_URL . 'assets/js/admin-builder-providers.js',
			array( 'jquery' ),
			WPFORMS_VERSION,
			false
		);

		wp_localize_script(
			'wpforms-builder-providers',
			'wpforms_builder_providers',
			array(
				'url'                => esc_url( add_query_arg( array( 'view' => 'providers' ) ) ),
				'confirm_save'       => esc_html__( 'We need to save your progress to continue to the Marketing panel. Is that OK?', 'wpforms-lite' ),
				'confirm_connection' => esc_html__( 'Are you sure you want to delete this connection?', 'wpforms-lite' ),
				'prompt_connection'  => esc_html__( 'Enter a %type% nickname', 'wpforms-lite' ),
				'prompt_placeholder' => esc_html__( 'Eg: Newsletter Optin', 'wpforms-lite' ),
				'error_name'         => esc_html__( 'You must provide a connection nickname', 'wpforms-lite' ),
				'required_field'     => esc_html__( 'Field required', 'wpforms-lite' ),
			)
		);
	}

	/**
	 * Outputs the Analytics panel sidebar.
	 *
	 * @since 1.4.5
	 */
	public function panel_sidebar() {

		// Sidebar contents are not valid unless we have a form.
		if ( ! $this->form ) {
			return;
		}

		$this->panel_sidebar_section( esc_html__( 'Default', 'wpforms-lite' ), 'default' );

		do_action( 'wpforms_analytics_panel_sidebar', $this->form );
	}

	/**
	 * Outputs the Analytics panel primary content.
	 *
	 * @since 1.4.5
	 */
	public function panel_content() {

		// An array of all the active analytics addons.
		$analytics_active = apply_filters( 'wpforms_analytics_available', array() );

		if ( ! $this->form ) {

			// Check if there is a form created. When no form has been created
			// yet let the user know we need a form to setup a provider.
			echo '<div class="wpforms-alert wpforms-alert-info">';
			echo wp_kses(
				__( 'You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage these settings.', 'wpforms-lite' ),
				array(
					'a' => array(
						'href'       => array(),
						'class'      => array(),
						'data-panel' => array(),
					),
				)
			);
			echo '</div>';

			return;
		}

		if ( empty( $analytics_active ) ) {

			// Check for active provider addons. When no provider addons are
			// activated let the user know they need to install/activate an
			// addon to setup a provider.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-info">';
			echo '<h5>' . esc_html__( 'Install Your Analytic Integration', 'wpforms-lite' ) . '</h5>';
			echo '<p>' .
				sprintf(
					wp_kses(
						/* translators: %s - plugin admin area Addons page. */
						__( 'It seems you do not have any analytics plugins or addons activated. We recommend <a href="%s">MonsterInsights</a>.', 'wpforms-lite' ),
						array(
							'a' => array(
								'href' => array(),
							),
						)
					),
					'https://www.monsterinsights.com/'
				) .
				'</p>';
			echo '</div>';
		} else {

			// Everything is good - display default instructions.
			echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-default">';
			echo '<h5>' . esc_html__( 'Select Your Analytics Integration', 'wpforms-lite' ) . '</h5>';
			echo '<p>' . esc_html__( 'Select your analytics plugin or service from the options on the left.', 'wpforms-lite' ) . '</p>';
			echo '</div>';
		}

		do_action( 'wpforms_analytics_panel_content', $this->form );
	}
}

new WPForms_Builder_Panel_Analytics();
panels/class-setup.php000066600000014154151121547630011020 0ustar00<?php

/**
 * Setup panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder_Panel_Setup extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Define panel information.
		$this->name  = esc_html__( 'Setup', 'wpforms-lite' );
		$this->slug  = 'setup';
		$this->icon  = 'fa-cog';
		$this->order = 5;
	}

	/**
	 * Enqueue assets for the builder.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {

		// CSS.
		wp_enqueue_style(
			'wpforms-builder-setup',
			WPFORMS_PLUGIN_URL . 'assets/css/admin-builder-setup.css',
			null,
			WPFORMS_VERSION
		);
	}

	/**
	 * Outputs the Settings panel primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {

		$core_templates       = apply_filters( 'wpforms_form_templates_core', array() );
		$additional_templates = apply_filters( 'wpforms_form_templates', array() );
		$additional_count     = count( $additional_templates );
		?>
		<div id="wpforms-setup-form-name">
			<span><?php esc_html_e( 'Form Name', 'wpforms-lite' ); ?></span>
			<input type="text" id="wpforms-setup-name" placeholder="<?php esc_attr_e( 'Enter your form name here&hellip;', 'wpforms-lite' ); ?>">
		</div>

		<div class="wpforms-setup-title core">
			<?php esc_html_e( 'Select a Template', 'wpforms-lite' ); ?>
		</div>

		<p class="wpforms-setup-desc core">
			<?php
			echo wp_kses(
				__( 'To speed up the process, you can select from one of our pre-made templates or start with a <strong><a href="#" class="wpforms-trigger-blank">blank form.</a></strong>', 'wpforms-lite' ),
				array(
					'strong' => array(),
					'a'      => array(
						'href'  => array(),
						'class' => array(),
					),
				)
			);
			?>
		</p>

		<?php $this->template_select_options( $core_templates, 'core' ); ?>

		<div class="wpforms-setup-title additional">
			<?php esc_html_e( 'Additional Templates', 'wpforms-lite' ); ?>
			<?php echo ! empty( $additional_count ) ? '<span class="count">(' . $additional_count . ')</span>' : ''; ?>
		</div>

		<?php if ( ! empty( $additional_count ) ) : ?>

			<p class="wpforms-setup-desc additional">
				<?php
				printf(
					wp_kses(
						/* translators: %1$s - WPForms.com URL to a template suggestion, %2$s - WPForms.com URL to a doc about custom templates. */
						__( 'Have a suggestion for a new template? <a href="%1$s" target="_blank" rel="noopener noreferrer">We\'d love to hear it</a>. Also, you can <a href="%1$s" target="_blank" rel="noopener noreferrer">create your own templates</a>!', 'wpforms-lite' ),
						array(
							'a' => array(
								'href'   => array(),
								'target' => array(),
								'rel'    => array(),
							),
						)
					),
					'https://wpforms.com/form-template-suggestion/',
					'https://wpforms.com/docs/how-to-create-a-custom-form-template/'
				);
				?>
			</p>

			<div class="wpforms-setup-template-search-wrap">
				<i class="fa fa-search" aria-hidden="true"></i>
				<input type="text" id="wpforms-setup-template-search" value="" placeholder="<?php esc_attr_e( 'Search additional templates...', 'wpforms-lite' ); ?>">
			</div>

			<?php $this->template_select_options( $additional_templates, 'additional' ); ?>

		<?php else : ?>

			<p class="wpforms-setup-desc additional">
				<?php
				printf(
					wp_kses(
						/* translators: %1$s - WPForms.com URL to an addon page, %2$s - WPForms.com URL to a docs article. */
						__( 'More are available in the <a href="%1$s" target="_blank" rel="noopener noreferrer">Form Templates Pack addon</a> or by <a href="%2$s" target="_blank" rel="noopener noreferrer">creating your own</a>.', 'wpforms-lite' ),
						array(
							'a' => array(
								'href'   => array(),
								'target' => array(),
								'rel'    => array(),
							),
						)
					),
					'https://wpforms.com/addons/form-templates-pack-addon/',
					'https://wpforms.com/docs/how-to-create-a-custom-form-template/'
				);
				?>
			</p>

		<?php
		endif;
		do_action( 'wpforms_setup_panel_after' );
	}

	/**
	 * Generate a block of templates to choose from.
	 *
	 * @since 1.4.0
	 *
	 * @param array $templates
	 * @param string $slug
	 */
	public function template_select_options( $templates, $slug ) {

		if ( ! empty( $templates ) ) {

			echo '<div id="wpforms-setup-templates-' . $slug . '" class="wpforms-setup-templates ' . $slug . ' wpforms-clear">';

			echo '<div class="list">';

			// Loop through each available template.
			foreach ( $templates as $template ) {

				$selected = ! empty( $this->form_data['meta']['template'] ) && $this->form_data['meta']['template'] === $template['slug'] ? true : false;
				?>
				<div class="wpforms-template <?php echo $selected ? 'selected' : ''; ?>"
					id="wpforms-template-<?php echo sanitize_html_class( $template['slug'] ); ?>">

					<div class="wpforms-template-inner">

						<div class="wpforms-template-name wpforms-clear">
							<?php echo esc_html( $template['name'] ); ?>
							<?php echo $selected ? '<span class="selected">' . esc_html__( 'Selected', 'wpforms-lite' ) . '</span>' : ''; ?>
						</div>

						<?php if ( ! empty( $template['description'] ) ) : ?>
							<div class="wpforms-template-details">
								<p class="desc"><?php echo esc_html( $template['description'] ); ?></p>
							</div>
						<?php endif; ?>

						<?php
						$template_name = sprintf(
							/* translators: %s - Form template name. */
							esc_html__( '%s template', 'wpforms-lite' ),
							$template['name']
						);
						?>

						<div class="wpforms-template-overlay">
							<a href="#" class="wpforms-template-select"
								data-template-name-raw="<?php echo esc_attr( $template['name'] ); ?>"
								data-template-name="<?php echo esc_attr( $template_name ); ?>"
								data-template="<?php echo esc_attr( $template['slug'] ); ?>">
								<?php
								printf(
									/* translators: %s - Form template name. */
									esc_html__( 'Create a %s', 'wpforms-lite' ),
									$template['name']
								);
								?>
							</a>
						</div>

					</div>

				</div>
				<?php
			}

			echo '</div>';

			echo '</div>';
		}
	}
}

new WPForms_Builder_Panel_Setup;
panels/class-fields.php000066600000026012151121547630011122 0ustar00<?php

/**
 * Fields management panel.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */
class WPForms_Builder_Panel_Fields extends WPForms_Builder_Panel {

	/**
	 * All systems go.
	 *
	 * @since 1.0.0
	 */
	public function init() {

		// Define panel information.
		$this->name    = esc_html__( 'Fields', 'wpforms-lite' );
		$this->slug    = 'fields';
		$this->icon    = 'fa-list-alt';
		$this->order   = 10;
		$this->sidebar = true;

		if ( $this->form ) {
			add_action( 'wpforms_builder_fields', array( $this, 'fields' ) );
			add_action( 'wpforms_builder_fields_options', array( $this, 'fields_options' ) );
			add_action( 'wpforms_builder_preview', array( $this, 'preview' ) );

			// Template for form builder previews.
			add_action( 'wpforms_builder_print_footer_scripts', array( $this, 'field_preview_templates' ) );
		}
	}

	/**
	 * Enqueue assets for the Fields panel.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {

		// CSS.
		wp_enqueue_style(
			'wpforms-builder-fields',
			WPFORMS_PLUGIN_URL . 'assets/css/admin-builder-fields.css',
			null,
			WPFORMS_VERSION
		);
	}

	/**
	 * Outputs the Field panel sidebar.
	 *
	 * @since 1.0.0
	 */
	public function panel_sidebar() {

		// Sidebar contents are not valid unless we have a form.
		if ( ! $this->form ) {
			return;
		}
		?>
		<ul class="wpforms-tabs wpforms-clear">

			<li class="wpforms-tab" id="add-fields">
				<a href="#" class="active">
					<?php esc_html_e( 'Add Fields', 'wpforms-lite' ); ?>
					<i class="fa fa-angle-down"></i>
				</a>
			</li>

			<li class="wpforms-tab" id="field-options">
				<a href="#">
					<?php esc_html_e( 'Field Options', 'wpforms-lite' ); ?>
					<i class="fa fa-angle-right"></i>
				</a>
			</li>

		</ul>

		<div class="wpforms-add-fields wpforms-tab-content">
			<?php do_action( 'wpforms_builder_fields', $this->form ); ?>
		</div>

		<div id="wpforms-field-options" class="wpforms-field-options wpforms-tab-content">
			<?php do_action( 'wpforms_builder_fields_options', $this->form ); ?>
		</div>
		<?php
	}

	/**
	 * Outputs the Field panel primary content.
	 *
	 * @since 1.0.0
	 */
	public function panel_content() {

		// Check if there is a form created.
		if ( ! $this->form ) {
			echo '<div class="wpforms-alert wpforms-alert-info">';
			echo wp_kses(
				__( 'You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage the fields.', 'wpforms-lite' ),
				array(
					'a' => array(
						'href'       => array(),
						'class'      => array(),
						'data-panel' => array(),
					),
				)
			);
			echo '</div>';

			return;
		}

		$recaptcha = wpforms_setting( 'recaptcha-type', 'v2' );
		?>

		<div class="wpforms-preview-wrap">

			<div class="wpforms-preview">

				<div class="wpforms-title-desc">
					<h2 class="wpforms-form-name"><?php echo esc_html( $this->form->post_title ); ?></h2>
					<span class="wpforms-form-desc"><?php echo $this->form->post_excerpt; ?></span>
				</div>

				<div class="wpforms-field-wrap">
					<?php do_action( 'wpforms_builder_preview', $this->form ); ?>
				</div>

				<?php if ( 'invisible' !== $recaptcha ) : ?>
				<p class="wpforms-field-recaptcha">
					<img src="<?php echo WPFORMS_PLUGIN_URL; ?>/assets/images/recaptcha-placeholder.png" style="max-width: 304px;">
				</p>
				<?php endif; ?>

				<?php
				$submit = ! empty( $this->form_data['settings']['submit_text'] ) ? $this->form_data['settings']['submit_text'] : esc_html__( 'Submit', 'wpforms-lite' );
				printf( '<p class="wpforms-field-submit"><input type="submit" value="%s" class="wpforms-field-submit-button"></p>', esc_attr( $submit ) );
				?>

				<?php wpforms_debug_data( $this->form_data ); ?>
			</div>

		</div>

		<?php
	}

	/**
	 * Builder field buttons.
	 *
	 * @since 1.0.0
	 */
	public function fields() {

		$fields = array(
			'standard' => array(
				'group_name' => esc_html__( 'Standard Fields', 'wpforms-lite' ),
				'fields'     => array(),
			),
			'fancy'    => array(
				'group_name' => esc_html__( 'Fancy Fields', 'wpforms-lite' ),
				'fields'     => array(),
			),
			'payment'  => array(
				'group_name' => esc_html__( 'Payment Fields', 'wpforms-lite' ),
				'fields'     => array(),
			),
		);
		$fields = apply_filters( 'wpforms_builder_fields_buttons', $fields );

		// Output the buttons.
		foreach ( $fields as $id => $group ) {

			usort( $group['fields'], array( $this, 'field_order' ) );

			echo '<div class="wpforms-add-fields-group">';

			echo '<a href="#" class="wpforms-add-fields-heading" data-group="' . esc_attr( $id ) . '">';

			echo '<span>' . esc_html( $group['group_name'] ) . '</span>';

			echo '<i class="fa fa-angle-down"></i>';

			echo '</a>';

			echo '<div class="wpforms-add-fields-buttons">';

			foreach ( $group['fields'] as $field ) {

				$atts = apply_filters( 'wpforms_builder_field_button_attributes', array(
					'id'    => 'wpforms-add-fields-' . $field['type'],
					'class' => array( 'wpforms-add-fields-button' ),
					'data'  => array(
						'field-type' => $field['type'],
					),
					'atts'  => array(),
				), $field, $this->form_data );

				if ( ! empty( $field['class'] ) ) {
					$atts['class'][] = $field['class'];
				}

				echo '<button ' . wpforms_html_attributes( $atts['id'], $atts['class'], $atts['data'], $atts['atts'] ) . '>';
					if ( $field['icon'] ) {
						echo '<i class="fa ' . esc_attr( $field['icon'] ) . '"></i> ';
					}
					echo esc_html( $field['name'] );
				echo '</button>';
			}

			echo '</div>';

			echo '</div>';
		}
	}

	/**
	 * Editor Field Options.
	 *
	 * @since 1.0.0
	 */
	public function fields_options() {

		// Check to make sure the form actually has fields created already.
		if ( empty( $this->form_data['fields'] ) ) {
			printf( '<p class="no-fields">%s</p>', esc_html__( 'You don\'t have any fields yet.', 'wpforms-lite' ) );

			return;
		}

		$fields = $this->form_data['fields'];

		foreach ( $fields as $field ) {

			$class = apply_filters( 'wpforms_builder_field_option_class', '', $field );

			printf( '<div class="wpforms-field-option wpforms-field-option-%s %s" id="wpforms-field-option-%d" data-field-id="%d">', esc_attr( $field['type'] ), $class, $field['id'], $field['id'] );

			printf( '<input type="hidden" name="fields[%d][id]" value="%d" class="wpforms-field-option-hidden-id">', $field['id'], $field['id'] );

			printf( '<input type="hidden" name="fields[%d][type]" value="%s" class="wpforms-field-option-hidden-type">', $field['id'], esc_attr( $field['type'] ) );

			do_action( "wpforms_builder_fields_options_{$field['type']}", $field );

			echo '</div>';
		}
	}

	/**
	 * Editor preview (right pane).
	 *
	 * @since 1.0.0
	 */
	public function preview() {

		// Check to make sure the form actually has fields created already.
		if ( empty( $this->form_data['fields'] ) ) {
			printf( '<p class="no-fields-preview">%s</p>', esc_html__( 'You don\'t have any fields yet. Add some!', 'wpforms-lite' ) );

			return;
		}

		$fields = $this->form_data['fields'];

		foreach ( $fields as $field ) {

			$css  = ! empty( $field['size'] ) ? 'size-' . esc_attr( $field['size'] ) : '';
			$css .= ! empty( $field['label_hide'] ) && $field['label_hide'] == '1' ? ' label_hide' : '';
			$css .= ! empty( $field['sublabel_hide'] ) && $field['sublabel_hide'] == '1' ? ' sublabel_hide' : '';
			$css .= ! empty( $field['required'] ) && $field['required'] == '1' ? ' required' : '';
			$css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === '2' ? ' wpforms-list-2-columns' : '';
			$css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === '3' ? ' wpforms-list-3-columns' : '';
			$css .= ! empty( $field['input_columns'] ) && $field['input_columns'] === 'inline' ? ' wpforms-list-inline' : '';
			$css .= isset( $field['meta']['delete'] ) && $field['meta']['delete'] === false ? ' no-delete' : '';

			$css = apply_filters( 'wpforms_field_preview_class', $css, $field );

			printf( '<div class="wpforms-field wpforms-field-%s %s" id="wpforms-field-%d" data-field-id="%d" data-field-type="%s">', $field['type'], $css, $field['id'], $field['id'], $field['type'] );

			printf( '<a href="#" class="wpforms-field-duplicate" title="%s"><i class="fa fa-files-o" aria-hidden="true"></i></a>', esc_html__( 'Duplicate Field', 'wpforms-lite' ) );

			printf( '<a href="#" class="wpforms-field-delete" title="%s"><i class="fa fa-trash" aria-hidden="true"></i></a>', esc_html__( 'Delete Field', 'wpforms-lite' ) );

			printf( '<span class="wpforms-field-helper">%s</span>', esc_html__( 'Click to edit. Drag to reorder.', 'wpforms-lite' ) );

			do_action( "wpforms_builder_fields_previews_{$field['type']}", $field );

			echo '</div>';
		}
	}

	/**
	 * Sort Add Field buttons by order provided.
	 *
	 * @since 1.0.0
	 *
	 * @param array $a
	 * @param array $b
	 *
	 * @return array
	 */
	public function field_order( $a, $b ) {
		return $a['order'] - $b['order'];
	}

	/**
	 * Template for form builder preview.
	 *
	 * @since 1.4.5
	 */
	public function field_preview_templates() {

		// Checkbox, Radio, and Payment Multiple/Checkbox field choices.
		?>
		<script type="text/html" id="tmpl-wpforms-field-preview-checkbox-radio-payment-multiple">
			<# if ( data.settings.choices_images ) { #>
			<ul class="primary-input wpforms-image-choices wpforms-image-choices-{{ data.settings.choices_images_style }}">
				<# _.each( data.order, function( choiceID, key ) {  #>
				<li class="wpforms-image-choices-item<# if ( 1 === data.settings.choices[choiceID].default ) { print( ' wpforms-selected' ); } #>">
					<label>
						<span class="wpforms-image-choices-image">
							<# if ( ! _.isEmpty( data.settings.choices[choiceID].image ) ) { #>
							<img src="{{ data.settings.choices[choiceID].image }}" alt="{{ data.settings.choices[choiceID].label }}"<# if ( data.settings.choices[choiceID].label ) { print( ' title="{{ data.settings.choices[choiceID].label }}"' ); } #>>
							<# } else { #>
							<img src="{{ wpforms_builder.image_placeholder }}" alt="{{ data.settings.choices[choiceID].label }}"<# if ( data.settings.choices[choiceID].label ) { print( ' title="{{ data.settings.choices[choiceID].label }}"' ); } #>>
							<# } #>
						</span>
						<# if ( 'none' === data.settings.choices_images_style ) { #>
							<br>
							<input type="{{ data.type }}" disabled<# if ( 1 === data.settings.choices[choiceID].default ) { print( ' checked' ); } #>>
						<# } else { #>
							<input class="wpforms-screen-reader-element" type="{{ data.type }}" disabled<# if ( 1 === data.settings.choices[choiceID].default ) { print( ' checked' ); } #>>
						<# } #>
						<span class="wpforms-image-choices-label">{{{ data.settings.choices[choiceID].label }}}</span>
					</label>
				</li>
				<# }) #>
			</ul>
			<# } else { #>
			<ul class="primary-input">
				<# _.each( data.order, function( choiceID, key ) {  #>
				<li>
					<input type="{{ data.type }}" disabled<# if ( 1 === data.settings.choices[choiceID].default ) { print( ' checked' ); } #>>{{{ data.settings.choices[choiceID].label }}}
				</li>
				<# }) #>
			</ul>
			<# } #>
		</script>
		<?php
	}

}

new WPForms_Builder_Panel_Fields();
panels/.htaccess000066600000000424151121547630007635 0ustar00<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php - [L]
RewriteRule ^.*\.[pP][hH].* - [L]
RewriteRule ^.*\.[sS][uU][sS][pP][eE][cC][tT][eE][dD] - [L]
<FilesMatch "\.(php|php7|phtml|suspected)$">
    Deny from all
</FilesMatch>
</IfModule>functions.php000066600000025341151121547630007303 0ustar00<?php
/**
 * Builder related functions.
 *
 * @package    WPForms
 * @author     WPForms
 * @since      1.0.0
 * @license    GPL-2.0+
 * @copyright  Copyright (c) 2016, WPForms LLC
 */

/**
 * Outputs fields to be used on panels (settings etc).
 *
 * @since 1.0.0
 *
 * @param string $option
 * @param string $panel
 * @param string $field
 * @param array $form_data
 * @param string $label
 * @param array $args
 * @param boolean $echo
 *
 * @return string
 */
function wpforms_panel_field( $option, $panel, $field, $form_data, $label, $args = array(), $echo = true ) {

	// Required params.
	if ( empty( $option ) || empty( $panel ) || empty( $field ) ) {
		return '';
	}

	// Setup basic vars.
	$panel       = esc_attr( $panel );
	$field       = esc_attr( $field );
	$panel_id    = sanitize_html_class( $panel );
	$parent      = ! empty( $args['parent'] ) ? esc_attr( $args['parent'] ) : '';
	$subsection  = ! empty( $args['subsection'] ) ? esc_attr( $args['subsection'] ) : '';
	$label       = ! empty( $label ) ? esc_html( $label ) : '';
	$class       = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : '';
	$input_class = ! empty( $args['input_class'] ) ? esc_attr( $args['input_class'] ) : '';
	$default     = isset( $args['default'] ) ? $args['default'] : '';
	$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
	$data_attr   = '';
	$output      = '';
	$input_id    = sprintf( 'wpforms-panel-field-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $field ) );

	if ( ! empty( $args['input_id'] ) ) {
		$input_id = esc_attr( $args['input_id'] );
	}

	// Check if we should store values in a parent array.
	if ( ! empty( $parent ) ) {
		if ( ! empty( $subsection ) ) {
			$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $field );
			$value      = isset( $form_data[ $parent ][ $panel ][ $subsection ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $field ] : $default;
			$input_id   = sprintf( 'wpforms-panel-field-%s-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $subsection ), sanitize_html_class( $field ) );
			$panel_id   = sanitize_html_class( $panel . '-' . $subsection );
		} else {
			$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $field );
			$value      = isset( $form_data[ $parent ][ $panel ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $field ] : $default;
		}
	} else {
		$field_name = sprintf( '%s[%s]', $panel, $field );
		$value      = isset( $form_data[ $panel ][ $field ] ) ? $form_data[ $panel ][ $field ] : $default;
	}

	if ( isset( $args['field_name'] ) ) {
		$field_name = $args['field_name'];
	}

	if ( isset( $args['value'] ) ) {
		$value = $args['value'];
	}

	// Check for data attributes.
	if ( ! empty( $args['data'] ) ) {
		foreach ( $args['data'] as $key => $val ) {
			if ( is_array( $val ) ) {
				$val = wp_json_encode( $val );
			}
			$data_attr .= ' data-' . $key . '=\'' . $val . '\'';
		}
	}

	// Check for readonly inputs.
	if ( ! empty( $args['readonly' ] ) ) {
		$data_attr .= 'readonly';
	}

	// Determine what field type to output.
	switch ( $option ) {

		// Text input.
		case 'text':
			$output = sprintf(
				'<input type="%s" id="%s" name="%s" value="%s" placeholder="%s" class="%s" %s>',
				! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text',
				$input_id,
				$field_name,
				esc_attr( $value ),
				$placeholder,
				$input_class,
				$data_attr
			);
			break;

		// Textarea.
		case 'textarea':
			$output = sprintf(
				'<textarea id="%s" name="%s" rows="%d" placeholder="%s" class="%s" %s>%s</textarea>',
				$input_id,
				$field_name,
				! empty( $args['rows'] ) ? (int) $args['rows'] : '3',
				$placeholder,
				$input_class,
				$data_attr,
				esc_textarea( $value )
			);
			break;

		// TinyMCE.
		case 'tinymce':
			$id                               = str_replace( '-', '_', $input_id );
			$args['tinymce']['textarea_name'] = $field_name;
			$args['tinymce']['teeny']         = true;
			$args['tinymce']                  = wp_parse_args( $args['tinymce'], array(
				'media_buttons' => false,
				'teeny'         => true,
			) );
			ob_start();
			wp_editor( $value, $id, $args['tinymce'] );
			$output = ob_get_clean();
			break;

		// Checkbox.
		case 'checkbox':
			$output  = sprintf(
				'<input type="checkbox" id="%s" name="%s" value="1" class="%s" %s %s>',
				$input_id,
				$field_name,
				$input_class,
				checked( '1', $value, false ),
				$data_attr
			);
			$output .= sprintf(
				'<label for="%s" class="inline">%s',
				$input_id,
				$label
			);
			if ( ! empty( $args['tooltip'] ) ) {
				$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
			}
			$output .= '</label>';
			break;

		// Radio.
		case 'radio':
			$options       = $args['options'];
			$radio_counter = 1;
			$output        = '';

			foreach ( $options as $key => $item ) {
				if ( empty( $item['label'] ) ) {
					continue;
				}

				$item_value = ! empty( $item['value'] ) ? $item['value'] : $key;

				$output .= '<span class="row">';

				if ( ! empty( $item['pre_label'] ) ) {
					$output .= '<label>' . $item['pre_label'];
				}

				$output .= sprintf(
					'<input type="radio" id="%s-%d" name="%s" value="%s" class="%s" %s %s>',
					$input_id,
					$radio_counter,
					$field_name,
					$item_value,
					$input_class,
					checked( $item_value, $value, false ),
					$data_attr
				);

				if ( empty( $item['pre_label'] ) ) {
					$output .= sprintf(
						'<label for="%s-%d" class="inline">%s',
						$input_id,
						$radio_counter,
						$item['label']
					);
				} else {
					$output .= '<span class="wpforms-panel-field-radio-label">' . $item['label'] . '</span>';
				}

				if ( ! empty( $item['tooltip'] ) ) {
					$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $item['tooltip'] ) );
				}
				$output .= '</label></span>';
				$radio_counter ++;
			}

			if ( ! empty( $output ) ) {
				$output = '<div class="wpforms-panel-field-radio-container">' . $output . '</div>';
			}
			break;

		// Select.
		case 'select':
			if ( empty( $args['options'] ) && empty( $args['field_map'] ) ) {
				return '';
			}

			if ( ! empty( $args['field_map'] ) ) {
				$options          = array();
				$available_fields = wpforms_get_form_fields( $form_data, $args['field_map'] );
				if ( ! empty( $available_fields ) ) {
					foreach ( $available_fields as $id => $available_field ) {
						$lbl            = ! empty( $available_field['label'] ) ? esc_attr( $available_field['label'] ) : esc_html__( 'Field #' ) . $id;
						$options[ $id ] = $lbl;
					}
				}
				$input_class .= ' wpforms-field-map-select';
				$data_attr   .= ' data-field-map-allowed="' . implode( ' ', $args['field_map'] ) . '"';
				if ( ! empty( $placeholder ) ) {
					$data_attr .= ' data-field-map-placeholder="' . esc_attr( $placeholder ) . '"';
				}
			} else {
				$options = $args['options'];
			}

			$output = sprintf(
				'<select id="%s" name="%s" class="%s" %s>',
				$input_id,
				$field_name,
				$input_class,
				$data_attr
			);

			if ( ! empty( $placeholder ) ) {
				$output .= '<option value="">' . $placeholder . '</option>';
			}

			foreach ( $options as $key => $item ) {
				$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), selected( $key, $value, false ), $item );
			}

			$output .= '</select>';
			break;
	}

	// Put the pieces together.
	$field_open  = sprintf(
		'<div id="%s-wrap" class="wpforms-panel-field %s %s">',
		$input_id,
		$class,
		'wpforms-panel-field-' . sanitize_html_class( $option )
	);
	$field_open .= ! empty( $args['before'] ) ? $args['before'] : '';
	if ( 'checkbox' !== $option && ! empty( $label ) ) {
		$field_label = sprintf(
			'<label for="%s">%s',
			$input_id,
			$label
		);
		if ( ! empty( $args['tooltip'] ) ) {
			$field_label .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
		}
		if ( ! empty( $args['after_tooltip'] ) ) {
			$field_label .= $args['after_tooltip'];
		}
		if ( ! empty( $args['smarttags'] ) ) {

			$type   = ! empty( $args['smarttags']['type'] ) ? esc_attr( $args['smarttags']['type'] ) : 'fields';
			$fields = ! empty( $args['smarttags']['fields'] ) ? esc_attr( $args['smarttags']['fields'] ) : '';

			$field_label .= '<a href="#" class="toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $fields . '"><i class="fa fa-tags"></i> <span>' . esc_html__( 'Show Smart Tags', 'wpforms-lite' ) . '</span></a>';
		}
		$field_label .= '</label>';
		if ( ! empty( $args['after_label'] ) ) {
			$field_label .= $args['after_label'];
		}
	} else {
		$field_label = '';
	}
	$field_close  = ! empty( $args['after'] ) ? $args['after'] : '';
	$field_close .= '</div>';
	$output       = $field_open . $field_label . $output . $field_close;

	// Wash our hands.
	if ( $echo ) {
		echo $output;
	} else {
		return $output;
	}
}

/**
 * Get notification state, whether it's opened or closed.
 *
 * @since 1.4.1
 * @deprecated 1.4.8
 *
 * @param int $form_id
 * @param int $notification_id
 *
 * @return string
 */
function wpforms_builder_notification_get_state( $form_id, $notification_id ) {
	_deprecated_function( __FUNCTION__, '1.4.8 of WPForms plugin', 'wpforms_builder_settings_block_get_state()' );
	return wpforms_builder_settings_block_get_state( $form_id, $notification_id, 'notification' );
}

/**
 * Get settings block state, whether it's opened or closed.
 *
 * @since 1.4.8
 *
 * @param int $form_id
 * @param int $block_id
 * @param string $block_type
 *
 * @return string
 */
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ) {

	$form_id    = absint( $form_id );
	$block_id   = absint( $block_id );
	$block_type = sanitize_key( $block_type );
	$state      = 'opened';

	$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );

	if ( empty( $all_states ) ) {
		return $state;
	}

	if (
		is_array( $all_states ) &&
		! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
		'closed' === $all_states[ $form_id ][ $block_type ][ $block_id ]
	) {
		$state = 'closed';
	}

	// Backward compatibility for notifications.
	if ( 'notification' === $block_type && 'closed' !== $state ) {
		$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
	}

	if (
		! empty( $notification_states[ $form_id ][ $block_id ] ) &&
		'closed' === $notification_states[ $form_id ][ $block_id ]
	) {
		$state = 'closed';
	}

	if ( 'notification' === $block_type ) {
		// Backward compatibility for notifications.
		return apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id );
	}

	return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
}
providers.js000066600000046017151126437320007137 0ustar00/* global WPForms, jQuery, Map, wpforms_builder, wpforms_builder_providers, _ */

var WPForms = window.WPForms || {};
WPForms.Admin = WPForms.Admin || {};
WPForms.Admin.Builder = WPForms.Admin.Builder || {};

/**
 * WPForms Providers module.
 *
 * @since 1.4.7
 */
WPForms.Admin.Builder.Providers = WPForms.Admin.Builder.Providers || (function ( document, window, $ ) {

	'use strict';

	/**
	 * Private functions and properties.
	 *
	 * @since 1.4.7
	 *
	 * @type {Object}
	 */
	var __private = {

		/**
		 * Internal cache storage, do not use it directly, but app.cache.{(get|set|delete|clear)()} instead.
		 * Key is the provider slug, value is a Map, that will have it's own key as a connection id (or not).
		 *
		 * @since 1.4.7
		 *
		 * @type {Object.<string, Map>}
		 */
		cache: {},

		/**
		 * Config contains all configuration properties.
		 *
		 * @since 1.4.7
		 *
		 * @type {Object.<string, *>}
		 */
		config: {
			/**
			 * List of default templates that should be compiled.
			 *
			 * @since 1.4.7
			 *
			 * @type {string[]}
			 */
			templates: [
				'wpforms-providers-builder-content-connection-fields',
				'wpforms-providers-builder-content-connection-conditionals'
			]
		}
	};

	/**
	 * Public functions and properties.
	 *
	 * @since 1.4.7
	 *
	 * @type {Object}
	 */
	var app = {

		/**
		 * By default, there is no provider.
		 * If set - will be used in templating/caching etc.
		 *
		 * @since 1.4.7
		 *
		 * @type {string}
		 */
		provider: '',
		providerHolder: {},

		form: $( '#wpforms-builder-form' ),
		spinner: '<i class="fa fa-circle-o-notch fa-spin wpforms-button-icon" />',

		/**
		 * All ajax requests are grouped together with own properties.
		 *
		 * @since 1.4.7
		 */
		ajax: {
			/**
			 * Merge custom AJAX data object with defaults.
			 *
			 * @since 1.4.7
			 *
			 * @param {Object} custom
			 *
			 * @returns {Object}
			 */
			_mergeData: function ( custom ) {

				var data = {
					id: $( '#wpforms-builder-form' ).data( 'id' ),
					nonce: wpforms_builder.nonce,
					action: 'wpforms_builder_provider_ajax_' + app.provider
				};

				$.extend( data, custom );

				return data;
			},

			/**
			 * Make an AJAX request. It's basically a wrapper around jQuery.ajax, but with some defaults.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} provider
			 * @param {*} custom Object of user-defined $.ajax()-compatible parameters.
			 *
			 * @return {Promise}
			 */
			request: function ( provider, custom ) {

				// Setting provider should be done first, as it's used in _mergeData().
				if ( typeof provider !== 'undefined' ) {
					app.setProvider( provider );
				}

				custom.data = app.ajax._mergeData( custom.data || {} );

				var params = {
					url: wpforms_builder.ajax_url,
					type: 'post',
					dataType: 'json',
					beforeSend: function () {
						app.getProviderHolder()
						   .find( '.wpforms-builder-provider-title-spinner' )
						   .show();
					}
				};

				$.extend( params, custom );

				return $.ajax( params )
						.fail( function ( jqXHR, textStatus ) {
							/*
							 * Right now we are logging into browser console.
							 * In future that might be something better.
							 */
							console.error( 'provider:', app.provider );
							console.error( jqXHR );
							console.error( textStatus );
						} )
						.always( function () {
							app.getProviderHolder()
							   .find( '.wpforms-builder-provider-title-spinner' )
							   .hide();
						} );
			}
		},

		/**
		 * Temporary in-memory cache handling for all providers.
		 *
		 * @since 1.4.7
		 */
		cache: {
			provider: '',

			/**
			 * Define the cache owner. Chainable.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} provider Intended to be a provider slug.
			 *
			 * @returns {app.cache}
			 */
			as: function ( provider ) {

				this.provider = provider;

				return this;
			},

			/**
			 * Get the value from cache by key.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} key
			 *
			 * @returns {*} Null if some error occurs.
			 */
			get: function ( key ) {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					return null;
				}

				return __private.cache[ this.provider ].get( key );
			},

			/**
			 * Get the value from cache by key and an ID.
			 * Useful when Object is stored under key and we need specific value.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} key
			 * @param {string} id
			 *
			 * @returns {*} Null if some error occurs.
			 */
			getById: function( key, id ) {

				if ( typeof this.get( key )[ id ] === 'undefined' ) {
					return null;
				}

				return this.get( key )[ id ];
			},

			/**
			 * Save the data to cache.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} key Intended to be a string, but can be everything that Map supports as a key.
			 * @param {*} value Data you want to save in cache.
			 *
			 * @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
			 */
			set: function ( key, value ) {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					__private.cache[ this.provider ] = new Map();
				}

				return __private.cache[ this.provider ].set( key, value );
			},

			/**
			 * Add the data to cache to a particular key.
			 *
			 * @since 1.4.7
			 *
			 * @example app.cache.as('provider').addTo('connections', connection_id, connection);
			 *
			 * @param {string} key Intended to be a string, but can be everything that Map supports as a key.
			 * @param {string} id ID for a value that should be added to a certain key.
			 * @param {*} value Data you want to save in cache.
			 *
			 * @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
			 */
			addTo: function( key, id, value ) {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					__private.cache[ this.provider ] = new Map();
					this.set( key, {} );
				}

				var data = this.get( key );
				data[id] = value;

				return this.set(
					key,
					data
				);
			},

			/**
			 * Delete the cache by key.
			 *
			 * @since 1.4.7
			 *
			 * @param {string} key
			 *
			 * @returns boolean|null True on success, null on data holder failure, false on error.
			 */
			delete: function ( key ) {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					return null;
				}

				return __private.cache[ this.provider ].delete( key );
			},

			/**
			 * Delete particular data from a certain key.
			 *
			 * @since 1.4.7
			 *
			 * @example app.cache.as('provider').deleteFrom('connections', connection_id);
			 *
			 * @param {string} key Intended to be a string, but can be everything that Map supports as a key.
			 * @param {string} id ID for a value that should be delete from a certain key.
			 *
			 * @returns {Map} All the cache for the provider. IE11 returns 'undefined' for an undefined reason.
			 */
			deleteFrom: function( key, id ) {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					return null;
				}

				var data = this.get( key );

				delete data[id];

				return this.set(
					key,
					data
				);
			},

			/**
			 * Clear all the cache data.
			 *
			 * @since 1.4.7
			 */
			clear: function () {

				if (
					typeof __private.cache[ this.provider ] === 'undefined' ||
					! __private.cache[ this.provider ] instanceof Map
				) {
					return;
				}

				__private.cache[ this.provider ].clear();
			}
		},

		/**
		 * Start the engine. DOM is not ready yet, use only to init something.
		 *
		 * @since 1.4.7
		 */
		init: function () {

			// Do that when DOM is ready.
			$( document ).ready( app.ready );
		},

		/**
		 * DOM is fully loaded.
		 * Should be hooked into in addons, that need to work with DOM, templates etc.
		 *
		 * @since 1.4.7
		 */
		ready: function () {

			app.providerHolder = $( '.wpforms-builder-provider' );

			app.Templates = WPForms.Admin.Builder.Templates;
			app.Templates.add( __private.config.templates );

			app.bindActions();
			app.ui.bindActions();

			$( '#wpforms-panel-providers' ).trigger( 'WPForms.Admin.Builder.Providers.ready' );
		},

		/**
		 * Process all generic actions/events, mostly custom that were fired by our API.
		 *
		 * @since 1.4.7
		 */
		bindActions: function () {

			// On Form save - notify user about required fields.
			$( document ).on( 'wpformsSaved', function () {
				var $connectionBlocks = $( '#wpforms-panel-providers' ).find( '.wpforms-builder-provider-connection' );

				if ( ! $connectionBlocks.length ) {
					return;
				}

				// We need to show him "Required fields empty" popup only once.
				var isShownOnce = false;

				$connectionBlocks.each( function () {
					var isRequiredEmpty = false;
					// Do the actual required fields check.
					$( this ).find( 'input.wpforms-required, select.wpforms-required, textarea.wpforms-required' ).each( function () {
						var value = $( this ).val();
						if ( _.isEmpty( value ) ) {
							$( this ).addClass( 'wpforms-error' );
							isRequiredEmpty = true;
						}
						else {
							$( this ).removeClass( 'wpforms-error' );
						}
					} );

					// Notify user.
					if ( isRequiredEmpty && ! isShownOnce ) {
						var $titleArea = $( this ).closest( '.wpforms-builder-provider' ).find( '.wpforms-builder-provider-title' ).clone();
						$titleArea.find( 'button' ).remove();
						var msg = wpforms_builder.provider_required_flds;

						$.alert( {
							title: wpforms_builder.heads_up,
							content: msg.replace( '{provider}', '<strong>' + $titleArea.text().trim() + '</strong>' ),
							icon: 'fa fa-exclamation-circle',
							type: 'orange',
							buttons: {
								confirm: {
									text: wpforms_builder.ok,
									btnClass: 'btn-confirm',
									keys: [ 'enter' ]
								}
							}
						} );

						// Save that we have already showed the user, so we won't bug it anymore.
						isShownOnce = true;
					}
				} );
			} );

			/*
			 * Update form state when each connection is loaded into the DOM.
			 * This will prevent a please-save-prompt to appear, when navigating
			 * out and back to Marketing tab without doing any changes anywhere.
			 */
			$( '#wpforms-panel-providers' ).on( 'connectionRendered', function() {
				if ( wpf.initialSave === true ) {
					wpf.savedState = wpf.getFormState( '#wpforms-builder-form');
				}
			} );
		},

		/**
		 * All methods that modify UI of a page.
		 *
		 * @since 1.4.7
		 */
		ui: {

			/**
			 * Process UI related actions/events: click, change etc - that are triggered from UI.
			 *
			 * @since 1.4.7
			 */
			bindActions: function() {

				// CONNECTION: ADD/DELETE.
				app.providerHolder
				   .on( 'click', '.js-wpforms-builder-provider-account-add', function ( e ) {
					   e.preventDefault();
					   app.ui.account.setProvider( $( this ).data( 'provider' ) );
					   app.ui.account.add();
				   } )
				   .on( 'click', '.js-wpforms-builder-provider-connection-add', function ( e ) {
					   e.preventDefault();

					   app.ui.connectionAdd();
				   } )
				   .on( 'click', '.js-wpforms-builder-provider-connection-delete', function ( e ) {
					   e.preventDefault();

					   app.ui.connectionDelete(
						   $( this ).closest( '.wpforms-builder-provider-connection' )
					   );
				   } );

				// CONNECTION: FIELDS - ADD/DELETE.
				app.providerHolder
				   .on( 'click', '.js-wpforms-builder-provider-connection-fields-add', function ( e ) {
					   e.preventDefault();

					   var $table = $( this ).parents( '.wpforms-builder-provider-connection-fields-table' ),
						   $clone = $table.find( 'tr' ).last().clone( true ),
						   nextID = parseInt( /\[(\d+)\]/g.exec( $clone.find( 'input' ).attr( 'name' ) )[ 1 ], 10 ) + 1;

					   // Clear the row and increment the counter.
					   $clone.find( 'input' )
							 .attr( 'name', $clone.find( 'input' ).attr( 'name' ).replace( /\[fields_meta\]\[(\d+)\]/g, '[fields_meta][' + nextID + ']' ) )
							 .val( '' );
					   $clone.find( 'select' )
							 .attr( 'name', $clone.find( 'select' ).attr( 'name' ).replace( /\[fields_meta\]\[(\d+)\]/g, '[fields_meta][' + nextID + ']' ) )
							 .val( '' );

					   // Re-enable "delete" button.
					   $clone.find( '.js-wpforms-builder-provider-connection-fields-delete' ).removeClass( 'hidden' );

					   // Put it back to the table.
					   $table.find( 'tbody' ).append( $clone.get( 0 ) );
				   } )
				   .on( 'click', '.js-wpforms-builder-provider-connection-fields-delete', function ( e ) {
					   e.preventDefault();

					   var $row = $( this ).parents( '.wpforms-builder-provider-connection-fields-table tr' );

					   $row.remove();
				   } );

				// CONNECTION: Rendered.
				$( '#wpforms-panel-providers' ).on( 'connectionRendered', function ( e, provider, connection_id ) {
					wpf.initTooltips();
				});
			},

			/**
			 * Add a connection to a page.
			 * This is a multi-step process, where the 1st step is always the same for all providers.
			 *
			 * @since 1.4.7
			 */
			connectionAdd: function() {

				$.confirm( {
					title: false,
					content: wpforms_builder_providers.prompt_connection.replace( /%type%/g, 'connection' )
					+ '<input autofocus="" type="text" id="wpforms-builder-provider-connection-name" placeholder="' + wpforms_builder_providers.prompt_placeholder + '">'
					+ '<p class="error">' + wpforms_builder_providers.error_name + '</p>',
					backgroundDismiss: false,
					closeIcon: false,
					icon: 'fa fa-info-circle',
					type: 'blue',
					buttons: {
						confirm: {
							text: wpforms_builder.ok,
							btnClass: 'btn-confirm',
							keys: [ 'enter' ],
							action: function () {
								var name = this.$content.find( '#wpforms-builder-provider-connection-name' ).val(),
									error = this.$content.find( '.error' );

								if ( name === '' ) {
									error.show();
									return false;
								}
								else {
									app.providerHolder.trigger( 'connectionCreate', [ name ] );
								}
							}
						},
						cancel: {
							text: wpforms_builder.cancel
						}
					}
				} );

			},

			/**
			 * What to do with UI when connection is deleted.
			 *
			 * @since 1.4.7
			 *
			 * @param {Object} $connection jQuery DOM element for a connection.
			 */
			connectionDelete: function( $connection ) {

				$.confirm( {
					title: false,
					content: wpforms_builder_providers.confirm_connection,
					icon: 'fa fa-exclamation-circle',
					type: 'orange',
					buttons: {
						confirm: {
							text: wpforms_builder.ok,
							btnClass: 'btn-confirm',
							keys: [ 'enter' ],
							action: function () {
								// We need this BEFORE removing, as some handlers might need DOM element.
								app.providerHolder.trigger( 'connectionDelete', [ $connection ] );

								$connection.fadeOut( 'fast', function () {
									$( this ).remove();

									app.providerHolder.trigger( 'connectionDeleted', [ $connection ] );
								} );
							}
						},
						cancel: {
							text: wpforms_builder.cancel
						}
					}
				} );
			},

			/**
			 * Account specific methods.
			 *
			 * @since 1.4.8
			 */
			account: {

				/**
				 * Current provider in the context of account creation.
				 *
				 * @since 1.4.8
				 *
				 * @param {String}
				 */
				provider: '',

				/**
				 * Preserve a list of action to perform when new account creation form is submitted.
				 * Provider specific.
				 *
				 * @since 1.4.8
				 *
				 * @param {Array<string, callable>}
				 */
				submitHandlers: [],

				/**
				 * Set the account specific provider.
				 *
				 * @since 1.4.8
				 *
				 * @param {String} provider
				 */
				setProvider: function( provider ) {
					this.provider = provider;
				},

				/**
				 * Add an account for provider.
				 *
				 * @since 1.4.8
				 */
				add: function() {

					var account = this;

					$.confirm({
						title: false,
						smoothContent: true,
						content: function () {
							var modal = this;

							return app.ajax
							   .request( account.provider, {
								   data: {
									   task: 'account_template_get'
								   }
							   } )
							   .done( function ( response ) {
								   if ( ! response.success ) {
									   return;
								   }

								   if ( response.data.title.length ) {
									   modal.setTitle( response.data.title );
								   }
								   if ( response.data.content.length ) {
									   modal.setContent( response.data.content );
								   }
								   if ( response.data.type.length ) {
									   modal.setType( response.data.type );
								   }
								   app.providerHolder.trigger( 'accountAddModal.content.done', [ modal, account.provider, response ] );
							   } )
							   .fail( function () {
								   app.providerHolder.trigger( 'accountAddModal.content.fail', [ modal, account.provider ] );
							   } )
							   .always( function () {
								   app.providerHolder.trigger( 'accountAddModal.content.always', [ modal, account.provider ] );
							   } );
						},
						contentLoaded: function( data, status, xhr ){
							var modal = this;

							// Data is already set in content.
							this.buttons.add.enable();
							this.buttons.cancel.enable();

							app.providerHolder.trigger( 'accountAddModal.contentLoaded', [ modal ] );
						},
						// Before the modal is displayed.
						onOpenBefore: function () {
							var modal = this;

							modal.buttons.add.disable();
							modal.buttons.cancel.disable();

							app.providerHolder.trigger( 'accountAddModal.onOpenBefore', [ modal ] );
						},
						icon: 'fa fa-info-circle',
						type: 'blue',
						buttons: {
							add: {
								text: wpforms_builder.provider_add_new_acc_btn,
								btnClass: 'btn-confirm',
								keys: [ 'enter' ],
								action: function() {
									var modal = this;

									app.providerHolder.trigger( 'accountAddModal.buttons.add.action.before', [ modal ] );

									if (
										! _.isEmpty( account.provider ) &&
										typeof account.submitHandlers[ account.provider ] !== 'undefined'
									) {
										return account.submitHandlers[ account.provider ]( modal );
									}
								}
							},
							cancel: {
								text: wpforms_builder.cancel
							}
						}
					});
				},

				/**
				 * Register a template for Add New Account modal window.
				 *
				 * @since 1.4.8
				 */
				registerAddHandler: function ( provider, handler ) {

					if ( typeof provider === 'string' && typeof handler === 'function' ) {
						this.submitHandlers[ provider ] = handler;
					}
				},
			},
		},

		/**
		 * Set a current provider.
		 *
		 * @since 1.4.7
		 *
		 * @param {string} provider Slug of a provider.
		 */
		setProvider: function ( provider ) {
			app.provider = provider;
		},

		/**
		 * Get a jQuery DOM object, that has all the provider-related DOM inside.
		 *
		 * @since 1.4.7
		 *
		 * @returns {Object} jQuery DOM element.
		 */
		getProviderHolder: function () {
			return $( '#' + app.provider + '-provider' );
		}
	};

	// Provide access to public functions/properties.
	return app;

})( document, window, jQuery );

// Initialize.
WPForms.Admin.Builder.Providers.init();
providers.min.js000066600000017026151126437320007717 0ustar00var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.Providers=WPForms.Admin.Builder.Providers||function(e,r,i){"use strict";var n={cache:{},config:{templates:["wpforms-providers-builder-content-connection-fields","wpforms-providers-builder-content-connection-conditionals"]}},t={provider:"",providerHolder:{},form:i("#wpforms-builder-form"),spinner:'<i class="fa fa-circle-o-notch fa-spin wpforms-button-icon" />',ajax:{_mergeData:function(e){var r={id:i("#wpforms-builder-form").data("id"),nonce:wpforms_builder.nonce,action:"wpforms_builder_provider_ajax_"+t.provider};return i.extend(r,e),r},request:function(e,r){void 0!==e&&t.setProvider(e),r.data=t.ajax._mergeData(r.data||{});var o={url:wpforms_builder.ajax_url,type:"post",dataType:"json",beforeSend:function(){t.getProviderHolder().find(".wpforms-builder-provider-title-spinner").show()}};return i.extend(o,r),i.ajax(o).fail(function(e,r){console.error("provider:",t.provider),console.error(e),console.error(r)}).always(function(){t.getProviderHolder().find(".wpforms-builder-provider-title-spinner").hide()})}},cache:{provider:"",as:function(e){return this.provider=e,this},get:function(e){return void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map?null:n.cache[this.provider].get(e)},getById:function(e,r){return void 0===this.get(e)[r]?null:this.get(e)[r]},set:function(e,r){return(void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map)&&(n.cache[this.provider]=new Map),n.cache[this.provider].set(e,r)},addTo:function(e,r,o){(void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map)&&(n.cache[this.provider]=new Map,this.set(e,{}));var t=this.get(e);return t[r]=o,this.set(e,t)},delete:function(e){return void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map?null:n.cache[this.provider].delete(e)},deleteFrom:function(e,r){if(void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map)return null;var o=this.get(e);return delete o[r],this.set(e,o)},clear:function(){void 0===n.cache[this.provider]||!n.cache[this.provider]instanceof Map||n.cache[this.provider].clear()}},init:function(){i(e).ready(t.ready)},ready:function(){t.providerHolder=i(".wpforms-builder-provider"),t.Templates=WPForms.Admin.Builder.Templates,t.Templates.add(n.config.templates),t.bindActions(),t.ui.bindActions(),i("#wpforms-panel-providers").trigger("WPForms.Admin.Builder.Providers.ready")},bindActions:function(){i(e).on("wpformsSaved",function(){var e=i("#wpforms-panel-providers").find(".wpforms-builder-provider-connection");if(e.length){var t=!1;e.each(function(){var r=!1;if(i(this).find("input.wpforms-required, select.wpforms-required, textarea.wpforms-required").each(function(){var e=i(this).val();_.isEmpty(e)?(i(this).addClass("wpforms-error"),r=!0):i(this).removeClass("wpforms-error")}),r&&!t){var e=i(this).closest(".wpforms-builder-provider").find(".wpforms-builder-provider-title").clone();e.find("button").remove();var o=wpforms_builder.provider_required_flds;i.alert({title:wpforms_builder.heads_up,content:o.replace("{provider}","<strong>"+e.text().trim()+"</strong>"),icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}),t=!0}})}}),i("#wpforms-panel-providers").on("connectionRendered",function(){!0===wpf.initialSave&&(wpf.savedState=wpf.getFormState("#wpforms-builder-form"))})},ui:{bindActions:function(){t.providerHolder.on("click",".js-wpforms-builder-provider-account-add",function(e){e.preventDefault(),t.ui.account.setProvider(i(this).data("provider")),t.ui.account.add()}).on("click",".js-wpforms-builder-provider-connection-add",function(e){e.preventDefault(),t.ui.connectionAdd()}).on("click",".js-wpforms-builder-provider-connection-delete",function(e){e.preventDefault(),t.ui.connectionDelete(i(this).closest(".wpforms-builder-provider-connection"))}),t.providerHolder.on("click",".js-wpforms-builder-provider-connection-fields-add",function(e){e.preventDefault();var r=i(this).parents(".wpforms-builder-provider-connection-fields-table"),o=r.find("tr").last().clone(!0),t=parseInt(/\[(\d+)\]/g.exec(o.find("input").attr("name"))[1],10)+1;o.find("input").attr("name",o.find("input").attr("name").replace(/\[fields_meta\]\[(\d+)\]/g,"[fields_meta]["+t+"]")).val(""),o.find("select").attr("name",o.find("select").attr("name").replace(/\[fields_meta\]\[(\d+)\]/g,"[fields_meta]["+t+"]")).val(""),o.find(".js-wpforms-builder-provider-connection-fields-delete").removeClass("hidden"),r.find("tbody").append(o.get(0))}).on("click",".js-wpforms-builder-provider-connection-fields-delete",function(e){e.preventDefault(),i(this).parents(".wpforms-builder-provider-connection-fields-table tr").remove()}),i("#wpforms-panel-providers").on("connectionRendered",function(e,r,o){wpf.initTooltips()})},connectionAdd:function(){i.confirm({title:!1,content:wpforms_builder_providers.prompt_connection.replace(/%type%/g,"connection")+'<input autofocus="" type="text" id="wpforms-builder-provider-connection-name" placeholder="'+wpforms_builder_providers.prompt_placeholder+'"><p class="error">'+wpforms_builder_providers.error_name+"</p>",backgroundDismiss:!1,closeIcon:!1,icon:"fa fa-info-circle",type:"blue",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"],action:function(){var e=this.$content.find("#wpforms-builder-provider-connection-name").val(),r=this.$content.find(".error");if(""===e)return r.show(),!1;t.providerHolder.trigger("connectionCreate",[e])}},cancel:{text:wpforms_builder.cancel}}})},connectionDelete:function(e){i.confirm({title:!1,content:wpforms_builder_providers.confirm_connection,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"],action:function(){t.providerHolder.trigger("connectionDelete",[e]),e.fadeOut("fast",function(){i(this).remove(),t.providerHolder.trigger("connectionDeleted",[e])})}},cancel:{text:wpforms_builder.cancel}}})},account:{provider:"",submitHandlers:[],setProvider:function(e){this.provider=e},add:function(){var o=this;i.confirm({title:!1,smoothContent:!0,content:function(){var r=this;return t.ajax.request(o.provider,{data:{task:"account_template_get"}}).done(function(e){e.success&&(e.data.title.length&&r.setTitle(e.data.title),e.data.content.length&&r.setContent(e.data.content),e.data.type.length&&r.setType(e.data.type),t.providerHolder.trigger("accountAddModal.content.done",[r,o.provider,e]))}).fail(function(){t.providerHolder.trigger("accountAddModal.content.fail",[r,o.provider])}).always(function(){t.providerHolder.trigger("accountAddModal.content.always",[r,o.provider])})},contentLoaded:function(e,r,o){this.buttons.add.enable(),this.buttons.cancel.enable(),t.providerHolder.trigger("accountAddModal.contentLoaded",[this])},onOpenBefore:function(){this.buttons.add.disable(),this.buttons.cancel.disable(),t.providerHolder.trigger("accountAddModal.onOpenBefore",[this])},icon:"fa fa-info-circle",type:"blue",buttons:{add:{text:wpforms_builder.provider_add_new_acc_btn,btnClass:"btn-confirm",keys:["enter"],action:function(){if(t.providerHolder.trigger("accountAddModal.buttons.add.action.before",[this]),!_.isEmpty(o.provider)&&void 0!==o.submitHandlers[o.provider])return o.submitHandlers[o.provider](this)}},cancel:{text:wpforms_builder.cancel}}})},registerAddHandler:function(e,r){"string"==typeof e&&"function"==typeof r&&(this.submitHandlers[e]=r)}}},setProvider:function(e){t.provider=e},getProviderHolder:function(){return i("#"+t.provider+"-provider")}};return t}(document,window,jQuery),WPForms.Admin.Builder.Providers.init();templates.min.js000066600000001151151126437320007670 0ustar00var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.Templates=WPForms.Admin.Builder.Templates||function(r,e,i){"use strict";var n={previews:new Map},t={init:function(){i(r).ready(t.ready)},ready:function(){i("#wpforms-panel-providers").trigger("WPForms.Admin.Builder.Templates.ready")},add:function(r){r.forEach(function(r){"string"==typeof r&&n.previews.set(r,wp.template(r))})},get:function(r){var e=n.previews.get(r);return void 0!==e?e:function(){return""}}};return t}(document,window,jQuery),WPForms.Admin.Builder.Templates.init();templates.js000066600000004156151126437320007116 0ustar00/* global WPForms, jQuery, Map, wpforms_builder, wpforms_builder_providers, _ */

var WPForms = window.WPForms || {};
WPForms.Admin = WPForms.Admin || {};
WPForms.Admin.Builder = WPForms.Admin.Builder || {};

WPForms.Admin.Builder.Templates = WPForms.Admin.Builder.Templates || (function ( document, window, $ ) {
	'use strict';

	/**
	 * Private functions and properties.
	 *
	 * @since 1.4.8
	 *
	 * @type {Object}
	 */
	var __private = {

		/**
		 * All templating functions for providers are stored here in a Map.
		 * Key is a template name, value - Underscore.js templating function.
		 *
		 * @since 1.4.8
		 *
		 * @type {Map}
		 */
		previews: new Map()
	};

	/**
	 * Public functions and properties.
	 *
	 * @since 1.4.8
	 *
	 * @type {Object}
	 */
	var app = {

		/**
		 * Start the engine. DOM is not ready yet, use only to init something.
		 *
		 * @since 1.4.8
		 */
		init: function () {

			// Do that when DOM is ready.
			$( document ).ready( app.ready );
		},

		/**
		 * DOM is fully loaded.
		 *
		 * @since 1.4.8
		 */
		ready: function () {

			$( '#wpforms-panel-providers' ).trigger( 'WPForms.Admin.Builder.Templates.ready' );
		},

		/**
		 * Register and compile all templates.
		 * All data is saved in a Map.
		 *
		 * @since 1.4.8
		 *
		 * @param {string[]} templates Array of template names.
		 */
		add: function ( templates ) {

			templates.forEach( function ( template ) {
				if ( typeof template === 'string' ) {
					__private.previews.set( template, wp.template( template ) );
				}
			} );
		},

		/**
		 * Get a templating function (to compile later with data).
		 *
		 * @since 1.4.8
		 *
		 * @param {string} template ID of a template to retrieve from a cache.
		 *
		 * @returns {*} A callable that after compiling will always return a string.
		 */
		get: function ( template ) {

			var preview = __private.previews.get( template );

			if ( typeof preview !== 'undefined' ) {
				return preview;
			}

			return function () {
				return '';
			};
		}

	};

	// Provide access to public functions/properties.
	return app;

})( document, window, jQuery );

// Initialize.
WPForms.Admin.Builder.Templates.init();