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; }
protected function do_build() { $title = __('Edit 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 NelioABCssAlternativeExperiment(-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()); } } } // If everything is OK, we keep going! // --------------------------------------------------- // 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 $alts = $experiment->get_json4js_alternatives(); for ($i = 0; $i < count($alts); ++$i) { $alts[$i]['value'] = urlencode($alts[$i]['value']); } $view->set_alternatives($alts); // 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 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; }
/** * This function checks whether there are any Theme experiments running or * not. If there are, it will add some hooks to WordPress, just to make sure * that the framework used to create the active (original or alternative) * theme is recovering the appropriate information. */ public static function make_compat() { // Let's check if there's a theme experiment running require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_exps = NelioABExperimentsManager::get_running_experiments_from_cache(); $found = false; foreach ($running_exps as $exp) { /** @var NelioABExperiment $exp */ if ($exp->get_type() == NelioABExperiment::THEME_ALT_EXP) { $found = true; } } if (!$found) { return; } // If there's some exp running, let's make sure we're compatible with the framework // used to create it. add_filter('option_optionsframework', array('NelioABThemeCompatibilityLayer', 'fix_optionsframework_compatibility')); }
public function validate() { global $nelioab_admin_controller; $exp = $nelioab_admin_controller->data; $errors = array(); try { if (trim($exp->get_name()) == '') { array_push($errors, array('exp_name', __('Naming an experiment is mandatory. Please, choose a name for the experiment.', 'nelioab'))); } else { $duplicated_name_found = false; foreach (NelioABExperimentsManager::get_experiments() as $aux) { if (!$duplicated_name_found && $exp->get_name() == $aux->get_name() && $exp->get_id() != $aux->get_id()) { array_push($errors, array('exp_name', __('There is another experiment with the same name. Please, choose a new one.', 'nelioab'))); $duplicated_name_found = true; } } } } catch (Exception $e) { $errors = array(array('none', $e->getMessage())); } $nelioab_admin_controller->validation_errors = $errors; return count($nelioab_admin_controller->validation_errors) == 0; }
public static function generate_html_content() { // Obtain DATA from APPSPOT and check its type dynamically $experiment = null; try { $exp_id = -time(); if (isset($_POST['id'])) { $exp_id = $_POST['id']; } $exp_type = -1; if (isset($_POST['exp_type'])) { $exp_type = $_POST['exp_type']; } $experiment = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type); global $nelioab_admin_controller; $nelioab_admin_controller->data = $experiment; } catch (Exception $e) { require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; NelioABErrorController::build($e); } $type = $experiment->get_type(); $controller = NelioABSelectExpProgressPageController::get_controller($type); call_user_func(array($controller, 'generate_html_content')); }
public function start() { // If the experiment is already running, quit if ($this->get_status() == NelioABExperiment::STATUS_RUNNING) { return; } // Checking whether the experiment can be started or not... require_once NELIOAB_UTILS_DIR . '/backend.php'; require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_exps = NelioABExperimentsManager::get_running_experiments_from_cache(); $this_exp_origins = $this->get_origins(); array_push($this_exp_origins, -1); foreach ($running_exps as $running_exp) { /** @var NelioABExperiment $running_exp */ switch ($running_exp->get_type()) { case NelioABExperiment::THEME_ALT_EXP: $err_str = sprintf(__('The experiment cannot be started, because there is a theme experiment running. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); case NelioABExperiment::CSS_ALT_EXP: /** @var NelioABGlobalAlternativeExperiment $running_exp */ foreach ($this_exp_origins as $origin_id) { if (in_array($origin_id, $running_exp->get_origins())) { $err_str = sprintf(__('The experiment cannot be started, because there is a CSS experiment running. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } } break; case NelioABExperiment::WIDGET_ALT_EXP: /** @var NelioABGlobalAlternativeExperiment $running_exp */ foreach ($this_exp_origins as $origin_id) { if (in_array($origin_id, $running_exp->get_origins())) { $err_str = sprintf(__('The experiment cannot be started, because there is a Widget experiment running. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } } break; case NelioABExperiment::MENU_ALT_EXP: /** @var NelioABGlobalAlternativeExperiment $running_exp */ foreach ($this_exp_origins as $origin_id) { if (in_array($origin_id, $running_exp->get_origins())) { $err_str = sprintf(__('The experiment cannot be started, because there is a Menu experiment running. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } } break; case NelioABExperiment::HEATMAP_EXP: if ($this->get_type() != NelioABExperiment::WIDGET_ALT_EXP) { $err_str = __('The experiment cannot be started, because there is one (or more) heatmap experiments running. Please make sure to stop any running heatmap experiment before starting the new one.', 'nelioab'); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } break; } } // If everything is OK, we can start it! $url = sprintf(NELIOAB_BACKEND_URL . '/exp/global/%s/start', $this->get_id()); try { NelioABBackend::remote_post($url); $this->set_status(NelioABExperiment::STATUS_RUNNING); } catch (Exception $e) { throw $e; } }
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); } } }
if ($_GET['exp_type'] == NelioABExperiment::PAGE_ALT_EXP || $_GET['exp_type'] == NelioABExperiment::POST_ALT_EXP) { $show_back_link = true; } } if (isset($_POST['load_from_appengine'])) { try { require_once NELIOAB_UTILS_DIR . '/backend.php'; require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $exp_type = 0; if (!isset($_GET['exp_type']) || !isset($_GET['id'])) { $err = NelioABErrCodes::TOO_FEW_PARAMETERS; throw new Exception(NelioABErrCodes::to_string($err), $err); } // Get the Heatmap $exp_type = $_GET['exp_type']; $exp = NelioABExperimentsManager::get_experiment_by_id($_GET['id'], $exp_type); if ($exp_type == NelioABExperiment::HEATMAP_EXP) { $url = sprintf(NELIOAB_BACKEND_URL . '/exp/hm/%s/result', $exp->get_id()); $post_id = $exp->get_post_id(); global $nelioab_controller; if ($post_id == NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS) { $post_id = false; } } else { if (!isset($_GET['post'])) { $err = NelioABErrCodes::TOO_FEW_PARAMETERS; throw new Exception(NelioABErrCodes::to_string($err), $err); } $url = sprintf(NELIOAB_BACKEND_URL . '/exp/post/%s/hm/%s/result', $exp->get_id(), $_GET['post']); $post_id = $_GET['post']; }
/** * PHPDOC * * @param string $type PHPDOC * @param int $form_id PHPDOC * * @return void * * @since PHPDOC */ private function send_form_action_if_required($type, $form_id) { require_once NELIOAB_MODELS_DIR . '/goals/actions/form-submission-action.php'; require_once NELIOAB_MODELS_DIR . '/goals/actions/action.php'; require_once NELIOAB_UTILS_DIR . '/backend.php'; $kap = NelioABFormSubmissionAction::type_to_kind_and_plugin($type); if (!$kap) { return; } $f = 'nelioab_current_id'; if (!isset($_POST[$f])) { return; } $f = 'nelioab_current_actual_id'; if (!isset($_POST[$f])) { return; } $f = 'nelioab_userid'; if (!isset($_POST[$f]) || strlen(trim($_POST[$f])) === 0) { return; } // Constructing FORM EVENT object: $page = $_POST['nelioab_current_id']; $actual_page = $_POST['nelioab_current_actual_id']; $ev = array('kind' => $kap['kind'], 'form' => $form_id, 'plugin' => $kap['plugin'], 'page' => $page, 'actualPage' => $actual_page, 'user' => $_POST['nelioab_userid']); $the_theme = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::THEME_ALT_EXP); if ($the_theme) { $ev['activeTheme'] = $the_theme->get_id(); } $the_css = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::CSS_ALT_EXP); if ($the_css) { $ev['activeCSS'] = $the_css->get_id(); } $the_widget = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::WIDGET_ALT_EXP); if ($the_widget) { $ev['activeWidget'] = '' . $the_widget->get_id(); } $the_menu = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::MENU_ALT_EXP); if ($the_menu) { $ev['activeMenu'] = $the_menu->get_id(); } // Check if there's one experiment at least with a form submission action, // which corresponds to the given form, then send the event. Otherwise, // get out! require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $send_form_event = false; $running_exps = NelioABExperimentsManager::get_relevant_running_experiments_from_cache(); foreach ($running_exps as $exp) { /** @var NelioABExperiment $exp */ foreach ($exp->get_goals() as $goal) { /** @var NelioABAltExpGoal $goal */ foreach ($goal->get_actions() as $action) { /** @var NelioABFormSubmissionAction $action */ if ($action->get_type() == $type && $action->get_form_id() == $ev['form']) { // If this action uses the form, then we have to check whether // it accepts submissions from anywhere or only from the tested // page. if ($action->accepts_submissions_from_any_page()) { $send_form_event = true; break; } if ($exp->get_originals_id() == $ev['page']) { $send_form_event = true; break; } } } if ($send_form_event) { break; } } if ($send_form_event) { break; } } if (!$send_form_event) { return; } $url = sprintf(NELIOAB_BACKEND_URL . '/site/%s/form', NelioABAccountSettings::get_site_id()); $data = NelioABBackend::build_json_object_with_credentials($ev); $data['timeout'] = 50; for ($attemp = 0; $attemp < 5; ++$attemp) { try { NelioABBackend::remote_post_raw($url, $data); break; } catch (Exception $e) { // If the form submission event could not be sent, it may be that's // because there is no more quota available if ($e->getCode() == NelioABErrCodes::NO_MORE_QUOTA) { // If that was the case, simply leave break; } // If there was another error... we just keep trying (attemp) up to 5 // times. } } }
/** * Activates Nelio A/B Testing * * This function is called by the "registed_activation_hook". It is the * opposite of the nelioab_deactivate_plugin function. Its aim is to make sure * that alternatives (draft post/pages with a metatype) are not visible in the * admin area, but can be editted and used. * * We also make sure that it's called after an update. * * @return void * * @since PHPDOC */ function nelioab_activate_plugin() { /** @var wpdb $wpdb */ global $wpdb; // Old Stuff Compa: rename the meta key that identifies post/page alternatives... $wpdb->update($wpdb->postmeta, array('meta_key' => '_is_nelioab_alternative'), array('meta_key' => 'is_nelioab_alternative')); // We remove all information about "_is_nelioab_alternative" for posts whose // IDs are less than 15. In previous versions of the plugin, Title experiments // marked those posts as alternatives (negative IDs from -1 to -15 were used // and WordPress interpreted them as positive IDs). $query = '' . 'DELETE FROM ' . $wpdb->postmeta . ' WHERE ' . 'post_id < 15 AND meta_key = \'_is_nelioab_alternative\''; $wpdb->query($query); // Showing previous page and post alternatives 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); } $query = 'UPDATE ' . $wpdb->posts . ' SET post_type = %s WHERE post_type = %s'; // execute the query foreach ($post_types as $post_type) { $wpdb->query($wpdb->prepare($query, $post_type, 'nelioab_alt_' . $post_type)); } // Recover previous widget alternatives require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php'; NelioABWidgetExpAdminController::restore_alternative_widget_backup(); // Recover previous menu alternatives require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php'; NelioABMenuExpAdminController::restore_alternative_menu_backup(); // Make sure that the cache uses new classes require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; NelioABExperimentsManager::update_running_experiments_cache('now'); // Save the latest version we use for "(re)activating" the plugin and // show the welcome message $version = get_option('nelioab_last_version_installed', false); update_option('nelioab_last_version_installed', NELIOAB_PLUGIN_VERSION); // Prepare the code for showing the welcome message if (!is_network_admin() && !isset($_GET['activate-multi'])) { if (NELIOAB_PLUGIN_VERSION === $version) { set_transient('_nelioab_welcome_user', 'nelioab-reactivated', 30); } else { if (NELIOAB_PLUGIN_VERSION !== $version) { set_transient('_nelioab_welcome_user', 'nelioab-updated', 30); } else { set_transient('_nelioab_welcome_user', 'nelioab-installed', 30); } } } }
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 function duplicate($new_name) { $id = parent::duplicate($new_name); if (-1 == $id) { return $id; } require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; /** @var NelioABPostAlternativeExperiment $exp */ $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type()); $alts = 0; foreach ($exp->get_alternatives() as $alt) { /** @var NelioABAlternative $alt */ $new_id = $exp->create_alternative_copying_content($alt->get_name(), $alt->get_value()); if ($new_id) { $alt->set_value($new_id); $alt->mark_as_dirty(); ++$alts; } else { $alt->mark_as_removed(); $alt->mark_as_dirty(); } } if (0 == $alts) { $exp->set_status(NelioABExperiment::STATUS_DRAFT); } $exp->save(); return $exp->get_id(); }
public function start() { // Checking whether the experiment can be started or not... require_once NELIOAB_UTILS_DIR . '/backend.php'; require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_exps = NelioABExperimentsManager::get_running_experiments_from_cache(); foreach ($running_exps as $running_exp) { /** @var NelioABGlobalAlternativeExperiment $running_exp */ // $running_exp can actually be anything, but we're focusing // on Global Alternative Experiments only. switch ($running_exp->get_type()) { case NelioABExperiment::THEME_ALT_EXP: $err_str = sprintf(__('The experiment cannot be started, because there is a theme experiment running. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); case NelioABExperiment::CSS_ALT_EXP: if (in_array($this->get_post_id(), $running_exp->get_origins()) || in_array(-1, $running_exp->get_origins())) { $err_str = sprintf(__('The experiment cannot be started, because there is a running CSS experiment that may be changing the appearence of the tested page. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } } } // If everything is OK, we can start it! // If the experiment is already running, quit if ($this->get_status() == NelioABExperiment::STATUS_RUNNING) { return; } require_once NELIOAB_UTILS_DIR . '/backend.php'; $url = sprintf(NELIOAB_BACKEND_URL . '/exp/hm/%s/start', $this->get_id()); NelioABBackend::remote_post($url); $this->set_status(NelioABExperiment::STATUS_RUNNING); }
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; }
/** * PHPDOC * * @param int $order_id PHPDOC * * @return void * * @since PHPDOC */ public function sync_order_completed($order_id) { $order = wc_get_order($order_id); $items = $order->get_items(); $user = get_post_meta($order_id, '_nelioab_userid', true); $env = get_post_meta($order_id, '_nelioab_form_env', true); if (!$user) { return; } require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_experiments = NelioABExperimentsManager::get_running_experiments_from_cache(); // Let's start by selecting the relevant experiments. // A relevant experiment is a running experiment that was in the environment // that was active during the purchase AND that has at least one conversion // action in its goals that tracks an "Order Completed" event. $relevant_experiments = array(); $relevant_conversion_actions = array(); foreach ($env as $id => $alt) { foreach ($running_experiments as $exp) { if ($exp->get_id() != $id) { continue; } foreach ($exp->get_goals() as $goal) { if ($goal->get_kind() != NelioABGoal::ALTERNATIVE_EXPERIMENT_GOAL) { continue; } foreach ($goal->get_actions() as $action) { echo "Considering {$action->get_id()}... "; if ($action->get_type() != NelioABAction::WC_ORDER_COMPLETED) { echo "NO<br>"; continue; } echo "YES<br>"; // Once we've found a Order Complete conversion action, we save: // a) the experiment // b) the product controlled by that conversion action if (!in_array($exp, $relevant_experiments)) { array_push($relevant_experiments, $exp); } array_push($relevant_conversion_actions, $action); } } } } // Now we need to see if products are being tested and, if they are, // the IDs of the concrete alternatives the visitor saw. $relevant_products = array(); foreach ($relevant_experiments as $exp) { if ($exp->get_type() != NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP) { continue; } $alt_num = false; foreach ($env as $id => $alt) { if ($exp->get_id() == $id) { $alt_num = $alt; break; } } if ($alt_num !== false) { if (0 == $alt_num) { // We use "-1" because it's the ID we use for the "original alternative" object // (which doesn't exist in AE). $alt = -1; } else { $alts = $exp->get_alternatives(); if ($alt_num > count($alts)) { continue; } $alt = $alts[$alt_num - 1]; $alt = $alt->get_id(); } $relevant_products[$exp->get_originals_id()] = $alt; break; } } // Once we have the list of PRODUCT_ID => ACTUAL_PRODUCT_ID, we need to // include all the other relevant product IDs: foreach ($relevant_conversion_actions as $action) { $product_id = $action->get_product_id(); if (!isset($relevant_products[$product_id])) { $relevant_products[$product_id] = $product_id; } } // Now we need to get information about the global experiments: $css_alt = false; $menu_alt = false; $theme_alt = false; $widget_alt = false; foreach ($relevant_experiments as $exp) { foreach ($env as $id => $alt_num) { if ($exp->get_id() != $id) { continue; } $alt = false; switch ($exp->get_type()) { case NelioABExperiment::CSS_ALT_EXP: case NelioABExperiment::MENU_ALT_EXP: case NelioABExperiment::THEME_ALT_EXP: case NelioABExperiment::WIDGET_ALT_EXP: if (0 == $alt_num) { $alt = $exp->get_original(); } else { $alts = $exp->get_alternatives(); if ($alt_num > count($alts)) { continue; } $alt = $alts[$alt_num - 1]; } $alt = $alt->get_id(); break; } if ($alt) { switch ($exp->get_type()) { case NelioABExperiment::CSS_ALT_EXP: $css_alt = $alt; break; case NelioABExperiment::MENU_ALT_EXP: $menu_alt = $alt; break; case NelioABExperiment::THEME_ALT_EXP: $theme_alt = $alt; break; case NelioABExperiment::WIDGET_ALT_EXP: $widget_alt = $alt; break; } } } } // Finally, we can create the result object $result = array('products' => array()); foreach ($relevant_products as $product_id => $actual_product_id) { $product_found = false; foreach ($items as $item) { if (isset($item['product_id']) && $item['product_id'] == $product_id) { $product_found = true; break; } } if ($product_found) { array_push($result['products'], $product_id . ':' . $actual_product_id); } } if (count($result['products']) > 0) { $result['kind'] = 'OrderComplete'; $result['products'] = implode(',', $result['products']); $result['user'] = $user; if ($css_alt) { $result['activeCSS'] = $css_alt; } if ($menu_alt) { $result['activeMenu'] = $menu_alt; } if ($theme_alt) { $result['activeTheme'] = $theme_alt; } if ($widget_alt) { $result['activeWidget'] = $widget_alt; } $url = sprintf(NELIOAB_BACKEND_URL . '/site/%s/productevent', NelioABAccountSettings::get_site_id()); $data = NelioABBackend::build_json_object_with_credentials($result); $data['timeout'] = 50; for ($attemp = 0; $attemp < 5; ++$attemp) { try { NelioABBackend::remote_post_raw($url, $data); break; } catch (Exception $e) { // If the form submission event could not be sent, it may be that's // because there is no more quota available if ($e->getCode() == NelioABErrCodes::NO_MORE_QUOTA) { // If that was the case, simply leave break; } // If there was another error... we just keep trying (attemp) up to 5 // times. } } } }
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 function duplicate($new_name) { $id = parent::duplicate($new_name); if (-1 == $id) { return $id; } require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php'; $controller = NelioABMenuExpAdminController::get_instance(); require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; /** @var NelioABMenuAlternativeExperiment $exp */ $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type()); $alts = 0; $controller->begin(); foreach ($exp->get_alternatives() as $alt) { /** @var NelioABAlternative $alt */ $menu_id = $controller->duplicate_menu_and_create_alternative($alt->get_value(), $exp->get_id()); $body = array('value' => $menu_id); try { NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $alt->get_id()), $body); $alts++; } catch (Exception $e) { } } $controller->commit(); if (0 == $alts) { $exp->set_status(NelioABExperiment::STATUS_DRAFT); } $exp->save(); return $exp->get_id(); }
public function start() { // If the experiment is already running, quit if ($this->get_status() == NelioABExperiment::STATUS_RUNNING) { return; } // Checking whether the experiment can be started or not... require_once NELIOAB_UTILS_DIR . '/backend.php'; require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_exps = NelioABExperimentsManager::get_running_experiments_from_cache(); foreach ($running_exps as $running_exp) { /** @var NelioABExperiment $running_exp */ if ($running_exp->get_type() != NelioABExperiment::PAGE_ALT_EXP && $running_exp->get_type() != NelioABExperiment::POST_ALT_EXP && $running_exp->get_type() != NelioABExperiment::CPT_ALT_EXP && $running_exp->get_type() != NelioABExperiment::HEADLINE_ALT_EXP) { continue; } if ($running_exp->get_originals_id() == $this->get_originals_id()) { if ($running_exp->get_type() == NelioABExperiment::PAGE_ALT_EXP) { $err_str = sprintf(__('The experiment cannot be started, because there is another experiment running that is testing the same page. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); } else { if ($running_exp->get_type() == NelioABExperiment::POST_ALT_EXP) { $err_str = sprintf(__('The experiment cannot be started, because there is another experiment running that is testing the same post. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); } else { if ($running_exp->get_type() == NelioABExperiment::CPT_ALT_EXP) { $err_str = sprintf(__('The experiment cannot be started, because there is another experiment running that is testing the same custom post. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); } else { $err_str = sprintf(__('The experiment cannot be started, because there is another experiment that is testing the title of the same page. Please, stop the experiment named «%s» before starting the new one.', 'nelioab'), $running_exp->get_name()); } } } throw new Exception($err_str, NelioABErrCodes::EXPERIMENT_CANNOT_BE_STARTED); } } // If everything is OK, we can start it! // (keep in mind that, if it is a title experiment, we'll create the goal in AE // And there we go! $url = sprintf(NELIOAB_BACKEND_URL . '/exp/post/%s/start', $this->get_id()); try { NelioABBackend::remote_post($url); $this->set_status(NelioABExperiment::STATUS_RUNNING); } catch (Exception $e) { throw $e; } }
public function save() { $exp_id = parent::save(); // 2. UPDATE THE ALTERNATIVES // ------------------------------------------------------------------------- // 2.1 REUSE ALL APPSPOT ALTERNATIVES $i = 0; while ($i < count($this->appspot_ids) && $i < count($this->selected_themes)) { $theme = $this->selected_themes[$i]; $body = array('name' => $theme->name, 'value' => $theme->value); $url = sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $this->appspot_ids[$i]); NelioABBackend::remote_post($url, $body); $i++; } // 2.2 CREATE NEW APPSPOT ALTERNATIVES (IF REQUIRED) while ($i < count($this->selected_themes)) { $theme = $this->selected_themes[$i]; $body = array('name' => $theme->name, 'value' => $theme->value, 'kind' => NelioABExperiment::THEME_ALT_EXP_STR); try { $result = NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/exp/global/%s/alternative', $exp_id), $body); array_push($this->appspot_ids, $result); } catch (Exception $e) { } $i++; } // 2.3 REMOVE UNUSED APPSPOT ALTERNATIVES (IF REQUIRED) $last_valid = $i; while ($i < count($this->appspot_ids)) { $id = $this->appspot_ids[$i]; $url = sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/delete', $id); NelioABBackend::remote_post($url); $i++; } $aux = $this->appspot_ids; $this->appspot_ids = array(); for ($i = 0; $i < $last_valid; ++$i) { array_push($this->appspot_ids, $aux[$i]); } require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; NelioABExperimentsManager::update_experiment($this); }
/** * Initializes the properties of this class. * * This function iterates over all the experiment and assigned alternative * in which this visitor participates and initializes the relevant * properties of the class. In particular, it sets the properties * `$css_info`, `$menu_info,` `$theme_info`, and `$widget_info` for global * experiments and the arrays `$exps` and `$headline_exps`. * * * @param array $env a hashmap of experiments (key) and the alternatives (value) this visitor is supposed to see. * * @since 4.0.0 */ private static function prepareEnvironment($env) { require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; $running_exps = NelioABExperimentsManager::get_running_experiments_from_cache(); self::$ids = array(); self::$css_info = false; self::$menu_info = false; self::$theme_info = false; self::$widget_info = false; self::$exps = array(); self::$headline_exps = array(); self::$wc_product_summary_exps = array(); foreach ($env as $exp_id => $alt) { /** @var NelioABExperiment $aux */ $exp = NULL; foreach ($running_exps as $aux) { if ($aux->get_id() == $exp_id) { $exp = $aux; } } if ($exp) { switch ($exp->get_type()) { case NelioABExperiment::PAGE_ALT_EXP: case NelioABExperiment::POST_ALT_EXP: case NelioABExperiment::CPT_ALT_EXP: /** @var NelioABPostAlternativeExperiment $exp */ self::add_regular_exp($exp, $alt); array_push(self::$ids, $exp->get_id()); break; case NelioABExperiment::HEADLINE_ALT_EXP: /** @var NelioABHeadlineAlternativeExperiment $exp */ self::add_headline_exp($exp, $alt); array_push(self::$ids, $exp->get_id()); break; case NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP: /** @var NelioABHeadlineAlternativeExperiment $exp */ self::add_wc_product_summary_exp($exp, $alt); array_push(self::$ids, $exp->get_id()); break; case NelioABExperiment::CSS_ALT_EXP: case NelioABExperiment::MENU_ALT_EXP: case NelioABExperiment::THEME_ALT_EXP: case NelioABExperiment::WIDGET_ALT_EXP: /** @var NelioABGlobalAlternativeExperiment $exp */ self::add_global_exp($exp, $alt); array_push(self::$ids, $exp->get_id()); break; } } } }
/** * PHPDOC * * @param int $alt_id PHPDOC * @param string $name PHPDOC * @param string $content PHPDOC * * @return void * * @since PHPDOC */ public function update_css_alternative($alt_id, $name, $content) { $body = array('name' => $name, 'content' => $content); NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $alt_id), $body); foreach ($this->get_alternatives() as $alt) { /** @var NelioABAlternative $alt */ if ($alt->get_id() == $alt_id) { $alt->set_name($name); $alt->set_value($content); break; } } require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; NelioABExperimentsManager::update_experiment($this); }
/** * Returns the list of running experiments for which the current user has one alternative assigned. * * @return array the list of running experiments for which the current user has one alternative assigned. * * @see NelioABVisitor::get_experiment_ids_in_request * * @since 4.0.0 */ public static function get_relevant_running_experiments_from_cache() { if (self::$relevant_running_experiments) { return self::$relevant_running_experiments; } $env_ids = NelioABVisitor::get_experiment_ids_in_request(); $running_experiments = self::get_running_experiments_from_cache(); $relevant_running_experiments = array(); foreach ($running_experiments as $exp) { /** @var NelioABExperiment $exp */ $is_relevant = false; for ($i = 0; $i < count($env_ids) && !$is_relevant; ++$i) { if ($exp->get_id() == $env_ids[$i]) { $is_relevant = true; } } if ($is_relevant) { $already_in_array = false; foreach ($relevant_running_experiments as $relevant_exp) { /** @var NelioABExperiment $relevant_exp */ if ($relevant_exp->get_id() == $exp->get_id()) { $already_in_array = true; } } if (!$already_in_array) { array_push($relevant_running_experiments, $exp); } } } if (NelioABVisitor::is_fully_loaded()) { self::$relevant_running_experiments = $relevant_running_experiments; } else { self::$relevant_running_experiments = false; } return $relevant_running_experiments; }
public function duplicate($new_name) { $id = parent::duplicate($new_name); if (-1 == $id) { return $id; } require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php'; require_once NELIOAB_MODELS_DIR . '/experiments-manager.php'; /** @var NelioABMenuAlternativeExperiment $exp */ $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type()); $alts_src = $this->get_alternatives(); $alts_dest = $exp->get_alternatives(); for ($i = 0; $i < count($alts_src); ++$i) { /** @var NelioABAlternative $alt_src */ $alt_src = $alts_src[$i]; /** @var NelioABAlternative $alt_dest */ $alt_dest = $alts_dest[$i]; NelioABWidgetExpAdminController::duplicate_widgets($this->get_id(), $alt_src->get_id(), $exp->get_id(), $alt_dest->get_id()); } return $id; }
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 PAGE vs POST alternatives // ---------------------------------------------- $alt_type = NelioABExperiment::PAGE_ALT_EXP; $title = __('Edit Page Experiment', 'nelioab'); if (isset($_GET['experiment-type']) && $_GET['experiment-type'] == NelioABExperiment::POST_ALT_EXP) { $alt_type = NelioABExperiment::POST_ALT_EXP; $title = __('Edit Post 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 page or post // ---------------------------------------------- if (isset($_GET['post-id']) && $_GET['experiment-type'] == NelioABExperiment::POST_ALT_EXP) { $experiment->set_original($_GET['post-id']); } if (isset($_GET['page-id']) && $_GET['experiment-type'] == NelioABExperiment::PAGE_ALT_EXP) { $experiment->set_original($_GET['page-id']); } // Checking whether there are pages or posts available // --------------------------------------------------- // ...pages... $list_of_pages = get_pages(); if ($alt_type == NelioABExperiment::PAGE_ALT_EXP && count($list_of_pages) == 0) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(sprintf(__('There are no pages available.<br/><br/><a class="button button-primary" href="%s">Create one now.</a>', 'nelioab'), admin_url('/post-new.php?post_type=page'))); return $view; } // ...posts... $options_for_posts = array('posts_per_page' => 1); $list_of_posts = get_posts($options_for_posts); require_once NELIOAB_UTILS_DIR . '/data-manager.php'; NelioABArrays::sort_posts($list_of_posts); if ($alt_type == NelioABExperiment::POST_ALT_EXP && count($list_of_posts) == 0) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(sprintf(__('There are no posts available.<br/><br/><a class="button button-primary" href="%s">Create one now</a>', 'nelioab'), admin_url('/post-new.php'))); 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_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; }