<commit_before><?php
if (!defined('NELLIEL_VERSION'))
{
    die("NOPE.AVI");
}

function nel_thread_generator($dataforce, $board_id, $write, $write_id)
{
    $dbh = nel_database();
    $references = nel_board_references($board_id);
    $board_settings = nel_board_settings($board_id);
    $file_handler = nel_file_handler();

    if ($write)
    {
        nel_session_is_ignored('render', true);
    }

    $dataforce['dotdot'] = '../../../';
    $render = new NellielTemplates\RenderCore();
    $render->getTemplateInstance()->setTemplatePath(TEMPLATE_PATH);
    $dom = $render->newDOMDocument();
    $render->loadTemplateFromFile($dom, 'thread.html');
    nel_process_i18n($dom, nel_board_settings($board_id, 'board_language'));
    $expand_dom = $render->newDOMDocument();
    $collapse_dom = $render->newDOMDocument();
    $render->startRenderTimer();
    $dom->getElementById('form-post-index')->extSetAttribute('action', $dataforce['dotdot'] . PHP_SELF);

    $dataforce['response_id'] = $write_id;
    $prepared = $dbh->prepare('SELECT * FROM "' . $references['thread_table'] . '" WHERE "thread_id" = ? LIMIT 1');
    $gen_data['thread'] = $dbh->executePreparedFetch($prepared, array($write_id), PDO::FETCH_ASSOC);

    $prepared = $dbh->prepare('SELECT * FROM "' . $references['post_table'] .
         '" WHERE "parent_thread" = ? ORDER BY "post_number" ASC');
    $treeline = $dbh->executePreparedFetchAll($prepared, array($write_id), PDO::FETCH_ASSOC);

    if (empty($treeline))
    {
        return;
    }

    $gen_data['post_counter'] = 0;
    $gen_data['expand_post'] = FALSE;
    $dataforce['omitted_done'] = TRUE;
    $gen_data['first100'] = FALSE;
    $dataforce['posts_ending'] = false;
    $dataforce['index_rendering'] = false;
    $dataforce['abbreviate'] = false;

    while ($gen_data['post_counter'] < $gen_data['thread']['post_count'])
    {
        $gen_data['post'] = $treeline[$gen_data['post_counter']];

        if ($gen_data['post_counter'] === 0)
        {
            nel_render_board_header($board_id, $dataforce, $render, $treeline);
            nel_render_posting_form($board_id, $dataforce, $render);
        }

        if ($gen_data['post_counter'] == $gen_data['thread']['post_count'] - 1)
        {
            $dataforce['posts_ending'] = true;
        }

        if ($gen_data['post']['has_file'] == 1)
        {
            $prepared = $dbh->prepare('SELECT * FROM "' . $references['file_table'] .
                 '" WHERE "post_ref" = ? ORDER BY "file_order" ASC');
            $gen_data['files'] = $dbh->executePreparedFetchAll($prepared, array($gen_data['post']['post_number']), PDO::FETCH_ASSOC);
        }

        if ($gen_data['post_counter'] === 99)
        {
            $render_temp = clone $render;
            nel_render_insert_hr($dom);
            nel_render_board_footer($board_id, $render_temp, true);
            $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-0-100.html', $render_temp->outputRenderSet(), FILE_PERM, true);
            unset($render_temp);
        }

        if ($gen_data['post']['op'] == 1)
        {
            $base_new_post_node = nel_render_post($board_id, $dataforce, $render, FALSE, FALSE, $gen_data, $treeline, $dom);
            $expand_div = $dom->getElementById('thread-expand-');
            $expand_div->changeId('thread-expand-' . $gen_data['thread']['thread_id']);
            $omitted_element = $expand_div->getElementsByClassName('omitted-posts')->item(0);

            if ($gen_data['thread']['post_count'] > $board_settings['abbreviate_thread'])
            {
                $omitted_count = $gen_data['thread']['post_count'] - $board_settings['abbreviate_thread'];
                $omitted_element->firstChild->setContent($omitted_count);
            }
            else
            {
                $omitted_element->removeSelf();
            }

            $import_node = $collapse_dom->importNode($expand_div->cloneNode(true), true);
            $collapse_dom->appendChild($import_node);
            $expand_div->removeSelf();
        }
        else
        {
            $base_new_post_node = nel_render_post($board_id, $dataforce, $render, TRUE, FALSE, $gen_data, $treeline, $dom);

            if ($gen_data['thread']['post_count'] > $board_settings['abbreviate_thread'])
            {
                if ($gen_data['post_counter'] > $gen_data['thread']['post_count'] - $board_settings['abbreviate_thread'])
                {
                    $import_node = $collapse_dom->importNode($base_new_post_node, true);
                    $collapse_dom->getElementById('thread-expand-' . $gen_data['thread']['thread_id'])->appendChild($import_node);
                }
            }

            $import_node = $expand_dom->importNode($base_new_post_node, true);
            $expand_dom->appendChild($import_node);
        }

        $new_post_element = nel_render_post_adjust_relative($base_new_post_node, $gen_data);
        $imported = $dom->importNode($new_post_element, true);
        $dom->getElementById('thread-')->appendChild($imported);
        ++ $gen_data['post_counter'];
    }

    $dom->getElementById('post-id-')->removeSelf();
    $dom->getElementById('thread-')->changeId('thread-' . $write_id);
    nel_render_insert_hr($dom);
    nel_render_thread_form_bottom($board_id, $dom);
    $render->appendHTMLFromDOM($dom);
    $render->appendHTMLFromDOM($collapse_dom, 'collapse');
    $render->appendHTMLFromDOM($expand_dom, 'expand');
    nel_render_board_footer($board_id, $render, true);

    if ($write)
    {
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '.html', $render->outputRenderSet(), FILE_PERM, true);
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-expand.html', $render->outputRenderSet('expand'), FILE_PERM, true);
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-collapse.html', $render->outputRenderSet('collapse'), FILE_PERM, true);
    }
    else
    {
        if ($dataforce['expand'])
        {
            echo $render->outputRenderSet('expand');
        }
        else if ($dataforce['collapse'])
        {
            echo $render->outputRenderSet('collapse');<commit_msg>Fix a double hr in thread view<commit_after><?php
if (!defined('NELLIEL_VERSION'))
{
    die("NOPE.AVI");
}

function nel_thread_generator($dataforce, $board_id, $write, $write_id)
{
    $dbh = nel_database();
    $references = nel_board_references($board_id);
    $board_settings = nel_board_settings($board_id);
    $file_handler = nel_file_handler();

    if ($write)
    {
        nel_session_is_ignored('render', true);
    }

    $dataforce['dotdot'] = '../../../';
    $render = new NellielTemplates\RenderCore();
    $render->getTemplateInstance()->setTemplatePath(TEMPLATE_PATH);
    $dom = $render->newDOMDocument();
    $render->loadTemplateFromFile($dom, 'thread.html');
    nel_process_i18n($dom, nel_board_settings($board_id, 'board_language'));
    $expand_dom = $render->newDOMDocument();
    $collapse_dom = $render->newDOMDocument();
    $render->startRenderTimer();
    $dom->getElementById('form-post-index')->extSetAttribute('action', $dataforce['dotdot'] . PHP_SELF);

    $dataforce['response_id'] = $write_id;
    $prepared = $dbh->prepare('SELECT * FROM "' . $references['thread_table'] . '" WHERE "thread_id" = ? LIMIT 1');
    $gen_data['thread'] = $dbh->executePreparedFetch($prepared, array($write_id), PDO::FETCH_ASSOC);

    $prepared = $dbh->prepare('SELECT * FROM "' . $references['post_table'] .
         '" WHERE "parent_thread" = ? ORDER BY "post_number" ASC');
    $treeline = $dbh->executePreparedFetchAll($prepared, array($write_id), PDO::FETCH_ASSOC);

    if (empty($treeline))
    {
        return;
    }

    $gen_data['post_counter'] = 0;
    $gen_data['expand_post'] = FALSE;
    $dataforce['omitted_done'] = TRUE;
    $gen_data['first100'] = FALSE;
    $dataforce['posts_ending'] = false;
    $dataforce['index_rendering'] = false;
    $dataforce['abbreviate'] = false;
    $hr_added = false;

    while ($gen_data['post_counter'] < $gen_data['thread']['post_count'])
    {

        $gen_data['post'] = $treeline[$gen_data['post_counter']];

        if ($gen_data['post_counter'] === 0)
        {
            nel_render_board_header($board_id, $dataforce, $render, $treeline);
            nel_render_posting_form($board_id, $dataforce, $render);
        }

        if ($gen_data['post_counter'] == $gen_data['thread']['post_count'] - 1)
        {
            $dataforce['posts_ending'] = true;
        }

        if ($gen_data['post']['has_file'] == 1)
        {
            $prepared = $dbh->prepare('SELECT * FROM "' . $references['file_table'] .
                 '" WHERE "post_ref" = ? ORDER BY "file_order" ASC');
            $gen_data['files'] = $dbh->executePreparedFetchAll($prepared, array($gen_data['post']['post_number']), PDO::FETCH_ASSOC);
        }

        if ($gen_data['post_counter'] === 99)
        {
            $render_temp = clone $render;
            nel_render_insert_hr($dom);
            $hr_added = true;
            nel_render_board_footer($board_id, $render_temp, true);
            $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-0-100.html', $render_temp->outputRenderSet(), FILE_PERM, true);
            unset($render_temp);
        }

        if ($gen_data['post']['op'] == 1)
        {
            $base_new_post_node = nel_render_post($board_id, $dataforce, $render, FALSE, FALSE, $gen_data, $treeline, $dom);
            $expand_div = $dom->getElementById('thread-expand-');
            $expand_div->changeId('thread-expand-' . $gen_data['thread']['thread_id']);
            $omitted_element = $expand_div->getElementsByClassName('omitted-posts')->item(0);

            if ($gen_data['thread']['post_count'] > $board_settings['abbreviate_thread'])
            {
                $omitted_count = $gen_data['thread']['post_count'] - $board_settings['abbreviate_thread'];
                $omitted_element->firstChild->setContent($omitted_count);
            }
            else
            {
                $omitted_element->removeSelf();
            }

            $import_node = $collapse_dom->importNode($expand_div->cloneNode(true), true);
            $collapse_dom->appendChild($import_node);
            $expand_div->removeSelf();
        }
        else
        {
            $base_new_post_node = nel_render_post($board_id, $dataforce, $render, TRUE, FALSE, $gen_data, $treeline, $dom);

            if ($gen_data['thread']['post_count'] > $board_settings['abbreviate_thread'])
            {
                if ($gen_data['post_counter'] > $gen_data['thread']['post_count'] - $board_settings['abbreviate_thread'])
                {
                    $import_node = $collapse_dom->importNode($base_new_post_node, true);
                    $collapse_dom->getElementById('thread-expand-' . $gen_data['thread']['thread_id'])->appendChild($import_node);
                }
            }

            $import_node = $expand_dom->importNode($base_new_post_node, true);
            $expand_dom->appendChild($import_node);
        }

        $new_post_element = nel_render_post_adjust_relative($base_new_post_node, $gen_data);
        $imported = $dom->importNode($new_post_element, true);
        $dom->getElementById('thread-')->appendChild($imported);
        ++ $gen_data['post_counter'];
    }

    $dom->getElementById('post-id-')->removeSelf();
    $dom->getElementById('thread-')->changeId('thread-' . $write_id);

    if(!$hr_added)
    {
        nel_render_insert_hr($dom);
    }

    nel_render_thread_form_bottom($board_id, $dom);
    $render->appendHTMLFromDOM($dom);
    $render->appendHTMLFromDOM($collapse_dom, 'collapse');
    $render->appendHTMLFromDOM($expand_dom, 'expand');
    nel_render_board_footer($board_id, $render, true);

    if ($write)
    {
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '.html', $render->outputRenderSet(), FILE_PERM, true);
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-expand.html', $render->outputRenderSet('expand'), FILE_PERM, true);
        $file_handler->writeFile($references['page_path'] . $write_id . '/' . $write_id . '-collapse.html', $render->outputRenderSet('collapse'), FILE_PERM, true);
    }
    else
    {
        if ($dataforce['expand'])
        {
            echo $render->outputRenderSet('expand');
        }
        else if ($dataforce['collapse'])
        {
            echo $render->outputRenderSet('collapse');
{'fraction_non_alphanumeric': 0.17219065656565657, 'fraction_numerical': 0.002840909090909091, 'mean_word_length': 3.110606552059682, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 111, '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': '407547', 'n_tokens_mistral': 4055, 'n_tokens_neox': 3937, 'n_words': 520}