Пример #1
0
 protected function createFakeComment(Content $content)
 {
     $comment = Comment::create(['content_id' => $content->getKey(), 'created_at' => $this->faker->dateTimeThisDecade, 'text' => $this->faker->text(512), 'user_id' => $this->getRandomUser()->getKey()]);
     $repliesNumber = $this->faker->numberBetween(0, 3);
     for ($i = 0; $i < $repliesNumber; $i++) {
         $this->createFakeCommentReply($comment);
     }
 }
Пример #2
0
 public function show($groupName)
 {
     $group = Group::name($groupName)->with('creator')->firstOrFail();
     $group->checkAccess();
     $stats = ['contents' => intval(Content::where('group_id', $group->getKey())->count()), 'comments' => intval(Content::where('group_id', $group->getKey())->sum('comments')), 'entries' => intval(Entry::where('group_id', $group->getKey())->count()), 'banned' => intval(GroupBan::where('group_id', $group->getKey())->count()), 'subscribers' => $group->subscribers, 'moderators' => intval(GroupModerator::where('group_id', $group->getKey())->count())];
     return array_merge($group->toArray(), ['stats' => $stats]);
 }
Пример #3
0
 public function removeContent(Request $request)
 {
     $id = hashids_decode($request->get('content'));
     $content = Content::findOrFail($id);
     $content->usave()->delete();
     return Response::json(['status' => 'ok']);
 }
Пример #4
0
 public function fire($job, $data)
 {
     $content = Content::findOrFail($data['id']);
     $content->autoThumbnail();
     $job->delete();
     Pusher::trigger('content-' . $content->getKey(), 'loaded-thumbnail', ['url' => $content->getThumbnailPath()]);
 }
Пример #5
0
 public function delete()
 {
     foreach ($this->replies as $reply) {
         $reply->delete();
     }
     Content::where('id', $this->content_id)->decrement('comments_count');
     return parent::delete();
 }
