Removing "old baggage" CSS from Moodle 1.x

Removing "old baggage" CSS from Moodle 1.x

by Andreas Giesen -
Number of replies: 7

I have the assignment to migrate Moodle courses from a 2.1 to 3.2 (I have no control over the basic setup). 

The courses have been created under 1.x and have been styled with a CSS < style ></ style > included to a section summary. Later the courses have been exported and imported to a new 2.1. The 1.x version is not available any more. 

The CSS has been kept by Moodle, but is not accessible any more from within the course / editor due to the new restrictions concerning CSS. Now exporting and importing to 3.2 the CSS is still there, still not accessible. Thus no changes can be made, but the old style often is broken in the 3.2 environment. I need to delete the old CSS, and include it newly via Javascript in the course because the courses need to be exported and imported again including the CSS. 

Is there any way other than going directly to the database in order to delete the old "baggage" CSS? I would prefer that over overriding it with !important on every style. 

Average of ratings: -
In reply to Andreas Giesen

Re: Removing "old baggage" CSS from Moodle 1.x

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I've read this three times and I'm still confused...

Are we talking about exported Moodle backups here or something else? Where does this CSS you are talking about "live". 

You're not referring to SCORM modules or something similar are you?

In reply to Howard Miller

Re: Removing "old baggage" CSS from Moodle 1.x

by Andreas Giesen -

I find this a bit confusing myself... ;) 

Complete Moodle courses have been exported as backups from 1.8 and imported to 2.1 in the past. In 1.8 they where styled by inline-CSS and a < style >-Block in the last section summary. The CSS has been kept (and even URLs for background-images updated) by Moodle, but is not accessible any more via the editor. Also the inline-CSS still exists when checking say a p with webmaster-tools, but is also not accessible. 


This is terrible, because overruling it with Javascript-CSS eben with !important on every parameter does not work. And finding all the inline CSS in the database should be no fun. 

As the 1.8 version does not exist any more, and 2.1 already filters the inline-CSS, there is no way to remove the CSS before exporting the backup. 

Maybe within the backup-files via a text-editor? 



In reply to Andreas Giesen

Re: Removing "old baggage" CSS from Moodle 1.x

by Andreas Giesen -

Ok, in the XML-files I can access it. At least the < style >-Block can be removed easily. But the inline CSS is of course still a pain. 


A section-XML looks like this: 

<?xml version="1.0" encoding="UTF-8"?>

<section id="1319">

  <number>0</number>

  <name>$@NULL@$</name>

  <summary>&lt;table width="100%" cellpadding="10" border="1" frame="void" rules="none" style="text-align: left; vertical-align: top; float: none; background-image: none;"&gt;&lt;tbody&gt;

  &lt;tr&gt;

    &lt;td width="60%" valign="top" colspan="2" rowspan="1" style="text-align: left; font-weight: normal; vertical-align: top; background-image: none;"&gt;&lt;font size="4" style="color: rgb(197, 192, 186);"&gt;&lt;br /&gt;&lt;font face="Lato,sans-serif" size="5"&gt;Herzlich Willkommen!&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="arial,helvetica,sans-serif" size="5"&gt; &lt;/font&gt;&lt;br /&gt;

    &lt;/td&gt;

  &lt;/tr&gt;

  &lt;tr&gt;

  &lt;/tr&gt;&lt;/tbody&gt;

&lt;/table&gt;&lt;br /&gt;

&lt;div class="head"&gt;

  &lt;div class="headerA"&gt;

    &lt;p&gt;&lt;br /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;br /&gt;&lt;/p&gt;

    &lt;p&gt;Liebe Kursteilnehmerin, lieber Kursteilnehmer, In diesem Kurs ... &lt;/p&gt;&lt;/div&gt;

  &lt;div class="headerB"&gt; &lt;img width="435" vspace="5" hspace="5" height="280" border="0" align="left" src="https://moodle.org/pluginfile.php/133/mod_forum/post/1536016/image.png" alt="Titel" title="Titel" /&gt;&lt;/div&gt; &lt;/div&gt;</summary>

  <summaryformat>1</summaryformat>

  <sequence>9169,9170,9171</sequence>

  <visible>1</visible>

</section>

As you can see, the inline CSS is there; also this at least (the  @@PLUGINFILE@@) answers why the image-URLs have been updated in the process. 


In reply to Andreas Giesen

Re: Removing "old baggage" CSS from Moodle 1.x

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Ahh... looks like somebody has copied text into a Moodle resource which is full of inline CSS. The usual culprit is copy/paste from Word. 

Moodle isn't "keeping the CSS", it's just in the data. The block of text that somebody edited like that back in 1.8. 

Average of ratings: Useful (1)
In reply to Howard Miller

Re: Removing "old baggage" CSS from Moodle 1.x

by Andreas Giesen -

Yes, that is the cause, exactly. In other styles the typical Word CSS can be seen. 

The CSS is "in the data" but it is not shown by the new editor due to the restrictions. I would have expected Moodle to strip the data, that is not considered safe, and that would have helped a lot, but it is now clear to me that if that had happened, also images would be gone etc. so I understand why it is done this way. 

But I am out of ideas for solutions. The result is always terrible, and responsiveness is also defied by the table-based structure. 

In reply to Andreas Giesen

Re: Removing "old baggage" CSS from Moodle 1.x

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Atto does some cleaning and there is a plugin which does more... but there won't be anything in restore to do this. Garbage in, garbage out.  You would need to go and re-edit everything. 

It's possible somebody has scripted something to deal with this - but I'm not aware of it. 

In reply to Howard Miller

Re: Removing "old baggage" CSS from Moodle 1.x

by Andreas Giesen -

That's what I was afraid of. :| For now the client is not interested in investing in that much effort. I will have to make it functional and that's it. I don't like it if the result of my work is "garbage out" even if did not cause the "garbage in" ;)