Make Lightbox 1.0 simple enhancement for phpwcms contentpart

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi Marcus,

nice thing you've done here! :D
I tried to test it, but got an error, I think I followed all your instructions,
could you point me in the right direction? Dunno if it's a bug or I did somethig wrong :?

Here is the test link: http://www.exil.be/index.php?fr_exil click on top right link "Infos pratiques" > I get the following result: http://www.exil.be/index.php?fr_info

Error talks about unexpected T_STRING. I use charset=iso-8859-15, anything to do with it... ?? Dunno were I messed up :?

Thanks for your input!

Cheers

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

mmh, sorry - I've can't find any error in my script (i've installed the script today on a new phpwcms-installation and got no probs)

looks your function same like this:

Code: Select all

<?php
// MAKE LIGHTBOX v1.0.1
// marcus@localhorst (m.o.) 03.04.2007
//
// ------------------------------------
// The red lights mean you're leaving
// The white ones mean returning
// Tell me how this story ends
// And I'll keep them fires burning
// --------------------- ARCADE FIRE --
//

#     \|/
#    --o--
#     /|\


$template_default_article_imagelist_table_class   = $template_default['article']['imagelist_table_class'];
$template_default_article_imagelist_class         = $template_default["article"]["imagelist_class"];
$template_default_article_imagelist_caption_class = $template_default["article"]["imagelist_caption_class"];

//echo "<pre>";print_r($GLOBALS["phpwcms"]);echo "</pre>";
// change the following only if required!

function makelightbox($img,$thumb,$caption="",$pos="gallery_0") {
 $img = base64_decode($img);
 $thumb = stripslashes($thumb); // holds the pure orginal htmlcode for displaying the thumbimage
 // $caption = convert_to_anything($caption); //maybe you need to check the caption for something illegal ;-)
 list($img, $width_height) = explode('?', $img);
 
     $img = $GLOBALS["phpwcms"]["content_path"].$GLOBALS['phpwcms']['cimage_path'].$img;
  // #------------------------------------------------------------------------------
  // if you use phpwcms version 1.1 use this line!
  // $img = $GLOBALS["phpwcms"]["file_tmp"]."".$GLOBALS["phpwcms"]["dir_preview"]."".$img;
  // #------------------------------------------------------------------------------

 // if you want to use an other presentation methode or an other script you can change the linkage here.
 $image ="<a href=\"".$img."\" rel=\"lightbox[".$pos."]\" title=\"".$caption."\">".$thumb."</a>";
 return $image;
}

// first search for given css class $template_default_article_imagelist_class to seperate each gallery-table
$searchcp ='#<table.*[^>]class="'.$template_default_article_imagelist_table_class.'">(.*)<\/table>#Us'; // U = ungreedy
preg_match_all($searchcp,$content["all"],$matchcp, PREG_PATTERN_ORDER);

// if found one or more picture tables loop through then and replace for each.
foreach($matchcp[0] as $mypos => $piccp) {
  if (!$mypos > 0) {
    $block["htmlhead"] .="<!-- Lightbox 2.02 -->\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/prototype.js\"></script>\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/scriptaculous.js?load=effects\"></script>\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/lightbox.js\"></script>\n";
    $block["htmlhead"] .="<link href=\"".$phpwcms['templates']."/inc_app/lightbox/css/lightbox.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
    $block["htmlhead"] .="<!-- //Lightbox 2.02 -->\n";
  }


  $pos = "gallery_".$mypos; // this give unique names for the gallery slideshow.
 
  // search for imagelisttd which describe the image table
  $search ='#<td class="'.$template_default_article_imagelist_class.'">(.*)<\/td>#U'; // U = ungreedy
  preg_match_all($search,$matchcp[0][$mypos],$match, PREG_PATTERN_ORDER);
  //print_r($match);
 
  // search for .imglistcaption class to grab the caption
  $searchcapt ='#<td class="'.$template_default_article_imagelist_caption_class.'">(.*)<\/td>#U'; // U = ungreedy
  preg_match_all($searchcapt,$matchcp[0][$mypos],$matchcapt, PREG_PATTERN_ORDER);


  if(is_array($match[1])) {
  // now loop through the matches and replace them with the custom code from function makelightbox
    foreach($match[1] as $i => $imgcell) {
        $caption=$matchcapt[1][$i]; // get image caption if available - if not, it's empty
        $linkfind ='#<a href="image_zoom.php\?show=(.*)".*[^>]>(.*)</a>#Ue';
        $linkreplacer ="makelightbox('$1','$2','$caption','$pos')";
        $replace = preg_replace($linkfind,$linkreplacer,$match[1][$i]);
        // last thing is replace the exact strings with the new one
        $content["all"]   = str_replace($match[1][$i], $replace, $content["all"]); 
    }
  }
}
?> 
on this line

Code: Select all

76: $replace = preg_replace($linkfind,$linkreplacer,$match[1][$i]);
the parser hangs. is that function complete?

greetings
marcus

User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi Marcus,

thx for fast reply and ... sadly yes just replaced my file with yours (was the same) and same result... strange ?

I commented line 76 and look what it gives (seems ok to me so far):

Code: Select all

nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);
Maybe a path to the solution? It's strange that the parser hangs on the preg_replace...

