mirror of
https://github.com/friendica/friendica
synced 2024-12-23 09:20:17 +00:00
Merge pull request #3640 from annando/better-smiley-support
Preparation for Unicode Emojis
This commit is contained in:
commit
c9daecb80d
2 changed files with 41 additions and 4 deletions
|
@ -13,6 +13,26 @@ use Friendica\App;
|
||||||
|
|
||||||
class Smilies {
|
class Smilies {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Replaces/adds the emoticon list
|
||||||
|
*
|
||||||
|
* This function should be used whenever emoticons are added
|
||||||
|
*
|
||||||
|
* @param array $b Array of emoticons
|
||||||
|
* @param string $smiley The text smilie
|
||||||
|
* @param string $representation The replacement
|
||||||
|
*/
|
||||||
|
public static function add(&$b, $smiley, $representation) {
|
||||||
|
$found = array_search($smiley, $b['texts']);
|
||||||
|
|
||||||
|
if (!is_int($found)) {
|
||||||
|
$b['texts'][] = $smiley;
|
||||||
|
$b['icons'][] = $representation;
|
||||||
|
} else {
|
||||||
|
$b['icons'][$found] = $representation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function to list all smilies
|
* @brief Function to list all smilies
|
||||||
*
|
*
|
||||||
|
@ -107,7 +127,6 @@ class Smilies {
|
||||||
call_hooks('smilie', $params);
|
call_hooks('smilie', $params);
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,12 +140,13 @@ class Smilies {
|
||||||
* function from being executed by the prepare_text() routine when preparing
|
* function from being executed by the prepare_text() routine when preparing
|
||||||
* bbcode source for HTML display
|
* bbcode source for HTML display
|
||||||
*
|
*
|
||||||
* @param string $s
|
* @param string $s Text that should be replaced
|
||||||
* @param boolean $sample
|
* @param boolean $sample
|
||||||
|
* @param boolean $no_images Only replace emoticons without images
|
||||||
*
|
*
|
||||||
* @return string HML Output of the Smilie
|
* @return string HML Output of the Smilie
|
||||||
*/
|
*/
|
||||||
public static function replace($s, $sample = false) {
|
public static function replace($s, $sample = false, $no_images = false) {
|
||||||
if(intval(get_config('system','no_smilies'))
|
if(intval(get_config('system','no_smilies'))
|
||||||
|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
|
|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
|
||||||
return $s;
|
return $s;
|
||||||
|
@ -135,6 +155,19 @@ class Smilies {
|
||||||
$s = preg_replace_callback('/<code>(.*?)<\/code>/ism','self::encode',$s);
|
$s = preg_replace_callback('/<code>(.*?)<\/code>/ism','self::encode',$s);
|
||||||
|
|
||||||
$params = self::get_list();
|
$params = self::get_list();
|
||||||
|
|
||||||
|
if ($no_images) {
|
||||||
|
$cleaned = array('texts' => array(), 'icons' => array());
|
||||||
|
$icons = $params['icons'];
|
||||||
|
foreach ($icons AS $key => $icon) {
|
||||||
|
if (!strstr($icon, '<img ')) {
|
||||||
|
$cleaned['texts'][] = $params['texts'][$key];
|
||||||
|
$cleaned['icons'][] = $params['icons'][$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$params = $cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
$params['string'] = $s;
|
$params['string'] = $s;
|
||||||
|
|
||||||
if($sample) {
|
if($sample) {
|
||||||
|
@ -180,5 +213,4 @@ class Smilies {
|
||||||
$r = str_replace($x[0],$t,$x[0]);
|
$r = str_replace($x[0],$t,$x[0]);
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ require_once 'include/map.php';
|
||||||
require_once 'mod/proxy.php';
|
require_once 'mod/proxy.php';
|
||||||
require_once 'include/Contact.php';
|
require_once 'include/Contact.php';
|
||||||
require_once 'include/plaintext.php';
|
require_once 'include/plaintext.php';
|
||||||
|
require_once 'include/Smilies.php';
|
||||||
|
|
||||||
function bb_PictureCacheExt($matches) {
|
function bb_PictureCacheExt($matches) {
|
||||||
if (strpos($matches[3], "data:image/") === 0) {
|
if (strpos($matches[3], "data:image/") === 0) {
|
||||||
|
@ -1276,6 +1277,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
||||||
$Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $Text);
|
$Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace non graphical smilies for external posts
|
||||||
|
if ($simplehtml) {
|
||||||
|
$Text = Smilies::replace($Text, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Replace inline code blocks
|
// Replace inline code blocks
|
||||||
$Text = preg_replace_callback("|(?!<br[^>]*>)<code>([^<]*)</code>(?!<br[^>]*>)|ism",
|
$Text = preg_replace_callback("|(?!<br[^>]*>)<code>([^<]*)</code>(?!<br[^>]*>)|ism",
|
||||||
|
|
Loading…
Reference in a new issue