<commit_before><?php

namespace wcf\system\template\plugin;

use wcf\system\template\TemplateScriptingCompiler;
use wcf\util\StringUtil;

/**
 * Template prefilter plugin which allows inserting code dynamically upon the contents
 * of 'content'.
 *
 * Usage:
 *  {hascontent}
 *  <ul>
 *      {content}
 *          {if $foo}<li>bar</li>{/if}
 *      {/content}
 *  </ul>
 *  {hascontentelse}
 *      <p>baz</p>
 *  {/hascontent}
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\System\Template\Plugin
 */
class HascontentPrefilterTemplatePlugin implements IPrefilterTemplatePlugin
{
    /**
     * @inheritDoc
     */
    public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler)
    {
        $ldq = \preg_quote($compiler->getLeftDelimiter(), '~');
        $rdq = \preg_quote($compiler->getRightDelimiter(), '~');

        return \preg_replace_callback(
            "~{$ldq}hascontent( assign='(?P<assign>.*)')?{$rdq}(?P<before>.*){$ldq}content{$rdq}(?P<content>.*){$ldq}\\/content{$rdq}(?P<after>.*)({$ldq}hascontentelse{$rdq}(?P<else>.*))?{$ldq}\\/hascontent{$rdq}~sU",
            ['self', 'replaceContentCallback'],
            $sourceContent
        );
    }

    /**
     * Reorders content to provide a logical order. In fact the content of
     * '{content}' is moved outside the if-condition in order to capture
     * the content during runtime, safely determining whether content is empty
     * or not.
     *
     * @param array $matches
     * @return  string
     */
    protected static function replaceContentCallback(array $matches)
    {
        $beforeContent = $matches['before'];
        $content = $matches['content'];
        $afterContent = $matches['after'];<commit_msg>Fix PHP 8.2 compatibility in HascontentPrefilterTemplatePlugin<commit_after><?php

namespace wcf\system\template\plugin;

use wcf\system\template\TemplateScriptingCompiler;
use wcf\util\StringUtil;

/**
 * Template prefilter plugin which allows inserting code dynamically upon the contents
 * of 'content'.
 *
 * Usage:
 *  {hascontent}
 *  <ul>
 *      {content}
 *          {if $foo}<li>bar</li>{/if}
 *      {/content}
 *  </ul>
 *  {hascontentelse}
 *      <p>baz</p>
 *  {/hascontent}
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\System\Template\Plugin
 */
class HascontentPrefilterTemplatePlugin implements IPrefilterTemplatePlugin
{
    /**
     * @inheritDoc
     */
    public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler)
    {
        $ldq = \preg_quote($compiler->getLeftDelimiter(), '~');
        $rdq = \preg_quote($compiler->getRightDelimiter(), '~');

        return \preg_replace_callback(
            "~{$ldq}hascontent( assign='(?P<assign>.*)')?{$rdq}(?P<before>.*){$ldq}content{$rdq}(?P<content>.*){$ldq}\\/content{$rdq}(?P<after>.*)({$ldq}hascontentelse{$rdq}(?P<else>.*))?{$ldq}\\/hascontent{$rdq}~sU",
            [self::class, 'replaceContentCallback'],
            $sourceContent
        );
    }

    /**
     * Reorders content to provide a logical order. In fact the content of
     * '{content}' is moved outside the if-condition in order to capture
     * the content during runtime, safely determining whether content is empty
     * or not.
     *
     * @param array $matches
     * @return  string
     */
    protected static function replaceContentCallback(array $matches)
    {
        $beforeContent = $matches['before'];
        $content = $matches['content'];
        $afterContent = $matches['after'];
{'fraction_non_alphanumeric': 0.15479957805907174, 'fraction_numerical': 0.004746835443037975, 'mean_word_length': 3.2762119503945883, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5017071', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1157, 'n_words': 240}