/** * Render promotion section. * For users without api key only. * * @since 0.1.0 * * @return string */ public function render_promotion_notice() { $result = ''; $helper = new Core\Cre_Helper(); if (!$helper->has_option('api_key')) { $result .= '<p>'; $result .= esc_html__('Still need a CleverReach account?', 'cleverreachextension') . ' '; $result .= '<a href="' . esc_url('http://www.cleverreach.com/frontend/account.php?rk=85097mbwkysub"') . '">'; $result .= esc_html__('Sign up for free!', 'cleverreachextension'); $result .= '</a>'; $result .= '</p>'; $result .= '<p><a href="' . esc_url('http://www.cleverreach.com/frontend/account.php?rk=85097mbwkysub"') . '">'; $result .= '<img src="http://s3-eu-west-1.amazonaws.com/cloud-files.crsend.com/img/affiliate/en/468_60.png" />'; $result .= '</a></p>'; } return $result; }
/** * Parse form submission via ajax and return status response. * * @since 0.1.0 */ public function ajax_controller_interaction() { check_ajax_referer($this->plugin_name . '_ajax_interaction_nonce', 'nonce'); $result = $post_attr = array(); // @TODO: if ( $_POST['cr_form'] ) { // Parse serialized ajax post data as `$post` (array). parse_str($_POST['cr_form'], $post); // @TODO: Get rid of `parse_str()` if (is_email($post['email'])) { // Prepare receiver adapter. $client = new Api\Cleverreach(); $receiver = new Api\Cleverreach_Receiver_Adapter($client); // Populate `$post_attr` (array) according to CleverReach API defaults. foreach ($post as $key => $value) { if ('email' != $key) { // Skip 'email' as this is not needed as separate attribute. array_push($post_attr, array('key' => sanitize_html_class($key), 'value' => sanitize_text_field($value))); } } // Populate `$source` (string) $helper = new Cre_Helper(); if ($helper->has_option('source')) { $source = $helper->get_option('source'); } else { $source = get_bloginfo('name'); } // Populate `$user` (array) according to CleverReach API defaults. $user = array('email' => sanitize_email($post['email']), 'registered' => time(), 'source' => esc_html($source), 'attributes' => $post_attr); $receiver_added = $receiver->add($user); // Test returned data. if (is_object($receiver_added) && 'SUCCESS' == $receiver_added->status) { $result['type'] = 'success'; // Prepare form adapter. $form = new Api\Cleverreach_Form_Adapter($client); // Send activation mail. $user_data = array('user_ip' => '127.0.0.1', 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1', 'referer' => esc_url(home_url())); $form->send_activation_mail($helper->get_option('form_id'), sanitize_email($post['email']), $user_data); } else { $result['type'] = 'error'; if ('duplicate data' == $receiver_added) { $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_duplicate', esc_html__('It seems like you\'re already subscribed to our list.', 'cleverreachextension'))); } else { $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_common', esc_html__('Sorry, there seems to be a problem with your data.', 'cleverreachextension'))); } } // end of is_object() && 'SUCCESS' } else { $result['type'] = 'error'; $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_invalid_email', esc_html__('Sorry, there seems to be a problem with your email address.', 'cleverreachextension'))); } // end of is_email() // Finally return JSON result. $result = json_encode($result); echo $result; die; }
<?php /** * Visual Composer Integration * Hooks into `cleverreach_extension` shortcode * * @since 0.2.0 * * Optimized for Visual Composer v4.6.2 * @link http://vc.wpbakery.com/ * @docs https://wpbakery.atlassian.net/wiki/display/VC/Visual+Composer+Pagebuilder+for+WordPress */ use CleverreachExtension\Core; use CleverreachExtension\Core\Api; $values = array(); $client = new Api\Cleverreach(); $helper = new Core\Cre_Helper(); if ($client->has_valid_api_key() && $helper->has_option('list_id')) { $form = new Api\Cleverreach_Form_Adapter($client); $forms = $helper->parse_list($form->get_list($helper->get_option('list_id')), 'form_id'); // Prepare dropdown list in terms of Visual Composer. foreach ($forms as $form) { $values[$form['name']] = $form['id']; } // Append `Custom` at the very end of the list. $values[esc_html__('Custom', 'cleverreachextension')] = 'custom'; } vc_map(array('name' => esc_html__('CleverReach Form', 'cleverreachextension'), 'base' => 'cleverreach_extension', 'class' => 'cleverreach_extension', 'icon' => '', 'category' => esc_html__('CleverReach', 'cleverreachextension'), 'admin_enqueue_js' => array(), 'admin_enqueue_css' => array(), 'params' => array(array('type' => 'dropdown', 'holder' => 'div', 'class' => 'cre_form_id', 'heading' => esc_html__('Form', 'cleverreachextension'), 'param_name' => 'form_id', 'value' => $values, 'std' => $helper->get_option('form_id'), 'description' => esc_html__('Check the wiki on how to customize your form.', 'cleverreachextension')))));
/** * Parse form submission via ajax and return status response. * * @since 0.1.0 * * @wp-hook wp_ajax_nopriv_cre_ajax_controller_interaction * @wp-hook wp_ajax_cre_ajax_controller_interaction */ public function ajax_controller_interaction() { check_ajax_referer($this->plugin_name . '_ajax_interaction_nonce', 'nonce'); $result = $post_attr = array(); // @TODO: if ( $_POST['cr_form'] ) { // Parse serialized ajax post data as `$post` (array). parse_str($_POST['cr_form'], $post); // @TODO: Get rid of `parse_str()` if (is_email($post['email'])) { // Prepare receiver adapter. $helper = new Cre_Helper(); $client = new Api\Cleverreach(); $receiver = new Api\Cleverreach_Receiver_Adapter($client); $group = new Api\Cleverreach_Group_Adapter($client); // Populate `$post_attr` (array) according to CleverReach API defaults. foreach ($post as $key => $value) { // Join values if $value is an array. if (is_array($value)) { $value = join(', ', $value); } if ('email' != $key) { // Skip 'email' as this is not needed as separate attribute. // Create fields for default forms. if ('true' === $helper->get_option('ajax')) { // Attribute `$key` may only contain lowercase a-z and 0-9. Everything else will be converted to `_`. $key = strtolower($key); $key = str_replace(' ', '_', $key); $key = str_replace('-', '_', $key); $key = preg_replace('/[^A-Za-z0-9\\-]/', '_', $key); if ($value && $key[0] !== '_') { // Exclude (hidden) fields starting with an underscore. $group->attribute_add($key, 0); } } array_push($post_attr, array('key' => sanitize_html_class($key), 'value' => sanitize_text_field($value))); } } // Populate `$source` (string) $source = get_bloginfo('name'); if (isset($_POST['source'])) { $source = $_POST['source']; } elseif ($helper->has_option('source')) { $source = $helper->get_option('source'); } // Populate `$user` (array) according to CleverReach API defaults. $user = array('email' => sanitize_email($post['email']), 'registered' => time(), 'source' => esc_html(trim($source)), 'attributes' => $post_attr); $list_id = empty($_POST['list']) ? $helper->get_option('list_id') : (int) $_POST['list']; $receiver_added = $receiver->add($user, $list_id); // Test returned data. if (is_object($receiver_added) && 'SUCCESS' == $receiver_added->status) { $result['type'] = 'success'; // Prepare form adapter. $form = new Api\Cleverreach_Form_Adapter($client); // Send activation mail. $user_data = array('user_ip' => '127.0.0.1', 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1', 'referer' => esc_url(home_url())); $form_id = empty($_POST['form']) ? $helper->get_option('form_id') : (int) $_POST['form']; $form->send_activation_mail($form_id, sanitize_email($post['email']), $user_data); } else { $result['type'] = 'error'; if ('duplicate data' == $receiver_added) { $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_duplicate', esc_html__('It seems like you\'re already subscribed to our list.', 'cleverreach-extension'))); } else { $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_common', esc_html__('Sorry, there seems to be a problem with your data.', 'cleverreach-extension'))); } } // end of is_object() && 'SUCCESS' } else { $result['type'] = 'error'; $result['status'] = sanitize_text_field(apply_filters('cleverreach_extension_error_msg_invalid_email', esc_html__('Sorry, there seems to be a problem with your email address.', 'cleverreach-extension'))); } // end of is_email() // Finally return JSON result. $result = json_encode($result); echo $result; die; }