示例#1
0
 public static function generate_html_content()
 {
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     $view = new NelioABCssEditPage();
     $exp_id = 0;
     $css_id = 0;
     if (isset($_REQUEST['exp_id'])) {
         $exp_id = $_REQUEST['exp_id'];
     }
     if (isset($_REQUEST['css_id'])) {
         $css_id = $_REQUEST['css_id'];
     }
     try {
         $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, NelioABExperiment::CSS_ALT_EXP);
         $view->experiment = $exp;
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     if (isset($_REQUEST['css_save_alt']) && isset($_REQUEST['css_alt_name']) && isset($_REQUEST['css_alt_value'])) {
         require_once NELIOAB_MODELS_DIR . '/alternatives/css-alternative-experiment.php';
         $exp->update_css_alternative($css_id, $_REQUEST['css_alt_name'], urldecode($_REQUEST['css_alt_value']));
     }
     foreach ($view->experiment->get_alternatives() as $alt) {
         if ($alt->get_id() == $css_id) {
             $view->css_alt = $alt;
         }
     }
     $view->do_render();
     die;
 }
 public static function generate_html_content()
 {
     global $nelioab_admin_controller;
     if (isset($nelioab_admin_controller->data)) {
         $exp = $nelioab_admin_controller->data;
         $exp_id = $exp->get_id();
     } else {
         $exp_id = -time();
         if (isset($_REQUEST['exp_id'])) {
             $exp_id = $_REQUEST['exp_id'];
         }
         $exp = null;
         try {
             $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, NelioABExperiment::THEME_ALT_EXP);
         } catch (Exception $e) {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
     $title = __('Results of the Experiment', 'nelioab');
     $view = new NelioABThemeAltExpProgressPage($title);
     $view->set_experiment($exp);
     $goals = $exp->get_goals();
     $view->set_goals($goals);
     $goal_id = -1;
     if (isset($_REQUEST['goal'])) {
         $goal_id = $_REQUEST['goal'];
     }
     $view->set_current_selected_goal($goal_id);
     $view->render_content();
     die;
 }
 public static function generate_html_content()
 {
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     try {
         $summary = NelioABExperimentsManager::get_dashboard_summary();
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     $title = __('Dashboard', 'nelioab');
     $view = new NelioABDashboardPage($title);
     $view->set_summary($summary);
     $view->render_content();
     die;
 }
 public static function generate_html_content()
 {
     global $nelioab_admin_controller;
     if (isset($nelioab_admin_controller->data)) {
         $exp = $nelioab_admin_controller->data;
         $exp_id = $exp->get_id();
     } else {
         $exp_id = -time();
         if (isset($_REQUEST['exp_id'])) {
             $exp_id = $_REQUEST['exp_id'];
         }
         $exp_type = -1;
         if (isset($_POST['exp_type'])) {
             $exp_type = $_POST['exp_type'];
         }
         $exp = null;
         try {
             $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type);
         } catch (Exception $e) {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
     $title = __('Results of the Experiment', 'nelioab');
     $view = new NelioABWidgetAltExpProgressPage($title);
     $view->set_experiment($exp);
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
     $widgets_in_experiments = NelioABWidgetExpAdminController::get_widgets_in_experiments();
     $are_there_alternatives_to_apply = false;
     foreach ($widgets_in_experiments as $info) {
         if ($info['exp'] == $exp->get_id()) {
             $are_there_alternatives_to_apply = true;
         }
     }
     $view->set_there_are_alternatives_to_apply($are_there_alternatives_to_apply);
     $goals = $exp->get_goals();
     $view->set_goals($goals);
     $goal_id = -1;
     if (isset($_REQUEST['goal'])) {
         $goal_id = $_REQUEST['goal'];
     }
     $view->set_current_selected_goal($goal_id);
     $view->render_content();
     die;
 }
 public static function get_controller($type)
 {
     // Determine the proper controller and give it the control...
     switch ($type) {
         case NelioABExperiment::HEADLINE_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/headline-alt-exp-creation-page-controller.php';
             return 'NelioABHeadlineAltExpCreationPageController';
         case NelioABExperiment::POST_ALT_EXP:
         case NelioABExperiment::PAGE_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/post-alt-exp-creation-page-controller.php';
             return 'NelioABPostAltExpCreationPageController';
         case NelioABExperiment::THEME_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/theme-alt-exp-creation-page-controller.php';
             return 'NelioABThemeAltExpCreationPageController';
         case NelioABExperiment::CSS_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/css-alt-exp-creation-page-controller.php';
             return 'NelioABCssAltExpCreationPageController';
         case NelioABExperiment::WIDGET_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/widget-alt-exp-creation-page-controller.php';
             return 'NelioABWidgetAltExpCreationPageController';
         case NelioABExperiment::MENU_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/menu-alt-exp-creation-page-controller.php';
             return 'NelioABMenuAltExpCreationPageController';
         case NelioABExperiment::HEATMAP_EXP:
             require_once NELIOAB_ADMIN_DIR . '/others/heatmap-exp-creation-page-controller.php';
             return 'NelioABHeatmapExpCreationPageController';
         case NelioABExperiment::CPT_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/alternatives/cpt-alt-exp-creation-page-controller.php';
             return 'NelioABCptAltExpCreationPageController';
         case NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/woocommerce/product-summary-alt-exp-creation-page-controller.php';
             return 'NelioABProductSummaryAltExpCreationPageController';
         default:
             require_once NELIOAB_UTILS_DIR . '/backend.php';
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             $err = NelioABErrCodes::UNKNOWN_ERROR;
             $e = new Exception(NelioABErrCodes::to_string($err), $err);
             NelioABErrorController::build($e);
     }
 }
 public static function get_controller($type)
 {
     // Determine the proper controller and give it the control...
     switch ($type) {
         case NelioABExperiment::HEADLINE_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/headline-alt-exp-progress-page-controller.php';
             return 'NelioABHeadlineAltExpProgressPageController';
         case NelioABExperiment::POST_ALT_EXP:
         case NelioABExperiment::PAGE_ALT_EXP:
         case NelioABExperiment::CPT_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/post-alt-exp-progress-page-controller.php';
             return 'NelioABPostAltExpProgressPageController';
         case NelioABExperiment::THEME_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/theme-alt-exp-progress-page-controller.php';
             return 'NelioABThemeAltExpProgressPageController';
         case NelioABExperiment::CSS_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/css-alt-exp-progress-page-controller.php';
             return 'NelioABCssAltExpProgressPageController';
         case NelioABExperiment::WIDGET_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/widget-alt-exp-progress-page-controller.php';
             return 'NelioABWidgetAltExpProgressPageController';
         case NelioABExperiment::MENU_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/menu-alt-exp-progress-page-controller.php';
             return 'NelioABMenuAltExpProgressPageController';
         case NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP:
             require_once NELIOAB_ADMIN_DIR . '/progress/headline-alt-exp-progress-page-controller.php';
             return 'NelioABHeadlineAltExpProgressPageController';
         case NelioABExperiment::HEATMAP_EXP:
             // Nothing to be done in here...
         // Nothing to be done in here...
         default:
             require_once NELIOAB_UTILS_DIR . '/backend.php';
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             $err = NelioABErrCodes::UNKNOWN_ERROR;
             $e = new Exception(NelioABErrCodes::to_string($err), $err);
             NelioABErrorController::build($e);
     }
 }
 public function on_valid_submit()
 {
     // 1. Save the data properly
     global $nelioab_admin_controller;
     $experiment = $nelioab_admin_controller->data;
     try {
         $experiment->save();
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     // 2. Redirect to the appropiate page
     echo '[SUCCESS]' . admin_url('admin.php?page=nelioab-experiments&action=list');
     die;
 }
 public static function duplicate_experiment($new_name, $exp_id, $exp_type)
 {
     $exp = NULL;
     try {
         $action = 'duplicate-' . $exp_id;
         if (!isset($_REQUEST['_nonce']) || !nelioab_verify_onetime_nonce($_REQUEST['_nonce'], $action)) {
             require_once NELIOAB_UTILS_DIR . '/backend.php';
             $err = NelioABErrCodes::INVALID_NONCE;
             throw new Exception(NelioABErrCodes::to_string($err), $err);
         }
         $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type);
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     try {
         if ($exp == NULL) {
             $err = NelioABErrCodes::INVALID_EXPERIMENT;
             throw new Exception(NelioABErrCodes::to_string($err), $err);
         }
         $exp->duplicate($new_name);
     } catch (Exception $e) {
         global $nelioab_admin_controller;
         switch ($e->getCode()) {
             case NelioABErrCodes::EXPERIMENT_CANNOT_BE_DUPLICATED:
                 $nelioab_admin_controller->error_message = $e->getMessage();
                 return;
             default:
                 require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
                 NelioABErrorController::build($e);
         }
     }
 }
 public function edit_alternative_content()
 {
     // 1. Save any local changes
     global $nelioab_admin_controller;
     $experiment = $nelioab_admin_controller->data;
     try {
         $experiment->save();
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     // 2. Redirect to the edit page
     $exp_id = $experiment->get_id();
     $widget_alt_id = 0;
     if (isset($_POST['content_to_edit'])) {
         $widget_alt_id = $_POST['content_to_edit'];
         $widget_alt_id = $experiment->get_real_id_for_alt($widget_alt_id);
     }
     echo '[SUCCESS]' . admin_url('widgets.php?nelioab_exp=' . $exp_id . '&nelioab_alt=' . $widget_alt_id . '&nelioab_check=' . md5($exp_id . $widget_alt_id) . '&back_to_edit=1');
     die;
 }
 public static function manage_site_registration()
 {
     global $nelioab_admin_controller;
     if (isset($_POST['nelioab_registration_action'])) {
         $action = $_POST['nelioab_registration_action'];
         try {
             switch ($action) {
                 case 'register':
                     $type = 'unknown';
                     if (isset($_POST['nelioab_registration_type'])) {
                         $type = $_POST['nelioab_registration_type'];
                     }
                     $sector = 'unknown';
                     if (isset($_POST['nelioab_registration_sector'])) {
                         $sector = $_POST['nelioab_registration_sector'];
                     }
                     NelioABAccountSettings::register_this_site($type, $sector);
                     $nelioab_admin_controller->message = __('This site has been successfully activated in your account.', 'nelioab');
                     break;
                 case 'deregister':
                     NelioABAccountSettings::deregister_this_site();
                     $nelioab_admin_controller->message = __('This site is no longer active in your account.', 'nelioab');
                 case 'unlink':
                     NelioABAccountSettings::unlink_this_site();
                     $nelioab_admin_controller->message = __('The site is no longer linked to any of your other active sites. If you have free slots, you may now activate it as a completely different and new site.', 'nelioab');
             }
         } catch (Exception $e) {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
 }
 public function edit_alternative_content()
 {
     // 1. Save any local changes
     global $nelioab_admin_controller;
     $experiment = $nelioab_admin_controller->data;
     // Before saving the experiment, we have to get the alternative we
     // want to edit (after saving it, its IDs and/or its values may have
     // change).
     $post_id = '' . $_POST['content_to_edit'];
     if (strpos($post_id, ':')) {
         $aux = explode(':', $post_id);
         $post_id = $aux[1];
     }
     $alt_to_edit = false;
     foreach ($experiment->get_alternatives() as $alt) {
         if ($alt->get_value() == $post_id) {
             $alt_to_edit = $alt;
         }
     }
     try {
         $experiment->save();
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     // 2. Redirect to the edit page
     update_post_meta($alt_to_edit->get_value(), '_nelioab_original_id', $experiment->get_originals_id());
     echo '[SUCCESS]' . admin_url('post.php?action=edit&post=' . $alt_to_edit->get_value());
     die;
 }
 public function set_current_selected_goal($id)
 {
     $this->goal = false;
     foreach ($this->goals as $goal) {
         if ($goal->get_id() == $id) {
             $this->goal = $goal;
         }
     }
     if (!$this->goal) {
         foreach ($this->goals as $goal) {
             if ($goal->is_main_goal()) {
                 $this->goal = $goal;
             }
         }
     }
     // If there's only one goal, but it's not set as the main goal (weird),
     // I use it by default. It should not happen, but sometimes it does. This
     // fragment resolves the issue.
     if (!$this->goal) {
         if (count($this->goals) == 1) {
             $this->goal = $this->goals[0];
         }
     }
     if (!$this->goal) {
         return;
     }
     try {
         $this->results = $this->goal->get_results();
     } catch (Exception $e) {
         require_once NELIOAB_UTILS_DIR . '/backend.php';
         if ($e->getCode() == NelioABErrCodes::RESULTS_NOT_AVAILABLE_YET) {
             $this->results = null;
         } else {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
 }