private function setConfigAttribute(HTMLPurifier_Config $config, $key, $subkey, $value) { if (version_compare($config->version, '4.0.0') >= 0) { $config->set("{$key}.{$subkey}", $value); } else { $config->set($key, $subkey, $value); } }
private static function html5Config(\HTMLPurifier_Config $config) { $config->set('HTML.DefinitionID', 'jivoo.html5'); $config->set('HTML.DefinitionRev', 1); $def = $config->maybeGetRawHTMLDefinition(); if ($def) { $def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'); $def->addElement('figcaption', 'Inline', 'Flow', 'Common'); } }
/** * @return \HTMLPurifier_Config */ protected function get_config() { if (is_null($this->config)) { $this->config = \HTMLPurifier_Config::createDefault(); $this->config->set('HTML.Doctype', 'HTML 4.01 Transitional'); $this->config->set('HTML.AllowedAttributes', array('a.href', 'a.target', 'img.src', '*.class')); $this->config->set('Attr.AllowedFrameTargets', array('_blank')); $this->config->set('HTML.Allowed', 'a,abbr,acronym,b,blockquote,cite,code,dd,div,dl,dt,em,i,li,ol,p,pre,s,span,strike,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,tt,u,ul'); } return $this->config; }
/** * @param string|array|HTMLPurifier_Config $config * @param HTMLPurifier_ConfigSchema $schema * @return HTMLPurifier_Config */ public static function create($config = null, HTMLPurifier_ConfigSchema $schema = null) { if (!$schema instanceof HTMLPurifier_ConfigSchema) { $schema = HTMLPurifier_ConfigSchema::makeFromSerial(); } if ($config instanceof HTMLPurifier_Config) { $configObj = $config; } else { $configObj = new HTMLPurifier_Config($schema); $configObj->set('Core.Encoding', 'UTF-8'); $configObj->set('HTML.Doctype', 'HTML 4.01 Transitional'); if (is_string($config)) { $configObj->loadIni($config); } elseif (is_array($config)) { $configObj->loadArray($config); } } $def = $configObj->getHTMLDefinition(true); // this finalizes config HTMLPurifier_HTML5Definition::setup($def); return $configObj; }
public function register(Application $app) { parent::register($app); $app['form.secret'] = $app->share(function () use($app) { return md5('form_secret' . $app['salt']); }); $app['html_purifier.allowed_elements'] = ['p', 'ul', 'ol', 'li', 'b', 'i', 'strong', 'em', 'img', 'sub', 'sup', 'blockquote', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'address', 'br', 'dl', 'dt', 'dd']; $app['html_purifier.allowed_attributes'] = ['*.class', 'img.src', 'img.alt', 'a.href', 'a.title', 'td.abbr', 'td.colspan', 'td.rowspan', 'th.abbr', 'th.colspan', 'th.rowspan', 'table.summary']; $app['html_purifier.config'] = $app->share(function () use($app) { $config = new \HTMLPurifier_Config(\HTMLPurifier_ConfigSchema::instance()); $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $config->set('HTML.AllowedElements', implode(',', $app['html_purifier.allowed_elements'])); $config->set('HTML.AllowedAttributes', implode(',', $app['html_purifier.allowed_attributes'])); $config->set('AutoFormat.RemoveEmpty', true); $config->set('AutoFormat.AutoParagraph', true); $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true); $cachePath = $app['paths.cache'] . '/htmlpurifier'; if (!is_dir($cachePath)) { mkdir($cachePath, 0777, true); } $config->set('Cache.SerializerPath', $cachePath); return $config; }); $app['html_purifier'] = $app->share(function () use($app) { return new \HTMLPurifier($app['html_purifier.config']); }); $app['form.html_purifier'] = $app->share(function () use($app) { return new HtmlPurifier($app['html_purifier']); }); $app['form.html_extension'] = $app->share(function () use($app) { return new HtmlExtension(new HtmlType($app['form.html_purifier']), new HtmlTypeGuesser($app['annotations.reader'])); }); $app['form.extensions'] = $app->share($app->extend('form.extensions', function (array $extensions) use($app) { $extensions[] = new DoctrineOrmExtension($app['orm.manager_registry']); $extensions[] = $app['form.html_extension']; return $extensions; })); $app['form.type.extensions'] = $app->share($app->extend('form.type.extensions', function (array $extensions) use($app) { $extensions[] = new FormTypeExtension(); $extensions[] = new DateTypeExtension(); $extensions[] = new TimeTypeExtension(); return $extensions; })); }
public function testInherit() { $this->schema->add('Phantom.Masked', 25, 'int', false); $this->schema->add('Phantom.Unmasked', 89, 'int', false); $this->schema->add('Phantom.Latemasked', 11, 'int', false); $config = new HTMLPurifier_Config($this->schema); $config->set('Phantom.Masked', 800); $subconfig = HTMLPurifier_Config::inherit($config); $config->set('Phantom.Latemasked', 100, 'int', false); $this->assertIdentical($subconfig->get('Phantom.Masked'), 800); $this->assertIdentical($subconfig->get('Phantom.Unmasked'), 89); $this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100); }
function test_finalize() { // test finalization $this->schema->addNamespace('Poem'); $this->schema->add('Poem', 'Meter', 'iambic', 'string', false); $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; $config->set('Poem', 'Meter', 'irregular'); $config->finalize(); $this->expectError('Cannot set directive after finalization'); $config->set('Poem', 'Meter', 'vedic'); $this->expectError('Cannot load directives after finalization'); $config->loadArray(array('Poem.Meter' => 'octosyllable')); $this->expectError('Cannot load directives after finalization'); $config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini'); }
/** * Add options to HTML Purifier config * * @param \HTMLPurifier_Config $config Config instance * * @return \HTMLPurifier_Config */ protected static function postprocessOptions($config, $options) { if ($options['HTML.SafeIframe'] && empty($options['URI.SafeIframeRegexp'])) { $config->set('URI.SafeIframeRegexp', '%.*%'); } return $config; }
public function __construct() { $this->config = \HTMLPurifier_Config::createDefault(); $this->config->set('HTML.Allowed', 'p,h2,h3,h4,h5,h6,strong,em,u,strike,a[href],ul,ol,li,img[src|alt]'); }
/** * Configure allowed tags * * @param \HTMLPurifier_Config $config */ protected function fillAllowedElementsConfig($config) { $converter = new TagDefinitionConverter(); if ($this->allowedElements) { $config->set('HTML.AllowedElements', $converter->getElements($this->allowedElements)); $config->set('HTML.AllowedAttributes', $converter->getAttributes($this->allowedElements)); } }