Skip to content

Commit

Permalink
Autotags Close Tag now are only checked for specific autotags that re…
Browse files Browse the repository at this point in the history
…quire them

Update to feature #776
  • Loading branch information
eSilverStrike committed May 11, 2017
1 parent 297f463 commit f7b9c26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
10 changes: 8 additions & 2 deletions public_html/lib-common.php
Expand Up @@ -4646,12 +4646,18 @@ function COM_allowedAutotags($list_only = false, $allowed_tags = array())
// List autotags user has permission to use (with descriptions)
$autotags = array_keys(PLG_collectTags('permission'));
$description = array_flip(PLG_collectTags('description'));
$closetag = array_flip(PLG_collectTags('closetag'));
foreach ($autotags as $tag) {
if (in_array($tag, $closetag)) {
$tagname = '[' . $tag . ':][/' . $tag . ']';
} else {
$tagname = '[' . $tag . ':]';
}
if (!empty($description[$tag])) {
$desc = str_replace(array('[', ']'), array('[', ']'), $description[$tag]);
$list .= COM_getTooltip('[' . $tag . ':]', $desc, '', $LANG01[132], 'information') . ', ';
$list .= COM_getTooltip($tagname, $desc, '', $LANG01[132], 'information') . ', ';
} else {
$list .= '[' . $tag . ':] , ';
$list .= $tagname . ' , ';
}
}
$list = rtrim($list, ', ');
Expand Down
32 changes: 18 additions & 14 deletions system/lib-plugins.php
Expand Up @@ -1580,7 +1580,6 @@ function PLG_collectTags($type = 'tagname')
}
}
}

}

return $autolinkModules;
Expand Down Expand Up @@ -1614,6 +1613,9 @@ function PLG_replaceTags($content, $plugin = '', $remove = false)
} else {
$autolinkModules = PLG_collectTags();
}

//See if any tags require close tags
$tags_requireclose = array_flip(PLG_collectTags('closetag'));

for ($i = 1; $i <= 5; $i++) {
list($content, $markers) = GLText::protectJavascript($content);
Expand Down Expand Up @@ -1667,19 +1669,21 @@ function PLG_replaceTags($content, $plugin = '', $remove = false)
'parm2' => $label,
);

// Check for close tag after end of start tag. if exist we have a parm3
$close_tag = '[/' . $moduleTag . ']';
$start_pos_close_tag = MBYTE_strpos($content_lower, $close_tag, $end_pos_tag);
if ($start_pos_close_tag > $end_pos_tag) { // make sure close tag is after tag
$end_of_whole_tag_pos = $start_pos_close_tag + strlen($close_tag);
$wrapped_text_length = $start_pos_close_tag - ($end_pos_tag + 1);
$wrapped_text = MBYTE_substr($content, ($end_pos_tag + 1), $wrapped_text_length);

// New parm3
$newTag['parm3'] = $wrapped_text;
// Since parm3 now update tagstr and length as well
$newTag['tagstr'] = $tag . $wrapped_text . $close_tag;
$newTag['length'] = $end_of_whole_tag_pos - $start_pos_tag;
if (in_array($moduleTag, $tags_requireclose)) {
// Check for close tag after end of start tag. if exist we have a parm3
$close_tag = '[/' . $moduleTag . ']';
$start_pos_close_tag = MBYTE_strpos($content_lower, $close_tag, $end_pos_tag);
if ($start_pos_close_tag > $end_pos_tag) { // make sure close tag is after tag
$end_of_whole_tag_pos = $start_pos_close_tag + strlen($close_tag);
$wrapped_text_length = $start_pos_close_tag - ($end_pos_tag + 1);
$wrapped_text = MBYTE_substr($content, ($end_pos_tag + 1), $wrapped_text_length);

// New parm3
$newTag['parm3'] = $wrapped_text;
// Since parm3 now update tagstr and length as well
$newTag['tagstr'] = $tag . $wrapped_text . $close_tag;
$newTag['length'] = $end_of_whole_tag_pos - $start_pos_tag;
}
}

$tags[] = $newTag;
Expand Down

0 comments on commit f7b9c26

Please sign in to comment.