public function save(PostRequest $request, $forum, $topic, $post = null) { $url = \DB::transaction(function () use($request, $forum, $topic, $post) { // parsing text and store it in cache $text = app()->make('Parser\\Post')->parse($request->text); // post has been modified... if ($post !== null) { $this->authorize('update', [$post, $forum]); $data = $request->only(['text', 'user_name']) + ['edit_count' => $post->edit_count + 1, 'editor_id' => auth()->id()]; $post->fill($data)->save(); $activity = Stream_Update::class; // user want to change the subject. we must update topics table if ($post->id === $topic->first_post_id) { $path = str_slug($request->get('subject'), '_'); $topic->fill($request->all() + ['path' => $path])->save(); $this->topic->setTags($topic->id, $request->get('tag', [])); } } else { $activity = Stream_Create::class; // create new post and assign it to topic. don't worry about the rest: trigger will do the work $post = $this->post->create($request->all() + ['user_id' => auth()->id(), 'topic_id' => $topic->id, 'forum_id' => $forum->id, 'ip' => request()->ip(), 'browser' => request()->browser(), 'host' => request()->server('SERVER_NAME')]); // get id of users that were mentioned in the text $usersId = (new Ref_Login())->grab($text); if ($usersId) { app()->make('Alert\\Post\\Login')->with(['users_id' => $usersId, 'sender_id' => auth()->id(), 'sender_name' => $request->get('user_name', auth()->user()->name), 'subject' => excerpt($topic->subject, 48), 'excerpt' => excerpt($text), 'url' => route('forum.topic', [$forum->path, $topic->id, $topic->path], false)])->notify(); } } $url = route('forum.topic', [$forum->path, $topic->id, $topic->path], false); $url .= '?p=' . $post->id . '#id' . $post->id; $object = (new Stream_Post(['url' => $url]))->map($post); stream($activity, $object, (new Stream_Topic())->map($topic, $forum)); return $url; }); return redirect()->to($url); }
/** * @param \Coyote\Forum $forum * @param Request $request * @return $this */ public function index($forum, Request $request) { // builds breadcrumb for this category $this->breadcrumb($forum); // create view with online users $viewers = app()->make('Session\\Viewers')->render($request->getRequestUri()); $this->pushForumCriteria(); $forumList = $this->forum->forumList(); $this->topic->pushCriteria(new BelongsToForum($forum->id)); $topics = $this->topic->paginate(auth()->id(), $request->getSession()->getId()); // let's cache tags. we don't need to run this query every time $tags = Cache::remember('forum:tags', 60 * 24, function () { return $this->forum->getTagClouds(); }); return parent::view('forum.category')->with(compact('viewers', 'forumList', 'forum', 'topics', 'tags')); }
/** * @param $forum * @param PostRequest $request * @return \Illuminate\Http\RedirectResponse */ public function save($forum, PostRequest $request) { $url = \DB::transaction(function () use($request, $forum) { $path = str_slug($request->get('subject'), '_'); // create new topic $topic = $this->topic->create($request->all() + ['path' => $path, 'forum_id' => $forum->id]); // create new post and assign it to topic. don't worry about the rest: trigger will do the work $this->post->create($request->all() + ['user_id' => auth()->id(), 'topic_id' => $topic->id, 'forum_id' => $forum->id, 'ip' => request()->ip(), 'browser' => request()->browser(), 'host' => request()->server('SERVER_NAME')]); $this->topic->setTags($topic->id, $request->get('tag')); // parsing text and store it in cache $text = app()->make('Parser\\Post')->parse($request->text); // get id of users that were mentioned in the text $usersId = (new Ref_Login())->grab($text); if ($usersId) { app()->make('Alert\\Post\\Login')->with(['users_id' => $usersId, 'sender_id' => auth()->id(), 'sender_name' => $request->get('user_name', auth()->user()->name), 'subject' => excerpt($request->subject, 48), 'excerpt' => excerpt($text), 'url' => route('forum.topic', [$forum->path, $topic->id, $path], false)])->notify(); } stream(Stream_Create::class, (new Stream_Topic())->map($topic, $forum, $text)); return route('forum.topic', [$forum->path, $topic->id, $path]); }); return redirect()->to($url); }