示例#1
0
 private function createPost($event, $status)
 {
     if (isset($status->retweeted_status) || isset($status->quoted_status)) {
         return null;
     }
     $statusUrl = "https://twitter.com/statuses/" . $status->id_str;
     try {
         return \relive\models\Post::where('postURL', '=', $statusUrl)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         $rankPoints = $this->rankPost($status);
         //$datetime = new \DateTime();
         //$datetime->setTimestamp(strtotime($status->created_at));
         $post = \relive\models\Post::firstOrCreate(['datetime' => strtotime($status->created_at), 'postURL' => htmlspecialchars($statusUrl, ENT_QUOTES, 'UTF-8'), 'author' => htmlspecialchars($status->user->screen_name, ENT_QUOTES, 'UTF-8'), 'caption' => htmlspecialchars($status->text, ENT_QUOTES, 'UTF-8'), 'provider_id' => $this->provider->provider_id, 'rankPoints' => $rankPoints]);
         if (isset($status->entities->hashtags)) {
             $this->createHashtags($post, $status);
         }
         if (isset($status->entities->media)) {
             foreach ($status->entities->media as $twitter_media) {
                 $media = \relive\models\Media::create(['post_id' => $post->post_id, 'type' => htmlspecialchars($twitter_media->type, ENT_QUOTES, 'UTF-8')]);
                 $this->createMediaUrls($media->media_id, $twitter_media);
             }
         }
         $relationship = \relive\models\PostEventRelationship::firstOrCreate(['event_id' => $event->event_id, 'post_id' => $post->post_id, 'isFiltered' => 0]);
         return $post;
     }
 }
示例#2
0
 private function createPost($event, $instaPost)
 {
     if ($instaPost->type === "image") {
         try {
             return \relive\models\Post::where('postURL', '=', $instaPost->link)->firstOrFail();
         } catch (ModelNotFoundException $e) {
             $rankPoints = $this->rankPost($instaPost);
             //$datetime = new \DateTime();
             //$datetime->setTimestamp($instaPost->created_time);
             $post = \relive\models\Post::firstOrCreate(['datetime' => $instaPost->created_time, 'postURL' => htmlspecialchars($instaPost->link, ENT_QUOTES, 'UTF-8'), 'author' => htmlspecialchars($instaPost->user->username, ENT_QUOTES, 'UTF-8'), 'caption' => htmlspecialchars($instaPost->caption->text, ENT_QUOTES, 'UTF-8'), 'provider_id' => $this->provider->provider_id, 'rankPoints' => $rankPoints]);
             if (isset($instaPost->tags)) {
                 $this->createHashtags($post, $instaPost);
             }
             if (isset($instaPost->images)) {
                 $this->saveImageUrls($post, $instaPost->images);
             }
             $relationship = \relive\models\PostEventRelationship::firstOrCreate(['event_id' => $event->event_id, 'post_id' => $post->post_id, 'isFiltered' => 0]);
             return $post;
         }
     }
 }
示例#3
0
 private function createPost($event, $gPlusPost)
 {
     if ($gPlusPost->verb === "post" && (!isset($gPlusPost->object->attachments) || $gPlusPost->object->attachments[0]->objectType === "photo" || $gPlusPost->object->attachments[0]->objectType === "album")) {
         try {
             return \relive\models\Post::where('postURL', '=', $gPlusPost->url)->firstOrFail();
         } catch (ModelNotFoundException $e) {
             $rankPoints = $this->rankPost($gPlusPost);
             $content = htmlspecialchars(strip_tags($gPlusPost->object->content), ENT_QUOTES, 'UTF-8');
             $post = \relive\models\Post::firstOrCreate(['datetime' => strtotime($gPlusPost->published), 'postURL' => htmlspecialchars($gPlusPost->url, ENT_QUOTES, 'UTF-8'), 'author' => htmlspecialchars($gPlusPost->actor->displayName, ENT_QUOTES, 'UTF-8'), 'caption' => $content, 'provider_id' => $this->provider->provider_id, 'rankPoints' => $rankPoints]);
             $this->createHashtags($post, $content);
             if (isset($gPlusPost->object->attachments)) {
                 if ($gPlusPost->object->attachments[0]->objectType === "photo") {
                     $media = \relive\models\Media::create(['post_id' => $post->post_id, 'type' => 'photo']);
                     $this->saveImageUrls($media->media_id, $gPlusPost->object->attachments[0]->fullImage);
                 } else {
                     if ($gPlusPost->object->attachments[0]->objectType === "album") {
                         $media = \relive\models\Media::create(['post_id' => $post->post_id, 'type' => 'photo']);
                         $thumbnails = $gPlusPost->object->attachments[0]->thumbnails;
                         $count = 0;
                         foreach ($thumbnails as $thumbnail) {
                             $result = $this->saveImageUrls($media->media_id, $gPlusPost->object->attachments[0]->image);
                             if ($result) {
                                 $count++;
                             }
                         }
                         if ($count === 0) {
                             $media->delete();
                         }
                     }
                 }
             }
             $relationship = \relive\models\PostEventRelationship::firstOrCreate(['event_id' => $event->event_id, 'post_id' => $post->post_id, 'isFiltered' => 0]);
             return $post;
         }
     }
 }