diff --git a/CHANGELOG.md b/CHANGELOG.md index b98e14b..913fc75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. -## [2.1.7] 2021-05-19 BETA +## [2.2.0] 2021-05-22 ### Added - New {courseteachers} tag (ALPHA). - New %7Bcoursemoduleid%7D tag. -- New option for you to define your own global {global_...} tags. +- New define custom global {global_...} tags (up to 20). - New {courserequest} tag. - New {courserequestmenu} tag. - New {courserequestmenu0} tag. @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - New {supportname} tag. - New {supportemail} tag. - New {supportpage} tag. +- New {webpage} gets automatically substituted to {profile_field_webpage} as of Moodle 3.11. ### Updated - {coursesummary} can now include other FilterCodes. - {categorycards} titles now always display white. @@ -25,7 +26,9 @@ All notable changes to this project will be documented in this file. - {profile_field_...} of type Checkbox now displays Yes/No instead of a 1 or 0. - {profile_field_...} of other types will now display value if field contains 0. - {profile_field_...} tags will now be removed if user is not logged in. -- Updated documentation. +- {filtercodes} tag now works on all pages but only for users who have course:update capability. +- Custom menu tags should not be processed through the "URL to Link" (urltolink) filter. See README.md to update your theme. +- Documentation in this README.md file. - Copyright notice for 2021. ## [2.1.0] 2020-11-23 @@ -47,8 +50,10 @@ All notable changes to this project will be documented in this file. - New Moodle date/time format option for the {coursestartdate} tag. - New Moodle date/time format option for the {courseenddate} tag. - New Moodle date/time format option for the {coursecompletiondate} tag. -- New {now dateTimeFormat} tag. - New {ifminsitemanager} tag. +- New {now} tag. +- New option to format the date/time {now dateTimeFormat}. + ### Updated - {courseprogress} and {courseprogressbar} now show zero progress if progress is 0. - {alert} to allow for optional contextual class stying. diff --git a/README.md b/README.md index 09065ef..89d791c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ FilterCodes filter plugin for Moodle ==================================== ![PHP](https://img.shields.io/badge/PHP-v5.6%20%2F%20v7.0%20%2F%20v7.1%2F%20v7.2%2F%20v7.3%2F%20v7.4-blue.svg) -![Moodle](https://img.shields.io/badge/Moodle-v2.7%20to%20v3.10.x-orange.svg) +![Moodle](https://img.shields.io/badge/Moodle-v2.7%20to%20v3.11.x-orange.svg) [![GitHub Issues](https://img.shields.io/github/issues/michael-milette/moodle-filter_filtercodes.svg)](https://github.com/michael-milette/moodle-filter_filtercodes/issues) [![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)](#contributing) [![License](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](#license) @@ -248,8 +248,8 @@ Note: {if*rolename*} and {ifmin*rolename*} type tags are based on role archetype #### Courses -* {ifenrolled}{/ifenrolled} : Will display the enclosed content only if the user **is** enrolled in the current course. -* {ifnotenrolled}{/ifnotenrolled} : Will display the enclosed content only if the user is **not** enrolled in the current course. +* {ifenrolled}{/ifenrolled} : Will display the enclosed content only if the user **is** enrolled as **a student** in the current course. This tag does not take any other roles into consideration. +* {ifnotenrolled}{/ifnotenrolled} : Will display the enclosed content only if the user is **not** enrolled as **a student** in the current course. This tag does not take any other roles into consideration. * {ifincourse}{/ifincourse} : Will display the enclosed content only if the user is in a course other than the Front page. * {ifinsection}{/ifinsection} : Will display the enclosed content only if the user is in a section of a course which is not the Front Page. * {ifnotinsection}{/ifnotinsection} : Will display the enclosed content only if the user is not in a section of a course. @@ -458,6 +458,8 @@ There are two ways to make FilterCodes work in Moodle's custom menu: ### For themes based on **boost** +Note: Supported in Moodle 3.2 and later. + Add the following code to core_renderer section of your theme. Note: Your theme may even already have such a class (they often do): use filter_manager; @@ -474,8 +476,8 @@ Add the following code to core_renderer section of your theme. Note: Your theme // Don't apply auto-linking filters. $filtermanager = filter_manager::instance(); - $filteroptions = array('originalformat' => FORMAT_HTML, 'noclean' => true); - $skipfilters = array('activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink'); + $filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true]; + $skipfilters = ['activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink']; // Filter custom user menu. // Don't filter custom user menu on the settings page. Otherwise it ends up @@ -506,8 +508,8 @@ Add the following code to core_renderer section of your theme. Note: Your theme // Don't apply auto-linking filters. $filtermanager = filter_manager::instance(); - $filteroptions = array('originalformat' => FORMAT_HTML, 'noclean' => true); - $skipfilters = array('activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink'); + $filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true]; + $skipfilters = ['activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink']; if (empty($custommenuitems) && !empty($CFG->custommenuitems)) { $custommenuitems = $CFG->custommenuitems; @@ -529,7 +531,7 @@ Add the following code to core_renderer section of your theme. Note: Your theme } $this->language = $custommenu->add($currentlang, new moodle_url('#'), $strlang, 10000); foreach ($langs as $langtype => $langname) { - $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname); + $this->language->add($langname, new moodle_url($this->page->url, ['lang' => $langtype]), $langname); } } @@ -539,6 +541,8 @@ Add the following code to core_renderer section of your theme. Note: Your theme ### For themes based on the older **bootstrapbase** +Note: Supported in Moodle 2.7 to 3.6. + Add the following code to core_renderer section of your theme for Moodle 2.7 to 3.6. Be sure to replace "themename" with the name of the theme's directory. Note: Your theme may even already have such a class (they often do): class theme_themename_core_renderer extends theme_bootstrapbase_core_renderer { @@ -556,8 +560,8 @@ Add the following code to core_renderer section of your theme for Moodle 2.7 to // Don't apply auto-linking filters. $filtermanager = filter_manager::instance(); - $filteroptions = array('originalformat' => FORMAT_HTML, 'noclean' => true); - $skipfilters = array('activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink'); + $filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true]; + $skipfilters = ['activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters', 'urltolink']; // Filter custom user menu. // Don't filter custom user menu on the theme settings page. Otherwise it ends up @@ -588,6 +592,8 @@ To patch Moodle to handle this properly for most Moodle themes, apply the follow * Moodle 3.8: https://github.com/michael-milette/moodle/tree/MDL-63219-M38 * Moodle 3.9: https://github.com/michael-milette/moodle/tree/MDL-63219-M39 * Moodle 3.10: https://github.com/michael-milette/moodle/tree/MDL-63219-M310 +* Moodle 3.11: https://github.com/michael-milette/moodle/tree/MDL-63219-M311 +* Moodle master: https://github.com/michael-milette/moodle/tree/MDL-63219-master ## Scrape'ing content @@ -661,6 +667,24 @@ Choose the type of link for the teacher\s link in the {courseteachers} tags. Cho Define your own global tags, sometimes also called global blocks. This feature enables you to create your own tags that are prefixed by global_ . You can currently define up to 20 custom {global_...} tags. +### Customizing or translating the forms generated by the {form...} tags + +You can translate or customize the form tags in Moodle's language editor. Here is how to do it: + +1. Navigate to Site Administration > Language > Language Customization. +2. Select the language you want to customize. +3. Click the **Open Language Pack for Editing** button. +4. Wait until the **Continue** button apppears. This may take a little time. Please be patient. +5. In the **Show Strings of These Components** field, scroll down and select **filter_filtercodes.php**. +6. Click the **Show Strings** button. +7. Scroll down to the strings called formcheckin, formcontactus, formcourserequest, formquickquestion and formsupport. This is the HTML for the tags of the same name. +8. Edit the form as needed. +9. Scroll to the bottom of the page and click the **Save changes to the language pack** button. + +For more information on editing language strings in Moodle, visit: https://docs.moodle.org/en/Language_customisation. + +Alternatively, you could simply insert the HTML for the form in the Atto editor. These {form...} tags are just provided to quickly create generic forms on your Moodle site. + [(Back to top)](#table-of-contents) # Updating @@ -801,7 +825,7 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo * ID Number [{idnumber}]: {idnumber} * User name [{username}]: {username} * User description [{userdescription}] : {userdescription} -* Website URL [{website}] : {website} +* User web page URL [{webpage}] : {webpage} * Scrape h1 from example.com: {scrape url="https://example.com/" tag="h1"} * User profile picture URL (small) [{userpictureurl sm}]: {userpictureurl sm} * User profile picture URL (medium) [{userpictureurl md}]: {userpictureurl md} @@ -832,7 +856,6 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo * Course Context ID (encoded) [%7Bcoursecontextid%7D]: %7Bcoursecontextid%7D * Course Module ID (encoded) [%7Bcoursemoduleid%7D]: %7Bcoursemoduleid%7D (Note: Only available in a course activity) * Course ID number [{courseidnumber}]: {courseidnumber} -* Course custom fields [{coursefields}]: {coursefields} * Section ID [{sectionid}]: {sectionid} * Section ID (encoded) [%7Bsectionid%7D]: %7Bsectionid%7D * Teachers in this course [{courseteachers}]: {courseteachers} @@ -840,10 +863,10 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo * Available free moodledata disk space [{diskfreespacedata}]: {diskfreespacedata} * My Enrolled Courses [{mycourses}]: {mycourses} * My Enrolled Courses menu [{mycoursesmenu}]: {mycoursesmenu} -* My Enrolled Courses [{courserequest}]: {myccourserequestourses} +* Link to the request a course page (blank if not enabled) [{courserequest}]: {courserequest} * Request a course / Course request in top level menu [{courserequestmenu0}]: {courserequestmenu0} * Request a course / Course request in submenu [{courserequestmenu}]: {courserequestmenu} -* Dev sub-menu items [{menudev}]: {menudev} +* Moodle Dev custom menu items [{menudev}]: {menudev} * Course category ID (0 if not in a course or category list of course) [{categoryid}]: {categoryid} * Course category name (blank if not in a course) [{categoryname}]: {categoryname} * Course category number (blank if not in a course) [{categorynumber}]: {categorynumber} @@ -876,11 +899,11 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo * Referrer [{referrer}]: {referrer} * ReCAPTCHA [{recaptcha}]: {recaptcha} * Readonly (for form fields when logged-in) [{readonly}]: {readonly} -* Soft hyphen [{-}]: AHyphenWilloOlyAppearHere{-}WhenThereIsNoMoreSpace. +* Soft hyphen [{-}]: AHyphenWillOnlyAppearHere{-}WhenThereIsNotEnoughSpace. * Non-breaking space [{nbsp}]: This{nbsp}: Is it! (view source code to see the non-breaking space) * English [{langx en}]Content[{/langx}]: {langx en}Content{/langx} * String with component [{getstring:filter_filtercodes}]filtername[{/getstring}]: {getstring:filter_filtercodes}filtername{/getstring} -* String [{getstring}]Help[{/getstring}]: {getstring}Help{/getstring} +* String [{getstring}]Help[{/getstring}]: {getstring}help{/getstring} * Toggle editing menu [{toggleeditingmenu}]: {toggleeditingmenu} * Editing Toggle [{editingtoggle}]: Toggle editing * FontAwesome "fa-globe": v4.x [{fa fa-globe}] {fa fa-globe}, v5.x [{fas fa-globe}] {fas fa-globe}. Must be supported by your theme. @@ -889,16 +912,16 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo * You should not see the following note [{note}]This could be a comment, todo or reminder.[{/note}]: {note}This could be a comment, todo or reminder.{/note} * Click for [{help}content{/help}] : {help}Enables you to create popup help icons and bubbles just like Moodle does.{/help} * Click for [{info}content{/info}] : {Info}Enables you to create popup info icons and bubbles just like the Help popup but with an info icon. Useful for adding extra information or hidden tips in your content.{/info} -* {alert}This is an example of an alert box.{/info} +* {alert}This is an example of an alert box.{/alert} * [{highlight}]This text is highlighted in yellow.[{/highlight}] : {highlight}This text is highlighted in yellow.{/highlight} * Current language [{lang}] : {lang} -* Display content of custom profile field [{profile_field_shortname}]: Location: {profile_field_location} - assuming you had created a custom profile field with a shortname called 'location'. +* Display content of custom profile field [{profile_field_learningstyle}] - assuming you have a custom profile field with a shortname called 'learningstyle': {profile_field_learningstyle} * Display profile owner's full name on profile pages [{profilefullname}]: This is the profile of {profilefullname}. * If you are logged-in as a different user [{ifloggedinas}] : {ifloggedinas}You are logged-in as a different user.{/ifloggedinas} * If you are NOT logged-in as a different user [{ifloggedinas}] : {ifnotloggedinas}You are logged-in as yourself.{/ifnotloggedinas} * If Editing mode activated (on) [{ifeditmode}]Don't forget to turn off editing mode![{/ifeditmode}]: {ifeditmode}Don't forget to turn off editing mode!{/ifeditmode} * If defined custom profile field with a shortname called "iswoman" is not blank or zero [{ifprofile_field_iswoman}Female{/ifprofile_field_iswoman}]: {ifprofile_field_iswoman}Female{/ifprofile_field_iswoman} -* If Editing mode is deactivated (off) [{ifnoteditmode}]<a href="{wwwroot}/course/view.php?id={courseid}&sesskey={sesskey}&edit=on">Turn edit mode on<a/>[{/ifnoteditmode}]: {ifnoteditmode}Turn edit mode on{/ifnoteditmode}; +* If Editing mode is deactivated (off) [{ifnoteditmode}]<a href="{wwwroot}/course/view.php?id={courseid}&sesskey={sesskey}&edit=on">Turn edit mode on<a/>[{/ifnoteditmode}]: {ifnoteditmode}Turn edit mode on{/ifnoteditmode} * If Enrolled [{ifenrolled}]You are enrolled in this course.[{/ifenrolled}]: {ifenrolled}You are enrolled in this course.{/ifenrolled} * If Not Enrolled [{ifnotenrolled}]You are not enrolled in this course.[{/ifnotenrolled}]: {ifnotenrolled}You are not enrolled in this course.{/ifnotenrolled} * If LoggedIn [{ifloggedin}]You are logged-in.[{/ifloggedin}]: {ifloggedin}You are logged-in.{/ifloggedin} @@ -1007,7 +1030,7 @@ Verify that the component (plugin) name and/or the string key are correct. If a ### How can I customize or translate the forms generated by the {form...} tags? -You can translate or customize the forms in Moodle's language editor. Note that using these tags are optional. You can also simply insert the HTML for the form in the Atto editor. These {form...} tags are just provided to quickly create generic forms on your Moodle site. +See **Customizing or translating the forms generated by the {form...} tags** in the [Usage](#usage) section. ### What are the Supported dateTimeFormat formats? @@ -1059,18 +1082,18 @@ Michael Milette - Author and Lead Developer Big thank you to the following contributors. (Please let me know if I forgot to include you in the list): +* 3iPunt and abertranb: New {ifcustomrole} tag (2020). +* 3iPunt and abertranb: New {ifnotcustomrole} tag (2020). +* andrewhancox: Enhanced {coursecards} tag (2020). * comete-upn: New {getstring} tag (2018). * ewallah: Testing of phpunit testing script (2019). -* vpn: Enhanced {alert} tag (2020). -* rschrenk: Enhanced [{tag}] commenting options (2020). -* andrewhancox: Enhanced {coursecards} tag (2020). -* petermApredne: New {firstaccessdate} tag (2020). -* petermApredne: New {coursestartdate} tag (2020). -* petermApredne: New {courseenddate} tag (2020). -* petermApredne: New {coursecompletiondate} tag (2020). * pablojavier: New {iftenant} tag (2020). -* 3iPunt and abertranb: New {ifcustomrole} tag (2020). -* 3iPunt and abertranb: New {ifnotcustomrole} tag (2020). +* petermApredne: New {coursecompletiondate} tag (2020). +* petermApredne: New {courseenddate} tag (2020). +* petermApredne: New {coursestartdate} tag (2020). +* petermApredne: New {firstaccessdate} tag (2020). +* rschrenk: Enhanced [{tag}] commenting options (2020). +* vpn: Enhanced {alert} tag (2020). Thank you also to all the people who have requested features, tested and reported bugs. @@ -1079,7 +1102,7 @@ Thank you also to all the people who have requested features, tested and reporte Some of the features we are considering for future releases include: * Catch-up on developing unit testing. -* Add ability to access course meta information. Example, teacher's name. +* Add ability to access course meta information. * Add ability to list courses in the current course's category. * Add ability to list subcategories of the current category. * Add settings page with option to disable unused or unwanted filters in order to optimize performance or simply disable features. diff --git a/filter.php b/filter.php index bc12a9f..ca59573 100644 --- a/filter.php +++ b/filter.php @@ -441,9 +441,9 @@ public function filter($text, array $options = []) { } $menu .= '-{getstring}phpinfo{/getstring}|/admin/phpinfo.php' . PHP_EOL; $menu .= '-###' . PHP_EOL; - $menu .= '-Layoutit|https://www.layoutit.com/build" target="popup" onclick="window.open(\'https://www.layoutit.com/build\',\'popup\',\'width=1340,height=700\'); return false;|Bootstrap Page Builder ({getstring}english{/getstring})' . PHP_EOL; - $menu .= '-Pixlr|https://pixlr.com/editor/" target="popup" onclick="window.open(\'https://pixlr.com/editor/\',\'popup\',\'width=1340,height=700\'); return false;|Photo Editor ({getstring}english{/getstring})' . PHP_EOL; - $menu .= '-ScreenApp|https://screenapp.io/#/recording" target="popup" onclick="window.open(\'https://screenapp.io/#/recording\',\'popup\',\'width=1340,height=700\'); return false;|Screen Recorder ({getstring}english{/getstring})' . PHP_EOL; + $menu .= '-{getstring:filtercodes}pagebuilder{/getstring}|{getstring:filtercodes}pagebuilderlink{/getstring}" target="popup" onclick="window.open(\'{getstring:filtercodes}pagebuilderlink{/getstring}\',\'popup\',\'width=1340,height=700\'); return false;' . PHP_EOL; + $menu .= '-{getstring:filtercodes}photoeditor{/getstring}|{getstring:filtercodes}photoeditorlink{/getstring}" target="popup" onclick="window.open(\'{getstring:filtercodes}photoeditorlink{/getstring}\',\'popup\',\'width=1340,height=700\'); return false;' . PHP_EOL; + $menu .= '-{getstring:filtercodes}screenrecorder{/getstring}|{getstring:filtercodes}screenrecorderlink{/getstring}" target="popup" onclick="window.open(\'{getstring:filtercodes}screenrecorderlink{/getstring}\',\'popup\',\'width=1340,height=700\'); return false;' . PHP_EOL; $menu .= '-###' . PHP_EOL; $menu .= '-MoodleDev docs|https://moodle.org/development|Moodle.org ({getstring}english{/getstring})' . PHP_EOL; $menu .= '-MoodleDev forum|https://moodle.org/mod/forum/view.php?id=55|Moodle.org ({getstring}english{/getstring})' . PHP_EOL; @@ -669,24 +669,6 @@ function ($matches) use ($USER) { } } - // Tags starting with: {support...}. - if (stripos($text, '{support') !== false) { - // Tag: {supportname}. - if (stripos($text, '{supportname}') !== false) { - $replace['/\{supportname\}/i'] = $CFG->supportname; - } - - // Tag: {supportemail}. - if (stripos($text, '{supportemail}') !== false) { - $replace['/\{supportemail\}/i'] = $CFG->supportemail; - } - - // Tag: {supportpage}. - if (stripos($text, '{supportpage}') !== false) { - $replace['/\{supportpage\}/i'] = $CFG->supportpage; - } - } - if (get_config('filter_filtercodes', 'enable_scrape')) { // Must be enabled in FilterCodes settings. // Tag: {scrape url="" tag="" class="" id="" code=""}. if (stripos($text, '{scrape ') !== false) { @@ -1830,7 +1812,7 @@ function ($matches) { // If the tag exists and is not set to "Not visible" in the custom profile field's settings. if (isset($profiledata[$field->id]) && $isuser && - ($field->visible == '0' || !get_config('filter_filtercodes', 'ifprofilefiedonlyvisible'))) { + ($field->visible == '0' || get_config('filter_filtercodes', 'ifprofilefiedonlyvisible'))) { $data = trim($profiledata[$field->id]); } else { $data = ''; @@ -1838,7 +1820,7 @@ function ($matches) { // If the value is empty or zero, remove the all of the tags and their contents for that field shortname. if (empty($data)) { - $replace['/\{' . $tag . '(.*?)\}(.*?)\{\/' . $tag . '\}/ims'] = ''; + $replace['/\{ ' . $tag . '(.*?)\}(.*?)\{\/' . $tag . '\}/ims'] = ''; continue; } diff --git a/lang/en/filter_filtercodes.php b/lang/en/filter_filtercodes.php index 48b55b4..5504b2b 100644 --- a/lang/en/filter_filtercodes.php +++ b/lang/en/filter_filtercodes.php @@ -47,8 +47,8 @@ $string['courseteachershowpic_desc'] = 'If enabled, will display the teacher\'s profile picture in {courseteachers} tags.'; $string['courseteacherlinktype'] = 'Teacher link type'; $string['courseteacherlinktype_desc'] = 'Choose the type of link for the teacher\s link in the {courseteachers} tags.'; -$string['ifprofilefiedonlyvisible'] = '{ifprofilefied} only visible.'; -$string['ifprofilefiedonlyvisible_desc'] = 'Restrict the {ifprofilefied} tag to only access visible fields. Hidden fields will behave as if the field was empty. If unchecked, this tag will be able to check hidden user fields.'; +$string['ifprofilefiedonlyvisible'] = '{ifprofile_field_} only visible.'; +$string['ifprofilefiedonlyvisible_desc'] = 'Restrict the {ifprofile_field_...} tag to only access visible profile fields. Hidden fields will behave as if the field was empty. If unchecked, this tag will be able to check hidden user fields.'; $string['sizeb'] = 'B'; $string['sizekb'] = 'KB'; @@ -67,6 +67,13 @@ $string['globaltagnamedesc'] = 'This will be part of your tag name, prefixed with "global_". Example: If you enter "address" here, your tag will be called {global_address}". Must be a single string of letters only, no spaces, numbers or special characters are permitted.'; $string['globaltagcontenttitle'] = 'Content'; $string['globaltagcontentdesc'] = 'This is the content that your global tag will replace. Example: If your tag is called "{global_address}", that tag will be replaced by the content entered into this field.'; +$string['pagebuilder'] = 'Page builder'; +$string['pagebuilderlink'] = 'https://www.layoutit.com/build'; +$string['photoeditor'] = 'Photo editor'; +$string['photoeditorname'] = 'Pixlr'; +$string['photoeditorlink'] = 'https://pixlr.com/editor/'; +$string['screenrecorder'] = 'Screen recorder'; +$string['screenrecorderlink'] = 'https://screenapp.io/#/recording'; $string['formquickquestion'] = '
diff --git a/lib.php b/lib.php index c43dd4c..e0cd4ef 100644 --- a/lib.php +++ b/lib.php @@ -40,8 +40,8 @@ function filter_filtercodes_render_navbar_output() { // Don't apply auto-linking filters. $filtermanager = filter_manager::instance(); - $filteroptions = array('originalformat' => FORMAT_HTML, 'noclean' => true); - $skipfilters = array('activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters'); + $filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true]; + $skipfilters = ['activitynames', 'data', 'glossary', 'sectionnames', 'bookchapters']; // Filter Custom Menu. $CFG->custommenuitems = $filtermanager->filter_text($CFG->custommenuitems, diff --git a/settings/general.php b/settings/general.php index 61cce8e..301e298 100644 --- a/settings/general.php +++ b/settings/general.php @@ -87,6 +87,9 @@ $name = 'filter_filtercodes/courseteacherlinktype'; $title = get_string('courseteacherlinktype', 'filter_filtercodes'); $description = get_string('courseteacherlinktype_desc', 'filter_filtercodes'); -$choices = ['' => get_string('none'), 'email' => get_string('issueremail', 'badges'), 'message' => get_string('message', 'message'), 'profile' => get_string('profile')]; +$choices = ['' => get_string('none'), + 'email' => get_string('issueremail', 'badges'), + 'message' => get_string('message', 'message'), + 'profile' => get_string('profile')]; $setting = new admin_setting_configselect($name, $title, $description, $default, $choices); $settings->add($setting); diff --git a/settings/global.php b/settings/global.php index 8fbc8ea..38304cf 100644 --- a/settings/global.php +++ b/settings/global.php @@ -1,84 +1,83 @@ -. - -/** - * Settings for global custom tags for FilterCodes. - * - * @package filter_filtercodes - * @copyright 2017-2021 TNG Consulting Inc. - www.tngconsulting.ca - * @author Michael Milette - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -// FilterCodes plugin. -$name = 'filter_filtercodes'; - -// Page Table of contents -$title = get_string('globaltagheadingtitle', $name); -$description = get_string('globaltagheadingdesc', $name); -$setting = new admin_setting_heading($name . '/globaltagheadingtitle', $title, $description); -$settings->add($setting); - - -// Number of tags. -$title = get_string('globaltagcount', $name); -$description = get_string('globaltagcountdesc', $name); -$default = 0; -$choices = []; -for ($i = 0; $i <= 20; $i++) { - $choices[$i] = $i; -} -$settings->add(new admin_setting_configselect($name . '/globaltagcount', $title, $description, $default, $choices)); - -// This is the descriptors for each FilterCodes tag. -$tagtitle = get_string('globaltagnametitle', $name); -$tagdescription = get_string('globaltagnamedesc', $name); -$contenttitle = get_string('globaltagcontenttitle', $name); -$contentdescription = get_string('globaltagcontentdesc', $name); -$format = get_string('htmlformat'); -$default = ''; - -$globaltagcount = get_config($name, 'globaltagcount'); -for ($i = 1; $i <= $globaltagcount; $i++) { - // Tag name. - $setting = new admin_setting_configtext($name . '/globalname' . $i, - $tagtitle . get_config($name, 'globalname' . $i), - $tagdescription, $default, PARAM_ALPHA); - $settings->add($setting); - - // Tag content editor. - if (($editor = get_config($name, 'globaleditor' . $i)) == '') { - // First time. Initialize to Yes. - set_config('globaleditor' . $i, $editor = 1, $name); - } - - if (empty($editor)) { - // Plain text area. - $setting = new admin_setting_configtextarea($name . '/globalcontent' . $i, $contenttitle, - $contentdescription, $default, PARAM_RAW); - } else { - // Rich text area. - $setting = new admin_setting_confightmleditor($name . '/globalcontent' . $i, $contenttitle, - $contentdescription, $default, PARAM_RAW); - } - $settings->add($setting); - - // Content editor type. - $setting = new admin_setting_configcheckbox($name . '/globaleditor' . $i, $format, '', 1); - $settings->add($setting); -} +. + +/** + * Settings for global custom tags for FilterCodes. + * + * @package filter_filtercodes + * @copyright 2017-2021 TNG Consulting Inc. - www.tngconsulting.ca + * @author Michael Milette + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// FilterCodes plugin. +$name = 'filter_filtercodes'; + +// Page Table of contents. +$title = get_string('globaltagheadingtitle', $name); +$description = get_string('globaltagheadingdesc', $name); +$setting = new admin_setting_heading($name . '/globaltagheadingtitle', $title, $description); +$settings->add($setting); + +// Number of tags. +$title = get_string('globaltagcount', $name); +$description = get_string('globaltagcountdesc', $name); +$default = 0; +$choices = []; +for ($i = 0; $i <= 20; $i++) { + $choices[$i] = $i; +} +$settings->add(new admin_setting_configselect($name . '/globaltagcount', $title, $description, $default, $choices)); + +// This is the descriptors for each FilterCodes tag. +$tagtitle = get_string('globaltagnametitle', $name); +$tagdescription = get_string('globaltagnamedesc', $name); +$contenttitle = get_string('globaltagcontenttitle', $name); +$contentdescription = get_string('globaltagcontentdesc', $name); +$format = get_string('htmlformat'); +$default = ''; + +$globaltagcount = get_config($name, 'globaltagcount'); +for ($i = 1; $i <= $globaltagcount; $i++) { + // Tag name. + $setting = new admin_setting_configtext($name . '/globalname' . $i, + $tagtitle . get_config($name, 'globalname' . $i), + $tagdescription, $default, PARAM_ALPHA); + $settings->add($setting); + + // Tag content editor. + if (($editor = get_config($name, 'globaleditor' . $i)) == '') { + // First time. Initialize to Yes. + set_config('globaleditor' . $i, $editor = 1, $name); + } + + if (empty($editor)) { + // Plain text area. + $setting = new admin_setting_configtextarea($name . '/globalcontent' . $i, $contenttitle, + $contentdescription, $default, PARAM_RAW); + } else { + // Rich text area. + $setting = new admin_setting_confightmleditor($name . '/globalcontent' . $i, $contenttitle, + $contentdescription, $default, PARAM_RAW); + } + $settings->add($setting); + + // Content editor type. + $setting = new admin_setting_configcheckbox($name . '/globaleditor' . $i, $format, '', 1); + $settings->add($setting); +} diff --git a/tests/filter_test.php b/tests/filter_test.php index 1567745..5184340 100644 --- a/tests/filter_test.php +++ b/tests/filter_test.php @@ -52,7 +52,7 @@ class filter_filtercodes_testcase extends advanced_testcase { protected function setUp() { parent::setUp(); $this->resetAfterTest(true); - $this->filter = new filter_filtercodes(context_system::instance(), array()); + $this->filter = new filter_filtercodes(context_system::instance(), []); } /** @@ -70,224 +70,224 @@ public function test_filter_filtercodes() { $context = context_course::instance($course->id); filter_set_local_state('filtercodes', $context->id, TEXTFILTER_ON); - $tests = array( - array ( + $tests = [ + [ 'before' => 'No langx tags', 'after' => 'No langx tags', - ), - array ( + ], + [ 'before' => '{langx es}Todo el texto está en español{/langx}', 'after' => 'Todo el texto está en español', - ), - array ( + ], + [ 'before' => '{langx fr}Ceci est du texte en français{/langx}', 'after' => 'Ceci est du texte en français', - ), - array ( + ], + [ 'before' => 'Some non-filtered content plus some content in Spanish' . ' ({langx es}mejor dicho, en español{/langx})', 'after' => 'Some non-filtered content plus some content in Spanish' . ' (mejor dicho, en español)', - ), - array ( + ], + [ 'before' => 'Some non-filtered content plus some content in French ({langx fr}mieux en français{/langx})', 'after' => 'Some non-filtered content plus some content in French (mieux en français)', - ), - array ( + ], + [ 'before' => '{langx es}Algo de español{/langx}{langx fr}Quelque chose en français{/langx}', 'after' => 'Algo de españolQuelque chose en français', - ), - array ( + ], + [ 'before' => 'Non-filtered {begin}{langx es}Algo de español{/langx}{langx fr}Quelque chose en français{/langx}'. ' Non-filtered{end}', 'after' => 'Non-filtered {begin}Algo de españolQuelque chose en français'. ' Non-filtered{end}', - ), - array ( + ], + [ 'before' => '{langx}Bad filter syntax{langx}', 'after' => '{langx}Bad filter syntax{langx}', - ), - array ( + ], + [ 'before' => '{langx}Bad filter syntax{langx}{langx es}Algo de español{/langx}', 'after' => '{langx}Bad filter syntax{langx}Algo de español', - ), - array ( + ], + [ 'before' => 'Before {langx}Bad filter syntax{langx} {langx es}Algo de español{/langx} After', 'after' => 'Before {langx}Bad filter syntax{langx} Algo de español After', - ), - array ( + ], + [ 'before' => 'Before {langx non-existent-language}Some content{/langx} After', 'after' => 'Before Some content After', - ), - array ( + ], + [ 'before' => 'Before {langx en_ca}Some content{/langx} After', 'after' => 'Before Some content After', - ), - array ( + ], + [ 'before' => 'Before {langx en-ca}Some content{/langx} After', 'after' => 'Before Some content After', - ), - array ( + ], + [ 'before' => 'Before{nbsp}: Some content After', 'after' => 'Before : Some content After', - ), - array ( + ], + [ 'before' => 'Before{-}: Some content After', 'after' => 'Before­: Some content After', - ), - array ( + ], + [ 'before' => '{firstname}', 'after' => $USER->firstname, - ), - array ( + ], + [ 'before' => '{lastname}', 'after' => $USER->lastname, - ), - array ( + ], + [ 'before' => '{alternatename}', 'after' => !empty(trim($USER->alternatename)) ? $USER->alternatename : $USER->firstname, - ), - array ( + ], + [ 'before' => '{fullname}', 'after' => $USER->firstname . ' ' . $USER->lastname, - ), - array ( + ], + [ 'before' => '{getstring}help{/getstring}', 'after' => 'Help', - ), - array ( + ], + [ 'before' => '{getstring:filter_filtercodes}pluginname{/getstring}', 'after' => 'Filter Codes', - ), - array ( + ], + [ 'before' => '{city}', 'after' => $USER->city, - ), - array ( + ], + [ 'before' => '{country}', 'after' => !empty($USER->country) ? get_string($USER->country, 'countries') : '', - ), - array ( + ], + [ 'before' => '{email}', 'after' => $USER->email, - ), - array ( + ], + [ 'before' => '{userid}', 'after' => $USER->id, - ), - array ( + ], + [ 'before' => '%7Buserid%7D', 'after' => $USER->id, - ), - array ( + ], + [ 'before' => '{idnumber}', 'after' => $USER->idnumber, - ), - array ( + ], + [ 'before' => '{institution}', 'after' => $USER->institution, - ), - array ( + ], + [ 'before' => '{department}', 'after' => $USER->department, - ), - array ( + ], + [ 'before' => '{usercount}', - 'after' => $DB->count_records('user', array('deleted' => 0)) - 2, - ), - array ( + 'after' => $DB->count_records('user', ['deleted' => 0]) - 2, + ], + [ 'before' => '{usersactive}', - 'after' => $DB->count_records('user', array('deleted' => 0, 'suspended' => 0, 'confirmed' => 1)) - 2, - ), - array ( + 'after' => $DB->count_records('user', ['deleted' => 0, 'suspended' => 0, 'confirmed' => 1]) - 2, + ], + [ 'before' => '{courseid}', 'after' => $PAGE->course->id, - ), - array ( + ], + [ 'before' => '{courseidnumber}', 'after' => $PAGE->course->idnumber, - ), - array ( + ], + [ 'before' => '%7Bcourseid%7D', 'after' => $PAGE->course->id, - ), - array ( + ], + [ 'before' => '{coursename}', 'after' => $PAGE->course->fullname, - ), - array ( + ], + [ 'before' => '{courseshortname}', 'after' => $PAGE->course->shortname, - ), - array ( + ], + [ 'before' => '{coursecount}', - 'after' => $DB->count_records('course', array()) - 1, - ), - array ( + 'after' => $DB->count_records('course', []) - 1, + ], + [ 'before' => '{coursesactive}', - 'after' => $DB->count_records('course', array('visible' => 1)) - 1, - ), - array ( + 'after' => $DB->count_records('course', ['visible' => 1]) - 1, + ], + [ 'before' => '{coursesummary}', 'after' => $PAGE->course->summary, - ), - array ( + ], + [ 'before' => '{siteyear}', 'after' => date('Y'), - ), - array ( + ], + [ 'before' => '{editingtoggle}', 'after' => ($PAGE->user_is_editing() ? 'off' : 'on'), - ), - array ( + ], + [ 'before' => '{wwwroot}', 'after' => $CFG->wwwroot, - ), - array ( + ], + [ 'before' => '{wwwcontactform}', 'after' => $CFG->wwwroot . '/local/contact/index.php', - ), - array ( + ], + [ 'before' => '{protocol}', 'after' => 'http' . (is_https() ? 's' : ''), - ), - array ( + ], + [ 'before' => '{pagepath}', 'after' => '/?', - ), - array ( + ], + [ 'before' => '{ipaddress}', 'after' => getremoteaddr(), - ), - array ( + ], + [ 'before' => '{sesskey}', 'after' => sesskey(), - ), - array ( + ], + [ 'before' => '%7Bsesskey%7D', 'after' => sesskey(), - ), - array ( + ], + [ 'before' => '{sectionid}', 'after' => @$PAGE->cm->sectionnum, - ), - array ( + ], + [ 'before' => '%7Bsectionid%7D', 'after' => @$PAGE->cm->sectionnum, - ), - array ( + ], + [ 'before' => '{readonly}', 'after' => 'readonly="readonly"', - ), - array ( + ], + [ 'before' => '{fa fa-icon-name}', 'after' => '', - ), - array ( + ], + [ 'before' => '{glyphicon glyphicon-name}', 'after' => '', - ), - ); + ], + ]; foreach ($tests as $test) { $this->assertEquals($test['after'], $this->filter->filter($test['before'])); diff --git a/version.php b/version.php index 7602321..9599820 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020112307; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2021052200; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014051200; // Requires Moodle version 2.7 or later. $plugin->component = 'filter_filtercodes'; // Full name of the plugin (used for diagnostics). -$plugin->release = '2.1.7'; +$plugin->release = '2.2.0'; $plugin->maturity = MATURITY_STABLE;