Example #1
0
 public function display_settings_page()
 {
     // disconnect Lingotek account
     if (array_key_exists('delete_access_token', $_GET) && $_GET['delete_access_token']) {
         delete_option('lingotek_token');
         delete_option('lingotek_community');
         delete_option('lingotek_defaults');
     }
     // connect Lingotek account
     if (array_key_exists('access_token', $_GET)) {
         // set and get token details
         $client = new Lingotek_API();
         $token_details = $client->get_token_details($_GET['access_token']);
         if ($token_details && strlen($token_details->login_id)) {
             update_option('lingotek_token', array('access_token' => $_GET['access_token'], 'login_id' => $token_details->login_id));
             add_settings_error('lingotek_token', 'account-connection', __('Your Lingotek account has been successfully connected.', 'wp-lingotek'), 'updated');
         } else {
             add_settings_error('lingotek_token', 'account-connection', __('Your Lingotek account was not connected.	The Access Token received was invalid.', 'wp-lingotek'), 'error');
         }
     }
     // set page key primarily used for form submissions
     $page_key = $this->plugin_slug . '_settings';
     if (isset($_GET['sm'])) {
         $page_key .= '&sm=' . $_GET['sm'];
     }
     // set community
     if (!empty($_POST) && key_exists('lingotek_community', $_POST) && strlen($_POST['lingotek_community'])) {
         check_admin_referer($page_key, '_wpnonce_' . $page_key);
         update_option('lingotek_community', $_POST['lingotek_community']);
         add_settings_error('lingotek_community', 'update', __('Your community has been successfully saved.', 'wp-lingotek'), 'updated');
         $this->set_community_resources($_POST['lingotek_community']);
     }
     $community_id = get_option('lingotek_community');
     if (!$community_id) {
         add_settings_error('lingotek_community', 'error', __('Select and save the community that you would like to use.', 'wp-lingotek'), 'error');
     }
     $token_details = self::has_token_details();
     $redirect_url = admin_url('admin.php?page=' . $this->plugin_slug . '_settings&sm=account');
     if ($token_details) {
         $access_token = $token_details['access_token'];
         $login_id = $token_details['login_id'];
         $base_url = get_option('lingotek_base_url');
         include LINGOTEK_ADMIN_INC . '/settings.php';
     } else {
         $connect_url = "";
         // connect cloak redirect
         if (isset($_GET['connect'])) {
             // set sandbox or production (after button clicked)
             if (strcasecmp($_GET['connect'], 'sandbox') == 0) {
                 update_option('lingotek_base_url', Lingotek_API::SANDBOX_URL);
             } else {
                 update_option('lingotek_base_url', Lingotek_API::PRODUCTION_URL);
             }
             $client = new Lingotek_API();
             echo '<div class="wrap"><p class="description">' . __("Redirecting to Lingotek to connect your account...", 'wp-lingotek') . '</p></div>';
             $connect_url = strcasecmp($_GET['connect'], 'new') == 0 ? $client->get_new_url($redirect_url) : $client->get_connect_url($redirect_url);
         }
         $connect_account_cloak_url_new = admin_url('admin.php?page=' . $this->plugin_slug . '_settings&connect=new');
         $connect_account_cloak_url_test = admin_url('admin.php?page=' . $this->plugin_slug . '_settings&connect=sandbox');
         $connect_account_cloak_url_prod = admin_url('admin.php?page=' . $this->plugin_slug . '_settings&connect=production');
         include LINGOTEK_ADMIN_INC . '/settings/connect-account.php';
     }
 }