Example #1
0
 /**
  * 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);
         }
     }
 }