Example #1
0
function jd_doTwitterAPIPost($twit, $auth = false, $id = false, $media = false)
{
    if (!wpt_check_oauth($auth)) {
        $error = __('This account is not authorized to post to Twitter.', 'wp-to-twitter');
        wpt_saves_error($id, $auth, $twit, $error, '401', time());
        wpt_set_log('wpt_status_message', $id, $error);
        return true;
    }
    // exit silently if not authorized
    $check = !$auth ? get_option('jd_last_tweet') : get_user_meta($auth, 'wpt_last_tweet', true);
    // get user's last tweet
    // prevent duplicate Tweets
    if ($check == $twit) {
        if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
            wpt_mail("Matched: tweet identical: #{$id}", "{$twit}, {$auth}, {$id}");
            // DEBUG
        }
        $error = __('This tweet is identical to another Tweet recently sent to this account.', 'wp-to-twitter') . ' ' . __('Twitter requires all Tweets to be unique.', 'wp-to-twitter');
        wpt_saves_error($id, $auth, $twit, $error, '403', time());
        wpt_set_log('wpt_status_message', $id, $error);
        return true;
    } else {
        if ($twit == '' || !$twit) {
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail("Tweet check: empty sentence: #{$id}", "{$twit}, {$auth}, {$id}");
                // DEBUG
            }
            $error = __('This tweet was blank and could not be sent to Twitter.', 'wp-tweets-pro');
            wpt_saves_error($id, $auth, $twit, $error, '403', time());
            wpt_set_log('wpt_status_message', $id, $error);
            return true;
        } else {
            // must be designated as media and have a valid attachment
            $attachment = $media ? wpt_post_attachment($id) : false;
            if ($attachment) {
                $meta = wp_get_attachment_metadata($attachment);
                if (!isset($meta['width'], $meta['height'])) {
                    if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                        wpt_mail("Image Data Does not Exist for Attachment #{$attachment}", print_r($args, 1));
                    }
                    $attachment = false;
                }
            }
            // support for HTTP deprecated as of 1/14/2014 -- https://dev.twitter.com/discussions/24239
            $api = $media && $attachment ? "https://api.twitter.com/1.1/statuses/update_with_media.json" : "https://api.twitter.com/1.1/statuses/update.json";
            if (wtt_oauth_test($auth) && ($connection = wtt_oauth_connection($auth))) {
                if ($media && $attachment) {
                    $connection->media($api, array('status' => $twit, 'source' => 'wp-to-twitter', 'include_entities' => 'true', 'id' => $id, 'auth' => $auth));
                } else {
                    $connection->post($api, array('status' => $twit, 'source' => 'wp-to-twitter', 'include_entities' => 'true'));
                }
                $http_code = $connection ? $connection->http_code : 'failed';
            } else {
                if (wtt_oauth_test(false) && ($connection = wtt_oauth_connection(false))) {
                    if ($media) {
                        $connection->media($api, array('status' => $twit, 'source' => 'wp-to-twitter', 'include_entities' => 'true', 'id' => $id, 'auth' => $auth));
                    } else {
                        $connection->post($api, array('status' => $twit, 'source' => 'wp-to-twitter', 'include_entities' => 'true'));
                    }
                    $http_code = $connection ? $connection->http_code : 'failed';
                }
            }
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail('Twitter Connection', print_r($connection, 1));
            }
            if ($connection) {
                if (isset($connection->http_header['x-access-level']) && $connection->http_header['x-access-level'] == 'read') {
                    $supplement = sprintf(__('Your Twitter application does not have read and write permissions. Go to <a href="%s">your Twitter apps</a> to modify these settings.', 'wp-to-twitter'), 'https://dev.twitter.com/apps/');
                } else {
                    $supplement = '';
                }
                $return = false;
                switch ($http_code) {
                    case '200':
                        $return = true;
                        $error = __("200 OK: Success!", 'wp-to-twitter');
                        update_option('wpt_authentication_missing', false);
                        break;
                    case '304':
                        $error = __("304 Not Modified: There was no new data to return", 'wp-to-twitter');
                        break;
                    case '400':
                        $error = __("400 Bad Request: The request was invalid. This is the status code returned during rate limiting.", 'wp-to-twitter');
                        break;
                    case '401':
                        $error = __("401 Unauthorized: Authentication credentials were missing or incorrect.", 'wp-to-twitter');
                        update_option('wpt_authentication_missing', "{$auth}");
                        break;
                    case '403':
                        $error = __("403 Forbidden: The request is understood, but has been refused by Twitter. Possible reasons: too many Tweets, same Tweet submitted twice, Tweet longer than 140 characters.", 'wp-to-twitter');
                        break;
                    case '404':
                        $error = __("404 Not Found: The URI requested is invalid or the resource requested does not exist.", 'wp-to-twitter');
                        break;
                    case '406':
                        $error = __("406 Not Acceptable: Invalid Format Specified.", 'wp-to-twitter');
                        break;
                    case '422':
                        $error = __("422 Unprocessable Entity: The image uploaded could not be processed..", 'wp-to-twitter');
                        break;
                    case '429':
                        $error = __("429 Too Many Requests: You have exceeded your rate limits.", 'wp-to-twitter');
                        break;
                    case '500':
                        $error = __("500 Internal Server Error: Something is broken at Twitter.", 'wp-to-twitter');
                        break;
                    case '502':
                        $error = __("502 Bad Gateway: Twitter is down or being upgraded.", 'wp-to-twitter');
                        break;
                    case '503':
                        $error = __("503 Service Unavailable: The Twitter servers are up, but overloaded with requests - Please try again later.", 'wp-to-twitter');
                        break;
                    case '504':
                        $error = __("504 Gateway Timeout: The Twitter servers are up, but the request couldn't be serviced due to some failure within our stack. Try again later.", 'wp-to-twitter');
                        break;
                    default:
                        $error = __("<strong>Code {$http_code}</strong>: Twitter did not return a recognized response code.", 'wp-to-twitter');
                        break;
                }
                $error .= $supplement != '' ? " {$supplement}" : '';
                // debugging
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("Twitter Response: {$http_code}, #{$id}", "{$http_code}, {$error}");
                    // DEBUG
                }
                // end debugging
                $update = !$auth ? update_option('jd_last_tweet', $twit) : update_user_meta($auth, 'wpt_last_tweet', $twit);
                wpt_saves_error($id, $auth, $twit, $error, $http_code, time());
                if ($http_code == '200') {
                    $jwt = get_post_meta($id, '_jd_wp_twitter', true);
                    if (!is_array($jwt)) {
                        $jwt = array();
                    }
                    $jwt[] = urldecode($twit);
                    if (empty($_POST)) {
                        $_POST = array();
                    }
                    $_POST['_jd_wp_twitter'] = $jwt;
                    update_post_meta($id, '_jd_wp_twitter', $jwt);
                    if (!function_exists('wpt_pro_exists')) {
                        // schedule a one-time promotional box for 4 weeks after first successful Tweet. Experiment...
                        if (get_option('wpt_promotion_scheduled') == false) {
                            wp_schedule_single_event(time() + 60 * 60 * 24 * 7 * 4, 'wpt_schedule_promotion_action');
                            update_option('wpt_promotion_scheduled', 1);
                        }
                    }
                }
                if (!$return) {
                    wpt_set_log('wpt_status_message', $id, $error);
                } else {
                    wpt_set_log('wpt_status_message', $id, __('Tweet sent successfully.', 'wp-to-twitter'));
                }
                return $return;
            } else {
                wpt_set_log('wpt_status_message', $id, __('No Twitter OAuth connection found.', 'wp-to-twitter'));
                return false;
            }
        }
    }
}
Example #2
0
function jd_doTwitterAPIPost($twit, $auth = false)
{
    // prevent duplicate Tweets
    if (!wpt_check_oauth($auth)) {
        return true;
    }
    // exit silently if not authorized
    $check = !$auth ? get_option('jd_last_tweet') : get_user_meta($auth, 'wpt_last_tweet', true);
    // get user's last tweet
    if ($check == $twit || $twit == '' || !$twit) {
        return true;
    } else {
        global $jdwp_api_post_status;
        if (wtt_oauth_test($auth) && ($connection = wtt_oauth_connection($auth))) {
            $connection->post($jdwp_api_post_status, array('status' => $twit, 'source' => 'wp-to-twitter'));
            $http_code = $connection ? $connection->http_code : 'failed';
        } else {
            if (wtt_oauth_test(false) && ($connection = wtt_oauth_connection(false))) {
                $connection->post($jdwp_api_post_status, array('status' => $twit, 'source' => 'wp-to-twitter'));
                $http_code = $connection ? $connection->http_code : 'failed';
            }
        }
        if ($connection) {
            switch ($http_code) {
                case '200':
                    $return = true;
                    $error = __("200 OK: Success!", 'wp-to-twitter');
                    delete_option('wpt_authentication_missing');
                    break;
                case '400':
                    $return = false;
                    $error = __("400 Bad Request: The request was invalid. This is the status code returned during rate limiting.", 'wp-to-twitter');
                    break;
                case '401':
                    $return = false;
                    $error = __("401 Unauthorized: Authentication credentials were missing or incorrect.", 'wp-to-twitter');
                    update_option('wpt_authentication_missing', 'true');
                    break;
                case '403':
                    $return = false;
                    $error = __("403 Forbidden: The request is understood, but it has been refused. This code is used when requests are understood, but are denied by Twitter. Reasons can include: Too many Tweets created in a short time or the same Tweet was submitted twice in a row, among others. This is not an error by WP to Twitter.", 'wp-to-twitter');
                    break;
                case '500':
                    $return = false;
                    $error = __("500 Internal Server Error: Something is broken at Twitter.", 'wp-to-twitter');
                    break;
                case '503':
                    $return = false;
                    $error = __("503 Service Unavailable: The Twitter servers are up, but overloaded with requests - Please try again later.", 'wp-to-twitter');
                    break;
                case '502':
                    $return = false;
                    $error = __("502 Bad Gateway: Twitter is down or being upgraded.", 'wp-to-twitter');
                    break;
                default:
                    $return = false;
                    $error = __("<strong>Code {$http_code}</strong>: Twitter did not return a recognized response code.", 'wp-to-twitter');
                    break;
            }
            // debugging
            //wp_mail('*****@*****.**','Response code',"$http_code $error" );
            // end debugging
            $update = !$auth ? update_option('jd_last_tweet', $twit) : update_user_meta($auth, 'wpt_last_tweet', $twit);
            if (!$return) {
                update_option('jd_status_message', $error);
            } else {
                delete_option('jd_status_message');
            }
            return $return;
        } else {
            update_option('jd_status_message', __('No Twitter OAuth connection found.', 'wp-to-twitter'));
        }
    }
}
Example #3
0
function wtt_connect_oauth($auth = false)
{
    if (!$auth) {
        echo '<div class="ui-sortable meta-box-sortables">';
        echo '<div class="postbox">';
    }
    $class = $auth ? 'wpt-profile' : 'wpt-settings';
    $form = !$auth ? '<form action="" method="post">' : '';
    $nonce = !$auth ? wp_nonce_field('wp-to-twitter-nonce', '_wpnonce', true, false) . wp_referer_field(false) . '</form>' : '';
    if (!wtt_oauth_test($auth, 'verify')) {
        // show notification to authenticate with OAuth. No longer global; settings only.
        if (!wpt_check_oauth()) {
            $admin_url = is_plugin_active('wp-tweets-pro/wpt-pro-functions.php') ? admin_url('admin.php?page=wp-tweets-pro') : admin_url('options-general.php?page=wp-to-twitter/wp-to-twitter.php');
            $message = sprintf(__("Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter'), $admin_url);
            echo "<div class='error'><p>{$message}</p></div>";
        }
        $ack = !$auth ? get_option('app_consumer_key') : get_user_meta($auth, 'app_consumer_key', true);
        $acs = !$auth ? get_option('app_consumer_secret') : get_user_meta($auth, 'app_consumer_secret', true);
        $ot = !$auth ? get_option('oauth_token') : get_user_meta($auth, 'oauth_token', true);
        $ots = !$auth ? get_option('oauth_token_secret') : get_user_meta($auth, 'oauth_token_secret', true);
        $submit = !$auth ? '<p class="submit"><input type="submit" name="submit" class="button-primary" value="' . __('Connect to Twitter', 'wp-to-twitter') . '" /></p>' : '';
        print '
			<h3><span>' . __('Connect to Twitter', 'wp-to-twitter') . '</span></h3>
			<div class="inside ' . $class . '">
			<div class="notes">
			<h4>' . __('WP to Twitter Set-up', 'wp-to-twitter') . '</h4>
			</div>
					<h4>' . __('1. Register this site as an application on ', 'wp-to-twitter') . '<a href="https://apps.twitter.com/app/new/" target="_blank">' . __('Twitter\'s application registration page', 'wp-to-twitter') . '</a></h4>
						<ul>
						<li>' . __('If you\'re not currently logged in to Twitter, log-in to the account you want associated with this site', 'wp-to-twitter') . '</li>
						<li>' . __('Your application name cannot include the word "Twitter."', 'wp-to-twitter') . '</li>
						<li>' . __('Your Application Description can be anything.', 'wp-to-twitter') . '</li>
						<li>' . __('The WebSite and Callback URL should be ', 'wp-to-twitter') . '<strong>' . esc_url(home_url()) . '</strong></li>
						</ul>
					<p><em>' . __('Agree to the Twitter Developer Agreement and continue.', 'wp-to-twitter') . '</em></p>
					<h4>' . __('2. Switch to the "Permissions" tab in Twitter apps', 'wp-to-twitter') . '</h4>
						<ul>
						<li>' . __('Select "Read and Write" for the Application Type', 'wp-to-twitter') . '</li>
						<li>' . __('Update the application settings', 'wp-to-twitter') . '</li>
						</ul>
					<h4>' . __('3. Switch to the Keys and Access Tokens tab and regenerate your consumer key and secret, then create your access token.', 'wp-to-twitter') . '</h4>
						<ul>
						<li>' . __('Copy your API key and API secret from the "Application Settings" section.', 'wp-to-twitter') . '</li>
						<li>' . __('Copy your Access token and Access token secret from the "Your Access Token" section.', 'wp-to-twitter') . '</li>
						</ul>
			' . $form . '
				<fieldset class="options">						
					<div class="tokens">
					<p>
						<label for="wtt_app_consumer_key">' . __('API Key', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_app_consumer_key" id="wtt_app_consumer_key" value="' . esc_attr($ack) . '" />
					</p>
					<p>
						<label for="wtt_app_consumer_secret">' . __('API Secret', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_app_consumer_secret" id="wtt_app_consumer_secret" value="' . esc_attr($acs) . '" />
					</p>
					</div>
					<h4>' . __('4. Copy and paste your Access Token and Access Token Secret into the fields below', 'wp-to-twitter') . '</h4>
					<p>' . __('If the Access Level for your Access Token is not "<em>Read and write</em>", you must return to step 2 and generate a new Access Token.', 'wp-to-twitter') . '</p>
					<div class="tokens">
					<p>
						<label for="wtt_oauth_token">' . __('Access Token', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_oauth_token" id="wtt_oauth_token" value="' . esc_attr($ot) . '" />
					</p>
					<p>
						<label for="wtt_oauth_token_secret">' . __('Access Token Secret', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_oauth_token_secret" id="wtt_oauth_token_secret" value="' . esc_attr($ots) . '" />
					</p>
					</div>
				</fieldset>
				' . $submit . '
				<input type="hidden" name="oauth_settings" value="wtt_oauth_test" class="hidden" style="display: none;" />
				' . $nonce . '
			</div>	
				';
    } else {
        if (wtt_oauth_test($auth)) {
            $ack = !$auth ? esc_attr(get_option('app_consumer_key')) : esc_attr(get_user_meta($auth, 'app_consumer_key', true));
            $acs = !$auth ? esc_attr(get_option('app_consumer_secret')) : esc_attr(get_user_meta($auth, 'app_consumer_secret', true));
            $ot = !$auth ? esc_attr(get_option('oauth_token')) : esc_attr(get_user_meta($auth, 'oauth_token', true));
            $ots = !$auth ? esc_attr(get_option('oauth_token_secret')) : esc_attr(get_user_meta($auth, 'oauth_token_secret', true));
            $uname = !$auth ? esc_attr(get_option('wtt_twitter_username')) : esc_attr(get_user_meta($auth, 'wtt_twitter_username', true));
            $nonce = !$auth ? wp_nonce_field('wp-to-twitter-nonce', '_wpnonce', true, false) . wp_referer_field(false) . '</form>' : '';
            if (!$auth) {
                $submit = '
					<input type="submit" name="submit" class="button-primary" value="' . __('Disconnect your WordPress and Twitter Account', 'wp-to-twitter') . '" />
					<input type="hidden" name="oauth_settings" value="wtt_twitter_disconnect" class="hidden" />
				';
            } else {
                $submit = '<input type="checkbox" name="oauth_settings" value="wtt_twitter_disconnect" id="disconnect" /> <label for="disconnect">' . __('Disconnect your WordPress and Twitter Account', 'wp-to-twitter') . '</label>';
            }
            print '
			<h3><span>' . __('Disconnect from Twitter', 'wp-to-twitter') . '</span></h3>
			<div class="inside ' . $class . '">
			' . $form . '
				<div id="wtt_authentication_display">
					<fieldset class="options">
					<ul>
						<li><strong class="auth_label">' . __('Twitter Username ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $uname . '</code></li>
						<li><strong class="auth_label">' . __('API Key ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ack . '</code></li>
						<li><strong class="auth_label">' . __('API Secret ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $acs . '</code></li>
						<li><strong class="auth_label">' . __('Access Token ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ot . '</code></li>
						<li><strong class="auth_label">' . __('Access Token Secret ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ots . '</code></li>
					</ul>
					</fieldset>
					<div>
					' . $submit . '
					</div>
				</div>		
				' . $nonce . '
			</div>';
        }
    }
    if (!$auth) {
        echo "</div>";
        echo "</div>";
    }
}
Example #4
0
function wtt_connect_oauth($auth = false)
{
    if (!$auth) {
        echo '<div class="ui-sortable meta-box-sortables">';
        echo '<div class="postbox">';
    }
    $server_time = date(DATE_COOKIE);
    $response = wp_remote_get("https://twitter.com/", array('timeout' => 1, 'redirection' => 1));
    if (is_wp_error($response)) {
        $warning = '';
        $error = $response->errors;
        if (is_array($error)) {
            $warning = "<ul>";
            foreach ($error as $k => $e) {
                foreach ($e as $v) {
                    $warning .= "<li>" . $v . "</li>";
                }
            }
            $warning .= "</ul>";
        }
        $ssl = __("Connection Problems? If you're getting an SSL related error, you'll need to contact your host.", 'wp-to-twitter');
        $date = __("There was an error querying Twitter's servers", 'wp-to-twitter');
        $errors = "<p>" . $ssl . "</p>" . $warning;
    } else {
        $date = date(DATE_COOKIE, strtotime($response['headers']['date']));
        $errors = '';
    }
    $class = $auth ? 'wpt-profile' : 'wpt-settings';
    $form = !$auth ? '<form action="" method="post">' : '';
    $nonce = !$auth ? wp_nonce_field('wp-to-twitter-nonce', '_wpnonce', true, false) . wp_referer_field(false) . '</form>' : '';
    if (!wtt_oauth_test($auth, 'verify')) {
        // show notification to authenticate with OAuth. No longer global; settings only.
        if (!wpt_check_oauth()) {
            $admin_url = is_plugin_active('wp-tweets-pro/wpt-pro-functions.php') ? admin_url('admin.php?page=wp-tweets-pro') : admin_url('options-general.php?page=wp-to-twitter/wp-to-twitter.php');
            $message = sprintf(__("Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter'), $admin_url);
            echo "<div class='error'><p>{$message}</p></div>";
        }
        $ack = !$auth ? esc_attr(get_option('app_consumer_key')) : esc_attr(get_user_meta($auth, 'app_consumer_key', true));
        $acs = !$auth ? esc_attr(get_option('app_consumer_secret')) : esc_attr(get_user_meta($auth, 'app_consumer_secret', true));
        $ot = !$auth ? esc_attr(get_option('oauth_token')) : esc_attr(get_user_meta($auth, 'oauth_token', true));
        $ots = !$auth ? esc_attr(get_option('oauth_token_secret')) : esc_attr(get_user_meta($auth, 'oauth_token_secret', true));
        $submit = !$auth ? '<p class="submit"><input type="submit" name="submit" class="button-primary" value="' . __('Connect to Twitter', 'wp-to-twitter') . '" /></p>' : '';
        print '	
			<div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
			<h3 class="hndle"><span>' . __('Connect to Twitter', 'wp-to-twitter') . '</span></h3>
			<div class="inside ' . $class . '">
			<div class="notes">
			<h4>' . __('WP to Twitter Set-up', 'wp-to-twitter') . '</h4>
			<p>' . __('Your server time:', 'wp-to-twitter') . ' <code>' . $server_time . '</code> ' . __("Twitter's time:") . ' <code>' . $date . '</code>. ' . __('If these timestamps are not within 5 minutes of each other, your server will not connect to Twitter.', 'wp-to-twitter') . '</p>
			' . $errors . '
			<p>' . __('Your server timezone (should be UTC,GMT,Europe/London or equivalent):', 'wp-to-twitter') . ' ' . date_default_timezone_get() . '</p>
			</div>
					<h4>' . __('1. Register this site as an application on ', 'wp-to-twitter') . '<a href="http://dev.twitter.com/apps/new" target="_blank">' . __('Twitter\'s application registration page', 'wp-to-twitter') . '</a></h4>
						<ul>
						<li>' . __('If you\'re not currently logged in to Twitter, log-in to the account you want associated with this site', 'wp-to-twitter') . '</li>
						<li>' . __('Your application name cannot include the word "Twitter."', 'wp-to-twitter') . '</li>
						<li>' . __('Your Application Description can be anything.', 'wp-to-twitter') . '</li>
						<li>' . __('The WebSite and Callback URL should be ', 'wp-to-twitter') . '<strong>' . get_bloginfo('url') . '</strong></li>					
						</ul>
					<p><em>' . __('Agree to the Developer Rules of the Road and continue.', 'wp-to-twitter') . '</em></p>
					<h4>' . __('2. Switch to the "Permissions" tab in Twitter apps', 'wp-to-twitter') . '</h4>
						<ul>
						<li>' . __('Select "Read and Write" for the Application Type', 'wp-to-twitter') . '</li>
						<li>' . __('Update the application settings', 'wp-to-twitter') . '</li>
						</ul>
					<h4>' . __('3. Switch to the API Keys tab and regenerate your API keys, then create your access token.', 'wp-to-twitter') . '</h4>
						<ul>
						<li>' . __('Copy your API key and API secret from the top section.', 'wp-to-twitter') . '</li>
						<li>' . __('Copy your Access token and Access token secret from the bottom section.', 'wp-to-twitter') . '</li>
						</ul>
			' . $form . '
				<fieldset class="options">						
					<div class="tokens">
					<p>
						<label for="wtt_app_consumer_key">' . __('API Key', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_app_consumer_key" id="wtt_app_consumer_key" value="' . $ack . '" />
					</p>
					<p>
						<label for="wtt_app_consumer_secret">' . __('API Secret', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_app_consumer_secret" id="wtt_app_consumer_secret" value="' . $acs . '" />
					</p>
					</div>
					<h4>' . __('4. Copy and paste your Access Token and Access Token Secret into the fields below', 'wp-to-twitter') . '</h4>
					<p>' . __('If the Access level for your Access Token is not "<em>Read and write</em>", you must return to step 2 and generate a new Access Token.', 'wp-to-twitter') . '</p>
					<div class="tokens">
					<p>
						<label for="wtt_oauth_token">' . __('Access Token', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_oauth_token" id="wtt_oauth_token" value="' . $ot . '" />
					</p>
					<p>
						<label for="wtt_oauth_token_secret">' . __('Access Token Secret', 'wp-to-twitter') . '</label>
						<input type="text" size="45" name="wtt_oauth_token_secret" id="wtt_oauth_token_secret" value="' . $ots . '" />
					</p>
					</div>
				</fieldset>
				' . $submit . '
				<input type="hidden" name="oauth_settings" value="wtt_oauth_test" class="hidden" style="display: none;" />
				' . $nonce . '
			</div>	
				';
    } else {
        if (wtt_oauth_test($auth)) {
            $ack = !$auth ? esc_attr(get_option('app_consumer_key')) : esc_attr(get_user_meta($auth, 'app_consumer_key', true));
            $acs = !$auth ? esc_attr(get_option('app_consumer_secret')) : esc_attr(get_user_meta($auth, 'app_consumer_secret', true));
            $ot = !$auth ? esc_attr(get_option('oauth_token')) : esc_attr(get_user_meta($auth, 'oauth_token', true));
            $ots = !$auth ? esc_attr(get_option('oauth_token_secret')) : esc_attr(get_user_meta($auth, 'oauth_token_secret', true));
            $uname = !$auth ? esc_attr(get_option('wtt_twitter_username')) : esc_attr(get_user_meta($auth, 'wtt_twitter_username', true));
            $nonce = !$auth ? wp_nonce_field('wp-to-twitter-nonce', '_wpnonce', true, false) . wp_referer_field(false) . '</form>' : '';
            if (!$auth) {
                $submit = '
					<input type="submit" name="submit" class="button-primary" value="' . __('Disconnect Your WordPress and Twitter Account', 'wp-to-twitter') . '" />
					<input type="hidden" name="oauth_settings" value="wtt_twitter_disconnect" class="hidden" />
				';
            } else {
                $submit = '<input type="checkbox" name="oauth_settings" value="wtt_twitter_disconnect" id="disconnect" /> <label for="disconnect">' . __('Disconnect your WordPress and Twitter Account', 'wp-to-twitter') . '</label>';
            }
            $warning = get_option('wpt_authentication_missing') ? '<p>' . __('<strong>Troubleshooting tip:</strong> Connected, but getting a error that your Authentication credentials are missing or incorrect? Check that your Access token has read and write permission. If not, you\'ll need to create a new token. <a href="http://www.joedolson.com/articles/wp-to-twitter/support-2/#q1">Read the FAQ</a>', 'wp-to-twitter') . '</p>' : '';
            if (!is_wp_error($response)) {
                $diff = abs(time() - strtotime($response['headers']['date'])) > 300 ? '<p> ' . __('Your time stamps are more than 5 minutes apart. Your server could lose its connection with Twitter.', 'wp-to-twitter') . '</p>' : '';
            } else {
                $diff = __('WP to Twitter could not contact Twitter\'s remote server. Here is the error triggered: ', 'wp-to-twitter') . $errors;
            }
            print '
			<div class="handlediv"><span class="screen-reader-text">Click to toggle</span></div>
			<h3 class="hndle"><span>' . __('Disconnect from Twitter', 'wp-to-twitter') . '</span></h3>
			<div class="inside ' . $class . '">
			' . $form . '
				<div id="wtt_authentication_display">
					<fieldset class="options">
					<ul>
						<li><strong class="auth_label">' . __('Twitter Username ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $uname . '</code></li>
						<li><strong class="auth_label">' . __('Consumer Key ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ack . '</code></li>
						<li><strong class="auth_label">' . __('Consumer Secret ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $acs . '</code></li>
						<li><strong class="auth_label">' . __('Access Token ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ot . '</code></li>
						<li><strong class="auth_label">' . __('Access Token Secret ', 'wp-to-twitter') . '</strong> <code class="auth_code">' . $ots . '</code></li>
					</ul>
					</fieldset>
					<div>
					' . $submit . '
					</div>
				</div>		
				' . $nonce . '
			<p>' . __('Your server time:', 'wp-to-twitter') . ' <code>' . $server_time . '</code>.<br />' . __('Twitter\'s server time: ', 'wp-to-twitter') . '<code>' . $date . '</code>.</p>
			' . $errors . $diff . '</div>';
            // sent as debugging
            global $wpt_server_string;
            $wpt_server_string = __('Your server time:', 'wp-to-twitter') . ' <code>' . $server_time . '</code>
			' . __('Twitter\'s server time: ', 'wp-to-twitter') . '<code>' . $date . '</code>
			' . $errors . $diff;
        }
    }
    if (!$auth) {
        echo "</div>";
        echo "</div>";
    }
}