You are here

function twitter_puller::parse_items in Twitter Pull 6.2

Same name and namespace in other branches
  1. 6 twitter_pull.class.inc \twitter_puller::parse_items()
  2. 7.2 twitter_pull.class.inc \twitter_puller::parse_items()
  3. 7 twitter_pull.class.inc \twitter_puller::parse_items()
2 calls to twitter_puller::parse_items()
twitter_puller::get_items in ./twitter_pull.class.inc
twitter_puller::twitter_get_items in ./twitter_pull.class.inc
Use the twitter module to get the results.

File

./twitter_pull.class.inc, line 182
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();

      // Convert arrays to objects.
      $item = json_decode(json_encode($item), FALSE);
      $user = !empty($item->retweeted_status) ? $item->retweeted_status->user : $item->user;

      // when importing lists $user is an array and not an object, secure $user as object.
      $user = (object) $user;
      $obj->id = check_plain($item->id_str);

      // The name is the user's 'human-readable' name.
      $obj->username = check_plain(!empty($user->name) ? $user->name : $item->from_user);

      // The screen_name is the Twitter machine name, i.e., the string that is
      // commonly seen with an '@' prefixed.
      $obj->screenname = check_plain(!empty($user->screen_name) ? $user->screen_name : $item->from_user);

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

      //-- Convert date to unix timestamp so themers can easily work with it.

      //-- We need to suppress possible warnings (in PHP 5.3+) related to non-set timezones because

      //-- Drupal6 does not save proper timezones (just offsets) and there's no good way to fix this.
      $obj->timestamp = @strtotime($item->created_at);
      $obj->time_ago = t('!time ago.', array(
        '!time' => format_interval(time() - $obj->timestamp),
      ));
      $tweets[] = $obj;
    }
  }
  $this->tweets = $tweets;
}