+ // There are no media entities? So we quit.
+ if (!is_array($post->extended_entities->media)) {
+ return "";
+ }
+
+ // When the post links to an external page, we only take one picture.
+ // This could be improved in the future.
+ if (count($post->entities->urls) > 0) {
+ $picture = "";
+ foreach($post->extended_entities->media AS $medium) {
+ if (isset($medium->media_url_https)) {
+ $picture = $medium->media_url_https;
+ $postarray['body'] = str_replace($medium->url, "", $postarray['body']);
+ }
+ }
+ return $picture;
+ }
+
+ // This is a pure media post, first search for all media urls
+ $media = array();
+ foreach($post->extended_entities->media AS $medium) {
+ switch($medium->type) {
+ case 'photo':
+ $media[$medium->url] .= "\n[img]".$medium->media_url_https."[/img]";
+ $postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
+ break;
+ case 'video':
+ case 'animated_gif':
+ $media[$medium->url] .= "\n[img]".$medium->media_url_https."[/img]";
+ $postarray['object-type'] = ACTIVITY_OBJ_VIDEO;
+ if (is_array($medium->video_info->variants)) {
+ $bitrate = 0;
+ // We take the video with the highest bitrate
+ foreach ($medium->video_info->variants AS $variant) {
+ if (($variant->content_type == "video/mp4") AND ($variant->bitrate >= $bitrate)) {
+ $media[$medium->url] = "\n[video]".$variant->url."[/video]";
+ $bitrate = $variant->bitrate;
+ }
+ }
+ }
+ break;
+ // The following code will only be activated for test reasons
+ //default:
+ // $postarray['body'] .= print_r($medium, true);
+ }
+ }
+
+ // Now we replace the media urls.
+ foreach ($media AS $key => $value) {
+ $postarray['body'] = str_replace($key, "\n".$value."\n", $postarray['body']);
+ }
+ return "";
+}
+
+function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing_contact, $noquote) {