Anyway, if someone has a clue, help is welcome.

Cheers

User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hey marcus,

we changed a bit the lightbox.php file and now it works, you can see results at http://www.exil.be/index.php?fr_info :)

It was the preg_replace he (he as in 'the server') didn't like, don't know why, apparently the $1 in $linkreplacer was a problem...

Here is the modified lightbox:

Code: Select all

<?php
// MAKE LIGHTBOX v1.0.1
// marcus@localhorst (m.o.) 03.04.2007
//
// ------------------------------------
// The red lights mean you're leaving
// The white ones mean returning
// Tell me how this story ends
// And I'll keep them fires burning
// --------------------- ARCADE FIRE --
//

#     \|/
#    --o--
#     /|\


$template_default_article_imagelist_table_class   = $template_default['article']['imagelist_table_class'];
$template_default_article_imagelist_class         = $template_default["article"]["imagelist_class"];
$template_default_article_imagelist_caption_class = $template_default["article"]["imagelist_caption_class"];

//echo "<pre>";print_r($GLOBALS["phpwcms"]);echo "</pre>";
// change the following only if required!

function makelightbox($img,$thumb,$caption="",$pos="gallery_0") {
 $img = base64_decode($img);
 $thumb = stripslashes($thumb); // holds the pure orginal htmlcode for displaying the thumbimage
 // $caption = convert_to_anything($caption); //maybe you need to check the caption for something illegal ;-)
 list($img, $width_height) = explode('?', $img);
 
     $img = $GLOBALS["phpwcms"]["content_path"].$GLOBALS['phpwcms']['cimage_path'].$img;
  // #------------------------------------------------------------------------------
  // if you use phpwcms version 1.1 use this line!
  // $img = $GLOBALS["phpwcms"]["file_tmp"]."".$GLOBALS["phpwcms"]["dir_preview"]."".$img;
  // #------------------------------------------------------------------------------

 // if you want to use an other presentation methode or an other script you can change the linkage here.
 $image ="<a href=\"".$img."\" rel=\"lightbox[".$pos."]\" title=\"".$caption."\">".$thumb."</a>";
 return $image;
}

// first search for given css class $template_default_article_imagelist_class to seperate each gallery-table
$searchcp ='#<table.*[^>]class="'.$template_default_article_imagelist_table_class.'">(.*)<\/table>#Us'; // U = ungreedy
preg_match_all($searchcp,$content["all"],$matchcp, PREG_PATTERN_ORDER);

// if found one or more picture tables loop through then and replace for each.
foreach($matchcp[0] as $mypos => $piccp) {
  if (!$mypos > 0) {
    $block["htmlhead"] .="<!-- Lightbox 2.02 -->\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/prototype.js\"></script>\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/scriptaculous.js?load=effects\"></script>\n";
    $block["htmlhead"] .="<script type=\"text/javascript\" src=\"".$phpwcms['templates']."inc_app/lightbox/js/lightbox.js\"></script>\n";
    $block["htmlhead"] .="<link href=\"".$phpwcms['templates']."/inc_app/lightbox/css/lightbox.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
    $block["htmlhead"] .="<!-- //Lightbox 2.02 -->\n";
  }


  $pos = "gallery_".$mypos; // this give unique names for the gallery slideshow.
 
  // search for imagelisttd which describe the image table
  $search ='#<td class="'.$template_default_article_imagelist_class.'">(.*)<\/td>#U'; // U = ungreedy
  preg_match_all($search,$matchcp[0][$mypos],$match, PREG_PATTERN_ORDER);
  //print_r($match);
 
  // search for .imglistcaption class to grab the caption
  $searchcapt ='#<td class="'.$template_default_article_imagelist_caption_class.'">(.*)<\/td>#U'; // U = ungreedy
  preg_match_all($searchcapt,$matchcp[0][$mypos],$matchcapt, PREG_PATTERN_ORDER);


  if(is_array($match[1])) {
  // now loop through the matches and replace them with the custom code from function makelightbox
  //	var_dump($match[1]);
    foreach($match[1] as $i => $imgcell) {
		// begin philippe at piezo (or ple AT alter DOT be)
		// just a hack, not secure, but works as possible
		$pletabtemp = split('<a href=',$imgcell);
		if(count($pletabtemp)>1){
			$pletabtemp2=split("show=",$pletabtemp[1]);
			$pletabtemp3=split("%3D%3D",$pletabtemp2[1]);
			$ple_img_code =$pletabtemp3[0];
			$ple_img_decode =base64_decode($pletabtemp3[0]);
			$pletabtemp5 = split("\?",$ple_img_decode);
			$ple_img_decode = $pletabtemp5[0];
			$pletabtemp4 = split('\" ',$match[1][$i]);
			$ple_vars = $pletabtemp4[2].'" '.$pletabtemp4[3].'" '.$pletabtemp4[4].'" '.$pletabtemp4[5].'" '.$pletabtemp4[6].'" ';
			$ple_img_src = '<img src="'.$GLOBALS["phpwcms"]["content_path"].$GLOBALS['phpwcms']['cimage_path'].$ple_img_decode.'"'.$ple_vars.'/>';
			$linkreplacer =makelightbox($ple_img_code,$ple_img_src,'','$pos');
			//echo $ple_img_src;
			//$caption=$matchcapt[1][$i]; // get image caption if available - if not, it's empty
        	//$linkfind ='#<a href="image_zoom.php\?show=(.*)".*[^>]>(.*)</a>#Ue';
			$content["all"]   = str_replace($match[1][$i], $linkreplacer, $content["all"]);
		}
		
		// end philippe
        /*$caption=$matchcapt[1][$i]; // get image caption if available - if not, it's empty
        $linkfind ='#<a href="image_zoom.php\?show=(.*)".*[^>]>(.*)</a>#Ue';
		$linkreplacer ="makelightbox('$1','$2','$caption','$pos')";
        $replace = preg_replace($linkfind,$linkreplacer,$match[1][$i]);
        // last thing is replace the exact strings with the new one
		//$content["all"]   = str_replace($match[1][$i], $linkreplacer, $content["all"]);*/
    }
  }
}
?> 
Philippe (vow), who did the coding says he didn't check it thouroughly so it might not be very 'clean' or even secure, can you tell me what you think about it?