Пример #6
0
 public function getURLTitle()
 {
     $url = Input::get('url');
     try {
         $client = new Client($url);
         $response = $client->get()->send();
     } catch (Exception $e) {
         return Response::json(['status' => 'error']);
     }
     // Only HTML content-type is supported
     $contentType = $response->getHeader('Content-Type');
     if (strpos($contentType, 'text/html') === false) {
         return Response::json(['status' => 'error']);
     }
     $html = $response->getBody();
     // Fix for HTML5
     $html = preg_replace('/<meta charset="(.+)">/', '<meta http-equiv="Content-Type" content="text/html; charset=$1">', $html);
     $contentType = $response->getHeader('Content-Type');
     // Small hack to use encoding used on the given page
     $encodingHint = '';
     if (preg_match('/charset=(.*)/', $contentType, $results)) {
         $encodingHint = '<meta http-equiv="Content-Type" content="text/html; charset=' . $results[1] . '">';
     }
     $doc = new \DOMDocument('1.0', 'UTF-8');
     @$doc->loadHTML($encodingHint . $html);
     $xpath = new \DOMXPath($doc);
     $title = '';
     $description = '';
     // Try to get OpenGraph data first
     try {
         $title = $xpath->query('/html/head/meta[@property="og:title"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
     } catch (Exception $e) {
     }
     try {
         $description = $xpath->query('/html/head/meta[@property="og:description"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
     } catch (Exception $e) {
     }
     // Use title and meta data if OpenGraph data wasn't found
     try {
         if (empty($title)) {
             $title = $xpath->query('/html/head/title')->item(0)->nodeValue;
         }
     } catch (Exception $e) {
     }
     try {
         if (empty($description)) {
             $description = $xpath->query('/html/head/meta[@name="description"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
         }
     } catch (Exception $e) {
     }
     $title = Str::limit($title, 128);
     $description = Str::limit($description, 255);
     // Find duplicates
     $duplicates = Content::where('url', $url)->where('group_id', Input::get('group'))->get(['title', 'group_id'])->toArray();
     return Response::json(['status' => 'ok', 'title' => $title, 'description' => $description, 'duplicates' => $duplicates]);
 }
Пример #7
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $dayBefore = Carbon::now()->subDay();
     $content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail();
     $params = ['access_token' => config('social.facebook.page_token'), 'name' => $content->title, 'link' => route('content_comments', $content->getKey()), 'description' => $content->description];
     if ($content->thumbnail) {
         $params['picture'] = $content->getThumbnailPath(500, 250);
     }
     Guzzle::post('https://graph.facebook.com/strimoid/feed', ['body' => $params]);
 }
Пример #8
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $dayBefore = Carbon::now()->subDay();
     $content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail();
     $client = new Client(['base_url' => 'https://api.twitter.com/1.1/', 'defaults' => ['auth' => 'oauth']]);
     $oauth = new Oauth1(['consumer_key' => config('social.twitter.consumer_key'), 'consumer_secret' => config('social.twitter.consumer_secret'), 'token' => config('social.twitter.token'), 'token_secret' => config('social.twitter.token_secret')]);
     $client->getEmitter()->attach($oauth);
     $params = ['status' => Str::limit($content->title, 100) . ' https://strm.pl/c/' . $content->hashId()];
     $client->post('statuses/update.json', ['body' => $params]);
 }
Пример #9
0
 public function getURLTitle()
 {
     $url = request('url');
     $data = OEmbed::getData($url);
     $title = data_get($data, 'meta.title', '');
     $title = str_limit($title, 128);
     $description = data_get($data, 'meta.description', '');
     $description = str_limit($description, 255);
     // Find duplicates
     $duplicates = Content::where('url', $url)->get(['title', 'group_id'])->toArray();
     return ['status' => 'ok', 'title' => $title, 'description' => $description, 'duplicates' => $duplicates];
 }
Пример #10
0
 public function fire($job, $data)
 {
     $content = Content::findOrFail($data['id']);
     $url = Config::get('app.iframely_host') . '/oembed';
     $response = Guzzle::get($url, ['query' => ['url' => $content->url]])->json();
     $content->type = $response['type'];
     $content->save();
     if ($data['thumbnail'] && array_key_exists('thumbnail_url', $response)) {
         $content->setThumbnail($response['thumbnail_url']);
     }
     $content->autoThumbnail();
     WS::send(json_encode(['topic' => 'content.' . $content->getKey() . '.thumbnail', 'url' => $content->getThumbnailPath(100, 75)]));
     $content->unset('thumbnail_loading');
     $job->delete();
 }
Пример #11
0
 /**
  * @return mixed
  */
 public function saveThumbnail()
 {
     $id = hashids_decode(request('id'));
     $content = Content::findOrFail($id);
     $thumbnails = session('thumbnails', []);
     if (!$content->canEdit(user())) {
         return redirect()->route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.');
     }
     $index = (int) request('thumbnail');
     if (request()->has('thumbnail') && isset($thumbnails[$index])) {
         $content->setThumbnail($thumbnails[$index]);
     } else {
         $content->removeThumbnail();
     }
     return redirect()->route('content_comments', $content);
 }
Пример #12
0
 public function search()
 {
     if (Input::has('q')) {
         $keywords = preg_replace('/((\\w+):(\\w+\\pL.))+\\s?/i', '', Input::get('q'));
         switch (Input::get('t')) {
             case 'e':
                 $builder = Entry::where('text', 'like', '%' . $keywords . '%');
                 break;
             case 'g':
                 $builder = Group::where('name', 'like', '%' . $keywords . '%')->orWhere('urlname', 'like', '%' . $keywords . '%');
                 break;
             case 'c':
             default:
                 $builder = Content::where(function ($query) use($keywords) {
                     $query->where('title', 'like', '%' . $keywords . '%')->orWhere('description', 'like', '%' . $keywords . '%');
                 });
                 break;
         }
         $this->builder = $builder;
         $this->setupFilters(Input::get('q'));
         $results = $this->builder->paginate(25);
     }
     return view('search.main', compact('results'));
 }
Пример #13
0
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function softRemoveContent()
 {
     $id = hashids_decode(request('id'));
     $content = Content::findOrFail($id);
     if ($content->canRemove(user())) {
         $content->deletedBy()->associate(user());
         $content->save();
         $content->delete();
         return Response::json(['status' => 'ok']);
     }
     return Response::json(['status' => 'error']);
 }
Пример #14
0
<?php

use Strimoid\Models\Content;
$builder = Content::fromDaysAgo(3);
if (isset($group) && $group instanceof Strimoid\Models\Group) {
    $builder->where('group_id', $group->getKey());
}
$popularContents = $builder->remember(60)->orderBy('uv', 'desc')->take(5)->get();
?>

<div class="well popular_contents_widget">
    <h4>Popularne treści</h4>

    <ul class="media-list popular_contents_list">
        @foreach ($popularContents as $content)
        <li class="media">
            @if ($content->thumbnail && !$content->nsfw)
            <a class="pull-left" href="{!! route('content_comments_slug', [$content, Str::slug($content->title)]) !!}" rel="nofollow" target="_blank">
                <img src="{!! $content->getThumbnailPath(40, 40) !!}" style="height: 40px; width: 40px; border-radius: 3px;">
            </a>
            @endif
            <div class="media-body">
                <h6 class="media-heading"><a href="{!! route('content_comments_slug', [$content, Str::slug($content->title)]) !!}">{{{ Str::limit($content->title, 50) }}}</a></h6>
                <small>
                    <span class="glyphicon glyphicon-thumbs-up"></span> {!! $content->uv !!}
                    <span class="glyphicon glyphicon-thumbs-down"></span> {!! $content->dv !!}
                </small>
            </div>
        </li>
        @endforeach
    </ul>
Пример #15
0
 /**
  * @param  string  $id
  * @param  string  $type
  * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
  */
 private function getObject($id, $type)
 {
     $id = \Hashids::decode($id);
     $id = current($id);
     switch ($type) {
         case 'content':
             return Content::findOrFail($id);
         case 'related':
             return ContentRelated::findOrFail($id);
         case 'entry':
             return Entry::findOrFail($id);
         case 'entry_reply':
             return EntryReply::findOrFail($id);
         case 'comment':
             return Comment::findOrFail($id);
         case 'comment_reply':
             return CommentReply::findOrFail($id);
     }
 }
Пример #16
0
 /**
  * @return mixed
  */
 public function saveThumbnail(Request $request)
 {
     $id = hashids_decode($request->input('id'));
     $content = Content::findOrFail($id);
     $thumbnails = Session::get('thumbnails');
     if (!$content->canEdit(Auth::user())) {
         return Redirect::route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.');
     }
     $index = (int) Input::get('thumbnail');
     if (Input::has('thumbnail') && isset($thumbnails[$index])) {
         $content->setThumbnail($thumbnails[$index]);
     } else {
         $content->removeThumbnail();
     }
     return Redirect::route('content_comments', $content);
 }
Пример #17
0
 /**
  * @param Request $request
  * @param Content $content
  *
  * @return mixed
  */
 public function edit(Request $request, $content)
 {
     if (!$content->canEdit(user())) {
         return response()->json(['status' => 'error', 'error' => 'Minął czas dozwolony na edycję treści.'], 400);
     }
     $rules = ['title' => 'min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255'];
     if ($content->text) {
         $rules['text'] = 'min:1|max:50000';
     } else {
         $rules['url'] = 'url_custom|max:2048';
     }
     $this->validate($request, $rules);
     $fields = ['title', 'description', 'nsfw', 'eng'];
     $fields[] = $content->text ? 'text' : 'url';
     $content->update(Input::only($fields));
 }
Пример #18
0
 public function delete()
 {
     Content::where('id', $this->content_id)->decrement('related_count');
     return parent::delete();
 }
Пример #19
-2
 function parse_usernames($body)
 {
     $body = preg_replace_callback('/(?<=^|\\s)c\\/([a-z0-9_-]+)(?=$|\\s|:|.)/i', function ($matches) {
         $content = Content::find($matches[1]);
         if ($content) {
             return '[' . str_replace('_', '\\_', $content->title) . '](' . $content->getSlug() . ')';
         } else {
             return 'c/' . $matches[1];
         }
     }, $body);
     $body = preg_replace_callback('/(?<=^|\\s)u\\/([a-z0-9_-]+)(?=$|\\s|:|.)/i', function ($matches) {
         $target = User::name($matches[1])->first();
         if ($target) {
             return '[u/' . str_replace('_', '\\_', $target->name) . '](/u/' . $target->name . ')';
         }
         return 'u/' . $matches[1];
     }, $body);
     $body = preg_replace_callback('/(?<=^|\\s)@([a-z0-9_-]+)(?=$|\\s|:|.)/i', function ($matches) {
         $target = User::name($matches[1])->first();
         if ($target) {
             return '[@' . str_replace('_', '\\_', $target->name) . '](/u/' . $target->name . ')';
         }
         return '@' . $matches[1];
     }, $body);
     $body = preg_replace_callback('/(?<=^|\\s)(?<=\\s|^)g\\/([a-z0-9_-żźćńółęąśŻŹĆĄŚĘŁÓŃ]+)(?=$|\\s|:|.)/i', function ($matches) {
         $target = Group::name($matches[1])->first();
         $fakeGroup = class_exists('Folders\\' . studly_case($matches[1]));
         if ($target || $fakeGroup) {
             $urlname = $target ? $target->urlname : $matches[1];
             return '[g/' . str_replace('_', '\\_', $urlname) . '](/g/' . $urlname . ')';
         }
         return 'g/' . $matches[1];
     }, $body);
     return $body;
 }