Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-12-19 18:03:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

base64 encoding of css

For whatever reason, the stylesheets inside TXP are encoded in base64. This is a mild impediment on at least these counts:

  • plugins that search the admin side for stuff (e.g. smd_where_used) can’t look at stylesheets in the database without doing some special extra coding
  • stylesheets take up more space in the database
  • it has possible performance impacts (I have no concrete data to back this up, but since it’s another function call that needs to be made when viewing, editing and saving stylesheets it must have some kind of performance penalty, however small)

Ruud gave his thumbs up to the notion of abolishing the base64 step (and I’d like to get rid of it too), but making this change in a backwards-compatible manner is not trivial. Well, from TXP’s perspective it is fairly easy, but from a plugin perspective it presents problems.

On upgrade it’s easy for TXP to check if the stylesheets are encoded and resave them without encoding — I’ve done it and it works well. But then rvm_css will break. And jmd_img_selector will need updating. I don’t know about hcg_templates; I’m sure there are other plugins that are affected. Is this a problem? Is there a way to handle it such that it doesn’t swallow stylesheets / kill your site if a plugin is given a non-base64-encoded block of code?

One potential way that wet suggested of handling it might be to rename the database column from its current css to something else. This would mean that existing plugins will generate an error if they try to write to it, which is perhaps preferable to silently trying to base64_decode plaintext and mangling your stylesheets without warning. An alternative is for plugin authors to update their plugins to check whether they’ve been given base64 or not (there’s a regexp to do that). But this adds complexity and weight to plugins for no gain and since the whole point of rvm_css (for example) is pure speed, this step seems counter intuitive.

So I’d like to gauge:

  1. which plugins will be affected1
  2. if the benefit of changing the core outweighs the plugin fallout that it generates
  3. if anyone can think of a good way of making this change as unobtrusive as possible

Please post your thoughts here. Thanks in advance.

1 EDIT: Known affected plugins:

  • rvm_css : updated, thanks
  • rah_css_embed : updated, thanks
  • jmd_img_selector : will be updated by jm soon
  • fla_style_switcher / fla_altstyle_link : no longer supported (see smd_style instead)
  • ako_cssParse : no longer supported by author (see smd_style or rah_css_parse instead)
  • cnk_versioning
  • smd_style
  • smd_where_used (enhancement required to search stylesheets)

Last edited by Bloke (2010-07-05 01:18:49)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2009-12-19 18:41:18

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: base64 encoding of css

The base64 decoding in rvm_css only happens if you update the stylesheet on the admin side, not when loading the style sheet (static file) on the public side, so there’s no impact on speed. I don’t mind updating my plugin to support both situations.

Which regex did you have in mind? This one: ^[a-zA-Z0-9/+]*={0,2}$

I’d vote for updating the data inside the css column instead of creating a new column.

Offline

#3 2009-12-19 19:18:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: base64 encoding of css

ruud wrote:

…there’s no impact on speed. I don’t mind updating my plugin to support both situations.

OK, that’s good to know. Brilliant, thanks. I know jmd_img_selector just has some css inside it that’s encoded prior to insertion into the txp_css table upon plugin installation so that may require version detection or a new plugin version for 4.3.0 and higher. Be interesting to find out if there are any other well-used plugins that might explode.

Which regex did you have in mind? This one: ^[a-zA-Z0-9/+]*={0,2}$

Yup, that’s the only one I could find that the consensus concluded was well tested and reliable enough for base64 detection.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2009-12-19 20:08:24

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: base64 encoding of css

updated plugin: rvm_css

Offline

#5 2009-12-20 00:15:12

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: base64 encoding of css

Does that cope with both Ruud?

I’m presuming this will go through SVN first. I’m thinking that this is exactly the type of update where the pros of being “up-to-date” are outweighed by the cons of potential “f**k-up” via the odd plugin or two so I wouldn’t go with this one on my live sites until I knew it had been proven. That being the case I would go with installing to XAMPP and installing plugins to find out which work and which don’t then report back here so we can inform the relevant plugin writers that they will need an update.

If that’s the case we need volunteers.

Last edited by thebombsite (2009-12-20 00:16:14)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#6 2009-12-20 12:13:05

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: base64 encoding of css

Yes, it copes with both situations, so you can install it on current TXP versions as well.

Offline

#7 2009-12-20 13:44:42

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: base64 encoding of css

I want to say, I love you… wait that was not it. Oh yes, updated rah_css_embed.

Offline

#8 2010-01-10 10:25:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: base64 encoding of css

Many thanks to the authors who have updated their plugins or contacted me to say they will do so. This community rocks!

Once jm has updated jmd_img_selector I’ll commit the patch because I think that’s the last major hurdle (besides smd_style which is going through a revamp too).

Anyone who uses ako_cssParse please speak up. Adrian does not have the time to support it any more so if anyone needs it I’ll adopt it and make the necessary changes. smd_style has this functionality built in, but if you don’t want the fully fledged stylesheet switching capability of smd_style and would prefer to just be able to use TXP tags in your stylesheets, let me know.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2010-01-10 15:24:43

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: base64 encoding of css

From old ashes rah_css_parse with updated base64_decoding.

Last edited by Gocom (2010-01-10 15:28:03)

Offline

#10 2010-01-11 09:17:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: base64 encoding of css

Gocom wrote:

From old ashes rah_css_parse

Brilliant, thanks Gocom. Saves me a job :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2010-01-11 13:00:35

chriloi
Plugin Author
From: Vienna, Austria
Registered: 2006-01-17
Posts: 120
Website

Re: base64 encoding of css

Thanks for the email Stef!

I’m going to update cnk_versioning to handle this, but I’m struggling with a simple question:

How to detect encoding when no css data is stored in the database? (When using cnk_versioning some might delete all css styles to begin a new design from scratch…)

Offline

#12 2010-01-11 13:21:24

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: base64 encoding of css

chriloi wrote:

How to detect encoding when no css data is stored in the database?

Two methods come in my mind:

  1. Comparing TXP’s version.
  2. Comparison of outputs done by css.php (if it returns correct content for base64 encoded content and such).

Offline

Board footer

Powered by FluxBB