Forum code that automatically turns urls into clickable links
16 posts by 2 authors in: Forums > CMS Builder
Last Post: December 29, 2018 (RSS)
Oops, sorry, I didn't catch the typo. My bad.
The test record ‘recipe’ text box contains only the following as text:
______________________________________
TEXT BEFORE A LINK
http://www.thecmsbcookbook.com
AFTER LINK
qzl
AFTER A Q-Z-L
<a href="http://www.thecmsbcookbook.com/css/fonts2019.css.php" />CLICK TO ACCEPT THIS</a>
lzq
AFTER AN L-Z-Q
_______________________________Z_____
As always, you're the best!
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By daniel - December 28, 2018
Hey Jerry,
I found the other issue - the two htmlPurify() calls are missing the 2nd parameter, so it simply wasn't running. It should be:
// did we find an ending blockquote?
if (count( $tmp ) > 1) {
// purify content after blockquote
$tmp[1] = htmlPurify($tmp[1], $config);
}
else {
// purify only element
$tmp[0] = htmlPurify($tmp[0], $config);
}
As for the link rendering within the blockquote, that is because the content already contains an <a></a> tag which is being rendered into a link. If you also want the link to not render, that's a separate issue from the purifier.
Let me know any questions!
Technical Lead
interactivetools.com
Hi Daniel,
I'm sorry this one has become so time consuming for you. I'm sure it's not the only thing on your plate.
I inserted the new code, but it throws an undefined index error because $config is not defined.
I assumed $config was either supposed to be $chunk or $chunks, but any combination of these throw errors like
#7937 - E_USER_WARNING: Base directory /home3/ellescho/public_html/thecmsbcookbook/cmsAdmin/3rdParty/HTMLPurifier/standalone/HTMLPurifier/DefinitionCache/Serializer does not exist,
please create or change using %Cache.SerializerPath
/home3/ellescho/public_html/thecmsbcookbook/cmsAdmin/3rdParty/HTMLPurifier/HTMLPurifier.standalone.php (line 15689)
http://www.thecmsbcookbook.com/recipedetailJ.php?589
BTW, I think you're misunderstanding the functions reversed issue.
The links outside of the blockquotes should render as live links
Any links inside the block quotes should not render as live links.
BTW: It should be the same as the way the forum posts work. :-)
<a href='thecmsbcookbook.com/test.php">Not A Live Link When In Block Quotes</a>
See the issue in http://www.thecmsbcookbook.com/recipedetailJ.php?589
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By daniel - December 28, 2018 - edited: December 28, 2018
Hi Jerry,
$config was from the very first snippet I posted and needs to be initialized before using htmlPurify:
$config = array();
$config['AutoFormat.Linkify'] = true;
I do understand what you're asking for; though there are a few differences between your use case and what happens here on the forum. If you paste HTML into the forum, such as "<a href='thecmsbcookbook.com/test.php">Not A Live Link When In Block Quotes</a>" the forum encodes the HTML so that it doesn't render, and instead displays the HTML tags as text. If your $recipe variable contains unencoded HTML it will render as HTML when output - regardless of anything the purifier has done.
(Also, worth noting that links are added within blockquotes on these forums if you include the full URL):
<a href='http://thecmsbcookbook.com/test.php">Live Link When In Block Quotes</a>
So, if you want to be able to display HTML as text in your recipes, you'll need to save them as encoded HTML. Since anything copied from the forums should already be encoded, I think you're mostly covered, but you can also manually encode/decode online with a tool such as https://www.online-toolz.com/tools/text-html-entities-convertor.php
Hopefully that does the trick!
Thanks,
Technical Lead
interactivetools.com
Hi Daniel,
Appreciate your keeping up with this.
I mistakenly left the
$config = array();
$config['AutoFormat.Linkify'] = true;
out when I updated the code.
Maybe some of the issues I'm still having are because I've over simplified the test code.
Let me put all the original recipe code back in to the page and see if that solves any of the issues in the Block Quotes.
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Hi Daniel,
When I put the rest of the code into the viewers, everything worked as planned.
Couldn't have done this without your help. Many thanks!
I've created 2 recipes in my CMSB Cookbook to document the process.
A simple implementation of the htmlPurify library
http://www.thecmsbcookbook.com/recipedetail.php?590
And a more complex implementation for the Cookbook
http://www.thecmsbcookbook.com/recipedetail.php?324
Hope they're helpful to others.
Best for the new year!
Jerry Kornluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php