-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
20 changed files
with
3,461 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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. |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,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', [])) | ||
); | ||
} | ||
} |
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,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')) | ||
); | ||
} | ||
} |
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,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', [])) | ||
); | ||
} | ||
} |
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,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; | ||
} | ||
} |
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,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) | ||
); | ||
} | ||
} |
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,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, | ||
]; | ||
} | ||
} |
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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.