Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeloc committed Jan 26, 2024
1 parent bb6ea2a commit c92a304
Show file tree
Hide file tree
Showing 20 changed files with 3,461 additions and 12 deletions.
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
### 1.0.2
- Possible fix for the blank settings page.

### 1.0.1
- Use TextFormatter's `Emoticons` plugin insteag of `Preg`.

### 1.0.0
- First release.
- First release.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Simple emoji manager for Flarum.

Screenshots:

<img width="709" alt="3" src="https://github.com/nodeloc/flarum-ext-my-emoji/assets/149086144/7f7d0129-0a12-4239-92b8-597acd0a2914">

<img width="311" alt="4" src="https://github.com/nodeloc/flarum-ext-my-emoji/assets/149086144/27e4ad8a-1d3f-4bc5-99ca-c3b4871d344a">
![Picker](https://i.imgur.com/I7l1s6O.png)

- [Settings](https://i.imgur.com/hqlbvZB.png)
- [Edit Emoji Modal](https://i.imgur.com/nonfIjB.png)

## Features

Expand Down
2 changes: 0 additions & 2 deletions js/src/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { extend, override } from 'flarum/common/extend';

import app from 'flarum/common/app';
import AdminPage from 'flarum/admin/components/AdminPage';
import CustomEmojiListState from './states/CustomEmojiListState';
import CustomEmojiSection from './components/CustomEmojiSection';
import Emoji from '../common/models/Emoji';
import ExtensionPage from 'flarum/admin/components/ExtensionPage';
import Stream from 'flarum/common/utils/Stream';

app.initializers.add('nodeloc-flarum-ext-my-emoji', (app) => {
app.store.models.myemoji = Emoji;
Expand Down
2,885 changes: 2,885 additions & 0 deletions js/yarn.lock

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions src/Api/Controllers/CreateEmojiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Nodeloc\MyEmoji\Api\Controllers;

use Flarum\Api\Controller\AbstractCreateController;
use Nodeloc\MyEmoji\Api\Serializers\EmojiSerializer;
use Nodeloc\MyEmoji\Commands\CreateEmoji;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

class CreateEmojiController extends AbstractCreateController
{
/**
* {@inheritdoc}
*/
public $serializer = EmojiSerializer::class;

/**
* @var Dispatcher
*/
protected $bus;

/**
* @param Dispatcher $bus
*/
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
}

/**
* {@inheritdoc}
*/
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new CreateEmoji(Arr::get($request->getParsedBody(), 'data', []))
);
}
}
35 changes: 35 additions & 0 deletions src/Api/Controllers/DeleteEmojiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Nodeloc\MyEmoji\Api\Controllers;

use Flarum\Api\Controller\AbstractDeleteController;
use Nodeloc\MyEmoji\Commands\DeleteEmoji;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;

class DeleteEmojiController extends AbstractDeleteController
{
/**
* @var Dispatcher
*/
protected $bus;

/**
* @param Dispatcher $bus
*/
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
}

/**
* {@inheritdoc}
*/
protected function delete(ServerRequestInterface $request)
{
$this->bus->dispatch(
new DeleteEmoji(Arr::get($request->getQueryParams(), 'id'))
);
}
}
42 changes: 42 additions & 0 deletions src/Api/Controllers/ImportEmojiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Nodeloc\MyEmoji\Api\Controllers;

use Flarum\Api\Controller\AbstractCreateController;
use Nodeloc\MyEmoji\Api\Serializers\EmojiSerializer;
use Nodeloc\MyEmoji\Commands\ImportEmoji;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

class ImportEmojiController extends AbstractCreateController
{
/**
* {@inheritdoc}
*/
public $serializer = EmojiSerializer::class;

/**
* @var Dispatcher
*/
protected $bus;

/**
* @param Dispatcher $bus
*/
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
}

/**
* {@inheritdoc}
*/
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new ImportEmoji(Arr::get($request->getParsedBody(), 'data', []))
);
}
}
71 changes: 71 additions & 0 deletions src/Api/Controllers/ListEmojisController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Nodeloc\MyEmoji\Api\Controllers;

use Flarum\Api\Controller\AbstractListController;
use Flarum\Http\UrlGenerator;
use Nodeloc\MyEmoji\Api\Serializers\EmojiSerializer;
use Nodeloc\MyEmoji\Models\Emoji;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

class ListEmojisController extends AbstractListController
{
/**
* {@inheritdoc}
*/
public $serializer = EmojiSerializer::class;

public $sortFields = ['id'];

/**
* @var UrlGenerator
*/
protected $url;

public function __construct(UrlGenerator $url)
{
$this->url = $url;
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Tobscure\JsonApi\Document $document
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$params = $request->getQueryParams();

$limit = $this->extractLimit($request);

// This is a trick to be able to retrieve all
// myemoji from the db. We need them to create a JSON file to export.
// -- need to think a better way to do this.
if ($limit == $this->limit) {
return Emoji::all();
}

$offset = $this->extractOffset($request);

$results = Emoji::skip($offset)->take($limit + 1)->orderBy('id', 'desc')->get();

// Check for more results
$hasMoreResults = $limit > 0 && $results->count() > $limit;

// Pop
if ($hasMoreResults) {
$results->pop();
}

// Add pagination to the request
$document->addPaginationLinks(
$this->url->to('api')->route('myemoji.list'),
$params,
$offset,
$limit,
$hasMoreResults ? null : 0
);

return $results;
}
}
45 changes: 45 additions & 0 deletions src/Api/Controllers/UpdateEmojiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Nodeloc\MyEmoji\Api\Controllers;

use Flarum\Api\Controller\AbstractShowController;
use Nodeloc\MyEmoji\Api\Serializers\EmojiSerializer;
use Nodeloc\MyEmoji\Commands\EditEmoji;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

class UpdateEmojiController extends AbstractShowController
{
/**
* {@inheritdoc}
*/
public $serializer = EmojiSerializer::class;

/**
* @var Dispatcher
*/
protected $bus;

/**
* @param Dispatcher $bus
*/
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
}

/**
* {@inheritdoc}
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$id = Arr::get($request->getQueryParams(), 'id');
$data = Arr::get($request->getParsedBody(), 'data', []);

return $this->bus->dispatch(
new EditEmoji($id, $data)
);
}
}
29 changes: 29 additions & 0 deletions src/Api/Serializers/EmojiSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Nodeloc\MyEmoji\Api\Serializers;

use Flarum\Api\Serializer\AbstractSerializer;
use Nodeloc\MyEmoji\Models\Emoji;

class EmojiSerializer extends AbstractSerializer
{
protected $type = 'myemoji';

/**
* Get the default set of serialized attributes for a model.
*
* @param Emoji $model
*
* @return array
*/
protected function getDefaultAttributes($model)
{
return [
'title' => $model->title,
'text_to_replace' => $model->text_to_replace,
'path' => $model->path,
'category' => $model->category,
'category_name' => $model->category_name,
];
}
}
21 changes: 21 additions & 0 deletions src/Commands/CreateEmoji.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Nodeloc\MyEmoji\Commands;

class CreateEmoji
{
/**
* The attributes of the new emoji.
*
* @var array
*/
public $data;

/**
* @param array $data The attributes of the new emoji.
*/
public function __construct(array $data)
{
$this->data = $data;
}
}
30 changes: 30 additions & 0 deletions src/Commands/CreateEmojiHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Nodeloc\MyEmoji\Commands;

use Nodeloc\MyEmoji\Models\Emoji;
use Illuminate\Support\Arr;

class CreateEmojiHandler
{
/**
* @param CreateEmoji $command
* @return Emoji
*/
public function handle(CreateEmoji $command)
{
$data = $command->data;

$emoji = Emoji::build(
Arr::get($data, 'attributes.category'),
Arr::get($data, 'attributes.category_name'),
Arr::get($data, 'attributes.title'),
Arr::get($data, 'attributes.textToReplace'),
Arr::get($data, 'attributes.path')
);

$emoji->save();

return $emoji;
}
}
21 changes: 21 additions & 0 deletions src/Commands/DeleteEmoji.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Nodeloc\MyEmoji\Commands;

class DeleteEmoji
{
/**
* The ID of the emoji to delete.
*
* @var int
*/
public $emojiId;

/**
* @param int $tagId The ID of the emoji to delete.
*/
public function __construct($tagId)
{
$this->tagId = $tagId;
}
}
Loading

0 comments on commit c92a304

Please sign in to comment.