/** * Create a new post * @param string $body Content of post, will be run through filters * @param integer $threadid Thread ID * @param integer| $posterid Poster's ID. Defaults to currently authenticated user * @param bool|false $hidden Is the post hidden from normal view? * @param bool|true $save Should the post be automatically saved into the database? * @return Post The resulting post object */ public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true) { // Check users rights if (!Auth::check() && $posterid === null) { abort(403); // 403 Forbidden } // Check thread $thread = Thread::findOrFail($threadid); if ($thread->locked) { abort(403); // 403 Forbidden } // Run post through filters $body = PostProcessor::preProcess($body); // Create new post $post = new Post(); $post->thread_id = $threadid; $post->poster_id = Auth::user()->id; $post->body = $body; $post->hidden = $hidden; // defaults to false // Put post into database if ($save) { $post->save(); } return $post; }
public function newPost(Request $request) { // Ensure // Collect input $threadid = $request->input('thread', 0); $content = $request->input('body', ''); if ($content == '' || $threadid == 0) { abort(400); // 400 Bad Request } // Run post through filters $content = PostProcessor::preProcess($content); // Create new post $post = Post::newPost($content, $threadid); // Generate response $resp = new Response(json_encode(['status' => true, 'html' => $post->getPostView()->render()]), 200); $resp->header('Content-Type', 'application/json'); return $resp; }
/** * Parse markdown to HTML, similar to postParse, except online inline elements are accepted. This is good for * one-line descriptions and such, but bad for bodies of text, i.e. posts. * @param Request $request * @return string */ public function postInlineParse(Request $request) { $markdown = PostProcessor::postProcess($request->input('markdown')); return $this->parser->parseParagraph($markdown); }