public function getExcerpt($length = 200, $includeTitle = false, $focus = null, $stripFields = [])
    {
        $title = null;
        if ($includeTitle && $this->title !== null) {
            $title = Html::trimText(strip_tags($this->title), $length);
            $length -= strlen($title);
        }

        if ($this->body instanceof Content) {
            $this->body = $this->body->toArray();
        }

        if ($this->body instanceof LegacyContent) {
            $this->body = $this->body->getValues();
        }

        if (!is_array($stripFields)) {
            trigger_error(sprintf('Wrong type for "stripField" parameter. Expected array, got %s. Ignoring "stripField".', gettype($stripFields)), E_USER_DEPRECATED);
            $stripFields = [];
        }

        if (is_array($this->body)) {
            // Assume it's an array, strip some common
            // fields that we don't need, merge with
            // the unwanted fields , implode the rest.
            $stripKeys = array_merge([
                'id',
                'slug',
                'datepublish',
                'datedepublish',
                'datecreated',
                'datechanged',
                'username',
                'ownerid',
                'title',
                'contenttype',
                'status',
                'taxonomy',
                'templatefields',
                'sortorder',
            ], $stripFields);

            $excerpt = '';
            array_walk($this->body, function ($value, $key) use (&$excerpt, $stripKeys) {
                if (in_array($key, $stripKeys)) {
                    return;
                }
                // We need non-empty strings that don't look like serialized JSON.
                // Otherwise, Twig Markup is also OK.
                if (is_string($value) && !empty($value) && !in_array($value[0], ['{', '[']) ||
                    $value instanceof Markup) {
                    $excerpt .= (string) $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);
    }
public function getExcerpt($length = 200, $includeTitle = false, $focus = null, $stripFields = [])
    {
        $title = null;
        if ($includeTitle && $this->title !== null) {
            $title = Html::trimText(strip_tags($this->title), $length);
            $length -= strlen($title);
        }

        if ($this->body instanceof Content) {
            $this->body = $this->body->toArray();
        }

        if ($this->body instanceof LegacyContent) {
            $this->body = $this->body->getValues();
        }

        if (!is_array($stripFields)) {
            trigger_error(sprintf('Wrong type for "stripField" parameter. Expected array, got %s. Ignoring "stripField".', gettype($stripFields)), E_USER_DEPRECATED);
            $stripFields = [];
        }

        if (is_array($this->body)) {
            // Assume it's an array, strip some common
            // fields that we don't need, merge with
            // the unwanted fields , implode the rest.
            $stripKeys = array_merge([
                'id',
                'slug',
                'datepublish',
                'datedepublish',
                'datecreated',
                'datechanged',
                'username',
                'ownerid',
                'title',
                'contenttype',
                'status',
                'taxonomy',
                'templatefields',
                'sortorder',
            ], $stripFields);

            $excerpt = '';
            array_walk($this->body, function ($value, $key) use (&$excerpt, $stripKeys) {
                if (in_array($key, $stripKeys)) {
                    return;
                }
                // We need non-empty strings that don't look like serialized JSON.
                // Otherwise, Twig Markup is also OK.
                if (is_string($value) && !empty($value) && !in_array($value[0], ['{', '[']) ||
                    $value instanceof Markup) {
                    $excerpt .= (string) $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);
    }
public function getExcerpt ( $ length = 200 , $ includeTitle = false , $ focus = null , $ stripFields = [ ] ) { $ title = null ; if ( $ includeTitle && $ this -> title !== null ) { $ title = Html :: trimText ( strip_tags ( $ this -> title ) , $ length ) ; $ length -= strlen ( $ title ) ; } if ( $ this -> body instanceof Content ) { $ this -> body = $ this -> body -> toArray ( ) ; } if ( $ this -> body instanceof LegacyContent ) { $ this -> body = $ this -> body -> getValues ( ) ; } if ( ! is_array ( $ stripFields ) ) { trigger_error ( sprintf ( 'Wrong type for "stripField" parameter. Expected array, got %s. Ignoring "stripField".' , gettype ( $ stripFields ) ) , E_USER_DEPRECATED ) ; $ stripFields = [ ] ; } if ( is_array ( $ this -> body ) ) { // Assume it's an array, strip some common // fields that we don't need, merge with // the unwanted fields , implode the rest. $ stripKeys = array_merge ( [ 'id' , 'slug' , 'datepublish' , 'datedepublish' , 'datecreated' , 'datechanged' , 'username' , 'ownerid' , 'title' , 'contenttype' , 'status' , 'taxonomy' , 'templatefields' , 'sortorder' , ] , $ stripFields ) ; $ excerpt = '' ; array_walk ( $ this -> body , function ( $ value , $ key ) use ( & $ excerpt , $ stripKeys ) { if ( in_array ( $ key , $ stripKeys ) ) { return ; } // We need non-empty strings that don't look like serialized JSON. // Otherwise, Twig Markup is also OK. if ( is_string ( $ value ) && ! empty ( $ value ) && ! in_array ( $ value [ 0 ] , [ '{' , '[' ] ) || $ value instanceof Markup ) { $ excerpt .= ( string ) $ 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 ) ; }
Get the excerpt of a given piece of text.

@param int               $length
@param bool              $includeTitle
@param array|string|null $focus
@param array             $stripFields

@return string|null
Get the excerpt of a given piece of text .