Ejemplo n.º 1
0
 /**
  * @return mixed
  */
 public function index()
 {
     if (Input::has('folder')) {
         $username = request('user', auth()->id());
         $entity = $this->folders->getByName($username, request('folder'));
     } else {
         $groupName = request('group', 'all');
         $entity = $this->groups->requireByName($groupName);
     }
     $type = request('type', 'all');
     $canSortBy = ['comments', 'uv', 'created_at', 'frontpage_at'];
     $orderBy = in_array(request('sort'), $canSortBy) ? request('sort') : null;
     $builder = $entity->contents($type, $orderBy)->with('group', 'user');
     // Time filter
     $time = request('time');
     if ($time) {
         $builder->fromDaysAgo($time);
     }
     // Domain filter
     $domain = request('domain');
     if ($domain) {
         $builder->where('domain', $domain);
     }
     // User filter
     if (Input::has('user')) {
         $user = User::name(request('user'))->firstOrFail();
         $builder->where('user_id', $user->getKey());
     }
     $perPage = Input::has('per_page') ? between(request('per_page'), 1, 100) : 20;
     return $builder->paginate($perPage);
 }
Ejemplo n.º 2
0
 protected function filterUser($value)
 {
     $user = User::name($value)->first();
     if ($user) {
         $this->builder->where('user_id', $user->getKey());
     }
 }
Ejemplo n.º 3
0
 public function parse(InlineParserContext $inlineContext)
 {
     $cursor = $inlineContext->getCursor();
     // The @ symbol must not have any other characters immediately prior
     $previousChar = $cursor->peek(-1);
     if ($previousChar !== null && $previousChar !== ' ') {
         // peek() doesn't modify the cursor, so no need to restore state first
         return false;
     }
     // Save the cursor state in case we need to rewind and bail
     $previousState = $cursor->saveState();
     // Advance past the @ symbol to keep parsing simpler
     $cursor->advance();
     // 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;
     }
     $user = User::name($handle)->first();
     if (!$user) {
         $cursor->restoreState($previousState);
         return false;
     }
     $profileUrl = route('user_profile', $user, false);
     $inlineContext->getContainer()->appendChild(new Link($profileUrl, '@' . $handle));
     return true;
 }
Ejemplo n.º 4
0
 public function showRanking($group = null)
 {
     $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 ($group) {
         $query->where('group_id', $group->getKey());
         $data['group'] = $group;
     }
     if (Input::has('user')) {
         $user = User::name(Input::get('user'))->firstOrFail();
     }
     // Time filter
     $time = intval(Input::get('time')) ?: 90;
     $fromDay = Carbon::now()->diffInDays(Carbon::create(2013, 1, 1)) - $time;
     $query->where('day', '>', $fromDay);
     $data['users'] = $query->paginate(50);
     return view('ranking.ranking', $data);
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 public function createConversation(Request $request)
 {
     $target = User::name(request('username'))->firstOrFail();
     if ($target->getKey() == auth()->id()) {
         return redirect()->action('ConversationController@showCreateForm')->withInput()->with('danger_msg', 'Ekhm... wysyłanie wiadomości do samego siebie chyba nie ma sensu ;)');
     }
     if ($target->isBlockingUser(user())) {
         return redirect()->action('ConversationController@showCreateForm')->withInput()->with('danger_msg', 'Zostałeś zablokowany przez wybranego użytkownika.');
     }
     $this->validate($request, ['text' => 'required|max:10000']);
     $conversation = Conversation::withUser(auth()->id())->withUser($target->getKey())->first();
     if (!$conversation) {
         $conversation = Conversation::create([]);
         $conversation->users()->attach([auth()->id(), $target->getKey()]);
     } else {
         $conversation->notifications()->where('user_id', $target->getKey())->delete();
     }
     $conversation->messages()->create(['user_id' => Auth::id(), 'text' => $request->input('text')]);
     return redirect()->to('/conversations');
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 public function show($username)
 {
     $user = User::name($username)->firstOrFail();
     return $this->getInfo($user);
 }
Ejemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function getByName($name)
 {
     return $this->users->name($name)->first();
 }
Ejemplo n.º 10
-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;
 }