示例#1
0
 public static function getPostsForEvent($event_id)
 {
     $app = \Slim\Slim::getInstance();
     //return all post
     $allGetVars = $app->request->get();
     //default startAt = 0, limit = 15
     $startAt = @$allGetVars['startAt'] ? intval($allGetVars['startAt']) : 0;
     $limit = @$allGetVars['limit'] ? $allGetVars['limit'] : 15;
     $orderBy = @$allGetVars['orderBy'] ? $allGetVars['orderBy'] : "datetime";
     if (!filter_var($event_id, FILTER_VALIDATE_INT) || !filter_var($limit, FILTER_VALIDATE_INT)) {
         $app->render(400, ['Status' => 'Invalid event id.']);
         return;
     }
     if ($orderBy != "post_id") {
         $orderBy = "datetime";
     }
     $event = \relive\models\Event::find($event_id);
     if ($event) {
         $event->rankPoints = $event->rankPoints + 1;
         $event->save();
         $crawljob = \relive\models\CrawlJob::where('event_id', '=', $event_id)->first();
         if ($crawljob) {
             $crawljob->delay = 10;
             $crawljob->save();
         }
         $posts = \relive\models\Post::whereIn('post_id', function ($query) use($event_id) {
             $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event_id)->where('isFiltered', False);
         })->orderBy('datetime', 'desc')->offset($startAt)->limit($limit)->get();
         echo json_encode($posts, JSON_UNESCAPED_SLASHES);
     } else {
         $app->render(404, ['Status', 'Event not found.']);
     }
 }
示例#2
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;
     }
 }
示例#3
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;
         }
     }
 }
示例#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;
         }
     }
 }
示例#5
0
            }
        }
        if (isset($_GET['updateevent'])) {
            $event_id = $_GET['event_id'];
            $event = \relive\models\Event::find($event_id);
            $event->eventName = $_GET['eventName'];
            $event->startDate = strtotime($_GET['startDate']);
            $event->endDate = strtotime($_GET['endDate']);
            $event->save();
            \relive\models\EventHashtagRelationship::where('event_id', '=', $event_id)->delete();
            $hashtags = array();
            if (isset($_GET['hashtag1']) && $_GET['hashtag1'] !== '') {
                $hashtags[] = $_GET['hashtag1'];
            }
            if (isset($_GET['hashtag2']) && $_GET['hashtag2'] !== '') {
                $hashtags[] = $_GET['hashtag2'];
            }
            if (isset($_GET['hashtag3']) && $_GET['hashtag3'] !== '') {
                $hashtags[] = $_GET['hashtag3'];
            }
            foreach ($hashtags as $tag) {
                $hashtag = \relive\models\Hashtag::firstOrCreate(['hashtag' => $tag]);
                $eventhashtagrelationship = \relive\models\EventHashtagRelationship::firstOrCreate(['event_id' => $event_id, 'hashtag_id' => $hashtag->hashtag_id]);
            }
        }
    }
    $unpublishedEvents = \relive\models\Event::where('isPublished', '=', '0')->get();
    $publishedEvents = \relive\models\Event::where('isPublished', '=', '1')->get();
    $reportedPosts = \relive\models\Post::join('reports', 'posts.post_id', '=', 'reports.post_id')->groupBy('posts.post_id')->selectRaw('*,(select count(*) from reports c where c.post_id = posts.post_id) as `count`')->where('isSettled', '=', 0)->orderBy('datetime', 'desc')->get();
    include './relive/templates/moderate.php';
}
示例#6
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]);
    }
}
示例#7
0
require_once '/var/www/vendor/autoload.php';
if (isset($_GET['event_id'])) {
    $event = \relive\models\SearchIndex::find($_GET['event_id']);
}
if ($event) {
    $hashtags = \relive\models\Hashtag::whereIn('hashtag_id', function ($query) use($event) {
        $query->select('hashtag_id')->from('eventhashtagrelationships')->where('event_id', '=', $event->event_id);
    })->select('hashtag')->get();
    $tags = [];
    foreach ($hashtags as $hashtag) {
        array_push($tags, $hashtag->hashtag);
    }
    $keyword = join(',', $tags);
    $posts = \relive\models\Post::whereIn('post_id', function ($query) use($event) {
        $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event->event_id)->where('isFiltered', False);
    })->orderBy('datetime', 'desc')->offset(0)->limit(15)->get();
} else {
    header("Location: http://relive.space/");
}
?>
<!DOCTYPE html>
<html lang="en">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb##">
    <meta charset="UTF-8">
    <title>relive</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon" sizes="57x57" href="//relive.space/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="//relive.space/apple-touch-icon-60x60.png">