function fetchFriendTweetsAndFriends($lurl, $fa) { $fd = new FollowDAO($this->db, $this->logger); $td = new TweetDAO($this->db, $this->logger); $ud = new UserDAO($this->db, $this->logger); $continue_fetching = true; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) { $stale_friend = $fd->getStalestFriend($this->owner_object->id); if ($stale_friend != null) { $this->logger->logStatus($stale_friend->user_name . " is friend most need of update", get_class($this)); $stale_friend_tweets = str_replace("[id]", $stale_friend->user_name, $this->api->cURL_source['user_timeline']); $args = array(); $args["count"] = 200; if ($stale_friend->last_status_id > 0) { $args['since_id'] = $stale_friend->last_status_id; } list($cURL_status, $twitter_data) = $this->api->apiRequest($stale_friend_tweets, $this->logger, $args); if ($cURL_status == 200) { try { $count = 0; $tweets = $this->api->parseXML($twitter_data); if (count($tweets) > 0) { $stale_friend_updated_from_tweets = false; foreach ($tweets as $tweet) { if ($td->addTweet($tweet, $stale_friend, $this->logger) > 0) { $count++; //expand and insert links contained in tweet $this->processTweetURLs($tweet, $lurl, $fa); } if (!$stale_friend_updated_from_tweets) { //Update stale_friend values here $stale_friend->full_name = $tweet['full_name']; $stale_friend->avatar = $tweet['avatar']; $stale_friend->location = $tweet['location']; $stale_friend->description = $tweet['description']; $stale_friend->url = $tweet['url']; $stale_friend->is_protected = $tweet['is_protected']; $stale_friend->follower_count = $tweet['follower_count']; $stale_friend->friend_count = $tweet['friend_count']; $stale_friend->tweet_count = $tweet['tweet_count']; $stale_friend->joined = date_format(date_create($tweet['joined']), "Y-m-d H:i:s"); if ($tweet['status_id'] > $stale_friend->last_status_id) { $stale_friend->last_status_id = $tweet['status_id']; } $ud->updateUser($stale_friend, $this->logger); $stale_friend_updated_from_tweets = true; } } } else { $this->fetchAndAddUser($stale_friend->id, "Friends"); } $this->logger->logStatus(count($tweets) . " tweet(s) found for " . $stale_friend->username . " and {$count} saved", get_class($this)); } catch (Exception $e) { $this->logger->logStatus('Could not parse friends XML for $stale_friend->username', get_class($this)); } $this->fetchUserFriendsByIDs($stale_friend->id, $fd); } elseif ($cURL_status == 401 || $cURL_status == 404) { try { $e = $this->api->parseError($twitter_data); $ued = new UserErrorDAO($this->db, $this->logger); $ued->insertError($stale_friend->id, $cURL_status, $e['error'], $this->owner_object->id); $this->logger->logStatus('User error saved', get_class($this)); } catch (Exception $e) { $this->logger->logStatus('Could not parse timeline error for $stale_friend->username', get_class($this)); } } } else { $this->logger->logStatus('No friend staler than 1 day', get_class($this)); $continue_fetching = false; } } }