public static function load($id)
 {
     $json_data = NelioABBackend::remote_get(NELIOAB_BACKEND_URL . '/exp/post/' . $id);
     $json_data = json_decode($json_data['body']);
     $exp = new NelioABHeadlineAlternativeExperiment($json_data->key->id);
     $exp->set_name($json_data->name);
     if (isset($json_data->description)) {
         $exp->set_description($json_data->description);
     }
     $exp->set_type_using_text($json_data->kind);
     $exp->set_original($json_data->originalPost);
     $exp->set_status($json_data->status);
     $exp->set_finalization_mode($json_data->finalizationMode);
     if (isset($json_data->finalizationModeValue)) {
         $exp->set_finalization_value($json_data->finalizationModeValue);
     }
     $exp->track_heatmaps(false);
     if (isset($json_data->showHeatmap) && $json_data->showHeatmap) {
         $exp->track_heatmaps($json_data->showHeatmap);
     }
     if (isset($json_data->goals)) {
         NelioABExperiment::load_goals_from_json($exp, $json_data->goals);
     }
     $alternatives = array();
     if (isset($json_data->alternatives)) {
         foreach ($json_data->alternatives as $json_alt) {
             $alt = new NelioABHeadlineAlternative($json_alt->key->id);
             $alt->set_name($json_alt->name);
             $alt->set_value(json_decode($json_alt->value, true));
             array_push($alternatives, $alt);
         }
     }
     $exp->set_appspot_alternatives($alternatives);
     return $exp;
 }
コード例 #2
0
 public static function load($id)
 {
     $json_data = NelioABBackend::remote_get(NELIOAB_BACKEND_URL . '/exp/global/' . $id);
     $json_data = json_decode($json_data['body']);
     $exp = new NelioABWidgetAlternativeExperiment($json_data->key->id);
     $exp->set_type_using_text($json_data->kind);
     $exp->set_name($json_data->name);
     if (isset($json_data->description)) {
         $exp->set_description($json_data->description);
     }
     $exp->set_status($json_data->status);
     $exp->set_finalization_mode($json_data->finalizationMode);
     if (isset($json_data->finalizationModeValue)) {
         $exp->set_finalization_value($json_data->finalizationModeValue);
     }
     if (isset($json_data->start)) {
         $exp->set_start_date($json_data->start);
     }
     if (isset($json_data->finalization)) {
         $exp->set_end_date($json_data->finalization);
     }
     if (isset($json_data->goals)) {
         NelioABExperiment::load_goals_from_json($exp, $json_data->goals);
     }
     $alternatives = array();
     if (isset($json_data->alternatives)) {
         foreach ($json_data->alternatives as $json_alt) {
             $alt = new NelioABAlternative($json_alt->key->id);
             $alt->set_name($json_alt->name);
             if (isset($json_alt->content)) {
                 $alt->set_value($json_alt->content->value);
             } else {
                 $alt->set_value('');
             }
             array_push($alternatives, $alt);
         }
     }
     $exp->set_appspot_alternatives($alternatives);
     return $exp;
 }
コード例 #3
0
 /**
  * PHPDOC
  *
  * @return void
  *
  * @since PHPDOC
  */
 public function update_winning_alternative_from_appengine()
 {
     $this->winning_alternative = false;
     try {
         require_once NELIOAB_UTILS_DIR . '/backend.php';
         $json_data = NelioABBackend::remote_get(sprintf(NELIOAB_BACKEND_URL . '/exp/%s/%s/winner', $this->get_exp_kind_url_fragment(), $this->get_id()));
         $json_data = json_decode($json_data['body']);
         if (isset($json_data->winner) && $json_data->winner != 'NO_WINNER') {
             $this->set_winning_alternative_using_id($json_data->winner);
         }
     } catch (Exception $e) {
     }
 }
コード例 #4
0
 /**
  * It cancels the scheduling of an experiment.
  *
  * Once the scheduling has been cancelled, the experiment has to either
  * be started manually or scheduled again. This operation is executed
  * in AppEngine.
  *
  * @return void
  *
  * @since 3.2.0
  */
 public function cancel_scheduling()
 {
     $url = sprintf(NELIOAB_BACKEND_URL . '/exp/%2$s/%1$s/unschedule', $this->get_id(), $this->get_exp_kind_url_fragment());
     NelioABBackend::remote_get($url);
 }
