-
Hi all,
I've inherited a site that I now have to update. It is an art site and the thumbnails pop up in a javascript popup, one for the verticals, and one for the horizontals. I actually understand what the code does, except one part which is throwing me off completely. The code is below, and the parts that I don't get are these:
PHP Code:
if (($theBack=="4") || ($theBack=="7") || ($theBack=="10") || ($theBack=="11") || ($theBack=="12")) {
the numbers in the quotation marks correspond to images, but I can't figure out why these were chosen, or any in the code below for that matter. Without knowing which images to plug in here, since things have updated, my popup pages aren't working right. I have to get this site finished asap, so help on this would rock more than you know...
Full code:
PHP Code:
<?
$imgName=$_GET['img'];
?>
<IMG SRC="images/<? print $imgName ?>.jpg"><BR>
<?
if ($section) {
if ($section=="ent") {
// 'ent has from e1 through e23
if ($imgName) {
$imgStrip=str_replace("v", "", $imgName);
$imgStrip=str_replace("e", "", $imgStrip);
if ($imgStrip=="1") {
$theBack=$imgStrip;
} else {
$theBack=$imgStrip-1;
}
if ($imgStrip=="23") {
$theForward=$imgStrip;
} else {
$theForward=$imgStrip+1;
}
if (($theBack=="13") || ($theBack=="14") || ($theBack=="15") || ($theBack=="23")) {
$ifVertb="v";
$goBack="vpopup.php?section=ent&img=";
} else {
$ifVertb="h";
$goBack="hpopup.php?section=ent&img=";
}
if (($theForward=="13") || ($theForward=="14") || ($theForward=="15") || ($theForward=="23")) {
$ifVertf="v";
$goForward="vpopup.php?section=ent&img=";
} else {
$ifVertf="h";
$goForward="hpopup.php?section=ent&img=";
}
$goBack=$goBack . "e" . $theBack . $ifVertb;
$goForward=$goForward . "e" . $theForward . $ifVertf;
}
} elseif ($section=="dig") {
//'dig has from d1 through d12
if ($imgName) {
$imgStrip=str_replace("v", "", $imgName);
$imgStrip=str_replace("d", "", $imgStrip);
if ($imgStrip <> "1") {
$theBack=$imgStrip-1;
} else {
$theBack=$imgStrip;
}
if ($imgStrip <> "12") {
$theForward=$imgStrip+1;
} else {
$theForward=$imgStrip;
}
if (($theBack=="4") || ($theBack=="7") || ($theBack=="10") || ($theBack=="11") || ($theBack=="12")) {
$ifVertb="h";
$goBack="hpopup.php?section=dig&img=";
} else {
$ifVertb="v";
$goBack="vpopup.php?section=dig&img=";
}
if (($theForward=="4") || ($theForward=="7") || ($theForward=="10") || ($theForward=="11") || ($theForward=="12")) {
$ifVertf="h";
$goForward="hpopup.php?section=dig&img=";
} else {
$ifVertf="v";
$goForward="vpopup.php?section=dig&img=";
}
$goBack=$goBack . "d" . $theBack . $ifVertb;
$goForward=$goForward . "d" . $theForward . $ifVertf;
}
} elseif ($section=="comp") {
//'comp has from c1 through c30
if ($imgName) {
$imgStrip=str_replace("v", "", $imgName);
$imgStrip=str_replace("c", "", $imgStrip);
if ($imgStrip <> "1") {
$theBack=$imgStrip-1;
} else {
$theBack=$imgStrip;
}
if ($imgStrip <> "30") {
$theForward=$imgStrip+1;
} else {
$theForward=$imgStrip;
}
if (($theBack=="1") || ($theBack=="2") || ($theBack=="3") || ($theBack=="4") || ($theBack=="27")) {
$ifVertb="v";
$goBack="vpopup.php?section=comp&img=";
} else {
$ifVertb="h";
$goBack="hpopup.php?section=comp&img=";
}
if (($theForward=="1") || ($theForward=="2") || ($theForward=="3") || ($theForward=="4") || ($theForward=="27")) {
$ifVertf="v";
$goForward="vpopup.php?section=comp&img=";
} else {
$ifVertf="h";
$goForward="hpopup.php?section=comp&img=";
}
$goBack=$goBack . "c" . $theBack . $ifVertb;
$goForward=$goForward . "c" . $theForward . $ifVertf;
}
} elseif ($section=="adv") {
//'adv has from a1 through a20
if ($imgName) {
$imgStrip=str_replace("v", "", $imgName);
$imgStrip=str_replace("a", "", $imgStrip);
if ($imgStrip <> "1") {
$theBack=$imgStrip-1;
} else {
$theBack=$imgStrip;
}
if ($imgStrip <> "20") {
$theForward=$imgStrip+1;
} else {
$theForward=$imgStrip;
}
if (($theBack=="10") || ($theBack=="13") || ($theBack=="14") || ($theBack=="15") || ($theBack=="17") || ($theBack=="18") || ($theBack=="19")) {
$ifVertb="h";
$goBack="hpopup.php?section=adv&img=";
} else {
$ifVertb="v";
$goBack="vpopup.php?section=adv&img=";
}
if (($theForward=="10") || ($theForward=="13") || ($theForward=="14") || ($theForward=="15") || ($theForward=="17") || ($theForward=="18") || ($theForward=="19")) {
$ifVertf="h";
$goForward="hpopup.php?section=adv&img=";
} else {
$ifVertf="v";
$goForward="vpopup.php?section=adv&img=";
}
$goBack=$goBack . "a" . $theBack . $ifVertb;
$goForward=$goForward . "a" . $theForward . $ifVertf;
}
} elseif ($section=="sketch") {
//'comp has from s1 through s22
if ($imgName) {
$imgStrip=str_replace("v", "", $imgName);
$imgStrip=str_replace("s", "", $imgStrip);
if ($imgStrip <> "1") {
$theBack=$imgStrip-1;
} else {
$theBack=$imgStrip;
}
if ($imgStrip <> "22") {
$theForward=$imgStrip+1;
} else {
$theForward=$imgStrip;
}
if (($theBack=="14") || ($theBack=="15") || ($theBack=="16") || ($theBack=="17") || ($theBack=="18") || ($theBack=="19") || ($theBack=="20") || ($theBack=="21")) {
$ifVertb="v";
$goBack="vpopup.php?section=sketch&img=";
} else {
$ifVertb="h";
$goBack="hpopup.php?section=sketch&img=";
}
if (($theForward=="14") || ($theForward=="15") || ($theForward=="16") || ($theForward=="17") || ($theForward=="18") || ($theForward=="19") || ($theForward=="20") || ($theForward=="21")) {
$ifVertf="v";
$goForward="vpopup.php?section=sketch&img=";
} else {
$ifVertf="h";
$goForward="hpopup.php?section=sketch&img=";
}
$goBack=$goBack . "s" . $theBack . $ifVertb;
$goForward=$goForward . "s" . $theForward . $ifVertf;
}
}
} else {
//'it's blank.. don't do **** with forward and back
}
?>
-
Hi freakyfish,
I moved your thread from the Javascript forum to this forum (PHP) as your question is PHP related.
(All your posted code above is PHP)
The line in question:
if (($theBack=="4") || ($theBack=="7") || ($theBack=="10")....
is basically checking to see wether the variable "$theBack" is set to one of the predefined values. If it is, the curly-bracket enclosed code, should be executed. if not, the 'else' statement gets executed.
if ($var==1 || $var==2 || $var==3...) basically means:
If variable $var is set to either 1,2,3.. (etc) execute the following code.
It looks like he has predefined which images are vertically oriented, and which ones are horizontal. The result refers to different javascript popup window definitions.
(clumsy verbose code, which leaves little flexibility if you were to add new pictures)
As there are no comments or indents, it's hard to decrypt the code. I only skimmed trough it.
If the Jvascript part works OK, then keep it. You should probably rewrite the PHP code though.
-
Lol.. wow, I feel silly thinking that was all javascript!
The popup windows open fine, but here's my dilemma, which you did indeed forsee, I have to add images and I couldn't figure out whether the images that were predefined were defined as vertical or horizaontal. I've tried plugging in images of all sorts to see if I could figure it out, but still fail... here is the actual site and the popup windows.. you'll see that once clicking on a thumb, the php popup opens and then allows you to scroll through the images, but everynow and then one isn't displayed right, which is my problem here.
The worst culprit is http://www.danilostudio.com/frameset_dig.html
I really appreciate your response. I figured it had to do with vertical and horizontal positioning, but since i've added images I can't get which is which right in the code! :S
-
It's very hard to debug/reverse engineer code you didn't write yourself, when there's no comments attached, and the code itself does not utilize known workarounds.
It looks like the previous author has spent a lot of time on naming conventions for uploaded pictures, so as to extract which pictures are vertically oriented, and which ones are horizontal.
There are ways of extracting that information just by reading the picture info. Obviously, you won't know if the artist intended to make the first value (width) the longest or shortest. In those cases, you will have to manually name them.
Most of the code deals with what should happen if visitors click the forward or backward buttons at given places in the slide show.
If you start from scratch, I'm sure you could work out a more efficient way of dealing with how different button actions (events) should trigger different behaviour.
If I had to do this, I would certainly rewrite the whole PHP section to something I found workable, and would try to make the whole business of uploading new images, easier.
You have to sketch out what you want the interface to achieve, and then build your code around that idea/solution. Repainting some old (uncomprehensible) code, will give much more work than rewriting the code to a structure you are comfortable with.
-
You are so right on many counts; that code made it HELL to add any new images, especially if the order of the images changed... every single one then had to be renamed to work with that code... and rewriting it is indeed the way to go, but I have to laugh because I'm html/css, not php!! I had redone the rest of the site from php to html, but wanted to try to keep the slide show...
I spent hours studying that code. what agrivated me most is that I understood it (like actionscript a little) but couldn't figure out the picture orientation part. Grrrrr...
So in the end, I wound up redoing the entire thing with regular javascript popups and an optional flash slideshow!
You rock for all you're help! :)
-
Thank you for your kind words.
Just wanted to add that the site in itself is great. Mostly due to the breathtaking quality of the sketches and other artwork beeing presented.
This is an artist who most certainly deserves positive exposure through a well designed website.
Best of luck! ;)