<commit_before><?php

function removeDirectory($src)
{
    if (!($dir = @opendir($src))) {
        return;
    }

    while (false !== ($file = readdir($dir))) {
        if ($file === '.' || $file === '..') {
            continue;
        }

        if (is_dir($src.'/'.$file)) {
            removeDirectory($src.'/'.$file);

            continue;
        }

        unlink($src.'/'.$file);
    }

    closedir($dir);

    @rmdir($src);
}

function copyDirectory($src, $dst)
{
    $dir = opendir($src);
    @mkdir($dst);

    while (false !== ($file = readdir($dir))) {
        if (substr($file, 0, 1) === '.') {
            continue;
        }

        if (is_dir($src.'/'.$file)) {
            copyDirectory($src.'/'.$file, $dst.'/'.$file);

            continue;
        }

        copy($src.'/'.$file, $dst.'/'.$file);
    }

    closedir($dir);
}

function cacheDirectory($dir, $base = '')
{
    global $parser, $websiteDirectory, $changelogContent;

    foreach (scandir($dir) as $item) {
        if (substr($item, 0, 1) === '.') {
            continue;
        }

        if (is_dir($dir.'/'.$item)) {
            cacheDirectory($dir.'/'.$item, $base.'/'.$item);

            continue;
        }

        if (substr($item, -4) === '.rst') {
            $directory = $websiteDirectory.$base;

            if (!is_dir($directory)) {
                mkdir($directory, 0777, true);
            }

            $content = file_get_contents($dir.'/'.$item);
            $content = str_replace(
                '.. include:: ../release/parts/latest.rst',
                $changelogContent,
                $content
            );
            $content = $parser->parse($content);
            // Add one level to every title <h1> to <h2>, <h2> to <h3> etc.
            $content = preg_replace_callback('/(<\/?h)([1-6])/', function ($match) {
                return $match[1].($match[2] + 1);
            }, $content);
            $uri = $base.'/'.substr($item, 0, -4).'.html';

            $menu = buildMenu($uri);

            ob_start();
            include __DIR__.'/../src/site/resources/layout.php';
            $html = ob_get_contents();
            ob_end_clean();<commit_msg>Add links to releases<commit_after><?php

function removeDirectory($src)
{
    if (!($dir = @opendir($src))) {
        return;
    }

    while (false !== ($file = readdir($dir))) {
        if ($file === '.' || $file === '..') {
            continue;
        }

        if (is_dir($src.'/'.$file)) {
            removeDirectory($src.'/'.$file);

            continue;
        }

        unlink($src.'/'.$file);
    }

    closedir($dir);

    @rmdir($src);
}

function copyDirectory($src, $dst)
{
    $dir = opendir($src);
    @mkdir($dst);

    while (false !== ($file = readdir($dir))) {
        if (substr($file, 0, 1) === '.') {
            continue;
        }

        if (is_dir($src.'/'.$file)) {
            copyDirectory($src.'/'.$file, $dst.'/'.$file);

            continue;
        }

        copy($src.'/'.$file, $dst.'/'.$file);
    }

    closedir($dir);
}

function cacheDirectory($dir, $base = '')
{
    global $parser, $websiteDirectory, $changelogContent;

    foreach (scandir($dir) as $item) {
        if (substr($item, 0, 1) === '.') {
            continue;
        }

        if (is_dir($dir.'/'.$item)) {
            cacheDirectory($dir.'/'.$item, $base.'/'.$item);

            continue;
        }

        if (substr($item, -4) === '.rst') {
            $directory = $websiteDirectory.$base;

            if (!is_dir($directory)) {
                mkdir($directory, 0777, true);
            }

            $content = file_get_contents($dir.'/'.$item);
            $content = str_replace(
                '.. include:: ../release/parts/latest.rst',
                $changelogContent,
                $content
            );
            $content = $parser->parse($content);
            // Add one level to every title <h1> to <h2>, <h2> to <h3> etc.
            $content = preg_replace_callback('/(<\/?h)([1-6])/', function ($match) {
                return $match[1].($match[2] + 1);
            }, $content);
            $content = preg_replace(
                '/phpmd-(\d+\.\S+)/',
                '<a href="https://github.com/phpmd/phpmd/releases/tag/$1" title="$0 release">$0</a>',
                $content
            );
            $uri = $base.'/'.substr($item, 0, -4).'.html';

            $menu = buildMenu($uri);

            ob_start();
            include __DIR__.'/../src/site/resources/layout.php';
            $html = ob_get_contents();
            ob_end_clean();
{'fraction_non_alphanumeric': 0.20632497273718647, 'fraction_numerical': 0.009378407851690295, 'mean_word_length': 1.5822072072072073, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 1, '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': '1962169', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1430, 'n_words': 250}