Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a gallery plugin
#9
I updated the function, moving the JS/CSS script.
That way it only loads the extra JS/CSS files on the pages that has a gallery.

I also attached all the files to this post.
To get everything working you have to edit the path in these files:
jquery.lightbox-0.5.js
jquery.lightbox-0.5.css
meta.php
ex.: ../theme/YOUR-THEME/files/lightbox-ico-loading.gif
Code:
<?php if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
/*
* @File:        functions.php
* @Action:        SG theme

To call the function,
edit the page and add
<?php nQaG("main gallery folder","subfolder with photos"); ?>
in the source.
*/


function nQaG($gallery_dir,$folder){

        // Loads the JS files and CS files into the head
add_action('theme-header','insert_javascript_and_css');
$lines = file("theme/Sg/files/meta.php");
foreach ($lines as $line_num => $line)
{echo $line;}

        // Shortening the address to the gallery folders
$alldir = $gallery_dir."/".$folder."/";
$tndir = $gallery_dir."/".$folder."/tn/";

        // Creating the thumbnail folder if it doesn't exist
if (!is_dir($tndir)) {mkdir($tndir);}

        // Counting all the images in both folders
$img_count = count(glob($alldir."*.{jpg,JPG,jpeg,JPEG}",GLOB_BRACE));
$tn_count = count(glob($tndir."*.{jpg,JPG,jpeg,JPEG}",GLOB_BRACE));

        // Sorting the imagelist
$img_dir_list = glob($alldir."*.{jpg,JPG,jpeg,JPEG}",GLOB_BRACE);
sort($img_dir_list);

        // If there are more images than thumbnails
if ($tn_count < $img_count)
{
        //create thumbnails
    $dir_handle = opendir($alldir);
    foreach($img_dir_list as $imagefile)
    {
        if (!file_exists($tndir.$imagefile)){
            $onlyfile = str_replace($alldir, "", $imagefile);
            $img = imagecreatefromjpeg($alldir.$onlyfile);
            $width = imagesx($img);
            $height = imagesy($img);
            $tn_width = 200;
            $new_height = ceil($tn_width * ($height / $width));
            $tmp = imagecreatetruecolor($tn_width, $new_height);
            imagecopyresized($tmp,$img,0,0,0,0,$tn_width,$new_height,$width,$height);
            imagejpeg($tmp, $tndir.$onlyfile);
        }
    }
}
    // Create and Open the file that holds the gallery content
        $createIndex = "$alldir"."index.php";
        $fh = fopen($createIndex, 'w') or die("can't open file");

    // Write the content
        $stringData = "<div id=\"gallery\">\n<ul>\n";
        fwrite($fh, $stringData);

        foreach($img_dir_list as $imglink){
        $links = str_replace($alldir, "", $imglink);
        fwrite($fh,"<li><a title=\"$gallery_dir\" href=\"../$alldir$links\" ><img class=\"shadows\" src=\"../$tndir$links\" alt=\"$gallery_dir\" /></a></li>\n");
    }
        $stringData = "</ul>\n</div>";
        fwrite($fh, $stringData);
        fclose($fh);
        
    // Include the gallery content in the page
include ($alldir."index.php");
}

?>
Reply


Messages In This Thread
Creating a gallery plugin - by Dialup - 2011-12-28, 20:01:20
Creating a gallery plugin - by RobA - 2011-12-30, 00:14:27
Creating a gallery plugin - by Dialup - 2012-01-03, 23:28:11
Creating a gallery plugin - by Connie - 2012-01-03, 23:44:36
Creating a gallery plugin - by Dialup - 2012-01-04, 00:11:42
Creating a gallery plugin - by n00dles101 - 2012-01-04, 00:41:13
Creating a gallery plugin - by Dialup - 2012-01-04, 06:03:48
Creating a gallery plugin - by Dialup - 2012-01-04, 06:27:45
Creating a gallery plugin - by Dialup - 2012-01-04, 18:30:12



Users browsing this thread: 1 Guest(s)