Esempio n. 1
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]);
 }
Esempio n. 2
0
 public function removeEntry(Request $request)
 {
     $id = hashids_decode($request->get('content'));
     $entry = Entry::findOrFail($id);
     $entry->usave()->delete();
     return Response::json(['status' => 'ok']);
 }
Esempio n. 3
0
 public static function boot()
 {
     static::creating(function ($reply) {
         $reply->group_id = $reply->parent->group_id;
     });
     static::created(function ($reply) {
         $reply->parent->increment('replies_count');
     });
     static::deleted(function ($reply) {
         $reply->parent->decrement('replies_count');
     });
     parent::boot();
 }
Esempio n. 4
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'));
 }
Esempio n. 5
0
 public function addEntry(Request $request)
 {
     $this->validate($request, Entry::rules());
     $group = Group::name(Input::get('groupname'))->firstOrFail();
     $group->checkAccess();
     if (Auth::user()->isBanned($group)) {
         return Response::json(['status' => 'error', 'error' => 'Zostałeś zbanowany w wybranej grupie']);
     }
     if ($group->type == 'announcements' && !Auth::user()->isModerator($group)) {
         return Response::json(['status' => 'error', 'error' => 'Nie możesz dodawać wpisów do wybranej grupy']);
     }
     $entry = new Entry();
     $entry->text = Input::get('text');
     $entry->user()->associate(Auth::user());
     $entry->group()->associate($group);
     $entry->save();
     return Response::json(['status' => 'ok']);
 }
Esempio n. 6
0
 protected function createFakeEntryReply(Entry $entry)
 {
     $entry->replies()->create(['created_at' => $this->faker->dateTimeThisDecade, 'text' => $this->faker->text(512), 'user_id' => $this->getRandomUser()->getKey()]);
 }
Esempio n. 7
0
 public function onEntryEdit(Entry $entry)
 {
     $notification = $entry->notifications()->first();
     $this->updateNotificationTargets($notification, $entry->text_source);
 }
Esempio n. 8
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);
     }
 }
Esempio n. 9
0
 /**
  * @param Entry $entry
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function remove($entry)
 {
     if (!$entry->canRemove()) {
         abort(403, 'Access denied');
     }
     $entry->delete();
     return response()->json(['status' => 'ok']);
 }
Esempio n. 10
0
<?php

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

<div class="well popular_contents_widget">
    <h5>@lang('common.recently popular')</h5>

    <ul class="media-list popular_contents_list">
        @foreach ($popularEntries as $entry)
        <?php 
$text = preg_replace('/<a class="show_spoiler">(.*?)<\\/a>/s', '', $entry->text);
$text = preg_replace('/<span class="spoiler">(.*?)<\\/span>/s', '', $text);
$text = strip_tags($text);
?>
        <li class="media">
            <a class="pull-left" href="{!! route('single_entry', $entry) !!}">
                <img src="{!! $entry->user->getAvatarPath(40, 40) !!}" alt="{!! $entry->user->name !!}"
                     style="height: 40px; width: 40px; border-radius: 3px;">
            </a>
            <div class="media-body">
                <h6 class="media-heading">
                    <a href="{!! route('single_entry', $entry) !!}">{!! Str::limit($text, 100) !!}</a>
                </h6>
                <small>
                    <i class="fa fa-thumbs-up"></i> {{ $entry->uv }}</a>
Esempio n. 11
0
 public function onNewEntry(Entry $entry)
 {
     $arrayEntry = $entry->toArray();
     $additionalData = array('hashId' => $entry->hashId(), 'avatarPath' => $entry->user->getAvatarPath(), 'entryUrl' => $entry->getURL());
     Pusher::trigger('entries', 'new-entry', array_merge($arrayEntry, $additionalData));
 }