/** * Main control method */ public function authControl() { $this->setViewTemplate('post.index.tpl'); if (isset($_REQUEST['t']) && is_numeric($_REQUEST['t']) && $this->post_dao->isPostInDB($_REQUEST['t'])) { $post_id = $_REQUEST['t']; $this->addToViewCacheKey($post_id); $post = $this->post_dao->getPost($post_id); $this->addToView('post', $post); $this->addToView('likely_orphans', $this->post_dao->getLikelyOrphansForParent($post->pub_date, $post->author_user_id, $post->author_username, 15)); $this->addToView('all_tweets', $this->post_dao->getAllPosts($post->author_user_id, 15)); $all_replies = $this->post_dao->getRepliesToPost($post_id); $this->addToView('replies', $all_replies); $all_replies_count = count($all_replies); $this->addToView('reply_count', $all_replies_count); $all_retweets = $this->post_dao->getRetweetsOfPost($post_id); $this->addToView('retweets', $all_retweets); $retweet_reach = $this->post_dao->getPostReachViaRetweets($post_id); $this->addToView('retweet_reach', $retweet_reach); $public_replies = $this->post_dao->getPublicRepliesToPost($post_id); $public_replies_count = count($public_replies); $this->addToView('public_reply_count', $public_replies_count); $private_replies_count = $all_replies_count - $public_replies_count; $this->addToView('private_reply_count', $private_replies_count); } else { $this->addToView('error', 'Post not found'); } return $this->generateView(); }
function testFetchUserStreamWithTwoPostsNoComments() { /* $this->assertTrue(unserialize('a:2:{s:5:"posts";a:2:{i:0;a:21:{s:7:"post_id";s:25:"606837591_108956622464235";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:50:"The Pacific is really good. Can\'t wait for part 3.";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=108956622464235&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269488627";s:12:"created_time";s:10:"1269488627";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=108956622464235&id=606837591";}i:1;a:21:{s:7:"post_id";s:25:"606837591_107266209295210";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:23:"SHAKE IT LIKE A POM-POM";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=107266209295210&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269411918";s:12:"created_time";s:10:"1269411918";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=107266209295210&id=606837591";}}s:8:"profiles";a:1:{i:0;a:5:{s:2:"id";s:9:"606837591";s:3:"url";s:0:"";s:4:"name";s:12:"Gina Trapani";s:10:"pic_square";s:60:"http://profile.ak.fbcdn.net/v222/1942/94/q606837591_9678.jpg";s:4:"type";s:4:"user";}}}')); $stream = unserialize('a:2:{s:5:"posts";a:2:{i:0;a:21:{s:7:"post_id";s:25:"606837591_108956622464235";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:50:"The Pacific is really good. Can\'t wait for part 3.";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=108956622464235&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269488627";s:12:"created_time";s:10:"1269488627";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=108956622464235&id=606837591";}i:1;a:21:{s:7:"post_id";s:25:"606837591_107266209295210";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:23:"SHAKE IT LIKE A POM-POM";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=107266209295210&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269411918";s:12:"created_time";s:10:"1269411918";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=107266209295210&id=606837591";}}s:8:"profiles";a:1:{i:0;a:5:{s:2:"id";s:9:"606837591";s:3:"url";s:0:"";s:4:"name";s:12:"Gina Trapani";s:10:"pic_square";s:60:"http://profile.ak.fbcdn.net/v222/1942/94/q606837591_9678.jpg";s:4:"type";s:4:"user";}}}'); $this->assertTrue(is_array($stream)); $this->assertTrue(is_array($stream["posts"])); //print_r($stream["posts"]); */ $fbc = new FacebookCrawler($this->instance, $this->logger, $this->fb, $this->db); $session_key = 'f8c16f44b43083fc2545a46d-606837591'; $fbc->fetchUserPostsAndReplies($this->instance->network_user_id, $session_key); $pd = new PostDAO($this->db, $this->logger); $this->assertTrue($pd->isPostInDB('108956622464235')); $this->assertTrue($pd->isPostInDB('107266209295210')); }
/** * Main control method */ public function authControl() { $this->setViewTemplate('post.index.tpl'); $network = isset($_GET['n']) ? $_GET['n'] : 'twitter'; $_GET['n'] = $network; if ($this->shouldRefreshCache()) { if (isset($_GET['t']) && is_numeric($_GET['t']) && $this->post_dao->isPostInDB($_GET['t'], $network)) { $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('geoencoder', true); if (isset($options['distance_unit']->option_value)) { $distance_unit = $options['distance_unit']->option_value; } else { $distance_unit = 'km'; } $post_id = $_GET['t']; $post = $this->post_dao->getPost($post_id, $network); $this->addToView('post', $post); $this->addToView('unit', $distance_unit); // costly query //$this->addToView('likely_orphans', $this->post_dao->getLikelyOrphansForParent($post->pub_date, //$post->author_user_id,$post->author_username, 15) ); //$this->addToView('all_tweets', $this->post_dao->getAllPosts($post->author_user_id, 15) ); $all_replies = $this->post_dao->getRepliesToPost($post_id, $network, 'default', $distance_unit); $this->addToView('replies', $all_replies); $all_replies_by_location = $this->post_dao->getRepliesToPost($post_id, $network, 'location', $distance_unit); $this->addToView('replies_by_location', $all_replies_by_location); $all_replies_count = count($all_replies); $this->addToView('reply_count', $all_replies_count); $all_retweets = $this->post_dao->getRetweetsOfPost($post_id, $network, 'default', $distance_unit); $this->addToView('retweets', $all_retweets); $all_retweets_by_location = $this->post_dao->getRetweetsOfPost($post_id, $network, 'location', $distance_unit); $this->addToView('retweets_by_location', $all_retweets_by_location); $retweet_reach = $this->post_dao->getPostReachViaRetweets($post_id, $network); $this->addToView('retweet_reach', $retweet_reach); $public_replies = $this->post_dao->getPublicRepliesToPost($post_id, $network); $public_replies_count = count($public_replies); $this->addToView('public_reply_count', $public_replies_count); $private_replies_count = $all_replies_count - $public_replies_count; $this->addToView('private_reply_count', $private_replies_count); } else { $this->addErrorMessage('Post not found'); } } return $this->generateView(); }
function testFetchSearchResults() { $this->api->available = true; $this->api->available_api_calls_for_crawler = 1; $tc = new TwitterCrawler($this->instance, $this->logger, $this->api, $this->db); $tc->fetchInstanceUserInfo(); $tc->fetchSearchResults('@whitehouse'); $pdao = new PostDAO($this->db, $this->logger); $this->assertTrue($pdao->isPostInDB(11841192840.0)); $post = $pdao->getPost(11841192840.0); $this->assertEqual($post->post_text, "RT @CindyPDX: @whitehouse PLS send to my President: http://familiesofautistickids.ning.com/video/through-my-eyes-thanh-bui <Does he remember our son?"); }
/** * Method to find distance between reply and initial post * @param PostDAO $post_dao * @param array $post * @param str $geodata * @return int $reply_retweet_distance */ public function getDistance($post_dao, $post, $geodata) { if ($post['in_reply_to_post_id'] != NULL) { if ($post_dao->isPostInDB($post['in_reply_to_post_id'], 'twitter')) { $original_post = $post_dao->getPost($post['in_reply_to_post_id'], 'twitter'); if ($original_post->is_geo_encoded == 1) { $o_post_geo = $original_post->geo; $reply_retweet_distance = self::getDistanceBetweenPosts($geodata, $o_post_geo); } else { if ($original_post->is_geo_encoded == 0) { return FALSE; } } } else { $reply_retweet_distance = -1; } } if ($post['in_retweet_of_post_id'] != NULL) { if ($post_dao->isPostInDB($post['in_retweet_of_post_id'], 'twitter')) { $original_post = $post_dao->getPost($post['in_retweet_of_post_id'], 'twitter'); if ($original_post->is_geo_encoded == 1) { $o_post_geo = $original_post->geo; $reply_retweet_distance = self::getDistanceBetweenPosts($geodata, $o_post_geo); } else { if ($original_post->is_geo_encoded == 0) { return FALSE; } } } else { $reply_retweet_distance = -1; } } return $reply_retweet_distance; }
<?php session_start(); if (!isset($_SESSION['user'])) { header("Location: /session/login.php"); } // set up chdir(".."); require_once "common/init.php"; $pd = new PostDAO($db); if (isset($_REQUEST['t']) && is_numeric($_REQUEST['t']) && $pd->isPostInDB($_REQUEST['t'])) { $post_id = $_REQUEST['t']; $s = new SmartyThinkTank(); if (!$s->is_cached('status.index.tpl', $post_id)) { $post = $pd->getPost($post_id); $u = new Utils(); // BUG: THIS ISN'T GOING TO WORK WHEN LOOKING AT POSTS OF OTHER USERS BECAUSE THEY DON'T HAVE INSTANCES //$id = new InstanceDAO($db); //$i = $id->getByUsername($post->author_username); // instead, lets pull the instance object out of the session variable $i = unserialize($_SESSION['instance']); if (isset($i)) { $s->assign('likely_orphans', $pd->getLikelyOrphansForParent($post->pub_date, $i->network_user_id, $post->author_username, 15)); $s->assign('all_tweets', $pd->getAllPosts($i->network_user_id, 15)); } $cfg = new Config($i->network_username, $i->network_user_id); // instantiate data access objects $ud = new UserDAO($db); $all_replies = $pd->getRepliesToPost($post_id); $all_replies_count = count($all_replies); $all_retweets = $pd->getRetweetsOfPost($post_id);