public function do_render()
 {
     $url = admin_url('admin.php?page=nelioab-add-experiment&experiment-type=');
     // LANDING PAGE
     $page_on_front = get_option('page_on_front');
     if ($page_on_front != 0) {
         $this->print_beautiful_box('landing-page', __('A/B Test Your Landing Page', 'nelioab'), array(&$this, 'print_new_exp_box', array('landing-page', $url . NelioABExperiment::PAGE_ALT_EXP . '&lp', __('<strong>Pure A/B Testing from the very beginning!</strong> Create one or more alternatives of your landing page and see which one converts better! If your website starts at your Landing Page, why shouldn\'t you start it first?', 'nelioab'))));
     }
     // PAGE
     $this->print_beautiful_box('page', __('New A/B Test for Pages', 'nelioab'), array(&$this, 'print_new_exp_box', array('page', $url . NelioABExperiment::PAGE_ALT_EXP, __('<strong>Pure A/B Testing!</strong> Create one or more alternatives of a page and <strong>change whatever you want</strong>: the colors, the text, the layout... and do it using your default WordPress editor! Then define the goals and you\'re ready!', 'nelioab'))));
     // POST
     $this->print_beautiful_box('post', __('New A/B Test for Posts', 'nelioab'), array(&$this, 'print_new_exp_box', array('post', $url . NelioABExperiment::POST_ALT_EXP, __('<strong>Pure A/B Testing!</strong> Create one or more alternatives of a post and <strong>change whatever you want</strong>: the colors, the text, the layout... and do it using your default WordPress editor! Then define the goals and you\'re ready!', 'nelioab'))));
     // WOOCOMMERCE PRODUCT SUMMARY
     if (NelioABWooCommerceSupport::is_plugin_active()) {
         $this->print_beautiful_box('wc-product-summary', __('WooCommerce Product Summary', 'nelioab'), array(&$this, 'print_new_exp_box', array('wc-product-summary', $url . NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP, __('<strong>Change the name, short description, and featured image of your product, and discover which combination leads to more sales</strong>. Every time the product appears in your website, it is counted as a visit. Once a purchase containing that product is completed, you have a new conversion. Easy, right?', 'nelioab'))));
     }
     // HEADLINE ONLY
     $this->print_beautiful_box('title', __('New A/B Test for Headlines', 'nelioab'), array(&$this, 'print_new_exp_box', array('title', $url . NelioABExperiment::HEADLINE_ALT_EXP, __('Headline Testing is perfect for Publishers. <strong>Try with different Titles, Featured Images, and Excerpts, and check which combination is more appealing</strong>. Every time the Headline is printed somewhere in your site, it is counted as a visit. If a visitor accesses the post, you have a conversion!', 'nelioab'))));
     // THEMES (enabled starting at version 3.4)
     if (NelioABWpHelper::is_at_least_version(3.4)) {
         $this->print_beautiful_box('theme', __('New A/B Theme Test ', 'nelioab'), array(&$this, 'print_new_exp_box', array('theme', $url . NelioABExperiment::THEME_ALT_EXP, __('Would you like to <strong>change your WordPress completely</strong>? Do you want to <strong>test small variations of two child themes</strong>? Then this gives you what you need! Just keep in mind to configure each theme individually before using this kind of experiment.', 'nelioab'))));
     }
     // HEATMAPS
     $this->print_beautiful_box('heatmap', __('New Heatmap Experiment for Pages or (Custom) Posts', 'nelioab'), array(&$this, 'print_new_exp_box', array('heatmap', $url . NelioABExperiment::HEATMAP_EXP, __('If you don\'t know how to get started with A/B Testing, run a Heatmap Experiment and <strong>discover how your users behave when navigating through your website</strong>! This is one of the easiest ways to get ideas on what to do next.', 'nelioab'))));
     // CSS
     $this->print_beautiful_box('css', __('New A/B CSS Test', 'nelioab'), array(&$this, 'print_new_exp_box', array('css', $url . NelioABExperiment::CSS_ALT_EXP, __('Do you want to <strong>change the appearence of your WordPress site, but tweaking only small elements here and there</strong>? Then CSS Tests is what you\'re looking for. Create one or more CSS fragments that will be applied to your website and discover which one offers the better results.', 'nelioab'))));
     // CUSTOM POST TYPES
     $this->print_beautiful_box('cpt', __('New Custom Post Type Test', 'nelioab'), array(&$this, 'print_new_exp_box', array('cpt', $url . NelioABExperiment::CPT_ALT_EXP, __('<strong>Pure A/B Testing!</strong> Create one or more alternatives of a custom post type and <strong>change whatever you want</strong>: the title, the text, the custom fields... and do it using your default WordPress editor! Then define the goals and you\'re ready!', 'nelioab'))));
     // WIDGET
     $this->print_beautiful_box('widget', __('New Widget Test', 'nelioab'), array(&$this, 'print_new_exp_box', array('widget', $url . NelioABExperiment::WIDGET_ALT_EXP, __('Do you want to <strong>arrange widgets in a different order, use different widget setups, or even introduce completely new widgets?</strong> Then Widget Tests is what you need. Select and arrange the widgets you need as a new alternative and discover which one offers the better results.', 'nelioab'))));
     // MENU
     $this->print_beautiful_box('menu', __('New Menu Test', 'nelioab'), array(&$this, 'print_new_exp_box', array('menu', $url . NelioABExperiment::MENU_ALT_EXP, __('Menus are one of the most important elements in your WordPress site, for they get a lot of attention from your visitors. <strong>Modify the labels of your menu items, rearrange them, or use a completely different menu</strong> and test which one helps you get more conversions!', 'nelioab'))));
 }
