/** * Returns the fully rendered HTML content of this post. * * @param boolean $skipCache * @return string */ public function getBodyFormatted($skipCache = false) { if (!$skipCache) { // Markdown parsed content if (!is_null($this->body_html)) { if (!mb_check_encoding($this->body_html, 'UTF-8')) { return "<tt style=\"color:red;\">Invalid encoding. This should never happen!</tt>"; } return $this->body_html; } // Raw HTML input if (!is_null($this->body_parsed)) { return $this->body_parsed; } } $ContentFormatter = new ContentFormatter(); $this->body_too_long = false; $this->body_parsed = $ContentFormatter->formatPost($this); $this->body_parsed_preview = null; $this->body_parsed_at = $this->freshTimestamp(); $this->body_has_content = $ContentFormatter->hasContent(); if (!mb_check_encoding($this->body_parsed, 'UTF-8')) { return "<tt style=\"color:red;\">Invalid encoding. This should never happen!</tt>"; } // If our body is too long, we need to pull the first X characters and do that instead. // We also set a token indicating this post has hidden content. if (mb_strlen($this->body) > 1200) { $this->body_too_long = true; $this->body_parsed_preview = $ContentFormatter->formatPost($this, 1000); } // We use an update here instead of just saving $post because, in this method // there will frequently be additional properties on this object that cannot // be saved. To make life easier, we just touch the object. static::where(['post_id' => $this->post_id])->update(['body_has_content' => $this->body_has_content, 'body_too_long' => $this->body_too_long, 'body_parsed' => $this->body_parsed, 'body_parsed_preview' => $this->body_parsed_preview, 'body_parsed_at' => $this->body_parsed_at]); return $this->body_parsed; }