Thanks for your help,

Cheers
Last edited by Kosse on Sun 15. Apr 2007, 19:53, edited 1 time in total.

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

(take out phillipes mailadress from the example above - or I will put it to my spam database hehe :-)

Is there no preg_replace working on your server? that cannot be?! maybe it works with the backreference //1 (?) (just an idea that I get now)

or doesn't it work in only my code?

greetings marcus

User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

marcus@localhorst wrote:(take out phillipes mailadress from the example above - or I will put it to my spam database hehe :-)

Is there no preg_replace working on your server? that cannot be?! maybe it works with the backreference //1 (?) (just an idea that I get now)

or doesn't it work in only my code?

greetings marcus
hey Marcus, thanks 4 checking, I think the preg_replace didn't work in ur code (I don't understand why though...)

ps: edited Philippe's email ;)

Cheers

Nordlicht
Posts: 160
Joined: Wed 12. Apr 2006, 08:16
Location: Germany, near Hamburg
Contact:

Post by Nordlicht »

culda_a wrote:I was thinking on something like this:

Image
Here we go...
LightboxEX with a slideshow and music.

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

should I update my package? :shock:
ok - comes soon 8)

cbraun75
Posts: 5
Joined: Fri 13. May 2005, 22:35
Contact:

Lightbox 2 Problem with Firefox?

Post by cbraun75 »

Hi just one Question, I have implemented the lightbox -> works fine with IE but not with the firefox. I have only implemented the multilanguage for poor men nothing more. But in Firefox only the existing side comes with the big picture and the real site is gone.

Has somebody an idea?

Site which you can test it is http://www.galerie-geiger.de

Thanxx

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

Hi,
I've noticed, that you include the JS Code of lightbox twice. maybe that's it?

Code: Select all

<META name="pragma" content="no-cache">

<script type="text/javascript" src="template/inc_app/lightbox/js/prototype.js"></script> 
<script type="text/javascript" src="template/inc_app/lightbox/js/scriptaculous.js?load=effects"></script> 
<script type="text/javascript" src="template/inc_app/lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="template/inc_app/lightbox/css/lightbox.css" type="text/css" media="screen" />

<script type="text/javascript" src="template/multilang/languages.js"></script>
<style type="text/css">.invisibleonload {visibility:hidden}</style>
<!-- Lightbox 2.02 -->
<script type="text/javascript" src="/template/inc_app/lightbox/js/prototype.js"></script>
<script type="text/javascript" src="/template/inc_app/lightbox/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="/template/inc_app/lightbox/js/lightbox.js"></script>
<link href="/template//inc_app/lightbox/css/lightbox.css" rel="stylesheet" type="text/css" />
<!-- //Lightbox 2.02 -->
</head>
delete the first part (maybe you placed that in your template head?) and try it again...
best marcus

cbraun75
Posts: 5
Joined: Fri 13. May 2005, 22:35
Contact:

Thanxx a lot!!!

Post by cbraun75 »

Yes thats it! Thank you

Post Reply