Forums / All Other Contributions/Addons / Additional Image Titles [support]

Additional Image Titles [support]

Started by gjh42 on 23 Jan 2009, 4:35 AM · Views: 12,099

Results 21 to 40 of 68
16 Nov 2009, 5:07 PM
#21
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Additional Image Titles [support]

I am testing out this mod and have run into a snag and I think it's with my confusion over how to specify the folder and file path.

My additional image exists here:
/images/silks/silk-custom_01.jpg

Can you tell me how this file should be referenced in the additional_image_titles_defines.php ? I am a bit confused over the use of underscores in the included examples in relation to the folder and filename. I've tried:

ADDIMG_SILKS_SILK-CUSTOM_01_jpg
ADDIMG_SILKS_SILK_CUSTOM_01_jpg
ADDIMG_SILKS_SILK-CUSTOM_01.jpg

Whatever I am doing wrong, it is disabling my entire site. After uploading the two files and I do a refresh on my site, it won't load and goes completely blank. When viewing page source, it's completely blank. Every page on the site exhibits this behavior until I delete the additional_image_titles_defines.php file.

---UPDATE---
I just tested again, but didn't edit the additional_images_titles_defines.php file. I just uploaded the includes folder (and renamed modules\your_template to my custom template) with the included examples and it still disables my entire site. :dontgetit

17 Nov 2009, 8:32 PM
#22
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

As the readme says, replace all / . and - characters with _ in the defines. I did not mention explicitly, though the example shows, that you need to use all upper case letters.

ADDIMG_SILKS_SILK_CUSTOM_01_jpg
will not work; it needs to be
ADDIMG_SILKS_SILK_CUSTOM_01_JPG

Do you know what version of PHP your host uses? There is no good reason that the unedited files should crash your site, except that the mod uses the PHP function ereg_replace(), which I understand is deprecated in PHP 5.3 and will cause a problem with any script that uses it.

If that is the case, you may be able to change ereg_replace to preg_replace in the code; I have not yet checked on the syntax to see whether there is any difference in usage between the two functions. I will get back on this, and if necessary, release a new version of the mod to account for the PHP situation.

17 Nov 2009, 9:02 PM
#23
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

Zen Cart 1.3.8a (all security patches)
PHP 5.2.11
MySQL 5.0.81

I just tried again with the corrected define (ADDIMG_SILKS_SILK_CUSTOM_01_JPG) and the site still goes completely blank on refresh.

I also changed ereg_replace to preg_replace in additional_images.php.

17 Nov 2009, 9:21 PM
#24
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

So it's not the PHP version... have you downloaded a new copy of the mod? Perhaps a file got corrupted when unzipping or something.

17 Nov 2009, 9:35 PM
#25
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

I just deleted my local copy of the mod and re-downloaded it.

Same issue. I guess there must be something quirky then with my host provider setup.

18 Nov 2009, 2:03 AM
#26
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

Sorry you still have a problem, but I can't think of anything else that could be responsible...

Re: the PHP 5.3 deprecated function issue, you can just change ereg_replace to preg_replace and it will work fine - in fact, faster than before by an amount only detectable in mass repetitions. Preg_replace is much more powerful and flexible as well, but can still be used in the same basic fashion.

18 Nov 2009, 5:22 AM
#27
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

I found the issue and fixed it.

I installed the debug error logging utility and got these results:

PHP Parse error:  syntax error, unexpected '}' in /includes/languages/english/extra_definitions/additional_image_titles_defines.php on line 6

I looked on line 6 and it's:

define ('ADDIMG_TEXT_TOP','true'};//change to false to put text below images

In additional_image_titles_defines.php, I changed the } to a )

The } was in the original file. So, anyone else that happens to run into the same problem as I did, change:

('ADDIMG_TEXT_TOP','true'}

to

('ADDIMG_TEXT_TOP','true')
18 Nov 2009, 6:04 AM
#28
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