Пример #2
0
 /**
  * Creates a new instance of this class.
  *
  * @return NelioABFreeTrialPage the new instance of this class.
  *
  * @since 4.1.3
  */
 public function __construct()
 {
     $colorscheme = NelioABWpHelper::get_current_colorscheme();
     $title = __('Nelio A/B Testing &mdash; Free Trial', 'nelioab');
     $title .= sprintf(' <span class="nelio-ftcode" style="color:%1$s;border-color:%1$s;">%2$s%3$s</span>', $colorscheme['primary'], __('Code:', 'nelioab'), NelioABAccountSettings::get_nelioab_option('free_trial_code'));
     parent::__construct($title);
 }
 public function __construct($title)
 {
     parent::__construct($title);
     $this->set_icon('icon-nelioab');
     $this->exp = null;
     $this->goal = null;
     $this->results = null;
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     $this->colorscheme = NelioABWpHelper::get_current_colorscheme();
 }
 public function __construct($title, $alt_type = NelioABExperiment::CPT_ALT_EXP)
 {
     parent::__construct($title);
     $this->set_icon('icon-nelioab');
     $this->set_form_name('nelioab_edit_ab_cpt_exp_form');
     $this->alt_type = $alt_type;
     $this->original_id = -1;
     $this->post_type_name = false;
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     $this->post_types = NelioABWpHelper::get_custom_post_types();
     // Prepare tabs
     $this->add_tab('info', __('General', 'nelioab'), array($this, 'print_basic_info'));
     $this->add_tab('alts', __('Alternatives', 'nelioab'), array($this, 'print_alternatives'));
     $this->add_tab('goals', __('Goals', 'nelioab'), array($this, 'print_goals'));
 }
        protected function print_the_real_alternatives()
        {
            // REAL ALTERNATIVES
            // -----------------------------------------
            $exp = $this->exp;
            if ($this->results == null) {
                $alt_results = null;
                $ori_conversions = 0;
            } else {
                $alt_results = $this->results->get_alternative_results();
                $ori_conversions = $alt_results[0]->get_num_of_conversions();
                // in this function, the original alternative is NOT used
                $alt_results = array_slice($alt_results, 1);
            }
            $conversions_label = __('Conversions', 'nelioab');
            $pageviews_label = __('Pageviews', 'nelioab');
            $conversion_views_label = __('Conversions / Views', 'nelioab');
            $conversion_rate_label = __('Conversion Rate', 'nelioab');
            $alternative_label = __('Alternative', 'nelioab');
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            $color = $colorscheme['primary'];
            $base_color = $color;
            $i = 0;
            foreach ($exp->get_alternatives() as $alt) {
                $i++;
                $name = $this->trunk($alt->get_name());
                $icon = $this->get_experiment_icon($exp);
                $id = $alt->get_id();
                $graphic_id = 'graphic-' . $id;
                if ($alt_results != null) {
                    $alt_result = $alt_results[$i - 1];
                    $pageviews = $alt_result->get_num_of_visitors();
                    $conversions = $alt_result->get_num_of_conversions();
                    $conversion_rate = $alt_result->get_conversion_rate();
                    $improvement_factor = $alt_result->get_improvement_factor();
                } else {
                    $pageviews = 0;
                    $conversions = 0;
                    $conversion_rate = 0.0;
                    $improvement_factor = 0.0;
                }
                $alt_conversion_views = $conversions . ' / ' . $pageviews;
                $aux = $ori_conversions * $this->goal->get_benefit() * $improvement_factor / 100;
                $print_improvement = true;
                // format improvement factor
                if ($improvement_factor < 0) {
                    $arrow = 'fa-arrow-down';
                    $stats_color = 'red';
                    $improvement_factor = $improvement_factor * -1;
                } else {
                    if ($improvement_factor > 0) {
                        $arrow = 'fa-arrow-up';
                        $stats_color = 'green';
                    } else {
                        // $improvement_factor = 0.0
                        $arrow = 'fa-none';
                        $stats_color = 'black';
                        $print_improvement = false;
                    }
                }
                if ($aux > 0) {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux, 2));
                } else {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux * -1, 2));
                }
                $alt_conversion_rate = number_format_i18n(floatval($conversion_rate), 2) . ' %';
                $alt_improvement_factor = number_format_i18n(floatval($improvement_factor), 2) . ' %';
                $alternative_number = $i;
                $winner = false;
                $winner_color = '';
                if ($this->is_winner($alt->get_id())) {
                    $icon = $this->get_winner_icon($exp);
                    $color = $colorscheme['winner'];
                    $winner_color = 'style="background-color:' . $colorscheme['primary'] . ';color:' . $colorscheme['foreground'] . ';"';
                    $winner = true;
                } else {
                    $color = $base_color;
                }
                $action_links = $this->get_action_links($exp, $alt->get_id(), $winner);
                $buttons = implode(' ', $action_links);
                if (!$print_improvement) {
                    $gain = '';
                    $alt_improvement_factor = '';
                }
                $result = <<<HTML
