michael-milette / moodle-filter_filtercodes

FilterCodes filter for Moodle enables content creators to easily customize and personalize course and site content using plain text tags (no HTML). For premium support, contact us at https://www.tngconsulting.ca/contact
https://moodle.org/plugins/filter_filtercodes
GNU General Public License v3.0
32 stars 45 forks source link

Stripping out text #197

Closed jb-fol closed 2 years ago

jb-fol commented 2 years ago

This filter code in text:

This webinar was held on {coursestartdate strftimedaydate} and had {courseparticipantcount} participants.

results in:

This webinar was held on Monday 8 February 2021 participants.

As you can see, the "and had xxx" is missing from the rendered text after the date.

Using

This webinar was held on {coursestartdate} and had {courseparticipantcount} participants.

results in the correctly rendered text of:

This webinar was held on 8/02/21 and had 119 participants.

but I want the date in a different format 😅

Any thoughts?

Related to #191 ?

jb-fol commented 2 years ago

I thought this might be the same as #191 but there are no line breaks in my text in the editor or the rendered text.

Looking at HTML view in Atto Editor shows

<p>This webinar was held on {coursestartdate strftimedaydate} and had {courseparticipantcount} participants.</p>

Inspect element on rendered text shows:

<p id="yui_3_17_2_1_1642509117461_749">This webinar was held on Monday 8 February 2021 participants.</p>

michael-milette commented 2 years ago

Hi @jb-fol ,

Thank you for reporting this. This is an issue common to all date-related functions in FilterCodes. There is already a ticket open for this in #166. If you have time to figure it out, feel free to submit a pull request, share your thoughts in #166. I am also open to being hired to fix this issue.

I would remove the functionality for now but I know that there are some people who do use these functions successfully. Unfortunately, I have not had time to give this the attention it would require to resolve the issue.

What is really weird is that I am not doing anything different from any of the other tags. The regex function simply does not seem to like dates under some circumstances.

Since there is already an open ticket for this, #166 any text after course start date is trimmed, please join that discussion. I am closing this ticket. If you feel that this issue is different in some way, please let me know and I will reopen this ticket.

Best regards,

Michael

Best regards,

Michael

jb-fol commented 2 years ago

Thanks @michael-milette

I can't figure out what's causing the problem, but it's something to do with

// Hack to remove everything after the closing }, if it is still there.
// TODO: Improve regex above to support PHP strftime strings.
$matches[1] = strtok($matches[1], '}');

My solution was to simply change the date string to what I wanted, so rather than using

{coursestartdate strftimedaydate}

I altered the code (line 1247) to get_string('strftimedaydate'));

which means I can just use {coursestartdate} as the filter.

Thanks for your work on this plugin, as always 👏