<?php session_start(); if (!isset($_SESSION['user'])) { header("Location: /session/login.php"); } // set up chdir(".."); require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $db = new Database($TWITALYTIC_CFG); $conn = $db->getConnection(); $ud = new UserDAO($db); $fd = new FollowDAO($db); $id = new InstanceDAO($db); $td = new TweetDAO($db); if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) { $user = $ud->getUserByName($_REQUEST['u']); $i = $id->getByUsername($_REQUEST['i']); if (isset($i)) { $cfg = new Config($i->twitter_username, $i->twitter_user_id); $s = new SmartyTwitalytic(); if (!$s->is_cached('user.index.tpl', $i->twitter_username . "-" . $user['user_name'])) { $s->assign('profile', $user); $s->assign('user_statuses', $td->getAllTweets($user['user_id'], 20)); $s->assign('sources', $td->getStatusSources($user['user_id'])); $s->assign('cfg', $cfg); $s->assign('instance', $i); $exchanges = $td->getExchangesBetweenUsers($cfg->twitter_user_id, $user['user_id']); $s->assign('exchanges', $exchanges);
/** * Fetch instance user friends by user IDs. * @param int $uid * @param FollowDAO $fd */ private function fetchUserFriendsByIDs($uid, $fd) { $continue_fetching = true; $status_message = ""; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) { $args = array(); $friend_ids = $this->api->cURL_source['following_ids']; if (!isset($next_cursor)) { $next_cursor = -1; } $args['cursor'] = strval($next_cursor); $args['user_id'] = strval($uid); list($cURL_status, $twitter_data) = $this->api->apiRequest($friend_ids, $args); if ($cURL_status > 200) { $continue_fetching = false; } else { $status_message = "Parsing XML. "; $status_message .= "Cursor " . $next_cursor . ":"; $ids = $this->api->parseXML($twitter_data); $next_cursor = $this->api->getNextCursor(); $status_message .= count($ids) . " friend IDs queued to update. "; $this->logger->logInfo($status_message, __METHOD__ . ',' . __LINE__); $status_message = ""; if (count($ids) == 0) { $continue_fetching = false; } $updated_follow_count = 0; $inserted_follow_count = 0; foreach ($ids as $id) { // add/update follow relationship if ($fd->followExists($id['id'], $uid, 'twitter')) { //update it if ($fd->update($id['id'], $uid, 'twitter', Utils::getURLWithParams($friend_ids, $args))) { $updated_follow_count++; } } else { //insert it if ($fd->insert($id['id'], $uid, 'twitter', Utils::getURLWithParams($friend_ids, $args))) { $inserted_follow_count++; } } } $status_message .= "{$updated_follow_count} existing follows updated; " . $inserted_follow_count . " new follows inserted."; $this->logger->logUserInfo($status_message, __METHOD__ . ',' . __LINE__); } } }
<?php session_start(); if (!isset($_SESSION['user'])) { header("Location: ../session/login.php"); } // set up chdir(".."); require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $ud = new UserDAO($db); $fd = new FollowDAO($db); $id = new InstanceDAO($db); $pd = new PostDAO($db); $s = new SmartyThinkTank(); if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) { $user = $ud->getUserByName($_REQUEST['u']); $i = $id->getByUsername($_REQUEST['i']); if (isset($i)) { $cfg = new Config($i->network_username, $i->network_user_id); if (!$s->is_cached('user.index.tpl', $i->network_username . "-" . $user->user_name)) { $s->assign('profile', $user); $s->assign('user_statuses', $pd->getAllPosts($user->user_id, 20)); $s->assign('sources', $pd->getStatusSources($user->user_id)); $s->assign('cfg', $cfg); $s->assign('instance', $i); $s->assign('i', $i); // HATE TO DO THIS BUT SOME TEMPLATES LOOKING FOR $i AND NOT $instance $exchanges = $pd->getExchangesBetweenUsers($cfg->twitter_user_id, $user->user_id); $s->assign('exchanges', $exchanges);
function cleanUpFollows() { $fd = new FollowDAO($this->db, $this->logger); $continue_fetching = true; while ($this->api->available && $this->api->available_api_calls_for_crawler > 0 && $continue_fetching) { $oldfollow = $fd->getOldestFollow(); $friendship_call = $this->api->cURL_source['show_friendship']; $args = array(); $args["source_id"] = $oldfollow["followee_id"]; $args["target_id"] = $oldfollow["follower_id"]; list($cURL_status, $twitter_data) = $this->api->apiRequest($friendship_call, $this->logger, $args); if ($cURL_status == 200) { try { $friendship = $this->api->parseXML($twitter_data); if ($friendship['source_follows_target'] == 'true') { $fd->update($oldfollow["followee_id"], $oldfollow["follower_id"]); } else { $fd->deactivate($oldfollow["followee_id"], $oldfollow["follower_id"]); } if ($friendship['target_follows_source'] == 'true') { $fd->update($oldfollow["follower_id"], $oldfollow["followee_id"]); } else { $fd->deactivate($oldfollow["follower_id"], $oldfollow["followee_id"]); } } catch (Exception $e) { $status_message = 'Could not parse friendship XML'; } } else { $continue_fetching = false; } } }
$s->assign('msg', 'You have no Twitter accounts configured. <a href="' . $THINKTANK_CFG['site_root_path'] . 'account/?p=twitter">Set up a Twitter account here</a>'); $s->display('message.tpl'); $db->closeConnection($conn); die; } } // save the session instance network username to the current instance $_SESSION['network_username'] = $i->network_username; $_SESSION['instance'] = serialize($i); if (!$s->is_cached('index.tpl', $i->network_username . "-" . $_SESSION['user'])) { $cfg = new Config($i->network_username, $i->network_user_id); $u = new Utils(); // instantiate data access objects $ud = new UserDAO($db); $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);
function testGetUnloadedFollowerDetails() { $dao = new FollowDAO($this->db, $this->logger); $unloaded_followers = $dao->getUnloadedFollowerDetails(13); $this->assertTrue(count($unloaded_followers) == 1); $this->assertTrue($unloaded_followers[0]['follower_id'] == 14); }
/** * Fetch instance user friends by user IDs. * @param int $uid * @param FollowDAO $follow_dao */ private function fetchUserFriendsByIDs($uid, $follow_dao) { $continue_fetching = true; $status_message = ""; while ($continue_fetching) { $args = array(); $endpoint = $this->api->endpoints['following_ids']; if (!isset($next_cursor)) { $next_cursor = -1; } $args['cursor'] = strval($next_cursor); $args['user_id'] = strval($uid); try { list($http_status, $payload) = $this->api->apiRequest($endpoint, $args); } catch (APICallLimitExceededException $e) { $this->logger->logInfo($e->getMessage(), __METHOD__ . ',' . __LINE__); break; } if ($http_status > 200) { $continue_fetching = false; } else { $status_message = "Parsing JSON. "; $status_message .= "Cursor " . $next_cursor . ":"; $ids = $this->api->parseJSONIDs($payload); $next_cursor = $this->api->getNextCursor(); $status_message .= count($ids) . " friend IDs queued to update. "; $this->logger->logInfo($status_message, __METHOD__ . ',' . __LINE__); $status_message = ""; if (count($ids) == 0) { $continue_fetching = false; } $updated_follow_count = 0; $inserted_follow_count = 0; foreach ($ids as $id) { // add/update follow relationship if ($follow_dao->followExists($id['id'], $uid, 'twitter')) { //update it if ($follow_dao->update($id['id'], $uid, 'twitter')) { $updated_follow_count++; } } else { //insert it if ($follow_dao->insert($id['id'], $uid, 'twitter')) { $inserted_follow_count++; } } } $status_message .= "{$updated_follow_count} existing follows updated; " . $inserted_follow_count . " new follows inserted."; $this->logger->logUserInfo($status_message, __METHOD__ . ',' . __LINE__); } } }
$db->closeConnection($conn); die; } if (!isset($_REQUEST['d'])) { $_REQUEST['d'] = "all-tweets"; } $s = new SmartyThinkTank(); if (!$s->is_cached('inline.view.tpl', $i->network_username . "-" . $_SESSION['user'] . "-" . $_REQUEST['d'])) { $cfg = new Config($i->network_username, $i->network_user_id); $s->assign('cfg', $cfg); $s->assign('i', $i); $u = new Utils(); // instantiate data access objects $ud = new UserDAO($db); $pd = new PostDAO($db); $fd = new FollowDAO($db); $ld = new LinkDAO($db); $s->assign('display', $_REQUEST['d']); // pass data to smarty switch ($_REQUEST['d']) { case "tweets-all": $s->assign('header', 'All Posts'); $s->assign('all_tweets', $pd->getAllPosts($i->network_user_id, 15)); break; case "tweets-mostreplies": $s->assign('header', 'Most Replied-To Posts'); $s->assign('most_replied_to_tweets', $pd->getMostRepliedToPosts($i->network_user_id, 15)); break; case "tweets-mostretweeted": $s->assign('header', 'Most Forwarded'); $s->assign('most_retweeted', $pd->getMostRetweetedPosts($i->network_user_id, 15));
function testGetStalestFriend() { $dao = new FollowDAO($this->db, $this->logger); $stalest_friend = $dao->getStalestFriend(12); $this->assertTrue($stalest_friend != null); $this->assertTrue($stalest_friend->user_id == 13); }
function testGetOldestFollow() { $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen, active) VALUES (930061, 20, '2001-04-08 23:54:41', 1);"; $this->db->exec($q); $dao = new FollowDAO($this->db, $this->logger); $oldest_follow = $dao->getOldestFollow(); $this->assertTrue($oldest_follow != null); $this->assertEqual($oldest_follow["followee_id"], 930061); $this->assertEqual($oldest_follow["follower_id"], 20); }
<?php session_start(); if (!isset($_SESSION['user'])) { header("Location: ../session/login.php"); } // set up chdir(".."); require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $db = new Database($THINKTANK_CFG); $conn = $db->getConnection(); $ud = new UserDAO($db); $fd = new FollowDAO($db); $id = new InstanceDAO($db); $td = new TweetDAO($db); if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) { $user = $ud->getUserByName($_REQUEST['u']); $i = $id->getByUsername($_REQUEST['i']); if (isset($i)) { $cfg = new Config($i->twitter_username, $i->twitter_user_id); $s = new SmartyThinkTank(); if (!$s->is_cached('user.index.tpl', $i->twitter_username . "-" . $user->user_name)) { $s->assign('profile', $user); $s->assign('user_statuses', $td->getAllTweets($user->user_id, 20)); $s->assign('sources', $td->getStatusSources($user->user_id)); $s->assign('cfg', $cfg); $s->assign('instance', $i); $exchanges = $td->getExchangesBetweenUsers($cfg->twitter_user_id, $user->user_id); $s->assign('exchanges', $exchanges);