JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace WPForms\Integrations\ConstantContact\V3\Settings;
use Exception;
use WPForms\Integrations\ConstantContact\V3\Api\Api;
use WPForms\Integrations\ConstantContact\V3\Auth;
use WPForms\Integrations\ConstantContact\V3\ConstantContact;
use WPForms\Providers\Provider\Settings\FormBuilder as FormBuilderAbstract;
/**
* Class FormBuilder.
*
* @since 1.9.3
*/
class FormBuilder extends FormBuilderAbstract {
/**
* Register all hooks (actions and filters) here.
*
* @since 1.9.3
*/
protected function init_hooks() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
parent::init_hooks();
add_filter(
'wpforms_providers_settings_builder_ajax_connections_get_' . $this->core->slug,
[ $this, 'ajax_connections_get' ]
);
if ( is_admin() ) {
add_filter(
"wpforms_providers_provider_settings_formbuilder_display_content_default_screen_{$this->core->slug}",
[ $this, 'builder_settings_default_content' ]
);
}
add_filter( 'wpforms_save_form_args', [ $this, 'save_form' ], 11, 3 );
}
/**
* Display content inside the panel sidebar area.
*
* @since 1.9.3
*/
public function display_sidebar() {
if ( ConstantContact::get_current_version() !== 3 ) {
return;
}
parent::display_sidebar();
}
/**
* Enqueue JavaScript and CSS files if needed.
* When extending - include the `parent::enqueue_assets();` not to break things!
*
* @since 1.9.3
*/
public function enqueue_assets() {
parent::enqueue_assets();
$min = wpforms_get_min_suffix();
wp_enqueue_script(
'wpforms-constant-contact-v3-builder',
WPFORMS_PLUGIN_URL . "assets/js/integrations/constant-contact-v3/builder{$min}.js",
[ 'underscore', 'wpforms-admin-builder-providers', 'wpforms-constant-contact-v3-auth' ],
WPFORMS_VERSION,
true
);
}
/**
* Pre-process provider data before saving it in form_data when editing a form.
*
* @since 1.9.3
*
* @param array|mixed $form Form array which is usable with `wp_update_post()`.
* @param array $data Data retrieved from $_POST and processed.
* @param array $args Empty by default. May have custom data not intended to be saved, but used for processing.
*
* @return array
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpUnusedParameterInspection
*/
public function save_form( $form, $data, $args ): array {
$form = (array) $form;
// Get a filtered (or modified by another addon) form content.
$form_data = json_decode( stripslashes( $form['post_content'] ), true );
// Provider exists.
if ( ! empty( $form_data['providers'][ $this->core->slug ] ) ) {
$modified_post_content = $this->modify_form_data( $form_data );
if ( ! empty( $modified_post_content ) ) {
$form['post_content'] = wpforms_encode( $modified_post_content );
return $form;
}
}
/*
* This part works when modification is locked or current filter was called on NOT a Providers panel.
* Then we need to restore provider connections from the previous form content.
*/
// Get a "previous" form content (current content is still not saved).
$prev_form = ! empty( $data['id'] )
? wpforms()->obj( 'form' )->get( $data['id'], [ 'content_only' => true ] )
: [];
if ( ! empty( $prev_form['providers'][ $this->core->slug ] ) ) {
$provider = $prev_form['providers'][ $this->core->slug ];
if ( ! isset( $form_data['providers'] ) ) {
$form_data = array_merge( $form_data, [ 'providers' => [] ] );
}
$form_data['providers'] = array_merge( (array) $form_data['providers'], [ $this->core->slug => $provider ] );
$form['post_content'] = wpforms_encode( $form_data );
}
return $form;
}
/**
* Prepare modifications for form content if it's not locked.
*
* @since 1.9.3
*
* @param array $form_data Form content.
*
* @return array|null
*/
protected function modify_form_data( array $form_data ) {
/**
* The connection is locked.
* Why? User clicked the "Save" button when one of the AJAX requests
* for data retrieval from API was in progress or failed.
*/
if (
isset( $form_data['providers'][ $this->core->slug ]['__lock__'] ) &&
absint( $form_data['providers'][ $this->core->slug ]['__lock__'] ) === 1
) {
return null;
}
// Modify content as we need, done by reference.
foreach ( $form_data['providers'][ $this->core->slug ] as $connection_id => $connection ) {
if ( $connection_id === '__lock__' ) {
unset( $form_data['providers'][ $this->core->slug ]['__lock__'] );
}
}
return $form_data;
}
/**
* Rewrite the Add New Account button to trigger Auth popup instead of default authorization flow.
*
* @since 1.9.3
*/
protected function display_content_header() {
if ( ! empty( wpforms_get_providers_options( $this->core->slug ) ) ) {
parent::display_content_header();
return;
}
?>
<div class="wpforms-builder-provider-title wpforms-panel-content-section-title">
<?php echo esc_html( $this->core->name ); ?>
<button type="button" class="wpforms-builder-provider-title-add wpforms-builder-constant-contact-v3-provider-sign-up">
<?php esc_html_e( 'Add New Account', 'wpforms-lite' ); ?>
</button>
</div>
<?php
}
/**
* Get the list of all saved connections.
*
* @since 1.9.3
*
* @return array Return null on any kind of error. Array of data otherwise.
*/
public function ajax_connections_get(): array {
$data = [
'actions' => [
'subscribe' => __( 'Subscribe', 'wpforms-lite' ),
'unsubscribe' => __( 'Unsubscribe', 'wpforms-lite' ),
'delete' => __( 'Delete subscriber', 'wpforms-lite' ),
],
'actions_fields' => [
'subscribe' => [
'email' => [
'label' => __( 'Email', 'wpforms-lite' ),
'type' => 'select',
'map' => 'email',
'required' => true,
],
'list' => [
'label' => __( 'Select List', 'wpforms-lite' ),
'type' => 'select',
'required' => true,
'placeholder' => __( '--- Select Mailing List ---', 'wpforms-lite' ),
],
'custom_fields' => [
'label' => __( 'Custom Fields', 'wpforms-lite' ),
'type' => 'custom-fields',
'required' => false,
],
],
'unsubscribe' => [
'email' => [
'label' => __( 'Email', 'wpforms-lite' ),
'type' => 'select',
'map' => 'email',
'required' => true,
'placeholder' => __( '--- Select Form Field ---', 'wpforms-lite' ),
],
'opt_out_reason' => [
'label' => __( 'Reason', 'wpforms-lite' ),
'type' => 'select',
'required' => false,
'placeholder' => __( '--- Select Form Field ---', 'wpforms-lite' ),
],
],
'delete' => [
'email' => [
'label' => __( 'Email', 'wpforms-lite' ),
'type' => 'select',
'map' => 'email',
'required' => true,
],
],
],
'connections' => isset( $this->form_data['providers'][ $this->core->slug ] )
? array_reverse( $this->form_data['providers'][ $this->core->slug ], true )
: [],
'conditionals' => [],
];
foreach ( $data['connections'] as $connection ) {
if ( empty( $connection['id'] ) ) {
continue;
}
// This will either return an empty placeholder or complete set of rules, as a DOM.
$data['conditionals'][ $connection['id'] ] = wpforms()->is_pro()
? wpforms_conditional_logic()->builder_block(
[
'form' => $this->form_data,
'type' => 'panel',
'parent' => 'providers',
'panel' => $this->core->slug,
'subsection' => $connection['id'],
],
false
)
: '';
}
return array_merge( $data, $this->get_accounts_data() );
}
/**
* Get accounts data.
*
* @since 1.9.3
*
* @return array
*/
private function get_accounts_data(): array {
$accounts = wpforms_get_providers_options( $this->core->slug );
$data = [
'accounts' => $accounts,
'custom_fields' => [],
'lists' => [],
];
if ( empty( $accounts ) ) {
return $data;
}
$predefined_custom_fields = ConstantContact::get_predefined_custom_fields();
foreach ( $accounts as $account_id => $account ) {
try {
$api = new Api( $account );
$data['lists'][ $account_id ] = $api->get_contact_list();
$data['custom_fields'][ $account_id ] = array_merge( $predefined_custom_fields, $api->get_custom_fields( 'label', 'custom_field_id' ) );
} catch ( Exception $e ) {
continue;
}
}
return $data;
}
/**
* Builder custom templates.
*
* @since 1.9.3
*/
public function builder_custom_templates() {
$templates = [
'connection',
'error',
'select-field',
];
foreach ( $templates as $template ) {
$template_name = ucwords( str_replace( '-', ' ', $template ) );
$script_id = 'tmpl-wpforms-' . esc_attr( $this->core->slug ) . '-builder-content-connection';
if ( $template !== 'connection' ) {
$script_id .= '-' . $template;
}
?>
<!-- Single Constant Contact connection block: <?php echo esc_attr( $template_name ); ?>. -->
<script type="text/html" id="<?php echo esc_attr( $script_id ); ?>">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo wpforms_render(
'integrations/constant-contact-v3/builder/' . $template,
[
'slug' => $this->core->slug,
],
true
);
?>
</script>
<?php
}
}
/**
* Default content for the provider settings panel in the form builder.
*
* @since 1.9.3
*
* @param string $content Default content.
*
* @return string
* @noinspection HtmlUnknownTarget
*/
public function builder_settings_default_content( string $content ): string {
ob_start();
?>
<p>
<a
href="<?php echo esc_url( Auth::get_auth_url() ); ?>"
class="wpforms-btn wpforms-btn-md wpforms-btn-orange wpforms-builder-constant-contact-v3-provider-sign-up"
target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Try Constant Contact for Free', 'wpforms-lite' ); ?>
</a>
</p>
<p>
<?php
printf(
'<a href="%1$s" target="_blank" rel="noopener noreferrer" class="secondary-text">%2$s</a>',
esc_url( admin_url( 'admin.php?page=wpforms-page&view=constant-contact' ) ),
esc_html__( 'Learn more about the power of email marketing.', 'wpforms-lite' )
);
?>
</p>
<?php
return $content . ob_get_clean();
}
}