Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get this script running with GS
#1
I have a script that I use now and then to quickBuild image galleries. It was originally written for use with sNews but there are no sNews-specific details or hooks in the script, and it was believed that it could run in almost any (php) environment. Having tried out juliancc's Simple Image Gallery plugin, I come to realise that I would -- for my own sites -- rather use this script. For one thing it lets me create many galleries, not just one, so that's a start. And it's really simple to use. And since it's just for my own needs, I can change the output around as I see fit with relative ease. What I can't do, at the moment, is make it work with GS. So I come here asking why, and what needs to be done to make it work - if at all possible.

The script comes in two parts, one general processor that should basically be called in once in a template and then left alone; and the other part is the specific gallery handler, a copy of which is created for each new gallery needed (and of course some variables changed, like paths). I've tried looking at the details of the scripts, and I've looked at the details of Julian's Simple Gallery plugin to see how it works. I get scared just by doing this, and then the scripts (ALL of them) stand up on their skanky hind legs and shoo me. It's nasty, I tell you. Let me show you:

gallerycode.php
Code:
<?php
function get_gallery($viewPath, $dirPath, $imgClass = '', $ordered = true )
{
    $dirObj = dir( $dirPath );
    $i = 0;
    $strOutput = "";
    $arrImages = array();
    while (false !== ($entryName = $dirObj->read()))
    {
        if (is_file( $dirPath . $entryName ))
        {
            $fileInfo = pathinfo( $dirPath . $entryName );
            $fileExtension = $fileInfo['extension'];
            $extLength = strlen($fileExtension);
            $entry = substr($entryName, 0, -$extLength-1);
            
            if ( is_image_extension( $fileInfo["extension"] ) )
            {
                ++$i;
                if ( $ordered )
                {
                    $arrImages[$entry] = $entryName;
                }
                else
                {
                    $viewLink = '<a class="thumb left" href="'.$viewPath.$entryName.'" title="'.$entry.'" rel="shadowbox['.$galleryTitle.']">';
                    $strOutput .= $viewLink.'<img class="'.$imgClass.'" src="'.$dirPath.$entryName.'" alt="" /></a>
                    ';
                }
            }
        }
    } // End while
    
    $dirObj->close();
    
    if ( $i > 0 )
    {
        if ( $ordered )
        {
            // Sort images
            asort( $arrImages );
            
            // fill $strOutput
            foreach ( $arrImages as $entry => $entryName )
            {
                    $viewLink = '<a class="thumb left" href="'.$viewPath.$entryName.'" title="'.$entry.'" rel="shadowbox['.$galleryTitle.']">';
                    $strOutput .= $viewLink.'<img class="'.$imgClass.'" src="'.$dirPath.$entryName.'" alt="'.$entry.'" /></a>
                    ';
            }
        }
        
        $strOutput = $strOutput;
    }
    return $strOutput;
}


function show_gallery($viewPath, $dirPath, $imgClass = '', $ordered = true) {
   if ( $strGallery = get_gallery($viewPath, $dirPath, $imgClass) )
      echo $strGallery;
}

function is_image_extension( $strExtension = '') {
   if ( ($strExtension > '') && in_array( $strExtension, array( 'gif', 'png', 'jpg', 'jpe', 'jpeg' ) ))
      return true;
   return false;
}
?>

To make this work, I need a folder of images and, within that folder, another folder for the thumbs (which I batchCreate in PS), plus this part:

gallery.php
Code:
<?php
$galleryDir   = 'galleries/'; // Set to the directory that contains gallery images
$galleryTitle = 'Gallery Title';

$useThumbsDir  = true; // Expect to find thumbs directory in $galleryDir

$mainImgClass  = 'full'; // Add to css and here
$thumbImgClass = 'thm'; // Add to css and here
$sortImages = true;

// Set to the directory that contains galleries
$dirPath = '' . (($galleryDir !== '') ? ($galleryDir . '/') : '') ;

if ($useTitle && ($galleryTitle !== '')) {
    echo "<h2>$galleryTitle</h2>";
}

// Process main
if ($useThumbsDir) {
    $viewPath = $dirPath;
    $dirPathThumbs = $dirPath . 'thumbs/';
    show_gallery($viewPath, $dirPathThumbs, $thumbImgClass, $sortImages);
    echo '<section class="clearer"></section>
    ';
}
else {
    show_gallery($viewPath, $dirPath, $mainImgClass, $sortImages);
}

