Files
UNIT3D-Community-Edition/app/Http/Resources/ChatMessageResource.php
singularity43 c0319d9feb (Update) ChatMessageResource Resource
Add new array fields.
2019-02-09 15:01:45 -05:00

55 lines
1.8 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author Poppabear
*/
namespace App\Http\Resources;
use App\Helpers\Bbcode;
use Illuminate\Http\Resources\Json\JsonResource;
use ChristofferOK\LaravelEmojiOne\LaravelEmojiOne;
class ChatMessageResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function toArray($request)
{
$emojiOne = app()->make(LaravelEmojiOne::class);
$logger = null;
if($this->user_id && $this->user_id == 1) {
$logger = Bbcode::parse('[div class="align-left"][div class="chatTriggers"]'.clean($this->message).'[/div][/div]');
$logger = $emojiOne->toImage($logger);
$logger = str_replace("a href=\"/#","a trigger=\"bot\" class=\"chatTrigger\" href=\"/#",$logger);
} else {
$logger = Bbcode::parse('[div class="align-left"]'.clean($this->message).'[/div]');
$logger = $emojiOne->toImage($logger);
}
return [
'id' => $this->id,
'bot' => new BotResource($this->whenLoaded('bot')),
'user' => new UserResource($this->whenLoaded('user')),
'receiver' => new UserResource($this->whenLoaded('receiver')),
'chatroom' => new ChatRoomResource($this->whenLoaded('chatroom')),
'message' => htmlspecialchars_decode($logger),
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String(),
];
}
}