/** * Retroactively add the names to contacts based on past form submissions for 2.2.3 upgrade * */ function leadout_set_names_retroactively() { global $wpdb; $q = "\n SELECT \n ls_1.* \n FROM \n li_submissions ls_1\n INNER JOIN\n (\n SELECT \n MAX(form_date) max_form_date, lead_hashkey\n FROM \n li_submissions\n WHERE \n LOWER(form_fields) LIKE '%name%'\n AND form_deleted = 0\n GROUP BY lead_hashkey\n ) ls_2\n ON \n ls_1.lead_hashkey = ls_2.lead_hashkey AND \n ls_1.form_date = ls_2.max_form_date\n ORDER BY\n ls_1.form_date DESC"; $submissions = $wpdb->get_results($q); if (count($submissions)) { foreach ($submissions as $submission) { $contact_first_name = ''; $contact_last_name = ''; $fields = json_decode(stripslashes($submission->form_fields), TRUE); if (count($fields)) { foreach ($fields as $key => $field) { $lower_label_text = strtolower($field['label']); if ($lower_label_text == 'first' || $lower_label_text == 'first name' || $lower_label_text == 'name' || $lower_label_text == 'your name' || $lower_label_text == 'your first name') { $contact_first_name = $field['value']; } if ($lower_label_text == 'last' || $lower_label_text == 'last name' || $lower_label_text == 'your last name' || $lower_label_text == 'surname') { $contact_last_name = $field['value']; } } } if ($contact_first_name || $contact_last_name) { $q = $wpdb->prepare("UPDATE {$wpdb->li_leads} SET lead_first_name = %s, lead_last_name = %s WHERE hashkey = %s", $contact_first_name, $contact_last_name, $submission->lead_hashkey); $wpdb->query($q); } } } leadout_update_option('leadin_options', 'names_added_to_contacts', 1); }
/** * Creates onboarding settings page */ function leadout_plugin_onboarding() { global $wp_version; $li_options = get_option('leadin_options'); echo '<div id="leadout" class="li-onboarding wrap centered' . ($wp_version < 3.8 && !is_plugin_active('mp6/mp6.php') ? 'pre-mp6' : '') . '">'; ?> <div class="oboarding-steps"> <img src="<?php echo LEADIN_PATH . '/images/leadout_logo.png'; ?> " width="147px"> <?php if ($li_options['onboarding_step'] <= 1) { ?> <?php $this->leadout_header('You\'re 3 steps away from understanding your visitors better.', 'li_setup_header', 'Onboarding Step 2 - Get Contact Reports'); ?> <ol class="oboarding-steps-names"> <li class="oboarding-step-name completed">Activate LeadOut</li> <li class="oboarding-step-name active">Get Contact Reports</li> <li class="oboarding-step-name">Grow Your Contacts List</li> <li class="oboarding-step-name">Email your new contacts</li> </ol> <div class="oboarding-step"> <h2 class="oboarding-step-title">Where should we send your contact reports?</h2> <div class="oboarding-step-content"> <p class="oboarding-step-description">LeadOut will help you get to know your website visitors by sending you a report including traffic source and pageview history each time a visitor fills out a form.</p> <form id="li-onboarding-form" method="post" action="options.php"> <div> <?php settings_fields('leadout_settings_options'); ?> <?php $this->li_email_callback(); ?> </div> <?php $this->print_hidden_settings_fields(); ?> <input type="submit" name="submit" id="onboarding-step-1-button" class="button button-primary button-big" style="margin-top: 15px;" value="<?php esc_attr_e('Save Email'); ?> "> </form> </div> </div> <!-- Facebook Conversion Code for Installed plugin --> <script>(function() { var _fbq = window._fbq || (window._fbq = []); if (!_fbq.loaded) { var fbds = document.createElement('script'); fbds.async = true; fbds.src = '//connect.facebook.net/en_US/fbds.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fbds, s); _fbq.loaded = true; } })(); window._fbq = window._fbq || []; window._fbq.push(['track', '6024677413664', {'value':'0.00','currency':'USD'}]); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6024677413664&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript> <?php } elseif ($li_options['onboarding_step'] == 2 && !isset($_GET['activate_popup']) && !isset($_GET['activate_esp'])) { ?> <?php $this->leadout_header('You\'re 2 steps away from understanding your visitors better.', 'li_setup_header', 'Onboarding Step 3 - Grow Your Contact List'); ?> <ol class="oboarding-steps-names"> <li class="oboarding-step-name completed">Activate LeadOut</li> <li class="oboarding-step-name completed">Get Contact Reports</li> <li class="oboarding-step-name active">Grow Your Contacts List</li> <li class="oboarding-step-name">Email your new contacts</li> </ol> <div class="oboarding-step"> <h2 class="oboarding-step-title">Grow your contacts list with our popup form</h2> <div class="oboarding-step-content"> <p class="oboarding-step-description">Start converting more visitors to contacts on <?php echo get_bloginfo('wpurl'); ?> . Don't worry, you'll be able to customize this form more later.</p> </div> <form id="li-onboarding-form" method="post" action="options.php"> <?php $this->print_hidden_settings_fields(); ?> <div class="popup-options"> <label class="popup-option"> <input type="radio" name="popup-position" value="slide_in" checked="checked" >Slide in <img src="<?php echo LEADIN_PATH; ?> /images/popup-bottom.png"> </label> <label class="popup-option"> <input type="radio" name="popup-position" value="popup">Popup <img src="<?php echo LEADIN_PATH; ?> /images/popup-over.png"> </label> <label class="popup-option"> <input type="radio" name="popup-position" value="top">Top <img src="<?php echo LEADIN_PATH; ?> /images/popup-top.png"> </label> </div> <a id="btn-activate-subscribe" href="<?php echo get_admin_url() . 'admin.php?page=leadout_settings&leadout_action=activate&power_up=subscribe_widget&redirect_to=' . get_admin_url() . urlencode('admin.php?page=leadout_settings&activate_popup=true&popup_position=slide_in'); ?> " class="button button-primary button-big"><?php esc_attr_e('Activate the popup form'); ?> </a> <p><a href="<?php echo get_admin_url() . 'admin.php?page=leadout_settings&activate_popup=false'; ?> ">Don't activate the popup form right now</a></p> </form> </div> <?php } elseif (isset($_GET['activate_popup']) && !isset($_GET['activate_esp'])) { ?> <?php // Set the popup position based on get URL if (isset($_GET['activate_popup'])) { if (isset($_GET['popup_position'])) { $vex_class_option = ''; switch ($_GET['popup_position']) { case 'slide_in': $vex_class_option = 'vex-theme-bottom-right-corner'; break; case 'popup': $vex_class_option = 'vex-theme-default'; break; case 'top': $vex_class_option = 'vex-theme-top'; break; } leadout_update_option('leadin_subscribe_options', 'li_subscribe_vex_class', $vex_class_option); } } ?> <?php $this->leadout_header('You\'re 1 step away from understanding your visitors better.', 'li_setup_header', 'Onboarding Step 4 - Email your contacts'); ?> <ol class="oboarding-steps-names"> <li class="oboarding-step-name completed">Activate LeadOut</li> <li class="oboarding-step-name completed">Get Contact Reports</li> <li class="oboarding-step-name completed">Grow Your Contacts List</li> <li class="oboarding-step-name active">Email your new contacts</li> </ol> <div class="oboarding-step"> <h2 class="oboarding-step-title">Which email provider do you use?</h2> <div class="oboarding-step-content"> <p class="oboarding-step-description">LeadOut works best when connected to an email provider. Don’t worry, we won’t start syncing contacts until we get your account details later.</p> </div> <form id="li-onboarding-form" method="post" action="options.php"> <?php $this->print_hidden_settings_fields(); ?> <div class="popup-options"> <label class="esp-option"> <input type="radio" name="esp" value="mailchimp_connect" checked="checked" ><span class="esp-name mailchimp">MailChimp</span> </label> <label class="esp-option"> <input type="radio" name="esp" value="constant_contact_connect"><span class="esp-name constant-contact">Constant Contact</span> </label> <label class="esp-option"> <input type="radio" name="esp" value="aweber_connect"><span class="esp-name aweber">Aweber</span> </label> <label class="esp-option"> <input type="radio" name="esp" value="getresponse_connect"><span class="esp-name getresponse">GetResponse</span> </label> <label class="esp-option"> <input type="radio" name="esp" value="campaign_monitor_connect"><span class="esp-name campaign-monitor">CampaignMonitor</span> </label> </div> <a id="btn-activate-esp" href="<?php echo get_admin_url() . 'admin.php?page=leadout_settings&leadout_action=activate&power_up=mailchimp_connect&redirect_to=' . get_admin_url() . urlencode('admin.php?page=leadout_settings&activate_esp=true&esp=mailchimp'); ?> " class="button button-primary button-big"><?php esc_attr_e('Select your email tool'); ?> </a> <p><a href="<?php echo get_admin_url() . 'admin.php?page=leadout_settings&activate_esp=false'; ?> ">Don't connect an email provider right now</a></p> </form> </div> <?php } elseif (isset($_GET['activate_esp'])) { ?> <?php leadout_update_option('leadin_options', 'onboarding_complete', 1); ?> <?php $this->leadout_header('Setup Complete!', 'li_setup_header', 'Onboarding Complete'); ?> <ol class="oboarding-steps-names"> <li class="oboarding-step-name completed">Activate LeadOut</li> <li class="oboarding-step-name completed">Get Contact Reports</li> <li class="oboarding-step-name completed">Grow Your Contacts List</li> <li class="oboarding-step-name completed">Email your new contacts</li> </ol> <div class="oboarding-step"> <h2 class="oboarding-step-title">LeadOut is waiting for your first form submission.</h2> <div class="oboarding-step-content"> <p class="oboarding-step-description">LeadOut is set up and waiting for a form submission. Once LeadOut detects a form submission, a new contact will be added to your contacts list. We recommend filling out a form on your site to test that LeadOut is working correctly.</p> <form id="li-onboarding-form" method="post" action="options.php"> <?php $this->print_hidden_settings_fields(); ?> <a href="<?php echo get_admin_url() . 'admin.php?page=leadout_settings'; ?> " class="button button-primary button-big"><?php esc_attr_e('Complete Setup'); ?> </a> </form> </div> </div> <?php } ?> </div><!--/oboarding-steps --> </div><!--/wrap --> <?php }
/** * Creates or updates the LeadOut tables */ function leadout_db_install() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $multisite_prefix = is_multisite() ? $wpdb->prefix : ''; $sql = "\n\t\tCREATE TABLE " . $multisite_prefix . "li_leads (\n\t\t `lead_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `lead_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t `hashkey` varchar(16) DEFAULT NULL,\n\t\t `lead_ip` varchar(40) DEFAULT NULL,\n\t\t `lead_source` text,\n\t\t `lead_email` varchar(255) DEFAULT NULL,\n\t\t `lead_first_name` varchar(255) NOT NULL,\n \t\t `lead_last_name` varchar(255) NOT NULL,\n\t\t `lead_status` set('contact','lead','comment','subscribe','contacted','customer') NOT NULL DEFAULT 'contact',\n\t\t `merged_hashkeys` text,\n\t\t `lead_deleted` int(1) NOT NULL DEFAULT '0',\n\t\t `blog_id` int(11) unsigned NOT NULL,\n\t\t `company_data` mediumtext NOT NULL,\n \t\t `social_data` mediumtext NOT NULL,\n\t\t PRIMARY KEY (`lead_id`),\n\t\t KEY `hashkey` (`hashkey`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;\n\n\t\tCREATE TABLE " . $multisite_prefix . "li_pageviews (\n\t\t `pageview_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `pageview_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t `lead_hashkey` varchar(16) NOT NULL,\n\t\t `pageview_title` varchar(255) NOT NULL,\n\t\t `pageview_url` text NOT NULL,\n\t\t `pageview_source` text NOT NULL,\n\t\t `pageview_session_start` int(1) NOT NULL,\n\t\t `pageview_deleted` int(1) NOT NULL DEFAULT '0',\n\t\t `blog_id` int(11) unsigned NOT NULL,\n\t\t PRIMARY KEY (`pageview_id`),\n\t\t KEY `lead_hashkey` (`lead_hashkey`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;\n\n\t\tCREATE TABLE " . $multisite_prefix . "li_submissions (\n\t\t `form_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `form_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t `lead_hashkey` varchar(16) NOT NULL,\n\t\t `form_page_title` varchar(255) NOT NULL,\n\t\t `form_page_url` text NOT NULL,\n\t\t `form_fields` text NOT NULL,\n\t\t `form_selector_id` mediumtext NOT NULL,\n\t\t `form_selector_classes` mediumtext NOT NULL,\n\t\t `form_hashkey` varchar(16) NOT NULL,\n\t\t `form_deleted` int(1) NOT NULL DEFAULT '0',\n\t\t `blog_id` int(11) unsigned NOT NULL,\n\t\t PRIMARY KEY (`form_id`),\n\t\t KEY `lead_hashkey` (`lead_hashkey`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;\n\n\t\tCREATE TABLE " . $multisite_prefix . "li_tags (\n\t\t `tag_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `tag_text` varchar(255) NOT NULL,\n\t\t `tag_slug` varchar(255) NOT NULL,\n\t\t `tag_form_selectors` mediumtext NOT NULL,\n\t\t `tag_synced_lists` mediumtext NOT NULL,\n\t\t `tag_order` int(11) unsigned NOT NULL,\n\t\t `blog_id` int(11) unsigned NOT NULL,\n\t\t `tag_deleted` int(1) NOT NULL,\n\t\t PRIMARY KEY (`tag_id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;\n\n\t\tCREATE TABLE " . $multisite_prefix . "li_tag_relationships (\n\t\t `tag_relationship_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t `tag_id` int(11) unsigned NOT NULL,\n\t\t `contact_hashkey` varchar(16) NOT NULL,\n \t\t `form_hashkey` varchar(16) NOT NULL,\n\t\t `tag_relationship_deleted` int(1) unsigned NOT NULL,\n\t\t `blog_id` int(11) unsigned NOT NULL,\n\t\t PRIMARY KEY (`tag_relationship_id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;"; dbDelta($sql); leadout_update_option('leadin_options', 'li_db_version', LEADIN_DB_VERSION); }