/** * * called whenever we want to update the Tweets from Twitter * @param string $type favorites|mine * @param string $twitter_id the account from which to retrieve Tweets */ public function get_tweets($type, $twitter_id) { $found = 0; if ($type == 'favorites') { $tweets = $this->get_favorites($twitter_id); } else { $type = 'mine'; $tweets = $this->get_statuses($twitter_id); } $PerchTwitterTweets = new PerchTwitter_Tweets(); //get list of existing Tweet IDs for comparison and deduping. $a = $PerchTwitterTweets->get_tweet_ids($twitter_id, $type); if (PerchUtil::count($tweets)) { foreach ($tweets as $tweet) { //loop through all retrieved Tweets $formatted_tweet_id = trim($tweet->id_str); if (!in_array($formatted_tweet_id, $a)) { $data = array(); $data['tweetTwitterID'] = $formatted_tweet_id; $data['tweetUser'] = trim($tweet->user->screen_name); $data['tweetUserRealName'] = trim($tweet->user->name); $data['tweetUserAvatar'] = trim($tweet->user->profile_image_url); $data['tweetDate'] = date('Y:m:d H:i:s', strtotime($tweet->created_at)); $data['tweetTimeOffset'] = (int) $tweet->user->utc_offset; $data['tweetText'] = trim($tweet->text); $data['tweetHTML'] = $this->get_tweet_html($tweet); $data['tweetType'] = $type; $data['tweetAccount'] = $twitter_id; // set a flag if this is an @reply, we can then exclude these at runtime if desired if ($tweet->in_reply_to_user_id != '') { $data['tweetIsReply'] = 1; } //create a single Tweet entry in the database $PerchTwitterTweets->create($data); $found++; } else { PerchUtil::debug('<br />match: ' . $tweet->id); } } } return $found; }