function fetchFriendTweetsAndFriends($lurl, $fa) { $fd = new FollowDAO($this->db, $this->logger); $pd = new PostDAO($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->user_id); if ($stale_friend != null) { $this->logger->logStatus($stale_friend->username . " is friend most need of update", get_class($this)); $stale_friend_tweets = str_replace("[id]", $stale_friend->username, $this->api->cURL_source['user_timeline']); $args = array(); $args["count"] = 200; if ($stale_friend->last_post_id > 0) { $args['since_id'] = $stale_friend->last_post_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 ($pd->addPost($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->post_count = $tweet['post_count']; $stale_friend->joined = date_format(date_create($tweet['joined']), "Y-m-d H:i:s"); if ($tweet['post_id'] > $stale_friend->last_post_id) { $stale_friend->last_post_id = $tweet['post_id']; } $ud->updateUser($stale_friend); $stale_friend_updated_from_tweets = true; } } } else { $this->fetchAndAddUser($stale_friend->user_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->user_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->user_id, $cURL_status, $e['error'], $this->owner_object->user_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; } } }