'quill-editor', 'style' => 'height: 300px;', 'placeholder' => 'Digite seu conteúdo aqui...' ]; // Mesclar opções $options = array_merge($defaultOptions, $options); // Construir atributos $attributes = ''; foreach ($options as $key => $value) { if ($key !== 'value') { $attributes .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; } } // Retornar HTML do campo return sprintf( '', htmlspecialchars($name), htmlspecialchars($id), $attributes, htmlspecialchars($value) ); } /** * Renderiza um campo de texto simples (sem Quill) * * @param string $name Nome do campo * @param string $id ID do elemento * @param string $value Valor inicial * @param array $options Opções adicionais * @return string HTML do campo */ public static function renderTextarea(string $name, string $id, string $value = '', array $options = []): string { // Opções padrão $defaultOptions = [ 'class' => 'form-control', 'rows' => 5 ]; // Mesclar opções $options = array_merge($defaultOptions, $options); // Construir atributos $attributes = ''; foreach ($options as $key => $value) { if ($key !== 'value') { $attributes .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; } } // Retornar HTML do campo return sprintf( '', htmlspecialchars($name), htmlspecialchars($id), $attributes, htmlspecialchars($value) ); } /** * Renderiza um campo de texto com editor (Quill ou textarea simples) * baseado na configuração do sistema * * @param string $name Nome do campo * @param string $id ID do elemento * @param string $value Valor inicial * @param array $options Opções adicionais * @return string HTML do campo */ public static function renderField(string $name, string $id, string $value = '', array $options = []): string { // Verificar se o Quill está habilitado $useQuill = self::isQuillEnabled(); if ($useQuill) { return self::renderEditor($name, $id, $value, $options); } else { return self::renderTextarea($name, $id, $value, $options); } } /** * Verifica se o editor Quill está habilitado no sistema * * @return bool True se o Quill estiver habilitado */ public static function isQuillEnabled(): bool { // Verificar variável de ambiente $useQuill = getenv('APP_EDITOR_QUILL') ?: 'true'; return filter_var($useQuill, FILTER_VALIDATE_BOOLEAN); } /** * Obtém a configuração do Quill em formato JSON * * @return string Configuração em formato JSON */ public static function getQuillConfig(): string { $config = [ 'theme' => 'snow', 'placeholder' => 'Digite seu conteúdo aqui...', 'modules' => [ 'toolbar' => [ ['bold', 'italic', 'underline', 'strike'], ['blockquote', 'code-block'], [{ 'header': [1, 2] }], [{ 'list': 'ordered'}, { 'list': 'bullet' }], [{ 'script': 'sub'}, { 'script': 'super' }], [{ 'indent': '-1'}, { 'indent': '+1' }], [{ 'direction': 'rtl' }], [{ 'size': ['small', false, 'large', 'huge'] }], [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'color': [] }, { 'background': [] }], [{ 'font': [] }], [{ 'align': [] }], ['link', 'image'], ['clean'] ] ] ]; return json_encode($config); } /** * Renderiza o script de inicialização do Quill * * @return string Script de inicialização */ public static function renderInitScript(): string { if (!self::isQuillEnabled()) { return ''; } $config = self::getQuillConfig(); $configJson = json_encode($config); return << // Configuração personalizada do Quill const quillSysConfig = {$configJson}; // Sobrescrever configuração padrão se necessário if (typeof window.quillDefaultConfig !== 'undefined') { window.quillDefaultConfig = Object.assign(window.quillDefaultConfig, quillSysConfig); } HTML; } /** * Limpa o conteúdo HTML gerado pelo Quill para segurança * * @param string $html Conteúdo HTML * @return string HTML limpo */ public static function sanitizeHtml(string $html): string { // Lista de tags permitidas $allowedTags = '