I am using mewebstudio/Purifier in my Laravel project.
I have a custom vue-component <image-slides> which can be created by the user, and a want to store it into database, so
user input example:
<h2>My Title</h2><image-slides images="https://i.imgur.com/123.jpg,https://i.imgur.com/321.jpg"></image-slides><p>some text</p>
when using default Purifier config:
clean('<h2>My Title</h2><image-slides images="https://i.imgur.com/123.jpg,https://i.imgur.com/321.jpg"></image-slides><p>some text</p>');
=> "<h2>My Title</h2><p>some text</p>"
I add the <image-slides> to the config/purifier.php
return [
'encoding' => 'UTF-8',
'finalize' => true,
'ignoreNonStrings' => false,
'cachePath' => storage_path('app/purifier'),
'cacheFileMode' => 0755,
'settings' => [
'default' => [
'HTML.Doctype' => 'XHTML 1.0 Transitional',
// before
'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td',
// after
'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td,image-slides[images]',
...
But I got error:
Element 'image-slides' is not supported (for information on implementing this, see the support forums)
I already clean the cache for both laravel and purifier(remove /storage/app/purifier folder)
How can I add a custom tag for Purifier?
just define it in config/purifier.php
return [
'settings' => [
'default' => [
'HTML.Allowed' => 'image-slide[images]'
],
'custom_elements' => [
['image-slides', 'Block', 'Flow', 'Common', [
'images' => 'Text'
]]
]
]
];
Related
I have made a custom palette in tt_content.php and want to add it to all content elements on the appearance tab like this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'--palette--;My Palette;my_palette',
'',
'before:sectionIndex'
);
This works for everything except Grid Elements (gridelements_pi1). How do I make the new palette show up on Grid Elements as well?
The comment from #MathiasBrodala lead me to finding the answer is in the order of extensions.
In this case I needed to add gridelements under suggests in my ext_emconf.php which ensures it will be loaded before my site package.
$EM_CONF[$_EXTKEY] = [
'title' => 'My Package',
'description' => 'TYPO3 Sitepackage',
'category' => 'templates',
'version' => '1.0.0',
'state' => 'stable',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-9.5.99',
'fluid_styled_content' => '8.7.0-9.5.99'
],
'suggests' => [
'gridelements' => '9.3.0-0.0.0',
],
'conflicts' => [
],
],
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 1
];
I would like to build a slider (Own Content Element). So on the backend i would like to have a section with multiple records. What do i mean? By clicking the "Create new" i would like to have an image selection and rich text selection.
Something like that.
How can i achieve this?
So far i have:
TCA/Overrides/tt_content.php
which gives me the rich editor and the image selection in backend, but not grouped.
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = array( 'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
);
tt_content.typosript
tt_content {
my_slider < lib.contentElement
my_slider {
templateRootPaths.10 = {$Private}Templates/
templateName = Slider.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
as = images
}
}
}
}
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.description}
</f:for>
<f:debug>{data}</f:debug>
</html>
Now with the current code i get the results in frontend. One Text and one Image. But how can i get it as group after configured it on the backend?
You need add new field to the sys_file_reference TCA:
Configuration/TCA/Overrides/sys_file_reference.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'sys_file_reference',
[
'tx_myext_description' => [
'label' => 'My field description',
'config' => [
'type' => 'text',
'cols' => '80',
'rows' => '15',
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
]
);
ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_description mediumtext,
);
Remember to add new field into database (using database compare tool in install tool).
Then use it in TCA of your new slider:
Configuration/TCA/Overrides/tt_content.php
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
'assets' => [
'config' => [
'overrideChildTca' => [
'types' => [
0 => ['showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][0]['showitem'].',tx_myext_description'],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION]['showitem'].',tx_myext_description'
],
],
],
],
],
],
];
And then your Fluid template may look like that:
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.properties.tx_myext_description -> f:format.html()}
</f:for>
</html>
I am using HTMLPurifier and this package for Laravel 5:
https://github.com/mewebstudio/Purifier
However, the docs show to use it like this:
$clean = Purifier::clean($dirty);
and the default config file is:
return [
'encoding' => 'UTF-8',
'finalize' => true,
'cachePath' => storage_path('app/purifier'),
'settings' => [
'default' => [
'HTML.Doctype' => 'XHTML 1.0 Strict',
'HTML.Allowed' => 'img[alt|src],ul,li,p,br,b',
'CSS.AllowedProperties' => '',
//'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
],
'test' => [
'Attr.EnableID' => true
],
"youtube" => [
"HTML.SafeIframe" => 'true',
"URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
],
],
];
This works fine, but I need to do some custom config work to allow the use of some HTML elements, namely the figure element tag.
In the docs for HTMLPurifier and elsewhere it shows doing this for example:
$def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
But no matter what I try I cannot use the Laravel config file to add new elements. Any help?
I am using Mews HTML Purifier and have it working great!
However, there are a couple of HTML5 elements such as figure that I want to not be stripped out.
I have looked at the docs:
http://htmlpurifier.org/docs/enduser-customize.html
But cannot see any information on adding elements / the full config options for when using the Laravel config file.
I cant find information when setting up the config like this:
return [
'encoding' => 'UTF-8',
'finalize' => true,
'cachePath' => storage_path('app/purifier'),
'settings' => [
'default' => [
'HTML.Doctype' => 'XHTML 1.0 Strict',
'HTML.Allowed' => 'img[alt|src],ul,li,p,br,b,figure',
'CSS.AllowedProperties' => '',
//'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
],
'test' => [
'Attr.EnableID' => true
],
"youtube" => [
"HTML.SafeIframe" => 'true',
"URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
],
],
];
And then using it like:
Purifier::clean($request->content);
I'm using HTMLPurifier and even thou I have :
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
it removes all 'target' attribues from the links.
Any idea why is it doing it?
The list of allowed frame targets is not enabled by default. You have to enable it manually.
In a Yii2 application, inside of a DetailView, I configured HtmlPurifier as follows:
[
'label' => 'Document PDF',
'format'=> 'raw',
'value' => HtmlPurifier::process(DocumentFunctions::viewDocumentPdfInView($model->document_id), [
'Attr.AllowedFrameTargets' => ['_blank'],
]),
],
Here is a simpler way I found:
[
'label' => 'Document PDF',
'format'=> ['html', 'config' => ['Attr.AllowedFrameTargets' => ['_blank']]],
'value' => DocumentFunctions::viewDocumentPdfInView($model->document_id),
]