parse url and mails on messages
This commit is contained in:
parent
7909856b9d
commit
6277142a8d
4 changed files with 43 additions and 11 deletions
1
IDEAS.md
1
IDEAS.md
|
|
@ -1,3 +1,4 @@
|
|||
- Permettre à un user de suivre un projet
|
||||
- permettre d'insérer des @user dans le texte avec lien vers user
|
||||
- permettre de modifier son mot de passe ? (je crois que ça n'as pas été mis exprès)
|
||||
- ~~parser les liens http~~
|
||||
|
|
|
|||
29
app/Lib/Utils.php
Normal file
29
app/Lib/Utils.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
class Utils
|
||||
{
|
||||
public static function plainToHtml(string $text)
|
||||
{
|
||||
$text = e($text);
|
||||
// url replace and email replace
|
||||
$text = preg_replace_callback(
|
||||
'/([^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/',
|
||||
function ($matches) {
|
||||
$match = collect($matches)->first() ?? '';
|
||||
if (filter_var($match, FILTER_VALIDATE_EMAIL)) {
|
||||
return strlen($match) ? "<a href=\"mailto:$match\">$match</a>" : $match;
|
||||
} else {
|
||||
$url = $match;
|
||||
if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {
|
||||
$url = sprintf('http://%s', $url);
|
||||
}
|
||||
return strlen($match) ? "<a href=\"$url\" target=\"_blank\">$match</a>" : $match;
|
||||
}
|
||||
},
|
||||
$text
|
||||
);
|
||||
return nl2br($text);
|
||||
}
|
||||
}
|
||||
|
|
@ -227,7 +227,8 @@ return [
|
|||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||
'View' => Illuminate\Support\Facades\View::class,
|
||||
'TicketType' => App\Enums\TicketType::class,
|
||||
'TicketStatus' => App\Enums\TicketStatus::class
|
||||
'TicketStatus' => App\Enums\TicketStatus::class,
|
||||
'Utils' => App\Lib\Utils::class
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -96,22 +96,23 @@
|
|||
@foreach ($messages as $message)
|
||||
@if ($message->user_id === null)
|
||||
<div class="offset-md-3 col-md-6 alert alert-secondary text-center">
|
||||
{!! nl2br(e($message->message)) !!} - Le {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i')}} <small class="text-muted">(Message système)</small>
|
||||
{!! nl2br(e($message->message)) !!} - Le {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i')}}
|
||||
<small class="text-muted">(Message système)</small>
|
||||
</div>
|
||||
@elseif ($message->user_id === Auth::user()->id)
|
||||
<div class="offset-md-4 col-md-8 alert alert-primary text-right">
|
||||
{!! nl2br(e($message->message)) !!}<br>
|
||||
<div class="offset-md-4 col-md-8 alert alert-primary">
|
||||
{!! Utils::plainToHtml($message->message) !!}
|
||||
@if ($message->file !== null)
|
||||
<a data-fslightbox href="{{ asset($message->file) }}" target="_blank">Ouvrir la pièce jointe</a><br>
|
||||
@endif
|
||||
<br><a data-fslightbox href="{{ asset($message->file) }}" target="_blank">Ouvrir la pièce jointe</a><br>
|
||||
@endif<br><br>
|
||||
<small class="text-muted">Le {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i')}} par {{ $message->user->name }}</small>
|
||||
</div>
|
||||
@else
|
||||
<div class="col-md-8 alert alert-success text-left">
|
||||
{!! nl2br(e($message->message)) !!}<br>
|
||||
<div class="col-md-8 alert alert-success">
|
||||
{!! Utils::plainToHtml($message->message) !!}
|
||||
@if ($message->file !== null)
|
||||
<a data-fslightbox href="{{ asset($message->file) }}" target="_blank">Ouvrir la pièce jointe</a><br>
|
||||
@endif
|
||||
<br><a data-fslightbox href="{{ asset($message->file) }}" target="_blank">Ouvrir la pièce jointe</a><br>
|
||||
@endif<br><br>
|
||||
<small class="text-muted">Le {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i')}} par {{ $message->user->name }}</small>
|
||||
</div>
|
||||
@endif
|
||||
|
|
@ -120,7 +121,7 @@
|
|||
<hr>
|
||||
<div>
|
||||
<h4>Description</h4>
|
||||
<p>{!! nl2br(e($ticket->text)) !!}</p>
|
||||
<p>{!! Utils::plainToHtml($ticket->text) !!}</p>
|
||||
<small class="text-muted">Créé le {{ \Carbon\Carbon::parse($ticket->created_at)->format('d/m/Y à H:i') }} par <b>{{ $ticket->user->name }}</b></small>
|
||||
</div>
|
||||
@if ($ticket->file !== null || $ticket->file2 !== null)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue