<commit_before><?php // $Id$
    //This function provides automatic linking to
    //activities when its name (title) is found inside every Moodle text
    //It's based in the glosssary filter by <NAME>
    //Modifications by stronk7.

    function activitynames_filter($courseid, $text) {

        global $CFG;

        if (empty($courseid)) {
            $courseid = SITEID;
        }

        $course = get_record("course","id",$courseid);
        $modinfo = unserialize($course->modinfo);

        if (!empty($modinfo)) {

            $linkarray = array();

            //Sort modinfo by name length
            usort($modinfo,'comparemodulenamesbylength');

            $cm = '';
            foreach ($modinfo as $activity) {
                //Exclude labels and hidden items
                if ($activity->mod != "label" && $activity->visible) {
                    $title = strip_tags(urldecode($activity->name));
                    $title = str_replace('"', "'", $title);
                    $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">";
                    $currentname = urldecode($activity->name);
                    if ($currentname = trim($currentname)) {
                        $linkarray[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                    }
                }
            }
            $text = filter_phrases ($text, $linkarray);
        }
        return $text;
    }



    //This function is used to order module names from longer to shorter
    function comparemodulenamesbylength($a, $b)  {
        if (strlen($a->name) == strlen($b->name)) {
            return 0;
        }
        return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
    }
?><commit_msg>Cache array of filterobjects per request.<commit_after><?php // $Id$
    //This function provides automatic linking to
    //activities when its name (title) is found inside every Moodle text
    //It's based in the glosssary filter by <NAME>
    //Modifications by stronk7.

    function activitynames_filter($courseid, $text) {

        global $CFG;

        static $activitylist;

        if (empty($courseid)) {
            $courseid = SITEID;
        }

        $course = get_record("course","id",$courseid);
        $modinfo = unserialize($course->modinfo);

        if (!empty($modinfo)) {

            $activitylist = array();      /// We will store all the activities here

            //Sort modinfo by name length
            usort($modinfo,'comparemodulenamesbylength');

            foreach ($modinfo as $activity) {
                //Exclude labels and hidden items
                if ($activity->mod != "label" && $activity->visible) {
                    $title = strip_tags(urldecode($activity->name));
                    $title = str_replace('"', "'", $title);
                    $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">";
                    $currentname = urldecode($activity->name);
                    if ($currentname = trim($currentname)) {
                        $activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                    }
                }
            }
            $text = filter_phrases ($text, $activitylist);
        }
        return $text;
    }



    //This function is used to order module names from longer to shorter
    function comparemodulenamesbylength($a, $b)  {
        if (strlen($a->name) == strlen($b->name)) {
            return 0;
        }
        return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
    }
?>
{'fraction_non_alphanumeric': 0.14339724547664057, 'fraction_numerical': 0.002160410477990818, 'mean_word_length': 1.878010878010878, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '644429', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1014, 'n_words': 253}