Browse Source

Integrate the Emoji branch properly under the Movim namespace

Remove heyupdate/emoji
pull/650/head
Timothée Jaussoin 8 years ago
parent
commit
417f80045b
  1. 2
      app/Message.php
  2. 39
      app/helpers/StringHelper.php
  3. 2
      app/widgets/Notifs/Notifs.php
  4. 2
      app/widgets/Post/Post.php
  5. 1
      composer.json
  6. 46
      composer.lock
  7. 2
      src/Movim/Daemon/Api.php
  8. 44
      src/Movim/Emoji.php
  9. 0
      src/Movim/Emoji/CompiledEmoji.php
  10. 2
      src/Movim/Emoji/compile-file-list.sh
  11. 4
      src/Movim/Emoji/replace-test.php
  12. 2
      src/Movim/Emoji/test-all-images.sh

2
app/Message.php

@ -259,7 +259,7 @@ class Message extends Model
public function convertEmojis()
{
$emoji = \MovimEmoji::getInstance();
$emoji = \Movim\Emoji::getInstance();
$this->body = addHFR($emoji->replace($this->body));
}

39
app/helpers/StringHelper.php

@ -1,47 +1,8 @@
<?php
use HeyUpdate\Emoji\Emoji;
use HeyUpdate\Emoji\Index\CompiledIndex;
use Movim\Route;
use App\Configuration;
/**
* @desc A singleton wrapper for the Emoji library
*/
class MovimEmoji
{
protected static $instance = null;
private $_emoji;
private $_theme;
protected function __construct()
{
$this->_theme = Configuration::findOrNew(1)->theme;
$this->_emoji = new Emoji(new CompiledIndex, $this->getPath());
}
public function replace($string)
{
$this->_emoji->setImageHtmlTemplate('<img alt="{{name}}" class="emoji" src="'.$this->getPath().'">');
$string = $this->_emoji->replaceEmojiWithImages($string);
return $string;
}
private function getPath()
{
return BASE_URI . 'themes/' . $this->_theme . '/img/emojis/svg/{{unicode}}.svg';
}
public static function getInstance()
{
if (!isset(static::$instance)) {
static::$instance = new MovimEmoji;
}
return static::$instance;
}
}
function addUrls($string, $preview = false)
{
// Add missing links

2
app/widgets/Notifs/Notifs.php

@ -26,7 +26,7 @@ class Notifs extends \Movim\Widget\Base
if (!$since) $since = date(SQL_DATE, 0);
$emoji = \MovimEmoji::getInstance();
$emoji = \Movim\Emoji::getInstance();
$notifs = \App\Post::whereIn('parent_id', function ($query) use ($since) {
$query->select('id')

2
app/widgets/Post/Post.php

@ -160,7 +160,7 @@ class Post extends \Movim\Widget\Base
public function prepareComments(\App\Post $post, $public = false)
{
$emoji = \MovimEmoji::getInstance();
$emoji = \Movim\Emoji::getInstance();
$view = $this->tpl();
$view->assign('post', $post);
$view->assign('public', $public);

1
composer.json

@ -20,7 +20,6 @@
"movim/moxl": "dev-master#7fa3206eaeb66b0afdabe319fad058a6385df848",
"embed/embed": "^v3.3",
"heyupdate/emoji": "dev-twemoji2#99dda1bed08472046cac1498221f08684ad83d55",
"respect/validation": "^1.1",
"ezyang/htmlpurifier": "^4.9",

46
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "eee8dd24078730a53b48b0d17aa538c7",
"content-hash": "fc899f6493cd93a21f33cff7686bfb61",
"packages": [
{
"name": "cboden/ratchet",
@ -1039,47 +1039,6 @@
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "heyupdate/emoji",
"version": "dev-twemoji2",
"source": {
"type": "git",
"url": "https://github.com/heyupdate/emoji.git",
"reference": "99dda1bed08472046cac1498221f08684ad83d55"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/heyupdate/emoji/zipball/99dda1bed08472046cac1498221f08684ad83d55",
"reference": "99dda1bed08472046cac1498221f08684ad83d55",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"HeyUpdate\\Emoji\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Convert unicode and named (i.e. :smile:) Emoji into images",
"keywords": [
"emoji"
],
"time": "2016-11-15 20:35:47"
},
{
"name": "illuminate/container",
"version": "v5.5.40",
@ -3118,8 +3077,7 @@
"minimum-stability": "stable",
"stability-flags": {
"rain/raintpl": 20,
"movim/moxl": 20,
"heyupdate/emoji": 20
"movim/moxl": 20
},
"prefer-stable": false,
"prefer-lowest": false,

2
src/Movim/Daemon/Api.php

@ -166,7 +166,7 @@ class Api
{
$string = $post['string'];
$emoji = \MovimEmoji::getInstance();
$emoji = \Movim\Emoji::getInstance();
return $emoji->replace($string);
}
}

44
emoji/MovimEmoji.php → src/Movim/Emoji.php

@ -1,7 +1,7 @@
<?php
/*-
* Copyright © 2018
* mirabilos <thorsten.glaser@teckids.org>
* mirabilos <thorsten.glaser@teckids.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
@ -19,13 +19,12 @@
* of said person’s immediate fault when using the work as intended.
*/
class MovimEmoji
namespace Movim;
class Emoji
{
protected static $instance = null;
private $_emoji;
private $_urlp1;
private $_urlp2;
private $_urlp3;
private $_regex = [
/* some easy cases first */
'/[#*0-9]\x{20E3}
@ -58,35 +57,42 @@ class MovimEmoji
protected function __construct()
{
$this->_emoji = require('CompiledEmoji.php');
$this->_urlp1 = '<img alt="';
$this->_urlp2 = '" class="emoji" src="' .
BASE_URI . 'themes/' . Configuration::findOrNew(1)->theme .
'/img/emojis/svg/';
$this->_urlp3 = '.svg" />';
$this->_emoji = require('Emoji/CompiledEmoji.php');
}
public function replace($string)
{
return preg_replace_callback($this->_regex, function ($matches) {
$astext = implode('-', array_map('dechex', unpack('N*',
mb_convert_encoding($matches[0], 'UCS-4BE', 'UTF-8'))));
/* do we know this character? */
$astext = implode('-',
array_map('dechex',
unpack('N*', mb_convert_encoding($matches[0], 'UCS-4BE', 'UTF-8'))
)
);
/* Do we know this character? */
if (!isset($this->_emoji[$astext])) {
/* no, return match unchanged */
/* No, return match unchanged */
return $matches[0];
}
/* yes, replace */
return $this->_urlp1 . $this->_emoji[$astext] . $this->_urlp2 .
$astext . $this->_urlp3;
/* Yes, replace */
return '<img
alt="' . $this->_emoji[$astext] . '"
class="emoji"
src="' .
BASE_URI .
'themes/' .
\App\Configuration::findOrNew(1)->theme .
'/img/emojis/svg/' .
$astext .
'.svg" />';
}, $string);
}
public static function getInstance()
{
if (!isset(static::$instance)) {
static::$instance = new MovimEmoji;
static::$instance = new Emoji;
}
return static::$instance;

0
emoji/CompiledEmoji.php → src/Movim/Emoji/CompiledEmoji.php

2
emoji/compile-file-list.sh → src/Movim/Emoji/compile-file-list.sh

@ -21,7 +21,7 @@
# Needs the Debian packages mksh and unicode-data installed.
cd "$(dirname "$0")"
srcpath=../themes/material/img/emojis/svg
srcpath=../../../themes/material/img/emojis/svg
cd "$srcpath"
set -A files -- *.svg

4
emoji/replace-test.php → src/Movim/Emoji/replace-test.php

@ -13,7 +13,7 @@ class Configuration
}
}
require_once 'MovimEmoji.php';
require_once '../Emoji.php';
$text = file_get_contents('php://stdin');
echo MovimEmoji::getInstance()->replace($text);
echo Emoji::getInstance()->replace($text);

2
emoji/test-all-images.sh → src/Movim/Emoji/test-all-images.sh

@ -19,7 +19,7 @@
# of said person’s immediate fault when using the work as intended.
cd "$(dirname "$0")"
srcpath=../themes/material/img/emojis/svg
srcpath=../../../themes/material/img/emojis/svg
saveIFS=$IFS
cd "$srcpath"
Loading…
Cancel
Save