/** * Display a listing of the resource. * @return \Illuminate\Http\Response */ public function index() { \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Checking out <em>who else is online</em>", action('Nexus\\ActivityController@index')); $activities = \Nexus\Helpers\ActivityHelper::recentActivities(); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcumbForUtility('Who is Online'); return view('activities.index', compact('activities', 'breadcrumbs')); }
/** * Display the specified resource. * * @param int $section_id - default to the first section * @return Response */ public function show($section_id = null) { if (!$section_id) { $section = \Nexus\Section::with('sections', 'topics')->first(); } else { $section = \Nexus\Section::with('sections', 'topics')->where('id', $section_id)->first(); } \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Browsing <em>{$section->title}</em>", action('Nexus\\SectionController@show', ['id' => $section->id])); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcrumbForSection($section); return view('sections.index', compact('section', 'breadcrumbs')); }
/** * Display the specified resource. * * @param string $user_name - the name of the user * @return Response */ public function show($user_name) { try { $user = \Nexus\User::with('comments', 'comments.author')->where('username', $user_name)->firstOrFail(); } catch (ModelNotFoundException $ex) { $message = "{$user_name} not found. Maybe you're thinking of someone else"; \Nexus\Helpers\FlashHelper::showAlert($message, 'warning'); return redirect('/users/'); } if ($user->id === \Auth::user()->id) { \Auth::user()->markCommentsAsRead(); \Auth::user()->save(); } \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Examining <em>{$user->username}</em>", action('Nexus\\UserController@show', ['user_name' => $user_name])); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcrumbForUser($user); return view('users.show', compact('user', 'breadcrumbs')); }
/** * Displays a list of messages sent to the logged in user * @todo - generate $activeUsers array from a list of active users * @return Response */ public function index($selected = null) { $allMessages = \Nexus\Message::with('user')->with('author')->where('user_id', \Auth::user()->id)->orderBy('id', 'desc')->get()->all(); $messages = array_slice($allMessages, 5); $recentMessages = array_reverse(array_slice($allMessages, 0, 5)); $recentActivities = \Nexus\Helpers\ActivityHelper::recentActivities(); $activeUsers = array(); foreach ($recentActivities as $activity) { if (\Auth::user()->id != $activity['user_id']) { $activeUsers[$activity['user_id']] = $activity->user->username; } } // mark all messages as read \Nexus\Message::where('user_id', \Auth::user()->id)->update(['read' => true]); \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Viewing <em>Inbox</em>", action('Nexus\\MessageController@index')); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcumbForUtility('Inbox'); return view('messages.index')->with(compact('messages', 'recentMessages', 'activeUsers', 'selected', 'breadcrumbs')); }
/** * perform a search against all the posts and * return some results * @todo - ignore word order * @todo - remove stop words * @todo - deal with exact phrases */ public function find($text) { $phraseSearch = false; $displaySearchResults = true; // if text is ^"(.*)"$ or ^'(.*)'$ then we are searching for a phrase $pattern = <<<'pattern' /^['|"](.*)['|"]$/ pattern; $matches = false; preg_match($pattern, $text, $matches); if (!$matches) { // set initial results as nothing $results = false; // look for all the words $rawSearchTerms = explode(' ', $text); $searchTerms = array(); // remove stop words here foreach ($rawSearchTerms as $word) { if (!in_array(strtolower($word), self::$stopWords)) { $searchTerms[] = $word; } } // dd($searchTerms); foreach ($searchTerms as $word) { // remove unwanted characters from the start and end // @todo this does not remove multiple unwanted commas etc $word = trim($word); if (strlen($word) !== 0) { if ($results) { $results = $results->where('text', 'like', "%{$word}%"); } else { // first where $results = \Nexus\Post::where('text', 'like', "%{$word}%"); } } } } else { $phrase = trim($matches[1]); $results = \Nexus\Post::where('text', 'like', "%{$phrase}%"); } if ($results) { $results->orderBy('time', 'desc'); } \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Searching", action('Nexus\\SearchController@index')); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcumbForUtility('Search'); return view('search.results', compact('results', 'breadcrumbs', 'text', 'displaySearchResults')); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($topic_id) { $posts = \Nexus\Post::with('author')->where('topic_id', $topic_id)->orderBy('id', 'dsc'); $topic = \Nexus\Topic::findOrFail($topic_id); // is this topic readonly to the authenticated user? $readonly = true; if ($topic->readonly == false) { $readonly = false; } if ($topic->section->moderator->id === \Auth::user()->id) { $readonly = false; } if (\Auth::user()->administrator) { $readonly = false; } // is this topic secret to the authenticated user? $userCanSeeSecrets = false; if ($topic->section->moderator->id === \Auth::user()->id) { $userCanSeeSecrets = true; } if (\Auth::user()->administrator) { $userCanSeeSecrets = true; } // get the previously read progress so we can indicate this in the view $readProgress = \Nexus\Helpers\ViewHelper::getReadProgress(\Auth::user(), $topic); // get the subscription status $topicStatus = \Nexus\Helpers\ViewHelper::getTopicStatus(\Auth::user(), $topic); $unsubscribed = $topicStatus['unsubscribed']; \Nexus\Helpers\ViewHelper::updateReadProgress(\Auth::user(), $topic); \Nexus\Helpers\ActivityHelper::updateActivity(\Auth::user()->id, "Reading <em>{$topic->title}</em>", action('Nexus\\TopicController@show', ['id' => $topic->id])); $breadcrumbs = \Nexus\Helpers\BreadcrumbHelper::breadcrumbForTopic($topic); return view('topics.index', compact('topic', 'posts', 'readonly', 'userCanSeeSecrets', 'readProgress', 'breadcrumbs', 'unsubscribed')); }
/** * wwhen a user logs out then remove their current activity * * @param Event $event * @return void */ public function handle($user) { $user = \Auth::user(); ActivityHelper::removeActivity($user->id); }