$pd = new PostDAO($db); $fd = new FollowDAO($db); // pass data to smarty $owner_stats = $ud->getDetails($i->network_user_id); $s->assign('owner_stats', $owner_stats); $s->assign('instance', $i); $s->assign('instances', $id->getByOwner($owner)); $s->assign('cfg', $cfg); $total_follows_with_errors = $fd->getTotalFollowsWithErrors($cfg->twitter_user_id); $s->assign('total_follows_with_errors', $total_follows_with_errors); $total_follows_with_full_details = $fd->getTotalFollowsWithFullDetails($cfg->twitter_user_id); $s->assign('total_follows_with_full_details', $total_follows_with_full_details); $total_follows_protected = $fd->getTotalFollowsProtected($cfg->twitter_user_id); $s->assign('total_follows_protected', $total_follows_protected); //TODO: Get friends with full details and also friends with errors, same as with followers $total_friends_loaded = $fd->getTotalFriends($cfg->twitter_user_id); $s->assign('total_friends', $total_friends_loaded); $total_friends_with_errors = $fd->getTotalFriendsWithErrors($cfg->twitter_user_id); $s->assign('total_friends_with_errors', $total_friends_with_errors); $total_friends_protected = $fd->getTotalFriendsProtected($cfg->twitter_user_id); $s->assign('total_friends_protected', $total_friends_protected); //Percentages $percent_followers_loaded = $u->getPercentage($owner_stats->follower_count, $total_follows_with_full_details + $total_follows_with_errors); $percent_followers_loaded = $percent_followers_loaded > 100 ? 100 : $percent_followers_loaded; $percent_tweets_loaded = $u->getPercentage($owner_stats->post_count, $i->total_posts_in_system); $percent_tweets_loaded = $percent_tweets_loaded > 100 ? 100 : $percent_tweets_loaded; $percent_friends_loaded = $u->getPercentage($owner_stats->friend_count, $total_friends_loaded); $percent_friends_loaded = $percent_friends_loaded > 100 ? 100 : $percent_friends_loaded; $percent_followers_suspended = round($u->getPercentage($total_follows_with_full_details, $total_follows_with_errors), 2); $percent_followers_protected = round($u->getPercentage($total_follows_with_full_details, $total_follows_protected), 2); $s->assign('percent_followers_loaded', $percent_followers_loaded);
function fetchInstanceUserFriends() { $fd = new FollowDAO($this->db, $this->logger); $this->instance->total_friends_in_system = $fd->getTotalFriends($this->owner_object->id); if ($this->instance->total_friends_in_system < $this->owner_object->friend_count) { $this->instance->is_archive_loaded_friends = false; $this->logger->logStatus($this->instance->total_friends_in_system . " friends in system, " . $this->owner_object->friend_count . " friends according to Twitter; Friend archive is not loaded", get_class($this)); } else { $this->instance->is_archive_loaded_friends = true; $this->logger->logStatus("Friend archive loaded", get_class($this)); } $status_message = ""; # Fetch friend pages $continue_fetching = true; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching && !$this->instance->is_archive_loaded_friends) { $friend_ids = $this->api->cURL_source['following']; $args = array(); if (!isset($next_cursor)) { $next_cursor = -1; } $args['cursor'] = strval($next_cursor); list($cURL_status, $twitter_data) = $this->api->apiRequest($friend_ids, $this->logger, $args); if ($cURL_status > 200) { $continue_fetching = false; } else { try { $status_message = "Parsing XML. "; $status_message .= "Cursor " . $next_cursor . ":"; $users = $this->api->parseXML($twitter_data); $next_cursor = $this->api->getNextCursor(); $status_message .= count($users) . " friends queued to update. "; $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; $updated_follow_count = 0; $inserted_follow_count = 0; if (count($users) == 0) { $this->instance->is_archive_loaded_friends = true; } foreach ($users as $u) { $utu = new User($u, 'Friends'); $this->ud->updateUser($utu, $this->logger); # add/update follow relationship if ($fd->followExists($utu->user_id, $this->instance->twitter_user_id)) { //update it if ($fd->update($utu->user_id, $this->instance->twitter_user_id)) { $updated_follow_count++; } } else { //insert it if ($fd->insert($utu->user_id, $this->instance->twitter_user_id)) { $inserted_follow_count++; } } } $status_message .= "{$updated_follow_count} existing friends updated; {$inserted_follow_count} new friends inserted."; } catch (Exception $e) { $status_message = 'Could not parse friends XML for $crawler_twitter_username'; } $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; } $this->logger->logStatus($status_message, get_class($this)); $status_message = ""; } }
function testGetTotalFriends() { $dao = new FollowDAO($this->db, $this->logger); $total_friends = $dao->getTotalFriends(12); $this->assertTrue($total_friends == 2); }