\t\t\t\t<div class="nelio-alternative alternative-{$i} postbox nelio-card">
\t\t\t\t\t<div class="alt-info-header" {$winner_color}>
\t\t\t\t\t\t{$icon}
\t\t\t\t\t\t<span class="alt-title">{$name}</span>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-body">
\t\t\t\t\t\t<div class="alt-screen no-hover" id="{$id}" style="color:{$color};">
\t\t\t\t\t\t\t\t<div class="alt-name">
\t\t\t\t\t\t\t\t\t{$alternative_label}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-number">
\t\t\t\t\t\t\t\t\t{$alternative_number}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t\t<div class="alt-stats">
\t\t\t\t\t\t\t<div class="alt-stats-graphic" id="{$graphic_id}"></div>
\t\t\t\t\t\t\t<div class="alt-status">
\t\t\t\t\t\t\t\t<div class="alt-cv">
\t\t\t\t\t\t\t\t\t<span class="alt-cv-title">{$conversion_views_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cv">{$alt_conversion_views}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-cr">
\t\t\t\t\t\t\t\t\t<span class="alt-cr-title">{$conversion_rate_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cr">{$alt_conversion_rate}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-stats" style="color:{$stats_color};">
\t\t\t\t\t\t\t\t\t<span class="alt-if"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$alt_improvement_factor}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-ii"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$gain}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-footer">
\t\t\t\t\t\t<div class="alt-info-footer-content">
\t\t\t\t\t\t\t{$buttons}
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t<script>
\t\t\t\tjQuery(document).ready(function() {
\t\t\t\t\tdrawAlternativeGraphic('{$graphic_id}',
\t\t\t\t\t\t{$conversions},
\t\t\t\t\t\t'{$conversions_label}',
\t\t\t\t\t\t'{$color}',
\t\t\t\t\t\t{$pageviews},
\t\t\t\t\t\t'{$pageviews_label}');
\t\t\t\t});
\t\t\t\t</script>
HTML;
                echo $result;
            }
        }
 /**
  * PHPDOC
  *
  * @param string        $name        PHPDOC
  * @param int           $src_post_id PHPDOC
  * @param boolean|array $ori_post    PHPDOC
  *
  * @return boolean|int PHPDOC
  *
  * @since PHPDOC
  */
 public function create_alternative_copying_content($name, $src_post_id, $ori_post = false)
 {
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     // Retrieve original post
     $src_post = get_post($src_post_id, ARRAY_A);
     if (!$src_post) {
         return false;
     }
     if ($ori_post && $src_post['post_type'] != $ori_post['post_type']) {
         switch ($ori_post['post_type']) {
             case 'page':
                 $aux = NelioABExperiment::PAGE_ALT_EXP;
                 break;
             case 'post':
                 $aux = NelioABExperiment::POST_ALT_EXP;
                 break;
             default:
                 $aux = NelioABExperiment::CPT_ALT_EXP;
         }
         return $this->create_empty_alternative($name, $aux, $ori_post['post_type']);
     }
     // Create new empty post
     $post_data = array('post_author' => $src_post['post_author'], 'post_type' => $src_post['post_type'], 'post_title' => $src_post['post_title'], 'post_content' => $src_post['post_content'], 'post_excerpt' => $src_post['post_excerpt'], 'post_status' => 'draft', 'post_name' => 'nelioab_' . rand(1, 10));
     $new_post_id = wp_insert_post($post_data, true);
     if (is_wp_error($new_post_id)) {
         return false;
     }
     $new_post = get_post($new_post_id, ARRAY_A);
     // Update the post_name
     $new_post['post_name'] = 'nelioab_' . $new_post_id;
     wp_update_post($new_post);
     // Prepare custom metadata
     add_post_meta($new_post_id, '_is_nelioab_alternative', 'true');
     // Override all information
     NelioABWpHelper::overwrite($new_post_id, $src_post_id);
     // Custom Permalinks compatibility
     require_once NELIOAB_UTILS_DIR . '/custom-permalinks-support.php';
     if (NelioABCustomPermalinksSupport::is_plugin_active()) {
         NelioABCustomPermalinksSupport::remove_custom_permalink($new_post_id);
     }
     return $new_post_id;
 }
        /**
         * This function adds just one script in the nav-menus.php page. The script
         * checks if the user is currently editing a menu exp alternative and, if
         * it is, it'll hide all menus except the alternative's.
         */
        public function add_code_to_hide_menus_when_editing_menu_exp()
        {
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
			<div id="nelioab-edit-alt-menus" class="widgets-holder-wrap" style="margin-bottom:1em;display:none;border: 1px solid #e5e5e5;-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);box-shadow: 0 1px 1px rgba(0,0,0,.04);">
				<div class="widgets-sortables ui-sortable">
					<div class="sidebar-name" style="padding:0.2em 1em;background-color:<?php 
            echo $colorscheme['focus'];
            ?>
;">
						<div class="sidebar-name-arrow"><br></div>
						<h3 style="color:<?php 
            echo $colorscheme['foreground'];
            ?>
;"><?php 
            _e('Alternative Menu', 'nelioab');
            ?>
</h3>
					</div>
				</div>

				<div class="content" style="padding:0em 1em 1em 1em;">
					<p><strong><?php 
            _e('Go back to...', 'nelioab');
            ?>
</strong></p>
					<ul style="margin-left:1.5em;">
						<?php 
            if (isset($_GET['back_to_edit'])) {
                $url = admin_url('admin.php?page=nelioab-experiments&action=edit&id=' . $_GET['nelioab_exp'] . '&ctab=tab-alts&exp_type=' . NelioABExperiment::MENU_ALT_EXP);
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('Editing this experiment', 'nelioab');
                ?>
</a></li>
						<?php 
            } else {
                $url = admin_url('admin.php?page=nelioab-experiments&action=progress&id=' . $_GET['nelioab_exp'] . '&exp_type=' . NelioABExperiment::MENU_ALT_EXP);
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('The results of the related experiment', 'nelioab');
                ?>
</a></li>
						<?php 
            }
            ?>
						<?php 
            $url = admin_url('admin.php?page=nelioab-experiments');
            ?>
						<li><a href="<?php 
            echo $url;
            ?>
"><?php 
            _e('My list of experiments', 'nelioab');
            ?>
</a></li>
					</ul>
				</div>

			</div>

			<script type="text/javascript">
			(function($) {
				// Hide Top Area
				$('.nav-tab-wrapper').hide();
				$('.manage-menus').hide();
				$('#nav-menus-frame').css('padding-top', '30px');
				// Hide Menu Box
				$('.menu-name-label').hide();
				$('.menu-settings').hide();
				$('.delete-action').hide();
				// Add Alternative Box
				$content = $('#nelioab-edit-alt-menus .content');
				$('#nelioab-edit-alt-menus .sidebar-name').on('click', function() {
					$content.toggle();
				});
				var $aux = $('#nelioab-edit-alt-menus').detach();
				$('#nav-menu-meta').prepend($aux);
				$aux.show();
				var $msg = $('#message');
				$msg.html($msg.html().replace(/Menu[0-9.\s]+(\s)?/, '<?php 
            echo esc_html(__('Alternative Menu', 'nelioab'));
            ?>
\1'));
			})(jQuery);
			</script>
			<?php 
        }
        protected function print_the_real_alternatives()
        {
            // REAL ALTERNATIVES
            // -----------------------------------------
            $exp = $this->exp;
            $the_themes = wp_get_themes();
            if ($this->results == null) {
                $alt_results = null;
                $ori_conversions = 0;
            } else {
                $alt_results = $this->results->get_alternative_results();
                $ori_conversions = $alt_results[0]->get_num_of_conversions();
                // in this function, the original alternative is NOT used
                $alt_results = array_slice($alt_results, 1);
            }
            $conversions_label = __('Conversions', 'nelioab');
            $pageviews_label = __('Pageviews', 'nelioab');
            $conversion_views_label = __('Conversions / Views', 'nelioab');
            $conversion_rate_label = __('Conversion Rate', 'nelioab');
            $alternative_label = __('Alternative', 'nelioab');
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            $color = $colorscheme['primary'];
            $base_color = $color;
            $i = 0;
            foreach ($exp->get_alternatives() as $alt) {
                $i++;
                $action_links = array();
                $name = $this->trunk($alt->get_name());
                $icon = $this->get_experiment_icon($exp);
                $id = $alt->get_id();
                $graphic_id = 'graphic-' . $id;
                if ($alt_results != null) {
                    $alt_result = $alt_results[$i - 1];
                    $pageviews = $alt_result->get_num_of_visitors();
                    $conversions = $alt_result->get_num_of_conversions();
                    $conversion_rate = $alt_result->get_conversion_rate();
                    $improvement_factor = $alt_result->get_improvement_factor();
                } else {
                    $pageviews = 0;
                    $conversions = 0;
                    $conversion_rate = 0.0;
                    $improvement_factor = 0.0;
                }
                $alt_conversion_views = $conversions . ' / ' . $pageviews;
                $aux = $ori_conversions * $this->goal->get_benefit() * $improvement_factor / 100;
                $print_improvement = true;
                // format improvement factor
                if ($improvement_factor < 0) {
                    $arrow = 'fa-arrow-down';
                    $stats_color = 'red';
                    $improvement_factor = $improvement_factor * -1;
                } else {
                    if ($improvement_factor > 0) {
                        $arrow = 'fa-arrow-up';
                        $stats_color = 'green';
                    } else {
                        // $improvement_factor = 0.0
                        $arrow = 'fa-none';
                        $stats_color = 'black';
                        $print_improvement = false;
                    }
                }
                if ($aux > 0) {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux, 2));
                } else {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux * -1, 2));
                }
                $alt_conversion_rate = number_format_i18n(floatval($conversion_rate), 2) . ' %';
                $alt_improvement_factor = number_format_i18n(floatval($improvement_factor), 2) . ' %';
                $alternative_number = $i;
                $winner_color = '';
                if ($this->is_winner($alt->get_id())) {
                    $icon = $this->get_winner_icon($exp);
                    $color = $colorscheme['winner'];
                    $winner_color = 'style="background-color:' . $colorscheme['primary'] . ';color:' . $colorscheme['foreground'] . ';"';
                } else {
                    $color = $base_color;
                }
                $theme = null;
                $theme_image = '#';
                foreach ($the_themes as $t) {
                    if ($t['Stylesheet'] == $alt->get_value()) {
                        $theme = $t;
                        $theme_image = $t->get_screenshot();
                        break;
                    }
                }
                if ($theme != NULL && $exp->get_status() == NelioABExperiment::STATUS_FINISHED) {
                    $img = '<span id="loading-' . $alt->get_value() . '" class="dashicons dashicons-update fa-spin animated nelio-apply"></span>';
                    $aux = sprintf(' <a class="apply-link button" href="javascript:nelioab_confirm_overwriting(\'%1$s\', \'%2$s\', \'%3$s\');">%4$s %5$s</a>', $alt->get_value(), $theme['Stylesheet'], $theme['Template'], $img, __('Apply', 'nelioab'));
                    array_push($action_links, $aux);
                }
                $buttons = implode(' ', $action_links);
                if (!$print_improvement) {
                    $gain = '';
                    $alt_improvement_factor = '';
                }
                $result = <<<HTML
