1
#1
Emoji support!
Posted November 4th 2016, 1:54am
Here's a simple hack that will add emoji support to phpBB 3.0.x.

Please note that this hack requires that you are using PHP 5.3+ with the mbstring extension installed. If you are using PHP 5.2 or earlier, do not make these changes! If the PHP mbstring extension is not installed, the hacks will do nothing. Also note that use of emojis in forum names and topic titles may cause problems with search engines.

So...here's how to add emoji support! First, open the includes/functions.php file, and at the top, find this code in the set_var() function:

				if (!preg_match('/^./u', $result))
{
$result = '';
}

Change the code to:

				if (!preg_match('/^./u', $result))
{
$result = '';
}
else if (@extension_loaded('mbstring'))
{
$result = preg_replace_callback('/([\x{1f000}-\x{1ffff}])/u', function($matches) {
return strtolower('&#x' . dechex(substr(mb_convert_encoding($matches[1], 'HTML-ENTITIES', 'UTF-8'), 2, -1)) . ';');
}, $result);
}

Now save the file. Next, open the includes/functions_content.php file and find the truncate_string() function. Replace the entire function with the following:

function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
{
$chars = array();

$strip_reply = false;
$stripped = false;
if ($allow_reply && strpos($string, 'Re: ') === 0)
{
$strip_reply = true;
$string = substr($string, 4);
}

if (@extension_loaded('mbstring'))
{
$string = preg_replace_callback('/([0-9a-f]{3};)/', function($matches) {
return mb_convert_encoding($matches[1], 'UTF-8', 'HTML-ENTITIES');
}, $string);
}

$_chars = utf8_str_split(htmlspecialchars_decode($string));
$chars = array_map('utf8_htmlspecialchars', $_chars);

// Now check the length ;)
if (sizeof($chars) > $max_length)
{
// Cut off the last elements from the array
$string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append)));
$stripped = true;
}

// Due to specialchars, we may not be able to store the string...
if (utf8_strlen($string) > $max_store_length)
{
// let's split again, we do not want half-baked strings where entities are split
$_chars = utf8_str_split(htmlspecialchars_decode($string));
$chars = array_map('utf8_htmlspecialchars', $_chars);

do
{
array_pop($chars);
$string = implode('', $chars);
}
while (!empty($chars) && utf8_strlen($string) > $max_store_length);
}

if ($strip_reply)
{
$string = 'Re: ' . $string;
}

if ($append != '' && $stripped)
{
$string = $string . $append;
}

if (@extension_loaded('mbstring'))
{
$string = preg_replace_callback('/([\x{1f000}-\x{1ffff}])/u', function($matches) {
return strtolower('&#x' . dechex(substr(mb_convert_encoding($matches[1], 'HTML-ENTITIES', 'UTF-8'), 2, -1)) . ';');
}, $string);
}

return $string;
}

Now save the file. That's it! You now have true emoji support, not the fake image-based support found in WordPress or in other versions of phpBB. Enjoy!
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357

Who is online

Users browsing this forum: No registered users and 0 guests