예제 #1
0
 protected function createFakeEntry(Group $group)
 {
     $entry = Entry::create(['created_at' => $this->faker->dateTimeThisDecade, 'group_id' => $group->getKey(), 'text' => $this->faker->text(512), 'user_id' => $this->getRandomUser()->getKey()]);
     $repliesNumber = $this->faker->numberBetween(0, 3);
     for ($i = 0; $i < $repliesNumber; $i++) {
         $this->createFakeEntryReply($entry);
     }
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function getByName($name)
 {
     $className = 'Strimoid\\Models\\Folders\\' . studly_case($name);
     if (class_exists($className)) {
         return new $className();
     }
     return $this->group->name($name)->first();
 }
예제 #3
0
 protected function filterGroup($value)
 {
     $group = Group::name($value)->first();
     if ($group) {
         $this->builder->where('group_id', $group->getKey());
     }
 }
예제 #4
0
 /**
  * Bind data to the view.
  *
  * @param View $view
  *
  * @return void
  */
 public function compose(View $view)
 {
     $data = $view->getData();
     if (Auth::check()) {
         $notifications = Auth::user()->notifications()->with('user')->orderBy('created_at', 'desc')->take(15)->get();
         $view->with('notifications', $notifications);
         $unreadCount = Auth::user()->notifications()->wherePivot('read', false)->count();
         $view->with('newNotificationsCount', $unreadCount);
     }
     // Get object from which we can extract name to use as page title
     $currentGroup = head(array_only($data, ['group', 'folder', 'fakeGroup']));
     $view->with('currentGroup', $currentGroup);
     if (isset($currentGroup) && isset($currentGroup->name)) {
         $pageTitle = $currentGroup->name;
         // Homepage title shall always be Strimoid.pl
         if ($currentGroup->urlname == 'all' && !Setting::get('homepage_subscribed', false)) {
             $pageTitle = 'Strimoid';
         }
         if ($currentGroup->urlname == 'subscribed' && Setting::get('homepage_subscribed', false)) {
             $pageTitle = 'Strimoid';
         }
     } else {
         $pageTitle = 'Strimoid';
     }
     $view->with('pageTitle', $pageTitle);
     // Needed by top bar with groups
     $popularGroups = Cache::remember('popularGroups', 60, function () {
         return Group::orderBy('subscribers_count', 'desc', true)->take(30)->get(['id', 'name', 'urlname']);
     });
     $view->with('popularGroups', $popularGroups);
 }
예제 #5
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]);
 }
예제 #6
0
 public function parse(InlineParserContext $inlineContext)
 {
     $cursor = $inlineContext->getCursor();
     // The 'g/' prefix must not have any other characters immediately prior
     $previousChar = $cursor->peek(-1);
     $nextChar = $cursor->peek(1);
     if ($previousChar !== null && $previousChar !== ' ') {
         // peek() doesn't modify the cursor, so no need to restore state first
         return false;
     }
     if ($nextChar !== '/') {
         return false;
     }
     // Save the cursor state in case we need to rewind and bail
     $previousState = $cursor->saveState();
     // Advance past the 'g/' prefix to keep parsing simpler
     $cursor->advanceBy(2);
     // Parse the handle
     $handle = $cursor->match('/^[A-Za-z0-9_]{1,32}(?!\\w)/');
     if (empty($handle)) {
         // Regex failed to match; this isn't a valid username
         $cursor->restoreState($previousState);
         return false;
     }
     $group = Group::name($handle)->first();
     if (!$group) {
         $cursor->restoreState($previousState);
         return false;
     }
     $groupUrl = route('group_contents', $group, false);
     $inlineContext->getContainer()->appendChild(new Link($groupUrl, 'g/' . $handle));
     return true;
 }
예제 #7
0
 public function removeFromFolder()
 {
     $group = Group::findOrFail(Input::get('group'));
     $folder = Folder::findOrFail(Input::get('folder'));
     $folder->groups()->detach($group);
     return Response::json(['status' => 'ok']);
 }
