コード例 #1
0
 /**
  * Returns PHPDOC
  *
  * @param int    $alt_id PHPDOC
  * @param string $name   PHPDOC
  *
  * @return void
  *
  * @since PHPDOC
  */
 public static function update_widget_set_alternative($alt_id, $name)
 {
     $body = array('name' => $name);
     NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $alt_id), $body);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 /**
  * Sanitizes all settings and stores some of them in AppEngine.
  *
  * This function parses the settings recovered from the form in the
  * Settings Page and sanitizes all string values to their appropriate
  * types. Also, it synchronizes some of these settings with AppEngine.
  *
  * @param array $input all settings as recovered from the form in the Settings page.
  *
  * @return array the same value as $input, but with the appropriate types.
  *
  * @since 2.1.0
  */
 public static function sanitize($input)
 {
     $new_input = array();
     if (isset($input['reset_settings']) && 'do_reset' == $input['reset_settings']) {
         return $new_input;
     }
     $new_input['def_conv_value'] = self::DEFAULT_CONVERSION_VALUE;
     if (isset($input['def_conv_value'])) {
         $new_input['def_conv_value'] = sanitize_text_field($input['def_conv_value']);
     }
     $new_input['plugin_available_to'] = self::DEFAULT_PLUGIN_AVAILABLE_TO;
     if (isset($input['plugin_available_to'])) {
         $new_input['plugin_available_to'] = sanitize_text_field($input['plugin_available_to']);
     }
     $new_input['conv_unit'] = self::DEFAULT_CONVERSION_UNIT;
     if (isset($input['conv_unit'])) {
         $new_input['conv_unit'] = sanitize_text_field($input['conv_unit']);
     }
     $new_input['use_colorblind'] = self::DEFAULT_USE_COLORBLIND_PALETTE;
     if (isset($input['use_colorblind'])) {
         $new_input['use_colorblind'] = sanitize_text_field($input['use_colorblind']);
         $new_input['use_colorblind'] = $new_input['use_colorblind'] == '1';
     }
     $new_input['theme_landing_page'] = self::DEFAULT_THEME_LANDING_PAGE;
     if (isset($input['theme_landing_page'])) {
         $new_input['theme_landing_page'] = sanitize_text_field($input['theme_landing_page']);
         $new_input['theme_landing_page'] = $new_input['theme_landing_page'] == '1';
     }
     $new_input['on_blank'] = self::DEFAULT_OUTWARDS_NAVIGATION_BLANK;
     if (isset($input['on_blank'])) {
         $new_input['on_blank'] = sanitize_text_field($input['on_blank']);
         $new_input['on_blank'] = $new_input['on_blank'] == '1';
     }
     $new_input['show_finished_experiments'] = self::DEFAULT_SHOW_FINISHED_EXPERIMENTS;
     if (isset($input['show_finished_experiments'])) {
         $new_input['show_finished_experiments'] = intval($input['show_finished_experiments']);
     }
     $new_input['min_confidence_for_significance'] = self::DEFAULT_CONFIDENCE_FOR_SIGNIFICANCE;
     if (isset($input['min_confidence_for_significance'])) {
         $new_input['min_confidence_for_significance'] = intval($input['min_confidence_for_significance']);
     }
     if (100 == $new_input['min_confidence_for_significance']) {
         $new_input['min_confidence_for_significance'] = 99;
     }
     $new_input['menu_location'] = self::DEFAULT_MENU_LOCATION;
     if (isset($input['menu_location'])) {
         $new_input['menu_location'] = intval($input['menu_location']);
     }
     $new_input['menu_in_admin_bar'] = self::DEFAULT_MENU_IN_ADMIN_BAR;
     if (isset($input['menu_in_admin_bar'])) {
         $new_input['menu_in_admin_bar'] = intval($input['menu_in_admin_bar']) == 1;
     }
     $new_input['headlines_quota_mode'] = self::HEADLINES_QUOTA_MODE_ALWAYS;
     if (isset($input['headlines_quota_mode'])) {
         $new_input['headlines_quota_mode'] = intval($input['headlines_quota_mode']);
     }
     // SYNC SOME SETTINGS WITH GOOGLE APP ENGINE
     try {
         $algorithm = self::ALGORITHM_PURE_RANDOM;
         if (isset($input['algorithm'])) {
             $algorithm = sanitize_text_field($input['algorithm']);
         }
         $make_site_consistent = self::DEFAULT_MAKE_SITE_CONSISTENT;
         if (isset($input['make_site_consistent'])) {
             $make_site_consistent = sanitize_text_field($input['make_site_consistent']);
             $make_site_consistent = $make_site_consistent == '1';
         }
         $expl_ratio = self::DEFAULT_EXPL_RATIO;
         if (isset($input['expl_ratio'])) {
             $expl_ratio = intval($input['expl_ratio']);
         }
         $get_params_visibility = self::DEFAULT_GET_PARAMS_VISIBILITY;
         if (isset($input['get_params_visibility'])) {
             $get_params_visibility = sanitize_text_field($input['get_params_visibility']);
         }
         $hm_tracking_mode = self::DEFAULT_HEATMAP_TRACKING_MODE;
         if (isset($input['hm_tracking_mode'])) {
             $hm_tracking_mode = sanitize_text_field($input['hm_tracking_mode']);
         }
         $user_split = self::DEFAULT_USER_SPLIT;
         if (isset($input['user_split'])) {
             $user_split = sanitize_text_field($input['user_split']);
         }
         $ori_perc = self::DEFAULT_ORIGINAL_PERCENTAGE;
         if (isset($input['ori_perc'])) {
             $ori_perc = intval($input['ori_perc']);
         }
         $perc_of_tested_users = self::DEFAULT_PERCENTAGE_OF_TESTED_USERS;
         if (isset($input['perc_of_tested_users'])) {
             $perc_of_tested_users = intval($input['perc_of_tested_users']);
         }
         $limit = self::get_quota_limit_per_exp();
         if (isset($input['quota_limit_per_exp'])) {
             $limit = intval($input['quota_limit_per_exp']);
         }
         $email = '';
         if (isset($input['notification_email'])) {
             $email = trim($input['notification_email']);
         }
         $notifications = ' ';
         if (isset($input['notify_exp_finalization']) && 'on' == $input['notify_exp_finalization']) {
             $notifications .= self::NOTIFICATION_EXP_FINALIZATION . ' ';
         }
         // Attributes to control if sync was OK
         $new_input['algorithm'] = self::get_algorithm();
         $new_input['make_site_consistent'] = self::make_site_consistent();
         $new_input['expl_ratio'] = self::get_exploitation_percentage();
         $new_input['get_params_visibility'] = self::get_params_visibility();
         $new_input['hm_tracking_mode'] = self::get_heatmap_tracking_mode();
         $new_input['user_split'] = self::get_split_user_mode();
         $new_input['ori_perc'] = self::get_original_percentage();
         $new_input['perc_of_tested_users'] = self::get_percentage_of_tested_users();
         $new_input['quota_limit_per_exp'] = self::get_quota_limit_per_exp();
         $new_input['notification_email'] = self::get_notification_email();
         $new_input['notifications'] = self::get_notifications();
         $new_input['try_algorithm'] = $algorithm;
         $new_input['try_make_site_consistent'] = $make_site_consistent;
         $new_input['try_expl_ratio'] = $expl_ratio;
         $new_input['try_get_params_visibility'] = $get_params_visibility;
         $new_input['try_hm_tracking_mode'] = $hm_tracking_mode;
         $new_input['try_user_split'] = $user_split;
         $new_input['try_ori_perc'] = $ori_perc;
         $new_input['try_perc_of_tested_users'] = $perc_of_tested_users;
         $new_input['try_quota_limit_per_exp'] = $limit;
         $new_input['try_notification_email'] = $email;
         $new_input['try_notifications'] = $notifications;
         // Send data to Google
         $url = sprintf(NELIOAB_BACKEND_URL . '/site/%s/settings', NelioABAccountSettings::get_site_id());
         $object = array('algorithm' => $algorithm, 'consistency' => $make_site_consistent, 'exploitPerc' => $expl_ratio, 'hideParams' => $get_params_visibility, 'hmMode' => $hm_tracking_mode, 'mode' => $user_split, 'partChance' => $perc_of_tested_users, 'oriPrio' => $ori_perc, 'notificationEmail' => $email, 'notifications' => $notifications, 'quotaLimit' => $limit);
         NelioABBackend::remote_post($url, $object);
         $new_input['algorithm'] = $algorithm;
         $new_input['make_site_consistent'] = $make_site_consistent;
         $new_input['expl_ratio'] = $expl_ratio;
         $new_input['get_params_visibility'] = $get_params_visibility;
         $new_input['hm_tracking_mode'] = $hm_tracking_mode;
         $new_input['user_split'] = $user_split;
         $new_input['ori_perc'] = $ori_perc;
         $new_input['perc_of_tested_users'] = $perc_of_tested_users;
         $new_input['quota_limit_per_exp'] = $limit;
         $new_input['notification_email'] = $email;
         $new_input['notifications'] = $notifications;
     } catch (Exception $e) {
     }
     return $new_input;
 }
