Ejemplo n.º 1
0
/** 
 * Sets the default lists for V2.0.0 and converts all existing statuses to tag format
 *
 */
function leadout_convert_statuses_to_tags()
{
    global $wpdb;
    $blog_ids = array();
    if (is_multisite()) {
        $blog_id = (object) Null;
        $blog_id->blog_id = $wpdb->blogid;
        array_push($blog_ids, $blog_id);
    } else {
        $blog_id = (object) Null;
        $blog_id->blog_id = 0;
        array_push($blog_ids, $blog_id);
    }
    foreach ($blog_ids as $blog) {
        if (is_multisite()) {
            $q = $wpdb->prepare("SELECT COUNT(TABLE_NAME) FROM information_schema.tables WHERE TABLE_NAME = {$wpdb->li_leads} LIMIT 1");
            $leadout_tables_exist = $wpdb->get_var($q);
            if (!$leadout_tables_exist) {
                leadout_db_install();
            }
        }
        // Get all the contacts from li_leads
        $q = $wpdb->prepare("SELECT lead_id, lead_status, hashkey FROM li_leads WHERE lead_status != 'contact' AND lead_email != '' AND lead_deleted = 0 AND blog_id = %d", $blog->blog_id);
        $contacts = $wpdb->get_results($q);
        // Check if there are any subscribers in the li_leads table and build the list if any exist
        $subscriber_exists = FALSE;
        foreach ($contacts as $contact) {
            if ($contact->lead_status == 'subscribe') {
                $subscriber_exists = TRUE;
                break;
            }
        }
        // Check if LeadOut Subscribe is activated
        if (!$subscriber_exists) {
            if (WPLeadIn::is_power_up_active('subscribe_widget')) {
                $subscriber_exists = TRUE;
            }
        }
        $existing_synced_lists = array();
        // Check to see if the mailchimp power-up is active and add the existing synced list for serialization
        $mailchimp_options = get_option('leadin_mls_options');
        if ($mailchimp_options['li_mls_subscribers_to_list']) {
            $leadout_mailchimp = new WPMailChimpConnect(TRUE);
            $leadout_mailchimp->admin_init();
            $lists = $leadout_mailchimp->admin->li_get_lists();
            if (count($lists)) {
                foreach ($lists as $list) {
                    if ($list->id == $mailchimp_options['li_mls_subscribers_to_list']) {
                        array_push($existing_synced_lists, array('esp' => 'mailchimp', 'list_id' => $list->id, 'list_name' => $list->name));
                        break;
                    }
                }
            }
        }
        // Check to see if the constant contact power-up is active and add the existing synced list for serialization
        $constant_contact_options = get_option('leadin_cc_options');
        if ($constant_contact_options['li_cc_subscribers_to_list']) {
            $leadout_constant_contact = new WPConstantContactConnect(TRUE);
            $leadout_constant_contact->admin_init();
            $lists = $leadout_constant_contact->admin->li_get_lists();
            if (count($lists)) {
                foreach ($lists as $list) {
                    if ($list->id == str_replace('@', '%40', $constant_contact_options['li_cc_subscribers_to_list'])) {
                        array_push($existing_synced_lists, array('esp' => 'constant_contact', 'list_id' => end(explode('/', $list->id)), 'list_name' => $list->name));
                        break;
                    }
                }
            }
        }
        unset($leadout_constant_contact);
        unset($leadout_mailchimp);
        // Create all the default comment lists (Commenters, Leads, Contacted, Customers). Figures out if it should add the subscriber list and puts the lists in the correct order
        $q = "\n            INSERT INTO {$wpdb->li_tags} \n                ( tag_text, tag_slug, tag_form_selectors, tag_synced_lists, tag_order ) \n            VALUES " . ($subscriber_exists ? "('Subscribers', 'subscribers', '.vex-dialog-form', " . (count($existing_synced_lists) ? $wpdb->prepare('%s', serialize($existing_synced_lists)) : "''") . ", 1 ), " : "") . " ('Commenters', 'commenters', '#commentform', '', " . ($subscriber_exists ? "2" : "1") . "),\n                ('Leads', 'leads', '', '', " . ($subscriber_exists ? "3" : "2") . "),\n                ('Contacted', 'contacted', '', '', " . ($subscriber_exists ? "4" : "3") . "),\n                ('Customers', 'customers', '', '', " . ($subscriber_exists ? "5" : "4") . ")";
        $wpdb->query($q);
        $tags = $wpdb->get_results("SELECT tag_id, tag_slug FROM {$wpdb->li_tags} WHERE tag_slug IN ( 'commenters', 'leads', 'contacted', 'customers', 'subscribers' )");
        foreach ($tags as $tag) {
            ${$tag->tag_slug . '_tag_id'} = $tag->tag_id;
        }
        $insert_values = '';
        foreach ($contacts as $contact) {
            switch ($contact->lead_status) {
                case 'comment':
                    $tag_id = $commenters_tag_id;
                    break;
                case 'lead':
                    $tag_id = $leads_tag_id;
                    break;
                case 'contacted':
                    $tag_id = $contacted_tag_id;
                    break;
                case 'customer':
                    $tag_id = $customers_tag_id;
                    break;
                case 'subscribe':
                    $tag_id = $subscribers_tag_id;
                    break;
            }
            $insert_values .= '(' . $tag_id . ', "' . $contact->hashkey . '" ),';
        }
        $q = "INSERT INTO {$wpdb->li_tag_relationships} ( tag_id, contact_hashkey ) VALUES " . rtrim($insert_values, ',');
        $wpdb->query($q);
        if (is_multisite()) {
            $q = $wpdb->prepare("INSERT {$wpdb->li_leads} SELECT * FROM li_leads WHERE li_leads.blog_id = %d", $blog->blog_id);
            $wpdb->query($q);
            $q = $wpdb->prepare("INSERT {$wpdb->li_pageviews} SELECT * FROM li_pageviews WHERE li_pageviews.blog_id = %d", $blog->blog_id);
            $wpdb->query($q);
            $q = $wpdb->prepare("INSERT {$wpdb->li_submissions} SELECT * FROM li_submissions WHERE li_submissions.blog_id = %d", $blog->blog_id);
            $wpdb->query($q);
        }
    }
    leadout_update_option('leadin_options', 'converted_to_tags', 1);
}
Ejemplo n.º 2
0
    /**
     * Prints the admin page title, icon and help notification
     *
     * @param string
     */
    function leadout_header($page_title = '', $css_class = '', $event_name = '')
    {
        $li_options = get_option('leadin_options');
        ?>
        
        <?php 
        if ($page_title) {
            ?>
            <?php 
            screen_icon('leadout');
            ?>
            <h2 class="<?php 
            echo $css_class;
            ?>
"><?php 
            echo $page_title;
            ?>
</h2>
        <?php 
        }
        ?>

        <?php 
        if (isset($_GET['tables_restored']) && $_GET['tables_restored']) {
            ?>
            <div id="message" class="updated">
                <p>Your LeadOut database tables were successfully restored and the product should start working correctly again.</p>
            </div>
        <?php 
        }
        ?>

        
        <?php 
        if ($li_options['onboarding_complete']) {
            ?>

            <?php 
            if (isset($_GET['settings-updated'])) {
                ?>
                <div id="message" class="updated">
                    <p><strong><?php 
                _e('Settings saved.');
                ?>
</strong></p>
                </div>

                <?php 
                foreach ($this->esp_power_ups as $power_up_name => $power_up_slug) {
                    if (WPLeadIn::is_power_up_active($power_up_slug)) {
                        global ${'leadout_' . $power_up_slug . '_wp'};
                        // e.g leadout_mailchimp_connect_wp
                        $esp_name = strtolower(str_replace('_connect', '', $power_up_slug));
                        // e.g. mailchimp
                        if (${'leadout_' . $power_up_slug . '_wp'}->admin->invalid_key) {
                            echo '<div id="message" class="error">';
                            echo '<p>' . 'Your ' . $power_up_name . ' key seems to not be correct.' . '</p>';
                            echo '</div>';
                        }
                    }
                }
                ?>
            <?php 
            } elseif ($this->has_leads() == FALSE) {
                ?>
                <div id="message" class="updated">
                    <p>LeadOut is set up and waiting for a form submission...</p>
                </div>
            <?php 
            }
            ?>
        <?php 
        }
        ?>
        <?php 
    }
Ejemplo n.º 3
0
 /**
  * Gets all the contacts in a list given a tag_id
  *
  * @param 	int
  * @param 	string 		serialized array
  * @return  object
  */
 function push_contacts_to_tagged_list($tag_id = 0, $tag_synced_lists = '')
 {
     global $wpdb;
     if (!$tag_synced_lists) {
         $this->get_tag_details($tag_id);
         $tag_synced_lists = $this->details->tag_synced_lists;
     }
     $contacts = $this->get_contacts_in_tagged_list($tag_id);
     if (count($contacts) && $tag_synced_lists) {
         $synced_lists = unserialize($tag_synced_lists);
         if (count($synced_lists)) {
             foreach ($synced_lists as $synced_list) {
                 $power_up_slug = $synced_list['esp'] . '_connect';
                 // e.g leadout_mailchimp_connect_wp
                 if (WPLeadIn::is_power_up_active($power_up_slug)) {
                     global ${'leadout_' . $power_up_slug . '_wp'};
                     // e.g leadout_mailchimp_connect_wp
                     ${'leadout_' . $power_up_slug . '_wp'}->bulk_push_contact_to_list($synced_list['list_id'], $contacts);
                 }
             }
         }
     }
 }