/**
  * Class constructor
  */
 function __construct($activated)
 {
     //=============================================
     // Hooks & Filters
     //=============================================
     if (!$activated) {
         return false;
     }
     global $inboundrocket_selectionsharer;
     $inboundrocket_selectionsharer = $this;
     add_action('wp_enqueue_scripts', array($this, 'inboundrocket_ss_scripts'));
     add_action('wp_ajax_selection_sharer_gettext', array($this, 'inboundrocket_ss_textlist_callback'));
     add_action('wp_ajax_nopriv_selection_sharer_gettext', array($this, 'inboundrocket_ss_textlist_callback'));
     add_action('wp_ajax_selection_sharer_track', array($this, 'inboundrocket_ss_track_callback'));
     add_action('wp_ajax_nopriv_selection_sharer_track', array($this, 'inboundrocket_ss_track_callback'));
     add_action('wp_ajax_selection_sharer_settings', array($this, 'inboundrocket_ss_settings_callback'));
     add_action('wp_ajax_nopriv_selection_sharer_settings', array($this, 'inboundrocket_ss_settings_callback'));
     add_action('wp_ajax_selection_sharer_shorturl', array($this, 'inboundrocket_ss_shorturl_callback'));
     add_action('wp_ajax_nopriv_selection_sharer_shorturl', array($this, 'inboundrocket_ss_shorturl_callback'));
     if (!inboundrocket_check_premium_user()) {
         add_action('wp_head', array($this, 'inboundrocket_ss_premium'));
     }
 }
    function inboundrocket_wb_scripts()
    {
        $this->inboundrocket_wb_styles();
        if (INBOUNDROCKET_ENABLE_DEBUG == true) {
            wp_enqueue_script("inboundrocket_wb_script", INBOUNDROCKET_WELCOME_BAR_PATH . '/js/welcome-bar.js', array('jquery'), false);
        } else {
            wp_enqueue_script("inboundrocket_wb_script", INBOUNDROCKET_WELCOME_BAR_PATH . '/js/welcome-bar.min.js', array('jquery'), false);
        }
        wp_localize_script('inboundrocket_wb_script', 'inboundrocket_wb_js', array('ajaxurl' => admin_url('admin-ajax.php'), 'nextNonce' => wp_create_nonce('wb_form_lead_submitted')));
        $this->wb_options = get_option('inboundrocket_wb_options');
        $ir_wb_cta_desktop = isset($this->wb_options['ir_wb_cta_desktop']) ? esc_attr($this->wb_options['ir_wb_cta_desktop']) : '';
        $ir_wb_cta_mobile = isset($this->wb_options['ir_wb_cta_mobile']) ? esc_attr($this->wb_options['ir_wb_cta_mobile']) : '';
        $ir_wb_email_placeholder = isset($this->wb_options['ir_wb_email_placeholder']) ? esc_attr($this->wb_options['ir_wb_email_placeholder']) : '';
        $ir_wb_button_text = isset($this->wb_options['ir_wb_button_text']) ? esc_attr($this->wb_options['ir_wb_button_text']) : '';
        $ir_wb_success_text = isset($this->wb_options['ir_wb_success_text']) ? esc_attr($this->wb_options['ir_wb_success_text']) : '';
        $ir_wb_interval = isset($this->wb_options['ir_wb_interval']) ? esc_attr($this->wb_options['ir_wb_interval']) : '';
        $ir_wb_show_every = isset($this->wb_options['ir_wb_show_every']) ? esc_attr($this->wb_options['ir_wb_show_every']) : '';
        $ir_wb_color = isset($this->wb_options['ir_wb_color']) ? esc_attr($this->wb_options['ir_wb_color']) : '';
        if ($ir_wb_color == 'red') {
            $text_style = '#ffffff';
            $button_style = '#000000';
            $bar_style = '#eb593c';
        } elseif ($ir_wb_color == 'green') {
            $text_style = '#ffffff';
            $button_style = '#000000';
            $bar_style = '#569625';
        } elseif ($ir_wb_color == 'lightblue') {
            $text_style = '#000000';
            $button_style = '#ffffff';
            $bar_style = '#def1ff';
        } elseif ($ir_wb_color == 'salmon') {
            $text_style = '#000000';
            $button_style = '#ffffff';
            $bar_style = '#f0e1d1';
        } elseif ($ir_wb_color == 'lightgrey') {
            $text_style = '#000000';
            $button_style = '#ffffff';
            $bar_style = '#ededed';
        }
        ?>
	
	
	<!-- START NORMAL welcome_bar -->
	<div class="noMobile showDesktop">
		<div class="welcome_bar" style="display: none; background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
; color: <?php 
        echo !empty($text_style) ? $text_style : '#000000';
        ?>
;">
			<?php 
        if (!inboundrocket_check_premium_user()) {
            echo '<a href="http://inboundrocket.co/?utm_source=' . $_SERVER['HTTP_HOST'] . '&utm_medium=welcome-bar&utm_campaign=logo" title="' . __('Powered by Inbound Rocket - You write. We will turn them into leads', 'inboundrocket') . '" target="_blank" class="inboundrocket-wb-branding" style="background-color:';
            echo !empty($bar_style) ? $bar_style : '#eee';
            echo '" ><img src="' . INBOUNDROCKET_WELCOME_BAR_PATH . '/img/welcome-bar-logo.png" alt="" /></a>';
        }
        ?>
			<span id="welcome-span" data-success="<?php 
        echo !empty($ir_wb_success_text) ? $ir_wb_success_text : __('Thank you for signing up!', 'inboundrocket');
        ?>
" style=""><?php 
        echo !empty($ir_wb_cta_desktop) ? $ir_wb_cta_desktop : __('Join Our Mailing List', 'inboundrocket');
        ?>
					<form id="welcome_bar-form" method="post" action=""><?php 
        wp_nonce_field('welcome_bar_form_lead_submitted', 'welcome_bar_form_nonce');
        ?>
					<?php 
        wp_nonce_field('wb_form_lead_submitted', 'wb_form_nonce');
        ?>
					<input type="hidden" name="origin" id="origin" value="desktop">
					<input type="hidden" name="current_page" id="current_page" value="<?php 
        echo $this->inboundrocket_wb_getURL();
        ?>
">
					<?php 
        wp_referer_field(true);
        ?>
					<!--<input type="text" name="name" id="name" placeholder="Firstname and Lastname"> -->
	                <input type="email" name="emailaddress" id="emailaddress" placeholder="<?php 
        echo !empty($ir_wb_email_placeholder) ? $ir_wb_email_placeholder : __('Email Address', 'inboundrocket');
        ?>
">
	                <button type="submit" class="welcome_bar-link"><?php 
        echo !empty($ir_wb_button_text) ? $ir_wb_button_text : __('Submit', 'inboundrocket');
        ?>
</button>
            	</form>
            </span>
			<a class="close-notify" style="background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
;" ><img src="<?php 
        echo INBOUNDROCKET_WELCOME_BAR_PATH;
        ?>
/img/welcome-bar-up-arrow.png" /></a>
			
		</div>
		<div class="welcome_bar-stub" style="display: none;"><a class="show-notify" onclick="welcome_bar_show();" style="background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
;"><img src="<?php 
        echo INBOUNDROCKET_WELCOME_BAR_PATH;
        ?>
/img/welcome-bar-down-arrow.png" /></a></div>
	</div>
	<!-- END NORMAL welcome_bar -->

	<!-- START MOBILE welcome_bar if only email heigh 6.8em name and email 9em-->
	<div class="showMobile noDesktop">
		<div class="mwelcome_bar" data-success="<?php 
        echo !empty($ir_wb_success_text) ? $ir_wb_success_text : __('Thank you for signing up!', 'inboundrocket');
        ?>
" style="display: none; background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
; color: <?php 
        echo !empty($text_style) ? $text_style : '#000000';
        ?>
;">	
			<span id="welcome-span" style="height: 6.8em;">
			<?php 
        echo !empty($ir_wb_cta_desktop) ? $ir_wb_cta_desktop : __('Join Our Mailing List', 'inboundrocket');
        ?>
<a class="mclose-notify" onclick="mwelcome_bar_hide();" style="background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
;">X</a>
			<?php 
        if (!inboundrocket_check_premium_user()) {
            echo '<a href="http://inboundrocket.co/?utm_source=' . $_SERVER['HTTP_HOST'] . '&utm_medium=welcome-bar-mobile&utm_campaign=logo" title="' . __('Powered by Inbound Rocket - You write. We\'ll turn them into leads', 'inboundrocket') . '" target="_blank" class="inboundrocket-wb-mbranding" style="background-color:';
            echo !empty($bar_style) ? $bar_style : '#eee';
            echo '" ><img src="' . INBOUNDROCKET_WELCOME_BAR_PATH . '/img/welcome-bar-logo.png" alt="" /></a>';
        }
        ?>
 
			<form id="mwelcome_bar-form" method="post" action=""><?php 
        wp_nonce_field('welcome_bar_form_lead_submitted', 'welcome_bar_form_nonce');
        ?>
				<input type="hidden" name="origin" id="origin" value="mobile">
				<input type="hidden" name="current_page" id="current_page" value="<?php 
        echo $this->inboundrocket_wb_getURL();
        ?>
">
				<?php 
        wp_referer_field(true);
        ?>
				<!-- <div class="minput"><input type="text" name="name" id="name" placeholder="Firstname and Lastname"></div> -->
                <div class="minput"><input type="email" name="emailaddress" id="emailaddress" placeholder="<?php 
        echo !empty($ir_wb_email_placeholder) ? $ir_wb_email_placeholder : __('Email Address', 'inboundrocket');
        ?>
"></div>
                <div class="minput"><button type="submit" class="mwelcome_bar-link"><?php 
        echo !empty($ir_wb_button_text) ? $ir_wb_button_text : __('Submit', 'inboundrocket');
        ?>
</button></div>
            </form></span>
		</div>
		<div class="mwelcome_bar-stub" style="display: none;"><a class="mshow-notify" onclick="mwelcome_bar_show();" style="background-color: <?php 
        echo !empty($bar_style) ? $bar_style : '#eee';
        ?>
;"><img src="<?php 
        echo INBOUNDROCKET_WELCOME_BAR_PATH;
        ?>
/img/welcome-bar-down-arrow.png" /></a></div>
	</div>
	<!-- END MOBILE welcome_bar -->
		<?php 
    }
 /**
  * Adds Inbound Rocket menu to /wp-admin sidebar
  */
 function inboundrocket_add_menu_items()
 {
     $options = get_option('inboundrocket_options');
     global $submenu;
     global $wp_version;
     $capability = 'activate_plugins';
     if (!current_user_can('activate_plugins')) {
         if (!array_key_exists('ir_grant_access_to_' . inboundrocket_get_user_role(), $options)) {
             return FALSE;
         } else {
             if (current_user_can('manage_network')) {
                 // super admin
                 $capability = 'manage_network';
             } else {
                 if (current_user_can('edit_pages')) {
                     // editor
                     $capability = 'edit_pages';
                 } else {
                     if (current_user_can('publish_posts')) {
                         // author
                         $capability = 'publish_posts';
                     } else {
                         if (current_user_can('edit_posts')) {
                             // contributor
                             $capability = 'edit_posts';
                         } else {
                             if (current_user_can('read')) {
                                 // subscriber
                                 $capability = 'read';
                             }
                         }
                     }
                 }
             }
         }
     }
     self::check_admin_action();
     if (ini_get('allow_url_fopen')) {
         $inboundrocket_icon = $wp_version < 3.8 && !is_plugin_active('mp6/mp6.php') ? INBOUNDROCKET_PATH . '/img/inboundrocket-icon-32x32.png' : 'data:image/svg+xml;base64,' . base64_encode(@file_get_contents(INBOUNDROCKET_PATH . '/img/inboundrocket-svg-icon.svg'));
     } else {
         $inboundrocket_icon = INBOUNDROCKET_PATH . '/img/inboundrocket-icon-32x32.png';
     }
     add_menu_page('Inbound Rocket', 'Inbound Rocket', $capability, 'inboundrocket_stats', array($this, 'inboundrocket_build_stats_page'), $inboundrocket_icon, '25.10167');
     foreach ($this->admin_power_ups as $power_up) {
         if ($power_up->activated) {
             $power_up->admin_init();
             // Creates the menu icon for power-up if it's set. Overrides the main Inbound Rocket menu to hit the contacts power-up
             if ($power_up->menu_text) {
                 add_submenu_page('inboundrocket_stats', $power_up->menu_text, $power_up->menu_text, $capability, 'inboundrocket_' . $power_up->menu_link, array($power_up, 'power_up_setup_callback'));
             }
         }
     }
     add_submenu_page('inboundrocket_stats', __('Lead Lists', 'inboundrocket'), __('Lead Lists', 'inboundrocket'), $capability, 'inboundrocket_lead_lists', array(&$this, 'inboundrocket_build_lead_list_page'));
     add_submenu_page('inboundrocket_stats', __('Settings', 'inboundrocket'), __('Settings', 'inboundrocket'), 'activate_plugins', 'inboundrocket_settings', array(&$this, 'inboundrocket_plugin_options'));
     add_submenu_page('inboundrocket_stats', __('Power-ups', 'inboundrocket'), __('Power-ups', 'inboundrocket'), 'activate_plugins', 'inboundrocket_power_ups', array(&$this, 'inboundrocket_power_ups_page'));
     if (!inboundrocket_check_premium_user()) {
         add_submenu_page('inboundrocket_stats', __('Upgrade to Premium', 'inboundrocket'), __('Upgrade to Premium', 'inboundrocket'), 'activate_plugins', 'inboundrocket_premium_upgrade', array(&$this, 'inboundrocket_premium_upgrade_page'));
     }
     $submenu['inboundrocket_stats'][0][0] = 'Stats';
 }
 /**
  * Replacement of Tweet tags with the correct HTML
  */
 public function tweet($text)
 {
     $this->ctt_options = get_option('inboundrocket_ctt_options');
     $handle = $this->ctt_options['ir_ctt_twitter_username'];
     if (!empty($handle)) {
         $handle_code = "&via=" . $handle . "&related=" . $handle;
     } else {
         $handle_code = '';
     }
     $short = $this->shorten(esc_attr($text), 100);
     $str = "<div class=\"ir-tweet-clear\"></div><div class=\"ir-click-to-tweet\"><div class=\"ir-ctt-text\"><a href=\"https://twitter.com/share?text=" . urlencode($short) . $handle_code . "&url=" . get_permalink() . "\" data-text=\"" . $short . "\" class=\"ctt-action\" target=\"_blank\">" . $short . "</a></div>";
     if (!inboundrocket_check_premium_user()) {
         $str .= "<a href=\"http://inboundrocket.co/?utm_source=" . $_SERVER['HTTP_HOST'] . "&utm_medium=click-to-tweet&utm_campaign=logo\" title=\"" . __('Powered by Inbound Rocket - You write. We will turn them into leads', 'inboundrocket') . "\" target=\"_blank\" class=\"inboundrocket-ctt-branding\">&nbsp;</a>";
     }
     $str .= "<a href=\"https://twitter.com/share?text=" . urlencode($short) . $handle_code . "&url=" . get_permalink() . "\" data-text=\"" . $short . "\" class=\"ir-ctt-btn ctt-action\" target=\"_blank\">" . __('Click To Tweet', 'inboundrocket') . "</a><div class=\"ir-ctt-tip\"></div></div>";
     return $str;
 }