forked from leftypol/leftypol
Markup modifiers. Fix issue #66 (public ban message lost when rebuilding post body)
This commit is contained in:
parent
4891735c49
commit
6d52c8b428
3 changed files with 45 additions and 4 deletions
|
@ -1456,13 +1456,43 @@ function markup(&$body, $track_cites = false) {
|
|||
}
|
||||
}
|
||||
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.+)</tinyboard>@', $body, $modifiers, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
|
||||
$skip_chars = 0;
|
||||
$body_tmp = $body;
|
||||
|
||||
foreach ($modifiers as $modifier) {
|
||||
// preg_match_all is not multibyte-safe
|
||||
foreach ($modifier as &$match) {
|
||||
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
|
||||
}
|
||||
|
||||
$modifier['type'] = $modifier[1][0];
|
||||
$modifier['content'] = $modifier[2][0];
|
||||
|
||||
if ($modifier['type'] == 'ban message') {
|
||||
// Public ban message
|
||||
$replacement = sprintf($config['mod']['ban_message'], $modifier['content']);
|
||||
} elseif (preg_match('/^escape /', $modifier['type'])) {
|
||||
// Escaped (not a real modifier)
|
||||
$replacement = '<tinyboard ' . substr($modifier['type'], strlen('escape ')) . '>' . $modifier['content'] . '</tinyboard>';
|
||||
} else {
|
||||
// Unknown
|
||||
$replacement = '';
|
||||
}
|
||||
|
||||
$body = mb_substr_replace($body, $replacement, $modifier[0][1] + $skip_chars, mb_strlen($modifier[0][0]));
|
||||
$skip_chars += mb_strlen($replacement) - mb_strlen($modifier[0][0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// replace tabs with 8 spaces
|
||||
$body = str_replace("\t", ' ', $body);
|
||||
|
||||
$tracked_cites = array();
|
||||
|
||||
// Cites
|
||||
if (isset($board) && preg_match_all('/(^|\s)>>(\d+?)([\s,.)?]|$)/m', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
|
||||
if (isset($board) && preg_match_all('/(^|\s)>>(\d+?)([\s,.)?]|$)/m', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
|
||||
if (count($cites[0]) > $config['max_cites']) {
|
||||
error($config['error']['toomanycites']);
|
||||
}
|
||||
|
@ -1561,6 +1591,10 @@ function markup(&$body, $track_cites = false) {
|
|||
return $tracked_cites;
|
||||
}
|
||||
|
||||
function escape_markup_modifiers($string) {
|
||||
return preg_replace('@<tinyboard ([\w\s]+)>(.+)</tinyboard>@', '<tinyboard escape $1>$2</tinyboard>', $string);
|
||||
}
|
||||
|
||||
function utf8tohtml($utf8) {
|
||||
return htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue