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;
 }
Ejemplo n.º 2
0
 /**
  * Returns true if everything is OK. If it isn't, an exception is thrown.
  *
  * @return boolean true if everything is OK. Otherwise, an exception is thrown.
  *
  * @throws Exception `INVALID_MAIL`
  * @throws Exception `INVALID_PRODUCT_REG_NUM`
  * @throws Exception `NON_ACCEPTED_TAC`
  * @throws Exception `BACKEND_NO_SITE_CONFIGURED`
  * @throws Exception `DEACTIVATED_USER`
  *
  * @since 2.1.0
  */
 public static function check_user_settings()
 {
     if (!NelioABAccountSettings::is_email_valid()) {
         $err = NelioABErrCodes::INVALID_MAIL;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::is_reg_num_valid()) {
         $err = NelioABErrCodes::INVALID_PRODUCT_REG_NUM;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::are_terms_and_conditions_accepted()) {
         $err = NelioABErrCodes::NON_ACCEPTED_TAC;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::has_a_configured_site()) {
         $err = NelioABErrCodes::BACKEND_NO_SITE_CONFIGURED;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     NelioABAccountSettings::check_account_status();
     if (!NelioABAccountSettings::is_account_active()) {
         $err = NelioABErrCodes::DEACTIVATED_USER;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     return true;
 }
        protected function do_render()
        {
            echo "<div class='nelio-message'>";
            printf('<img class="animated flipInY" src="%s" alt="%s" />', nelioab_admin_asset_link('/images/settings-icon.png'), __('Information Notice', 'nelioab'));
            $tac_text = '';
            if (NelioABAccountSettings::can_free_trial_be_started()) {
                echo '<h2>' . __('Welcome!', 'nelioab') . '</h2>';
                printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('Thank you very much for installing <strong>Nelio A/B Testing</strong> by <em>Nelio Software</em>. You\'re just one step away from optimizing your WordPress site.', 'nelioab'));
                printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Let\'s get started!', 'nelioab'));
                $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                $my_account_button = $this->make_button(__('Use Nelio Account', 'nelioab'), $account_url, false);
                $free_trial_button = $this->make_button(__('Start Free Trial', 'nelioab'), '#', true);
                $tac_text = sprintf(__('By starting the free trial you agree to be legally bound by these <a href="%s" target="_blank">terms</a>.', 'nelioab'), 'https://nelioabtesting.com/terms-and-conditions/');
            } else {
                if (!NelioABAccountSettings::is_email_valid() || !NelioABAccountSettings::is_reg_num_valid() || !NelioABAccountSettings::are_terms_and_conditions_accepted()) {
                    echo '<h2>' . __('Welcome!', 'nelioab') . '</h2>';
                    printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('Thank you very much for installing <strong>Nelio A/B Testing</strong> by <em>Nelio Software</em>. You\'re just one step away from optimizing your WordPress site.', 'nelioab'));
                    printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Let\'s get started!', 'nelioab'));
                    $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                    $my_account_button = $this->make_button(__('Use Nelio Account', 'nelioab'), $account_url, true);
                    $free_trial_button = '';
                } else {
                    echo '<h2>' . __('Setup', 'nelioab') . '</h2>';
                    printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('You\'re just one step away from optimizing WordPress with <strong style="white-space:nowrap;">Nelio A/B Testing</strong> by <em>Nelio Software</em>. Are you ready?', 'nelioab'));
                    printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Activate this site in your account.', 'nelioab'));
                    $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                    $my_account_button = $this->make_button(__('Open My Account', 'nelioab'), $account_url, true);
                    $free_trial_button = '';
                }
            }
            printf("<p id=\"nelio-cta-buttons\" class=\"nelio-admin-explanation\">%s %s</p>\n", $my_account_button, $free_trial_button);
            if (strlen($tac_text) > 0) {
                echo '<p style="padding-top:3em;font-size:95%;color:gray;">' . $tac_text . '</p>';
            }
            if (NelioABAccountSettings::can_free_trial_be_started()) {
                ?>
				<script type="text/javascript">
				(function($) {
					$('#nelio-cta-buttons .button-primary').click(function() {
						smoothTransitions();
						$.ajax({
							url: ajaxurl,
							data: {
								action: 'nelioab_start_free_trial'
							},
							type: 'post',
							success: function(res) {
								if ( "OK" === res ) {
									window.location = "<?php 
                echo admin_url('admin.php?page=nelioab-account&nabmode=free-trial');
                ?>
";
								} else {
									window.location.reload();
								}
							},
						});
					});
				})(jQuery);
				</script>
				<?php 
            }
            echo '</div>';
        }