コード例 #1
0
 /**
  * Load instance dashboard
  * @param str $username
  * @param str $network
  */
 private function loadPublicInstanceDashboard($username, $network)
 {
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $instance = $instance_dao->getByUsernameOnNetwork($username, $network);
     if (isset($instance) && $instance->is_public) {
         $this->setPageTitle($instance->network_username . "'s Public Profile");
         $this->addToView('instance', $instance);
         //user
         $user_dao = DAOFactory::getDAO('UserDAO');
         $user = $user_dao->getDetails($instance->network_user_id, $instance->network);
         $this->addToView('user_details', $user);
         //posts
         $recent_posts = $this->post_dao->getAllPosts($instance->network_user_id, $instance->network, 5, true);
         $this->addToView('recent_posts', $recent_posts);
         $most_replied_to_alltime = $this->post_dao->getMostRepliedToPosts($instance->network_user_id, $network, 5);
         $this->addToView('most_replied_to_alltime', $most_replied_to_alltime);
         $most_retweeted_alltime = $this->post_dao->getMostRetweetedPosts($instance->network_user_id, $network, 5);
         $this->addToView('most_retweeted_alltime', $most_retweeted_alltime);
         $most_replied_to_1wk = $this->post_dao->getMostRepliedToPostsInLastWeek($instance->network_username, $instance->network, 5);
         $this->addToView('most_replied_to_1wk', $most_replied_to_1wk);
         $most_retweeted_1wk = $this->post_dao->getMostRetweetedPostsInLastWeek($instance->network_username, $instance->network, 5);
         $this->addToView('most_retweeted_1wk', $most_retweeted_1wk);
         $conversations = $this->post_dao->getPostsAuthorHasRepliedTo($instance->network_user_id, 5);
         $this->addToView('conversations', $conversations);
         //follows
         $follow_dao = DAOFactory::getDAO('FollowDAO');
         $least_likely_followers = $follow_dao->getLeastLikelyFollowers($instance->network_user_id, 'twitter', 16);
         $this->addToView('least_likely_followers', $least_likely_followers);
         //follower count history
         $follower_count_dao = DAOFactory::getDAO('FollowerCountDAO');
         $follower_count_history_by_day = $follower_count_dao->getHistory($instance->network_user_id, 'twitter', 'DAY');
         $this->addToView('follower_count_history_by_day', $follower_count_history_by_day);
         $first_follower_count = $follower_count_history_by_day['history'][0]['count'];
         $last_follower_count = $follower_count_history_by_day['history'][sizeof($follower_count_history_by_day['history']) - 1]['count'];
         $this->addToView('follower_count_by_day_trend', ($last_follower_count - $first_follower_count) / sizeof($follower_count_history_by_day['history']));
         $follower_count_history_by_week = $follower_count_dao->getHistory($instance->network_user_id, 'twitter', 'WEEK');
         $this->addToView('follower_count_history_by_week', $follower_count_history_by_week);
         $first_follower_count = $follower_count_history_by_week['history'][0]['count'];
         $last_follower_count = $follower_count_history_by_week['history'][sizeof($follower_count_history_by_week['history']) - 1]['count'];
         $this->addToView('follower_count_by_week_trend', ($last_follower_count - $first_follower_count) / sizeof($follower_count_history_by_week['history']));
         $post_dao = DAOFactory::getDAO('PostDAO');
         list($all_time_clients_usage, $latest_clients_usage) = $post_dao->getClientsUsedByUserOnNetwork($instance->network_user_id, $instance->network);
         // Only show the top 10 most used clients, since forever
         $all_time_clients_usage = array_merge(array_slice($all_time_clients_usage, 0, 10), array('Others' => array_sum(array_slice($all_time_clients_usage, 10))));
         $this->addToView('all_time_clients_usage', $all_time_clients_usage);
         // Only show the two most used clients for the last 25 posts
         $latest_clients_usage = array_slice($latest_clients_usage, 0, 2);
         $this->addToView('latest_clients_usage', $latest_clients_usage);
     } else {
         $this->addErrorMessage($username . " on " . ucwords($network) . " isn't set up on this ThinkUp installation.");
     }
 }