コード例 #4
0
 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();
 }
コード例 #5
0
 public function stop()
 {
     require_once NELIOAB_UTILS_DIR . '/backend.php';
     $url = sprintf(NELIOAB_BACKEND_URL . '/exp/post/%s/stop', $this->get_id());
     NelioABBackend::remote_post($url);
     $this->set_status(NelioABExperiment::STATUS_FINISHED);
 }
コード例 #6
0
 public function save()
 {
     // 1. UPDATE OR CREATE THE EXPERIMENT
     if ($this->get_id() < 0) {
         $url = sprintf(NELIOAB_BACKEND_URL . '/site/%s/exp/global', NelioABAccountSettings::get_site_id());
     } else {
         $url = sprintf(NELIOAB_BACKEND_URL . '/exp/global/%s/update', $this->get_id());
     }
     if ($this->get_status() != NelioABExperiment::STATUS_PAUSED && $this->get_status() != NelioABExperiment::STATUS_RUNNING && $this->get_status() != NelioABExperiment::STATUS_FINISHED && $this->get_status() != NelioABExperiment::STATUS_TRASH) {
         $this->set_status($this->determine_proper_status());
     }
     $body = array('name' => $this->get_name(), 'description' => $this->get_description(), 'origin' => $this->get_origins(), 'status' => $this->get_status(), 'kind' => $this->get_textual_type(), 'finalizationMode' => $this->get_finalization_mode(), 'finalizationModeValue' => $this->get_finalization_value());
     /** @var array $result */
     $result = NelioABBackend::remote_post($url, $body);
     $exp_id = $this->get_id();
     if ($exp_id < 0) {
         if (is_wp_error($result)) {
             return 0;
         }
         $json = json_decode($result['body']);
         $exp_id = $json->key->id;
         $this->id = $exp_id;
     }
     // 1.1 SAVE GOALS
     // -------------------------------------------------------------------------
     $this->make_goals_persistent();
     return $this->get_id();
 }
