public static function fromGnip($json) { // Parse JSON when fed JSON string if (is_string($json)) { $object = json_decode($json); } else { if (is_object($json)) { $object = $json; } else { throw new Exception("Invalid JSON input:\n[[{$json}]]\n"); } } $t = new self(null); if (!isset($object->id)) { return false; } $t->id = preg_replace("/tag:.*:/", "", $object->id); $t->id_str = $t->id; $t->created_at = $object->postedTime; $t->text = $object->body; if (isset($object->actor->location)) { $t->location = $object->actor->location->displayName; } $t->from_user_name = $object->actor->preferredUsername; $t->from_user_id = str_replace("id:twitter.com:", "", $object->actor->id); $t->from_user_url = $object->actor->link; $t->from_user_lang = $object->actor->languages[0]; $t->from_user_tweetcount = $object->actor->statusesCount; $t->from_user_followercount = $object->actor->followersCount; $t->from_user_friendcount = $object->actor->friendsCount; $t->from_user_favourites_count = $object->actor->favoritesCount; $t->from_user_realname = $object->actor->displayName; $t->from_user_listed = $object->actor->listedCount; $t->from_user_utcoffset = $object->actor->utcOffset; $t->from_user_timezone = $object->actor->twitterTimeZone; $t->from_user_description = $object->actor->summary; $t->from_user_profile_image_url = $object->actor->image; $t->from_user_verified = $object->actor->verified; $t->from_user_timezone = null; if (isset($object->twitterTimeZone)) { $t->from_user_timezone = $object->twitterTimeZone; } $t->source = $object->generator->displayName; if (isset($object->geo) && $object->geo->type == "Point") { $t->geo->coordinates[0] = $object->geo->coordinates[0]; $t->geo->coordinates[1] = $object->geo->coordinates[1]; } $t->in_reply_to_user_id = null; // @todo $t->in_reply_to_screen_name = null; // @todo $t->in_reply_to_status_id = null; // @todo $t->retweet_count = $object->retweetCount; if ($t->retweet_count != 0 && isset($object->object)) { $t->retweet_id = preg_replace("/tag:.*:/", "", $object->object->id); } if (isset($object->twitter_filter_level)) { $t->filter_level = $object->twitter_filter_level; } else { $t->filter_level = 'none'; } if (isset($object->twitter_entities->twitter_lang)) { $t->lang = $object->twitter_entities->twitter_lang; } $t->favorite_count = $object->favoritesCount; // @todo: support for setting places in Gnip import $t->place_ids = array(); $t->places = array(); // @todo: support extended media entities in Gnip import, and setting photo_size_xy, and media_typ $t->urls = $object->twitter_entities->urls; $t->user_mentions = $object->twitter_entities->user_mentions; $t->hashtags = $object->twitter_entities->hashtags; if (count($t->user_mentions) > 0) { $t->in_reply_to_user_id_str = $t->user_mentions[0]->id_str; $t->in_reply_to_screen_name = $t->user_mentions[0]->screen_name; } if (isset($object->user_withheld->withheld_in_countries)) { $t->withheld_in_countries = $object->user_withheld->withheld_in_countries; } else { $t->withheld_in_countries = array(); } if (isset($object->status_withheld->withheld_in_countries)) { $t->from_user_withheld_in_countries = $object->status_withheld->withheld_in_countries; } else { $t->from_user_withheld_in_countries = array(); } $t->fromComplete(); return $t; }