コード例 #1
0
ファイル: visitor.php プロジェクト: jeremygeltman/ThinkThinly
 /**
  * Adds a headline alternative experiment in self::$headline_exps.
  *
  * @param NelioABHeadlineAlternativeExperiment $exp The Headline Alternative Experiment to be added.
  * @param int $alt_index The index of the alternative that this visitor is supposed to see.
  *
  * @since 4.0.0
  */
 private static function add_headline_exp($exp, $alt_index)
 {
     $alt = $exp->get_original();
     if ($alt_index > 0) {
         --$alt_index;
         $alts = $exp->get_alternatives();
         if ($alt_index < count($alts)) {
             $alt = $alts[$alt_index];
         }
     }
     self::$headline_exps[$exp->get_originals_id()] = array('exp' => $exp, 'alt' => $alt);
 }
 protected function do_build()
 {
     $title = __('Edit Headline 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 NelioABHeadlineAlternativeExperiment(-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::HEADLINE_ALT_EXP) {
         $experiment->set_original($_GET['post-id']);
     }
     // Checking whether there are pages or posts available
     // ---------------------------------------------------
     // ...pages...
     $list_of_pages = get_pages();
     $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 (count($list_of_pages) + count($list_of_posts) == 0) {
         require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php';
         $view = new NelioABMessagePage(__('There are no posts available.', 'nelioab'), __('Please, create one post 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;
 }