mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 14:16:32 +02:00
Refactor MakeWellFormed/Injector for performance and as little code duplication as possible. Also, make AutoParagraph smarter about root nodes that don't like p tags.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1221 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -9,28 +9,17 @@ class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
|
||||
{
|
||||
|
||||
function handleText(&$token, $config, &$context) {
|
||||
$current_nesting =& $context->get('CurrentNesting');
|
||||
// this snippet could be factored out
|
||||
$definition = $config->getHTMLDefinition();
|
||||
if (!empty($current_nesting)) {
|
||||
$parent_token = array_pop($current_nesting);
|
||||
$current_nesting[] = $parent_token;
|
||||
$parent = $definition->info[$parent_token->name];
|
||||
} else {
|
||||
$parent = $definition->info_parent_def;
|
||||
}
|
||||
if (!isset($parent->child->elements['a']) || isset($parent->excludes['a'])) {
|
||||
// parent element does not allow link elements, don't bother
|
||||
return;
|
||||
}
|
||||
if (!$this->allowsElement('a')) return;
|
||||
|
||||
if (strpos($token->data, '://') === false) {
|
||||
// our really quick heuristic failed, abort
|
||||
// this may not work so well if we want to match things like
|
||||
// "google.com"
|
||||
// "google.com", but then again, most people don't
|
||||
return;
|
||||
}
|
||||
|
||||
// there is/are URL(s). Let's split the string:
|
||||
// Note: this regex is extremely permissive
|
||||
$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
$token = array();
|
||||
|
Reference in New Issue
Block a user