function get_gallery($viewPath, $dirPath, $imgClass = '', $ordered = true )
{
    $dirObj = dir( $dirPath );
    $i = 0;
    $strOutput = "";
    $arrImages = array();
    while (false !== ($entryName = $dirObj->read()))
    {
        if (is_file( $dirPath . $entryName ))
        {
            $fileInfo = pathinfo( $dirPath . $entryName );
            $fileExtension = $fileInfo['extension'];
            $extLength = strlen($fileExtension);
            $entry = substr($entryName, 0, -$extLength-1);
            
            if ( is_image_extension( $fileInfo["extension"] ) )
            {
                ++$i;
                if ( $ordered )
                {
                    $arrImages[$entry] = $entryName;
                }
                else
                {
                    $viewLink = '<a class="thumb left" href="gallery/'.$entry.'/" title="'.$entry.'" rel="shadowbox['.$galleryTitle.']">';
                    $strOutput .= $viewLink.'<img class="'.$imgClass.'" src="'.$dirPath.$entryName.'" alt="" /></a></section>
                    ';
                }
            }
        }
    } // End while
    
    $dirObj->close();
    
    if ( $i > 0 )
    {
        if ( $ordered )
        {
            // Sort images
            asort( $arrImages );
            
            // fill $strOutput
            foreach ( $arrImages as $entry => $entryName )
            {
                    $viewLink = '<a class="thumb left" href="gallery/'.$entry.'/" title="'.$entry.'" rel="shadowbox['.$galleryTitle.']">';
                    $strOutput .= $viewLink.'<img class="'.$imgClass.'" src="'.$dirPath.$entryName.'" alt="'.$entry.'" /></a>
                    ';
            }
        }
        
        $strOutput = $strOutput;
    }
    return $strOutput;
}


function show_gallery($viewPath, $dirPath, $imgClass = '', $ordered = true) {
   if ( $strGallery = get_gallery($viewPath, $dirPath, $imgClass) )
      echo $strGallery;
}

function is_image_extension( $strExtension = '') {
   if ( ($strExtension > '') && in_array( $strExtension, array( 'gif', 'png', 'jpg', 'jpe', 'jpeg' ) ))
      return true;
   return false;
}
?>

As I said, gallerycode.php is included through a call in the template. Then, in the GS admin, I call in gallery.php on the page I want the thumbnails to appear. Trouble is, with GS, the scripts don't work and I can't even begin to understand what it is that migh cause this non-working thing to happen. Now, if it can't be done then it can't be done. But if it's easy enough to spot why it's not working and what needs changing, then I would surely appreciate some help.
Thanks.
There's nothing more foolish than a man chasing his hat.
Reply
#2
Would it be possible for you to send me all the source files and a working example in a zip file? I think I can turn this into a plugin, but I need to see a working example to figure out all the hops and stuff. I am not as good of a developer assume of the others are, but this seems rather easy.
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#3
Thanks for the offer Matthew. I've done some testing with the script on its own (something I should've done in the first place) and the issue seems to revolve around paths. I can't get the script posted above to behave when stand-alone, but I have an older version contained in a single file that does work as stand-alone, as long as the files are placed in the right location relative to the gallery folders and the script. I'll do some more testing to see if I can understand it better and if I can't I may take you up on the offer.
Thanks.
There's nothing more foolish than a man chasing his hat.
Reply
#4
I've got it running within a GS environment. Only problem is paths and I don't see how I can work around that. For example, say I have a page "samples" and want to put a gallery in it, I have to create a folder with the same name and put image folders and the gallery script in it. Ufortunately this will make the page "samples" unnavigateable (since there's a folder with same name, browser will change the url "domain/samples" to "domain/samples/" and expect an index file in it.
So, basically, I'm f***ed.
There's nothing more foolish than a man chasing his hat.
Reply
#5
Judging by your last post, why not change the value of this?

Code:
// Set to the directory that contains galleries
$dirPath = '' . (($galleryDir !== '') ? ($galleryDir . '/') : '') ;

Add a path to this variable so that your galleries are looked for elsewhere and it does'nt mess with your pages.

If you need help with this just pm me.
Reply




Users browsing this thread: 1 Guest(s)