Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private function getDefaultValuesForPosts() {
*/
private function setPostViewData(object $post, $index = false)
{
$post->excerptShort = in_array('excerpt', $this->data['posts_fields'] ?? []) ? $post->excerptShort : false;
$post->excerptShort = in_array('excerpt', $this->data['posts_fields'] ?? []) ? $this->sanitizeExcerpt($this->data['posts_display_as'] === 'news' ? $post->excerpt : $post->excerptShort) : false;
$post->postTitle = in_array('title', $this->data['posts_fields'] ?? []) ? $post->getTitle() : false;
$post->image = in_array('image', $this->data['posts_fields'] ?? []) ? $post->getImage() : [];
$post->hasPlaceholderImage = in_array('image', $this->data['posts_fields'] ?? []) && empty($post->image) ? true : false;
Expand Down Expand Up @@ -286,6 +286,23 @@ public function postUsesSchemaTypeEvent(object $post):bool {
return $post->getSchemaProperty('@type') === 'Event';
}

/**
* Sanitize excerpt by stripping tags, normalizing whitespace, trimming, and converting newlines to <br>.
*
* @param string $excerpt
*
* @return string
*/
private function sanitizeExcerpt(string $excerpt)
{
$excerpt = strip_tags($excerpt);
$excerpt = preg_replace("/[\r\n]+/", "\n", $excerpt);
$excerpt = trim($excerpt);
$excerpt = nl2br($excerpt);

return $excerpt;
}

/**
* Add sticky posts data.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@newsItem([
'heading' => $post->postTitle,
'content' => $post->excerpt,
'content' => $post->excerptShort,
'image' => $post->image,
'date' => $showDate ? [
'timestamp' => $post->getArchiveDateTimestamp(),
Expand Down