forked from leftypol/leftypol
Refactor post.php: move post body's markup splitting into a separate function
This commit is contained in:
parent
799072d692
commit
df78f0e79f
1 changed files with 39 additions and 24 deletions
63
post.php
63
post.php
|
@ -16,7 +16,8 @@ require_once 'inc/bootstrap.php';
|
||||||
* @param [type] $file file to the the md5 of.
|
* @param [type] $file file to the the md5 of.
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
function md5_hash_of_file($config, $file) {
|
function md5_hash_of_file($config, $file)
|
||||||
|
{
|
||||||
$cmd = false;
|
$cmd = false;
|
||||||
if ($config['bsd_md5']) {
|
if ($config['bsd_md5']) {
|
||||||
$cmd = '/sbin/md5 -r';
|
$cmd = '/sbin/md5 -r';
|
||||||
|
@ -34,6 +35,34 @@ function md5_hash_of_file($config, $file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip the markup from the given string
|
||||||
|
*
|
||||||
|
* @param string $post_body the body of the post.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function strip_markup($post_body)
|
||||||
|
{
|
||||||
|
if (mysql_version() >= 50503) {
|
||||||
|
return $post_body; // Assume we're using the utf8mb4 charset
|
||||||
|
} else {
|
||||||
|
// MySQL's `utf8` charset only supports up to 3-byte symbols
|
||||||
|
// Remove anything >= 0x010000
|
||||||
|
|
||||||
|
$chars = preg_split('//u', $post_body, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
$res = '';
|
||||||
|
foreach ($chars as $char) {
|
||||||
|
$o = 0;
|
||||||
|
$ord = ordutf8($char, $o);
|
||||||
|
if ($ord >= 0x010000)
|
||||||
|
continue;
|
||||||
|
$res .= $char;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method handling functions
|
* Method handling functions
|
||||||
*/
|
*/
|
||||||
|
@ -977,10 +1006,12 @@ function handle_post()
|
||||||
function ipv4to6($ip)
|
function ipv4to6($ip)
|
||||||
{
|
{
|
||||||
if (strpos($ip, ':') !== false) {
|
if (strpos($ip, ':') !== false) {
|
||||||
if (strpos($ip, '.') > 0)
|
if (strpos($ip, '.') > 0) {
|
||||||
$ip = substr($ip, strrpos($ip, ':') + 1);
|
$ip = substr($ip, strrpos($ip, ':') + 1);
|
||||||
else
|
} else {
|
||||||
return $ip; //native ipv6
|
// Native ipv6.
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$iparr = array_pad(explode('.', $ip), 4, 0);
|
$iparr = array_pad(explode('.', $ip), 4, 0);
|
||||||
$part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
|
$part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
|
||||||
|
@ -989,9 +1020,10 @@ function handle_post()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($country_code = geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
|
if ($country_code = geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
|
||||||
if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2')))
|
if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2'))) {
|
||||||
$post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . "</tinyboard>" .
|
$post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . "</tinyboard>" .
|
||||||
"\n<tinyboard flag alt>" . geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])) . "</tinyboard>";
|
"\n<tinyboard flag alt>" . geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])) . "</tinyboard>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,23 +1052,7 @@ function handle_post()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql_version() >= 50503) {
|
$post['body_nomarkup'] = strip_markup($post['body']);
|
||||||
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
|
|
||||||
} else {
|
|
||||||
// MySQL's `utf8` charset only supports up to 3-byte symbols
|
|
||||||
// Remove anything >= 0x010000
|
|
||||||
|
|
||||||
$chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY);
|
|
||||||
$post['body_nomarkup'] = '';
|
|
||||||
foreach ($chars as $char) {
|
|
||||||
$o = 0;
|
|
||||||
$ord = ordutf8($char, $o);
|
|
||||||
if ($ord >= 0x010000)
|
|
||||||
continue;
|
|
||||||
$post['body_nomarkup'] .= $char;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$post['tracked_cites'] = markup($post['body'], true);
|
$post['tracked_cites'] = markup($post['body'], true);
|
||||||
|
|
||||||
if ($post['has_file']) {
|
if ($post['has_file']) {
|
||||||
|
@ -1514,8 +1530,7 @@ function handle_post()
|
||||||
// Tell Javascript that we posted successfully
|
// Tell Javascript that we posted successfully
|
||||||
if (isset($_COOKIE[$config['cookies']['js']])) {
|
if (isset($_COOKIE[$config['cookies']['js']])) {
|
||||||
$js = json_decode($_COOKIE[$config['cookies']['js']]);
|
$js = json_decode($_COOKIE[$config['cookies']['js']]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$js = (object) array();
|
$js = (object) array();
|
||||||
}
|
}
|
||||||
// Tell it to delete the cached post for referer
|
// Tell it to delete the cached post for referer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue