| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/importers.tar |
class-base.php 0000666 00000007455 15114275427 0007321 0 ustar 00 <?php
/**
* Base Importer class.
*
* @package WPForms
* @author WPForms
* @since 1.4.2
* @license GPL-2.0+
* @copyright Copyright (c) 2017, WPForms LLC
*/
abstract class WPForms_Importer implements WPForms_Importer_Interface {
/**
* Importer name.
*
* @since 1.4.2
*
* @var string
*/
public $name;
/**
* Importer name in slug format.
*
* @since 1.4.2
*
* @var string
*/
public $slug;
/**
* Importer plugin path.
*
* @since 1.4.2
*
* @var string
*/
public $path;
/**
* Primary class constructor.
*
* @since 1.4.2
*/
public function __construct() {
$this->init();
// Add to list of available importers.
add_filter( 'wpforms_importers', array( $this, 'register' ), 10, 1 );
// Return array of all available forms.
add_filter( "wpforms_importer_forms_{$this->slug}", array( $this, 'get_forms' ), 10, 1 );
// Import a specific form with AJAX.
add_action( "wp_ajax_wpforms_import_form_{$this->slug}", array( $this, 'import_form' ) );
}
/**
* Add to list of registered importers.
*
* @since 1.4.2
*
* @param array $importers List of supported importers.
*
* @return array
*/
public function register( $importers = array() ) {
$importers[ $this->slug ] = array(
'name' => $this->name,
'slug' => $this->slug,
'path' => $this->path,
'installed' => file_exists( trailingslashit( WP_PLUGIN_DIR ) . $this->path ),
'active' => $this->is_active(),
);
return $importers;
}
/**
* If the importer source is available.
*
* @since 1.4.2
*
* @return bool
*/
protected function is_active() {
return is_plugin_active( $this->path );
}
/**
* Add the new form to the database and return AJAX data.
*
* @since 1.4.2
*
* @param array $form Form to import.
* @param array $unsupported List of unsupported fields.
* @param array $upgrade_plain List of fields, that are supported inside the paid WPForms, but not in Lite.
* @param array $upgrade_omit No field alternative in WPForms.
*/
public function add_form( $form, $unsupported = array(), $upgrade_plain = array(), $upgrade_omit = array() ) {
// Create empty form so we have an ID to work with.
$form_id = wp_insert_post( array(
'post_status' => 'publish',
'post_type' => 'wpforms',
) );
if ( empty( $form_id ) || is_wp_error( $form_id ) ) {
wp_send_json_success( array(
'error' => true,
'name' => sanitize_text_field( $form['settings']['form_title'] ),
'msg' => esc_html__( 'There was an error while creating a new form.', 'wpforms-lite' ),
) );
}
$form['id'] = $form_id;
$form['field_id'] = count( $form['fields'] ) + 1;
// Update the form with all our compiled data.
wpforms()->form->update( $form_id, $form );
// Make note that this form has been imported.
$this->track_import( $form['settings']['import_form_id'], $form_id );
// Build and send final AJAX response!
wp_send_json_success( array(
'name' => $form['settings']['form_title'],
'edit' => esc_url_raw( admin_url( 'admin.php?page=wpforms-builder&view=fields&form_id=' . $form_id ) ),
'preview' => wpforms_get_form_preview_url( $form_id ),
'unsupported' => $unsupported,
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
) );
}
/**
* After a form has been successfully imported we track it, so that in the
* future we can alert users if they try to import a form that has already
* been imported.
*
* @since 1.4.2
*
* @param int $source_id Imported plugin form ID.
* @param int $wpforms_id WPForms form ID.
*/
public function track_import( $source_id, $wpforms_id ) {
$imported = get_option( 'wpforms_imported', array() );
$imported[ $this->slug ][ $wpforms_id ] = $source_id;
update_option( 'wpforms_imported', $imported, false );
}
}
class-ninja-forms.php 0000666 00000036315 15114275427 0010627 0 ustar 00 <?php
/**
* Ninja Forms Importer class.
*
* @package WPForms
* @author WPForms
* @since 1.4.2
* @license GPL-2.0+
* @copyright Copyright (c) 2017, WPForms LLC
*/
class WPForms_Ninja_Forms extends WPForms_Importer {
/**
* @inheritdoc
*/
public function init() {
$this->name = 'Ninja Forms';
$this->slug = 'ninja-forms';
$this->path = 'ninja-forms/ninja-forms.php';
}
/**
* Get ALL THE FORMS.
*
* @since 1.4.2
*
* @return NF_Database_Models_Form[]
*/
public function get_forms() {
$forms_final = array();
if ( ! $this->is_active() ) {
return $forms_final;
}
$forms = Ninja_Forms()->form()->get_forms();
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
if ( ! $form instanceof NF_Database_Models_Form ) {
continue;
}
$forms_final[ $form->get_id() ] = $form->get_setting( 'title' );
}
}
return $forms_final;
}
/**
* @inheritdoc
*/
public function get_form( $id ) {
$form = array();
$form['settings'] = Ninja_Forms()->form( $id )->get()->get_settings();
$fields = Ninja_Forms()->form( $id )->get_fields();
$actions = Ninja_Forms()->form( $id )->get_actions();
foreach ( $fields as $field ) {
if ( ! $field instanceof NF_Database_Models_Field ) {
continue;
}
$form['fields'][] = array_merge(
array(
'id' => $field->get_id(),
),
$field->get_settings()
);
}
foreach ( $actions as $action ) {
if ( ! $action instanceof NF_Database_Models_Action ) {
continue;
}
$form['actions'][] = $action->get_settings();
}
return $form;
}
/**
* @inheritdoc
*/
public function import_form() {
// Run a security check.
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can() ) {
wp_send_json_error();
}
// Define some basic information.
$analyze = isset( $_POST['analyze'] );
$nf_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : 0;
$nf_form = $this->get_form( $nf_id );
$nf_form_name = $nf_form['settings']['title'];
$nf_recaptcha = false;
$nf_recaptcha_type = 'v2';
$fields_pro_plain = array( 'phone', 'date' );
$fields_pro_omit = array( 'html', 'divider' );
$fields_unsupported = array( 'spam', 'starrating', 'listmultiselect', 'hidden', 'total', 'shipping', 'quantity', 'product' );
$upgrade_plain = array();
$upgrade_omit = array();
$unsupported = array();
$form = array(
'id' => '',
'field_id' => '',
'fields' => array(),
'settings' => array(
'form_title' => $nf_form_name,
'form_desc' => '',
'submit_text' => esc_html__( 'Submit', 'wpforms-lite' ),
'submit_text_processing' => esc_html__( 'Sending', 'wpforms-lite' ),
'honeypot' => '1',
'notification_enable' => '1',
'notifications' => array(
1 => array(
'notification_name' => esc_html__( 'Notification 1', 'wpforms-lite' ),
'email' => '{admin_email}',
/* translators: %s - form name. */
'subject' => sprintf( esc_html__( 'New Entry: %s', 'wpforms-lite' ), $nf_form_name ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'replyto' => '',
'message' => '{all_fields}',
),
),
'confirmations' => array(
1 => array(
'type' => 'message',
'message' => esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ),
'message_scroll' => '1',
),
),
'import_form_id' => $nf_id,
),
);
// If form does not contain fields, bail.
if ( empty( $nf_form['fields'] ) ) {
wp_send_json_success( array(
'error' => true,
'name' => sanitize_text_field( $nf_form_name ),
'msg' => esc_html__( 'No form fields found.', 'wpforms-lite' ),
) );
}
// Convert fields.
foreach ( $nf_form['fields'] as $nf_field ) {
// Try to determine field label to use.
$label = $this->get_field_label( $nf_field );
// Next, check if field is unsupported. If unsupported make note and
// then continue to the next field.
if ( in_array( $nf_field['type'], $fields_unsupported, true ) ) {
$unsupported[] = $label;
continue;
}
// Now check if this install is Lite. If it is Lite and it's a
// field type not included, make a note then continue to the next
// field.
if ( ! wpforms()->pro && in_array( $nf_field['type'], $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
}
if ( ! wpforms()->pro && in_array( $nf_field['type'], $fields_pro_omit, true ) ) {
$upgrade_omit[] = $label;
continue;
}
// Determine next field ID to assign.
if ( empty( $form['fields'] ) ) {
$field_id = 1;
} else {
$field_id = (int) max( array_keys( $form['fields'] ) ) + 1;
}
switch ( $nf_field['type'] ) {
// Single line text, address, city, first name, last name,
// zipcode, email, number, textarea fields.
case 'textbox':
case 'address':
case 'city':
case 'firstname':
case 'lastname':
case 'zip':
case 'email':
case 'number':
case 'textarea':
$type = 'text';
if ( 'email' === $nf_field['type'] ) {
$type = 'email';
} elseif ( 'number' === $nf_field['type'] ) {
$type = 'number';
} elseif ( 'textarea' === $nf_field['type'] ) {
$type = 'textarea';
}
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'size' => 'medium',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'placeholder' => ! empty( $nf_field['placeholder'] ) ? $nf_field['placeholder'] : '',
'default_value' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'nf_key' => $nf_field['key'],
);
break;
// Single checkbox field.
case 'checkbox':
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'checkbox',
'label' => esc_html__( 'Single Checkbox Field', 'wpforms-lite' ),
'choices' => array(
1 => array(
'label' => $label,
'value' => '',
),
),
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'size' => 'medium',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'label_hide' => '1',
'nf_key' => $nf_field['key'],
);
break;
// Multi-check field, radio, select, state, and country fields.
case 'listcheckbox':
case 'listradio':
case 'listselect':
case 'liststate':
case 'listcountry':
$type = 'select';
if ( 'listcheckbox' === $nf_field['type'] ) {
$type = 'checkbox';
} elseif ( 'listradio' === $nf_field['type'] ) {
$type = 'radio';
}
$choices = array();
if ( 'listcountry' === $nf_field['type'] ) {
$countries = wpforms_countries();
foreach ( $countries as $key => $country ) {
$choices[] = array(
'label' => $country,
'value' => $key,
'default' => isset( $nf_field['default'] ) && $nf_field['default'] === $key ? '1' : '',
);
}
} else {
foreach ( $nf_field['options'] as $option ) {
$choices[] = array(
'label' => $option['label'],
'value' => $option['value'],
);
}
}
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'choices' => $choices,
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'size' => 'medium',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'nf_key' => $nf_field['key'],
);
break;
// HTML field.
case 'html':
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'html',
'code' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'label_disable' => '1',
'nf_key' => $nf_field['key'],
);
break;
// Divider field.
case 'hr':
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'divider',
'label' => '',
'description' => '',
'label_disable' => '1',
'nf_key' => $nf_field['key'],
);
break;
// Phone number field.
case 'phone':
$type = wpforms()->pro ? 'phone' : 'text';
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'format' => ! empty( $nf_field['mask'] ) && '(999) 999-9999' === $nf_field['mask'] ? 'us' : 'international',
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'size' => 'medium',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'placeholder' => ! empty( $nf_field['placeholder'] ) ? $nf_field['placeholder'] : '',
'default_value' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'nf_key' => $nf_field['key'],
);
break;
// Date field.
case 'date':
$type = wpforms()->pro ? 'date-time' : 'text';
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'format' => 'date',
'size' => 'medium',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'date_placeholder' => '',
'date_format' => 'm/d/Y',
'date_type' => 'datepicker',
'time_format' => 'g:i A',
'time_interval' => 30,
'nf_key' => $nf_field['key'],
);
break;
// ReCAPTCHA field.
case 'recaptcha':
$nf_recaptcha = true;
if ( 'invisible' === $nf_field['size'] ) {
$nf_recaptcha_type = 'invisible';
}
}
}
// If we are only analyzing the form, we can stop here and return the
// details about this form.
if ( $analyze ) {
wp_send_json_success( array(
'name' => $nf_form_name,
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
) );
}
// Settings.
// Confirmation message.
foreach ( $nf_form['actions'] as $action ) {
if ( 'successmessage' === $action['type'] ) {
$form['settings']['confirmations'][1]['message'] = $this->get_smarttags( $action['message'], $form['fields'] );
}
}
// ReCAPTCHA.
if ( $nf_recaptcha ) {
// If the user has already defined v2 reCAPTCHA keys in the WPForms
// settings, use those.
$site_key = wpforms_setting( 'recaptcha-site-key', '' );
$secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
// Try to abstract keys from NF.
if ( empty( $site_key ) || empty( $secret_key ) ) {
$nf_settings = get_option( 'ninja_forms_settings' );
if ( ! empty( $nf_settings['recaptcha_site_key'] ) && ! empty( $nf_settings['recaptcha_secret_key'] ) ) {
$wpforms_settings = get_option( 'wpforms_settings', array() );
$wpforms_settings['recaptcha-site-key'] = $nf_settings['recaptcha_site_key'];
$wpforms_settings['recaptcha-secret-key'] = $nf_settings['recaptcha_secret_key'];
$wpforms_settings['recaptcha-type'] = $nf_recaptcha_type;
update_option( 'wpforms_settings', $wpforms_settings );
}
}
if ( ! empty( $site_key ) && ! empty( $secret_key ) ) {
$form['settings']['recaptcha'] = '1';
}
}
// Setup email notifications.
$action_count = 1;
$action_defaults = array(
'notification_name' => esc_html__( 'Notification', 'wpforms-lite' ) . " $action_count",
'email' => '{admin_email}',
/* translators: %s - form name. */
'subject' => sprintf( esc_html__( 'New Entry: %s', 'wpforms-lite' ), $nf_form_name ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'replyto' => '',
'message' => '{all_fields}',
);
foreach ( $nf_form['actions'] as $action ) {
if ( 'email' !== $action['type'] ) {
continue;
}
$action_defaults['notification_name'] = esc_html__( 'Notification', 'wpforms-lite' ) . " $action_count";
$form['settings']['notifications'][ $action_count ] = $action_defaults;
if ( ! empty( $action['label'] ) ) {
$form['settings']['notifications'][ $action_count ]['notification_name'] = $action['label'];
}
if ( ! empty( $action['to'] ) ) {
$form['settings']['notifications'][ $action_count ]['email'] = $this->get_smarttags( $action['to'], $form['fields'] );
}
if ( ! empty( $action['reply_to'] ) ) {
$form['settings']['notifications'][ $action_count ]['replyto'] = $this->get_smarttags( $action['reply_to'], $form['fields'] );
}
if ( ! empty( $action['email_subject'] ) ) {
$form['settings']['notifications'][ $action_count ]['subject'] = $this->get_smarttags( $action['email_subject'], $form['fields'] );
}
if ( ! empty( $action['email_message'] ) ) {
$form['settings']['notifications'][ $action_count ]['message'] = $this->get_smarttags( $action['email_message'], $form['fields'] );
}
if ( ! empty( $action['from_name'] ) ) {
$form['settings']['notifications'][ $action_count ]['sender_name'] = $this->get_smarttags( $action['from_name'], $form['fields'] );
}
if ( ! empty( $action['from_address'] ) ) {
$form['settings']['notifications'][ $action_count ]['sender_address'] = $this->get_smarttags( $action['from_address'], $form['fields'] );
}
$action_count ++;
}
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
}
/**
* Get the field label.
*
* @since 1.4.2
*
* @param array $field
*
* @return string
*/
public function get_field_label( $field ) {
if ( ! empty( $field['label'] ) ) {
$label = sanitize_text_field( $field['label'] );
} else {
$label = sprintf(
/* translators: %1$s - field type; %2$s - field name if available. */
esc_html__( '%1$s Field', 'wpforms-lite' ),
ucfirst( $field['type'] )
);
}
return trim( $label );
}
/**
* @inheritdoc
*/
public function get_smarttags( $string, $fields ) {
preg_match_all( '/\{(.+?)\}/', $string, $tags );
if ( empty( $tags[1] ) ) {
return $string;
}
foreach ( $tags[1] as $tag ) {
$tag_formatted = str_replace( 'field:', '', $tag );
foreach ( $fields as $field ) {
if ( ! empty( $field['nf_key'] ) && $field['nf_key'] === $tag_formatted ) {
$string = str_replace( '{' . $tag . '}', '{field_id="' . $field['id'] . '"}', $string );
}
}
if ( 'wp:admin_email' === $tag ) {
$string = str_replace( '{wp:admin_email}', '{admin_email}', $string );
}
if ( 'all_fields_table' === $tag || 'fields_table' === $tag ) {
$string = str_replace( '{' . $tag . '}', '{all_fields}', $string );
}
}
return $string;
}
}
new WPForms_Ninja_Forms();
interface.php 0000666 00000001735 15114275427 0007237 0 ustar 00 <?php
/**
* Interface WPForms_Importer_Interface to handle common methods for all importers.
*
* @package WPForms
* @author WPForms
* @since 1.4.2
* @license GPL-2.0+
* @copyright Copyright (c) 2017, WPForms LLC
*/
interface WPForms_Importer_Interface {
/**
* Define required properties.
*
* @since 1.4.2
*/
public function init();
/**
* Get ALL THE FORMS.
*
* @since 1.4.2
*/
public function get_forms();
/**
* Get a single form.
*
* @since 1.4.2
*
* @param int $id Form ID.
*/
public function get_form( $id );
/**
* Import a single form using AJAX.
*
* @since 1.4.2
*/
public function import_form();
/**
* Replace 3rd-party form provider tags/shortcodes with our own Smart Tags.
*
* @since 1.4.2
*
* @param string $string Text to look for Smart Tags in.
* @param array $fields List of fields to process Smart Tags in.
*
* @return string
*/
public function get_smarttags( $string, $fields );
}
class-install-silent-skin.php 0000666 00000003142 15114275427 0012300 0 ustar 00 <?php
/**
* WordPress class extended for on-the-fly plugins installations, without error reporting.
*
* @package WPForms
* @author WPForms
* @since 1.4.9
* @license GPL-2.0+
* @copyright Copyright (c) 2018, WPForms LLC
*/
class WPForms_Install_Silent_Skin extends WP_Upgrader_Skin {
/**
* Set the upgrader object and store it as a property in the parent class.
*
* @since 1.4.9
*
* @param object $upgrader The upgrader object (passed by reference).
*/
public function set_upgrader( &$upgrader ) {
if ( is_object( $upgrader ) ) {
$this->upgrader =& $upgrader;
}
}
/**
* Empty out the header of its HTML content and only check to see if it has
* been performed or not.
*
* @since 1.4.9
*/
public function header() {
}
/**
* Empty out the footer of its HTML contents.
*
* @since 1.4.9
*/
public function footer() {
}
/**
* Instead of outputting HTML for errors, just return them.
* Ajax request will just ignore it.
*
* @since 1.4.9
*
* @param array $errors Array of errors with the install process.
*
* @return array
*/
public function error( $errors ) {
return $errors;
}
/**
* Empty out the feedback method to prevent outputting HTML strings as the install
* is progressing.
*
* @since 1.4.9
*
* @param string $string The feedback string.
*/
public function feedback( $string ) {
}
/**
* Empty out JavaScript output that calls function to decrement the update counts.
*
* @since 1.4.9
*
* @param string $type Type of update count to decrement.
*/
public function decrement_update_count( $type ) {
}
}
class-contact-form-7.php 0000666 00000042041 15114275427 0011135 0 ustar 00 <?php
/**
* Contact Form 7 Importer class.
*
* @package WPForms
* @author WPForms
* @since 1.4.2
* @license GPL-2.0+
* @copyright Copyright (c) 2017, WPForms LLC
*/
class WPForms_Contact_Form_7 extends WPForms_Importer {
/**
* @inheritdoc
*/
public function init() {
$this->name = 'Contact Form 7';
$this->slug = 'contact-form-7';
$this->path = 'contact-form-7/wp-contact-form-7.php';
}
/**
* @inheritdoc
*/
public function get_forms() {
$forms_final = array();
if ( ! $this->is_active() ) {
return $forms_final;
}
$forms = WPCF7_ContactForm::find( array(
'posts_per_page' => - 1,
) );
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
if ( ! empty( $form ) && ( $form instanceof WPCF7_ContactForm ) ) {
$forms_final[ $form->id() ] = $form->title();
}
}
}
return $forms_final;
}
/**
* Get a single form.
*
* @since 1.4.2
*
* @param int $id Form ID.
*
* @return WPCF7_ContactForm|bool
*/
public function get_form( $id ) {
$form = WPCF7_ContactForm::find( array(
'posts_per_page' => 1,
'p' => $id,
) );
if ( ! empty( $form[0] ) && ( $form[0] instanceof WPCF7_ContactForm ) ) {
return $form[0];
}
return false;
}
/**
* @inheritdoc
*/
public function import_form() {
// Run a security check.
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can() ) {
wp_send_json_error();
}
// Define some basic information.
$analyze = isset( $_POST['analyze'] );
$cf7_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : 0;
$cf7_form = $this->get_form( $cf7_id );
if ( ! $cf7_form ) {
wp_send_json_error( array(
'error' => true,
'name' => esc_html__( 'Unknown Form', 'wpforms-lite' ),
'msg' => esc_html__( 'The form you are trying to import does not exist.', 'wpforms-lite' ),
) );
}
$cf7_form_name = $cf7_form->title();
$cf7_fields = $cf7_form->scan_form_tags();
$cf7_properties = $cf7_form->get_properties();
$cf7_recaptcha = false;
$fields_pro_plain = array( 'url', 'tel', 'date' );
$fields_pro_omit = array( 'file' );
$fields_unsupported = array( 'quiz', 'hidden' );
$upgrade_plain = array();
$upgrade_omit = array();
$unsupported = array();
$form = array(
'id' => '',
'field_id' => '',
'fields' => array(),
'settings' => array(
'form_title' => $cf7_form_name,
'form_desc' => '',
'submit_text' => esc_html__( 'Submit', 'wpforms-lite' ),
'submit_text_processing' => esc_html__( 'Sending', 'wpforms-lite' ),
'honeypot' => '1',
'notification_enable' => '1',
'notifications' => array(
1 => array(
'notification_name' => esc_html__( 'Notification 1', 'wpforms-lite' ),
'email' => '{admin_email}',
/* translators: %s - form name. */
'subject' => sprintf( esc_html__( 'New Entry: %s', 'wpforms-lite' ), $cf7_form_name ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'replyto' => '',
'message' => '{all_fields}',
),
),
'confirmations' => array(
1 => array(
'type' => 'message',
'message' => esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ),
'message_scroll' => '1',
),
),
'import_form_id' => $cf7_id,
),
);
// If form does not contain fields, bail.
if ( empty( $cf7_fields ) ) {
wp_send_json_success( array(
'error' => true,
'name' => sanitize_text_field( $cf7_form_name ),
'msg' => esc_html__( 'No form fields found.', 'wpforms-lite' ),
) );
}
// Convert fields.
foreach ( $cf7_fields as $cf7_field ) {
if ( ! $cf7_field instanceof WPCF7_FormTag ) {
continue;
}
// Try to determine field label to use.
$label = $this->get_field_label( $cf7_properties['form'], $cf7_field->type, $cf7_field->name );
// Next, check if field is unsupported. If supported make note and
// then continue to the next field.
if ( in_array( $cf7_field->basetype, $fields_unsupported, true ) ) {
$unsupported[] = $label;
continue;
}
// Now check if this install is Lite. If it is Lite and it's a
// field type not included, make a note then continue to the next
// field.
if ( ! wpforms()->pro && in_array( $cf7_field->basetype, $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
}
if ( ! wpforms()->pro && in_array( $cf7_field->basetype, $fields_pro_omit, true ) ) {
$upgrade_omit[] = $label;
continue;
}
// Determine next field ID to assign.
if ( empty( $form['fields'] ) ) {
$field_id = 1;
} else {
$field_id = (int) max( array_keys( $form['fields'] ) ) + 1;
}
switch ( $cf7_field->basetype ) {
// Plain text, email, URL, number, and textarea fields.
case 'text':
case 'email':
case 'url':
case 'number':
case 'textarea':
$type = $cf7_field->basetype;
if ( 'url' === $type && ! wpforms()->pro ) {
$type = 'text';
}
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'size' => 'medium',
'required' => $cf7_field->is_required() ? '1' : '',
'placeholder' => $this->get_field_placeholder_default( $cf7_field ),
'default_value' => $this->get_field_placeholder_default( $cf7_field, 'default' ),
'cf7_name' => $cf7_field->name,
);
break;
// Phone number field.
case 'tel':
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'phone',
'label' => $label,
'format' => 'international',
'size' => 'medium',
'required' => $cf7_field->is_required() ? '1' : '',
'placeholder' => $this->get_field_placeholder_default( $cf7_field ),
'default_value' => $this->get_field_placeholder_default( $cf7_field, 'default' ),
'cf7_name' => $cf7_field->name,
);
break;
// Date field.
case 'date':
$type = wpforms()->pro ? 'date-time' : 'text';
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'format' => 'date',
'size' => 'medium',
'required' => $cf7_field->is_required() ? '1' : '',
'date_placeholder' => '',
'date_format' => 'm/d/Y',
'date_type' => 'datepicker',
'time_format' => 'g:i A',
'time_interval' => 30,
'cf7_name' => $cf7_field->name,
);
break;
// Select, radio, and checkbox fields.
case 'select':
case 'radio':
case 'checkbox':
$choices = array();
$options = (array) $cf7_field->labels;
foreach ( $options as $option ) {
$choices[] = array(
'label' => $option,
'value' => '',
);
}
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => $cf7_field->basetype,
'label' => $label,
'choices' => $choices,
'size' => 'medium',
'required' => $cf7_field->is_required() ? '1' : '',
'cf7_name' => $cf7_field->name,
);
if ( 'select' === $cf7_field->basetype && $cf7_field->has_option( 'include_blank' ) ) {
$form['fields'][ $field_id ]['placeholder'] = '---';
}
break;
// File upload field.
case 'file':
$extensions = '';
$max_size = '';
$file_types = $cf7_field->get_option( 'filetypes' );
$limit = $cf7_field->get_option( 'limit' );
if ( ! empty( $file_types[0] ) ) {
$extensions = implode( ',', explode( '|', strtolower( preg_replace( '/[^A-Za-z0-9|]/', '', strtolower( $file_types[0] ) ) ) ) );
}
if ( ! empty( $limit[0] ) ) {
$limit = $limit[0];
$mb = ( strpos( $limit, 'm' ) !== false );
$kb = ( strpos( $limit, 'kb' ) !== false );
$limit = (int) preg_replace( '/[^0-9]/', '', $limit );
if ( $mb ) {
$max_size = $limit;
} elseif ( $kb ) {
$max_size = round( $limit / 1024, 1 );
} else {
$max_size = round( $limit / 1048576, 1 );
}
}
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'file-upload',
'label' => $label,
'size' => 'medium',
'extensions' => $extensions,
'max_size' => $max_size,
'required' => $cf7_field->is_required() ? '1' : '',
'cf7_name' => $cf7_field->name,
);
break;
// Acceptance field.
case 'acceptance':
$form['fields'][ $field_id ] = array(
'id' => $field_id,
'type' => 'checkbox',
'label' => esc_html__( 'Acceptance Field', 'wpforms-lite' ),
'choices' => array(
1 => array(
'label' => $label,
'value' => '',
),
),
'size' => 'medium',
'required' => '1',
'label_hide' => '1',
'cf7_name' => $cf7_field->name,
);
break;
// ReCAPTCHA field.
case 'recaptcha':
$cf7_recaptcha = true;
}
}
// If we are only analyzing the form, we can stop here and return the
// details about this form.
if ( $analyze ) {
wp_send_json_success( array(
'name' => $cf7_form_name,
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
) );
}
// Settings.
// Confirmation message.
if ( ! empty( $cf7_properties['messages']['mail_sent_ok'] ) ) {
$form['settings']['confirmation_message'] = $cf7_properties['messages']['mail_sent_ok'];
}
// ReCAPTCHA.
if ( $cf7_recaptcha ) {
// If the user has already defined v2 reCAPTCHA keys in the WPForms
// settings, use those.
$site_key = wpforms_setting( 'recaptcha-site-key', '' );
$secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
$type = wpforms_setting( 'recaptcha-type', 'v2' );
// Try to abstract keys from CF7.
if ( empty( $site_key ) || empty( $secret_key ) ) {
$cf7_settings = get_option( 'wpcf7' );
if ( ! empty( $cf7_settings['recaptcha'] ) && is_array( $cf7_settings['recaptcha'] ) ) {
foreach ( $cf7_settings['recaptcha'] as $key => $val ) {
if ( ! empty( $key ) && ! empty( $val ) ) {
$site_key = $key;
$secret_key = $val;
}
}
$wpforms_settings = get_option( 'wpforms_settings', array() );
$wpforms_settings['recaptcha-site-key'] = $site_key;
$wpforms_settings['recaptcha-secret-key'] = $secret_key;
update_option( 'wpforms_settings', $wpforms_settings );
}
}
// Don't enable reCAPTCHA if user had configured invisible reCAPTCHA.
if ( 'v2' === $type && ! empty( $site_key ) && ! empty( $secret_key ) ) {
$form['settings']['recaptcha'] = '1';
}
}
// Setup email notifications.
if ( ! empty( $cf7_properties['mail']['subject'] ) ) {
$form['settings']['notifications'][1]['subject'] = $this->get_smarttags( $cf7_properties['mail']['subject'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail']['recipient'] ) ) {
$form['settings']['notifications'][1]['email'] = $this->get_smarttags( $cf7_properties['mail']['recipient'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail']['body'] ) ) {
$form['settings']['notifications'][1]['message'] = $this->get_smarttags( $cf7_properties['mail']['body'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail']['additional_headers'] ) ) {
$form['settings']['notifications'][1]['replyto'] = $this->get_replyto( $cf7_properties['mail']['additional_headers'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail']['sender'] ) ) {
$sender = $this->get_sender_details( $cf7_properties['mail']['sender'], $form['fields'] );
if ( $sender ) {
$form['settings']['notifications'][1]['sender_name'] = $sender['name'];
$form['settings']['notifications'][1]['sender_address'] = $sender['address'];
}
}
if ( ! empty( $cf7_properties['mail_2'] ) && '1' == $cf7_properties['mail_2']['active'] ) {
// Check if a secondary notification is enabled, if so set defaults
// and set it up.
$form['settings']['notifications'][2] = array(
'notification_name' => esc_html__( 'Notification 2', 'wpforms-lite' ),
'email' => '{admin_email}',
/* translators: %s - form name. */
'subject' => sprintf( esc_html__( 'New Entry: %s', 'wpforms-lite' ), $cf7_form_name ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'replyto' => '',
'message' => '{all_fields}',
);
if ( ! empty( $cf7_properties['mail_2']['subject'] ) ) {
$form['settings']['notifications'][2]['subject'] = $this->get_smarttags( $cf7_properties['mail_2']['subject'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail_2']['recipient'] ) ) {
$form['settings']['notifications'][2]['email'] = $this->get_smarttags( $cf7_properties['mail_2']['recipient'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail_2']['body'] ) ) {
$form['settings']['notifications'][2]['message'] = $this->get_smarttags( $cf7_properties['mail_2']['body'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail_2']['additional_headers'] ) ) {
$form['settings']['notifications'][2]['replyto'] = $this->get_replyto( $cf7_properties['mail_2']['additional_headers'], $form['fields'] );
}
if ( ! empty( $cf7_properties['mail_2']['sender'] ) ) {
$sender = $this->get_sender_details( $cf7_properties['mail_2']['sender'], $form['fields'] );
if ( $sender ) {
$form['settings']['notifications'][2]['sender_name'] = $sender['name'];
$form['settings']['notifications'][2]['sender_address'] = $sender['address'];
}
}
}
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
}
/**
* Lookup and return the placeholder or default value.
*
* @since 1.4.2
*
* @param object $field Field object.
* @param string $type Type of the field.
*
* @return string
*/
public function get_field_placeholder_default( $field, $type = 'placeholder' ) {
$placeholder = '';
$default_value = (string) reset( $field->values );
if ( $field->has_option( 'placeholder' ) || $field->has_option( 'watermark' ) ) {
$placeholder = $default_value;
$default_value = '';
}
if ( 'placeholder' === $type ) {
return $placeholder;
}
return $default_value;
}
/**
* Get the field label.
*
* @since 1.4.2
*
* @param string $form Form data and settings.
* @param string $type Field type.
* @param string $name Field name.
*
* @return string
*/
public function get_field_label( $form, $type, $name = '' ) {
preg_match_all( '/<label>([ \w\S\r\n\t]+?)<\/label>/', $form, $matches );
foreach ( $matches[1] as $match ) {
$match = trim( str_replace( "\n", '', $match ) );
preg_match( '/\[(?:' . preg_quote( $type ) . ') ' . $name . '(?:[ ](.*?))?(?:[\r\n\t ](\/))?\]/', $match, $input_match );
if ( ! empty( $input_match[0] ) ) {
return strip_shortcodes( sanitize_text_field( str_replace( $input_match[0], '', $match ) ) );
}
}
$label = sprintf(
/* translators: %1$s - field type; %2$s - field name if available. */
esc_html__( '%1$s Field %2$s', 'wpforms-lite' ),
ucfirst( $type ),
! empty( $name ) ? "($name)" : ''
);
return trim( $label );
}
/**
* @inheritdoc
*/
public function get_smarttags( $string, $fields ) {
preg_match_all( '/\[(.+?)\]/', $string, $tags );
if ( empty( $tags[1] ) ) {
return $string;
}
foreach ( $tags[1] as $tag ) {
foreach ( $fields as $field ) {
if ( ! empty( $field['cf7_name'] ) && $field['cf7_name'] === $tag ) {
$string = str_replace( '[' . $tag . ']', '{field_id="' . $field['id'] . '"}', $string );
}
}
}
return $string;
}
/**
* Find Reply-To in headers if provided.
*
* @since 1.4.2
*
* @param string $headers CF7 email headers.
* @param array $fields List of fields.
*
* @return string
*/
public function get_replyto( $headers, $fields ) {
if ( strpos( $headers, 'Reply-To:' ) !== false ) {
preg_match( '/Reply-To: \[(.+?)\]/', $headers, $tag );
if ( ! empty( $tag[1] ) ) {
foreach ( $fields as $field ) {
if ( ! empty( $field['cf7_name'] ) && $field['cf7_name'] === $tag[1] ) {
return '{field_id="' . $field['id'] . '"}';
}
}
}
}
return '';
}
/**
* Sender information.
*
* @since 1.4.2
*
* @param string $sender Sender strings in "Name <email@example.com>" format.
* @param array $fields List of fields.
*
* @return bool|array
*/
public function get_sender_details( $sender, $fields ) {
preg_match( '/(.+?)\<(.+?)\>/', $sender, $tag );
if ( ! empty( $tag[1] ) && ! empty( $tag[2] ) ) {
return array(
'name' => $this->get_smarttags( $tag[1], $fields ),
'address' => $this->get_smarttags( $tag[2], $fields ),
);
}
return false;
}
}
new WPForms_Contact_Form_7();
class-pirate-forms.php 0000666 00000044431 15114275427 0011012 0 ustar 00 <?php
/**
* Pirate Forms Importer class.
*
* @package WPForms
* @author WPForms
* @since 1.4.9
* @license GPL-2.0+
* @copyright Copyright (c) 2018, WPForms LLC
*/
class WPForms_Pirate_Forms extends WPForms_Importer {
/**
* Direct URL to download the latest version of WP Mail SMTP plugin from WP.org repo.
*
* @since 1.4.9
*
* @var string
*/
const URL_SMTP_ZIP = 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip';
/**
* WP Mail SMTP plugin basename.
*
* @since 1.4.9
*
* @var string
*/
const SLUG_SMTP_PLUGIN = 'wp-mail-smtp/wp_mail_smtp.php';
/**
* Default PirateForms smart tags.
*
* @var array
*/
public static $tags = array(
'[email]',
);
/**
* Define required properties.
*
* @since 1.4.9
*/
public function init() {
$this->name = 'Pirate Forms';
$this->slug = 'pirate-forms';
$this->path = 'pirate-forms/pirate-forms.php';
}
/**
* Get ALL THE FORMS.
* We need only ID's and names here.
*
* @since 1.4.9
*
* @return array
*/
public function get_forms() {
// Union those arrays, as array_merge() does keys reindexing.
$forms = $this->get_default_forms() + $this->get_pro_forms();
// Sort by IDs ASC.
ksort( $forms );
return $forms;
}
/**
* Pirate Forms has a default form, which doesn't have an ID.
*
* @since 1.4.9
*
* @return array
*/
protected function get_default_forms() {
$form = PirateForms_Util::get_form_options();
// Just make sure that it's there and not broken.
if ( empty( $form ) ) {
return array();
}
return array( 0 => esc_html__( 'Default Form', 'wpforms-lite' ) );
}
/**
* Copy-paste from Pro plugin code, it doesn't have API to get this data easily.
*
* @since 1.4.9
*
* @return array
*/
protected function get_pro_forms() {
$forms = array();
$query = new WP_Query(
array(
'post_type' => 'pf_form',
'post_status' => 'publish',
'posts_per_page' => - 1,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
)
);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$forms[ get_the_ID() ] = get_the_title();
}
}
return $forms;
}
/**
* Get a single form options.
*
* @since 1.4.9
*
* @param int $id Form ID.
*
* @return array
*/
public function get_form( $id ) {
return PirateForms_Util::get_form_options( (int) $id );
}
/**
* Import a single form using AJAX.
*
* @since 1.4.9
*/
public function import_form() {
// Run a security check.
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can() ) {
wp_send_json_error();
}
$analyze = isset( $_POST['analyze'] );
$pf_form_id = isset( $_POST['form_id'] ) ? (int) $_POST['form_id'] : 0;
$pf_form = $this->get_form( $pf_form_id );
$pf_fields_custom = PirateForms_Util::get_post_meta( $pf_form_id, 'custom' );
$pf_fields_default = array(
'name',
'email',
'subject',
'message',
'attachment',
'checkbox',
'recaptcha',
);
$fields_pro_plain = array( 'tel' ); // Convert them in Lite to the closest Standard alternatives.
$fields_pro_omit = array( 'label', 'file', 'attachment' ); // Strict PRO fields with no Lite alternatives.
$upgrade_plain = array();
$upgrade_omit = array();
$unsupported = array();
$fields = array();
if ( ! empty( $pf_fields_custom[0] ) ) {
$pf_fields_custom = $pf_fields_custom[0];
} else {
$pf_fields_custom = array();
}
if ( empty( $pf_form_id ) ) {
$pf_form_name = esc_html__( 'Default Form', 'wpforms-lite' );
} else {
$pf_form_name = get_post_field( 'post_title', $pf_form_id );
}
$pf_form_name = wpforms_decode_string( apply_filters( 'the_title', $pf_form_name, $pf_form_id ) );
// Prepare all DEFAULT fields.
foreach ( $pf_fields_default as $field ) {
// Ignore fields that are not displayed or not added at all.
if ( empty( $pf_form[ 'pirateformsopt_' . $field . '_field' ] ) ) {
continue;
}
// Ignore certain fields as they are dealt with later.
if ( 'recaptcha' === $field ) {
continue;
}
$required = 'req' === $pf_form[ 'pirateformsopt_' . $field . '_field' ] ? '1' : '';
$label = ! empty( $pf_form[ 'pirateformsopt_label_' . $field ] ) ? $pf_form[ 'pirateformsopt_label_' . $field ] : ucwords( $field );
// If it is Lite and it's a field type not included, make a note then continue to the next field.
if ( ! wpforms()->pro && in_array( $field, $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
}
if ( ! wpforms()->pro && in_array( $field, $fields_pro_omit, true ) ) {
$upgrade_omit[] = $label;
continue;
}
// Determine next field ID to assign.
if ( empty( $fields ) ) {
$field_id = 1;
} else {
$field_id = (int) max( array_keys( $fields ) ) + 1;
}
// Separately process certain fields.
switch ( $field ) {
case 'name':
case 'email':
case 'subject':
case 'message':
$type = $field;
if ( 'subject' === $field ) {
$type = 'text';
} elseif ( 'message' === $field ) {
$type = 'textarea';
}
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'required' => $required,
'size' => 'medium',
);
if ( 'name' === $field ) {
$fields[ $field_id ]['format'] = 'simple';
}
break;
case 'checkbox':
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => 'checkbox',
'label' => esc_html__( 'Single Checkbox Field', 'wpforms-lite' ),
'choices' => array(
1 => array(
'label' => $label,
'value' => '',
),
),
'size' => 'medium',
'required' => $required,
'label_hide' => true,
);
break;
case 'attachment':
case 'file':
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => 'file-upload',
'label' => $label,
'required' => $required,
'label_hide' => true,
);
// If PF attachments were saved into FS, we need to save them in WP Media.
// That will allow admins to easily delete if needed.
if (
! empty( $pf_form['pirateformsopt_save_attachment'] ) &&
'yes' === $pf_form['pirateformsopt_save_attachment']
) {
$fields[ $field_id ]['media_library'] = true;
}
break;
}
}
// Prepare all CUSTOM fields.
foreach ( $pf_fields_custom as $id => $field ) {
// Ignore fields that are not displayed.
if ( empty( $field['display'] ) ) {
continue;
}
$required = 'req' === $field['display'] ? '1' : ''; // Possible values in PF: 'yes', 'req'.
$label = sanitize_text_field( $field['label'] );
// If it is Lite and it's a field type not included, make a note then continue to the next field.
if ( ! wpforms()->pro && in_array( $field['type'], $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
}
if ( ! wpforms()->pro && in_array( $field['type'], $fields_pro_omit, true ) ) {
$upgrade_omit[] = $label;
continue;
}
// Determine next field ID to assign.
if ( empty( $fields ) ) {
$field_id = 1;
} else {
$field_id = (int) max( array_keys( $fields ) ) + 1;
}
switch ( $field['type'] ) {
case 'text':
case 'textarea':
case 'number':
case 'tel':
$type = $field['type'];
if ( 'textarea' === $field['type'] ) {
$type = 'textarea';
}
if ( 'tel' === $field['type'] ) {
$type = 'phone';
}
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'required' => $required,
'size' => 'medium',
);
if ( 'tel' === $field['type'] ) {
$fields[ $field_id ]['format'] = 'international';
}
break;
case 'checkbox':
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => 'checkbox',
'label' => esc_html__( 'Single Checkbox Field', 'wpforms-lite' ),
'choices' => array(
1 => array(
'label' => $label,
'value' => '',
),
),
'size' => 'medium',
'required' => $required,
'label_hide' => true,
);
break;
case 'select':
case 'multiselect':
$options = array();
$i = 1;
$type = 'select';
if ( 'multiselect' === $field['type'] ) {
$type = 'checkbox';
}
foreach ( explode( PHP_EOL, $field['options'] ) as $option ) {
$options[ $i ] = array(
'label' => $option,
'value' => '',
'image' => '',
);
$i ++;
}
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => $type,
'label' => $label,
'required' => $required,
'size' => 'medium',
'choices' => $options,
);
break;
case 'label':
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => 'html',
'code' => $field['label'],
'label_disable' => true,
);
break;
case 'file':
$fields[ $field_id ] = array(
'id' => $field_id,
'type' => 'file-upload',
'label' => $label,
'required' => $required,
'label_hide' => true,
);
// If PF attachments were saved into FS, we need to save them in WP Media.
// That will allow admins to easily delete if needed.
if (
! empty( $pf_form['pirateformsopt_save_attachment'] ) &&
'yes' === $pf_form['pirateformsopt_save_attachment']
) {
$fields[ $field_id ]['media_library'] = true;
}
break;
}
}
// If we are analyzing the form (in Lite only),
// we can stop here and return the details about this form.
if ( $analyze ) {
wp_send_json_success(
array(
'name' => $pf_form_name,
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
)
);
}
// Make sure we have imported some fields.
if ( empty( $fields ) ) {
wp_send_json_success(
array(
'error' => true,
'name' => $pf_form_name,
'msg' => esc_html__( 'No form fields found.', 'wpforms-lite' ),
)
);
}
// Create a form array, that holds all the data.
$form = array(
'id' => '',
'field_id' => '',
'fields' => $fields,
'settings' => array(
'form_title' => $pf_form_name,
'form_desc' => '',
'submit_text' => stripslashes( $pf_form['pirateformsopt_label_submit_btn'] ),
'submit_text_processing' => esc_html__( 'Sending', 'wpforms-lite' ),
'honeypot' => empty( $pf_form['pirateformsopt_recaptcha_field'] ) ? '0' : '1',
'notification_enable' => '1',
'notifications' => array(
1 => array(
'notification_name' => esc_html__( 'Default Notification', 'wpforms-lite' ),
'email' => $pf_form['pirateformsopt_email_recipients'],
/* translators: %s - form name. */
'subject' => sprintf( esc_html__( 'New Entry: %s', 'wpforms-lite' ), $pf_form_name ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => $this->get_smarttags( $pf_form['pirateformsopt_email'], $fields ),
'replyto' => '',
'message' => '{all_fields}',
),
),
'confirmations' => array(
1 => array(
'type' => empty( $pf_form['pirateformsopt_thank_you_url'] ) ? 'message' : 'page',
'page' => (int) $pf_form['pirateformsopt_thank_you_url'],
'message' => ! empty( $pf_form['pirateformsopt_label_submit'] ) ? $pf_form['pirateformsopt_label_submit'] : esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ),
'message_scroll' => '1',
),
),
'disable_entries' => 'yes' === $pf_form['pirateformsopt_store'] ? '0' : '1',
'import_form_id' => $pf_form_id,
),
);
// Do not save user IP address and UA.
if ( empty( $pf_form['pirateformsopt_store_ip'] ) || 'yes' !== $pf_form['pirateformsopt_store_ip'] ) {
$wpforms_settings = get_option( 'wpforms_settings', array() );
$wpforms_settings['gdpr'] = true;
update_option( 'wpforms_settings', $wpforms_settings );
$form['settings']['disable_ip'] = true;
}
// Save recaptcha keys.
if (
! empty( $pf_form['pirateformsopt_recaptcha_field'] ) &&
'yes' === $pf_form['pirateformsopt_recaptcha_field']
) {
// If the user has already defined v2 reCAPTCHA keys, use those.
$site_key = wpforms_setting( 'recaptcha-site-key', '' );
$secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
// Try to abstract keys from PF.
if ( empty( $site_key ) || empty( $secret_key ) ) {
if ( ! empty( $pf_form['pirateformsopt_recaptcha_sitekey'] ) && ! empty( $pf_form['pirateformsopt_recaptcha_secretkey'] ) ) {
$wpforms_settings = get_option( 'wpforms_settings', array() );
$wpforms_settings['recaptcha-site-key'] = $pf_form['pirateformsopt_recaptcha_sitekey'];
$wpforms_settings['recaptcha-secret-key'] = $pf_form['pirateformsopt_recaptcha_secretkey'];
$wpforms_settings['recaptcha-type'] = 'v2';
update_option( 'wpforms_settings', $wpforms_settings );
}
}
if (
( ! empty( $site_key ) && ! empty( $secret_key ) ) ||
( ! empty( $wpforms_settings['recaptcha-site-key'] ) && ! empty( $wpforms_settings['recaptcha-secret-key'] ) )
) {
$form['settings']['recaptcha'] = '1';
}
}
$this->import_smtp( $pf_form_id, $form );
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
}
/**
* Replace 3rd-party form provider tags/shortcodes with our own Smart Tags.
* See: PirateForms_Util::get_magic_tags() for all PF tags.
*
* @since 1.4.9
*
* @param string $string String to process the smart tag in.
* @param array $fields List of fields for the form.
*
* @return string
*/
public function get_smarttags( $string, $fields ) {
foreach ( self::$tags as $tag ) {
$wpf_tag = '';
if ( '[email]' === $tag ) {
foreach ( $fields as $field ) {
if ( 'email' === $field['type'] ) {
$wpf_tag = '{field_id="' . $field['id'] . '"}';
break;
}
}
}
$string = str_replace( $tag, $wpf_tag, $string );
}
return $string;
}
/**
* Import SMTP settings from Default form only.
*
* @since 1.4.9
*
* @param int $pf_form_id PirateForms form ID.
* @param array $form WPForms form array.
*/
protected function import_smtp( $pf_form_id, $form ) {
// At this point we import only default form SMTP settings.
if ( 0 !== $pf_form_id ) {
return;
}
$pf_form = $this->get_form( 0 );
// Use only if enabled.
if ( empty( $pf_form['pirateformsopt_use_smtp'] ) || 'yes' !== $pf_form['pirateformsopt_use_smtp'] ) {
return;
}
// If user has WP Mail SMTP already activated - do nothing as it's most likely already configured.
if ( is_plugin_active( self::SLUG_SMTP_PLUGIN ) ) {
return;
}
// Check that we successfully installed and activated the plugin.
if ( ! $this->install_activate_smtp() ) {
return;
}
/*
* Finally, start the settings importing.
*/
// WP Mail SMTP 1.x and PHP 5.3+ are allowed. Older WPMS versions are ignored.
if ( ! function_exists( 'wp_mail_smtp' ) ) {
return;
}
// TODO: change to \WPMailSMTP\Options in future.
$options = get_option( 'wp_mail_smtp', array() );
$options['mail']['from_email'] = $this->get_smarttags( $pf_form['pirateformsopt_email'], $form['fields'] );
$options['mail']['mailer'] = 'smtp';
$options['smtp']['host'] = $pf_form['pirateformsopt_smtp_host'];
$options['smtp']['port'] = $pf_form['pirateformsopt_smtp_port'];
$options['smtp']['encryption'] = empty( $pf_form['pirateformsopt_use_secure'] ) ? 'none' : $pf_form['pirateformsopt_use_secure'];
$options['smtp']['auth'] = ! empty( $pf_form['pirateformsopt_use_smtp_authentication'] ) && 'yes' === $pf_form['pirateformsopt_use_smtp_authentication'];
$options['smtp']['user'] = $pf_form['pirateformsopt_smtp_username'];
$options['smtp']['pass'] = $pf_form['pirateformsopt_smtp_password'];
update_option( 'wp_mail_smtp', $options );
}
/**
* Do all the voodoo to install and activate the WP Mail SMTP plugin behind the scene.
* No user interaction is needed.
*
* @since 1.4.9
*
* @return bool
*/
protected function install_activate_smtp() {
/*
* Check installation.
* If installed but not activated - bail.
* We don't want to break current site email deliverability.
*/
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// FALSE will bail the import.
if ( array_key_exists( self::SLUG_SMTP_PLUGIN, get_plugins() ) ) {
return false;
}
/*
* Let's try to install.
*/
$url = add_query_arg(
array(
'provider' => $this->slug,
'page' => 'wpforms-tools',
'view' => 'importer',
),
admin_url( 'admin.php' )
);
$creds = request_filesystem_credentials( esc_url_raw( $url ), '', false, false, null );
// Check for file system permissions.
if ( false === $creds ) {
return false;
}
if ( ! WP_Filesystem( $creds ) ) {
return false;
}
// We do not need any extra credentials if we have gotten this far, so let's install the plugin.
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once __DIR__ . '/class-install-silent-skin.php';
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
// Create the plugin upgrader with our custom skin.
$installer = new Plugin_Upgrader( new WPForms_Install_Silent_Skin() );
// Error check.
if ( ! method_exists( $installer, 'install' ) ) {
return false;
}
$installer->install( self::URL_SMTP_ZIP );
// Flush the cache and return the newly installed plugin basename.
wp_cache_flush();
if ( $installer->plugin_info() ) {
$plugin_basename = $installer->plugin_info();
// Activate, do not redirect, run the plugin activation routine.
$activated = activate_plugin( $plugin_basename );
if ( ! is_wp_error( $activated ) ) {
return true;
}
}
return false;
}
}
new WPForms_Pirate_Forms();
.htaccess 0000666 00000000424 15114361005 0006342 0 ustar 00 <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>