Exemplo n.º 1
0
 function execute()
 {
     $dao = new PostDAO();
     $res = '';
     $res = '{"records":' . json_encode($dao->search()) . '}';
     return $res;
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 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?");
 }
Exemplo n.º 4
0
/**
 * Smarty Tweet from ID plugin
 *
 * Type:     modifier<br>
 * Name:     tweet_from_id<br>
 * Date:     March 9, 2010
 * Purpose:  Converts a tweet id into a full Tweet object.
 * Input:    status id
 * Example:  {$tweet->in_reply_to_id|tweet_from_id}
 * @author   Thomas Woodham
 * @version 1.0
 * @param integer
 * @return object
 */
function smarty_modifier_tweet_from_id($status_id)
{
    global $db, $cfg, $i;
    // Necessary evil.
    $conn = $db->getConnection();
    $td = new PostDAO($db);
    if ($status_id > 0) {
        $tweet = $td->getPost($status_id);
    } else {
        $tweet = new Post(array('id' => 0, 'status_id' => 0));
    }
    return $tweet;
}
Exemplo n.º 5
0
 /**
  * Realiza un listado de todos los post cuyo autor es el amigo
  * del usuario.
  * 
  * @throws Exception Si el usuario no inicio sesion
  */
 public function perfil()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Editing posts requires login");
     }
     if (isset($_GET["id"])) {
         // obtiene el id del usuario del que se quieren ver los posts
         $userEmail = $_GET["id"];
         $user = $this->userDAO->findByEmail($userEmail);
         $posts = $this->postDAO->findPostsFriend($userEmail);
         // Carga los post en la vista y la renderiza
         $this->view->setVariable("posts", $posts);
         $this->view->setVariable("userName", $user->getName());
     }
     $this->view->render("posts", "perfilAmigo");
 }
 function testFetchUserStreamWithTwoPostsAndOneComment()
 {
     /*
     		$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"]);
     */
     $this->instance->network_user_id = '6068375911';
     $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);
     $p = $pd->getPost('108956622464235');
     $this->assertTrue($p->mention_count_cache == 1);
     $p = $pd->getPost('107266209295210');
     $this->assertTrue($p->mention_count_cache == 0);
 }
 /**
  * Load view with appropriate public post list. Default to reverse chronological order.
  * @param string $list
  */
 private function loadPublicPostList($list)
 {
     $totals = $this->post_dao->getTotalPagesAndPostsByPublicInstances($this->total_posts_per_page);
     switch ($list) {
         case 'timeline':
             $this->addToView('posts', $this->post_dao->getPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Latest');
             $this->addToView('description', 'Latest public posts and public replies');
             break;
         case 'mostretweets':
             $this->addToView('posts', $this->post_dao->getMostRetweetedPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Most forwarded');
             $this->addToView('description', 'Posts that have been forwarded most often');
             break;
         case 'mostretweets1wk':
             $this->addToView('posts', $this->post_dao->getMostRetweetedPostsByPublicInstancesInLastWeek($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Most forwarded this week');
             $this->addToView('description', 'Posts that have been forwarded most often this week');
             $totals = $this->post_dao->getTotalPagesAndPostsByPublicInstances($this->total_posts_per_page, 7);
             break;
         case 'mostreplies':
             $this->addToView('posts', $this->post_dao->getMostRepliedToPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Most replied to');
             $this->addToView('description', 'Posts that have been replied to most often');
             break;
         case 'mostreplies1wk':
             $this->addToView('posts', $this->post_dao->getMostRepliedToPostsByPublicInstancesInLastWeek($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Most replied to this week');
             $this->addToView('description', 'Posts that have been replied to most often this week');
             $totals = $this->post_dao->getTotalPagesAndPostsByPublicInstances($this->total_posts_per_page, 7);
             break;
         case 'photos':
             $this->addToView('posts', $this->post_dao->getPhotoPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Photos');
             $this->addToView('description', 'Posted photos');
             break;
         case 'links':
             $totals = $this->post_dao->getTotalLinkPagesAndPostsByPublicInstances($this->total_posts_per_page);
             $this->addToView('posts', $this->post_dao->getLinkPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Links');
             $this->addToView('description', 'Posted links');
             break;
         default:
             $this->addToView('posts', $this->post_dao->getPostsByPublicInstances($this->current_page, $this->total_posts_per_page));
             $this->addToView('header', 'Latest');
             $this->addToView('description', 'Latest public posts and public replies');
             break;
     }
     if ($totals['total_pages'] > $this->current_page) {
         $this->addToView('next_page', $this->current_page + 1);
     }
     $this->addToView('total_pages', $totals['total_pages']);
 }
Exemplo n.º 8
0
 /**
  * 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();
 }
 public function testPointCoordsNoPolygon()
 {
     $item = $this->getJSONStringFromFile("place3.json");
     $this->json_parser->parseJSON($item);
     // check post information
     $post = $this->post_dao->getPost('36358312584806400', 'twitter');
     $this->assertEqual($post->post_id, '36358312584806400');
     // should be no places info
     // check post_locations table information
     $post_loc_arr = $this->place_dao->getPostPlace('36358312584806400');
     $this->assertEqual($post_loc_arr['post_id'], '36358312584806400');
     $this->assertEqual($post_loc_arr['place_id'], null);
     $this->assertEqual($post_loc_arr['longlat'], 'POINT(139.722 35.6596)');
 }
Exemplo n.º 10
0
 /**
  * Metodo del controlador Comments cuya funcionalidad es insertar un comentario
  * en un post.
  * Verifica que el usuario ha iniciado sesion y que el post existe
  *
  * @throws Exception Si el usuario no inicio sesion
  * @return void
  */
 public function add()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Adding comments requires login");
     }
     if (isset($_GET["id"])) {
         // reaching via HTTP Post...
         // Se obtiene el post de la BD
         $idPost = $_GET["id"];
         $post = $this->postDAO->findByIdPost($idPost);
         // Si no existe el post lanza una excepcion
         if ($post == NULL) {
             throw new Exception("no such post with id: " . $idPost);
         }
         // Crea el objeto Comment
         $comment = new Comment();
         $comment->setDate(date("Y-m-d H:i:s"));
         $comment->setContent($_POST["content"]);
         $comment->setAuthor($this->currentUser->getEmail());
         $comment->setIdPost($post->getIdPost());
         try {
             // Valida el comentario, si falla lanza una excepcion
             $comment->checkIsValidForCreate();
             // Guarda el comentario en la BD
             $this->commentDAO->save($comment);
             // Redirige al post
             $this->view->redirect("posts", "viewPosts", "id=" . $post->getIdPost());
         } catch (ValidationException $ex) {
             $errors = $ex->getErrors();
             $this->view->setVariable("comment", $comment, true);
             $this->view->setVariable("errors", $errors, true);
             $this->view->redirect("posts", "viewPosts", "id=" . $post->getIdPost());
         }
     } else {
         throw new Exception("No such post id");
     }
 }
Exemplo n.º 11
0
<?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);
Exemplo n.º 12
0
<?php

session_start();
isset($_SESSION['user']) ? $_u = $_SESSION['user'] : ($_u = '');
isset($_SESSION['instance']) ? $_i = $_SESSION['instance'] : ($_i = '');
//Print_r  ($_i);
require_once "common/init.php";
$db = new Database($THINKTANK_CFG);
$conn = $db->getConnection();
$cfg = new Config();
$pd = new PostDAO($db);
$id = new InstanceDAO($db);
$s = new SmartyThinkTank();
//Pagination
$count = 15;
if (isset($_REQUEST['page'])) {
    $page = $_REQUEST['page'];
} else {
    $page = 1;
}
if ($page > 1) {
    $s->assign('prev_page', $page - 1);
}
$s->assign('cfg', $cfg);
$i = $id->getInstanceFreshestOne();
$s->assign('crawler_last_run', $i->crawler_last_run);
$s->assign('i', $_i);
// show tweet with public replies
if (isset($_REQUEST['t']) && $pd->isPostByPublicInstance($_REQUEST['t'])) {
    if (!$s->is_cached('public.tpl', $_REQUEST['t'])) {
        $post = $pd->getPost($_REQUEST['t']);
Exemplo n.º 13
0
 /**
  * Method to Update post if validation of geo-location data of post results in failure
  * @param PostDAO $pdao
  * @param int $post_id
  * @param str $network
  * @param str $is_geo_encoded
  * @return NULL
  */
 public function failedToGeoencode($pdao, $post_id, $network, $is_geo_encoded)
 {
     switch ($is_geo_encoded) {
         case 'ZERO_RESULTS':
             $pdao->setGeoencodedPost($post_id, $network, self::ZERO_RESULTS);
             break;
         case 'OVER_QUERY_LIMIT':
             self::$is_api_available = false;
             $pdao->setGeoencodedPost($post_id, $network, self::OVER_QUERY_LIMIT);
             $logger = Logger::getInstance();
             $logger->logUserError('Reached Google Maps\' query limit for now.', __METHOD__ . ',' . __LINE__);
             break;
         case 'REQUEST_DENIED':
             $pdao->setGeoencodedPost($post_id, $network, self::REQUEST_DENIED);
             break;
         case 'INVALID_REQUEST':
             $pdao->setGeoencodedPost($post_id, $network, self::INVALID_REQUEST);
     }
 }
Exemplo n.º 14
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: /session/login.php");
}
// set up
chdir("..");
require_once "common/init.php";
$od = new OwnerDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$pd = new PostDAO($db);
$id = new InstanceDAO($db);
if (isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u'])) {
    $username = $_REQUEST['u'];
    $oid = new OwnerInstanceDAO($db);
    if (!$oid->doesOwnerHaveAccess($owner, $username)) {
        echo 'Insufficient privileges. <a href="/">Back</a>.';
        die;
    } else {
        $tweets = $pd->getAllPostsByUsername($username);
    }
} else {
    echo 'No access';
    $db->closeConnection($conn);
    die;
}
$db->closeConnection($conn);
$s = new SmartyThinkTank();
$s->assign('tweets', $tweets);
$s->display('post.export.tpl', $username);
Exemplo n.º 15
0
<?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);
Exemplo n.º 16
0
} else {
    $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');
Exemplo n.º 17
0
}
//TODO: check that parent id and all orphan id's are valid and in the db, pass a success or error message back
echo $_GET["pid"];
echo "<br />";
$pid = $_GET["pid"];
$oid = $_GET["oid"];
$template = $_GET["t"];
$cache_key = $_GET["ck"];
foreach ($oid as $o) {
    echo $o;
    echo "<br />";
}
// 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";
$cfg = new Config();
$pd = new PostDAO($db);
foreach ($oid as $o) {
    echo "<br />";
    if (isset($_GET["fp"])) {
        $pd->assignParent($pid, $o, $_GET["fp"]);
    } else {
        $pd->assignParent($pid, $o);
    }
}
$db->closeConnection($conn);
$s = new SmartyThinkTank();
$s->clear_cache($template, $cache_key);
echo 'Assignment complete.<br /><a href="' . $THINKTANK_CFG['site_root_path'] . '?u=' . $_GET['u'] . '#replies">Back home</a>.';
Exemplo n.º 18
0
 function getTotalPostsByUser()
 {
     $pdao = new PostDAO($this->db, $this->logger);
     $total_posts = $pdao->getTotalPostsByUser(13);
     $this->assertTrue($total_posts == 40);
 }
Exemplo n.º 19
0
<?php

include_once 'Registry.php';
include_once 'dao/PostDAO.php';
include_once 'model/Post.php';
// Instanciar uma conexão com PDO
$conn = new PDO('mysql:host=localhost;port=3306;dbname=example-pdo', 'user', 'password');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Armazenar essa instância no Registry
$registry = Registry::getInstance();
$registry->set('Connection', $conn);
// Instanciar um novo Post e setar informações
$primeiroPost = new Post();
$primeiroPost->setTitle('Primeiro post');
$primeiroPost->setContent('Conteudo!');
// Instanciar um novo Post e setar informações
$segundoPost = new Post();
$segundoPost->setTitle('Segundo post');
$segundoPost->setContent('Conteudo!');
// Instanciar o DAO e trabalhar com os métodos
$postDAO = new PostDAO();
$postDAO->insert($primeiroPost);
$postDAO->insert($segundoPost);
// Resgatar todos os registros e iterar
$results = $postDAO->getAll();
foreach ($results as $post) {
    echo $post->getTitle() . '<br />';
    echo $post->getContent() . '<br />';
    echo '<br />';
}
Exemplo n.º 20
0
 public function deleteCommentModel($commentId)
 {
     $responseDTO = new ResponseDTO(DELETE_COMMENT_FORM);
     try {
         $postDAO = new PostDAO();
         $deletedComment = $postDAO->deleteComment($commentId);
         if ($deletedComment != 1) {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'eliminazione del commento");
             $responseDTO->setSubElementId($commentId);
         } else {
             if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
                 $responseDTO->setResponseSucc("#comment" . $commentId);
             } else {
                 $responseDTO->setResponseSucc("Commento eliminato con successo!");
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
 function fetchStrayRepliedToTweets($lurl, $fa)
 {
     $pd = new PostDAO($this->db, $this->logger);
     $strays = $pd->getStrayRepliedToPosts($this->owner_object->user_id);
     $status_message = count($strays) . ' stray replied-to tweets to load.';
     $this->logger->logStatus($status_message, get_class($this));
     foreach ($strays as $s) {
         if ($this->api->available && $this->api->available_api_calls_for_crawler > 0) {
             $this->fetchAndAddTweetRepliedTo($s['in_reply_to_post_id'], $pd, $lurl, $fa);
         }
     }
 }
Exemplo n.º 22
0
 /**
  * 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;
 }
Exemplo n.º 23
0
 function testAssignParent()
 {
     //Add two "parent" posts
     $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (550, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 1', 'web', '2006-03-01 00:01:00', 1, 0);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (551, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 2', 'web', '2006-03-01 00:01:00', 0, 0);";
     $this->db->exec($q);
     //Add a post with the parent post 550
     $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache, in_reply_to_post_id) VALUES (552, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is a reply with the wrong parent', 'web', '2006-03-01 00:01:00', 0, 0, 550);";
     $this->db->exec($q);
     $pdao = new PostDAO($this->db, $this->logger);
     $post = $pdao->getPost(552);
     //Assert parent post is 550
     $this->assertEqual($post->in_reply_to_post_id, 550);
     //Change parent post to 551
     $pdao->assignParent(551, 552);
     $child_post = $pdao->getPost(552);
     //Assert parent post is now 551
     $this->assertEqual($child_post->in_reply_to_post_id, 551);
     //Assert old parent post has one fewer reply total
     $old_parent = $pdao->getPost(550);
     $this->assertEqual($old_parent->mention_count_cache, 0);
     //Assert new parent post has one more reply total
     $new_parent = $pdao->getPost(551);
     $this->assertEqual($new_parent->mention_count_cache, 1);
 }
Exemplo n.º 24
0
 /**
  * Convert the post as it is returned from the database to how it looks when output by the Twitter API.
  * Also, add the replies into the post with the index "replies".
  *
  * If the $post parameter is not a Post object, the function returns null.
  *
  * @param Post $post The post object.
  * @return stdObject The post formatted to look like the Twitter API.
  */
 private function convertPostToTweet($post)
 {
     if (!$post instanceof Post) {
         return null;
     }
     if ($this->include_replies) {
         /*
          * Get all replies to the post. The limit is set to 0 because if the count is not greater than 0,
          * the method returns all replies.
          */
         $replies = $this->post_dao->getRepliesToPost($post->post_id, $post->network, $this->order_by, $this->unit, $this->is_public, 0);
         // if replies exist for this post
         if ($replies) {
             // recursively scan through the post replies, converting them
             foreach ($replies as $reply) {
                 $reply = $this->convertPostToTweet($reply);
             }
             // add the replies to the post
             $post->replies = $replies;
         }
     }
     /*
      * Chop and changing the data fetched from the database to look more like the official Twitter API.
      */
     $post->text = $post->post_text;
     $post->created_at = strftime('%a %b %d %T %z %Y', strtotime($post->pub_date));
     $post->id = $post->post_id;
     $post->favorited = $post->favorited ? true : false;
     $post->annotations = null;
     // to be implemented at some point
     $post->truncated = false;
     // always false
     $post->protected = $post->is_protected == 0 ? false : true;
     if ($post->geo != null) {
         $coordinates = preg_split('/(, |,| )/', $post->geo);
         $post->geo = new stdClass();
         $post->geo->coordinates = $coordinates;
         if (!isset($post->coordinates)) {
             $post->coordinates = new stdClass();
         }
         $post->coordinates->coordinates = $coordinates;
     }
     /*
      * SET THINKUP METADATA
      */
     $post->thinkup = new stdClass();
     $post->thinkup->retweet_count_cache = $post->retweet_count_cache;
     $post->thinkup->retweet_count_api = $post->retweet_count_api;
     $post->thinkup->reply_count_cache = $post->reply_count_cache;
     $post->thinkup->old_retweet_count_cache = $post->old_retweet_count_cache;
     $post->thinkup->is_geo_encoded = $post->is_geo_encoded;
     $user = $this->user_dao->getUserByName($post->author_username, $post->network);
     /*
      * Occasionally you run into users you haven't fetched yet. Bypass this code if you find one of them.
      */
     if ($user != null) {
         if (!$this->trim_user) {
             $post->user = $this->convertUserToStdClass($user);
             $post->user->id = $post->user->user_id;
             $post->user->followers_count = $post->user->follower_count;
             $post->user->profile_image_url = $post->user->avatar;
             $post->user->name = $post->user->full_name;
             $post->user->screen_name = $post->user->username;
             $post->user->statuses_count = $post->user->post_count;
             $post->user->created_at = strftime('%a %b %d %T %z %Y', strtotime($post->user->joined));
             $post->user->favorites_count = $post->user->favorites_count;
             if (isset($post->user->other)) {
                 if (isset($post->user->other['avg_tweets_per_day'])) {
                     $post->user->avg_tweets_per_day = $post->user->other['avg_tweets_per_day'];
                 }
             }
             $post->user->thinkup = new stdClass();
             $post->user->thinkup->last_post = $post->user->last_post;
             $post->user->thinkup->last_post_id = $post->user->last_post_id;
             $post->user->thinkup->found_in = $post->user->found_in;
         } else {
             $post->user = new stdClass();
             $post->user->id = $user->user_id;
         }
     }
     if ($this->include_entities) {
         /*
          * Gather hashtags and format them into a Tweet entity.
          */
         $extracted_hashtags = Post::extractHashtags($post->text);
         if (!isset($post->entities)) {
             $post->entities = new stdClass();
         }
         $post->entities->hashtags = array();
         if (!empty($extracted_hashtags)) {
             foreach ($extracted_hashtags as $hashtag_text) {
                 $hashtag = new stdClass();
                 $hashtag->text = str_replace('#', '', $hashtag_text);
                 $hashtag->indices[] = stripos($post->text, $hashtag_text);
                 $hashtag->indices[] = strlen($hashtag_text) + $hashtag->indices[0];
                 $post->entities->hashtags[] = $hashtag;
             }
         }
         /*
          * Gather mentions and format them into a Tweet entity.
          */
         $mentions = Post::extractMentions($post->text);
         if (!isset($post->entities)) {
             $post->entities = new stdClass();
         }
         $post->entities->user_mentions = array();
         if (!empty($mentions)) {
             foreach ($mentions as $username) {
                 $mentioned_user = $this->user_dao->getUserByName(str_replace('@', '', $username), $user->network);
                 $mention = new stdClass();
                 if (is_null($mentioned_user)) {
                     // skip this for now, probably not a good idea
                     continue;
                     /*
                      * If the user is not in our own ThinkUp database, a Twitter API call needs to be
                      * made to fill in the missing details.
                      *
                      * Not 100% sure if this is a good idea but it works.
                      */
                     $user_api_call = json_decode(Utils::getURLContents('https://api.twitter.com/1/users/show.json?screen_name=' . $username));
                     $mention->name = $user_api_call->name;
                     $mention->id = $user_api_call->id;
                     $mention->screen_name = $user_api_call->screen_name;
                 } else {
                     $mention->name = $mentioned_user->full_name;
                     $mention->id = $mentioned_user->user_id;
                     $mention->screen_name = $mentioned_user->username;
                 }
                 $mention->indices = array();
                 $mention->indices[] = stripos($post->text, $username);
                 $mention->indices[] = strlen($username) + $mention->indices[0];
                 $post->entities->user_mentions[] = $mention;
             }
         }
     }
     if ($post->in_retweet_of_post_id != null) {
         $post->retweeted_status = $this->post_dao->getPost($post->in_retweet_of_post_id, $user->network);
         $post->retweeted_status = $this->convertPostToTweet($post->retweeted_status);
     }
     /*
      * Unset no-longer-used variables in this post; mostly variables that have been moved to more
      * Twtter like locations / naming conventions.
      */
     unset($post->post_id, $post->pub_date, $post->network, $post->post_text, $post->author, $post->author_fullname, $post->author_username, $post->author_user_id, $post->author_avatar, $post->adj_pub_date, $post->user->follower_count, $post->user->is_protected, $post->user->network, $post->user->avatar, $post->user->full_name, $post->user->username, $post->user->user_id, $post->user->post_count, $post->user->joined, $post->user->favorites_count, $post->user->other, $post->link, $post->in_retweet_of_post_id, $post->in_retweet_of_user_id, $post->retweet_count_cache, $post->reply_count_cache, $post->old_retweet_count_cache, $post->is_geo_encoded, $post->rt_threshold, $post->is_protected, $post->user->last_post, $post->user->last_post_id, $post->user->found_in);
     return $post;
 }
Exemplo n.º 25
0
 public function commentAPostModel($commentForm, $postId = NULL)
 {
     $responseDTO = new ResponseDTO(WRITE_COMMENT_FORM);
     $formObjRaw = new FormDTO(WRITE_COMMENT_FORM, $commentForm);
     $formObjRaw->setSubElementId($postId);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $responseDTO->setSubElementId($formDataObj[WRITE_COMMENT_FORM . POSTID]);
         $validator = new FormValidator(WRITE_COMMENT_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $timestamp = date(DATE_FORMAT);
             $userLogged = SessionUtils::getUserLogged();
             $newCommentDTO = new CommentDTO(NULL, $formDataObj[WRITE_COMMENT_FORM . TEXT], $timestamp, $formDataObj[WRITE_COMMENT_FORM . POSTID], $userLogged);
             $postDAO = new PostDAO();
             $commentDTO = $postDAO->insertNewComment($newCommentDTO);
             if ($commentDTO->getCommentid() == 0) {
                 $responseDTO->setResponseSucc("Non è stato possibile inserire il commento del post");
             } else {
                 DataModelUtils::notifyAction($commentDTO->getCommentid() . SEPARATOR . $formDataObj[WRITE_COMMENT_FORM . POSTID] . SEPARATOR . $userLogged->getUserId() . SEPARATOR . SessionUtils::getDashboardId(), WRITE_COMMENT_FORM);
                 return $commentDTO;
             }
         } else {
             if (array_key_exists(TEXT, $validationError)) {
                 $responseDTO->setErrField(TEXT, $validationError[TEXT]);
             }
             return $responseDTO;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }