Merge pull request #3166 from pixelfed/staging

Add custom emoji
This commit is contained in:
daniel 2022-01-21 01:31:43 -07:00 committed by GitHub
commit a9da420b43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 814 additions and 12 deletions

View file

@ -2,6 +2,13 @@
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.2...dev) ## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.2...dev)
### Added
- Custom Emoji ([#3166](https://github.com/pixelfed/pixelfed/pull/3166))
### Metro 2.0 UI
- Added Hovercards ([16ced7b4](https://github.com/pixelfed/pixelfed/commit/16ced7b4))
- Fix word-break on statuses ([16ced7b4](https://github.com/pixelfed/pixelfed/commit/16ced7b4))
### Updated ### Updated
- Updated MediaStorageService, fix remote avatar bug. ([1c20d696](https://github.com/pixelfed/pixelfed/commit/1c20d696)) - Updated MediaStorageService, fix remote avatar bug. ([1c20d696](https://github.com/pixelfed/pixelfed/commit/1c20d696))

View file

@ -14,7 +14,7 @@ use App\{
Story, Story,
User User
}; };
use DB, Cache; use DB, Cache, Storage;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
@ -22,8 +22,10 @@ use App\Http\Controllers\Admin\{
AdminDiscoverController, AdminDiscoverController,
AdminInstanceController, AdminInstanceController,
AdminReportController, AdminReportController,
// AdminGroupsController,
AdminMediaController, AdminMediaController,
AdminSettingsController, AdminSettingsController,
// AdminStorageController,
AdminSupportController, AdminSupportController,
AdminUserController AdminUserController
}; };
@ -31,14 +33,17 @@ use Illuminate\Validation\Rule;
use App\Services\AdminStatsService; use App\Services\AdminStatsService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Services\StoryService; use App\Services\StoryService;
use App\Models\CustomEmoji;
class AdminController extends Controller class AdminController extends Controller
{ {
use AdminReportController, use AdminReportController,
AdminDiscoverController, AdminDiscoverController,
// AdminGroupsController,
AdminMediaController, AdminMediaController,
AdminSettingsController, AdminSettingsController,
AdminInstanceController, AdminInstanceController,
// AdminStorageController,
AdminUserController; AdminUserController;
public function __construct() public function __construct()
@ -343,4 +348,125 @@ class AdminController extends Controller
$stats = StoryService::adminStats(); $stats = StoryService::adminStats();
return view('admin.stories.home', compact('stories', 'stats')); return view('admin.stories.home', compact('stories', 'stats'));
} }
public function customEmojiHome(Request $request)
{
if(!config('federation.custom_emoji.enabled')) {
return view('admin.custom-emoji.not-enabled');
}
$this->validate($request, [
'sort' => 'sometimes|in:all,local,remote,duplicates,disabled,search'
]);
if($request->has('cc')) {
Cache::forget('pf:admin:custom_emoji:stats');
return redirect(route('admin.custom-emoji'));
}
$sort = $request->input('sort') ?? 'all';
if($sort == 'search' && empty($request->input('q'))) {
return redirect(route('admin.custom-emoji'));
}
$emojis = CustomEmoji::when($sort, function($query, $sort) use($request) {
if($sort == 'all') {
return $query->groupBy('shortcode')->latest();
} else if($sort == 'local') {
return $query->latest()->where('domain', '=', config('pixelfed.domain.app'));
} else if($sort == 'remote') {
return $query->latest()->where('domain', '!=', config('pixelfed.domain.app'));
} else if($sort == 'duplicates') {
return $query->latest()->groupBy('shortcode')->havingRaw('count(*) > 1');
} else if($sort == 'disabled') {
return $query->latest()->whereDisabled(true);
} else if($sort == 'search') {
$q = $query
->latest()
->where('shortcode', 'like', '%' . $request->input('q') . '%')
->orWhere('domain', 'like', '%' . $request->input('q') . '%');
if(!$request->has('dups')) {
$q = $q->groupBy('shortcode');
}
return $q;
}
})
->simplePaginate(10)
->withQueryString();
$stats = Cache::remember('pf:admin:custom_emoji:stats', 43200, function() {
return [
'total' => CustomEmoji::count(),
'active' => CustomEmoji::whereDisabled(false)->count(),
'remote' => CustomEmoji::where('domain', '!=', config('pixelfed.domain.app'))->count(),
'duplicate' => CustomEmoji::groupBy('shortcode')->havingRaw('count(*) > 1')->count()
];
});
return view('admin.custom-emoji.home', compact('emojis', 'sort', 'stats'));
}
public function customEmojiToggleActive(Request $request, $id)
{
abort_unless(config('federation.custom_emoji.enabled'), 404);
$emoji = CustomEmoji::findOrFail($id);
$emoji->disabled = !$emoji->disabled;
$emoji->save();
$key = CustomEmoji::CACHE_KEY . str_replace(':', '', $emoji->shortcode);
Cache::forget($key);
return redirect()->back();
}
public function customEmojiAdd(Request $request)
{
abort_unless(config('federation.custom_emoji.enabled'), 404);
return view('admin.custom-emoji.add');
}
public function customEmojiStore(Request $request)
{
abort_unless(config('federation.custom_emoji.enabled'), 404);
$this->validate($request, [
'shortcode' => [
'required',
'min:3',
'max:80',
'starts_with::',
'ends_with::',
Rule::unique('custom_emoji')->where(function ($query) use($request) {
return $query->whereDomain(config('pixelfed.domain.app'))
->whereShortcode($request->input('shortcode'));
})
],
'emoji' => 'required|file|mimes:jpg,png|max:' . (config('federation.custom_emoji.max_size') / 1000)
]);
$emoji = new CustomEmoji;
$emoji->shortcode = $request->input('shortcode');
$emoji->domain = config('pixelfed.domain.app');
$emoji->save();
$fileName = $emoji->id . '.' . $request->emoji->extension();
$request->emoji->storeAs('public/emoji', $fileName);
$emoji->media_path = 'emoji/' . $fileName;
$emoji->save();
return redirect(route('admin.custom-emoji'));
}
public function customEmojiDelete(Request $request, $id)
{
abort_unless(config('federation.custom_emoji.enabled'), 404);
$emoji = CustomEmoji::findOrFail($id);
Storage::delete("public/{$emoji->media_path}");
$emoji->delete();
return redirect(route('admin.custom-emoji'));
}
public function customEmojiShowDuplicates(Request $request, $id)
{
abort_unless(config('federation.custom_emoji.enabled'), 404);
$emoji = CustomEmoji::orderBy('id')->whereDisabled(false)->whereShortcode($id)->firstOrFail();
$emojis = CustomEmoji::whereShortcode($id)->where('id', '!=', $emoji->id)->cursorPaginate(10);
return view('admin.custom-emoji.duplicates', compact('emoji', 'emojis'));
}
} }

View file

@ -0,0 +1,51 @@
<?php
namespace App\Jobs\StatusPipeline;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Services\CustomEmojiService;
use App\Services\StatusService;
class StatusTagsPipeline implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $activity;
protected $status;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($activity, $status)
{
$this->activity = $activity;
$this->status = $status;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$res = $this->activity;
collect($res['tag'])
->filter(function($tag) {
// todo: finish hashtag + mention import
// return in_array($tag['type'], ['Emoji', 'Hashtag', 'Mention']);
return $tag && $tag['type'] == 'Emoji';
})
->map(function($tag) {
CustomEmojiService::import($tag['id'], $this->status->id);
});
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class CustomEmoji extends Model
{
use HasFactory;
const SCAN_RE = "/(?<=[^[:alnum:]:]|\n|^):([a-zA-Z0-9_]{2,}):(?=[^[:alnum:]:]|$)/x";
const CACHE_KEY = "pf:custom_emoji:";
public static function scan($text, $activitypub = false)
{
if(config('federation.custom_emoji.enabled') == false) {
return [];
}
return Str::of($text)
->matchAll(self::SCAN_RE)
->map(function($match) use($activitypub) {
$tag = Cache::remember(self::CACHE_KEY . $match, 14400, function() use($match) {
return self::orderBy('id')->whereDisabled(false)->whereShortcode(':' . $match . ':')->first();
});
if($tag) {
$url = url('/storage/' . $tag->media_path);
if($activitypub == true) {
$mediaType = Str::endsWith($url, '.png') ? 'image/png' : 'image/jpeg';
return [
'id' => url('emojis/' . $tag->id),
'type' => 'Emoji',
'name' => $tag->shortcode,
'updated' => $tag->updated_at->toAtomString(),
'icon' => [
'type' => 'Image',
'mediaType' => $mediaType,
'url' => $url
]
];
} else {
return [
'shortcode' => $match,
'url' => $url,
'static_path' => $url,
'visible_in_picker' => $tag->disabled == false
];
}
}
})
->filter(function($tag) use($activitypub) {
if($activitypub == true) {
return $tag && isset($tag['icon']);
} else {
return $tag && isset($tag['static_path']);
}
})
->values()
->toArray();
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace App\Services;
use App\Models\CustomEmoji;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Cache;
class CustomEmojiService
{
public static function get($shortcode)
{
if(config('federation.custom_emoji.enabled') == false) {
return;
}
return CustomEmoji::whereShortcode($shortcode)->first();
}
public static function import($url, $id = false)
{
if(config('federation.custom_emoji.enabled') == false) {
return;
}
if(Helpers::validateUrl($url) == false) {
return;
}
$emoji = CustomEmoji::whereUri($url)->first();
if($emoji) {
return;
}
$res = Http::acceptJson()->get($url);
if($res->successful()) {
$json = $res->json();
if(
!$json ||
!isset($json['id']) ||
!isset($json['type']) ||
$json['type'] !== 'Emoji' ||
!isset($json['icon']) ||
!isset($json['icon']['mediaType']) ||
!isset($json['icon']['url']) ||
!isset($json['icon']['type']) ||
$json['icon']['type'] !== 'Image' ||
!in_array($json['icon']['mediaType'], ['image/jpeg', 'image/png', 'image/jpg'])
) {
return;
}
if(!self::headCheck($json['icon']['url'])) {
return;
}
$emoji = new CustomEmoji;
$emoji->shortcode = $json['name'];
$emoji->uri = $json['id'];
$emoji->domain = parse_url($json['id'], PHP_URL_HOST);
$emoji->image_remote_url = $json['icon']['url'];
$emoji->save();
$ext = '.' . last(explode('/', $json['icon']['mediaType']));
$dest = storage_path('app/public/emoji/') . $emoji->id . $ext;
copy($emoji->image_remote_url, $dest);
$emoji->media_path = 'emoji/' . $emoji->id . $ext;
$emoji->save();
$name = str_replace(':', '', $json['name']);
Cache::forget('pf:custom_emoji:' . $name);
if($id) {
StatusService::del($id);
}
return;
} else {
return;
}
}
public static function headCheck($url)
{
$res = Http::head($url);
if(!$res->successful()) {
return false;
}
$type = $res->header('content-type');
$length = $res->header('content-length');
if(
!$type ||
!$length ||
!in_array($type, ['image/jpeg', 'image/png', 'image/jpg']) ||
$length > config('federation.custom_emoji.max_size')
) {
return false;
}
return true;
}
}

View file

@ -4,13 +4,13 @@ namespace App\Transformer\ActivityPub\Verb;
use App\Status; use App\Status;
use League\Fractal; use League\Fractal;
use App\Models\CustomEmoji;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class CreateNote extends Fractal\TransformerAbstract class CreateNote extends Fractal\TransformerAbstract
{ {
public function transform(Status $status) public function transform(Status $status)
{ {
$mentions = $status->mentions->map(function ($mention) { $mentions = $status->mentions->map(function ($mention) {
$webfinger = $mention->emailUrl(); $webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
@ -46,7 +46,10 @@ class CreateNote extends Fractal\TransformerAbstract
'name' => "#{$hashtag->name}", 'name' => "#{$hashtag->name}",
]; ];
})->toArray(); })->toArray();
$tags = array_merge($mentions, $hashtags);
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags);
return [ return [
'@context' => [ '@context' => [

View file

@ -4,6 +4,7 @@ namespace App\Transformer\ActivityPub\Verb;
use App\Status; use App\Status;
use League\Fractal; use League\Fractal;
use App\Models\CustomEmoji;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class Note extends Fractal\TransformerAbstract class Note extends Fractal\TransformerAbstract
@ -46,7 +47,10 @@ class Note extends Fractal\TransformerAbstract
'name' => "#{$hashtag->name}", 'name' => "#{$hashtag->name}",
]; ];
})->toArray(); })->toArray();
$tags = array_merge($mentions, $hashtags);
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags);
return [ return [
'@context' => [ '@context' => [

View file

@ -14,6 +14,7 @@ use App\Services\StatusLabelService;
use App\Services\StatusMentionService; use App\Services\StatusMentionService;
use App\Services\ProfileService; use App\Services\ProfileService;
use App\Services\PollService; use App\Services\PollService;
use App\Models\CustomEmoji;
class StatusStatelessTransformer extends Fractal\TransformerAbstract class StatusStatelessTransformer extends Fractal\TransformerAbstract
{ {
@ -25,17 +26,18 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
return [ return [
'_v' => 1, '_v' => 1,
'id' => (string) $status->id, 'id' => (string) $status->id,
//'gid' => $status->group_id ? (string) $status->group_id : null,
'shortcode' => HashidService::encode($status->id), 'shortcode' => HashidService::encode($status->id),
'uri' => $status->url(), 'uri' => $status->url(),
'url' => $status->url(), 'url' => $status->url(),
'in_reply_to_id' => (string) $status->in_reply_to_id, 'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id, 'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
'reblog' => null, 'reblog' => null,
'content' => $status->rendered ?? $status->caption, 'content' => $status->rendered ?? $status->caption,
'content_text' => $status->caption, 'content_text' => $status->caption,
'created_at' => $status->created_at->format('c'), 'created_at' => $status->created_at->format('c'),
'emojis' => [], 'emojis' => CustomEmoji::scan($status->caption),
'reblogs_count' => 0, 'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0, 'favourites_count' => $status->likes_count ?? 0,
'reblogged' => null, 'reblogged' => null,
'favourited' => null, 'favourited' => null,

View file

@ -23,10 +23,12 @@ use App\Jobs\RemoteFollowPipeline\RemoteFollowImportRecent;
use App\Jobs\ImageOptimizePipeline\{ImageOptimize,ImageThumbnail}; use App\Jobs\ImageOptimizePipeline\{ImageOptimize,ImageThumbnail};
use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Jobs\StatusPipeline\StatusReplyPipeline; use App\Jobs\StatusPipeline\StatusReplyPipeline;
use App\Jobs\StatusPipeline\StatusTagsPipeline;
use App\Util\ActivityPub\HttpSignature; use App\Util\ActivityPub\HttpSignature;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Services\ActivityPubFetchService; use App\Services\ActivityPubFetchService;
use App\Services\ActivityPubDeliveryService; use App\Services\ActivityPubDeliveryService;
use App\Services\CustomEmojiService;
use App\Services\InstanceService; use App\Services\InstanceService;
use App\Services\MediaPathService; use App\Services\MediaPathService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
@ -368,7 +370,6 @@ class Helpers {
$cw = true; $cw = true;
} }
$statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']); $statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']);
$status = Cache::lock($statusLockKey) $status = Cache::lock($statusLockKey)
->get(function () use( ->get(function () use(
@ -381,6 +382,7 @@ class Helpers {
$scope, $scope,
$id $id
) { ) {
if($res['type'] === 'Question') { if($res['type'] === 'Question') {
$status = self::storePoll( $status = self::storePoll(
$profile, $profile,
@ -416,6 +418,10 @@ class Helpers {
} else { } else {
StatusReplyPipeline::dispatch($status); StatusReplyPipeline::dispatch($status);
} }
if(isset($res['tag']) && is_array($res['tag']) && !empty($res['tag'])) {
StatusTagsPipeline::dispatch($res, $status);
}
return $status; return $status;
}); });
}); });

View file

@ -157,6 +157,8 @@ class RestrictedNames
'embed', 'embed',
'email', 'email',
'emails', 'emails',
'emoji',
'emojis',
'error', 'error',
'explore', 'explore',
'export', 'export',

View file

@ -44,6 +44,13 @@ return [
'enabled' => env('WEBFINGER', true) 'enabled' => env('WEBFINGER', true)
], ],
'network_timeline' => env('PF_NETWORK_TIMELINE', true) 'network_timeline' => env('PF_NETWORK_TIMELINE', true),
'custom_emoji' => [
'enabled' => env('CUSTOM_EMOJI', false),
// max size in bytes, default is 2mb
'max_size' => env('CUSTOM_EMOJI_MAX_SIZE', 2000000),
]
]; ];

View file

@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomEmojiTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('custom_emoji', function (Blueprint $table) {
$table->id();
$table->string('shortcode')->index();
$table->string('media_path')->nullable();
$table->string('domain')->nullable()->index();
$table->boolean('disabled')->default(false)->index();
$table->string('uri')->nullable();
$table->string('image_remote_url')->nullable();
$table->unsignedInteger('category_id')->nullable();
$table->unique(['shortcode', 'domain']);
$table->timestamps();
});
Schema::create('custom_emoji_categories', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->boolean('disabled')->default(false)->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('custom_emoji');
Schema::dropIfExists('custom_emoji_categories');
}
}

BIN
public/js/spa.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,63 @@
@extends('admin.partial.template-full')
@section('section')
</div>
<div class="header bg-primary pb-3 mt-n4">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<p class="display-1 text-white d-inline-block mb-0">Add Custom Emoji</p>
</div>
</div>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-6">
@if ($errors->any())
@foreach ($errors->all() as $error)
<div class="alert alert-danger py-2 {{$loop->last?'mb-4':'mb-2'}}">
<p class="mb-0"><i class="far fa-exclamation-triangle mr-2"></i> {{ $error }}</p>
</div>
@endforeach
@endif
<div class="card">
<div class="card-header font-weight-bold">
New Custom Emoji
</div>
<div class="card-body">
<form method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="shortcode" class="font-weight-light">Shortcode</label>
<input class="form-control" id="shortcode" name="shortcode" placeholder=":pixelfed:" required>
<p class="form-text small font-weight-bold">Must start and end with :</p>
</div>
<div class="form-group">
<label for="media" class="font-weight-light">Emoji Image</label>
<input type="file" class="form-control-file" id="media" name="emoji" required>
<p class="form-text font-weight-bold"><span class="small">Must be a <kbd>png</kbd> or <kbd>jpg</kbd> under</span> <span class="badge badge-info filesize" data-filesize="{{config('federation.custom_emoji.max_size')}}"></span></p>
</div>
<hr>
<button class="btn btn-primary btn-block">Add Emoji</button>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript">
$('.filesize').each(function(el, i) {
let size = filesize($(i).data('filesize'));
i.innerText = size;
})
</script>
@endpush

View file

@ -0,0 +1,101 @@
@extends('admin.partial.template-full')
@section('section')
</div>
<div class="header bg-primary pb-3 mt-n4">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<p class="display-1 text-white d-inline-block mb-1">Custom Emoji</p>
<p class="h1 text-white font-weight-light d-inline-block mb-0">Showing duplicates of {{$emoji->shortcode}}</p>
</div>
</div>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-6">
<div class="alert alert-warning py-2 mb-4">
<p class="mb-0">
<i class="far fa-exclamation-triangle mr-2"></i> Duplicate emoji shortcodes can lead to unpredictible results
</p>
<p class="mb-0 small">If you change the primary/in-use emoji, you will need to clear the cache by running the <strong>php artisan cache:clear</strong> command for the changes to take effect immediately.</p>
</div>
<p class="font-weight-bold">In Use</p>
<div class="list-group">
<div class="list-group-item">
<div class="media align-items-center">
<img src="{{url('storage/' . $emoji->media_path)}}" width="40" height="40" class="mr-3">
<div class="media-body">
<p class="font-weight-bold mb-0">{{ $emoji->shortcode }}</p>
<p class="text-muted small mb-0">{{ $emoji->domain }}</p>
</div>
<div class="ml-3 badge badge-info">Added {{$emoji->created_at->diffForHumans(null, true, true)}}</div>
<form
class="form-inline"
action="/i/admin/custom-emoji/toggle-active/{{$emoji->id}}"
method="post">
@csrf
<button
type="submit"
class="ml-3 btn btn-sm {{$emoji->disabled ? 'btn-danger' : 'btn-success'}}">
{{$emoji->disabled ? 'Disabled' : 'Active' }}
</button>
</form>
<button class="btn btn-danger px-2 py-1 ml-3 delete-emoji" data-id="{{$emoji->id}}">
<i class="far fa-trash-alt"></i>
</button>
</div>
</div>
</div>
<hr>
<p class="font-weight-bold">Not used (due to conflicting shortcode)</p>
<div class="list-group">
@foreach($emojis as $emoji)
<div class="list-group-item">
<div class="media align-items-center">
<img src="{{url('storage/' . $emoji->media_path)}}" width="40" height="40" class="mr-3">
<div class="media-body">
<p class="font-weight-bold mb-0">{{ $emoji->shortcode }}</p>
<p class="text-muted small mb-0">{{ $emoji->domain }}</p>
</div>
<div class="ml-3 badge badge-info">Added {{$emoji->created_at->diffForHumans(null, true, true)}}</div>
<form
class="form-inline"
action="/i/admin/custom-emoji/toggle-active/{{$emoji->id}}"
method="post">
@csrf
<button
type="submit"
class="ml-3 btn btn-sm {{$emoji->disabled ? 'btn-danger' : 'btn-success'}}">
{{$emoji->disabled ? 'Disabled' : 'Active' }}
</button>
</form>
<button class="btn btn-danger px-2 py-1 ml-3 delete-emoji" data-id="{{$emoji->id}}">
<i class="far fa-trash-alt"></i>
</button>
</div>
</div>
@endforeach
</div>
<div class="d-flex justify-content-center mt-3">
{{ $emojis->links() }}
</div>
</div>
</div>
</div>
@endsection

View file

@ -0,0 +1,170 @@
@extends('admin.partial.template-full')
@section('section')
</div>
<div class="header bg-primary pb-3 mt-n4">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<p class="display-1 text-white d-inline-block mb-0">Custom Emoji</p>
</div>
</div>
<div class="row">
<div class="col-xl-2 col-md-6">
<div class="mb-3">
<h5 class="text-light text-uppercase mb-0">Total Emoji</h5>
<span class="text-white h2 font-weight-bold mb-0 human-size">{{$stats['total']}}</span>
</div>
</div>
<div class="col-xl-2 col-md-6">
<div class="mb-3">
<h5 class="text-light text-uppercase mb-0">Total Active</h5>
<span class="text-white h2 font-weight-bold mb-0 human-size">{{$stats['active']}}</span>
</div>
</div>
<div class="col-xl-2 col-md-6">
<div class="mb-3">
<h5 class="text-light text-uppercase mb-0">Remote Emoji</h5>
<span class="text-white h2 font-weight-bold mb-0 human-size">{{$stats['remote']}}</span>
</div>
</div>
<div class="col-xl-2 col-md-6">
<div class="mb-3">
<h5 class="text-light text-uppercase mb-0">Duplicate Emoji</h5>
<span class="text-white h2 font-weight-bold mb-0 human-size">{{$stats['duplicate']}}</span>
</div>
</div>
<div class="col-xl-4 col-md-6">
<a
class="btn btn-dark btn-lg px-3 mb-1"
href="/i/admin/custom-emoji/new">
<i class="far fa-plus mr-1"></i>
Add Custom Emoji
</a>
</div>
</div>
<div class="row">
<div class="col-12 mt-2">
<p class="font-weight-light text-white small mb-0">
Stats are cached for 12 hours and may not reflect the latest data.<br /> To refresh the cache and view the most recent data, <a href="/i/admin/custom-emoji/home?cc=1" class="font-weight-bold text-white">click here</a>.
</p>
</div>
</div>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-6">
<form method="get" class="mb-3" id="duplicate-form">
<input type="hidden" name="sort" value="search">
<input class="form-control rounded-pill" name="q" placeholder="Search by shortcode or domain name" value="{{request()->input('q')}}">
@if($sort == 'search')
<div class="custom-control custom-checkbox mt-1">
<input type="checkbox" class="custom-control-input" id="showDuplicate" name="dups" value="1" onclick="document.getElementById('duplicate-form').submit()" {{ request()->has('dups') ? 'checked' : ''}}>
<label class="custom-control-label" for="showDuplicate">Show duplicate results</label>
</div>
@endif
</form>
@if($sort != 'search')
<ul class="nav nav-pills my-3 nav-fill">
<li class="nav-item">
<a class="nav-link {{$sort=='all'?'active':''}}" href="?sort=all">All</a>
</li>
<li class="nav-item">
<a class="nav-link {{$sort=='local'?'active':''}}" href="?sort=local">Local</a>
</li>
<li class="nav-item">
<a class="nav-link {{$sort=='remote'?'active':''}}" href="?sort=remote">Remote</a>
</li>
<li class="nav-item">
<a class="nav-link {{$sort=='duplicates'?'active':''}}" href="?sort=duplicates">Duplicates</a>
</li>
<li class="nav-item">
<a class="nav-link {{$sort=='disabled'?'active':''}}" href="?sort=disabled">Disabled</a>
</li>
</ul>
@endif
@if($sort == 'duplicates')
<div class="alert alert-warning py-2 mt-4">
<p class="mb-0">
<i class="far fa-exclamation-triangle mr-2"></i> Duplicate emoji shortcodes can lead to unpredictible results
</p>
</div>
@endif
<div class="list-group">
@foreach($emojis as $emoji)
<div class="list-group-item">
<div class="media align-items-center">
<img src="{{url('storage/' . $emoji->media_path)}}" width="40" height="40" class="mr-3">
<div class="media-body">
<p class="font-weight-bold mb-0">{{ $emoji->shortcode }}</p>
@if($emoji->domain != config('pixelfed.domain.app'))
<p class="text-muted small mb-0">{{ $emoji->domain }}</p>
@endif
</div>
@if($sort == 'duplicates')
<a
class="btn btn-primary rounded-pill btn-sm px-2 py-1 ml-3"
href="/i/admin/custom-emoji/duplicates/{{$emoji->shortcode}}">
View duplicates
</a>
{{-- <div class="ml-3 badge badge-info">Updated {{$emoji->updated_at->diffForHumans(null, true, true)}}</div> --}}
@else
<div class="ml-3 badge badge-info">Updated {{$emoji->updated_at->diffForHumans(null, true, true)}}</div>
<form
class="form-inline"
action="/i/admin/custom-emoji/toggle-active/{{$emoji->id}}"
method="post">
@csrf
<button
type="submit"
class="ml-3 btn btn-sm {{$emoji->disabled ? 'btn-danger' : 'btn-success'}}">
{{$emoji->disabled ? 'Disabled' : 'Active' }}
</button>
</form>
<button class="btn btn-danger px-2 py-1 ml-3 delete-emoji" data-id="{{$emoji->id}}">
<i class="far fa-trash-alt"></i>
</button>
@endif
</div>
</div>
@endforeach
</div>
<div class="d-flex justify-content-center mt-3">
{{ $emojis->links() }}
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript">
$('.delete-emoji').click(function(i) {
if(!window.confirm('Are you sure you want to delete this custom emoji?')) {
return;
}
let id = i.currentTarget.getAttribute('data-id');
axios.post('/i/admin/custom-emoji/delete/' + id)
.then(res => {
$(i.currentTarget).closest('.list-group-item').remove();
})
});
</script>
@endpush

View file

@ -0,0 +1,24 @@
@extends('admin.partial.template-full')
@section('section')
</div>
<div class="header bg-primary pb-3 mt-n4">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<p class="display-1 text-white d-inline-block mb-0">Custom Emoji</p>
</div>
</div>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-6">
<h1 class="text-center">This feature is not enabled</h1>
<p class="text-center">To enable this feature, set <code>CUSTOM_EMOJI=true</code> in<br /> your .env file and run <code>php artisan config:cache</code></p>
</div>
</div>
</div>
@endsection

View file

@ -1,7 +1,7 @@
<nav class="sidenav navbar navbar-vertical fixed-left navbar-expand-xs navbar-light bg-white" id="sidenav-main"> <nav class="sidenav navbar navbar-vertical fixed-left navbar-expand-xs navbar-light bg-white" id="sidenav-main">
<div class="scrollbar-inner"> <div class="scrollbar-inner">
<div class="sidenav-header align-items-center"> <div class="sidenav-header align-items-center">
<a class="navbar-brand" href="/"> <a class="navbar-brand" href="/i/web">
<img src="/img/pixelfed-icon-color.svg" class="navbar-brand-img"> <img src="/img/pixelfed-icon-color.svg" class="navbar-brand-img">
</a> </a>
</div> </div>
@ -69,6 +69,13 @@
</a> </a>
</li> </li>
<li class="nav-item">
<a class="nav-link {{request()->is('*custom-emoji*')?'active':''}}" href="{{route('admin.custom-emoji')}}">
<i class="ni ni-bold-right text-primary"></i>
<span class="nav-link-text">Custom Emoji <span class="badge badge-primary ml-1">NEW</span></span>
</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {{request()->is('*diagnostics*')?'active':''}}" href="{{route('admin.diagnostics')}}"> <a class="nav-link {{request()->is('*diagnostics*')?'active':''}}" href="{{route('admin.diagnostics')}}">
<i class="ni ni-bold-right text-primary"></i> <i class="ni ni-bold-right text-primary"></i>
@ -119,7 +126,7 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {{request()->is('*settings/pages')?'active':''}}" href="/i/admin/settings/pages"> <a class="nav-link {{request()->is('*settings/pages*')?'active':''}}" href="/i/admin/settings/pages">
<i class="ni ni-bold-right text-primary"></i> <i class="ni ni-bold-right text-primary"></i>
<span class="nav-link-text">Pages</span> <span class="nav-link-text">Pages</span>
</a> </a>

View file

@ -84,6 +84,12 @@ Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(functio
Route::get('diagnostics/home', 'AdminController@diagnosticsHome')->name('admin.diagnostics'); Route::get('diagnostics/home', 'AdminController@diagnosticsHome')->name('admin.diagnostics');
Route::post('diagnostics/decrypt', 'AdminController@diagnosticsDecrypt')->name('admin.diagnostics.decrypt'); Route::post('diagnostics/decrypt', 'AdminController@diagnosticsDecrypt')->name('admin.diagnostics.decrypt');
Route::get('custom-emoji/home', 'AdminController@customEmojiHome')->name('admin.custom-emoji');
Route::post('custom-emoji/toggle-active/{id}', 'AdminController@customEmojiToggleActive');
Route::get('custom-emoji/new', 'AdminController@customEmojiAdd');
Route::post('custom-emoji/new', 'AdminController@customEmojiStore');
Route::post('custom-emoji/delete/{id}', 'AdminController@customEmojiDelete');
Route::get('custom-emoji/duplicates/{id}', 'AdminController@customEmojiShowDuplicates');
}); });
Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () { Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () {

View file

@ -2,5 +2,6 @@
!.gitignore !.gitignore
!no-preview.png !no-preview.png
!m/ !m/
!emoji/
!textimg/ !textimg/
!headers/ !headers/

2
storage/app/public/emoji/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore