mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-10-22 07:52:19 +03:00
Updated html description code to be behind a proper interface. Set new convention for mode traits/interfaces.
36 lines
846 B
PHP
36 lines
846 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Models;
|
|
|
|
use BookStack\Util\HtmlContentFilter;
|
|
|
|
/**
|
|
* @property string $description
|
|
* @property string $description_html
|
|
*/
|
|
trait HtmlDescriptionTrait
|
|
{
|
|
public function descriptionHtml(bool $raw = false): string
|
|
{
|
|
$html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
|
|
if ($raw) {
|
|
return $html;
|
|
}
|
|
|
|
return HtmlContentFilter::removeScriptsFromHtmlString($html);
|
|
}
|
|
|
|
public function setDescriptionHtml(string $html, string|null $plaintext = null): void
|
|
{
|
|
$this->description_html = $html;
|
|
|
|
if ($plaintext !== null) {
|
|
$this->description = $plaintext;
|
|
}
|
|
|
|
if (empty($html) && !empty($plaintext)) {
|
|
$this->description_html = $this->descriptionHtml();
|
|
}
|
|
}
|
|
}
|