function include_main_account($authors, $post_info)
{
    if (wtt_oauth_test($post_info['authId'], 'verify')) {
        // $authors = array( 14, 'main'=>false ); 	// if you want a specific Author ID
        $authors = array($post_info['authId'], 'main' => false);
        // if you want the author of the post being published
    } else {
        $authors = array('main' => false);
    }
    return $authors;
}
function jd_check_functions()
{
    $message = "<div class='update'><ul>";
    // grab or set necessary variables
    $testurl = get_bloginfo('url');
    $shortener = get_option('jd_shortener');
    $title = urlencode('Your blog home');
    $shrink = jd_shorten_link($testurl, $title, false, 'true');
    $api_url = $jdwp_api_post_status;
    $yourls_URL = "";
    if ($shrink == FALSE) {
        if ($shortener == 1) {
            $error = htmlentities(get_option('wp_supr_error'));
        } else {
            if ($shortener == 2) {
                $error = htmlentities(get_option('wp_bitly_error'));
            } else {
                $error = _('No error information is available for your shortener.', 'wp-to-twitter');
            }
        }
        $message .= __("<li class=\"error\"><strong>WP to Twitter was unable to contact your selected URL shortening service.</strong></li>", 'wp-to-twitter');
        $message .= "<li><code>{$error}</code></li>";
    } else {
        $message .= __("<li><strong>WP to Twitter successfully contacted your selected URL shortening service.</strong>  The following link should point to your blog homepage:", 'wp-to-twitter');
        $message .= " <a href='{$shrink}'>{$shrink}</a></li>";
    }
    //check twitter credentials
    if (wtt_oauth_test()) {
        $rand = rand(1000000, 9999999);
        $testpost = jd_doTwitterAPIPost("This is a test of WP to Twitter. {$shrink} ({$rand})");
        if ($testpost) {
            $message .= __("<li><strong>WP to Twitter successfully submitted a status update to Twitter.</strong></li>", 'wp-to-twitter');
        } else {
            $error = get_option('jd_status_message');
            $message .= __("<li class=\"error\"><strong>WP to Twitter failed to submit an update to Twitter.</strong></li>", 'wp-to-twitter');
            $message .= "<li class=\"error\">{$error}</li>";
        }
    } else {
        $message .= "<strong>" . _e('You have not connected WordPress to Twitter.', 'wp-to-twitter') . "</strong> ";
    }
    // If everything's OK, there's  no reason to do this again.
    if ($testpost == FALSE && $shrink == FALSE) {
        $message .= __("<li class=\"error\"><strong>Your server does not appear to support the required methods for WP to Twitter to function.</strong> You can try it anyway - these tests aren't perfect.</li>", 'wp-to-twitter');
    } else {
    }
    if ($testpost && $shrink) {
        $message .= __("<li><strong>Your server should run WP to Twitter successfully.</strong></li>", 'wp-to-twitter');
    }
    $message .= "</ul>\r\n\t</div>";
    return $message;
}
Example #3
0
function jd_twit($post_ID, $type = 'instant')
{
    if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
        wpt_mail("0: jd_twit running #{$post_ID}", "Post ID: {$post_ID} / {$type}");
        // DEBUG
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || wp_is_post_revision($post_ID)) {
        return $post_ID;
    }
    wpt_check_version();
    $jd_tweet_this = get_post_meta($post_ID, '_jd_tweet_this', true);
    $newpost = $oldpost = $is_inline_edit = false;
    $sentence = $template = '';
    if (get_option('wpt_inline_edits') != 1) {
        if (isset($_POST['_inline_edit']) || isset($_REQUEST['bulk_edit'])) {
            return;
        }
    } else {
        if (isset($_POST['_inline_edit']) || isset($_REQUEST['bulk_edit'])) {
            $is_inline_edit = true;
        }
    }
    if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
        wpt_mail("1: JD Tweet This Value: #{$post_ID}", "Tweet this: {$jd_tweet_this} /" . get_option('jd_tweet_default') . " / {$type}");
        // DEBUG
    }
    if (get_option('jd_tweet_default') == 0) {
        $test = $jd_tweet_this != 'no' ? true : false;
    } else {
        $test = $jd_tweet_this == 'yes' ? true : false;
    }
    if ($test) {
        // test switch: depend on default settings.
        $post_info = jd_post_info($post_ID);
        $media = wpt_post_with_media($post_ID, $post_info);
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
            $auth = get_option('wpt_cotweet_lock') == 'false' || !get_option('wpt_cotweet_lock') ? $post_info['authId'] : get_option('wpt_cotweet_lock');
        } else {
            $auth = $post_info['authId'];
        }
        /* debug data */
        if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
            wpt_mail("2: POST Debug Data #{$post_ID}", "Post_Info: " . print_r($post_info, 1) . "\n\nPOST: " . print_r($_POST, 1) . " / {$type}");
        }
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true && function_exists('wpt_filter_post_info')) {
            $filter = wpt_filter_post_info($post_info);
            if ($filter == true) {
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("3a: Post filtered: #{$post_ID}", print_r($post_info, 1) . " / {$type}");
                }
                return false;
            }
        }
        /* Filter Tweet based on POST data -- allows custom filtering of unknown plug-ins, etc. */
        $filter = apply_filters('wpt_filter_post_data', false, $_POST);
        if ($filter) {
            return false;
        }
        $post_type = $post_info['postType'];
        if ($type == 'future' || get_post_meta($post_ID, 'wpt_publishing') == 'future') {
            $new = 1;
            // if this is a future action, then it should be published regardless of relationship
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail("4: Future post: #{$post_ID}", print_r($post_info, 1) . " / {$type}");
            }
            delete_post_meta($post_ID, 'wpt_publishing');
        } else {
            // if the post modified date and the post date are the same, this is new.
            // true if first date before or equal to last date
            $new = wpt_date_compare($post_info['_postModified'], $post_info['_postDate']);
        }
        // post is not previously published but has been backdated:
        // (post date is edited, but save option is 'publish')
        if ($new == 0 && (isset($_POST['edit_date']) && $_POST['edit_date'] == 1 && !isset($_POST['save']))) {
            $new = 1;
        }
        // can't catch posts that were set to a past date as a draft, then published.
        $post_type_settings = get_option('wpt_post_types');
        $post_types = array_keys($post_type_settings);
        if (in_array($post_type, $post_types)) {
            // identify whether limited by category/taxonomy
            $continue = wpt_category_limit($post_type, $post_info, $post_ID);
            if ($continue == false) {
                return;
            }
            // create Tweet and ID whether current action is edit or new
            $cT = get_post_meta($post_ID, '_jd_twitter', true);
            if (isset($_POST['_jd_twitter']) && $_POST['_jd_twitter'] != '') {
                $cT = $_POST['_jd_twitter'];
            }
            $customTweet = $cT != '' ? stripcslashes(trim($cT)) : '';
            // if ops is set and equals 'publish', this is being edited. Otherwise, it's a new post.
            if ($new == 0 || $is_inline_edit == true) {
                // if this is an old post and editing updates are enabled
                if (get_option('jd_tweet_default_edit') == 1) {
                    $jd_tweet_this = apply_filters('wpt_tweet_this_edit', $jd_tweet_this, $_POST);
                    if ($jd_tweet_this != 'yes') {
                        if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                            wpt_mail("3c: Tweet this: not equal to yes", "Exit // Post ID: {$post_ID}");
                            // DEBUG
                        }
                        return;
                    }
                }
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("4a: Edited post #{$post_ID}", "Tweet this: " . print_r($post_info, 1) . " / {$type}");
                    // DEBUG
                }
                if ($post_type_settings[$post_type]['post-edited-update'] == '1') {
                    $nptext = stripcslashes($post_type_settings[$post_type]['post-edited-text']);
                    $oldpost = true;
                }
            } else {
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("4b: New Post #{$post_ID}", "Tweet this: " . print_r($post_info, 1) . " / {$type}");
                    // DEBUG
                }
                if ($post_type_settings[$post_type]['post-published-update'] == '1') {
                    $nptext = stripcslashes($post_type_settings[$post_type]['post-published-text']);
                    $newpost = true;
                }
            }
            if ($newpost || $oldpost) {
                $template = $customTweet != "" ? $customTweet : $nptext;
                $sentence = jd_truncate_tweet($template, $post_info, $post_ID);
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("5: Tweet Truncated #{$post_ID}", "Truncated Tweet: {$sentence} / {$template} / {$type}");
                    // DEBUG
                }
                if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                    $sentence2 = jd_truncate_tweet($template, $post_info, $post_ID, false, $auth);
                }
            }
            if ($sentence != '') {
                // WPT PRO //
                if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                    $wpt_selected_users = $post_info['wpt_authorized_users'];
                    /* set up basic author/main account values */
                    $auth_verified = wtt_oauth_test($auth, 'verify');
                    if (empty($wpt_selected_users) && get_option('jd_individual_twitter_users') == 1) {
                        $wpt_selected_users = $auth_verified ? array($auth) : array(false);
                    }
                    if ($post_info['wpt_cotweet'] == 1 || get_option('jd_individual_twitter_users') != 1) {
                        $wpt_selected_users['main'] = false;
                    }
                    // filter selected users before using
                    $wpt_selected_users = apply_filters('wpt_filter_users', $wpt_selected_users, $post_info);
                    if ($post_info['wpt_delay_tweet'] == 0 || $post_info['wpt_delay_tweet'] == '' || $post_info['wpt_no_delay'] == 'on') {
                        foreach ($wpt_selected_users as $acct) {
                            if (wtt_oauth_test($acct, 'verify')) {
                                $tweet = jd_doTwitterAPIPost($sentence2, $acct, $post_ID, $media);
                            }
                        }
                    } else {
                        foreach ($wpt_selected_users as $acct) {
                            if ($auth != $acct) {
                                $offset = rand(60, 480);
                                // offset by 1-8 minutes for additional users
                            } else {
                                $offset = 0;
                            }
                            if (wtt_oauth_test($acct, 'verify')) {
                                $time = apply_filters('wpt_schedule_delay', (int) $post_info['wpt_delay_tweet'] * 60, $acct);
                                $scheduled = wp_schedule_single_event(time() + $time + $offset, 'wpt_schedule_tweet_action', array('id' => $acct, 'sentence' => $sentence, 'rt' => 0, 'post_id' => $post_ID));
                                $tweet = true;
                                // if scheduled, return true.
                                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                                    if ($acct) {
                                        $author_id = "#{$acct}";
                                    } else {
                                        $author_id = 'Main';
                                    }
                                    wpt_mail("7a: Tweet Scheduled for Auth ID {$author_id} #{$post_ID}", print_r(array('id' => $acct, 'sentence' => $sentence, 'rt' => 0, 'post_id' => $post_ID, 'timestamp' => time() + $time + $offset, 'current_time' => time(), 'timezone' => get_option('gmt_offset'), 'scheduled' => $scheduled, 'timestamp_string' => date('Y-m-d H:i:s', time() + $time + $offset), 'current_time_string' => date('Y-m-d H:i:s', time())), 1));
                                    // DEBUG
                                }
                            }
                        }
                    }
                    /* This cycle handles scheduling the automatic retweets */
                    if ($post_info['wpt_retweet_after'] != 0 && $post_info['wpt_no_repost'] != 'on') {
                        $repeat = $post_info['wpt_retweet_repeat'];
                        $first = true;
                        foreach ($wpt_selected_users as $acct) {
                            if (wtt_oauth_test($acct, 'verify')) {
                                for ($i = 1; $i <= $repeat; $i++) {
                                    switch ($i) {
                                        case 1:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt');
                                            break;
                                        case 2:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt2');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt2');
                                            break;
                                        case 3:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt3');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt3');
                                            break;
                                    }
                                    if (get_option('wpt_custom_type') == 'template') {
                                        $retweet = jd_truncate_tweet(trim($prepend . $append), $post_info, $post_ID, true, $acct);
                                    } else {
                                        $retweet = jd_truncate_tweet(trim($prepend . $template . $append), $post_info, $post_ID, true, $acct);
                                    }
                                    // add original delay to schedule
                                    $delay = isset($post_info['wpt_delay_tweet']) ? (int) $post_info['wpt_delay_tweet'] * 60 : 0;
                                    /* Don't delay the first Tweet of the group */
                                    $offset = $first == true ? 0 : rand(60, 240);
                                    // delay each co-tweet by 1-4 minutes
                                    $time = apply_filters('wpt_schedule_retweet', $post_info['wpt_retweet_after'] * (60 * 60) * $i, $acct, $i, $post_info);
                                    wp_schedule_single_event(time() + $time + $offset + $delay, 'wpt_schedule_tweet_action', array('id' => $acct, 'sentence' => $retweet, 'rt' => $i, 'post_id' => $post_ID));
                                    $tweet = true;
                                    if ($i == 4) {
                                        break;
                                    }
                                }
                            }
                            $first = false;
                        }
                    }
                } else {
                    $tweet = jd_doTwitterAPIPost($sentence, false, $post_ID, $media);
                }
                // END WPT PRO //
                if ($tweet == false) {
                    update_option('wp_twitter_failure', '1');
                }
            }
        } else {
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail("3c: Not a Tweeted post type #{$post_ID}", "Post_Info: " . print_r($post_info, 1) . " / {$type}");
            }
            return $post_ID;
        }
    }
    return $post_ID;
}
/**
 * Get list of users authorized to post to Twitter
 */
function wpt_authorized_users($selected = array())
{
    $override = apply_filters('wpt_override_author_selection', false);
    if ($override) {
        return $override;
    }
    global $user_ID;
    $users = get_option('wpt_authorized_users');
    if (!$users) {
        $args = array('meta_query' => array(array('key' => 'wtt_twitter_username', 'compare' => 'EXISTS')));
        // get all authorized users
        $users = get_users($args);
        $authorized_users = array();
        if (is_array($users)) {
            foreach ($users as $this_user) {
                if (wtt_oauth_test($this_user->ID, 'verify')) {
                    $twitter = get_user_meta($this_user->ID, 'wtt_twitter_username', true);
                    $authorized_users[] = array('ID' => $this_user->ID, 'name' => $this_user->display_name, 'twitter' => $twitter);
                }
            }
        }
        update_option('wpt_authorized_users', $authorized_users);
        $users = $authorized_users;
    }
    $main_account = get_option('wtt_twitter_username');
    $select = "<p class='wpt_auth_users'><label for='wpt_authorized_users'>" . __('Tweet to:', 'wp-tweets-pro') . "</label><br /><select multiple='multiple' name='_wpt_authorized_users[]' id='wpt_authorized_users'>\n\t\t<option value='main'>(" . __('Site account', 'wp-tweets-pro') . ") {$main_account}</option>";
    if (!empty($users)) {
        foreach ($users as $user) {
            $current = $user_ID;
            $active = '';
            // if this has been directly pulled, these are objects. Otherwise, arrays.
            if (is_object($user)) {
                $id = $user->ID;
                $name = $user->display_name;
                $twitter = get_user_meta($id, 'wtt_twitter_username', true);
            } else {
                $id = $user['ID'];
                $name = $user['name'];
                $twitter = $user['twitter'];
            }
            global $post;
            if ($id == $current && $current == $post->post_author || in_array($id, $selected)) {
                $active = " selected='selected'";
            }
            $select .= " <option value='{$id}'{$active}>{$name} (@{$twitter})</option>\n";
        }
    }
    $select .= "</select></p>";
    return $select;
}
Example #5
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 #6
0
function jd_twit($post_ID)
{
    wpt_check_version();
    $jd_tweet_this = get_post_meta($post_ID, '_jd_tweet_this', true);
    $newpost = $oldpost = $is_inline_edit = false;
    if (get_option('wpt_inline_edits') != 1) {
        if (isset($_POST['_inline_edit'])) {
            return;
        }
    } else {
        if (isset($_POST['_inline_edit'])) {
            $is_inline_edit = true;
        }
    }
    if ($jd_tweet_this != "no") {
        $post_info = jd_post_info($post_ID);
        /* debug data
        		wp_mail('*****@*****.**','Debug Data 1',print_r($post_info,1) );
        		wp_mail('*****@*****.**','Debug Data 2',print_r($_POST,1) );
        		// custom for Jason Ashmore -- but shouldn't hurt anybody else */
        if ($post_info['postTitle'] == '' || strpos($post_info['postTitle'], 'Untitled') === 0) {
            return;
        }
        $post_type = $post_info['postType'];
        // if the post modified date and the post date are the same, this is new.
        $new = wpt_date_compare($post_info['_postModified'], $post_info['_postDate']);
        // if this post is not previously published but has been backdated: lit. if post date is edited, but save option is 'publish'
        if ($new == 0 && (isset($_POST['edit_date']) && $_POST['edit_date'] == 1 && !isset($_POST['save']))) {
            $new = 1;
        }
        // post modified = updated? // postdate == published? therefore: posts which have been updated after creation (scheduled, updated in draft) may not turn up as new. // postStatus == future
        $post_type_settings = get_option('wpt_post_types');
        $post_types = array_keys($post_type_settings);
        if (in_array($post_type, $post_types)) {
            $sentence = '';
            $cT = get_post_meta($post_ID, '_jd_twitter', true);
            if (isset($_POST['_jd_twitter']) && $_POST['_jd_twitter'] != '') {
                $cT = $_POST['_jd_twitter'];
            }
            $customTweet = $cT != '' ? stripcslashes(trim($cT)) : '';
            // excluded post statuses that should never be tweeted
            if ($post_info['postStatus'] != 'draft' && $post_info['postStatus'] != 'auto-draft' && $post_info['postStatus'] != 'private' && $post_info['postStatus'] != 'inherit' && $post_info['postStatus'] != 'trash') {
                // && $post_info['postStatus'] != 'pending'
                // if ops is set and equals 'publish', this is being edited. Otherwise, it's a new post.
                if ($new == 0 && $post_info['postStatus'] != 'future' || $is_inline_edit == true) {
                    // if this is an old post and editing updates are enabled
                    if ($post_type_settings[$post_type]['post-edited-update'] == '1') {
                        $nptext = stripcslashes($post_type_settings[$post_type]['post-edited-text']);
                        $oldpost = true;
                    }
                } else {
                    if ($post_type_settings[$post_type]['post-published-update'] == '1') {
                        $nptext = stripcslashes($post_type_settings[$post_type]['post-published-text']);
                        $newpost = true;
                    }
                }
            }
            if ($newpost || $oldpost) {
                $sentence = $customTweet != "" ? $customTweet : $nptext;
                if ($post_info['shortUrl'] != '') {
                    $shrink = $post_info['shortUrl'];
                } else {
                    $shrink = jd_shorten_link($post_info['postLink'], $post_info['postTitle'], $post_ID);
                    store_url($post_ID, $shrink);
                }
                $sentence = jd_truncate_tweet($sentence, $post_info, $shrink, $post_ID);
                /* vestigial qtrans support
                			$regex="/<!--:[a-z]+-->(.*)<!--:-->/U";
                			//Return all the languages in the posttitle 
                			preg_match_all($regex,$jd_post_info['postTitle'],$matches,PREG_PATTERN_ORDER);
                			*/
            }
            if ($sentence != '') {
                if (get_option('jd_twit_cats') == '1') {
                    $continue = !in_allowed_category($post_info['categoryIds']) ? true : false;
                } else {
                    $continue = in_allowed_category($post_info['categoryIds']) ? true : false;
                }
                if (get_option('limit_categories') == '0') {
                    $continue = true;
                }
                if ($continue) {
                    // WPT PRO //
                    if (function_exists('wpt_pro_exists')) {
                        $auth = $post_info['authId'];
                        $user = get_userdata($auth);
                        $auth_verified = wtt_oauth_test($auth, 'verify');
                        if ($post_info['wpt_delay_tweet'] == 0 || $post_info['wpt_no_delay'] == 'on') {
                            $sendToTwitter = jd_doTwitterAPIPost($sentence, $auth);
                            if ($post_info['wpt_cotweet'] == 1 && $auth_verified) {
                                $offset = rand(60, 240);
                                // delay co-tweet by 1-4 minutes.
                                wp_schedule_single_event(time() + $offset, 'wpt_schedule_tweet_action', array('id' => false, 'sentence' => $sentence, 'rt' => 0));
                            }
                        } else {
                            $time = (int) $post_info['wpt_delay_tweet'] * 60;
                            wp_schedule_single_event(time() + $time, 'wpt_schedule_tweet_action', array('id' => $auth, 'sentence' => $sentence, 'rt' => 0));
                            if ($post_info['wpt_cotweet'] == 1 && $auth_verified) {
                                $offset = rand(60, 240);
                                // delay co-tweet by 1-4 minutes.
                                wp_schedule_single_event(time() + $time + $offset, 'wpt_schedule_tweet_action', array('id' => false, 'sentence' => $sentence, 'rt' => 0));
                            }
                            $sendToTwitter = true;
                        }
                        if ($post_info['wpt_retweet_after'] != 0 && $post_info['wpt_no_repost'] != 'on') {
                            $repeat = $post_info['wpt_retweet_repeat'];
                            for ($i = 1; $i <= $repeat; $i++) {
                                if ($i == 1) {
                                    $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt');
                                    $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt');
                                    $retweet = jd_truncate_tweet(trim($prepend . $sentence . $append), $post_info, $shrink, $post_ID, true);
                                }
                                if ($i == 2) {
                                    $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt2');
                                    $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt2');
                                    $retweet = jd_truncate_tweet(trim($prepend . $sentence . $append), $post_info, $shrink, $post_ID, true);
                                }
                                if ($i == 3) {
                                    $retweet = $sentence;
                                }
                                if ($i == 4) {
                                    $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt');
                                    $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt');
                                    $retweet = jd_truncate_tweet(trim($prepend . $sentence . $append), $post_info, $shrink, $post_ID, true);
                                }
                                $time = $post_info['wpt_retweet_after'] * (60 * 60) * $i;
                                wp_schedule_single_event(time() + $time, 'wpt_schedule_tweet_action', array('id' => $auth, 'sentence' => $retweet, 'rt' => $i));
                                if ($post_info['wpt_cotweet'] == 1 && $auth_verified) {
                                    $offset = rand(60, 240);
                                    // delay each co-tweet by 1-4 minutes
                                    wp_schedule_single_event(time() + $time + $offset, 'wpt_schedule_tweet_action', array('id' => false, 'sentence' => $retweet, 'rt' => $i));
                                }
                                $sendToTwitter = true;
                                if ($i == 4) {
                                    break;
                                }
                            }
                        }
                    } else {
                        $sendToTwitter = jd_doTwitterAPIPost($sentence);
                    }
                    // END WPT PRO //
                    $jwt = get_post_meta($post_ID, '_jd_wp_twitter', true);
                    if (!is_array($jwt)) {
                        $jwt = array();
                    }
                    $jwt[] = urldecode($sentence);
                    $_POST['_jd_wp_twitter'] = $jwt;
                    update_post_meta($post_ID, '_jd_wp_twitter', $jwt);
                    if ($sendToTwitter == false) {
                        update_option('wp_twitter_failure', '1');
                    }
                }
            }
        } else {
            return $post_ID;
        }
    }
    return $post_ID;
}
Example #7
0
/**
 * Handle Tweets sent via Ajax Tweet Now/Schedule Tweet buttons.
 *
 * @return string Confirmation message indicating success or failure of Tweeting.
 */