コード例 #5
0
 /**
  * PHPDOC
  *
  * @return NelioABAltExpGoalResult PHPDOC
  *
  * @since PHPDOC
  */
 public function get_results()
 {
     $results = new NelioABAltExpGoalResult();
     /** @var NelioABAlternativeExperiment $experiment */
     $experiment = $this->get_experiment();
     $url = sprintf(NELIOAB_BACKEND_URL . '/goal/alternativeexp/%s/result', $this->get_id());
     $json_data = null;
     $json_data = NelioABBackend::remote_get($url);
     $json_data = json_decode($json_data['body'], true);
     $results->set_total_visitors($json_data['totalVisitors']);
     $results->set_total_conversions($json_data['totalConversions']);
     $results->set_total_conversion_rate($json_data['totalConversionRate']);
     $results->set_visitors_history($json_data['historyVisitors']);
     $results->set_conversions_history($json_data['historyConversions']);
     $results->set_first_update($json_data['firstUpdate']);
     $results->set_last_update($json_data['lastUpdate']);
     $confidence = 0;
     if (isset($json_data['resultStatus'])) {
         $confidence = $json_data['confidenceInResultStatus'];
     }
     $results->set_summary_status(NelioABGTest::get_result_status_from_str($json_data['resultStatus']), $confidence);
     $alt_res = new NelioABAltStats(true);
     // Original
     $alt_res->set_name(__('Original', 'nelioab'));
     $alt_res->set_alt_id($json_data['originalStats']['altId']);
     $alt_res->set_num_of_visitors($json_data['originalStats']['visitors']);
     $alt_res->set_num_of_conversions($json_data['originalStats']['conversions']);
     $alt_res->set_conversion_rate($json_data['originalStats']['conversionRate']);
     if (isset($json_data['originalStats']['historyVisitors'])) {
         $alt_res->set_visitors_history($json_data['originalStats']['historyVisitors']);
     }
     if (isset($json_data['originalStats']['historyConversions'])) {
         $alt_res->set_conversions_history($json_data['originalStats']['historyConversions']);
     }
     $results->add_alternative_results($alt_res);
     if (is_array($json_data['alternativeStats'])) {
         foreach ($json_data['alternativeStats'] as $json_alt) {
             $alt_res = new NelioABAltStats();
             $alternative = null;
             foreach ($experiment->get_alternatives() as $alt) {
                 /** @var NelioABAlternative $alt */
                 if ($alt->get_id() == $json_alt['altId']) {
                     $alternative = $alt;
                 }
             }
             if ($alternative == null) {
                 foreach ($experiment->get_alternatives() as $alt) {
                     if ($alt->applies_to_post_id($json_alt['altId'])) {
                         $alternative = $alt;
                     }
                 }
             }
             if ($alternative == null) {
                 continue;
             }
             $alt_res->set_name($alternative->get_name());
             $alt_res->set_alt_id($json_alt['altId']);
             $alt_res->set_num_of_visitors($json_alt['visitors']);
             $alt_res->set_num_of_conversions($json_alt['conversions']);
             $alt_res->set_conversion_rate($json_alt['conversionRate']);
             $alt_res->set_improvement_factor($json_alt['improvementFactor']);
             if (isset($json_alt['historyVisitors'])) {
                 $alt_res->set_visitors_history($json_alt['historyVisitors']);
             }
             if (isset($json_alt['historyConversions'])) {
                 $alt_res->set_conversions_history($json_alt['historyConversions']);
             }
             $results->add_alternative_results($alt_res);
         }
     }
     if (is_array($json_data['gTests'])) {
         foreach ($json_data['gTests'] as $stats) {
             $g = new NelioABGTest($stats['message'], $experiment->get_originals_id());
             $min_ver = NULL;
             if (isset($stats['minVersion'])) {
                 $min_ver = $stats['minVersion'];
                 $g->set_min($min_ver);
             }
             $max_ver = NULL;
             if (isset($stats['maxVersion'])) {
                 $max_ver = $stats['maxVersion'];
                 $g->set_max($max_ver);
             }
             if (isset($stats['gtest'])) {
                 $g->set_gtest($stats['gtest']);
             }
             if (isset($stats['pvalue'])) {
                 $g->set_pvalue($stats['pvalue']);
             }
             if (isset($stats['certainty'])) {
                 $g->set_certainty($stats['certainty']);
             }
             $g->set_min_name(__('Unknown', 'nelioab'));
             $g->set_max_name(__('Unknown', 'nelioab'));
             $alts = $experiment->get_alternatives();
             for ($i = 0; $i < count($alts); ++$i) {
                 $alt = $alts[$i];
                 $short_name = sprintf(__('Alternative %s', 'nelioab'), $i + 1);
                 if ($alt->get_identifiable_value() == $min_ver || $alt->get_id() == $min_ver) {
                     $g->set_min_name($short_name, $alt->get_name());
                 }
                 if ($alt->get_identifiable_value() == $max_ver || $alt->get_id() == $max_ver) {
                     $g->set_max_name($short_name, $alt->get_name());
                 }
             }
             if ($experiment->get_originals_id() == $min_ver) {
                 $g->set_min_name(__('Original', 'nelioab'));
             }
             if ($experiment->get_originals_id() == $max_ver) {
                 $g->set_max_name(__('Original', 'nelioab'));
             }
             $results->add_gtest($g);
         }
     }
     return $results;
 }
