Commit 2dab9553 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Allow CSS comments in customised skins. Bug 1369830"

parents 28b194d8 859478ef
Filter.ExtractStyleBlocks.PreserveCSS
TYPE: bool
VERSION: 3.1.0
DEFAULT: false
EXTERNAL: CSSTidy
--DESCRIPTION--
<p>
If it turns on, HTML Purifier will attempt to preserve CSS comments.
</p>
--# vim: et sw=4 sts=4
......@@ -118,6 +118,9 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
*/
public function cleanCSS($css, $config, $context)
{
if ($config->get('Filter.ExtractStyleBlocks.PreserveCSS')) {
$this->_tidy->set_cfg('preserve_css', true);
}
// prepare scope
$scope = $config->get('Filter.ExtractStyleBlocks.Scope');
if ($scope !== null) {
......
......@@ -9,4 +9,4 @@ content.
Changes:
* None
* Add the configuration directive Filter.ExtractStyleBlocks.PreserveCSS to allow the comments while cleaning CSS
......@@ -3345,9 +3345,10 @@ function clean_html($text, $xhtml=false) {
* http://stackoverflow.com/questions/3241616/sanitize-user-defined-css-in-php#5209050
*
* @param string $input_css
* @param string $preserve_css, if turns on the CSS comments will be preserved
* @return string The cleaned CSS
*/
function clean_css($input_css) {
function clean_css($input_css, $preserve_css=false) {
require_once('htmlpurifier/HTMLPurifier.auto.php');
require_once('csstidy/class.csstidy.php');
......@@ -3357,6 +3358,7 @@ function clean_css($input_css) {
$config->set('Cache.SerializerPath', get_config('dataroot') . 'htmlpurifier');
$config->set('Filter.ExtractStyleBlocks', true);
$config->set('Filter.ExtractStyleBlocks.PreserveCSS', $preserve_css);
if (get_config('disableexternalresources')) {
$config->set('URI.DisableExternalResources', true);
......
......@@ -659,7 +659,7 @@ function designskinform_submit(Pieform $form, $values) {
$skin['view_button_normal_color'] = $values['view_button_normal_color'];
$skin['view_button_hover_color'] = $values['view_button_hover_color'];
$skin['view_button_text_color'] = $values['view_button_text_color'];
$skin['view_custom_css'] = clean_css($values['view_custom_css']);
$skin['view_custom_css'] = clean_css($values['view_custom_css'], $preserve_css=true);
$viewskin = array();
$viewskin['id'] = $values['id'];
......
......@@ -196,7 +196,7 @@ function importskinform_submit(Pieform $form, $values) {
// Custom CSS element...
$items = $skindata->getElementsByTagName('customcss');
foreach ($items as $item) {
$skin['view_custom_css'] = clean_css(unserialize($item->getAttribute('contents')));
$skin['view_custom_css'] = clean_css(unserialize($item->getAttribute('contents')), $preserve_css=true);
}
// Image element...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment