43 lines
933 B
PHP
43 lines
933 B
PHP
<?php
|
|
|
|
namespace App\View\Components;
|
|
|
|
use Illuminate\View\Component;
|
|
|
|
use App\Models\Card;
|
|
|
|
class CardText extends Component
|
|
{
|
|
protected Card $card;
|
|
|
|
protected string $subject;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Card $card, $subject = '')
|
|
{
|
|
$this->card = $card;
|
|
$this->subject = strlen($subject) ? $subject : $card->subject;
|
|
}
|
|
|
|
/**
|
|
* Get the view / contents that represent the component.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string
|
|
*/
|
|
public function render()
|
|
{
|
|
$subject = preg_quote(__($this->subject));
|
|
|
|
// Replace non escaped '?' with subject and also Unescape escaped '?'
|
|
$text = preg_replace(
|
|
['/(?<!\\\\)\?/u', '/\\\\\\?/u'] ,
|
|
["<strong>$subject</strong>", '?'],
|
|
$this->card->body);
|
|
|
|
return $text;
|
|
}
|
|
}
|