예제 #1
0
/**
 * Creates or updates the inboundrocket tables
 */
function inboundrocket_db_install()
{
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    inboundrocket_set_wpdb_tables();
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_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('leads','contact','contacted','customers','ambassadors','commenters','subscribers') NOT NULL DEFAULT 'leads',\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) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_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) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_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) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_shares} (\n\t\t  `share_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t  `share_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t  `lead_hashkey` varchar(16) NOT NULL,\n\t\t  `share_type` set('contact','ss-twitter-text','is-twitter-image','click-to-tweet','ss-email-text','ss-email-image','ss-facebook-text','is-facebook-image','ss-linkedin-text','is-pinterest-image') NOT NULL,\n\t\t  `share_deleted` int(1) NOT NULL DEFAULT '0',\n\t\t  `share` text NOT NULL,\n\t\t  `post_id` int(11) NOT NULL,\n\t\t  `blog_id` int(11) unsigned NOT NULL,\n\t\t  PRIMARY KEY (`share_id`),\n\t\t  KEY `lead_hashkey` (`lead_hashkey`)\n\t\t) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_sharer_stats} (\n\t\t\t`id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n   \t\t\t`share_id` int(11) unsigned NOT NULL,\n   \t\t\t`timestamp` timestamp NOT NULL,\n   \t\t\t`type` TEXT NOT NULL,\n   \t\t\tPRIMARY KEY (`id`),\n   \t\t\tCONSTRAINT `{$wpdb->ir_sharer_stats}` FOREIGN KEY (`share_id`) REFERENCES `{$wpdb->ir_shares}` (`id`) ON DELETE CASCADE\n   \t\t) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_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) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_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) {$charset_collate};";
    dbDelta($sql);
    $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->ir_emails} (\n\t\t  `email_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t  `email_subject` varchar(255) NOT NULL,\n\t\t  `email_text_content` varchar(255) NOT NULL,\n\t\t  `email_html_content` mediumtext NOT NULL,\n\t\t  `email_deleted` int(1) NOT NULL,\n\t\t  PRIMARY KEY (`email_id`)\n\t\t) {$charset_collate};";
    dbDelta($sql);
    inboundrocket_update_option('inboundrocket_options', 'ir_db_version', INBOUNDROCKET_DB_VERSION);
    inboundrocket_track_plugin_activity("Databases Installed");
}
    /**
     * Creates onboarding settings page
     */
    function inboundrocket_plugin_onboarding()
    {
        global $wp_version;
        inboundrocket_track_plugin_activity("Loaded On-boarding Page");
        $ir_options = get_option('inboundrocket_options');
        echo '<div id="inboundrocket" class="ir-onboarding wrap ' . ($wp_version < 3.8 && !is_plugin_active('mp6/mp6.php') ? 'pre-mp6' : '') . '">';
        $this->inboundrocket_header('Inbound Rocket Plugin Setup');
        ?>
        <div class="onboarding-steps">
		<?php 
        if (!isset($_GET['activate_powerup'])) {
            ?>
            
            <?php 
            if ($ir_options['onboarding_step'] == 1) {
                ?>

                <?php 
                inboundrocket_track_plugin_activity('Onboarding Step 2 - Get Contact Reports');
                ?>

                <ol class="onboarding-steps-names">
                    <li class="onboarding-step-name completed"><?php 
                _e('Activate Inbound Rocket', 'inboundrocket');
                ?>
</li>
                    <li class="onboarding-step-name active"><?php 
                _e('Get Contact Reports', 'inboundrocket');
                ?>
</li>
                    <li class="onboarding-step-name"><?php 
                _e('Activate Power-Ups', 'inboundrocket');
                ?>
</li>
                </ol>
                <div class="onboarding-step">
                    <h2 class="onboarding-step-title"><?php 
                _e('Where should we send your contact reports?', 'inboundrocket');
                ?>
</h2>
                    <div class="onboarding-step-content">
                        <p class="onboarding-step-description"><strong>Inbound Rocket</strong> <?php 
                _e('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.', 'inboundrocket');
                ?>
</p>
                        <form id="ir-onboarding-form" method="post" action="<?php 
                echo admin_url('options.php');
                ?>
">
	                        <?php 
                $this->print_hidden_settings_fields();
                ?>
							<?php 
                settings_fields('inboundrocket_options');
                ?>
							<div>
                            <?php 
                $this->ir_email_callback();
                ?>
                            <?php 
                if (function_exists('curl_init') && function_exists('curl_setopt')) {
                    ?>
                                    <br />
                            <?php 
                    $this->ir_subscription_callback();
                    ?>
                            <?php 
                }
                ?>
							</div>
                            <input type="submit" name="submit" id="submit" class="button button-primary button-big" value="<?php 
                esc_attr_e(__('Save Email', 'inboundrocket'));
                ?>
">
                        </form>
                    </div>
                </div>

            <?php 
            } elseif ($ir_options['onboarding_step'] == 2) {
                ?>
								
                <?php 
                inboundrocket_track_plugin_activity('Onboarding Step 3 - Activate Power-Ups');
                inboundrocket_update_option('inboundrocket_options', 'onboarding_step', 3);
                ?>

				<ol class="onboarding-steps-names">
                    <li class="onboarding-step-name completed"><?php 
                _e('Activate Inbound Rocket', 'inboundrocket');
                ?>
</li>
                    <li class="onboarding-step-name completed"><?php 
                _e('Get Contact Reports', 'inboundrocket');
                ?>
</li>
                    <li class="onboarding-step-name active"><?php 
                _e('Activate Power-Ups', 'inboundrocket');
                ?>
</li>
                </ol>
                <div class="onboarding-step">
                    <h2 class="onboarding-step-title"><?php 
                _e('Grow your visitors and your contacts on', 'inboundrocket');
                ?>
 <?php 
                echo get_bloginfo('wpurl');
                ?>
<br><small><?php 
                _e('by activating power-ups now', 'inboundrocket');
                ?>
</small></h2>
                    <form id="ir-onboarding-form" method="post" action="<?php 
                echo admin_url('options.php');
                ?>
">
	                    
                        <?php 
                $this->print_hidden_settings_fields();
                ?>
                        <div class="popup-options">
                            <label class="popup-option">
                                <input type="checkbox" name="powerups" value="selection_sharer" checked="checked"><?php 
                _e('Selection Sharer', 'inboundrocket');
                ?>
                                <img src="<?php 
                echo INBOUNDROCKET_PATH;
                ?>
/img/power-ups/power-up-icon-selection-sharer@2x.png">
                            </label>
                            <label class="popup-option">
                                <input type="checkbox" name="powerups" value="click_to_tweet"><?php 
                _e('Click To Tweet', 'inboundrocket');
                ?>
                                <img src="<?php 
                echo INBOUNDROCKET_PATH;
                ?>
/img/power-ups/powerup-icon-click-to-tweet@2x.png">
                            </label>
                            <label class="popup-option">
                                <input type="checkbox" name="powerups" value="welcome_bar"><?php 
                _e('Welcome Bar', 'inboundrocket');
                ?>
                                <img src="<?php 
                echo INBOUNDROCKET_PATH;
                ?>
/img/power-ups/powerup-icon-welcome-bar@2x.png">
                            </label>
                        </div>
                        <a id="btn-activate-subscribe" href="<?php 
                echo admin_url('admin.php?page=inboundrocket_settings&inboundrocket_action=activate&redirect_to=' . urlencode(admin_url('admin.php?page=inboundrocket_settings&activate_powerup=true')));
                ?>
&power_up=selection_sharer" class="button button-primary button-big"><?php 
                esc_attr_e(__('Activate these power-ups', 'inboundrocket'));
                ?>
</a>
                        <p><a href="<?php 
                echo admin_url('admin.php?page=inboundrocket_settings&activate_powerup=false');
                ?>
"><?php 
                _e('Don\'t activate power-ups right now', 'inboundrocket');
                ?>
</a></p>
                    </form>
                </div>
                
                <script type="text/javascript">
	                jQuery(document).ready(function($){
		                $('input[name=powerups]').change(function() {
							var url = $('#btn-activate-subscribe').attr('href');
							if( $(this).is(":checked") ) {
								url = url + ','+$(this).val();
								console.log(url);
								$('#btn-activate-subscribe').prop('href',url);
							} else {
								var url = $('#btn-activate-subscribe').attr('href');
								url = url.replace(','+$(this).val(),'');
								url = url.replace($(this).val(),'');
								$('#btn-activate-subscribe').prop('href',url);
							}
						});
					});
	            </script>

            <?php 
            }
            ?>

        <?php 
        } else {
            ?>
			
            <?php 
            inboundrocket_update_option('inboundrocket_options', 'onboarding_complete', 1);
            inboundrocket_track_plugin_activity('Onboarding Complete');
            ?>

            <ol class="onboarding-steps-names">
                <li class="onboarding-step-name completed"><?php 
            _e('Activate Inbound Rocket', 'inboundrocket');
            ?>
</li>
                <li class="onboarding-step-name completed"><?php 
            _e('Get Contact Reports', 'inboundrocket');
            ?>
</li>
                <li class="onboarding-step-name completed"><?php 
            _e('Activate Power-Ups', 'inboundrocket');
            ?>
</li>
            </ol>
            <div class="onboarding-step">
                <h2 class="onboarding-step-title"><?php 
            _e('Setup Complete!', 'inboundrocket');
            ?>
<br><small><?php 
            _e('Inbound Rocket is waiting for your first form submission.', 'inboundrocket');
            ?>
</small></h2>
                <div class="onboarding-step-content">
                    <p class="onboarding-step-description"><?php 
            _e('Inbound Rocket is setup and waiting for a form submission.', 'inboundrocket');
            ?>
<br /> <?php 
            _e('Once Inbound Rocket 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 Inbound Rocket is working correctly.', 'inboundrocket');
            ?>
</p><p class="onboarding-step-description"><?php 
            if (isset($_GET['activate_powerup']) && $_GET['activate_powerup'] == 'true') {
                _e('Next to our basic form and visitor tracking the following power-ups are also activated', 'inboundrocket');
                ?>
:<br /><?php 
                _e('Press "Complete Setup" and configure your power-ups.', 'inboundrocket');
            }
            ?>
</p>
                        <a href="<?php 
            echo admin_url('admin.php?page=inboundrocket_settings');
            ?>
" class="button button-primary button-big"><?php 
            esc_attr_e(__('Complete Setup', 'inboundrocket'));
            ?>
</a>
                </div>
            </div>

        <?php 
        }
        ?>
        
        </div>

        
        <div class="onboarding-steps-help">
            <h4><?php 
        _e('Any questions?', 'inboundrocket');
        ?>
</h4>
            <?php 
        if (isset($ir_options['premium']) && $ir_options['premium']) {
            ?>
                <p><?php 
            _e('Send us a message and we’re happy to help you get set up.', 'inboundrocket');
            ?>
</p>
                <a class="button" href="mailto:help@inboundrocket.co?Subject=Hello" title="Contact Inbound Rocket Support."><?php 
            _e('Mail with us', 'inboundrocket');
            ?>
</a>
            <?php 
        } else {
            ?>
                <p><?php 
            _e('Leave us a message in the WordPress support forums. We\'re always happy to help you get set up and can answer any questions there.', 'inboundrocket');
            ?>
</p>
                <a class="button" href="https://wordpress.org/support/plugin/inbound-rocket" target="_blank"><?php 
            _e('Go to Forums', 'inboundrocket');
            ?>
</a>
            <?php 
        }
        ?>
        </div>
        

        <?php 
        $this->inboundrocket_footer();
        //end wrap
        echo '</div>';
    }