Exemple #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;
     }
 }
 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;
         }
     }
 }
Exemple #3
0
     }
     \relive\misc\FacebookPagePoster::post($event->event_id);
     \relive\models\CrawlJob::create(['event_id' => $event->event_id]);
     $event->save();
 }
 if (isset($_GET['deleteevent'])) {
     $event_id = $_GET['event_id'];
     \relive\models\Event::find($event_id)->delete();
     \relive\models\Post::whereNotIn('post_id', function ($query) {
         $query->select('post_id')->from('posteventrelationships');
     })->delete();
 }
 if (isset($_GET['post_id'])) {
     if (isset($_GET['filter'])) {
         $post = \relive\models\PostEventRelationship::whereIn('post_id', function ($query) {
             $query->select('post_id')->from('reports')->where('post_id', '=', $_GET['post_id']);
         })->first();
         $post->isFiltered = 1;
         $post->save();
         $report = \relive\models\Report::where('post_id', '=', $_GET['post_id'])->get();
         foreach ($report as $rep) {
             $rep->isSettled = 1;
             $rep->save();
         }
     } else {
         if (isset($_GET['settle'])) {
             $report = \relive\models\Report::where('post_id', '=', $_GET['post_id'])->get();
             foreach ($report as $rep) {
                 $rep->isSettled = 1;
                 $rep->save();
             }
Exemple #4
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;
         }
     }
 }
Exemple #5
0
<?php

require_once '/var/www/vendor/autoload.php';
use relive\models\Event;
use relive\models\Post;
use relive\models\PostEventRelationship;
foreach (Event::all() as $event) {
    $event_id = $event->event_id;
    $count = PostEventRelationship::where('event_id', '=', $event_id)->count();
    if ($count > 500) {
        $post = Post::whereIn('post_id', function ($query) use($event_id) {
            $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event_id);
        })->orderBy('rankPoints', 'asc')->offset($count * 0.35)->limit(1)->first();
        $rankPoints = $post->rankPoints;
        PostEventRelationship::whereIn('post_id', function ($query) use($rankPoints) {
            $query->select('post_id')->from('posts')->where('rankPoints', '<', $rankPoints);
        })->where('event_id', '=', $event_id)->update(['isFiltered' => 1]);
        PostEventRelationship::whereIn('post_id', function ($query) use($rankPoints) {
            $query->select('post_id')->from('posts')->where('rankPoints', '>=', $rankPoints);
        })->where('event_id', '=', $event_id)->update(['isFiltered' => 0]);
    }
}
Exemple #6
0
 public static function reportPostFromEvent($event_id)
 {
     $app = \Slim\Slim::getInstance();
     $allPostVars = $app->request->post();
     $post_id = @$allPostVars['post_id'] ? $allPostVars['post_id'] : -1;
     if (isset($post_id) && $post_id != -1) {
         try {
             $relationship = \relive\models\PostEventRelationship::where('event_id', '=', $event_id)->where('post_id', '=', $post_id)->firstOrFail();
             $report = \relive\models\Report::create(['report_time' => time(), 'post_id' => $post_id]);
             echo json_encode($report, JSON_UNESCAPED_SLASHES);
         } catch (ModelNotFoundException $e) {
             $app->render(404, ['Status' => 'Relationship not found']);
         }
     }
 }