-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb0e8fc
commit 863ec3c
Showing
6 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
extensions/emoji/migrations/2018_09_29_060444_replace_emoji_shorcuts_with_unicode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Builder; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
$emojioneToTwemojiMap = [ | ||
'1f468-2764-1f468' => '1f468-200d-2764-fe0f-200d-1f468', | ||
'1f469-2764-1f469' => '1f469-200d-2764-fe0f-200d-1f469', | ||
'1f468-2764-1f48b-1f468' => '1f468-200d-2764-fe0f-200d-1f48b-200d-1f468', | ||
'1f469-2764-1f48b-1f469' => '1f469-200d-2764-fe0f-200d-1f48b-200d-1f469', | ||
'1f468-1f468-1f466' => '1f468-200d-1f468-200d-1f466', | ||
'1f468-1f468-1f466-1f466' => '1f468-200d-1f468-200d-1f466-200d-1f466', | ||
'1f468-1f468-1f467' => '1f468-200d-1f468-200d-1f467', | ||
'1f468-1f468-1f467-1f466' => '1f468-200d-1f468-200d-1f467-200d-1f466', | ||
'1f468-1f468-1f467-1f467' => '1f468-200d-1f468-200d-1f467-200d-1f467', | ||
'1f468-1f469-1f466-1f466' => '1f468-200d-1f469-200d-1f466-200d-1f466', | ||
'1f468-1f469-1f467' => '1f468-200d-1f469-200d-1f467', | ||
'1f468-1f469-1f467-1f466' => '1f468-200d-1f469-200d-1f467-200d-1f466', | ||
'1f468-1f469-1f467-1f467' => '1f468-200d-1f469-200d-1f467-200d-1f467', | ||
'1f469-1f469-1f466' => '1f469-200d-1f469-200d-1f466', | ||
'1f469-1f469-1f466-1f466' => '1f469-200d-1f469-200d-1f466-200d-1f466', | ||
'1f469-1f469-1f467' => '1f469-200d-1f469-200d-1f467', | ||
'1f469-1f469-1f467-1f466' => '1f469-200d-1f469-200d-1f467-200d-1f466', | ||
'1f469-1f469-1f467-1f467' => '1f469-200d-1f469-200d-1f467-200d-1f467', | ||
'1f441-1f5e8' => '1f441-200d-1f5e8', // as always PITA | ||
'1f3f3-1f308' => '1f3f3-fe0f-200d-1f308', | ||
|
||
// https://github.com/twitter/twemoji/issues/192 | ||
'1f91d-1f3fb' => '1f91d', | ||
'1f91d-1f3fc' => '1f91d', | ||
'1f91d-1f3fd' => '1f91d', | ||
'1f91d-1f3fe' => '1f91d', | ||
'1f91d-1f3ff' => '1f91d', | ||
'1f93c-1f3fb' => '1f93c', | ||
'1f93c-1f3fc' => '1f93c', | ||
'1f93c-1f3fd' => '1f93c', | ||
'1f93c-1f3fe' => '1f93c', | ||
'1f93c-1f3ff' => '1f93c', | ||
]; | ||
|
||
$fromCodePoint = function ($code) { | ||
$num = intval($code, 16); | ||
|
||
if ($num <= 0x7F) { | ||
return chr($num); | ||
} | ||
|
||
if ($num <= 0x7FF) { | ||
return chr(($num >> 6) + 192).chr(($num & 63) + 128); | ||
} | ||
|
||
if ($num <= 0xFFFF) { | ||
return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); | ||
} | ||
|
||
return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); | ||
}; | ||
|
||
$convertEmojioneToTwemoji = function ($code) use ($emojioneToTwemojiMap) { | ||
if (isset($emojioneToTwemojiMap[$code])) { | ||
return $emojioneToTwemojiMap[$code]; | ||
} | ||
|
||
return ltrim($code, '0'); | ||
}; | ||
|
||
$posts = $schema->getConnection()->table('posts') | ||
->select('id', 'content') | ||
->where('content', 'like', '%<EMOJI%') | ||
->cursor(); | ||
|
||
foreach ($posts as $post) { | ||
$content = preg_replace_callback( | ||
'/<EMOJI seq="(.+?)">.+?<\/EMOJI>/', | ||
function ($m) use ($convertEmojioneToTwemoji, $fromCodePoint) { | ||
$code = $convertEmojioneToTwemoji($m[1]); | ||
$codepoints = explode('-', $code); | ||
|
||
return implode('', array_map($fromCodePoint, $codepoints)); | ||
}, | ||
$post->content | ||
); | ||
|
||
$schema->getConnection()->table('posts') | ||
->where('id', $post->id) | ||
->update(['content' => $content]); | ||
} | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
// not implemented | ||
} | ||
]; |
31 changes: 31 additions & 0 deletions
31
framework/core/migrations/2018_09_15_041340_add_users_indicies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\Builder; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
$schema->table('users', function (Blueprint $table) { | ||
$table->index('joined_at'); | ||
$table->index('last_seen_at'); | ||
$table->index('discussion_count'); | ||
$table->index('comment_count'); | ||
}); | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
$schema->table('users', function (Blueprint $table) { | ||
$table->dropIndex(['joined_at']); | ||
$table->dropIndex(['last_seen_at']); | ||
$table->dropIndex(['discussion_count']); | ||
$table->dropIndex(['comment_count']); | ||
}); | ||
} | ||
]; |
37 changes: 37 additions & 0 deletions
37
framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\Builder; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
$schema->table('discussions', function (Blueprint $table) { | ||
$table->index('last_posted_at'); | ||
$table->index('last_posted_user_id'); | ||
$table->index('created_at'); | ||
$table->index('user_id'); | ||
$table->index('comment_count'); | ||
$table->index('participant_count'); | ||
$table->index('hidden_at'); | ||
}); | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
$schema->table('discussions', function (Blueprint $table) { | ||
$table->dropIndex(['last_posted_at']); | ||
$table->dropIndex(['last_posted_user_id']); | ||
$table->dropIndex(['created_at']); | ||
$table->dropIndex(['user_id']); | ||
$table->dropIndex(['comment_count']); | ||
$table->dropIndex(['participant_count']); | ||
$table->dropIndex(['hidden_at']); | ||
}); | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters