From b666886416f793074669a7e2bc1d7cc3c2b4746a Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 16 Aug 2013 21:08:01 +1000 Subject: A few modifications: 1. Finally, clean up some of the crappy code in inc/display.php; no more extreme clutter. new Thread() and new Post() take an array as the first parameter now. 2. Poster country flags. Currently requires the "geoip" extension. 3. Give post images a classname. This was also long-overdue. --- inc/functions.php | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 085d911f..c6751a91 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -149,6 +149,8 @@ function loadConfig() { $config['url_javascript'] = $config['root'] . $config['file_script']; if (!isset($config['additional_javascript_url'])) $config['additional_javascript_url'] = $config['root']; + if (!isset($config['uri_flags'])) + $config['uri_flags'] = $config['root'] . 'static/flags/%s.png'; if ($config['root_file']) { chdir($config['root_file']); @@ -1044,11 +1046,7 @@ function index($page, $mod=false) { if ($query->rowCount() < 1 && $page > 1) return false; while ($th = $query->fetch(PDO::FETCH_ASSOC)) { - $thread = new Thread( - $th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], - $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], - $th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod - ); + $thread = new Thread($th, $mod ? '?/' : $config['root'], $mod); if ($config['cache']['enabled'] && $cached = cache::get("thread_index_{$board['uri']}_{$th['id']}")) { $replies = $cached['replies']; @@ -1080,11 +1078,7 @@ function index($page, $mod=false) { if ($po['file']) $num_images++; - $thread->add(new Post( - $po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'], - $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], - $po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod) - ); + $thread->add(new Post($po, $mod ? '?/' : $config['root'], $mod)); } if ($omitted) { @@ -1467,6 +1461,18 @@ function unicodify($body) { return $body; } +function extract_modifiers($body) { + $modifiers = array(); + + if (preg_match_all('@(.+?)@um', $body, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + $modifiers[$match[1]] = $match[2]; + } + } + + return $modifiers; +} + function markup(&$body, $track_cites = false) { global $board, $config, $markup_urls; @@ -1730,17 +1736,9 @@ function buildThread($id, $return = false, $mod = false) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) { if (!isset($thread)) { - $thread = new Thread( - $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], - $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], - $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod - ); + $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); } else { - $thread->add(new Post( - $post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], - $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], - $post['filesize'], $post['filename'], $post['ip'], $post['embed'], $mod ? '?/' : $config['root'], $mod) - ); + $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); } } -- cgit v1.3 From 4876a27232cdf4d77613a6e2e3b4c185c319908b Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 16 Aug 2013 21:25:56 +1000 Subject: Much better post modifiers: raw HTML, ban messages, etc. --- inc/functions.php | 58 ++++++++++------------------------------------ post.php | 10 ++++---- templates/post_reply.html | 3 +++ templates/post_thread.html | 6 +++++ 4 files changed, 26 insertions(+), 51 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index c6751a91..80d67b6b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1464,64 +1464,30 @@ function unicodify($body) { function extract_modifiers($body) { $modifiers = array(); - if (preg_match_all('@(.+?)@um', $body, $matches, PREG_SET_ORDER)) { + if (preg_match_all('@(.+?)@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('@(.+?)@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'); diff --git a/post.php b/post.php index 11792379..d160c7e3 100644 --- a/post.php +++ b/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'] .= '1'; + } + 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'] .= '' . strtolower($country_code) . ''; } } - if ($mod && isset($post['raw']) && $post['raw']) { - $post['body'] = '' . $post['body'] . ''; - } - if (mysql_version() >= 50503) { $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset } else { diff --git a/templates/post_reply.html b/templates/post_reply.html index 56832710..1cce0e27 100644 --- a/templates/post_reply.html +++ b/templates/post_reply.html @@ -108,6 +108,9 @@ {{ post.postControls }}
{% 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 %}

diff --git a/templates/post_thread.html b/templates/post_thread.html index 5caca9a4..6824ce9d 100644 --- a/templates/post_thread.html +++ b/templates/post_thread.html @@ -81,6 +81,9 @@ {% endif %} {% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %} [{{ post.ip }}] + {% endif %} + {% if config.display_flags and post.modifiers.flag_country %} + {% endif %} @@ -127,6 +130,9 @@

{% 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 %}
{% if post.omitted or post.omitted_images %} -- cgit v1.3