test better emoji removal

This commit is contained in:
2017-09-09 10:32:46 +10:00
parent c3f0f191f3
commit 895b3b80e6
2 changed files with 36 additions and 5 deletions

View File

@@ -345,6 +345,16 @@ function booking_admin() {
'#options' => array(0 => t('No'), t('Yes')),
'#default_value' => variable_get('booking_studygroup_csv_ages', 0),
);
$form['features']['booking_enable_emoji_removal'] = array(
'#type' => 'radios',
'#title' => t('Remove emoji from user input?'),
'#description' => t('Select whether to strip emoji from user input before saving to database. Useful if mysql does not support utf8mb4.'),
'#options' => array(
0 => t('No'),
t('Yes')
),
'#default_value' => variable_get('booking_enable_emoji_removal', 1)
);
$form['misc'] = array(
'#type' => 'fieldset',
'#title' => 'Configuration Options'

View File

@@ -5,12 +5,32 @@
* from https://stackoverflow.com/a/41831874/7638834
*/
function _booking_remove_emoji($text){
// Taken from https://www.drupal.org/node/2043439#comment-8213973 but doesn't seem to work
//return preg_replace('/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F6FF}][\x{FE00}-\x{FEFF}]?/u', '', $text);
//this one seems to work ok
$clean_text = "";
/*
return preg_replace('/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|
\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|
[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|
[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|
[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F6FF}][\x{FE00}-\x{FEFF}]?/u', '', $text);
*/
//don't try to strip emojis if that feature is disabled
if (variable_get('booking_enable_emoji_removal', 1) == 0) {
return $text;
}
else {
return preg_replace(
'/[\x{1F600}-\x{1F64F}]|' .
'[\x{1F300}-\x{1F5FF}]|' .
'[\x{1F680}-\x{1F6FF}]|' .
'[\x{2600}-\x{26FF}]|' .
'[\x{2700}-\x{27BF}]|' .
'[\x{1F1E6}-\x{1F1FF}]|' .
'[\x{1F910}-\x{1F95E}]|' .
'[\x{1F980}-\x{1F991}]|' .
'[\x{1F9C0}]|' .
'[\x{1F9F9}]/u', '', $text);
}
/*
// Match Emoticons
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
$clean_text = preg_replace($regexEmoticons, '', $text);
@@ -49,6 +69,7 @@ function _booking_remove_emoji($text){
$clean_text = preg_replace($regexDingbats, '', $clean_text);
return $clean_text;
*/
}