Handle the content's BB codes

@param  string $content
@return string
769262
protected function bbCodesHandle($content) {
		$bbCodes = $this->getTagsLocator();
		
		return preg_replace_callback('~\[([a-z]+)\](.*?)\[/\1\]~', function($match) use($bbCodes) {
			array_shift($match);
			list($tag, $value) = $match;
			
			if (preg_match('~\[[a-z]+\]~', $value)) {
				$value = $this->bbCodesHandle($value);
			}
			
			if ($bbCodes->has($tag)) {
				return $bbCodes->get($tag)->render($value);
			}
			
			return $value;
		}, $content);
	}
571505
protected function shortenBools($content)
    {
        /*
         * 'true' or 'false' could be used as property names (which may be
         * followed by whitespace) - we must not replace those!
         * Since PHP doesn't allow variable-length (to account for the
         * whitespace) lookbehind assertions, I need to capture the leading
         * character and check if it's a `.`
         */
        $callback = function ($match) {
            if (trim($match[1]) === '.') {
                return $match[0];
            }

            return $match[1].($match[2] === 'true' ? '!0' : '!1');
        };
        $content = preg_replace_callback('/(^|.\s*)\b(true|false)\b(?!:)/', $callback, $content);

        // for(;;) is exactly the same as while(true), but shorter :)
        $content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content);

        // now make sure we didn't turn any do ... while(true) into do ... for(;;)
        preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);

        // go backward to make sure positional offsets aren't altered when $content changes
        $dos = array_reverse($dos);
        foreach ($dos as $do) {
            $offsetDo = $do[0][1];

            // find all `while` (now `for`) following `do`: one of those must be
            // associated with the `do` and be turned back into `while`
            preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo);
            foreach ($whiles as $while) {
                $offsetWhile = $while[0][1];

                $open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo);
                $close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo);
                if ($open === $close) {
                    // only restore `while` if amount of `{` and `}` are the same;
                    // otherwise, that `for` isn't associated with this `do`
                    $content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)'));
                    break;
                }
            }
        }

        return $content;
    }
962764
function strip_shortcodes( $content ) {
	global $shortcode_tags;

	if (empty($shortcode_tags) || !is_array($shortcode_tags))
		return $content;

	$pattern = $this->get_shortcode_regex();

	return preg_replace('/'.$pattern.'/s', '$1$6', $content);
}
341037
protected function formatContent($content)
    {
        return str_replace(
            ['{{slug}}', '{{name}}', '{{namespace}}'],
            [$this->slug, $this->name, $this->pluggable->getNamespace()],
            $content
        );
    }
551431
public function parseContent($content)
    {
        $cto = $this->getContentTypeObject();
        if (!empty($cto)) {
            return $cto->parseContent($content);
        } else {
            return $content;
        }
    }
761425
public function easyReadingContent($content)
	{
		global $post;

		if (isset($_GET['readable']) && $_GET['readable'] == '1' && get_field('easy_reading_select') == true && is_object($post) && isset($post->post_content) && in_the_loop() && is_main_query()) {
			$post_content = $post->post_content;
			if (strpos($post_content,  '<!--more-->') !== false) {
				$content_parts = explode('<!--more-->', $post_content);
				$post_content  = $content_parts[1];
			}
			$post_content 	   = preg_replace('/[^a-z]/i', '', sanitize_text_field($post_content));
			$sanitized_content = preg_replace('/[^a-z]/i', '', sanitize_text_field($content));

			if ($post_content == $sanitized_content) {
				$content = get_field('easy_reading_content');
				if (strpos($content,  '<!--more-->') !== false) {
					$content_parts = explode('<!--more-->', $content);
					$content = '<p class="lead">' . sanitize_text_field($content_parts[0]) . '</p>' . $content_parts[1];
				}
			}
		}

		return $content;
	}
1005593
public function sanitizeInput(string $content):string{
		return htmlspecialchars($content, ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_DISALLOWED | ENT_HTML5, 'UTF-8', false);
	}
