function _htmlpurifier_get_config in HTML Purifier 7
Same name and namespace in other branches
- 5 htmlpurifier.module \_htmlpurifier_get_config()
- 6.2 htmlpurifier.module \_htmlpurifier_get_config()
- 6 htmlpurifier.module \_htmlpurifier_get_config()
- 7.2 htmlpurifier.module \_htmlpurifier_get_config()
Returns the HTMLPurifier_Config object corresponding to a text format.
Parameters
int $format: (Optional) Text format ID. If left empty, the default configuration is returned.
Return value
Instance of HTMLPurifier_Config.
2 calls to _htmlpurifier_get_config()
- _htmlpurifier_process_text in ./
htmlpurifier.module - Processes HTML according to a format and returns purified HTML. Makes a cache pass if possible.
- _htmlpurifier_settings in ./
htmlpurifier.module - Generates a settings form for configuring HTML Purifier.
File
- ./
htmlpurifier.module, line 341 - Implements HTML Purifier as a Drupal filter.
Code
function _htmlpurifier_get_config($format = 0) {
$config = HTMLPurifier_Config::createDefault();
$config
->set('AutoFormat.AutoParagraph', TRUE);
$config
->set('AutoFormat.Linkify', TRUE);
$config
->set('HTML.Doctype', 'XHTML 1.0 Transitional');
// Probably
$config
->set('Core.AggressivelyFixLt', TRUE);
$config
->set('Cache.DefinitionImpl', 'Drupal');
if (!empty($_SERVER['SERVER_NAME'])) {
// SERVER_NAME is more reliable than HTTP_HOST
$config
->set('URI.Host', $_SERVER['SERVER_NAME']);
}
if (defined('LANGUAGE_RTL') && $GLOBALS['language']->direction === LANGUAGE_RTL) {
$config
->set('Attr.DefaultTextDir', 'rtl');
}
if ($format && ($config_function = _htmlpurifier_config_load($format))) {
$config_function($config);
}
else {
// We only support one instance of this module's filters (either basic or
// advanced) per text format, so choose the first settings we find.
// TODO: This is awkward, but the most straightforward conversion from the
// D6 version, which also treated this as a per-format setting and
// therefore had the same limitation.
$filters = $format ? filter_list_format($format) : array();
if (!empty($filters['htmlpurifier_advanced']->status) && isset($filters['htmlpurifier_advanced']->settings['htmlpurifier_advanced_config'])) {
$config_data = $filters['htmlpurifier_advanced']->settings['htmlpurifier_advanced_config'];
}
elseif (!empty($filters['htmlpurifier_basic']->status) && isset($filters['htmlpurifier_basic']->settings['htmlpurifier_basic_config'])) {
$config_data = $filters['htmlpurifier_basic']->settings['htmlpurifier_basic_config'];
}
else {
$config_data = FALSE;
}
if (!empty($config_data['Filter.ExtractStyleBlocks'])) {
if (!_htmlpurifier_load_csstidy()) {
$config_data['Filter.ExtractStyleBlocks'] = '0';
drupal_set_message(t("Could not enable ExtractStyleBlocks because CSSTidy was not installed. You can download CSSTidy module from <a href='http://drupal.org/project/csstidy'>http://drupal.org/project/csstidy</a>"), 'error', FALSE);
}
}
// {FALSE, TRUE, FALSE} = {no index, everything is allowed, don't do mq fix}
$config
->mergeArrayFromForm($config_data, FALSE, TRUE, FALSE);
}
// Allow other modules to alter the HTML definition.
$html_definition = $config
->getHTMLDefinition(TRUE);
drupal_alter('htmlpurifier_html_definition', $html_definition);
return $config;
}