/**
     * option page
     * @static
     * @return void
     */
    public static function plugin_options()
    {
        $msg = '';
        $error = '';
        $upyun = new UpYun(array());
        //update options
        if (isset($_POST['submit'])) {
            if (self::update_options()) {
                $msg = __('Options updated.', self::textdomain);
            } else {
                $error = __('Nothing changed.', self::textdomain);
            }
            $credentials = array('api_domain' => trim($_POST['rest_server']), 'bucketname' => trim($_POST['bucketname']), 'username' => trim($_POST['rest_user']), 'password' => !empty($_POST['rest_pwd']) ? trim($_POST['rest_pwd']) : self::decrypt(self::$rest_pwd), 'form_api_secret' => !empty($_POST['form_api_secret']) ? trim($_POST['form_api_secret']) : self::$form_api_secret, 'timeout' => trim($_POST['rest_timeout']), 'ssl' => FALSE);
            if (self::connect_remote_server($credentials)) {
                $msg .= __('Connected and Authenticated successfully.', self::textdomain);
            } else {
                $error_arr = self::raise_connection_error();
                $error .= $error_arr['error'];
            }
        }
        //tools
        if (isset($_GET['hacklog_do'])) {
            global $wpdb;
            switch ($_GET['hacklog_do']) {
                case 'replace_old_post_attach_url':
                    $orig_url = self::$local_baseurl;
                    $new_url = self::$remote_baseurl;
                    $sql = "UPDATE {$wpdb->posts} set post_content=replace(post_content,'{$orig_url}','{$new_url}')";
                    break;
                case 'recovery_post_attach_url':
                    $orig_url = self::$remote_baseurl;
                    $new_url = self::$local_baseurl;
                    $sql = "UPDATE {$wpdb->posts} set post_content=replace(post_content,'{$orig_url}','{$new_url}')";
                    break;
            }
            if (($num_rows = $wpdb->query($sql)) > 0) {
                $msg = sprintf('%d ' . __('posts has been updated.', self::textdomain), $num_rows);
                $msg .= sprintf('%1$s <blockquote><code>%2$s</code></blockquote> ', __('The following SQL statement was executeed:', self::textdomain), $sql);
            } else {
                $error = __('no posts been updated.', self::textdomain);
            }
        }
        ?>
		<div class="wrap">
		<?php 
        screen_icon();
        ?>
			<h2> <?php 
        _e('Hacklog Remote Attachment Upyun Options', self::textdomain);
        ?>
</h2>
			<?php 
        self::show_message($msg, 'm');
        self::show_message($error, 'e');
        ?>
			<form name="form1" method="post"
				  action="<?php 
        echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER));
        ?>
">
				<table width="100%" cellpadding="5" class="form-table">
					<tr valign="top">
						<th scope="row"><label for="rest_server"><?php 
        _e('REST API server', self::textdomain);
        ?>