コード例 #6
0
 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'];
 }
 $result = NelioABBackend::remote_get($url);
 $result = json_decode($result['body']);
 $counter = 0;
 if (isset($result->data)) {
     foreach ($result->data as $heatmap) {
         if (isset($heatmap->value)) {
             $value = json_decode($heatmap->value);
             $counter += $value->max;
         }
     }
 }
 if ($counter == 0) {
     if ($exp->get_status() == NelioABExperiment::STATUS_RUNNING) {
         $err = NelioABErrCodes::NO_HEATMAPS_AVAILABLE;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     } else {
コード例 #7
0
 /**
  * Returns the most relevant information of Nelio A/B Testing (to be displayed in the dashboard).
  *
  * @return array {
  *     Most relevant information of Nelio A/B Testing (to be displayed in the dashboard).
  *
  *     @type array $exps  List of running experiments.
  *     @type array $quota Two integers: the amount of `used` quota and the `total` quota available.
  * }
  *
  * @since 3.4.4
  */
 public static function get_dashboard_summary()
 {
     // This function is used in the Dashboard
     require_once NELIOAB_UTILS_DIR . '/backend.php';
     $json_data = NelioABBackend::remote_get(sprintf(NELIOAB_BACKEND_URL . '/site/%s/exp/summary', NelioABAccountSettings::get_site_id()));
     // Including types of experiments...
     require_once NELIOAB_MODELS_DIR . '/summaries/alt-exp-summary.php';
     require_once NELIOAB_MODELS_DIR . '/summaries/heatmap-exp-summary.php';
     $json_data = json_decode($json_data['body']);
     $result = array('exps' => array(), 'quota' => array('regular' => 5000, 'monthly' => 5000, 'extra' => 0));
     if (isset($json_data->quota)) {
         $result['quota']['regular'] = $json_data->quota + $json_data->quotaExtra;
     }
     if (isset($json_data->quotaPerMonth)) {
         $result['quota']['monthly'] = $json_data->quotaPerMonth;
     }
     if ($result['quota']['regular'] > $result['quota']['monthly']) {
         $diff = $result['quota']['regular'] - $result['quota']['monthly'];
         $result['quota']['extra'] += $diff;
         $result['quota']['regular'] = $result['quota']['monthly'];
     }
     if (isset($json_data->items)) {
         foreach ($json_data->items as $item) {
             /** @var NelioABExperimentSummary $exp */
             switch ($item->kind) {
                 case NelioABExperiment::HEATMAP_EXP_STR:
                     $exp = new NelioABHeatmapExpSummary($item->key->id);
                     break;
                 default:
                     $exp = new NelioABAltExpSummary($item->key->id);
             }
             if ($exp) {
                 $exp->load_json4ae($item);
                 array_push($result['exps'], $exp);
             }
         }
     }
     return $result;
 }
コード例 #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
 public static function load($id)
 {
     $json_data = NelioABBackend::remote_get(NELIOAB_BACKEND_URL . '/exp/hm/' . $id);
     $json_data = json_decode($json_data['body']);
     $exp = new NelioABHeatmapExperiment($json_data->key->id);
     $exp->set_type_using_text($json_data->kind);
     $exp->set_name($json_data->name);
     $exp->set_post_id($json_data->post);
     if (isset($json_data->description)) {
         $exp->set_description($json_data->description);
     }
     $exp->set_status($json_data->status);
     $exp->set_finalization_mode($json_data->finalizationMode);
     if (isset($json_data->finalizationModeValue)) {
         $exp->set_finalization_value($json_data->finalizationModeValue);
     }
     if (isset($json_data->goals)) {
         NelioABExperiment::load_goals_from_json($exp, $json_data->goals);
     }
     return $exp;
 }
コード例 #10
0
 public static function generate_html_content()
 {
     require_once NELIOAB_ADMIN_DIR . '/views/account-page.php';
     // Check data against APPENGINE
     $email = NelioABAccountSettings::get_email();
     $reg_num = NelioABAccountSettings::get_reg_num();
     if (NelioABAccountSettings::is_using_free_trial()) {
         $email = '';
         $reg_num = '';
     }
     $sites = array();
     $max_sites = 1;
     try {
         NelioABAccountSettings::check_account_status('now');
     } catch (Exception $e) {
     }
     $current_site_status = NelioABSite::NOT_REGISTERED;
     $error_retrieving_registered_sites = false;
     try {
         $sites_info = NelioABAccountSettings::get_registered_sites_information();
         $max_sites = $sites_info->get_max_sites();
         $sites = $sites_info->get_registered_sites();
         // CHECKING WHETHER WE HAVE INFORMATION ABOUT THIS SITE BEING REGISTERED,
         // EITHER BY ID OR BY URL
         // 1. We check if this user has a registered site whose URL is this site's url
         $registered_site_based_on_url = false;
         foreach ($sites as $site) {
             if ($site->get_url() == get_option('siteurl')) {
                 $registered_site_based_on_url = $site->get_id();
             }
         }
         // 2. We check if the WP installation has a SITE_ID
         // If it does, but it's none of the user's regitered sites,
         // we have a problem, and we'll say the status is INVALID_ID.
         if (NelioABAccountSettings::has_a_configured_site()) {
             $site_id = NelioABAccountSettings::get_site_id();
             $current_site_status = NelioABSite::INVALID_ID;
             foreach ($sites as $site) {
                 if ($site->get_id() == $site_id) {
                     $current_site_status = NelioABSite::ACTIVE;
                 }
             }
         }
         // POSSIBLE RESULTS OF THE PREVIOUS CHECKS:
         // (a) The site is properly registered (== it has a valid ID)
         //if ( NelioABSite::ACTIVE == $current_site_status )
         //	Nothing to do here
         // (b) We have information about an ID that the user, in AE, does not have
         if (NelioABSite::INVALID_ID == $current_site_status) {
             $current_site_status = NelioABSite::NOT_REGISTERED;
             NelioABAccountSettings::fix_registration_info('not-registered');
         }
         // (c) The site is not registered
         if (NelioABSite::NOT_REGISTERED == $current_site_status) {
             if ($registered_site_based_on_url) {
                 $current_site_status = NelioABSite::ACTIVE;
                 NelioABAccountSettings::fix_registration_info('registered', $registered_site_based_on_url);
             }
         }
         // (d) Other scenarios are:
         //   - INACTIVE. We don't care.
         //   - NON_MATCHING_URLS. We no longer use it.
     } catch (Exception $e) {
         $error_retrieving_registered_sites = true;
     }
     // Querying account information
     $user_info = array();
     try {
         $customer_id = NelioABAccountSettings::get_customer_id();
         if (strlen($customer_id) > 0) {
             $url = sprintf(NELIOAB_BACKEND_URL . '/customer/%s', $customer_id);
             $json = NelioABBackend::remote_get($url, true);
             $json = json_decode($json['body']);
             if (isset($user_info['firstname'])) {
                 $user_info['firstname'] = $json->firstname;
             } else {
                 $user_info['firstname'] = '';
             }
             $user_info['subscription_url'] = $json->subscriptionUrl;
             $user_info['subscription_plan'] = $json->subscriptionPlan;
             $user_info['status'] = $json->status;
             $user_info['total_quota'] = intval($json->quotaPerMonth);
             $user_info['quota'] = intval($json->quota + $json->quotaExtra);
         }
         // Agency stuff
         if (isset($json->hasAgency) && $json->hasAgency) {
             $user_info['agency'] = true;
             $user_info['agencyname'] = $json->agencyName;
             $user_info['agencymail'] = $json->agencyEmail;
         } else {
             $user_info['agency'] = false;
             $user_info['agencyname'] = 'Agency Name';
             $user_info['agencymail'] = '*****@*****.**';
         }
     } catch (Exception $e) {
     }
     // Render content
     $title = __('My Account', 'nelioab');
     $view = new NelioABAccountPage($title);
     $view->set_email($email);
     $view->set_email_validity(NelioABAccountSettings::is_email_valid());
     $view->set_reg_num($reg_num);
     $view->set_reg_num_validity(NelioABAccountSettings::is_reg_num_valid());
     $view->set_tac_checked(NelioABAccountSettings::are_terms_and_conditions_accepted());
     $view->set_registered_sites($sites);
     $view->set_max_sites($max_sites);
     $view->set_current_site_status($current_site_status);
     $view->set_user_info($user_info);
     if ($error_retrieving_registered_sites) {
         $view->set_error_retrieving_registered_sites();
     }
     $view->render_content();
     die;
 }
コード例 #11
0
/**
 * Deactivates our plugin.
 *
 * This function is called by the "registed_deactivation_hook". Alternatives
 * are regular pages or posts (draft status) with a special metaoption that
 * is used to hide them from the admin menu. When the plugin is deactivated,
 * no one hides the alternatives... In order to prevent them from appearing,
 * we change their post_type to a fake type.
 *
 * @return void
 *
 * @since PHPDOC
 */
function nelioab_deactivate_plugin()
{
    /** @var wpdb $wpdb */
    global $wpdb;
    require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
    require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php';
    if (isset($_GET['action']) && 'clean-and-deactivate' == $_GET['action']) {
        // Remove all alternative widgets
        NelioABWidgetExpAdminController::clean_all_alternative_widgets();
        // Remove all alternative menus
        NelioABMenuExpAdminController::clean_all_alternative_menus();
        // Remove all alternative pages and posts
        $query = '' . 'DELETE FROM ' . $wpdb->posts . ' WHERE ' . 'id IN (' . 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE ' . 'meta_key = \'_is_nelioab_alternative\' ' . ')';
        $wpdb->query($query);
        // Clean all experiments in AE
        require_once NELIOAB_UTILS_DIR . '/backend.php';
        for ($i = 0; $i < 5; ++$i) {
            try {
                NelioABBackend::remote_get(sprintf(NELIOAB_BACKEND_URL . '/site/%s/clean', NelioABAccountSettings::get_site_id()));
                break;
            } catch (Exception $e) {
            }
        }
        // Remove all Nelio options
        $query = 'DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE \'%nelioab%\'';
        $wpdb->query($query);
        $query = 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE \'%nelioab%\'';
        $wpdb->query($query);
    } else {
        // Hiding alternative posts
        $query = '' . 'UPDATE ' . $wpdb->posts . ' SET post_type = %s WHERE ' . 'id IN (' . 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE ' . 'meta_key = \'_is_nelioab_alternative\' ' . ') AND ' . 'post_type = %s';
        // recover post type names
        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);
        }
        // execute the query
        foreach ($post_types as $post_type) {
            $wpdb->query($wpdb->prepare($query, 'nelioab_alt_' . $post_type, $post_type));
        }
        // Hiding widget alternatives
        NelioABWidgetExpAdminController::backup_alternative_widgets();
        // Hiding menu alternatives
        NelioABMenuExpAdminController::backup_alternative_menus();
    }
}