public function getExcerpt($length = 200, $includeTitle = false, $focus = null)
{
$title = null;
if ($includeTitle && $this->title !== null) {
$title = Html::trimText(strip_tags($this->title), $length);
$length = $length - strlen($title);
}
if ($this->body instanceof Content) {
$this->body = $this->body->getValues();
}
if (is_array($this->body)) {
// Assume it's an array, strip some common fields that we don't need, implode the rest.
$stripKeys = ['id', 'slug', 'datepublish', 'datedepublish', 'datecreated', 'datechanged', 'username', 'ownerid', 'title', 'contenttype', 'status', 'taxonomy', 'templatefields'];
$excerpt = '';
array_walk($this->body, function ($value, $key) use(&$excerpt, $stripKeys) {
if (is_string($value) && !in_array($key, $stripKeys)) {
$excerpt .= $value . ' ';
}
});
} elseif (is_string($this->body) || is_object($this->body) && method_exists($this->body, '__toString')) {
// otherwise we just use the string.
$excerpt = (string) $this->body;
} else {
// Nope, got nothing.
$excerpt = '';
}
$excerpt = str_replace('>', '> ', $excerpt);
if (empty($focus)) {
$excerpt = Html::trimText(strip_tags($excerpt), $length);
} else {
$excerpt = $this->extractRelevant($focus, strip_tags($excerpt), $length);
}
if (!empty($title)) {
$excerpt = '<b>' . $title . '</b> ' . $excerpt;
}
return trim($excerpt);
}