\t\t\t\t<div class="nelio-alternative alternative-{$i} postbox nelio-card">
\t\t\t\t\t<div class="alt-info-header" {$winner_color}>
\t\t\t\t\t\t{$icon}
\t\t\t\t\t\t<span class="alt-title">{$name}</span>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-body">
\t\t\t\t\t\t<div class="alt-screen hover-img-fade" id="{$id}" style="color:{$color};">
\t\t\t\t\t\t\t<img class="alt-theme-img" src="{$theme_image}" width="320" height="240">
\t\t\t\t\t\t\t\t<div class="alt-name">
\t\t\t\t\t\t\t\t\t{$alternative_label}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-number">
\t\t\t\t\t\t\t\t\t{$alternative_number}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t\t<div class="alt-stats">
\t\t\t\t\t\t\t<div class="alt-stats-graphic" id="{$graphic_id}"></div>
\t\t\t\t\t\t\t<div class="alt-status">
\t\t\t\t\t\t\t\t<div class="alt-cv">
\t\t\t\t\t\t\t\t\t<span class="alt-cv-title">{$conversion_views_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cv">{$alt_conversion_views}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-cr">
\t\t\t\t\t\t\t\t\t<span class="alt-cr-title">{$conversion_rate_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cr">{$alt_conversion_rate}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-stats" style="color:{$stats_color};">
\t\t\t\t\t\t\t\t\t<span class="alt-if"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$alt_improvement_factor}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-ii"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$gain}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-footer">
\t\t\t\t\t\t<div class="alt-info-footer-content">
\t\t\t\t\t\t\t{$buttons}
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t<script>
\t\t\t\tjQuery(document).ready(function() {
\t\t\t\t\tdrawAlternativeGraphic('{$graphic_id}',
\t\t\t\t\t\t{$conversions},
\t\t\t\t\t\t'{$conversions_label}',
\t\t\t\t\t\t'{$color}',
\t\t\t\t\t\t{$pageviews},
\t\t\t\t\t\t'{$pageviews_label}');
\t\t\t\t});
\t\t\t\t</script>
HTML;
                echo $result;
            }
        }
 protected function do_build()
 {
     // Check settings
     require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
     $error = NelioABErrorController::build_error_page_on_invalid_settings();
     if ($error) {
         return;
     }
     // Preparing labels for CUSTOM POST alternatives
     // ----------------------------------------------
     $alt_type = NelioABExperiment::CPT_ALT_EXP;
     $title = __('Edit Custom Post Type Experiment', 'nelioab');
     // We recover the experiment (if any)
     // ----------------------------------------------
     global $nelioab_admin_controller;
     $experiment = NULL;
     $other_names = array();
     if (!empty($nelioab_admin_controller->data)) {
         $experiment = $nelioab_admin_controller->data;
         $alt_type = $experiment->get_type();
     } else {
         $experiment = new NelioABPostAlternativeExperiment(-time());
         $experiment->clear();
     }
     // ...and we also recover other experiment names (if any)
     if (isset($_POST['other_names'])) {
         $other_names = json_decode(urldecode($_POST['other_names']));
     } else {
         foreach (NelioABExperimentsManager::get_experiments() as $aux) {
             if ($aux->get_id() != $experiment->get_id()) {
                 array_push($other_names, $aux->get_name());
             }
         }
     }
     // Get id of Original custom post type
     // ----------------------------------------------
     if (isset($_GET['post-id']) && $_GET['experiment-type'] == NelioABExperiment::CPT_ALT_EXP) {
         $experiment->set_original($_GET['post-id']);
     }
     // Checking whether there are custom post types available
     // ---------------------------------------------------
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     $post_types = NelioABWpHelper::get_custom_post_types();
     if ($alt_type == NelioABExperiment::CPT_ALT_EXP && count($post_types) == 0) {
         require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php';
         $view = new NelioABMessagePage(__('There are no custom post types available.', 'nelioab'), __('You have to create a public custom post type and publish some custom posts first to use this type of experiment.', 'nelioab'));
         return $view;
     }
     $found = false;
     foreach ($post_types as $post_type) {
         $options_for_posts = array('posts_per_page' => 1, 'post_type' => $post_type->name, 'post_status' => 'publish');
         $list_of_posts = get_posts($options_for_posts);
         require_once NELIOAB_UTILS_DIR . '/data-manager.php';
         NelioABArrays::sort_posts($list_of_posts);
         if (count($list_of_posts) > 0) {
             $found = true;
             break;
         }
     }
     if ($alt_type == NelioABExperiment::CPT_ALT_EXP && !$found) {
         require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php';
         $view = new NelioABMessagePage(__('There are no custom posts available.', 'nelioab'), __('Please, create one custom post and try again.', 'nelioab'));
         return $view;
     }
     // If everything is OK, we keep going!
     // ---------------------------------------------------
     // Creating the view
     $view = $this->create_view($alt_type);
     foreach ($other_names as $name) {
         $view->add_another_experiment_name($name);
     }
     // Experiment information
     $view->set_basic_info($experiment->get_id(), $experiment->get_name(), $experiment->get_description(), $experiment->get_finalization_mode(), $experiment->get_finalization_value());
     // Experiment specific variables and alternatives
     $view->set_custom_post_type($experiment->get_post_type());
     $view->set_original_id($experiment->get_originals_id());
     $view->set_alternatives($experiment->get_json4js_alternatives());
     // Goals
     $goals = $experiment->get_goals();
     foreach ($goals as $goal) {
         $view->add_goal($goal->json4js());
     }
     return $view;
 }
