Laravel Mews HTMLPurifier - add custom config - php

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?

Related

Add TYPO3 palette to all elements?

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
];

Custom element is not supported

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'
]]
]
]
];

EAuth Extension Yii2, Class nodge\eauth\EAuth does not exist

I am trying to use EAuth extension in Yii2 advanced application. I installed it through composer and it installed it under vendor directory and configured as mentioned here (did the config in common/config/main). So, following is the directory structure for that:
root
vendor
nodege
lightopenid
provider
*files go here*
yii2-eauth
src
*files go here*
EAuth.php is under src folder. In controller I have done this in use:
use nodge\eauth\EAuth;
and when I do this:
$eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
I get the following error:
Class nodge\eauth\EAuth does not exist
What am I doing wrong? Any help?
Update:
This is my config:
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'eauth' => [
'class' => 'nodge\eauth\EAuth',
'popup' => true, // Use the popup window instead of redirecting.
'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache' on production environments.
'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited.
'httpClient' => [
// uncomment this to use streams in safe_mode
//'useStreamsFallback' => true,
],
'services' => [// You can change the providers and their classes.
'google' => [
// register your app here: https://code.google.com/apis/console/
'class' => 'nodge\eauth\services\GoogleOAuth2Service',
'clientId' => '...',
'clientSecret' => '...',
'title' => 'Google',
],
'facebook' => [
// register your app here: https://developers.facebook.com/apps/
'class' => 'nodge\eauth\services\FacebookOAuth2Service',
'clientId' => '---',
'clientSecret' => '---',
],
'yahoo' => [
'class' => 'nodge\eauth\services\YahooOpenIDService',
//'realm' => '*.example.org', // your domain, can be with wildcard to authenticate on subdomains.
],
],
],
],

Adding an element to HTMLPurifier with the Laravel 5 config file

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);

HTMLPurifier removes target="_blank"

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),
]

Categories