Build Teasercontent

@param string $content The whole resultcontent
@return string The cutted recultcontent
193839
public function buildTeaserContent($content)
    {
        if (is_array($this->pObj->swords) && count($this->pObj->swords)) {
            $amountOfSearchWords = count($this->pObj->swords);
            $content = strip_tags($content);
            // with each new searchword and all the croppings here the teaser for each word will become too small/short
            // I decided to add 20 additional letters for each searchword. It looks much better and is more readable
            $charsForEachSearchWord = ceil($this->conf['resultChars'] / $amountOfSearchWords) + 20;
            $charsBeforeAfterSearchWord = ceil($charsForEachSearchWord / 2);
            $aSearchWordWasFound = false;
            $isSearchWordAtTheBeginning = false;
            $teaserArray = [];
            foreach ($this->pObj->swords as $word) {
                // Always remove whitespace around searchword first
                $word = trim($word);

                // Check teaser text array first to avoid duplicate text parts
                if (count($teaserArray) > 0) {
                    foreach ($teaserArray as $teaserArrayItem) {
                        $searchWordPositionInTeaserArray = mb_stripos($teaserArrayItem, $word);
                        if (false === $searchWordPositionInTeaserArray) {
                            continue;
                        } else {
                            // One finding in teaser text array is sufficient
                            $aSearchWordWasFound = true;
                            break;
                        }
                    }
                }

                // Only search for current search word in content if it wasn't found in teaser text array already
                if (false === $aSearchWordWasFound) {
                    $pos = mb_stripos($content, $word);
                    if (false === $pos) {
                        continue;
                    }
                    $aSearchWordWasFound = true;

                    // if search word is the first word
                    if (0 === $pos) {
                        $isSearchWordAtTheBeginning = true;
                    }

                    // find search starting point
                    $startPos = $pos - $charsBeforeAfterSearchWord;
                    if ($startPos < 0) {
                        $startPos = 0;
                    }

                // crop some words behind searchword
                $partWithSearchWord = mb_substr($content, $startPos);
                $temp = $this->cObj->crop($partWithSearchWord, $charsForEachSearchWord . '|…|1');

                    // crop some words before search word
                    // after last cropping our text is too short now. So we have to find a new cutting position
                    ($startPos > 10) ? $length = strlen($temp) - 10 : $length = strlen($temp);

                    // Store content part containing the search word in teaser text array
                    $teaserArray[] = $this->cObj->crop($temp, '-' . $length . '||1');
                }
            }

            // When the searchword was found in title but not in content the teaser is empty
            // in that case we have to get the first x letters without containing any searchword
            if ($aSearchWordWasFound === false) {
                $teaser = $this->cObj->crop($content, $this->conf['resultChars'] . '||1');
            } elseif ($isSearchWordAtTheBeginning === true) {
                $teaser = implode(' ', $teaserArray);
            } else {
                $teaser = '…' . implode(' ', $teaserArray);
            }

            // highlight hits?
            if ($this->conf['highlightSword']) {
                $teaser = $this->highlightArrayOfWordsInContent($this->pObj->swords, $teaser);
            }
            return $teaser;
        } else {
            return $this->cObj->crop($content, $this->conf['resultChars'] . '|…|1');
        }
    }
254833
public function parseNoTemplate($content) {
        $this->_content = $content;
        $this->_parseDebugStart();
        $this->_parseExtend();
        $this->_parseInclude();
        $this->_parsePath();
        $this->_parseGravatar();
        $this->_parseAsset();
        $this->_parseUrl();
        $this->_parsePhp();
        $this->_parseLang();
        $this->_parseForeach();
        $this->_parseFor();
        $this->_parseVar();
        $this->_parseVarFunc();
        $this->_parseCondition();
        $this->_parseFunction();
        $this->_parseException();
        $this->_parseMinify();
        $this->_parseDebugEnd();

        return $this->_content;
    }
341037
protected function formatContent($content)
    {
        return str_replace(
            ['{{slug}}', '{{name}}', '{{namespace}}'],
            [$this->slug, $this->name, $this->pluggable->getNamespace()],
            $content
        );
    }
564785
public function getSerializedContent($content)
    {
        $serializationContext = clone $this->serializationContext;

        return $this->serializer->serialize(
            $content,
            'json',
            $serializationContext
        );
    }
1349698
public static function bb(&$content)
    {
        $content = preg_replace(array_flip(self::$_bbs), self::$_bbs, $content);

        return $content;
    }
197833
protected function createDocumentFromXML($content)
    {
        $previousValue = libxml_use_internal_errors(true);

        $document = new DOMDocument();
        $document->strictErrorChecking = false;
        $document->loadXML(trim($content));

        libxml_use_internal_errors($previousValue);

        return $document;
    }
880882
public static function encodeUnicode($content)
    {
        $content = self::shortcodeToUnicode($content);
        $content = self::entitiesToUnicode($content);

        return $content;
    }
674529
public static function fromString(string $content)
    {
        $arr = \json_decode($content, JSON_PRETTY_PRINT);
        $arr = attrToArray($arr);
        return fromArray($arr);
    }
669287
private function buildHeader(string $content): string
    {
        // needed for rooms with special (spaces, etc) characters in the name
        $room = rawurlencode($this->room);
        $header = "POST /v2/room/{$room}/notification?auth_token={$this->token} HTTP/1.1\r\n";

        $header .= "Host: {$this->host}\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . strlen($content) . "\r\n";
        $header .= "\r\n";

        return $header;
    }
1016051
public function getShortcodesFromContent($content)
    {
        $content = $this->getContentWithoutIgnoreBlocks($content);

        if (false === strpos($content, '[')) {
            return [];
        }

        $result = [];

        $regex = "\[([A-Za-z_]+[^\ \]]+)";
        preg_match_all('/' . $regex . '/', $content, $matches);

        if (!empty($matches[1])) {
            foreach ($matches[1] as $match) {
                $result[$match] = $match;
            }
        }

        if ($result) {
            return array_keys($result);
        }

        return $result;
    }
1051268
protected function parseContent($content)
    {
        $content = preg_replace_callback($this->shortcodeRegex(), [$this, 'doShortcodeTag'], $content);
        if (!$this->isFinishedParse()) {
            $content = $this->parseContent($content);
        }
        return $content;
    }
295106
public function getExcerpt($content = null)
    {
        $raw = $exc = $this->base->post_excerpt;

        if (!strlen($exc)) {
            $exc = $content === null ? $this->getRawContent() : $content;
            $exc = strip_shortcodes($exc);
            $exc = apply_filters('the_content', $exc);
            $exc = str_replace(']]>', ']]&gt;', $exc);
            $exc = wp_trim_words(
                $exc,
                apply_filters('excerpt_length', 55),
                apply_filters('excerpt_more', ' ' . '[&hellip;]')
            );
        }

        return apply_filters('wp_trim_excerpt', $exc, $raw);
    }
986131
public function strip($content)
    {
        if (empty($this->shortcodes)) {
            return $content;
        }

        $pattern = $this->getRegex();

        return preg_replace_callback("/{$pattern}/s", function ($m) {
            if ($m[1] == '[' && $m[6] == ']') {
                return substr($m[0], 1, -1);
            }

            return $m[1].$m[6];
        }, $content);
    }
560629
protected function detectFormatByContent($content)
    {
        if (preg_match('/^(\\{|\\[\\{).*(\\}|\\}\\])$/is', $content)) {
            return Client::FORMAT_JSON;
        }
        if (preg_match('/^([^=&])+=[^=&]+(&[^=&]+=[^=&]+)*$/', $content)) {
            return Client::FORMAT_URLENCODED;
        }
        if (preg_match('/^<\?xml.*>$/s', $content)) {
            return Client::FORMAT_XML;
        }
        return null;
    }
842446
protected function proccessResult($content){
        $obj = json_decode($content, true);

        if($obj === null){
            $obj = array(
                'content' => $content
            );
        }

        return $obj;
    }
638921
public function appendContent($content)
    {
        if (!empty($content)) {
            if (is_array($this->content)) {
                $this->content[] = $content;
            } else {
                $this->content .= $content;
            }
        }
        return $this;
    }
1087233
public function getLayout(& $content)
    {
        //$res = preg_match("/\<\!-- php__layout\((.+)\) --\>/", $str, $match);
        $res = preg_match("/\{layout\s+(.+)\}/", $content, $match);
        if ($res) {
            return str_replace(array('"', '\'', '.html'), '', $match[1]);
        }
        return null;
    }