コード例 #7
0
 /**
  * It duplicates the experiment in AppEngine and returns the new ID.
  *
  * This function should be extended by concrete subclasses, because, as it
  * is defined in this abstract class, it only duplicates all the the
  * information of the experiment in AppEngine. Any additional data that is
  * stored in WordPress, has to be duplicated by the overwriting methods.
  *
  * @param string $new_name the new name of the duplicated experiment.
  *
  * @return int the ID of the new experiment (if successfully duplicated) or -1 otherwise.
  *
  * @since 3.4.0
  */
 public function duplicate($new_name)
 {
     // If the experiment is not running, or finished, or ready...
     // then it cannot be duplicated
     if ($this->get_status() != NelioABExperiment::STATUS_RUNNING && $this->get_status() != NelioABExperiment::STATUS_FINISHED && $this->get_status() != NelioABExperiment::STATUS_READY) {
         return -1;
     }
     require_once NELIOAB_UTILS_DIR . '/backend.php';
     $url = sprintf(NELIOAB_BACKEND_URL . '/exp/%s/%s/duplicate', $this->get_exp_kind_url_fragment(), $this->get_id());
     $body = array('name' => $new_name);
     $result = NelioABBackend::remote_post($url, $body);
     $result = json_decode($result['body']);
     return $result->id;
 }
