Welcome! » Log In » Create A New Profile

Includes Pinterest in HTMLPurifier

Posted by JAvier 
JAvier
Includes Pinterest in HTMLPurifier
August 31, 2016 04:22AM

Hi, I've included the library HTMLPurifier in a Wordpress. And I managed to embed Facebook, Youtube, Vimeo, Twitter Etc .. But does not allow me to include code options:

Example Pinterest Code:

The first thing is to not allow me to include empty links.() I tried it with:

 $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', false);
  $config->set('AutoFormat.RemoveEmpty', false);

if I include a link, the HTMLPurifier clears me attributes data-pin-do, data-pin-lang and data-pin-width

this is part of my code:

$config->set('HTML.AllowedElements', array('a',...));
$config->set('HTML.AllowedAttributes', array('*.data-pin-do',...,'a.data-pin-lang','a.data-pin-width'));
$config->set('HTML.Allowed', 'div, *[style|class|data-pin-do], img[src]', );

I tested these possibilities but still does not work. Somebody could help me?

Thanks and regards

Re: Includes Pinterest in HTMLPurifier
August 31, 2016 04:31AM

For the data- attributes, see http://htmlpurifier.org/docs/enduser-customize.html

Don't know why empty a tags are being removed. Maybe post some full sample input and your full config?

Javier
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 04:39AM

For the moment the post only includes Pinterest pin.

sorry, the code is deleted, so I restart.

 <a data-pin-do="embedPin" data-pin-lang="es" data-pin-width="medium" href="https://es.pinterest.com/pin/449726712769198998/"></a>

This remove all links without text

Re: Includes Pinterest in HTMLPurifier
August 31, 2016 04:44AM

If you look at this sample you can see that empty a tags are preserved. So I find your described behavior puzzling. Try the default config (no extra options.)

Javier
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 04:54AM

Ok, I'm testing. And for includes attributes data-pin-do, data-pin-lang and data-pin-width?

Thanks

Re: Includes Pinterest in HTMLPurifier
August 31, 2016 04:59AM
Javier
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 06:14AM

I followed your link and I know my code is ok, but the page report a warning that the attribute is not supported

Warning: Global attribute 'data-pin-do' is not supported in any elements (for information on implementing this, see the support forums) on line 391

Warning: Global attribute 'data-pin-lang' is not supported in any elements (for information on implementing this, see the support forums) in 

Warning: Global attribute 'data-pin-width' is not supported in any elements (for information on implementing this, see the support forums) in 
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 06:19AM

Post me your code.

Javier
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 06:54AM

$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'ISO-8859-1'); // replace with your encoding
$config->set('HTML.Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
$config->set('URI.Host', $_SERVER['HTTP_HOST']);                                                                                                          


$config->set('HTML.AllowedElements', array('a','b','strong','i','em','u','img','h1','h2','h3','h4','iframe','ul', 'li','ol', 'table','tr','td', 'th', 'tbody','p','blockquote'));

$config->set('HTML.AllowedAttributes', array('href','class', 'src', 'alt', 'title', 'border', 'align', 'width', 'height', 'vspace', 'hspace', 'target', 'rel','data-pin-do', 'frameborder', 'style','data-pin-lang','data-pin-width','allowtransparency'));
  
$config->set('Attr.AllowedFrameTargets', array('_blank', '_self', '_parent', '_top'));
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', false);
$config->set('AutoFormat.RemoveEmpty', false);
$config->set('Core.RemoveProcessingInstructions', true);
$config->set('HTML.TargetBlank', true);
$config->set('HTML.TidyLevel', 'heavy');
$config->set('HTML.Trusted', true);
  
// Allow Youtube, Vimeo and Spotify Iframe    
 $config->set('HTML.SafeIframe', true);
 $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|www\.facebook\.com/plugins/|embed\.spotify\.com/)%'); //allow YouTube and Vimeo

$purifier = new HTMLPurifier($config);

The warning are the variables exactly pinterest

Thanks for help me

Javier
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 07:33AM

The warning is informed when this code is active

$def = $config->getHTMLDefinition(true);
Re: Includes Pinterest in HTMLPurifier
August 31, 2016 03:00PM

Go reread http://htmlpurifier.org/docs/enduser-customize.html

data-pin-do, data-pin-lang and data-pin-width are not supported by default. You will need to add support for them.

Javier
Re: Includes Pinterest in HTMLPurifier
September 01, 2016 09:01AM

i include HTMLDefinition:

  $config->set('Cache.DefinitionImpl', null); // TODO: remove this later!

  $def = $config->getHTMLDefinition(true);
  $def->addAttribute('a', 'data-pin-do', 'Text');

  $purifier = new HTMLPurifier($config);

But don't work

Re: Includes Pinterest in HTMLPurifier
September 02, 2016 12:33AM

This test script works for me:

<?php
include_once &#039;library/HTMLPurifier.auto.php&#039;;

$config = HTMLPurifier_Config::createDefault();
$config->set(&#039;Cache.DefinitionImpl&#039;, null); // TODO: remove this later!

$def = $config->getHTMLDefinition(true);
$def->addAttribute(&#039;a&#039;, &#039;data-pin-do&#039;, &#039;Text&#039;);

$purifier = new HTMLPurifier($config);
echo $purifier->purify(&#039;<a data-pin-do="af">af</a>&#039;);
Javier
Re: Includes Pinterest in HTMLPurifier
September 02, 2016 03:31AM

I need to include the attributes which generated errors before me:

 $config->set('HTML.AllowedAttributes', array('data-pin-do', 'data-pin-lang','data-pin-width',));

Thanks for all

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: