/** * Saves the tweets passed in. * * @param array $tweets - safe tweets (do error checking before passing to this function) * @return int - number of tweets saved */ function save_tweets($tweets) { global $wpdb; // strip out any tweets we already have $tweet_guids = array(); foreach ($tweets as $tweet) { $tweet_guids[] = AKTT_Tweet::guid_from_twid($tweet->id); } $existing_guids = $wpdb->get_col("\n\t\t\tSELECT guid\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE guid IN ('" . implode("','", $tweet_guids) . "')\n\t\t\tAND post_type = '" . AKTT::$post_type . "'\n\t\t"); // Set the args for any blog posts created $post_tweet_args = array('post_author' => $this->option('post_author'), 'post_category' => $this->option('post_category'), 'post_tags' => $this->option('post_tags'), 'title_prefix' => $this->option('blog_post_title_prefix')); // Save new tweets foreach ($tweets as $tweet) { if (in_array(AKTT_Tweet::guid_from_twid($tweet->id), $existing_guids)) { continue; } // Start up a tweet object $t = new AKTT_Tweet($tweet); if (!($result = $t->add())) { AKTT::log('There was an error saving a tweet. Tweet ID: ' . $t->id); continue; } // Now conditionially create the associated blog post if ($this->option('create_posts') == 1 && !($this->option('exclude_reply_tweets') && $t->is_reply()) && !($this->option('exclude_retweets') && $t->is_retweet()) && !$t->tweet_post_exists() && !$t->was_broadcast()) { AKTT::log('Creating a blog post for tweet ID: ' . $t->id); $t->create_blog_post($post_tweet_args); } } }
/** * Create blog post from tweet * * @param array $args * @return bool */ function create_blog_post($args = array()) { extract($args); // Add a space if we have a prefix $title_prefix = empty($title_prefix) ? '' : trim($title_prefix) . ' '; $post_content = $this->link_entities(false); // Append image to post if there is one, can't set it as a featured image until after save if (!empty($this->featured_image_id)) { $size = apply_filters('aktt_featured_image_size', 'medium'); $post_content .= "\n\n" . wp_get_attachment_image($this->featured_image_id, $size); } $gmt_time = self::twdate_to_time($this->date()); // Build the post data $data = array('post_title' => $title_prefix . $this->title(), 'post_content' => $post_content, 'post_author' => $post_author, 'post_status' => $post_status, 'post_type' => 'post', 'post_date' => date('Y-m-d H:i:s', AKTT::gmt_to_wp_time($gmt_time)), 'post_date_gmt' => date('Y-m-d H:i:s', $gmt_time), 'guid' => $this->guid() . '-post'); $data = apply_filters('aktt_tweet_create_blog_post_data', $data); // hook in here if you want to conditionally skip blog post creation if (!apply_filters('aktt_tweet_create_blog_post', true, $data, $this)) { return false; } $this->blog_post_id = wp_insert_post($data, true); if (is_wp_error($this->blog_post_id)) { AKTT::log('WP_Error:: ' . $this->blog_post_id->get_error_message()); return false; } // have to set up taxonomies after the insert in case we are in a context without // a 'current user' - see: http://core.trac.wordpress.org/ticket/19373 wp_set_object_terms($this->blog_post_id, intval($post_category), 'category'); wp_set_object_terms($this->blog_post_id, array_map('trim', explode(',', $post_tags)), 'post_tag'); // hook in here and return false to not set the format to "status", // or return another format to use that format instead of status if ($post_format = apply_filters('aktt_tweet_create_blog_post_format', 'status', $data, $this)) { set_post_format($this->blog_post_id, $post_format); } if (!empty($this->featured_image_id)) { update_post_meta($this->blog_post_id, '_thumbnail_id', $this->featured_image_id); } update_post_meta($this->blog_post_id, '_aktt_tweet_id', $this->id()); // twitter's tweet ID update_post_meta($this->blog_post_id, '_aktt_tweet_post_id', $this->post_id); // twitter's post ID // Add it to the tweet's post_meta as well update_post_meta($this->post_id, '_aktt_tweet_blog_post_id', $this->blog_post_id); // Let Social know to aggregate info about this post $account = false; foreach (AKTT::$accounts as $aktt_account) { if ($aktt_account->social_acct->id() == $this->data->user->id_str) { $account = $aktt_account->social_acct; break; } } if ($account) { Social::instance()->add_broadcasted_id($this->blog_post_id, 'twitter', $this->id(), $this->content(), $account, null); } // Let the account know we were successful return true; }
<?php include 'tweet-list.php'; ?> <p class="aktt_more_updates"><a href="<?php echo esc_url(AKTT::profile_url($username)); ?> "><?php echo apply_filters('aktt_follow_text', __('Follow Me on Twitter', 'twitter-tools')); ?> </a></p> <?php if (AKTT::option('credit')) { ?> <p class="aktt_credit"><?php _e('Powered by <a href="http://crowdfavorite.com/wordpress/plugins/twitter-tools/">Twitter Tools</a>', 'twitter-tools'); ?> </p> <?php }
<input type="submit" class="button-primary" value="<?php _e('Save Settings', 'twitter-tools'); ?> " /> </form> <h3><?php _e('Download Tweets', 'twitter-tools'); ?> </h3> <p> <?php _e('Tweets are downloaded automatically every 15 minutes. Can\'t wait?', 'twitter-tools'); ?> <a href="<?php echo esc_url(AKTT::get_manual_update_url()); ?> " class="aktt-manual-update button-secondary"><?php _e('Download Tweets Now', 'twitter-tools'); ?> </a> <span class="aktt-manual-update-running"></span> <img alt="" class="aktt-manual-update-request" src="<?php echo admin_url('images/wpspin_light.gif'); ?> "> </p> <?php } ?>
function aktt_shortcode_tweet($args) { if (!AKTT::$enabled) { return ''; } if ($account = AKTT::default_account()) { $username = $account->social_acct->name(); } else { // no accounts, get out return ''; } $args = shortcode_atts(array('account' => $username, 'id' => null), $args); // if we have an ID, only search by that if (!empty($args['id'])) { unset($args['account']); } $args['count'] = 1; $tweets = AKTT::get_tweets($args); if (count($tweets) != 1) { return ''; } $tweet = $tweets[0]; ob_start(); include AKTT_PATH . '/views/tweet.php'; return ob_get_clean(); }
static function download_tweet($status_id, $username = null) { if (empty(AKTT::$accounts)) { return false; } $account_found = $tweet = false; if (!empty($username)) { AKTT::get_social_accounts(); foreach (AKTT::$accounts as $id => $account) { if ($username == $account->social_acct->name()) { // proper account stored as $account $account_found = true; break; } } if (!$account_found) { $account = AKTT::$accounts[0]; // use any account } $response = Social::instance()->service('twitter')->request($account->social_acct, '1.1/statuses/show/' . urlencode($t->id) . '.json', array('include_entities' => 1, 'include_rts' => 1)); $content = $response->body(); if ($content->result == 'success') { $tweets = $content->response; if (!$tweets || !is_array($tweets) || count($tweets) != 1) { $tweet = $tweet[0]; } } } return $tweet; }
function widget($args, $instance) { extract($args); $username = $instance['account']; $tweets = AKTT::get_tweets($instance); echo $before_widget . $before_title . $instance['title'] . $after_title; include AKTT_PATH . 'views/widget.php'; echo $after_widget; }
<?php $content = $tweet->post_content; if (isset($tweet->tweet)) { $content = $tweet->tweet->link_entities(); } echo wptexturize($content); if (isset($tweet->tweet)) { $reply_id = $tweet->tweet->reply_id(); if (!empty($reply_id)) { ?> <a href="<?php echo esc_url(AKTT::status_url($tweet->tweet->reply_screen_name(), $reply_id)); ?> " class="aktt_tweet_reply"><?php printf(__('in reply to %s', 'twitter-tools'), esc_html($tweet->tweet->reply_screen_name())); ?> </a> <?php } ?> <a href="<?php echo esc_url($tweet->tweet->status_url()); ?> " class="aktt_tweet_time"><?php echo sprintf(__('%s ago', 'twitter-tools'), human_time_diff(strtotime($tweet->post_date_gmt))); ?> </a> <?php }