示例#1
0
    protected static function submit()
    {
        $id = $_GET['item'];
        $item = Items::get_instance()->get_item($id);
        if (false === $item) {
            throw new Exception(_r('Invalid item ID specified', 'instapaper'));
        }
        $user = get_option('instapaper_user');
        if (empty($user)) {
            throw new Exception(sprintf(_r('Please set your username and password in the <a href="%s">settings</a>.', 'instapaper'), get_option('baseurl') . 'admin/settings.php'));
        }
        if (!check_nonce('instapaper-submit', $_GET['_nonce'])) {
            throw new Exception(_r('Nonces did not match. Try again.', 'instapaper'));
        }
        $data = array('username' => get_option('instapaper_user', ''), 'password' => get_option('instapaper_pass', ''), 'url' => $item->permalink, 'title' => apply_filters('the_title', $item->title));
        $request = new HTTPRequest('', 2);
        $response = $request->post("https://www.instapaper.com/api/add", array(), $data);
        switch ($response->status_code) {
            case 400:
                throw new Exception(_r('Internal error. Please report this.', 'instapaper'));
            case 403:
                throw new Exception(sprintf(_r('Invalid username/password. Please check your details in the <a href="%s">settings</a>.', 'instapaper'), get_option('baseurl') . 'admin/settings.php'));
            case 500:
                throw new Exception(_r('An error occurred when contacting Instapaper. Please try again later.', 'instapaper'));
        }
        Instapaper::page_head();
        ?>
		<div id="message">
			<h1><?php 
        _e('Success!');
        ?>
</h1>
			<p class="sidenote"><?php 
        _e('Closing window in...', 'instapaper');
        ?>
</p>
			<p class="sidenote" id="counter">3</p>
		</div>
		<script>
			$(document).ready(function () {
				setInterval(countdown, 1000);
			});

			function countdown() {
				if(timer > 0) {
					$('#counter').text(timer);
					timer--;
				}
				else {
					self.close();
				}
			}

			var timer = 2;
		</script>
	<?php 
        Instapaper::page_foot();
        die;
    }