This typo/bug is addressed in posts 12 & 13 above; I apparently never uploaded the fixed (v1.1) zip to Free Addons back in July. I am uploading it now (v1.2) along with a couple of other improvements.

18 Nov 2009, 6:20 AM
#29
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

Glenn, this is an excellent mod. Very cool. Thank you for putting this together.

18 Nov 2009, 7:38 PM
#30
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

I am back! ;) I downloaded your latest v1.2

Question, this should work for pre-PHP 5.3 right?

I don't receive any errors and my site appears to function normally (no blank pages), but there are no image titles on the images I defined using v1.2. If I copy over version 1.0 (with the bracket fix) back the image titles work.

18 Nov 2009, 8:46 PM
#31
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

Using the v1.2 files, in additional_images.php, I changed preg_replace back to ereg_replace and image titles have returned.

18 Nov 2009, 10:32 PM
#32
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

That should teach me to go through the bother of testing even what appears cut & dried... I have duplicated that result. Now to see how preg_replace actually differs from ereg_replace. I couldn't find any difference in the interpreted descriptions for the current case, but there obviously is some difference. The preg version has lots more possibilities listed in the function description. My XAMPP uses PHP 5.2.6, not identical to yours, but ought to be close in treatment of functions.

18 Nov 2009, 11:18 PM
#33
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

Okay, preg_replace() is not recognizing a . character as something to replace, while ereg_replace() works with the identical pattern definition.

18 Nov 2009, 11:50 PM
#34
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

This is definitely annoying. From the official PHP site,
Pattern Syntax > Full stop: "Dot has no special meaning in a character class."

Square brackets: "An opening square bracket introduces a character class, terminated by a closing square bracket."

