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'; $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 build() { // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } $title = __('Settings', 'nelioab'); $view = new NelioABSettingsPage($title); $view->render(); }
public static function build() { // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } $aux = NelioABWidgetAltExpCreationPageController::get_instance(); $view = $aux->do_build(); $view->render(); }
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 build() { // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } $aux = NelioABPostAltExpCreationPageController::get_instance(); $view = $aux->do_build(); $page_on_front = get_option('page_on_front'); if (isset($_GET['lp']) && $page_on_front) { $view->set_original_id($page_on_front); } $view->render(); }
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 build() { // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } // Checking whether there are menus available $menus = wp_get_nav_menus(); if (count($menus) == 0) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(sprintf(__('There are no menus available.<br><a href="%s">Create one now.</a>', 'nelioab'), admin_url('/nav-menus.php'))); } else { $aux = NelioABMenuAltExpCreationPageController::get_instance(); $view = $aux->do_build(); } $view->render(); }
public static function build_error_page_on_invalid_settings() { // Check settings try { $aux = NelioABAccountSettings::check_user_settings(); } catch (Exception $e) { switch ($e->getCode()) { case NelioABErrCodes::DEACTIVATED_USER: case NelioABErrCodes::INVALID_MAIL: case NelioABErrCodes::INVALID_PRODUCT_REG_NUM: case NelioABErrCodes::NON_ACCEPTED_TAC: case NelioABErrCodes::BACKEND_NO_SITE_CONFIGURED: require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $view = NelioABErrorController::get_view($e); $view->render(); return true; default: return false; } } return false; }
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; }
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; } // 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; } else { $experiment = new NelioABThemeAlternativeExperiment(-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()); } } } // Checking whether there is more than one theme // available // --------------------------------------------------- $themes = wp_get_themes(); usort($themes, array($this, 'sort_themes_alphabetically')); if (count($themes) < 2) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(__('There is only one theme available', 'nelioab'), __('Please, install one or more themes to create an experiment of this type.', 'nelioab')); return $view; } // If everything is OK, we keep going! // --------------------------------------------------- $current_theme = wp_get_theme(); $current_theme_id = $current_theme['Stylesheet']; $current_theme_name = $current_theme->offsetGet('Title'); // We select the alternatives $experiment->add_selected_theme($current_theme_id, $current_theme_name); if (isset($_POST['nelioab_selected_themes'])) { $selected_themes = json_decode(urldecode($_POST['nelioab_selected_themes'])); if (is_array($selected_themes)) { foreach ($selected_themes as $theme) { if (isset($theme->isSelected) && $theme->isSelected) { $experiment->add_selected_theme($theme->value, $theme->name); } } } } else { $ori = $experiment->get_original(); if ($ori) { $experiment->add_selected_theme($ori->get_value(), $ori->get_name()); } foreach ($experiment->get_alternatives() as $alt) { $experiment->add_selected_theme($alt->get_value(), $alt->get_name()); } } if (isset($_POST['nelioab_appspot_ids'])) { $experiment->set_appspot_ids(json_decode(urldecode($_POST['nelioab_appspot_ids']))); } else { $experiment->set_appspot_ids($experiment->get_appspot_ids()); } // Creating the view $view = $this->create_view(); // Experiment information $view->set_basic_info($experiment->get_id(), $experiment->get_name(), $experiment->get_description(), $experiment->get_finalization_mode(), $experiment->get_finalization_value()); // Experiment alternatives $view->set_selected_themes($experiment->get_selected_themes()); $view->set_appspot_ids($experiment->get_appspot_ids()); $view->set_current_theme($current_theme_id, $current_theme_name, $current_theme->get_screenshot(), $current_theme->offsetGet('Author')); foreach ($themes as $theme) { $id = $theme['Stylesheet']; if ($id == $current_theme_id) { continue; } $view->add_theme($id, $theme->offsetGet('Title'), $theme->get_screenshot(), $theme->offsetGet('Author'), $experiment->is_theme_selected($id)); } // Goals $goals = $experiment->get_goals(); foreach ($goals as $goal) { $view->add_goal($goal->json4js()); } if (count($goals) == 0) { $new_goal = new NelioABAltExpGoal($experiment); $new_goal->set_name(__('Default', 'nelioab')); $view->add_goal($new_goal->json4js()); } return $view; }
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 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); } } }
protected function do_build() { $title = __('Edit Product Summary Experiment', 'nelioab'); // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } // 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; } else { $experiment = new NelioABProductSummaryAlternativeExperiment(-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 page or post // ---------------------------------------------- if (isset($_GET['post-id']) && $_GET['experiment-type'] == NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP) { $experiment->set_original($_GET['post-id']); } // Checking whether there are pages or posts available // --------------------------------------------------- // ...pages... $options_for_posts = array('posts_per_page' => 1, 'post_type' => 'product'); $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) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(__('There are no products available.', 'nelioab'), __('Please, create one and try again.', 'nelioab')); return $view; } // If everything is OK, we keep going! // --------------------------------------------------- // Creating the view $view = $this->create_view(); 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_original_id($experiment->get_originals_id()); $view->set_alternatives($experiment->get_json4js_alternatives()); return $view; }
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; }