mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-12 01:50:48 +01:00
Much better post modifiers: raw HTML, ban messages, etc.
This commit is contained in:
parent
cc62b888af
commit
4876a27232
@ -1464,64 +1464,30 @@ function unicodify($body) {
|
||||
function extract_modifiers($body) {
|
||||
$modifiers = array();
|
||||
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@um', $body, $matches, PREG_SET_ORDER)) {
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@us', $body, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
$modifiers[$match[1]] = $match[2];
|
||||
if (preg_match('/^escape /', $match[1]))
|
||||
continue;
|
||||
$modifiers[$match[1]] = html_entity_decode($match[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $modifiers;
|
||||
}
|
||||
|
||||
function markup(&$body, $track_cites = false) {
|
||||
global $board, $config, $markup_urls;
|
||||
|
||||
$modifiers = extract_modifiers($body);
|
||||
|
||||
$body = preg_replace('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@us', '', $body);
|
||||
|
||||
if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1')
|
||||
return $body;
|
||||
|
||||
$body = str_replace("\r", '', $body);
|
||||
$body = utf8tohtml($body);
|
||||
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@um', $body, $modifiers, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
|
||||
$skip_chars = 0;
|
||||
$body_tmp = $body;
|
||||
$end_markup = false;
|
||||
|
||||
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'], html_entity_decode($modifier['content']));
|
||||
if ($end_markup) {
|
||||
$body .= $replacement;
|
||||
}
|
||||
} elseif ($modifier['type'] == 'raw html') {
|
||||
$body = html_entity_decode($modifier['content']);
|
||||
$replacement = '';
|
||||
$end_markup = true;
|
||||
} elseif (preg_match('/^escape /', $modifier['type'])) {
|
||||
// Escaped (not a real modifier)
|
||||
$replacement = '<tinyboard ' . substr($modifier['type'], strlen('escape ')) . '>' . $modifier['content'] . '</tinyboard>';
|
||||
} else {
|
||||
// Unknown
|
||||
$replacement = '';
|
||||
}
|
||||
|
||||
if (!$end_markup) {
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($end_markup) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if (mysql_version() < 50503)
|
||||
$body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8');
|
||||
|
||||
|
10
post.php
10
post.php
@ -421,19 +421,19 @@ if (isset($_POST['delete'])) {
|
||||
wordfilters($post['body']);
|
||||
$post['body'] = escape_markup_modifiers($post['body']);
|
||||
|
||||
if ($mod && isset($post['raw']) && $post['raw']) {
|
||||
$post['body'] .= '<tinyboard raw html>1</tinyboard>';
|
||||
}
|
||||
|
||||
if ($config['country_flags']) {
|
||||
if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
|
||||
error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION));
|
||||
}
|
||||
if ($country_code = @geoip_country_code_by_name('8.8.8.8')) {
|
||||
if ($country_code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])) {
|
||||
$post['body'] .= '<tinyboard flag_country>' . strtolower($country_code) . '</tinyboard>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($mod && isset($post['raw']) && $post['raw']) {
|
||||
$post['body'] = '<tinyboard raw html>' . $post['body'] . '</tinyboard>';
|
||||
}
|
||||
|
||||
if (mysql_version() >= 50503) {
|
||||
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
|
||||
} else {
|
||||
|
@ -108,6 +108,9 @@
|
||||
{{ post.postControls }}
|
||||
<div class="body">
|
||||
{% endfilter %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% filter remove_whitespace %}
|
||||
{% if post.modifiers['ban message'] %}
|
||||
{{ config.mod.ban_message|sprintf(post.modifiers['ban message']) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
|
@ -81,6 +81,9 @@
|
||||
{% endif %}
|
||||
{% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %}
|
||||
[<a style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
|
||||
{% endif %}
|
||||
{% if config.display_flags and post.modifiers.flag_country %}
|
||||
<img class="flag" style="width:{{ config.flag_width }}px;height:{{ config.flag_height }}px" src="{{ config.uri_flags|sprintf(post.modifiers.flag_country) }}">
|
||||
{% endif %}
|
||||
<time datetime="{{ post.time|date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }}">{{ post.time|date(config.post_date) }}</time>
|
||||
</label>
|
||||
@ -127,6 +130,9 @@
|
||||
</p>
|
||||
<div class="body">
|
||||
{% endfilter %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% filter remove_whitespace %}
|
||||
{% if post.modifiers['ban message'] %}
|
||||
{{ config.mod.ban_message|sprintf(post.modifiers['ban message']) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if post.omitted or post.omitted_images %}
|
||||
<span class="omitted">
|
||||
|
Loading…
Reference in New Issue
Block a user