| 1 |
<?php |
<?php |
| 2 |
// $Id: css.module,v 1.3.2.2 2008/12/03 18:31:46 fax8 Exp $ |
// $Id: css.module,v 1.3.2.3 2008/12/03 18:36:09 fax8 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 100 |
|
|
| 101 |
// Controls for valid input data |
// Controls for valid input data |
| 102 |
case 'validate': |
case 'validate': |
| 103 |
;//do some input check here.. |
// Check for potentially malicious tags |
| 104 |
|
$pattern = '~<\s*\/?\s*(style|script|meta)\s*.*?>~i'; |
| 105 |
|
if (preg_match($pattern, $node->css_css)) { |
| 106 |
|
form_set_error('css_css', t('Please do not include any tags.')); |
| 107 |
|
} |
| 108 |
break; |
break; |
| 109 |
|
|
| 110 |
// Now that the form has been properly completed, it is time to commit the new |
// Now that the form has been properly completed, it is time to commit the new |
| 138 |
// filters transform user-supplied content, whereas we are extending it with |
// filters transform user-supplied content, whereas we are extending it with |
| 139 |
// additional information. |
// additional information. |
| 140 |
case 'view': |
case 'view': |
| 141 |
theme('css_import', $node->nid); |
if($node->in_preview) { |
| 142 |
|
// 'validate' immediately followed by 'view' means this is a preview |
| 143 |
|
if ($node->css_css) { |
| 144 |
|
$css = '<style type="text/css" media="all"> '. |
| 145 |
|
css_sanitize($node->css_css, 'preview'). |
| 146 |
|
' </style>'; |
| 147 |
|
drupal_set_html_head($css, 'preview'); |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
else { |
| 151 |
|
theme('css_import', $node->nid); |
| 152 |
|
} |
| 153 |
break; |
break; |
| 154 |
} |
} |
| 155 |
} |
} |
| 166 |
$date = gmdate('D, d M Y H:i:s', $object->changed) .' GMT'; |
$date = gmdate('D, d M Y H:i:s', $object->changed) .' GMT'; |
| 167 |
header("Last-Modified: $date"); |
header("Last-Modified: $date"); |
| 168 |
drupal_set_header('Content-Type: text/css; charset=utf-8'); |
drupal_set_header('Content-Type: text/css; charset=utf-8'); |
| 169 |
print($object->css); |
print(css_sanitize($object->css)); |
| 170 |
} |
} |
| 171 |
} |
} |
| 172 |
} |
} |
| 173 |
|
|
| 174 |
|
|
| 175 |
|
/** |
| 176 |
|
* Remove harmful code from CSS. |
| 177 |
|
*/ |
| 178 |
|
function css_sanitize($css, $type = 'view') { |
| 179 |
|
switch ($type) { |
| 180 |
|
case 'view': |
| 181 |
|
// Are there any security vulnerabilites from external CSS files? |
| 182 |
|
break; |
| 183 |
|
|
| 184 |
|
case 'preview': |
| 185 |
|
// Catch potentially malicious code |
| 186 |
|
$patterns = array( |
| 187 |
|
'~<\s*(/?)\s*(style|script|meta)\s*>~i', |
| 188 |
|
); |
| 189 |
|
$css = preg_replace($patterns, '<$1FILTERED $2>', $css); |
| 190 |
|
break; |
| 191 |
|
|
| 192 |
|
default: |
| 193 |
|
$css = ''; |
| 194 |
|
break; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
return $css; |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
/** |
/** |
| 202 |
* Adds @import for the css in the head tag of page |
* Adds @import for the css in the head tag of page |
| 203 |
* We use a theme function for this to let themers able |
* We use a theme function for this to let themers able |
| 210 |
// we use $preprocess = FALSE as we don't want to cache the CSS rules. |
// we use $preprocess = FALSE as we don't want to cache the CSS rules. |
| 211 |
drupal_add_css('?q=css/get/' . $nid, 'theme', 'all', FALSE); |
drupal_add_css('?q=css/get/' . $nid, 'theme', 'all', FALSE); |
| 212 |
} |
} |
| 213 |
|
|
| 214 |
|
|