function wpt_ajax_tweet()
{
    if (!check_ajax_referer('wpt-tweet-nonce', 'security', false)) {
        echo "Invalid Security Check";
        die;
    }
    $action = $_REQUEST['tweet_action'] == 'tweet' ? 'tweet' : 'schedule';
    // This isn't used right now, because of time.
    $authors = isset($_REQUEST['tweet_auth']) && $_REQUEST['tweet_auth'] != null ? $_REQUEST['tweet_auth'] : false;
    $current_user = wp_get_current_user();
    if (function_exists('wpt_pro_exists') && wpt_pro_exists()) {
        if (wtt_oauth_test($current_user->ID, 'verify')) {
            $auth = $user_ID = $current_user->ID;
        } else {
            $auth = false;
            $user_ID = $current_user->ID;
        }
    } else {
        $auth = false;
        $user_ID = $current_user->ID;
    }
    if (current_user_can('wpt_can_tweet')) {
        $options = get_option('wpt_post_types');
        $post_ID = intval($_REQUEST['tweet_post_id']);
        $type = get_post_type($post_ID);
        $default = isset($options[$type]['post-edited-text']) ? $options[$type]['post-edited-text'] : '';
        $sentence = isset($_REQUEST['tweet_text']) && trim($_REQUEST['tweet_text']) != '' ? $_REQUEST['tweet_text'] : $default;
        $sentence = stripcslashes(trim($sentence));
        $post_info = wpt_post_info($post_ID);
        $sentence = jd_truncate_tweet($sentence, $post_info, $post_ID, false, $user_ID);
        $schedule = isset($_REQUEST['tweet_schedule']) ? strtotime($_REQUEST['tweet_schedule']) : rand(60, 240);
        $print_schedule = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $schedule);
        $offset = 60 * 60 * get_option('gmt_offset');
        $schedule = $schedule - $offset;
        $media = wpt_post_with_media($post_ID, $post_info);
        switch ($action) {
            case 'tweet':
                jd_doTwitterAPIPost($sentence, $auth, $post_ID, $media);
                break;
            case 'schedule':
                wp_schedule_single_event($schedule, 'wpt_schedule_tweet_action', array('id' => $auth, 'sentence' => $sentence, 'rt' => 0, 'post_id' => $post_ID));
                break;
        }
        $return = $action == 'tweet' ? wpt_log('wpt_status_message', $post_ID) : "Tweet scheduled: '{$sentence}' for {$print_schedule}";
        echo $return;
    } else {
        echo __('You are not authorized to perform this action', 'wp-to-twitter');
    }
    die;
}
Example #8
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>";
    }
}
Example #9
0
function wpt_authorized_users($selected = array())
{
    global $user_ID;
    $users = get_option('wpt_authorized_users');
    if (!$users) {
        $count = count_users('time');
        $users = $count['total_users'] > 100 ? get_users(array('role' => 'administrator')) : ($users = get_users());
        $authorized_users = array();
        if (is_array($users)) {
            foreach ($users as $this_user) {
                if (wtt_oauth_test($this_user->ID, 'verify')) {
                    $twitter = get_user_meta($this_user->ID, 'wtt_twitter_username', true);
                    $authorized_users[] = array('ID' => $this_user->ID, 'name' => $this_user->display_name, 'twitter' => $twitter);
                }
            }
        }
        update_option('wpt_authorized_users', $authorized_users);
        $users = $authorized_users;
    }
    $select = "<p class='wpt_auth_users'><label for='wpt_authorized_users'>Tweet to:</label><br /><select multiple='multiple' name='_wpt_authorized_users[]' id='wpt_authorized_users'>";
    if (!empty($users)) {
        foreach ($users as $user) {
            $current = $user_ID;
            $active = '';
            // if this has been directly pulled, these are objects. Otherwise, arrays.
            if (is_object($user)) {
                $id = $user->ID;
                $name = $user->display_name;
                $twitter = get_user_meta($id, 'wtt_twitter_username', true);
            } else {
                $id = $user['ID'];
                $name = $user['name'];
                $twitter = $user['twitter'];
            }
            if ($id == $current || in_array($id, $selected)) {
                $active = " selected='selected'";
            }
            $select .= " <option value='{$id}'{$active}>{$name} (@{$twitter})</option>\n";
        }
    }
    $select .= "</select></p>";
    return $select;
}
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);
    $protocol = get_option('wpt_http') == '1' ? 'http:' : 'https:';
    $response = wp_remote_get("{$protocol}//api.twitter.com/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>";
        }
        if (strpos($warning, 'SSL') !== false) {
            $ssl = __("SSL Problems? Try <a href='#wpt_http'>switching to <code>http</code> queries</a>.<br />", 'wp-to-twitter');
        } else {
            $ssl = __('Error Message:', 'wp-to-twitter');
        }
        $date = __("There was an error querying Twitter's servers", 'wp-to-twitter');
        $errors = "<p>" . $ssl . $warning . "</p>";
    } 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')) {
        $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 '	
			<h3>' . __('Connect to Twitter', 'wp-to-twitter') . '</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>' . __('<em>Note</em>: you will not add your Twitter user information to WP to Twitter; it is not used in this authentication method.', 'wp-to-twitter') . '</p> 
			</div>
			' . $form . '
				<fieldset class="options">
					<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\'s Name will show up after "via" in your twitter stream. 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 "Settings" 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>
						<li>' . __('Return to the Details tab and create your access token. Refresh page to view your access tokens.', 'wp-to-twitter') . '</li>		
						</ul>	
					<p><em>' . __('Once you have registered your site as an application, you will be provided with four keys.', 'wp-to-twitter') . '</em></p>
					<h4>' . __('3. Copy and paste your consumer key and consumer secret into the fields below', 'wp-to-twitter') . '</h4>
					<div class="tokens">
					<p>
						<label for="wtt_app_consumer_key">' . __('Twitter Consumer 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">' . __('Twitter Consumer 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') == 'true' ? '<p>' . __('<strong>Troubleshooting tip:</strong> Connected, but getting a notice that your Authentication credentials are missing or incorrect? Check whether your Access token has read and write permission. If not, you\'ll need to create a new token.', 'wp-to-twitter') . '</p>' : '';
            $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>' : '';
            print '	
			<h3>' . __('Disconnect from Twitter', 'wp-to-twitter') . '</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 current server time: ', 'wp-to-twitter') . '<code>' . $date . '</code>.</p>
			' . $errors . $diff . '</div>';
        }
    }
    if (!$auth) {
        echo "</div>";
        echo "</div>";
    }
}