<commit_before><?PHP // $Id$

    require_once("../../config.php");
    require_once("lib.php");

    require_variable($id);           // course id
    optional_variable($search, "");  // search string
    optional_variable($page, "0");   // which page to show
    optional_variable($perpage, "20");   // which page to show

    $search = trim(strip_tags($search));

    if ($search) {
        $searchterms = explode(" ", $search);    // Search for words independently
        foreach ($searchterms as $key => $searchterm) {
            if (strlen($searchterm) < 2) {
                unset($searchterms[$key]);
            }
        }
        $search = trim(implode(" ", $searchterms));
    }

    if (! $course = get_record("course", "id", $id)) {
        error("Course id is incorrect.");
    }

    if ($course->category) {
        require_login($course->id);
    }

    add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=".urlencode(s($search)), "$search"); 

    $strforums = get_string("modulenameplural", "forum");
    $strsearch = get_string("search", "forum");
    $strsearchresults = get_string("searchresults", "forum");
    $strpage = get_string("page");

    $searchform = forum_print_search_form($course, s($search), true, "plain");

    if (!$search) {
        print_header("$course->shortname: $strsearch", "$course->fullname",
                 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> -> 
                  <A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search",
                  "", "", "&nbsp;", navmenu($course));

        print_simple_box_start("center");
        echo "<center>";
        echo "<br />";
        echo $searchform;
        echo "<br /><p>";
        print_string("searchhelp");
        echo "</p>";
        echo "</center>";
        print_simple_box_end();
    }

    if ($search) {

        $search = s($search);

        if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {


            print_header("$course->shortname: $strsearchresults", "$course->fullname",
                     "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> 
                      <a href=\"index.php?id=$course->id\">$strforums</a> -> 
                      <a href=\"search.php?id=$course->id\">$strsearch</a> -> \"$search\"", "search.search", 
                      "", "", "&nbsp;", navmenu($course));
            print_heading(get_string("nopostscontaining", "forum", $search));

            print_simple_box_start("center");
            echo "<center>";
            echo "<br />";
            echo $searchform;
            echo "<br /><p>";
            print_string("searchhelp");<commit_msg>Improved fix to $search variable<commit_after><?PHP // $Id$

    require_once("../../config.php");
    require_once("lib.php");

    require_variable($id);           // course id
    optional_variable($search, "");  // search string
    optional_variable($page, "0");   // which page to show
    optional_variable($perpage, "20");   // which page to show

    $search = trim(strip_tags($search));

    if ($search) {
        $searchterms = explode(" ", $search);    // Search for words independently
        foreach ($searchterms as $key => $searchterm) {
            if (strlen($searchterm) < 2) {
                unset($searchterms[$key]);
            }
        }
        $search = s(trim(implode(" ", $searchterms)));
    }

    if (! $course = get_record("course", "id", $id)) {
        error("Course id is incorrect.");
    }

    if ($course->category) {
        require_login($course->id);
    }

    add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=".urlencode($search)), $search); 

    $strforums = get_string("modulenameplural", "forum");
    $strsearch = get_string("search", "forum");
    $strsearchresults = get_string("searchresults", "forum");
    $strpage = get_string("page");

    $searchform = forum_print_search_form($course, $search, true, "plain");

    if (!$search) {
        print_header("$course->shortname: $strsearch", "$course->fullname",
                 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> -> 
                  <A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search",
                  "", "", "&nbsp;", navmenu($course));

        print_simple_box_start("center");
        echo "<center>";
        echo "<br />";
        echo $searchform;
        echo "<br /><p>";
        print_string("searchhelp");
        echo "</p>";
        echo "</center>";
        print_simple_box_end();
    }

    if ($search) {

        if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {


            print_header("$course->shortname: $strsearchresults", "$course->fullname",
                     "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> 
                      <a href=\"index.php?id=$course->id\">$strforums</a> -> 
                      <a href=\"search.php?id=$course->id\">$strsearch</a> -> \"$search\"", "search.search", 
                      "", "", "&nbsp;", navmenu($course));
            print_heading(get_string("nopostscontaining", "forum", $search));

            print_simple_box_start("center");
            echo "<center>";
            echo "<br />";
            echo $searchform;
            echo "<br /><p>";
            print_string("searchhelp");
{'fraction_non_alphanumeric': 0.20065075921908893, 'fraction_numerical': 0.0014461315979754157, 'mean_word_length': 2.3553668890236508, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 87, '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': '312008', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1624, 'n_words': 291}