Bakery Lightbox Caption with Email Link and Custom Subject

sky writer

YoJoe - I ended up using htmlentities, as suggested by Ruud, and it worked perfectly.
Thanks for the alternate suggestion.


YoJoe

skywriter: try to clean the $img_title variable from any non letter/digital chars using string replace function.
The easiest way:

$specialCharacters = array(
'#' => ",
'$' => ",
'%' => ",
'&' => ",
'@' => ",
'.' => ",
'€' => ",
'+' => ",
'=' => ",
'§' => ",
'\\' => ",
'/' => ",
);

while (list($character, $replacement) = each($specialCharacters)) {
$string = str_replace($character, '-' . $replacement . '-', $string);
}


There's also a more advanced preg_replace() function, but only you know what exact chars appear in image titles.
[size=1][url=http://www.wujitsu.pl]WuJitsu[/size] - [i]in web I trust[/i]  :cool:

Bug

I am curious about the fancybox in stead of lightbox, is this taken from a post on the forum?

sky writer

Thanks Ruud for pointing me in the right direction.  I had tried those before, along with many other things.  And I didn't work at that angle too much because I wasn't sure it was the right path.  Once you told me that was the direction to go, it took some time, but I figured it out.

I will share all this when I get some time to formulate it into something understandable.

Cheers!

sky writer

I've looked at those options but I can't find a way to make it work with my situation.

How do I use them to make the [TITLE] safe to use in the code as shown?

Ruud

You should use the php function htmlspecialchars of htmlentities for the title to replace all "problem" characters.
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

sky writer

I have been working toward this functionality for some time now.  I am building a website for an Art Gallery using Bakery as the gallery.  It's working very well.  Each work is shown as a thumbnail, and when clicked, opens using lightbox (actually fancybox, thanks to a great workaround by blackbird!).  The caption below the lightbox image shows the Product Name ($img_title), which contains the artist's name, artwork title, dimensions etc.

To take the usability a step further, I wanted to add an "INQUIRE" link beside each caption so that when a user clicked, it would open their email with the Product Name info in the subject line.  I found this functionality to put a hyperlink within a hyperlink on the lightbox site:
$email_caption = '<a href="mailto:curator@quinnsoftweed.ca?subject=[TITLE]">Inquire</a>';

Everything works perfectly except that most of the [TITLE] content has quotation marks and other symbols which break the functionality.

For instance: Alexis Arts "A Winters Walk" Oil 24x36"
Ends up in the Subject line as: Alexis Arts
I presume because the quotation mark is breaking something.

So I have been two days trying to learn about stripping slashes and string replacement, but nothing I have tried has worked.

If anyone can offer some guidance, it would be greatly appreciated.  If I can get this working, I will gladly put up a tutorial for others to benefit from.

Here is the affected code from Bakery view_overview.php:
$img_title = '[TITLE]';

$email_caption = '<a href="mailto:curator@quinnsoftweed.ca?subject=[TITLE]">Inquire</a>';

// Make array of all item thumbs and images
if (file_exists($thumb_dir.$thumb_file) && file_exists($img_dir.$image_file)) {

// If needed add lightbox2 link to the thumb/image...
if ($setting_lightbox2 == "overview" || $setting_lightbox2 == "all") {
$thumb_prepend = "<a href='".$img_url.$image_file."' rel='lightbox[image_".$item_id."]' title='".$img_title.$email_caption."'><img src='";