ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç PK\0Q~44db/install.phpnu[. /** * Filter post install hook * * @package filter_activitynames * @copyright 2012 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_filter_activitynames_install() { global $CFG; require_once("$CFG->libdir/filterlib.php"); filter_set_global_state('activitynames', TEXTFILTER_ON, 1); } PK\'\db/renamedclasses.phpnu[. /** * Renamed classes for the filter_activitynames plugin. * * @package filter_activitynames * @copyright Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; $renamedclasses = [ 'filter_activitynames' => \filter_activitynames\text_filter::class, ]; PK\fvkk lang/en/filter_activitynames.phpnu[. /** * Strings for component 'filter_activitynames', language 'en', branch 'MOODLE_20_STABLE' * * @package filter_activitynames * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['filtername'] = 'Activity names auto-linking'; $string['privacy:metadata'] = 'The Activity names auto-linking plugin does not store any personal data.'; PK\qE3 version.phpnu[. /** * Version details * * @package filter * @subpackage activitynames * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2025041400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'filter_activitynames'; // Full name of the plugin (used for diagnostics) PK\c filter.phpnu[. /** * File only retained to prevent fatal errors in code that tries to require/include this. * * @todo MDL-82708 delete this file as part of Moodle 6.0 development. * @deprecated This file is no longer required in Moodle 4.5+. * @package filter_activitynames * @copyright Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); debugging('This file is no longer required in Moodle 4.5+. Please do not include/require it.', DEBUG_DEVELOPER); PK\_ įclasses/privacy/provider.phpnu[. /** * Privacy Subsystem implementation for filter_activitynames. * * @package filter_activitynames * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace filter_activitynames\privacy; defined('MOODLE_INTERNAL') || die(); /** * Privacy Subsystem for filter_activitynames implementing null_provider. * * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements \core_privacy\local\metadata\null_provider { /** * Get the language string identifier with the component's language * file to explain why this plugin stores no data. * * @return string */ public static function get_reason(): string { return 'privacy:metadata'; } } PK\NH4classes/text_filter.phpnu[. namespace filter_activitynames; use cache; use cache_store; use core\output\html_writer; use core_collator; use course_modinfo; use filterobject; /** * This filter provides automatic linking to * activities when its name (title) is found inside every Moodle text * * @package filter_activitynames * @subpackage activitynames * @copyright 2004 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class text_filter extends \core_filters\text_filter { #[\Override] public function filter($text, array $options = []) { $coursectx = $this->context->get_course_context(false); if (!$coursectx) { return $text; } $courseid = $coursectx->instanceid; $activitylist = $this->get_cached_activity_list($courseid); $filterslist = []; if (!empty($activitylist)) { $cmid = $this->context->instanceid; if ($this->context->contextlevel == CONTEXT_MODULE && isset($activitylist[$cmid])) { // Remove filterobjects for the current module. $filterslist = array_values(array_diff_key($activitylist, [$cmid => 1, $cmid . '-e' => 1])); } else { $filterslist = array_values($activitylist); } } if ($filterslist) { // Modify each filter's regex pattern to match any whitespace sequence where there are spaces. // This allows matching activity names regardless of whether users type single spaces, double spaces, // or non-breaking spaces (which HTML editors often insert). $filterslist = filter_prepare_phrases_for_filtering($filterslist); foreach ($filterslist as $filterobject) { if ($filterobject->workregexp !== null) { $filterobject->workregexp = self::replace_spaces_with_whitespace($filterobject->workregexp); } } return filter_phrases($text, $filterslist, null, null, false, true); } else { return $text; } } /** * Replace literal spaces in a regex with general whitespace match. * * @param string $regex The regex pattern containing literal spaces. * @return string The regex pattern with spaces replaced. */ protected static function replace_spaces_with_whitespace($regex): string { return preg_replace_callback('/ +/', function($matches): string { $count = strlen($matches[0]); // Matches regular space, non-breaking space (U+00A0), or other whitespace. return '(?:[\s\xC2\xA0]{' . $count . '})'; }, $regex); } /** * Get all the cached activity list for a course * * @param int $courseid id of the course * @return filterobject[] the activities */ protected function get_cached_activity_list($courseid) { global $USER; $cached = cache::make_from_params(cache_store::MODE_REQUEST, 'filter', 'activitynames'); // Return cached activity list. if ($cached->get('cachecourseid') == $courseid && $cached->get('cacheuserid') == $USER->id) { return $cached->get('activitylist'); } // Not cached yet, get activity list and set cache. $activitylist = $this->get_activity_list($courseid); $cached->set('cacheuserid', $USER->id); $cached->set('cachecourseid', $courseid); $cached->set('activitylist', $activitylist); return $activitylist; } /** * Get all the activity list for a course * * @param int $courseid id of the course * @return filterobject[] the activities */ protected function get_activity_list($courseid) { $activitylist = []; $modinfo = get_fast_modinfo($courseid); if (!empty($modinfo->cms)) { $activitylist = []; // We will store all the created filters here. // Create array of visible activities sorted by the name length (we are only interested in properties name and url). $sortedactivities = []; foreach ($modinfo->cms as $cm) { // Use normal access control and visibility, but exclude labels and hidden activities. if ( $cm->visible && $cm->has_view() && $cm->uservisible && course_modinfo::is_mod_type_visible_on_course($cm->modname) ) { $sortedactivities[] = (object)[ 'name' => $cm->name, 'url' => $cm->url, 'id' => $cm->id, 'namelen' => -strlen($cm->name), // Negative value for reverse sorting. ]; } } // Sort activities by the length of the activity name in reverse order. core_collator::asort_objects_by_property($sortedactivities, 'namelen', core_collator::SORT_NUMERIC); foreach ($sortedactivities as $cm) { $title = s(trim(strip_tags($cm->name))); $currentname = trim($cm->name); // Normalize whitespace in activity names to handle double spaces and non-breaking spaces. // This ensures that activities with multiple consecutive spaces can still be matched // even when users type the name with different whitespace (e.g., single space, NBSP). $entitisedname = s($currentname); // Avoid empty or unlinkable activity names. if (!empty($title)) { $hreftagbegin = html_writer::start_tag( 'a', ['class' => 'autolink', 'title' => $title, 'href' => $cm->url, ] ); $activitylist[$cm->id] = new filterobject($currentname, $hreftagbegin, '', false, true); if ($currentname != $entitisedname) { // If name has some entity (& " < >) add that filter too. MDL-17545. $activitylist[$cm->id . '-e'] = new filterobject($entitisedname, $hreftagbegin, '', false, true); } } } } return $activitylist; } }PK\r#r#tests/text_filter_test.phpnu[. namespace filter_activitynames; /** * Test case for the activity names auto-linking filter. * * @package filter_activitynames * @copyright 2018 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \filter_activitynames\text_filter */ final class text_filter_test extends \advanced_testcase { public function test_links(): void { $this->resetAfterTest(true); // Create a test course. $course = $this->getDataGenerator()->create_course(); $context = \context_course::instance($course->id); // Create two pages that will be linked to. $page1 = $this->getDataGenerator()->create_module( 'page', ['course' => $course->id, 'name' => 'Test 1'] ); $page2 = $this->getDataGenerator()->create_module( 'page', ['course' => $course->id, 'name' => 'Test (2)'] ); // Create a label and question bank that should not be linked to. $this->getDataGenerator()->create_module( 'label', ['course' => $course->id, 'name' => 'Label 1', 'intro' => 'Label 1'] ); $this->getDataGenerator()->create_module( 'qbank', ['course' => $course->id, 'name' => 'Question bank 1'] ); // Format text with all three entries in HTML. $html = '

Please read the two pages Test 1 and Test (2), but not Label 1 or Question bank 1.

'; $filtered = format_text($html, FORMAT_HTML, ['context' => $context]); // Find all the glossary links in the result. $matches = []; preg_match_all( '~([^<]*)~', $filtered, $matches ); // There should be 2 links links. $this->assertCount(2, $matches[1]); // Check text of title attribute. $this->assertEquals($page1->name, $matches[1][0]); $this->assertEquals($page2->name, $matches[1][1]); // Check the ids in the links. $this->assertEquals($page1->cmid, $matches[2][0]); $this->assertEquals($page2->cmid, $matches[2][1]); // Check the link text. $this->assertEquals($page1->name, $matches[3][0]); $this->assertEquals($page2->name, $matches[3][1]); } public function test_links_activity_named_hyphen(): void { $this->resetAfterTest(true); // Create a test course. $course = $this->getDataGenerator()->create_course(); $context = \context_course::instance($course->id); // Work around an issue with the activity names filter which maintains a static cache // of activities for current course ID. We can re-build the cache by switching user. $this->setUser($this->getDataGenerator()->create_user()); // Create a page activity named '-' (single hyphen). $page = $this->getDataGenerator()->create_module('page', ['course' => $course->id, 'name' => '-']); $html = '

Please read the - page.

'; $filtered = format_text($html, FORMAT_HTML, ['context' => $context]); // Find the page link in the filtered html. preg_match_all( '~([^<]*)~', $filtered, $matches ); // We should have exactly one match. $this->assertCount(1, $matches[1]); $this->assertEquals($page->name, $matches[1][0]); $this->assertEquals($page->cmid, $matches[2][0]); $this->assertEquals($page->name, $matches[3][0]); } /** * Data provider for the test_links_with_whitespace. * * @return array */ public static function links_with_whitespace_provider(): array { return [ 'Regular spaces' => [ 'Assignment 1', '

Go to Assignment 1

', true, ], 'Two regular spaces' => [ 'Assignment 1', '

Go to Assignment 1

', true, ], 'NBSP + regular spaces' => [ 'Assignment 1', "

Go to Assignment\xC2\xA0 1

", true, ], 'Multiple spaces' => [ 'Assignment 1 - History', '

Go to Assignment 1 - History

', true, ], 'Mismatched spaces 1' => [ 'Assignment 1', '

Go to Assignment 1

', false, ], 'Mismatched spaces 2' => [ 'Assignment 1', '

Go to Assignment 1

', false, ], ]; } /** * Test that links can be matched with various whitespace combinations. * * @dataProvider links_with_whitespace_provider * @param string $activityname * @param string $html * @param bool $expectedresult */ public function test_links_with_whitespace(string $activityname, string $html, bool $expectedresult): void { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); $context = \context_course::instance($course->id); $this->getDataGenerator()->create_module( 'page', ['course' => $course->id, 'name' => $activityname] ); $filtered = format_text($html, FORMAT_HTML, ['context' => $context]); $haslink = strpos($filtered, 'assertEquals($expectedresult, $haslink); } public function test_cache(): void { $this->resetAfterTest(true); // Create a test courses. $course1 = $this->getDataGenerator()->create_course(); $course2 = $this->getDataGenerator()->create_course(); $context1 = \context_course::instance($course1->id); $context2 = \context_course::instance($course2->id); // Create page 1. $page1 = $this->getDataGenerator()->create_module( 'page', ['course' => $course1->id, 'name' => 'Test 1'] ); // Format text with page 1 in HTML. $html = '

Please read the two pages Test 1 and Test 2.

'; $filtered1 = format_text($html, FORMAT_HTML, ['context' => $context1]); // Find all the activity links in the result. $matches = []; preg_match_all( '~
([^<]*)~', $filtered1, $matches ); // There should be 1 link. $this->assertCount(1, $matches[1]); $this->assertEquals($page1->name, $matches[1][0]); // Create page 2. $page2 = $this->getDataGenerator()->create_module( 'page', ['course' => $course1->id, 'name' => 'Test 2'] ); // Filter the text again. $filtered2 = format_text($html, FORMAT_HTML, ['context' => $context1]); // The filter result does not change due to caching. $this->assertEquals($filtered1, $filtered2); // Change context, so that cache for course 1 is cleared. $filtered3 = format_text($html, FORMAT_HTML, ['context' => $context2]); $this->assertNotEquals($filtered1, $filtered3); $matches = []; preg_match_all( '~([^<]*)~', $filtered3, $matches ); // There should be no links. $this->assertCount(0, $matches[1]); // Filter the text for course 1. $filtered4 = format_text($html, FORMAT_HTML, ['context' => $context1]); // Find all the activity links in the result. $matches = []; preg_match_all( '~([^<]*)~', $filtered4, $matches ); // There should be 2 links. $this->assertCount(2, $matches[1]); $this->assertEquals($page1->name, $matches[1][0]); $this->assertEquals($page2->name, $matches[1][1]); } }PK\0Q~44db/install.phpnu[PK\'\rdb/renamedclasses.phpnu[PK\fvkk lang/en/filter_activitynames.phpnu[PK\qE3  version.phpnu[PK\c tfilter.phpnu[PK\_ įclasses/privacy/provider.phpnu[PK\NH4classes/text_filter.phpnu[PK\r#r#:tests/text_filter_test.phpnu[PK]