Moodle

enable rich html formatting in forum's intro textbox

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 2.0
  • Component/s: Forum
  • Labels:
    None
  • Environment:
    moodle 1.9.2 , mysql 5, php 5, apache 2
  • Database:
    MySQL
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

teachers complaint to me that the HTML layouts (rich formatting) they apply to the intro box of forums does not
show up after they apply it and show it to the students.
especially problematic when some of the text is justified to the right (Hebrew rtl) and some instructions are
(supposed to be) justified to the left (English ltr)

so i found out that the intro field is filtered by the format_text() function.
i removed it since i see no point (security wise) to have this specific piece of content filtered since the teachers
are responsible for the content and most of the time they try to embed multimedia and rich HTML code for the
benefit of the students.

so i change mod/forum/view.php (line 260) from
print_box(format_text($forum->intro), 'generalbox', 'intro');
to...
print_box($forum->intro, 'generalbox', 'intro');

i hope it is ok

  1. patch.txt
    08/Apr/09 5:58 AM
    2 kB
    Awantha Oshadi Weerapperuma

Issue Links

Activity

Hide
Awantha Oshadi Weerapperuma added a comment -

I think format_text() function is a pretty important one as it converts the input text to
html format while including proper line breaks and paragraph tags appropriately. What I suggest
is to remove the clean up of tags since the teachers are responsible for the proper content.

So I suggest to include
$options->noclean = true;

just before the
print_box(format_text($forum->intro), 'generalbox', 'intro');
function.

Thanks!
Oshadi

Show
Awantha Oshadi Weerapperuma added a comment - I think format_text() function is a pretty important one as it converts the input text to html format while including proper line breaks and paragraph tags appropriately. What I suggest is to remove the clean up of tags since the teachers are responsible for the proper content. So I suggest to include $options->noclean = true; just before the print_box(format_text($forum->intro), 'generalbox', 'intro'); function. Thanks! Oshadi
Hide
Awantha Oshadi Weerapperuma added a comment -

Hi,
This is the patch file that I'm suggestion for this issue.
After going through the code, I've found that intro box content is finally surrounded by <p> tags. <p>is a block-level element that should contain a paragraph, comprised of text, inline elements that modify the text (<p>, <a>, <abbr>, etc.), and images. And it is not a container for all other elements.Therefor I've remove the addition of surrounding <p> tags. And Since the teachers are responsible for the content, I've remove the clean up of tags.

So, I've modified the code...

print_box(format_text($forum->intro), 'generalbox', 'intro');

to..
$options = new stdClass();
$options->para = false;
$options->noclean = true;
print_box(format_text($forum->intro, FORMAT_MOODLE, $options), 'generalbox', 'intro');

Best regards!
oshadi

Show
Awantha Oshadi Weerapperuma added a comment - Hi, This is the patch file that I'm suggestion for this issue. After going through the code, I've found that intro box content is finally surrounded by <p> tags. <p>is a block-level element that should contain a paragraph, comprised of text, inline elements that modify the text (<p>, <a>, <abbr>, etc.), and images. And it is not a container for all other elements.Therefor I've remove the addition of surrounding <p> tags. And Since the teachers are responsible for the content, I've remove the clean up of tags. So, I've modified the code... print_box(format_text($forum->intro), 'generalbox', 'intro'); to.. $options = new stdClass(); $options->para = false; $options->noclean = true; print_box(format_text($forum->intro, FORMAT_MOODLE, $options), 'generalbox', 'intro'); Best regards! oshadi
Hide
Dan Poltawski added a comment -

I do not think this patch is suitable - it would be a security risk remove the cleaning of posts, especially without a permission test.

Show
Dan Poltawski added a comment - I do not think this patch is suitable - it would be a security risk remove the cleaning of posts, especially without a permission test.
Hide
Nadav Kavalerchik added a comment -

can you give an example of the security risk ?
do not forget, these are teachers that input the content of this "intro" field

Show
Nadav Kavalerchik added a comment - can you give an example of the security risk ? do not forget, these are teachers that input the content of this "intro" field
Hide
Nadav Kavalerchik added a comment -

Awantha - thank you for you solution.
we adopted this approach with minor variations (as necessary on different places)
Martin - maybe we should open different sub-issues for the different places in the code
in which issues like this occur.

teacher should defently have more freedom to embed (external code) and format any resource or activity's INTRO
box as they like with no limitation (and be responsible for that, i hope
students should be able to to have similar abilities in blogs, forums posts and comments...
but controlled by admin's setting (as it is right now)

examples:

(formatting of text by teachers trying to justify mix ltr and rtl text was removed,
until these changes were applied)

calendar/lib.php (lines 548~)
$options = new stdClass;
$options->noclean = true;
echo format_text($event->description, FORMAT_HTML,$options);

mod/forum/view.php (lines 234~ and 261~)
if (!empty($forum->intro)) { $options = new stdClass; $options->noclean = true; print_box(format_text($forum->intro,$options), 'generalbox', 'intro'); }

mod/choice/view.php (lines ~83)
if ($choice->text) { $options = new stdClass; $options->noclean = true; print_box(format_text($choice->text, $choice->format,$options), 'generalbox', 'intro'); }

some 3rd party modules too...

Show
Nadav Kavalerchik added a comment - Awantha - thank you for you solution. we adopted this approach with minor variations (as necessary on different places) Martin - maybe we should open different sub-issues for the different places in the code in which issues like this occur. teacher should defently have more freedom to embed (external code) and format any resource or activity's INTRO box as they like with no limitation (and be responsible for that, i hope students should be able to to have similar abilities in blogs, forums posts and comments... but controlled by admin's setting (as it is right now) examples: (formatting of text by teachers trying to justify mix ltr and rtl text was removed, until these changes were applied) calendar/lib.php (lines 548~) $options = new stdClass; $options->noclean = true; echo format_text($event->description, FORMAT_HTML,$options); mod/forum/view.php (lines 234~ and 261~) if (!empty($forum->intro)) { $options = new stdClass; $options->noclean = true; print_box(format_text($forum->intro,$options), 'generalbox', 'intro'); } mod/choice/view.php (lines ~83) if ($choice->text) { $options = new stdClass; $options->noclean = true; print_box(format_text($choice->text, $choice->format,$options), 'generalbox', 'intro'); } some 3rd party modules too...
Hide
Martin Dougiamas added a comment -

Sam, a duplicate to close/link to your existing work.

Show
Martin Dougiamas added a comment - Sam, a duplicate to close/link to your existing work.
Hide
Sam Hemelryk added a comment -

Resolved in 2.0 by Petr's work on MDL-16072

Show
Sam Hemelryk added a comment - Resolved in 2.0 by Petr's work on MDL-16072

Dates

  • Created:
    Updated:
    Resolved: