/**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * 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;
 }
Exemple #4
0
 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);
     $retweet_reach = $pd->getPostReachViaRetweets($post_id);
     $public_replies = $pd->getPublicRepliesToPost($post_id);
     $public_replies_count = count($public_replies);
     $private_replies_count = $all_replies_count - $public_replies_count;
     $post = $pd->getPost($post_id);
     $s->assign('post', $post);
     $s->assign('replies', $all_replies);
     $s->assign('retweets', $all_retweets);
     $s->assign('retweet_reach', $retweet_reach);
     $s->assign('public_reply_count', $public_replies_count);
     $s->assign('private_reply_count', $private_replies_count);
     $s->assign('reply_count', $all_replies_count);
     $s->assign('cfg', $cfg);
Exemple #5
0
 $status_id = $_REQUEST['t'];
 $s = new SmartyThinkTank();
 if (!$s->is_cached('status.index.tpl', $status_id)) {
     $post = $pd->getPost($status_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);
     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($status_id);
     $all_replies_count = count($all_replies);
     $all_retweets = $pd->getRetweetsOfPost($status_id);
     $retweet_reach = $pd->getPostReachViaRetweets($status_id);
     $public_replies = $pd->getPublicRepliesToPost($status_id);
     $public_replies_count = count($public_replies);
     $private_replies_count = $all_replies_count - $public_replies_count;
     $post = $pd->getPost($status_id);
     $s->assign('post', $post);
     $s->assign('replies', $all_replies);
     $s->assign('retweets', $all_retweets);
     $s->assign('retweet_reach', $retweet_reach);
     $s->assign('public_reply_count', $public_replies_count);
     $s->assign('private_reply_count', $private_replies_count);
     $s->assign('reply_count', $all_replies_count);
     $s->assign('cfg', $cfg);