246386
public function escapeXmlContent($content)
    {
        if (is_object($content) || is_array($content)) {
            if (method_exists($content, 'getUuid')) {
                return $content->getUuid();
            }

            return 'ERROR: wrong data';
        }

        if (preg_match('/[<>{}"&]/', $content)) {
            $content = '<![CDATA[' . $content . ']]>';
        }

        return $content;
    }
1066021
protected function processVars(string &$content): void
    {
        $pattern = $this->getTagPattern('(\$.+?)');
        $content = preg_replace_callback($pattern, function ($match) {
            return '<?php echo ' . $match[1] . '; ?>';
        }, $content);
    }
25935
public function convert($content)
    {
        $result = strtr($content, $this->rules);
        return $this->correct($result);
    }
1112898
protected function re($content)
    {
        preg_match_all('/more_list">(.*?)<\/ul>/s', $content, $match_ul);
        preg_match_all('/href="(.*?)" .*?">(.*?)</s', $match_ul[1][0], $match_li);
        preg_match_all('/\[(.*?)\]/', $match_ul[1][0], $match_time);

        $list = [];
        foreach ($match_li[0] as $key => $value) {
            $list[$key]['title'] = trim(mb_convert_encoding($match_li[2][$key], 'UTF-8', 'GB2312'));
            $list[$key]['url'] = trim(Config::$config['url_index'] . $match_li[1][$key]);
            $list[$key]['time'] = trim(mb_convert_encoding($match_time[1][$key], 'UTF-8', 'GB2312'));
        }
        return $list;
    }
1190024
private function fixContentEncoding($content)
    {
        if (!empty($content)) {
            // Little hack to force UTF-8
            if (false === strpos($content, '<?xml encoding')) {
                $hack = false === strpos(
                    $content,
                    '<body'
                ) ? '<?xml encoding="UTF-8"><body>' : '<?xml encoding="UTF-8">';
                $content = $hack.$content;
            }

            $encoding = mb_detect_encoding($content);
            $headPos = mb_strpos($content, '<head>');

            // Add a meta to the <head> section
            if (false !== $headPos) {
                $headPos += 6;
                $content = mb_substr($content, 0, $headPos).
                    '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'">'.
                    mb_substr($content, $headPos);
            }

            $content = mb_convert_encoding($content, 'HTML-ENTITIES', $encoding);
        }

        return $content;
    }
1294633
public static function get_content_value($content) {
        $arr = explode('##', $content->content);

        $strvalue = '';
        foreach ($arr as $a) {
            $strvalue .= $a . ' ';
        }

        return trim($strvalue, "\r\n ");
    }
1277786
protected function correct($content)
    {
        $corrections = $this->corrections;
        if (!empty($corrections)) {
            foreach ($corrections as $pattern => $replacement) {
                $reg_count = 0;

                /**
                 * @var $content
                 * reassign $content to corrected $content as long as corrections
                 * rules array loop
                 */
                $content = preg_replace('/' .
                    $pattern .
                    '/us', $replacement, $content, -1, $reg_count);
            }
        }
        return $content;
    }
247340
public function build($content)
    {
        $examples = $this->parser->extractExamples($content);

        for ($i = 0; $i < count($examples); $i++)
        {
            $examples[$i] =
                "## Example #".($i + 1)."\n\n".$this->buildBlock($examples[$i]);
        }

        return "# Examples\n\n".implode("\n", $examples);
    }
1005045
protected function processEndCondition(string &$content): void
    {
        $pattern = $this->getTagPattern(preg_quote('/', '/') . '(if|loop)');
        $content = preg_replace_callback($pattern, function ($match) {
            return '<?php } ?>';
        }, $content);
    }
372083
public function doShortcode($content)
    {
        if (false === strpos($content, '[')) {
            return $content;
        }

        if (empty($this->_shortcodes) || !is_array($this->_shortcodes))
            return $content;

        /**
         * Clear content from ignore blocks
         */
        $pattern = $this->getIgnorePattern();
        $content = preg_replace_callback("~$pattern~isu", ['self', '_stack'], $content);

        /**
         * parse nested
         */
        $content = $this->parseContent($content);

        /**
         * Replase shorcodes in content
         */
        $content = strtr($content, self::_stack());

        return $content;
    }