예제 #8
0
 public function getIndex()
 {
     $query = DailyAction::select(DB::raw('user_id, Sum(points) as points, Sum(contents) as contents,
             Sum(comments) as comments, Sum(entries) as entries, Sum(uv) as uv, Sum(dv) as dv'))->with('user')->groupBy('user_id')->orderBy('points', 'desc');
     if (Input::has('group')) {
         $group = Group::name(Input::get('group'))->firstOrFail();
         $query->where('group_id', $group->getKey());
         $data['group'] = $group;
     }
     // Time filter
     if (Input::has('time')) {
         $fromDay = Carbon::now()->diffInDays(Carbon::create(2013, 1, 1)) - Input::get('time');
         $query->where('day', '>', $fromDay);
     }
     return $query->paginate(50);
 }
예제 #9
0
 public function addModerator()
 {
     $group = Group::name(request('groupname'))->firstOrFail();
     $user = User::name(request('username'))->firstOrFail();
     if (!user()->isAdmin($group)) {
         abort(403, 'Access denied');
     }
     if ($user->isModerator($group)) {
         return redirect()->route('group_moderators', $group->urlname);
     }
     if ($user->isBlocking($group)) {
         return redirect()->route('group_moderators', $group->urlname)->with('danger_msg', 'Nie możesz dodać wybranego użytkownika jako moderatora, ponieważ zablokował tą grupę.');
     }
     $moderator = new GroupModerator();
     $moderator->group()->associate($group);
     $moderator->user()->associate($user);
     $type = request('admin') == 'on' ? 'admin' : 'moderator';
     $moderator->type = $type;
     $moderator->save();
     // Send notification to new moderator
     /*
     $this->sendNotifications([$user->getKey()], function ($notification) use ($moderator, $group) {
         $notification->type = 'moderator';
     
         $positionTitle = $moderator->type == 'admin' ? 'administratorem' : 'moderatorem';
         $notification->setTitle('Zostałeś ' . $positionTitle . ' w grupie ' . $group->urlname);
     
         $notification->group()->associate($group);
         $notification->save();
     });
     */
     // Log this action
     $action = new ModeratorAction();
     $action->type = ModeratorAction::TYPE_MODERATOR_ADDED;
     $action->is_admin = $moderator->type == 'admin' ? true : false;
     $action->moderator()->associate(user());
     $action->target()->associate($user);
     $action->group()->associate($group);
     $action->save();
     \Cache::tags(['user.moderated-groups', 'u.' . $user->getKey()])->flush();
     return redirect()->route('group_moderators', $group->urlname);
 }
예제 #10
0
 public function store(Request $request)
 {
     if (Input::has('group')) {
         Input::merge(['groupname' => request('group')]);
     }
     $this->validate($request, Entry::rules());
     $group = Group::name(request('group'))->firstOrFail();
     $group->checkAccess();
     if (user()->isBanned($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik został zbanowany w wybranej grupie.'], 400);
     }
     if ($group->type == 'announcements' && !user()->isModerator($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik nie może dodawać wpisów w tej grupie.'], 400);
     }
     $entry = new Entry();
     $entry->text = request('text');
     $entry->user()->associate(user());
     $entry->group()->associate($group);
     $entry->save();
     return response()->json(['status' => 'ok', '_id' => $entry->getKey(), 'entry' => $entry]);
 }
예제 #11
0
 public function addBan()
 {
     $user = User::name(request('username'))->firstOrFail();
     $group = Group::name(request('groupname'))->firstOrFail();
     $this->validate(request(), ['reason' => 'max:255']);
     if (request('everywhere') == '1') {
         foreach (user()->moderatedGroups as $group) {
             $ban = GroupBan::where('group_id', $group->id)->where('user_id', $user->id)->first();
             if (!$ban) {
                 $group->banUser($user, request('reason'));
             }
         }
     } else {
         if (!user()->isModerator($group)) {
             abort(403, 'Access denied');
         }
         $ban = GroupBan::where('group_id', $group->id)->where('user_id', $user->id)->first();
         if (!$ban) {
             $group->banUser($user, request('reason'));
         }
     }
     return redirect()->route('group_banned', $group);
 }
예제 #12
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']);
 }
예제 #13
0
 /**
  * @param Request $request
  *
  * @return mixed
  */
 public function addContent(Request $request)
 {
     $rules = ['title' => 'required|min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255', 'groupname' => 'required|exists:groups,urlname'];
     if (Input::get('type') == 'link') {
         $rules['url'] = 'required|url_custom|max:2048';
     } else {
         $rules['text'] = 'required|min:1|max:50000';
     }
     $this->validate($request, $rules);
     $group = Group::name(Input::get('groupname'))->firstOrFail();
     $group->checkAccess();
     if (Auth::user()->isBanned($group)) {
         return Redirect::action('ContentController@showAddForm')->withInput()->with('danger_msg', 'Zostałeś zbanowany w wybranej grupie');
     }
     if ($group->type == 'announcements' && !Auth::user()->isModerator($group)) {
         return Redirect::action('ContentController@showAddForm')->withInput()->with('danger_msg', 'Nie możesz dodawać treści do wybranej grupy');
     }
     $content = new Content(Input::only(['title', 'description', 'nsfw', 'eng']));
     if (Input::get('type') == 'link') {
         $content->url = Input::get('url');
     } else {
         $content->text = Input::get('text');
     }
     $content->user()->associate(Auth::user());
     $content->group()->associate($group);
     $content->save();
     if (Input::get('thumbnail') == 'on') {
         Queue::push('Strimoid\\Handlers\\DownloadThumbnail', ['id' => $content->getKey()]);
     }
     return Redirect::route('content_comments', $content);
 }
예제 #14
0
 public function wizard($tag = null)
 {
     $popularTags = ['programowanie', 'muzyka', 'gry', 'obrazki', 'it', 'internet', 'linux', 'humor', 'nauka', 'strimoid', 'zdjęcia', 'jam', 'oldschool', 'technika', 'śmieszne', 'art', 'technologia', 'wpisy', 'sztuka', 'zainteresowania'];
     if ($tag) {
         $groups = Group::where('tags', $tag)->orderBy('subscribers', 'desc')->paginate(25);
     } else {
         $groups = Group::orderBy('id', 'desc')->paginate(25);
     }
     return view('group.wizard', ['popular_tags' => $popularTags, 'groups' => $groups]);
 }
예제 #15
0
 /**
  * Add new content.
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function store(Request $request)
 {
     $rules = ['title' => 'required|min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255', 'group' => 'required|exists:groups,urlname'];
     if (request('text')) {
         $rules['text'] = 'required|min:1|max:50000';
     } else {
         $rules['url'] = 'required|url_custom';
     }
     $this->validate($request, $rules);
     $group = Group::name(request('group'))->firstOrFail();
     $group->checkAccess();
     if (user()->isBanned($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik został zbanowany w wybranej grupie.'], 400);
     }
     if ($group->type == 'announcements' && !user()->isModerator($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik nie może dodawać treści w tej grupie.'], 400);
     }
     $content = new Content($request->only(['title', 'description', 'nsfw', 'eng']));
     if (request('text')) {
         $content->text = request('text');
     } else {
         $content->url = request('url');
     }
     $content->user()->associate(user());
     $content->group()->associate($group);
     $content->save();
     // Download thumbnail in background to don't waste user time
     $thumbnail = $request->get('thumbnail');
     if ($thumbnail != 'false' && $thumbnail != 'off') {
         $content->thumbnail_loading = true;
         Queue::push('Strimoid\\Handlers\\DownloadThumbnail', ['id' => $content->getKey()]);
     }
     return response()->json(['status' => 'ok', '_id' => $content->getKey(), 'content' => $content]);
 }
예제 #16
-2
파일: utils.php 프로젝트: vegax87/Strimoid
 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;
 }