コード例 #2
0
 public function control()
 {
     /*
      * Check if the view is cached and, if it is, return the cached version before any of the application login
      * is executed.
      */
     if ($this->view_mgr->isViewCached()) {
         if ($this->view_mgr->is_cached('json.tpl', $this->getCacheKeyString())) {
             // set the json data to keep the ThinkUpController happy.
             $this->setJsonData(array());
             return $this->generateView();
         }
     }
     /*
      * Check if the API is disabled and, if it is, throw the appropriate exception.
      *
      * Docs: http://thinkupapp.com/docs/userguide/api/errors/apidisabled.html
      */
     $is_api_disabled = Config::getInstance()->getValue('is_api_disabled');
     if ($is_api_disabled) {
         throw new APIDisabledException();
     }
     // fetch the correct PostDAO and UserDAO from the DAOFactory
     $this->post_dao = DAOFactory::getDAO('PostDAO');
     $this->user_dao = DAOFactory::getDAO('UserDAO');
     /*
      * Use the information gathered from the query string to retrieve a
      * User object. This will be the standard object with which to get
      * User information from in API calls.
      */
     if ($this->user_id != null) {
         $this->user = $this->user_dao->getDetails($this->user_id, $this->network);
     } else {
         if ($this->username != null) {
             $this->user = $this->user_dao->getUserByName($this->username, $this->network);
         } else {
             $this->user = null;
         }
     }
     //Privacy checks
     if (substr($this->type, 0, 4) == 'user') {
         //user-related API call
         if (is_null($this->user)) {
             // Check why the User object is null. Could be missing required fields or not found.
             if (is_null($this->user_id) && is_null($this->username)) {
                 $m = 'A request of type ' . $this->type . ' requires a user_id or username to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 throw new UserNotFoundException();
             }
         } elseif ($this->user->is_protected) {
             //user is protected on originating network
             throw new UserNotFoundException();
         } else {
             $instance_dao = DAOFactory::getDAO('InstanceDAO');
             $instance = $instance_dao->getByUsernameOnNetwork($this->user->username, $this->user->network);
             if (isset($instance)) {
                 if (!$instance->is_public) {
                     //user is protected on ThinkUp
                     throw new UserNotFoundException();
                 }
             }
         }
     } else {
         //post-related API call
         if ($this->network == "facebook") {
             //assume all Facebook posts are private
             throw new PostNotFoundException();
         }
     }
     /*
      * This switch statement is the main part of this function. It decides
      * what type of posts will be fetched depending on the "type" GET
      * variable and use the PostDAO to fetch the appropriate posts from
      * the database.
      *
      * If a required field is missing it will create an error field to
      * output in JSON.
      */
     switch ($this->type) {
         /*
          * Gets a post.
          *
          * Required arguments: post_id
          *
          * Optional arguments: network, include_entities, include_replies, trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/post.html
          */
         case 'post':
             if (is_null($this->post_id)) {
                 $m = 'A request of type ' . $this->type . ' requires a post_id to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getPost($this->post_id, $this->network, $this->is_public);
             }
             break;
             /*
              * Gets all retweets to a post.
              *
              * Required arguments: post_id
              *
              * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
              * trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_retweets.html
              */
         /*
          * Gets all retweets to a post.
          *
          * Required arguments: post_id
          *
          * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
          * trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_retweets.html
          */
         case 'post_retweets':
             if (is_null($this->post_id)) {
                 $m = 'A request of type ' . $this->type . ' requires a post_id to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getRetweetsOfPost($this->post_id, $this->network, $this->order_by, $this->unit, $this->is_public, $this->count, $this->page);
             }
             break;
             /**
              * Gets replies to a post.
              *
              * Required arguments: post_id
              *
              * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
              * trim_user
              *
              * Ordering can only be done by either location or follower count.
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_replies.html
              */
         /**
          * Gets replies to a post.
          *
          * Required arguments: post_id
          *
          * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
          * trim_user
          *
          * Ordering can only be done by either location or follower count.
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_replies.html
          */
         case 'post_replies':
             if (is_null($this->post_id)) {
                 $m = 'A request of type ' . $this->type . ' requires a post_id to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getRepliesToPost($this->post_id, $this->network, $this->order_by, $this->unit, $this->is_public, $this->count, $this->page);
             }
             break;
             /*
              * Gets replies to a post within a date range.
              *
              * Required arguments: post_id, from and until
              *
              * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
              * trim_user
              *
              * Ordering can only be done by either location or follower count.
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_replies.html
              */
         /*
          * Gets replies to a post within a date range.
          *
          * Required arguments: post_id, from and until
          *
          * Optional arguments: network, order_by, unit, count, page, include_entities, include_replies,
          * trim_user
          *
          * Ordering can only be done by either location or follower count.
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/post_replies.html
          */
         case 'post_replies_in_range':
             if (is_null($this->post_id) || is_null($this->from) || is_null($this->until)) {
                 $m = 'A request of type ' . $this->type . ' requires a post_id to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getRepliesToPostInRange($this->post_id, $this->network, $this->from, $this->until, $this->order_by, $this->unit, $this->is_public, $this->count, $this->page);
             }
             break;
             /*
              * Get posts related to a post (replies to it, retweets of it).
              *
              * Required arguments: post_id
              *
              * Optional arguments: network, count, page, geo_encoded_only, include_original_post, include_entities,
              * include_replies, trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/related_posts.html
              */
         /*
          * Get posts related to a post (replies to it, retweets of it).
          *
          * Required arguments: post_id
          *
          * Optional arguments: network, count, page, geo_encoded_only, include_original_post, include_entities,
          * include_replies, trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/related_posts.html
          */
         case 'related_posts':
             if (is_null($this->post_id)) {
                 $m = 'A request of type ' . $this->type . ' requires a post_id to be specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getRelatedPosts($this->post_id, $this->network, $this->is_public, $this->count, $this->page, $geo_encoded_only = false, $include_original_post = false);
             }
             break;
             /*
              * Gets the user's most replied to posts.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, include_entities, include_replies, trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_most_replied_to.html
              */
         /*
          * Gets the user's most replied to posts.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, include_entities, include_replies, trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_most_replied_to.html
          */
         case 'user_posts_most_replied_to':
             $data = $this->post_dao->getMostRepliedToPosts($this->user->user_id, $this->network, $this->count, $this->page, $this->is_public);
             break;
             /*
              * Gets the user's most retweeted posts.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, include_entities, include_replies, trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_most_retweeted.html
              */
         /*
          * Gets the user's most retweeted posts.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, include_entities, include_replies, trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_most_retweeted.html
          */
         case 'user_posts_most_retweeted':
             $data = $this->post_dao->getMostRetweetedPosts($this->user->user_id, $this->network, $this->count, $this->page, $this->is_public);
             break;
             /*
              * Gets posts a user has made.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts.html
              */
         /*
          * Gets posts a user has made.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts.html
          */
         case 'user_posts':
             $data = $this->post_dao->getAllPosts($this->user->user_id, $this->network, $this->count, $this->page, true, $this->order_by, $this->direction, $this->is_public);
             break;
             /*
              * Gets posts a user has made.
              *
              * Required arguments: user_id or username, from and until
              *
              * Optional arguments: network, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_in_range.html
              */
         /*
          * Gets posts a user has made.
          *
          * Required arguments: user_id or username, from and until
          *
          * Optional arguments: network, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_posts_in_range.html
          */
         case 'user_posts_in_range':
             if (is_null($this->from) || is_null($this->until)) {
                 $m = 'A request of type ' . $this->type . ' requires valid from and until parameters to be ';
                 $m .= 'specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getPostsByUserInRange($this->user->user_id, $this->network, $this->from, $this->until, $this->order_by, $this->direction, $iterator = false, $this->is_public);
             }
             break;
             /*
              * Gets posts a user is mentioned in.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, include_rts, include_entities, include_replies, trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_mentions.html
              */
         /*
          * Gets posts a user is mentioned in.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, include_rts, include_entities, include_replies, trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_mentions.html
          */
         case 'user_mentions':
             $data = $this->post_dao->getAllMentions($this->user->username, $this->count, $this->network, $this->page, $this->is_public, $this->include_rts, $this->order_by, $this->direction);
             break;
             /*
              * Gets posts a user is mentioned in.within a date range
              *
              * Required arguments: user_id or username, from and until
              *
              * Optional arguments: network, count, page, include_rts, include_entities, include_replies, trim_user
              */
         /*
          * Gets posts a user is mentioned in.within a date range
          *
          * Required arguments: user_id or username, from and until
          *
          * Optional arguments: network, count, page, include_rts, include_entities, include_replies, trim_user
          */
         case 'user_mentions_in_range':
             if (is_null($this->from) || is_null($this->until)) {
                 $m = 'A request of type ' . $this->type . ' requires valid from and until parameters to be ';
                 $m .= 'specified.';
                 throw new RequiredArgumentMissingException($m);
             } else {
                 $data = $this->post_dao->getAllMentionsInRange($this->user->username, $this->count, $this->network, $this->from, $this->until, $this->page, $this->is_public, $this->include_rts, $this->order_by, $this->direction);
             }
             break;
             /*
              * Gets question posts a user has made.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_questions.html
              */
         /*
          * Gets question posts a user has made.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_questions.html
          */
         case 'user_questions':
             $data = $this->post_dao->getAllQuestionPosts($this->user->user_id, $this->network, $this->count, $this->page, $this->order_by, $this->direction, $this->is_public);
             break;
             /*
              * Gets question posts a user has made within a date range
              *
              * Required arguments: user_id or username, from and until
              *
              * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_questions.html
              */
         /*
          * Gets question posts a user has made within a date range
          *
          * Required arguments: user_id or username, from and until
          *
          * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/posts/user_questions.html
          */
         case 'user_questions_in_range':
             $data = $this->post_dao->getAllQuestionPostsInRange($this->user->user_id, $this->network, $this->count, $this->from, $this->until, $this->page, $this->order_by, $this->direction, $this->is_public);
             break;
             /*
              * Gets replies to a user.
              *
              * Required arguments: user_id or username
              *
              * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * http://thinkupapp.com/docs/userguide/api/posts/user_replies.html
              */
         /*
          * Gets replies to a user.
          *
          * Required arguments: user_id or username
          *
          * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * http://thinkupapp.com/docs/userguide/api/posts/user_replies.html
          */
         case 'user_replies':
             $data = $this->post_dao->getAllReplies($this->user->user_id, $this->network, $this->count, $this->page, $this->order_by, $this->direction, $this->is_public);
             break;
             /*
              * Gets replies to a user within a date range.
              *
              * Required arguments: user_id or username, from and until
              *
              * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
              * trim_user
              *
              * http://thinkupapp.com/docs/userguide/api/posts/user_replies.html
              */
         /*
          * Gets replies to a user within a date range.
          *
          * Required arguments: user_id or username, from and until
          *
          * Optional arguments: network, count, page, order_by, direction, include_entities, include_replies,
          * trim_user
          *
          * http://thinkupapp.com/docs/userguide/api/posts/user_replies.html
          */
         case 'user_replies_in_range':
             $data = $this->post_dao->getAllRepliesInRange($this->user->user_id, $this->network, $this->count, $this->from, $this->until, $this->page, $this->order_by, $this->direction, $this->is_public);
             break;
             /*
              * Generate an error because the API call type was not recognized.
              *
              * Docs: http://thinkupapp.com/docs/userguide/api/errors/apicalltypenotrecognised.html
              */
         /*
          * Generate an error because the API call type was not recognized.
          *
          * Docs: http://thinkupapp.com/docs/userguide/api/errors/apicalltypenotrecognised.html
          */
         default:
             throw new APICallTypeNotRecognizedException($this->type);
             break;
     }
     if (is_null($data)) {
         throw new PostNotFoundException();
     }
     switch ($this->network) {
         case 'twitter':
             if (is_array($data)) {
                 foreach ($data as $key => $post) {
                     $data[$key] = $this->convertPostToTweet($post);
                 }
             } else {
                 $data = $this->convertPostToTweet($data);
             }
             break;
         case 'facebook':
             // TODO: write a function here to convert to Facebook API style
             break;
         default:
             break;
     }
     // if no posts were found, $data is null. Set it to an empty array.
     if (is_null($data)) {
         $data = array();
     }
     $this->setJsonData($data);
     return $this->generateView();
 }
コード例 #3
0
ファイル: inline.view.php プロジェクト: jrunning/thinktank
 $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));
         break;
     case "tweets-convo":
         $s->assign('header', 'Conversations');
         $s->assign('author_replies', $pd->getPostsAuthorHasRepliedTo($i->network_user_id, 15));
         break;
     case "mentions-all":
         $s->assign('header', 'All Mentions');
         $s->assign('description', 'Any post that mentions you');
         $s->assign('all_mentions', $pd->getAllMentions($i->network_username, 15));
         $s->assign('all_tweets', $pd->getAllPosts($cfg->twitter_user_id, 15));
         break;
     case "mentions-allreplies":
         $s->assign('header', 'Replies');
         $s->assign('description', 'Posts that directly reply to you (i.e., start with your name)');
         $s->assign('all_replies', $pd->getAllReplies($i->network_user_id, 15));