:</label></th>
						<td>
                        <select id="rest_server" name="rest_server">
                        <?php 
        foreach ($upyun->get_available_api_servers() as $the_server => $server_desc) {
            ?>
                        <option value="<?php 
            echo $the_server;
            ?>
" <?php 
            selected($the_server, self::get_opt('rest_server'), true);
            ?>
>
                            <?php 
            echo $server_desc;
            ?>
                        </option>
                        <?php 
        }
        ?>
                        </select>
                        <span class="description"><?php 
        echo sprintf(__('the IP or domain name of remote file server.', self::textdomain));
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="rest_port"><?php 
        _e('REST API server port', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="rest_port" type="text" class="small-text" size="60" id="rest_port"
								   value="<?php 
        echo self::get_opt('rest_port');
        ?>
"/>
							<span class="description"><?php 
        _e('the listenning port of remote rest server.Generally it is 80.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="bucketname"><?php 
        _e('bucketname', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="bucketname" type="text" class="regular-text" size="60" id="bucketname"
								   value="<?php 
        echo self::get_opt('bucketname');
        ?>
"/>
							<span class="description"><?php 
        _e('the bucketname you want to store your files to.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="rest_user"><?php 
        _e('REST API username', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="rest_user" type="text" class="regular-text" size="60" id="rest_user"
								   value="<?php 
        echo self::get_opt('rest_user');
        ?>
"/>
							<span class="description"><?php 
        _e('the REST API username.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="rest_pwd"><?php 
        _e('REST API password', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="rest_pwd" type="password" class="regular-text" size="60" id="rest_pwd"
								   value=""/>
							<span class="description"><?php 
        _e('the API user \'s password.will not be displayed here since filled and updated.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="form_api_secret"><?php 
        _e('form api secret', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="form_api_secret" type="password" class="regular-text" size="60" id="form_api_secret"
								   value="<?php 
        echo self::get_opt('form_api_secret');
        ?>
"/>
							<span class="description"><?php 
        _e('the form API secret.Be aware that if you want to use the <strong>form API features</strong>,you MUST enable this in your Upyun dashboard.', self::textdomain);
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="form_api_timeout"><?php 
        _e('form API timeout(s)', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="form_api_timeout" type="text" class="small-text" size="30" id="form_api_timeout"
								   value="<?php 
        echo self::get_opt('form_api_timeout');
        ?>
"/>
							<span class="description"><?php 
        _e('form API authorization timeout.the max authorized time (calculated in seconds) when upload file via form API.It depends on your computer\'s network condition.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="form_api_content_max_length"><?php 
        _e('form API content max length(MiB)', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="form_api_content_max_length" type="text" class="small-text" size="30" id="form_api_content_max_length"
								   value="<?php 
        echo self::get_opt('form_api_content_max_length');
        ?>
"/>
							<span class="description"><?php 
        echo sprintf(__('the max file size (calculated in MiB) when upload file via form API.Currently,Upyun \'s limitation is %d MiB', self::textdomain), UpYun::FORM_API_MAX_CONTENT_LENGTH / 1024 / 1024);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="form_api_allowed_ext"><?php 
        _e('form API allowd ext', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="form_api_allowed_ext" type="text" class="regular-text" size="30" id="form_api_allowed_ext"
								   value="<?php 
        echo self::get_opt('form_api_allowed_ext');
        ?>
"/>
							<span class="description"><?php 
        _e('form API allowed file extension.For example: <strong>jpg,jpeg,gif,png,doc,pdf,zip,rar,tar.gz,tar.bz2,7z</strong>', self::textdomain);
        ?>
</span>
						</td>
					</tr>
                    <!-- anti-leech -->

					<tr valign="top">
						<th scope="row"><label for="anti_leech_token"><?php 
        _e('anti leech token key', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="anti_leech_token" type="text" class="regular-text" size="60" id="anti_leech_token"
								   value="<?php 
        echo self::get_opt('anti_leech_token');
        ?>
"/>
							<span class="description"><?php 
        _e('the anti leech token key your set in upyun panel', self::textdomain);
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="anti_leech_timeout"><?php 
        _e('anti leech timeout(s)', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="anti_leech_timeout" type="text" class="small-text" size="30" id="anti_leech_timeout"
								   value="<?php 
        echo self::get_opt('anti_leech_timeout');
        ?>
"/>
							<span class="description"><?php 
        _e('anti leech timeout', self::textdomain);
        ?>
</span>
						</td>
					</tr>


					<tr valign="top">
						<th scope="row"><label for="rest_timeout"><?php 
        _e('rest timeout(s)', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="rest_timeout" type="text" class="small-text" size="30" id="rest_timeout"
								   value="<?php 
        echo self::get_opt('rest_timeout');
        ?>
"/>
							<span class="description"><?php 
        _e('rest connection timeout.', self::textdomain);
        ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row"><label for="remote_baseurl"><?php 
        _e('Remote base URL', self::textdomain);
        ?>
								:</label></th>
						<td>
							<input name="remote_baseurl" type="text" class="regular-text" size="60" id="remote_baseurl"
								   value="<?php 
        echo self::get_opt('remote_baseurl');
        ?>
"/>
							<span class="description"><?php 
        _e('Remote base URL,the URL to your bucket root path.for example: <strong>http://xxx.b0.upaiyun.com</strong>.', self::textdomain);
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="rest_remote_path"><?php 
        _e('rest Remote path', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="rest_remote_path" type="text" class="regular-text" size="60" id="rest_remote_path"
								   value="<?php 
        echo self::get_opt('rest_remote_path');
        ?>
"/>
							<span class="description"><?php 
        _e('the relative path to your bucket main directory.Use "<strong>.</strong>" for rest main(root) directory.You can use sub-directory Like <strong>wp-files</strong>', self::textdomain);
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="http_remote_path"><?php 
        _e('HTTP Remote path', self::textdomain);
        ?>
:</label></th>
						<td>
							<input name="http_remote_path" type="text" class="regular-text" size="60" id="http_remote_path"
								   value="<?php 
        echo self::get_opt('http_remote_path');
        ?>
"/>
							<span class="description"><?php 
        _e('the relative path to your HTTP main directory.Use "<strong>.</strong>" for HTTP main(root) directory.You can use sub-directory Like <strong>wp-files</strong>', self::textdomain);
        ?>
</span>
						</td>
					</tr>
				</table>
				<p class="submit">
					<input type="submit" class="button-primary" name="submit"
						   value="<?php 
        _e('Save Options', self::textdomain);
        ?>
 &raquo;"/>
				</p>
			</form>
		</div>
		<div class="wrap">
			<hr/>
			<h2> <?php 
        _e('Hacklog Remote Attachment UpYun Status', self::textdomain);
        ?>
</h2>

			<p style="color:#999999;font-size:14px;">
		<?php 
        _e('Space used on remote server:', self::textdomain);
        ?>
		<?php 
        if (self::setup_rest()) {
            $total_size = self::$fs->get_bucket_usage();
            if (get_option(self::opt_space) != $total_size) {
                update_option(self::opt_space, $total_size);
            }
            echo self::human_size($total_size);
        } else {
            echo '<span style="color:#FF0000;">';
            _e('Authentication failed OR Failed to connect to remote server!', self::textdomain);
            echo '</span>';
        }
        ?>
			</p>
			<hr/>
			<h2>Tools</h2>

			<p style="color:#f00;font-size:14px;"><strong><?php 
        _e('warning:', self::textdomain);
        ?>
</strong>
		<?php 
        _e("if you haven't moved all your attachments OR dont't know what below means,please <strong>DO NOT</strong> click the link below!", self::textdomain);
        ?>
			</p>

			<h3><?php 
        _e('Move', self::textdomain);
        ?>
</h3>

			<p style="color:#4e9a06;font-size:14px;">
		<?php 
        _e('if you have moved all your attachments to the remote server,then you can click', self::textdomain);
        ?>
				<a onclick="return confirm('<?php 
        _e('Are your sure to do this?Make sure you have backuped your database tables.', self::textdomain);
        ?>
');"
				   href="<?php 
        echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER));
        ?>
&hacklog_do=replace_old_post_attach_url"><strong><?php 
        _e('here', self::textdomain);
        ?>
</strong></a><?php 
        _e(' to update the database.', self::textdomain);
        ?>
			</p>

			<h3><?php 
        _e('Recovery', self::textdomain);
        ?>
</h3>

			<p style="color:#4e9a06;font-size:14px;">
		<?php 
        _e('if you have moved all your attachments from the remote server to local server,then you can click', self::textdomain);
        ?>
				<a onclick="return confirm('<?php 
        _e('Are your sure to do this?Make sure you have backuped your database tables.', self::textdomain);
        ?>
');"
				   href="<?php 
        echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER));
        ?>
&hacklog_do=recovery_post_attach_url"><strong><?php 
        _e('here', self::textdomain);
        ?>
</strong></a><?php 
        _e(' to update the database.', self::textdomain);
        ?>
			</p>
		</div>
		<?php 
    }