Пример #10
0
 /**
  * This function is an AJAX callback that looks for posts.
  *
  * It returns a list of up to 20 posts (or pages). It is used by the
  * select2 widget (an item selector that looks more beautiful than regular
  * the "select>option" combo.
  *
  * Accepted POST params are:
  *
  * * term: {string} the (part of the) string used to look for items.
  * * type: {array}  array containing the types of element are we looking.
  * * default_id: {int} (optional) if set, the item with that ID will be
  * returned. If that item is not found, then we'll perform a regular search
  * (as if the param had not been set).
  *
  * @return array a list of matching posts.
  *
  * @since PHPDOC
  */
 public static function search_posts()
 {
     $term = false;
     if (isset($_POST['term']) & !empty($_POST['term'])) {
         $term = $_POST['term'];
     }
     $types = array();
     if (isset($_POST['type'])) {
         $types = $_POST['type'];
     }
     if (!is_array($types)) {
         $types = array($types);
     }
     $status = 'publish';
     if (isset($_POST['drafts']) && 'show-drafts' == $_POST['drafts']) {
         $status = array('publish', 'draft');
     }
     $default_id = false;
     if (isset($_POST['default_id'])) {
         $default_id = $_POST['default_id'];
     }
     if ($default_id == -1) {
         $default_id = false;
     }
     $default_thumbnail = sprintf('<img src="data:image/gif;%s" class="%s" alt="%s" />', 'base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'attachment-thumbnail wp-post-image nelioab-no-thumbnail', __('No featured image available', 'nelioab'));
     $args = array('post_title_like' => $term, 'posts_per_page' => 20, 'meta_key' => '_is_nelioab_alternative', 'meta_compare' => 'NOT EXISTS', 'post_status' => $status);
     if (count($types) > 0) {
         $aux = array();
         foreach ($types as $type) {
             if (strpos($type, 'nelioab-') === false) {
                 array_push($aux, $type);
             }
         }
         foreach ($types as $type) {
             if ('nelioab-all-post-types' == $type) {
                 array_push($aux, 'page');
                 array_push($aux, 'post');
                 foreach (NelioABWpHelper::get_custom_post_types() as $cpt) {
                     array_push($aux, $cpt->name);
                 }
             }
         }
         if (count($aux) > 0) {
             $args['post_type'] = $aux;
         }
     }
     if ($types && count($types) == 1 && 'page' === $types[0] && !$term) {
         $args['order'] = 'asc';
         $args['orderby'] = 'title';
     }
     $latest_post_item = false;
     if (in_array('nelioab-latest-posts', $types) || false !== $default_id) {
         $lp_title = __('Your latest posts', 'nelioab');
         if (!$term || strpos(strtolower($lp_title), strtolower($term)) !== false) {
             $latest_post_item = array('id' => NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS, 'type' => '<i>latest-posts</i>', 'title' => self::fix_title($lp_title), 'status' => '<i>dynamic</i>', 'date' => '', 'author' => 'WordPress', 'thumbnail' => $default_thumbnail);
         }
     }
     $theme_based_landing_page = false;
     if (in_array('nelioab-theme-landing-page', $types) && NelioABSettings::does_theme_use_a_custom_landing_page() || NelioABController::FRONT_PAGE__THEME_BASED_LANDING == $default_id) {
         $lp_title = __('Landing Page (Theme-based)', 'nelioab');
         if (!$term || strpos(strtolower($lp_title), strtolower($term)) !== false) {
             $theme_based_landing_page = array('id' => NelioABController::FRONT_PAGE__THEME_BASED_LANDING, 'type' => '<i>landing-page</i>', 'title' => self::fix_title($lp_title), 'status' => '<i>dynamic</i>', 'date' => '', 'author' => 'WordPress', 'thumbnail' => $default_thumbnail);
         }
     }
     // If there's a default_id set, it means that the user is interested
     // in one post only; I'm going to return that post to him
     if ($default_id !== false) {
         $id = $default_id;
         $post = false;
         if ($id == NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS) {
             header('Content-Type: application/json');
             echo json_encode(array($latest_post_item));
             die;
         }
         if ($id == NelioABController::FRONT_PAGE__THEME_BASED_LANDING) {
             header('Content-Type: application/json');
             echo json_encode(array($theme_based_landing_page));
             die;
         }
         if ($id > 0) {
             $post = get_post($id);
         }
         if ($post) {
             $thumbnail = get_the_post_thumbnail($post->ID, 'thumbnail');
             if ($thumbnail === '') {
                 $thumbnail = $default_thumbnail;
             }
             $item = array('id' => $post->ID, 'title' => self::fix_title($post->post_title), 'thumbnail' => $thumbnail, 'excerpt' => $post->post_excerpt);
             header('Content-Type: application/json');
             echo json_encode(array($item));
             die;
         }
     }
     $result = array();
     add_filter('posts_where', array('NelioABWpHelper', 'add_title_filter_to_wpquery'), 10, 2);
     $my_query = new WP_Query($args);
     remove_filter('posts_where', array('NelioABWpHelper', 'add_title_filter_to_wpquery'), 10, 2);
     if ($my_query->have_posts()) {
         global $post;
         while ($my_query->have_posts()) {
             $my_query->the_post();
             $thumbnail = get_the_post_thumbnail($post->ID, 'thumbnail');
             if ($thumbnail === '') {
                 $thumbnail = $default_thumbnail;
             }
             $item = array('id' => $post->ID, 'type' => $post->post_type, 'title' => self::fix_title($post->post_title), 'status' => $post->post_status, 'date' => $post->post_date, 'excerpt' => $post->post_excerpt, 'author' => get_the_author(), 'thumbnail' => $thumbnail);
             array_push($result, $item);
         }
     }
     if ($latest_post_item) {
         array_unshift($result, $latest_post_item);
     }
     if ($theme_based_landing_page) {
         array_unshift($result, $theme_based_landing_page);
     }
     header('Content-Type: application/json');
     echo json_encode($result);
     die;
 }
        protected function print_alternatives()
        {
            ?>
			<h2 style="padding-top:2em;"><?php 
            _e('Alternatives', 'nelioab');
            ?>
</h2>

			<?php 
            $this->print_theme($this->current_theme['id'], $this->current_theme['name'], $this->current_theme['image'], $this->current_theme['creator'], true, true);
            foreach ($this->themes as $theme) {
                $this->print_theme($theme['id'], $theme['name'], $theme['image'], $theme['creator'], $theme['selected']);
            }
            ?>

			<input type="hidden" name="nelioab_selected_themes" id="nelioab_selected_themes" value="<?php 
            echo rawurlencode(json_encode($this->selected_themes));
            ?>
" />

			<input type="hidden" name="nelioab_appspot_ids" id="nelioab_appspot_ids" value="<?php 
            echo rawurlencode(json_encode($this->appspot_ids));
            ?>
" />

			<script type="text/javascript">
				var NelioABSelectedThemes;
				(function($) {

					<?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
					NelioABParams = {css:{}};
					NelioABParams.css.value	= document.createElement('style');
					NelioABParams.css.value.setAttribute('type', 'text/css');
					NelioABParams.css.value.innerHTML = '' +
						'.nelioab-selected .theme-image-selector { ' +
						'  border-color:<?php 
            echo $colorscheme['primary'];
            ?>
 !important;' +
						'} ' +
						'.nelioab-theme.nelioab-selected, .nelioab-theme.nelioab-selected:hover { ' +
						'  background:<?php 
            echo $colorscheme['primary'];
            ?>
 !important;' +
						'}';
					document.getElementsByTagName('head')[0].appendChild(NelioABParams.css.value);


					NelioABSelectedThemes = JSON.parse( decodeURIComponent(
							jQuery('#nelioab_selected_themes').attr('value')
						)	);

					function validate() {
						var isOneSelected = false;
						for( var i = 0; i < NelioABSelectedThemes.length && !isOneSelected; ++i )
							if ( NelioABSelectedThemes[i].isSelected )
								isOneSelected = true;
						if ( isOneSelected )
							return [true,true];
						else
							return [true,false];
					}

					function toggleTheme( theme ) {
						if ( theme.hasClass( 'nelioab-is-current-theme' ) )
							return;
						var selected;
						if ( theme.hasClass('nelioab-selected') ) {
							theme.removeClass('nelioab-selected');
							selected = false;
						}
						else {
							theme.addClass('nelioab-selected');
							selected = true;
						}

						var id = theme.attr('id');
						var name = theme.find('.the-whole-name').first().text();
						var found = false;
						for( var i = 0; i < NelioABSelectedThemes.length && !found; ++i ) {
							var st = NelioABSelectedThemes[i];
							if ( st.value == id )
								found = st;
						}
						if ( !found ) {
							found = { value: id, name: name };
							NelioABSelectedThemes.push( found );
						}
						found.isSelected = selected;
						validate();
					}

					$('.nelioab-theme').click(function() {
						toggleTheme($(this));
					});

					// Save the experiment (and encode the alternatives)
					$(document).on('save-experiment', function() {
						$( '#nelioab_selected_themes' ).attr('value',
							encodeURIComponent( JSON.stringify( NelioABSelectedThemes ) )
								.replace( /'/g, "%27") );
					});

					$(document).on( 'tab-changed', function( e, tabId ) {
						if ( tabId == 'tab-theme-alts' )
							NelioABEditExperiment.validateCurrentTab = validate;
					});

				})(jQuery);
			</script>
			<?php 
        }
        /**
         * This function adds just one script in the widgets.php page. The script
         * checks if the user is currently editing a widget exp alternative and, if
         * it is, it'll hide all widgets except the alternative's.
         *
         * If he's editing no alternative, then all widgets that belong to one will
         * be hidden.
         */
        public function add_code_to_hide_widgets_when_editing_widget_exp()
        {
            $widgets_in_experiments = self::get_widgets_in_experiments();
            $viewing_original = !$this->validate($_GET, 'check');
            $exp_id = '';
            $alt_id = '';
            if ($viewing_original) {
                $widgets_to_hide = array_keys($widgets_in_experiments);
                $exp_id = 'original';
                $alt_id = 'original';
                ?>
				<script type="text/javascript">
				jQuery(document).ready(function() {
					var ids = <?php 
                echo json_encode($widgets_to_hide);
                ?>
;
					for ( i = 0; i < ids.length; ++i ) {
						jQuery('#widgets-right .nelioab-widget-' + ids[i]).closest('.widget').hide();
						jQuery('#wp_inactive_widgets .nelioab-widget-' + ids[i]).closest('.widget').hide();
					}
				});
				</script>
				<?php 
            } else {
                $widgets_to_show = array();
                $exp_id = $_GET['nelioab_exp'];
                $alt_id = $_GET['nelioab_alt'];
                foreach ($widgets_in_experiments as $widget_id => $exp_info) {
                    if ($exp_info['exp'] == $exp_id && $exp_info['alt'] == $alt_id) {
                        array_push($widgets_to_show, $widget_id);
                    }
                }
                require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
                $colorscheme = NelioABWpHelper::get_current_colorscheme();
                ?>

				<div id="nelioab-edit-alt-widgets" class="widgets-holder-wrap" style="border: 1px solid #e5e5e5;-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);box-shadow: 0 1px 1px rgba(0,0,0,.04);">
					<div class="widgets-sortables ui-sortable">
						<div class="sidebar-name" style="padding:0.2em 1em;background-color:<?php 
                echo $colorscheme['focus'];
                ?>
;">
							<div class="sidebar-name-arrow"><br></div>
							<h3 style="color:<?php 
                echo $colorscheme['foreground'];
                ?>
;"><?php 
                _e('Alternative Widget Set', 'nelioab');
                ?>
</h3>
						</div>
					</div>

					<div class="content" style="padding:0em 1em 1em 1em;">
						<p><?php 
                _e('Use the following button to duplicate the widgets you\'re currently using in your site.', 'nelioab');
                ?>
</p>
						<a class="button button-primary" id="duplicate-widgets"><?php 
                _e('Duplicate Widgets', 'nelioab');
                ?>
</a>
						<span class="spinner" style="float:none;"></span>
						<p><strong><?php 
                _e('Go back to...', 'nelioab');
                ?>
</strong></p>
						<ul style="margin-left:1.5em;">
							<?php 
                if (isset($_GET['back_to_edit'])) {
                    $url = admin_url('admin.php?page=nelioab-experiments&action=edit&id=' . $_GET['nelioab_exp'] . '&ctab=tab-alts&exp_type=' . NelioABExperiment::WIDGET_ALT_EXP);
                    ?>
								<li><a href="<?php 
                    echo $url;
                    ?>
"><?php 
                    _e('Editing this experiment', 'nelioab');
                    ?>
</a></li>
							<?php 
                } else {
                    $url = admin_url('admin.php?page=nelioab-experiments&action=progress&id=' . $_GET['nelioab_exp'] . '&exp_type=' . NelioABExperiment::WIDGET_ALT_EXP);
                    ?>
								<li><a href="<?php 
                    echo $url;
                    ?>
"><?php 
                    _e('The results of the related experiment', 'nelioab');
                    ?>
</a></li>
							<?php 
                }
                ?>
							<?php 
                $url = admin_url('admin.php?page=nelioab-experiments');
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('My list of experiments', 'nelioab');
                ?>
</a></li>
						</ul>
					</div>

				</div>

				<script type="text/javascript">
				(function($) {
					var $content = jQuery('#nelioab-edit-alt-widgets .content');
					$('#nelioab-edit-alt-widgets .sidebar-name').on('click', function() {
						$content.toggle();
					});

					$('#duplicate-widgets').on('click', function() {
						if ( $(this).hasClass('disabled') )
							return;
						$(this).addClass('disabled');
						$('#nelioab-edit-alt-widgets .spinner').css('display', 'inline-block');
						$('#available-widgets,.inactive-sidebar,.widget-liquid-right').fadeOut();

						jQuery.ajax({
							type:  'POST',
							async: false,
							url:   ajaxurl,
							data: {
									action: 'nelioab_duplicate_original_widgets',
									exp_id: <?php 
                echo $_GET['nelioab_exp'];
                ?>
,
									alt_id: <?php 
                echo $_GET['nelioab_alt'];
                ?>
,
									check:  '<?php 
                echo hash('md5', $_GET['nelioab_exp'] . $_GET['nelioab_alt']);
                ?>
',
								},
							success: function(data) {
								window.location.reload();
							},
							error: function(data) {
								// Something failed :-(
							},
						});

					});

					$(document).ajaxComplete(function() {
						if ( jQuery("#widgets-right .widget:visible").length > 0 )
							jQuery('#duplicate-widgets').addClass('disabled');
						else
							jQuery('#duplicate-widgets').removeClass('disabled');
					});

				})(jQuery);

				jQuery(document).ready(function() {
					// Hide all widgets and then show only those that belong to this alt/exp combo
					jQuery('#widgets-right .widget').hide();
					jQuery('#wp_inactive_widgets .widget').hide();
					var ids = <?php 
                echo json_encode($widgets_to_show);
                ?>
;
					for ( i = 0; i < ids.length; ++i )
						jQuery('.nelioab-widget-' + ids[i]).closest('.widget').css('display','');

					// Disable "duplicate widgets" button if there are widgets
					if ( jQuery("#widgets-right .widget:visible").length > 0 )
						jQuery('#duplicate-widgets').addClass('disabled');
					else
						jQuery('#duplicate-widgets').removeClass('disabled');

					// Add controls
					var $block = jQuery('#nelioab-edit-alt-widgets').detach();
					jQuery('#widgets-left').prepend($block);
					$block.show();
				});
				</script>
				<?php 
            }
            // Set the proper EXP/ALT combo values for new widgets
            ?>
			<script type="text/javascript">
			jQuery(document).ready(function() {
				jQuery('#available-widgets .widget input[name=nelioab_exp]').attr('value','<?php 
            echo $exp_id;
            ?>
');
				jQuery('#available-widgets .widget input[name=nelioab_alt]').attr('value','<?php 
            echo $alt_id;
            ?>
');
			});
			</script>
			<?php 
        }
Пример #13
0
/**
 * Deactivates our plugin.
 *
 * This function is called by the "registed_deactivation_hook". Alternatives
 * are regular pages or posts (draft status) with a special metaoption that
 * is used to hide them from the admin menu. When the plugin is deactivated,
 * no one hides the alternatives... In order to prevent them from appearing,
 * we change their post_type to a fake type.
 *
 * @return void
 *
 * @since PHPDOC
 */
function nelioab_deactivate_plugin()
{
    /** @var wpdb $wpdb */
    global $wpdb;
    require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
    require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php';
    if (isset($_GET['action']) && 'clean-and-deactivate' == $_GET['action']) {
        // Remove all alternative widgets
        NelioABWidgetExpAdminController::clean_all_alternative_widgets();
        // Remove all alternative menus
        NelioABMenuExpAdminController::clean_all_alternative_menus();
        // Remove all alternative pages and posts
        $query = '' . 'DELETE FROM ' . $wpdb->posts . ' WHERE ' . 'id IN (' . 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE ' . 'meta_key = \'_is_nelioab_alternative\' ' . ')';
        $wpdb->query($query);
        // Clean all experiments in AE
        require_once NELIOAB_UTILS_DIR . '/backend.php';
        for ($i = 0; $i < 5; ++$i) {
            try {
                NelioABBackend::remote_get(sprintf(NELIOAB_BACKEND_URL . '/site/%s/clean', NelioABAccountSettings::get_site_id()));
                break;
            } catch (Exception $e) {
            }
        }
        // Remove all Nelio options
        $query = 'DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE \'%nelioab%\'';
        $wpdb->query($query);
        $query = 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE \'%nelioab%\'';
        $wpdb->query($query);
    } else {
        // Hiding alternative posts
        $query = '' . 'UPDATE ' . $wpdb->posts . ' SET post_type = %s WHERE ' . 'id IN (' . 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE ' . 'meta_key = \'_is_nelioab_alternative\' ' . ') AND ' . 'post_type = %s';
        // recover post type names
        require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
        $cpts = NelioABWpHelper::get_custom_post_types();
        $post_types = array('post', 'page');
        foreach ($cpts as $post_type) {
            array_push($post_types, $post_type->name);
        }
        // execute the query
        foreach ($post_types as $post_type) {
            $wpdb->query($wpdb->prepare($query, 'nelioab_alt_' . $post_type, $post_type));
        }
        // Hiding widget alternatives
        NelioABWidgetExpAdminController::backup_alternative_widgets();
        // Hiding menu alternatives
        NelioABMenuExpAdminController::backup_alternative_menus();
    }
}
Пример #14
0
        public function do_render()
        {
            echo '<div id="post-body" class="metabox-holder columns-2">';
            echo '<div id="post-body-content">';
            if (count($this->experiments) == 0) {
                echo "<div class='nelio-message'>";
                echo sprintf('<img class="animated flipInY" src="%s" alt="%s" />', nelioab_admin_asset_link('/images/dashboard.png'), __('Dashboard Icon', 'nelioab'));
                echo '<h2 style="max-width:750px;">';
                printf('%1$s<br><br><a class="button button-primary" href="%3$s">%2$s</a>', __('Here you\'ll find relevant information about your running experiments.', 'nelioab'), __('Create One Now!', 'nelioab', 'create-experiment'), 'admin.php?page=nelioab-add-experiment');
                echo '</h2>';
                echo '</div>';
            } else {
                echo '<h2>' . __('Running Experiments', 'nelioab') . '</h2>';
                $this->print_cards();
            }
            echo '</div>';
            ?>
			<div id="postbox-container-1" class="postbox-container" style="overflow:hidden;">
				<h2>&nbsp;</h2>
				<?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $cs = NelioABWpHelper::get_current_colorscheme();
            ?>

				<div class="numbers" style="height:40px;">
					<div class="left" style="float:left; width:55%;">
						<span style="font-weight:bold;"><?php 
            _e('AVAILABLE QUOTA', 'nelioab');
            ?>
</span><br>
						<span style="color:<?php 
            echo $cs['primary'];
            ?>
; font-size:10px;"><?php 
            echo number_format_i18n($this->quota['regular'], 0);
            ?>
</span><span style="font-size:10px;"> / <?php 
            echo number_format_i18n($this->quota['monthly'], 0);
            if ($this->quota['extra'] > 0) {
                echo ' <span style="color:#999;">';
                printf(__('(+%s extra)', 'nelioab'), number_format_i18n($this->quota['extra'], 0));
                echo '</span>';
            }
            ?>
</span>
					</div>
					<div class="right" style="font-size:32px; text-align:right; float:right; width:38%; padding-right:5%; margin-top:8px; opacity:0.7;">
						<span><?php 
            // Let's compute the size of the extra quota (if any)
            if ($this->quota['extra'] > 0) {
                $extra = $this->quota['extra'];
                $max_extra = $this->quota['monthly'] / 2;
                if ($extra > $max_extra) {
                    $extra = $max_extra;
                }
                $extra_perc = $extra / $max_extra * 20;
            } else {
                $extra_perc = 0;
            }
            $extra_perc = number_format($extra_perc, 0);
            // Now let's compute the size of the regular bar
            if ($this->quota['regular'] > 0) {
                $perc = $this->quota['regular'] / $this->quota['monthly'] * 100;
            } else {
                $perc = 0;
            }
            $num_of_decs = 1;
            if (100 == $perc) {
                $num_of_decs = 0;
            }
            echo number_format($perc, $num_of_decs);
            ?>
%</span>
					</div>
				</div>

				<div class="progress-bar-container" style="background:none;border:2px solid rgba(0,0,0,0.1); width:95%; margin:0px; height:20px;"><?php 
            $bar = '<div class="progress-bar" style="margin:0;padding:0;display:inline-block;height:20px;background-color:%s;width:%s%%;"></div>';
            $perc = number_format($perc, 0);
            if ($perc + $extra_perc > 100) {
                $perc = 100 - $extra_perc;
            }
            printf($bar, $cs['primary'], $perc);
            printf($bar, $cs['secondary'], $extra_perc);
            ?>
</div>
			<?php 
            $this->print_rss();
            echo '</div>';
            // #post-body
        }
Пример #15
0
 private static function prepare_pro_label($label, $help = true)
 {
     if (!NelioABAccountSettings::is_plan_at_least(NelioABAccountSettings::PROFESSIONAL_SUBSCRIPTION_PLAN)) {
         $res = '<span class="pro-setting-label setting-disabled">' . $label;
         if ($help) {
             $res .= ' ' . self::get_icon('#AAA');
         }
         $res .= '</span>';
         return $res;
     } else {
         $aux = NelioABWpHelper::get_current_colorscheme();
         $color = $aux['primary'];
         $res = '<span class="pro-setting-label">' . $label;
         if ($help) {
             $res .= ' ' . self::get_icon($color);
         }
         $res .= '</span>';
         return $res;
     }
 }
Пример #16
0
    protected function do_render()
    {
        ?>

		<div id="post-body" class="metabox-holder columns-2">
		<form id="css_edit_value" method="POST" action="#">
			<input type="hidden" name="css_save_alt" id="css_save_alt" value="true"></input>
			<div id="post-body-content">

				<div id="titlediv">

					<div id="titlewrap">
						<label class="screen-reader-text" id="title-prompt-text" for="title">Enter title here</label>
						<input type="text" name="post_title" size="30" value="<?php 
        echo $this->css_alt->get_name();
        ?>
" id="title" autocomplete="off"></input>
					</div>

					<div class="inside">
						<div id="postdivrich" class="postarea edit-form-section">
							<div id="wp-content-wrap" class="wp-core-ui wp-editor-wrap tmce-active">
								<div class="wp-editor-tabs">
									<br>
									<!-- <a id="content-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Plain</a> -->
									<!-- <a id="content-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</a> -->
								</div>
							</div>
								<input type="hidden" id="content" name="content"></input>
								<pre id="editor"><?php 
        echo $this->css_alt->get_value();
        ?>
</pre>
								<script type="text/javascript" src="<?php 
        echo nelioab_admin_asset_link('/lib/ace-editor/ace.js');
        ?>
"></script>
								<script type="text/javascript">
									var nelioabCssEditor = ace.edit('editor');
									nelioabCssEditor.setTheme('ace/theme/tomorrow');
									nelioabCssEditor.session.setMode('ace/mode/css');
									nelioabCssEditor.setAutoScrollEditorIntoView(true);
									nelioabCssEditor.setOption('minLines', 20);
									nelioabCssEditor.setOption('maxLines', 100);
									nelioabCssEditor.setFontSize(15);
								</script>
						</div>
					</div>

				</div>
			</div><!-- /post-body-content -->

			<div id="postbox-container-1" class="postbox-container">

				<div id="save_nelioab_alternative_box" class="meta-box-sortables ui-sortable">
					<div id="submitdiv" class="postbox"><?php 
        require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
        $colorscheme = NelioABWpHelper::get_current_colorscheme();
        ?>
						<script>
							var nelioab_style_metabox = document.createElement("style");
							nelioab_style_metabox.setAttribute("type", "text/css");
							nelioab_style_metabox.innerHTML = "#save_nelioab_alternative_box h3.hndle { " +
								"color:<?php 
        echo $colorscheme['foreground'];
        ?>
; " +
								"background: <?php 
        echo $colorscheme['focus'];
        ?>
;" +
								"border: 1px solid <?php 
        echo $colorscheme['focus'];
        ?>
;" +
							"}" +
							"#favorite-actions, #message, .add-new-h2, .tablenav, #edit-slug-box { display:none; }" +
							"#save_nelioab_alternative_box .handlediv," +
							"#save_nelioab_alternative_box .handlediv:hover { visibility:visible; color:white; }";
							document.getElementsByTagName('head')[0].appendChild(nelioab_style_metabox);
						</script>

						<h3 style="cursor:auto;" class="hndle"><span><?php 
        _e('Update');
        ?>
</span></h3>
						<div class="inside">
							<div class="submitbox" id="submitpost">

								<div style="margin:1em;">
									<p><?php 
        _e('Select a page or post for preview', 'nelioab');
        ?>
</p>
									<?php 
        require_once NELIOAB_UTILS_DIR . '/html-generator.php';
        NelioABHtmlGenerator::print_full_searcher('post-options', false, 'show-drafts');
        ?>
								</div>

								<div class="misc-pub-section" style="min-height:4em;">
									<div style="float:right;margin-top:1em;">
										<input name="original_publish" type="hidden" id="original_publish" value="Update">
										<input name="save" type="submit"
											class="button button-primary" id="publish"
											tabindex="5"
											value="<?php 
        _e('Update');
        ?>
" />
										<script type="text/javascript">
										jQuery( "#css_edit_value" ).on( 'submit', function() {
											jQuery("#content").attr('value', nelioabCssEditor.getValue());
										});
										</script>
									</div>
									<div style="float:right;margin-top:1em;margin-right:1em;">
										<div id="preview-action">
											<a id="preview-button" class="preview button" target="wp-preview" id="post-preview" tabindex="4"><?php 
        _e('Preview');
        ?>
</a>
											<input type="hidden" name="wp-preview" id="wp-preview" value="" />
										</div>
									</div>
								</div>
								<?php 
        $url = admin_url('admin.php');
        $url = add_query_arg(array('nelioab-page' => 'save-css', 'preview' => 'true', 'nelioab_preview_css' => $_REQUEST['css_id']), $url);
        ?>
								<script>
									jQuery("#preview-button").click(function(e) {
										var aux = jQuery("#post-options").attr('value');
										if ( aux == -1 || aux == "" || aux == undefined ) return;
										if ( aux == <?php 
        echo NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS;
        ?>
 ) aux = "";
										else aux = "&p=" + aux;
										jQuery("#css_edit_value").attr('action', "<?php 
        echo $url;
        ?>
" + aux);
										jQuery("#css_edit_value").attr('target', '_blank');
										jQuery("#css_edit_value").submit();
										jQuery("#css_edit_value").attr('action', '#');
										jQuery("#css_edit_value").attr('target', '');
									});
								</script>

								<div style="margin:10px;">
									<b><?php 
        _e('Go back to...', 'nelioab');
        ?>
</b>
									<?php 
        $url = admin_url('admin.php?page=nelioab-experiments');
        $exp_id = $this->experiment->get_id();
        $exp_status = $this->experiment->get_status();
        ?>
									<ul style="margin-left:1.5em;">
										<?php 
        require_once NELIOAB_MODELS_DIR . '/experiment.php';
        switch ($exp_status) {
            case NelioABExperiment::STATUS_DRAFT:
            case NelioABExperiment::STATUS_READY:
                ?>
<li><a href="<?php 
                echo $url . '&action=edit&ctab=tab-alts&id=' . $exp_id . '&exp_type=' . $this->experiment->get_type();
                ?>
"><?php 
                _e('Editing this experiment', 'nelioab');
                ?>
</a></li><?php 
                break;
            case NelioABExperiment::STATUS_RUNNING:
            case NelioABExperiment::STATUS_FINISHED:
                ?>
<li><a href="<?php 
                echo $url . '&action=progress&id=' . $exp_id . '&exp_type=' . $this->experiment->get_type();
                ?>
"><?php 
                _e('The results of the related experiment', 'nelioab');
                ?>
</a></li><?php 
                break;
            case NelioABExperiment::STATUS_TRASH:
            case NelioABExperiment::STATUS_PAUSED:
            default:
                // Nothing here
        }
        ?>
									   <li><a href="<?php 
        echo $url;
        ?>
"><?php 
        _e('My list of experiments', 'nelioab');
        ?>
</a></li>
									   <li><a href="<?php 
        echo admin_url('admin.php?page=nelioab-dashboard');
        ?>
"><?php 
        _e('The Dashboard', 'nelioab');
        ?>
</a></li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- END OF SIDEBAR -->

			</div>
		</form>
		</div>
		<?php 
    }
Пример #17
0
        public function print_alternative_box()
        {
            ?>
			<div id="submitdiv"><?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
				<script>
					var nelioab_style_metabox = document.createElement("style");
					nelioab_style_metabox.setAttribute("type", "text/css");
					nelioab_style_metabox.innerHTML = "#save_nelioab_alternative_box h3.hndle { " +
						"color:<?php 
            echo $colorscheme['foreground'];
            ?>
; " +
						"background: <?php 
            echo $colorscheme['focus'];
            ?>
;" +
						"border: 1px solid <?php 
            echo $colorscheme['focus'];
            ?>
;" +
					"}" +
					"#favorite-actions, #message, .add-new-h2, .tablenav, #edit-slug-box { display:none; }" +
					"#save_nelioab_alternative_box .handlediv," +
					"#save_nelioab_alternative_box .handlediv:hover { visibility:visible; color:white; }";
					document.getElementsByTagName('head')[0].appendChild(nelioab_style_metabox);
				</script>
				<div class="submitbox" id="submitpost">
					<div class="misc-pub-section" style="min-height:4em;">
						<div style="float:right;margin-top:1em;">
							<input name="original_publish" type="hidden" id="original_publish" value="Update">
							<input name="save" type="submit"
								class="button button-primary" id="publish"
								tabindex="5"
								value="<?php 
            _e('Update');
            ?>
" />
						</div>
						<?php 
            $the_post_id = 0;
            if (isset($_GET['post'])) {
                $the_post_id = $_GET['post'];
            }
            $url = admin_url('admin.php?page=nelioab-experiments');
            $values = explode(',', get_post_meta($the_post_id, '_is_nelioab_alternative', true));
            $exp_id = $values[0];
            $exp_status = $values[1];
            ?>
						<div style="float:right;margin-top:1em;margin-right:1em;">
							<div id="preview-action">
								<?php 
            $type = 'post';
            $ori_id = get_post_meta($_GET['post'], '_nelioab_original_id', true);
            if (NelioABExperiment::STATUS_RUNNING == $exp_status || NelioABExperiment::STATUS_FINISHED == $exp_status) {
                $preview_button = __('Preview Changes');
            } else {
                $preview_button = __('Preview');
            }
            $preview_link = get_permalink($_GET['post']);
            $preview_link = esc_url(add_query_arg('preview', 'true', $preview_link));
            ?>
								<a class="preview button" href="<?php 
            echo $preview_link;
            ?>
" target="wp-preview-<?php 
            echo $_GET['post'];
            ?>
" id="post-preview"><?php 
            echo $preview_button;
            ?>
</a>
								<input type="hidden" name="wp-preview" id="wp-preview" value="" />
							</div>
						</div>
					</div>
					<div style="margin:0.8em 0.2em 0.8em 0.2em;">
						<b><?php 
            _e('Go back to...', 'nelioab');
            ?>
</b>
						<ul style="margin-left:1.5em;">
							<?php 
            switch ($exp_status) {
                case NelioABExperiment::STATUS_DRAFT:
                case NelioABExperiment::STATUS_READY:
                    ?>
<li><a href="<?php 
                    echo $url . '&action=edit&ctab=tab-alts&id=' . $exp_id . '&exp_type=' . NelioABExperiment::PAGE_OR_POST_ALT_EXP;
                    ?>
"><?php 
                    _e('Editing this experiment', 'nelioab');
                    ?>
</a></li><?php 
                    break;
                case NelioABExperiment::STATUS_RUNNING:
                case NelioABExperiment::STATUS_FINISHED:
                    ?>
<li><a href="<?php 
                    echo $url . '&action=progress&id=' . $exp_id . '&exp_type=' . NelioABExperiment::PAGE_OR_POST_ALT_EXP;
                    ?>
"><?php 
                    _e('The results of the related experiment', 'nelioab');
                    ?>
</a></li><?php 
                    break;
                case NelioABExperiment::STATUS_TRASH:
                case NelioABExperiment::STATUS_PAUSED:
                default:
                    // Nothing here
            }
            ?>
							<li><a href="<?php 
            echo $url;
            ?>
"><?php 
            _e('My list of experiments', 'nelioab');
            ?>
</a></li>
							<?php 
            if ($exp_status == NelioABExperiment::STATUS_RUNNING) {
                ?>
								<li><a href="<?php 
                echo admin_url('admin.php?page=nelioab-dashboard');
                ?>
"><?php 
                _e('The Dashboard', 'nelioab');
                ?>
</a></li>
							<?php 
            }
            ?>
						</ul>
					</div>
				</div>
			</div><?php 
        }
Пример #18
0
 /**
  * It initializes the controller.
  *
  * If Nelio's subscription has been deactivated, the plugin will do
  * nothing at all.
  *
  * @return void
  */
 public function init()
 {
     // If the user has been disabled... get out of here
     try {
         NelioABAccountSettings::check_user_settings();
     } catch (Exception $e) {
         // It is important we add the check here: if the user was deactivated, but it no
         // longer is, then it's important his settings are rechecked so that we can
         // re-enable it.
         if ($e->getCode() == NelioABErrCodes::DEACTIVATED_USER) {
             return;
         }
     }
     // Load the Visitor class so that all assigned alternatives are
     require_once NELIOAB_MODELS_DIR . '/visitor.php';
     NelioABVisitor::load();
     // Trick for proper THEME ALT EXP testing
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     // Theme alt exp related
     if (NelioABWpHelper::is_at_least_version(3.4)) {
         $aux = $this->controllers['alt-exp'];
         add_filter('stylesheet', array(&$aux, 'modify_stylesheet'));
         add_filter('template', array(&$aux, 'modify_template'));
         add_filter('sidebars_widgets', array(&$aux, 'show_the_appropriate_widgets'));
         add_filter('option_stylesheet', array(&$aux, 'modify_option_stylesheet'));
         add_filter('option_current_theme', array(&$aux, 'modify_option_current_theme'));
         require_once NELIOAB_UTILS_DIR . '/theme-compatibility-layer.php';
         NelioABThemeCompatibilityLayer::make_compat();
     }
     add_action('init', array(&$this, 'do_init'));
     add_action('init', array(&$this, 'init_admin_stuff'));
 }