So what is wrong withphp preg_replace('[/\\.-]','_',substr_replace($base_image,'',0,7)) when```php
ereg_replace('[/\.-]','_',substr_replace($base_image,'',0,7))

19 Nov 2009, 4:06 AM
#35
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

After several hours of tutorials, most of which (including the official PHP manual) failed to mention a critical aspect of pattern syntax, I have a working example.
It takes thisphp preg_replace('#[/\\\\.-]#','_', to replicate the pattern/replacement part of this```php
ereg_replace('[/\.-]','_',

Next, the manual's statement that a backslash \ inside a character class can be read as a literal by escaping it \\ is incomplete, as it needs to be double-escaped \\\\.
No doubt there are other subtleties to even these basic aspects of the function which are not mentioned in the tutorials...
19 Nov 2009, 5:08 PM
#36
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

Nice! It's odd though that PHP 5.3 doesn't seem to bark when these delimiters are missing, as your code works in 5.3.

Just an update...

In v1.2, I changed ereg_replace back to preg_replace and added your new pattern:

preg_replace('#[/\\\\.-]#','_',

and Additional Image Titles works great in PHP 5.2.11.

19 Nov 2009, 5:37 PM
#37
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Additional Image Titles [support]

Now that we have this all sorted out, I am following some advice I read and using str_replace instead of preg_replace in the mod, since the replacement is simple enough to allow it. I also like the comprehensibility ofphp str_replace(array('/','\\','.','-'),'_',substr_replace($base_image,'',0,7)) compared to ```php
preg_replace('#[/\\.-]#','_',substr_replace($base_image,'',0,7))

19 Nov 2009, 6:10 PM
#38
crunch avatar

crunch

Zen Follower

Join Date:
Mar 2009
Posts:
227
Plugin Contributions:
0

Re: Additional Image Titles [support]

I replaced preg_replace with str_replace and it's working fine.
I can feel your mod getting better, stronger, faster :flex:

9 Dec 2009, 12:13 AM
#39
perkiekat avatar

perkiekat

Zen Follower

Join Date:
Aug 2009
Location:
Carmi, IL
Posts:
354
Plugin Contributions:
0

Re: Additional Image Titles [support]

HelenSama:

This is an update to my other posts in this string. I'm the one, hopefully not the only one, who needs to have the additional image titles from Glenn's mod appear with the larger images in Lightbox/Slimbox.

I've made some progress, since I am using both the Additional Image Title add-on and the Slimbox add-on, both add-ons have modifications to additional_images.php. At first I could only have one or the other, I've now successfully meshed the modifications so that the additional image titles are appearing and also clicking on larger image brings up the Lightbox so that is working. Here is an example of it, still needs finishing touches but am happy it is working this much: http://peterfasano.com/zen/index.php?main_page=product_info&cPath=1_9&products_id=2

I still need to have the additional image titles appear with the larger image in the Lightbox instead of where you see the product name in the lower left hand corner. Here is the bottom part of additional_images.php where I have meshed the two modifications together:

// Link Preparation:
// bof Zen Lightbox v1.4 aclarke 2007-09-22
if (ZEN_LIGHTBOX_STATUS == 'true' || FUAL_SLIMBOX == 'true') {

$script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="' . zen_lightbox($products_image_large, addslashes($products_name), LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT) . '" rel="lightbox[gallery]" title="' . addslashes($products_name) . '">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';

} else {

$script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . $large_link . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';

}
// eof Zen Lightbox v1.4 aclarke 2007-09-22

$noscript_link = '<noscript>' . ($flag_display_large ? '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large) . '" target="_blank">' . $thumb_regular . '<br /><span class="imgLinkAdditional">' . TEXT_CLICK_TO_ENLARGE . '</span></a>' : $thumb_regular ) . '</noscript>';

//      $alternate_link = '<a href="' . $products_image_large . '" onclick="javascript:popupWindow(\''. $large_link . '\') return false;" title="' . $products_name . '" target="_blank">' . $thumb_regular . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';

$link = $script_link . "\n      " . $noscript_link;

// $link = $alternate_link;
// additional image titles
$add_img_constant = 'ADDIMG_' . strtoupper(ereg_replace('[/\.-]','_',substr_replace($base_image,'',0,7)));// if any other characters could be used in filepath, add them to list [ ]
if (defined($add_img_constant)) {//add text above or below images
$link = (ADDIMG_TEXT_TOP)? '<h4 class="addImgTitle">' . constant($add_img_constant) . '</h4>' . $link: $link . '<h4 class="addImgTitle">' . constant($add_img_constant) . '</h4>';
}
// /additional image titles
// List Box array generation:
$list_box_contents[$row][$col] = array('params' => 'class="additionalImages centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => "\n " . $link);
$col ++;
if ($col > (IMAGES_AUTO_ADDED -1)) {
$col = 0;
$row ++;
}
} // end for loop
} // endif

?>

Does anyone with more php coding experience than I have, have any suggestions? I've tried replacing the constant ($products_name) with the constant ($add_img_constant) but that does not work. (I also have a post in the Commercial Help Needed section but since I haven't gotten a reply resulting in help, I've been working or trying to work on it myself.

Also in the additional_image_titles_define.php code I downloaded I got an error just after installing that I corrected in my own copy. The error was ..... unexpected } encountered on line #6 --- which is this line --- define ('ADDIMG_TEXT_TOP','true'};//change to false to put text below images

I change the } to a ) to correct the error.

Hello,
I want to use this in the same manner as you do...with Slimbox. I added the above coding and also have this in my image titles:

define ('ADDIMG_TEXT_TOP',false);//change to false to put text below images
define ('ADDIMG_IMAGES_LARGE_PRIVATESTOCK_RED_01_LRG_JPG','102 - Naphthol Red');//example title for /images/large/Privatestock_red_01_LRG.jpg
define ('ADDIMG_IMAGES_LARGE_PRIVATESTOCK_BLUE_02_LRG_JPG','106 - Phthalocyanine Blue');//example title for /images/large/Privatestock_blue_02_LRG.jpg
?>

I only have two images right now to work with until i get this right...anyway...when I click on the image I get a forbidden page telling me I do not have permission to view the file....hummm...could someone please tell em what I am doing wrong here??

Thanks!
Pkat

Zen Cart user all the way for online stores!