You are here

function twitter_puller::parse_items in Twitter Pull 7

Same name and namespace in other branches
  1. 6.2 twitter_pull.class.inc \twitter_puller::parse_items()
  2. 6 twitter_pull.class.inc \twitter_puller::parse_items()
  3. 7.2 twitter_pull.class.inc \twitter_puller::parse_items()
1 call to twitter_puller::parse_items()
twitter_puller::get_items in ./twitter_pull.class.inc

File

./twitter_pull.class.inc, line 96
twitter pull class implementation

Class

twitter_puller
@file twitter pull class implementation

Code

function parse_items($items) {
  $tweets = array();

  //-- If search response then items are one level lower.
  if (isset($items->results) && is_array($items->results)) {
    $items = $items->results;
  }
  if (is_array($items)) {
    $items = array_slice($items, 0, $this->num_items);
    foreach ($items as $item) {
      $obj = new stdClass();
      if (isset($item->retweeted_status)) {
        $obj->id = check_plain($item->retweeted_status->id_str);
        $obj->username = isset($item->retweeted_status->user) && !empty($item->retweeted_status->user->screen_name) ? $item->retweeted_status->user->screen_name : $item->retweeted_status->from_user;
        $obj->username = check_plain($obj->username);

        //get the user photo for the retweet
        $obj->userphoto = isset($item->retweeted_status->user) && !empty($item->retweeted_status->user->profile_image_url) ? $item->retweeted_status->user->profile_image_url : $item->retweeted_status->profile_image_url;
        $obj->userphoto = check_plain($obj->userphoto);
        $obj->userphoto_https = isset($item->retweeted_status->user) && !empty($item->retweeted_status->user->profile_image_url_https) ? $item->retweeted_status->user->profile_image_url_https : $item->retweeted_status->profile_image_url_https;
        $obj->userphoto_https = check_plain($obj->userphoto_https);
        $obj->text = filter_xss($item->retweeted_status->text);

        //-- Convert date to unix timestamp so themer can easily work with it.
        $obj->timestamp = strtotime($item->retweeted_status->created_at);
      }
      else {
        $obj->id = check_plain($item->id_str);
        $obj->username = isset($item->user) && !empty($item->user->screen_name) ? $item->user->screen_name : $item->from_user;
        $obj->username = check_plain($obj->username);

        //retrieve the user photo
        $obj->userphoto = isset($item->user) && !empty($item->user->profile_image_url) ? $item->user->profile_image_url : $item->profile_image_url;
        $obj->userphoto = check_plain($obj->userphoto);
        $obj->userphoto_https = isset($item->user) && !empty($item->user->profile_image_url_https) ? $item->user->profile_image_url_https : $item->profile_image_url_https;
        $obj->userphoto_https = check_plain($obj->userphoto_https);
        $obj->text = filter_xss($item->text);

        //-- Convert date to unix timestamp so themer can easily work with it.
        $obj->timestamp = strtotime($item->created_at);
      }
      $tweets[] = $obj;
    }
  }
  $this->tweets = $tweets;
}