Forum Moderators: coopster

Message Too Old, No Replies

Problem with active links

links inside of php script made for joomla sigplus image gallery

         

xalu

7:15 am on Apr 26, 2011 (gmt 0)

10+ Year Member



Why isn't the "activeGallery" class getting activated for the links that are clicked?

Any ideas?


<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<div class="phpheading">
<div class="contentheading">gallery</div>
</div>
<div class="clr"></div>
<div id="galleryTopSlider">
<div class="slideImages">
<?php
$galleryCall = '{gallery lightbox=none slider=boxplus.carousel slider:edges=blurred slider:step=single overlay=1 width="150" height="150" cols=4 slider:positioning=side }gallery/slider{/gallery}' ;
$galleryCall = JHTML::_('content.prepare', $galleryCall);
echo $galleryCall;
?>
</div>
</div>
<br />

<?php
$defaultPath = 'images/stories/gallery/'; //define folder root (located in images/stories)
if (empty($_GET["gallery"]))//Is the gallery assigned?
{
$defaultGallery = '1';//if not assign one to variable//
$gallery = $defaultGallery; //assign to the gallery get//
include('images/stories/gallery/'.$gallery.'/describe.php'); // Get the description from each gallery folder
echo '<h2 class="gallerytitle">'.$title.'</h2>';//title from description


$check = $defaultPath.''.$defaultGallery; //path for checking

// Scan each folder for files.//
if ( ($files = @scandir($check.'/before/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=before">Before</a></div>';
$before = TRUE;
}

//Check during folder for images
if ( ($files = @scandir($check.'/during/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=during">During</a></div>';
$during = TRUE;
}

//Check after folder for images
if ( ($files = @scandir($check.'/after/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=after">After</a></div>';
$after = TRUE;
}
echo '<div class="clr"></div>';
//assign default folder with thumbs by checking for the first non empty folder
if ($before == TRUE)
{
$active ='activeGallery';
$subGallery = 'before';
}
else if ($during == TRUE)
{
$subGallery = 'during';
$active ='activeGallery';
}
else if ($after ==TRUE)
{
$subGallery = 'after';
$active ='activeGallery';
}
//end assign defualt thumbs
//Create the gallery based on the default settings above
echo '<div id="galleryBottom">';
$galleryCall = '{gallery width=100 height=100 layout=flow}/gallery/'.$gallery.'/'.$subGallery.'/{/gallery}' ;
$galleryCall = JHTML::_('content.prepare', $galleryCall);
echo $galleryCall;
echo '</div>';
echo '<div id="bottomSlider">';
$galleryCall = '{gallery depth=1 animation=7000 slider=boxplus.transition slider:effect=fade width=350 height=310 }/gallery/'.$gallery.'/{/gallery}' ;
$galleryCall = JHTML::_('content.prepare', $galleryCall);
echo $galleryCall;
echo '<br />';
echo $description;

}


//If album is clicked
else {

$gallery = $_GET["gallery"];
include('images/stories/gallery/'.$gallery.'/describe.php');
echo '<h2 class="gallerytitle">'.$title.'</h2>';
$check = $defaultPath.''.$gallery.'/'; //path for checking



//check before folder for images
if ( ($files = @scandir($check.'before/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=before">Before</a></div>';
$before = TRUE;

}

//Check during folder for images
if ( ($files = @scandir($check.'during/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=during">During</a></div>';
$during = TRUE;
}

//Check after folder for images
if ( ($files = @scandir($check.'after/')) && (count($files) > 2) )
{
echo '<div id="subGalleryLink" class="'.$active.'"><a href="gallery/?gallery='.$gallery.'&subGallery=after">After</a></div>';
$after = TRUE;
}
echo '<div class="clr"></div>';
// End of folder Check
//assign album by clicking
$subGallery = $_GET["subGallery"];
if (empty($_GET["subGallery"]))//Is the gallery assigned?
{
if ($before == TRUE)
{
$subGallery = 'before'; //if user clicks before, the before tab is loaded
$active = 'activeGallery'; //make the link "active" which changes the css style
}
else if ($during == TRUE)
{
$active = 'activeGallery';
$subGallery = 'during';

}
else if ($after ==TRUE)
{
$active = 'activeGallery';
$subGallery = 'after';

}
}
//end


//Create the gallery based on the default settings above
$gallery = $_GET["gallery"];

echo '<div id="galleryBottom">';
$galleryCall = '{gallery width=100 height=100 layout=flow}/gallery/'.$gallery.'/'.$subGallery.'/{/gallery}' ;
$galleryCall = JHTML::_('content.prepare', $galleryCall);
echo $galleryCall;
echo '</div>'; //end galleryBottom


echo '<div id="bottomSlider">';
$galleryCall = '{gallery depth=1 animation=7000 slider=boxplus.transition slider:effect=fade width=350 height=310 }/gallery/'.$gallery.'/{/gallery}' ;
$galleryCall = JHTML::_('content.prepare', $galleryCall);
echo $galleryCall;
echo '<br />';
echo $description;



}

?>


Thanks

rocknbil

4:16 pm on Apr 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure, first, what happens here when you view source? Does it look like this or not?

echo '<div id="subGalleryLink" class="activeGallery"><a href="gallery/?gallery='blah'&subGallery=before">Before</a></div>';

If it does, it's nothing with the PHP, it's your CSS.

xalu

3:22 am on Apr 27, 2011 (gmt 0)

10+ Year Member



no it shows class="" for all links. I checked css first with an assignment of the class. I can't seem to pinpoint the error. I have a feeling it has to do with when the variable is called and when its declared.

Does php require a variable to be initialized before being called? Can I assign the variables value after it's been called?

coopster

2:51 pm on Apr 28, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, xalu.

I have a feeling it has to do with when the variable is called and when its declared.


Yes, or at least looks this way. You are using $active in your first
if
control structure where you add that class to your element, but yet you have not assigned any value to it (or even initialized it) so naturally the resulting HTML will have an empty class value. As a matter of fact, if you have error_reporting turned up on your development machine you should be seeing errors if the variable has not yet been defined.

Looks more like a logic issue than anything else, but yes, you should still initialize the variable before using it. It's good programming practice.

xalu

2:08 am on Apr 29, 2011 (gmt 0)

10+ Year Member



Thanks coopster,

Any reason I couldn't translate this into an Object oriented program? I want to practice for my classes anyway and that form of logic is easy for me to understand, however, I have never done it with PHP, is it possible?

If it is I'll do the research on setting up. Any links with a few good OOP examples would be greatly appreciated.

Thanks

coopster

3:12 pm on May 2, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure, if that is your desire. Classes and Objects [php.net]

However, I was referring to the class attribute value of your HTML element, just to eliminate any possible confusion here.