コード例 #8
0
 /**
  * PHPDOC
  *
  * @return void
  *
  * @since 4.1.3
  */
 public static function process_free_trial_promo()
 {
     if (!isset($_POST['promo'])) {
         echo 'NO_PROMO_SPECIFIED';
         die;
     }
     $url = sprintf(NELIOAB_BACKEND_URL . '/customer/%s/promo', self::get_customer_id());
     $data = array('promo' => $_POST['promo']);
     switch ($_POST['promo']) {
         case 'basic-info':
             if (!isset($_POST['name']) || !isset($_POST['email'])) {
                 break;
             }
             $value = array('name' => $_POST['name'], 'mail' => $_POST['email']);
             $data['value'] = json_encode($value);
             try {
                 NelioABBackend::remote_post($url, $data);
                 self::complete_promo_action('basic-info');
                 self::update_nelioab_option('free_trial_name', $value['name']);
                 self::update_nelioab_option('free_trial_mail', $value['mail']);
                 echo 'OK';
                 die;
             } catch (Exception $e) {
             }
             break;
         case 'basic-info-check':
             try {
                 $url = sprintf(NELIOAB_BACKEND_URL . '/customer/%s/check', self::get_customer_id());
                 $res = NelioABBackend::remote_get($url);
                 $res = json_decode($res['body']);
                 if (isset($res->confirmed) && 1 == $res->confirmed) {
                     self::complete_promo_action('basic-info-check');
                     echo 'OK';
                     die;
                 }
             } catch (Exception $e) {
             }
             break;
         case 'site-info':
             if (!isset($_POST['type']) || !isset($_POST['sector'])) {
                 break;
             }
             $data['value'] = $_POST['type'] . ',' . $_POST['sector'];
             try {
                 NelioABBackend::remote_post($url, $data);
                 self::complete_promo_action('site-info');
                 echo 'OK';
                 die;
             } catch (Exception $e) {
             }
             break;
         case 'goals':
             if (!isset($_POST['goal']) || !isset($_POST['success'])) {
                 break;
             }
             $value = array('goal' => $_POST['goal'], 'success' => $_POST['success']);
             $data['value'] = json_encode($value);
             try {
                 NelioABBackend::remote_post($url, $data);
                 self::complete_promo_action('goals');
                 echo 'OK';
                 die;
             } catch (Exception $e) {
             }
             break;
         case 'connect':
         case 'tweet':
             try {
                 NelioABBackend::remote_post($url, $data);
                 self::complete_promo_action($_POST['promo']);
                 echo 'OK';
                 die;
             } catch (Exception $e) {
             }
             break;
         case 'recommend':
             if (!isset($_POST['value'])) {
                 break;
             }
             $data['value'] = $_POST['value'];
             try {
                 NelioABBackend::remote_post($url, $data);
                 self::complete_promo_action('recommend');
                 echo 'OK';
                 die;
             } catch (Exception $e) {
             }
             break;
         default:
             echo 'UNKNOWN_PROMO';
             die;
     }
     echo 'FAIL';
     die;
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
ファイル: backend.php プロジェクト: jeremygeltman/ThinkThinly
 /**
  * PHPDOC
  *
  * @param string  $url               PHPDOC
  * @param boolean $skip_status_check PHPDOC
  *
  * @return WP_Error|array The response or WP_Error on failure.
  *
  * @throws Exception with the appropriate error code.
  *
  * @since PHPDOC
  */
 public static function remote_get($url, $skip_status_check = false)
 {
     return NelioABBackend::remote_post($url, array(), $skip_status_check);
 }