protected function assemble($text, $readmore_matches, $trimmed)
{
$text = trim($text);
$last = $text[strlen($text) - 1];
$last_p_tag = null;
if ($last != '.' && $trimmed) {
$text .= $this->end;
}
if (!$this->strip) {
$last_p_tag = strrpos($text, '</p>');
if ($last_p_tag !== false) {
$text = substr($text, 0, $last_p_tag);
}
if ($last != '.' && $trimmed) {
$text .= $this->end . ' ';
}
}
$read_more_class = apply_filters('timber/post/preview/read_more_class', "read-more");
if ($this->readmore && !empty($readmore_matches) && !empty($readmore_matches[1])) {
$text .= ' <a href="' . $this->post->link() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>';
} elseif ($this->readmore) {
$text .= ' <a href="' . $this->post->link() . '" class="' . $read_more_class . '">' . trim($this->readmore) . '</a>';
}
if (!$this->strip && $last_p_tag && (strpos($text, '<p>') > -1 || strpos($text, '<p '))) {
$text .= '</p>';
}
return trim($text);
}