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; }
protected function filterUser($value) { $user = User::name($value)->first(); if ($user) { $this->builder->where('user_id', $user->getKey()); } }
/** * @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); }
public function activateAccount(Request $request, $token) { $user = User::where('activation_token', $token)->firstOrFail(); $ipHash = md5($request->getClientIp()); if (Cache::has('registration.' . $ipHash)) { abort(500); } $user->is_activated = true; $user->save(); auth()->login($user); Cache::put('registration.' . $ipHash, 'true', 60 * 24 * 7); return redirect()->to('/kreator')->with('success_msg', 'Witaj w gronie użytkowników serwisu ' . config('app.site_name') . '! ;) ' . 'Zacznij od zasubskrybowania dowolnej ilości grup, pasujących do twoich zainteresowań.'); }
/** * Execute the console command. * * @return void */ public function fire() { DB::connection()->disableQueryLog(); $conn = DB::connection('stats'); $conn->disableQueryLog(); $rows = DailyAction::select(DB::raw('user_id, Sum(points) as points'))->with(['user' => function ($q) { $q->select(['name', 'avatar']); }])->groupBy('user_id')->orderBy('points', 'desc')->get(); foreach ($rows as $row) { $user = User::find($row['user_id']); $user->total_points = $row['points']; $user->save(); } $this->info('All users processed'); }
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); }
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); }
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'); }
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); }
protected function createFakeSubscriber(Group $group, User $user) { $user->subscribedGroups()->attach($group); }
/** * @inheritdoc */ public function getByName($name) { return $this->users->name($name)->first(); }
/** * Get list of users mentioned in given text. */ protected function findMentionedUsers(string $text) : Collection { preg_match_all('/@([a-z0-9_-]+)/i', $text, $matches, PREG_SET_ORDER); $nicknames = array_pluck($matches, 1); return User::whereIn('name', $nicknames)->get(); }
public function show($username) { $user = User::name($username)->firstOrFail(); return $this->getInfo($user); }
public function banUser(User $user, $reason = '') { if ($user->isBanned($this)) { return false; } $ban = new GroupBan(); $ban->group()->associate($this); $ban->user()->associate($user); $ban->moderator()->associate(Auth::user()); $ban->reason = Input::get('reason'); $ban->save(); }
/** * Show user profile view. * * @param User $user * @param string $type * * @return \Illuminate\View\View */ public function showProfile($user, $type = 'all') { if ($user->removed_at) { abort(404, 'Użytkownik usunął konto.'); } $data = []; if ($type == 'contents') { $data['contents'] = $user->contents()->orderBy('created_at', 'desc')->paginate(15); } elseif ($type == 'comments') { $data['comments'] = $user->comments()->orderBy('created_at', 'desc')->paginate(15); } elseif ($type == 'comment_replies') { $data['replies'] = $user->commentReplies()->orderBy('created_at', 'desc')->paginate(15); } elseif ($type == 'entries') { $data['entries'] = $user->entries()->orderBy('created_at', 'desc')->paginate(15); } elseif ($type == 'entry_replies') { $data['replies'] = $user->entryReplies()->orderBy('created_at', 'desc')->paginate(15); } elseif ($type == 'moderated') { $data['moderated'] = $user->moderatedGroups()->paginate(25); } else { $data['actions'] = $user->actions()->with('element')->orderBy('created_at', 'desc')->paginate(15); } $data['type'] = $type; $data['user'] = $user; return view('user.profile', $data); }
private function getVoteElement($object, User $user) { if (!$object->votes()) { return false; } $vote = $object->votes()->where('user_id', $user->getKey())->first(); if (!$vote) { return false; } return $vote; }
public function canRemove(User $user = null) { return $user->isModerator($this->group); }
public function isAuthor(User $user = null) { $userId = $user ? $user->getKey() : auth()->id(); return (int) $userId === (int) $this->user_id; }
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; }