Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Lightbox not working with ImgBrowz0r

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #28190
    nidhins
    Member

    Hi

    I tried integrating prettyphoto lightbox plugin to the latest version of ImgBrowz0r , someone please tell me whats wrng in the code.

    url
    http://www.rotarytour.com/beta/ImgBrowz0r/index.php

    index.php

    Code:
    1024; $i++)
    $size /= 1024;

    return round($size, 2).’ ‘.$units[$i];
    }

    function get_microtime($microtime=false)
    {
    if ($microtime === false)
    $microtime = microtime();

    list($usec, $sec) = explode(‘ ‘, $microtime);
    return ((float)$usec + (float)$sec);
    }

    $start_timer = microtime();

    // Include class
    require ‘imgbrowz0r.php’;

    // These are all settings (set to default). The settings are not validated since you have to configure everything.
    // There is a chance that ImgBrowz0r stops working if you enter the wrong values.
    $config = array(
    // Directory settings. These are required. Without trailing slash. (required)
    ‘images_dir’ => dirname(__FILE__).’/gallery’,
    ‘cache_dir’ => dirname(__FILE__).’/cache’,

    // Url settings. These are required. Without trailing slash. (required)
    // %PATH% is replaced with the directory location and page number
    ‘main_url’ => ‘http://rotarytour.com/beta/imgbrowz0r/index.php?q=%PATH%’,
    ‘images_url’ => ‘http://rotarytour.com/beta/imgbrowz0r/gallery’,
    ‘cache_url’ => ‘http://rotarytour.com/beta/imgbrowz0r/cache’,

    // Sorting settings (optional)
    ‘dir_sort_by’ => 3, // 1 = filename, 2 = extension (dir), 3 = inode change time of file
    ‘img_sort_by’ => 3, // 1 = filename, 2 = extension (png, gif, etc.), 3 = inode change time of file

    // The sort order settings can have the following values:
    // SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING
    // SORT_ASC = ascending, SORT_DESC = descending
    ‘dir_sort_order’ => SORT_DESC,
    ‘img_sort_order’ => SORT_DESC,

    // Thumbnail settings (optional)
    ‘thumbs_per_page’ => 12, // Amount of thumbnails per page
    ‘max_thumb_row’ => 4, // Amount of thumbnails on a row
    ‘max_thumb_width’ => 200, // Maximum width of thumbnail
    ‘max_thumb_height’ => 200, // Maximum height of thumbnail

    // Time settings (optional)
    ‘time_format’ => ‘F jS, Y’, // Date formatting. Look at the PHP date() for help: http://nl3.php.net/manual/en/function.date.php
    ‘time_zone’ => 0, // Timezone. Example: 1
    ‘enable_dst’ => false, // Daylight saving time (DST). Set this to true to enable it.

    // Misc settings (optional)
    ‘ignore_port’ => false, // Ignore port in url. Set this to true to ignore the port.
    ‘dir_thumbs’ => false, // Show a thumbnail in a category box. Default is false.
    ‘random_thumbs’ => false, // Use random thumbnails for categories. Default is false.
    ‘read_thumb_limit’ => 0 // See README for information about this setting.
    );

    // Start the class
    $gallery = new imgbrowz0r($config);

    // XHTML stuff
    ?>


    jQuery lightbox clone – prettyPhoto – by Stephane Caron

    ImgBrowz0r <?php echo IMGBROWZ0R_VERSION ?>


    init();

    // Generate navigation and statistics. (optional, but remommended)
    // The output of the functions are now assigned to variabled, but
    // you can also call the functions directly.
    $gallery_breadcrumbs = $gallery->breadcrumbs();
    $gallery_pagination = $gallery->pagination();
    $gallery_statistics = $gallery->statistics();

    // Display description of the current directory. (optional)
    echo $gallery->description();

    // Display navigation
    echo ‘

    ‘, “nt”, $gallery_breadcrumbs, “nt”, $gallery_pagination, “nt”, $gallery_statistics, “n”, ‘

    ‘, “nn”;

    // Display images and directories. (required)
    echo $gallery->browse();

    // Display navigation
    echo ‘

    ‘, “nt”, $gallery_pagination, “nt”, $gallery_breadcrumbs, “n”, ‘

    ‘, “nn”;

    // Showing some stats (optional)
    echo ‘

    Processing time: ‘, round(get_microtime(microtime()) – get_microtime($start_timer), 5),
    ‘ && Memory usage: ‘, file_size(memory_get_usage()),
    ‘ && Memory peak: ‘, file_size(memory_get_peak_usage()), ‘

    ‘;

    ?>



    ImgBrowz0r.php

    Code:
    GD is not enabled!

    ‘);

    // Check if all the required values are set
    if (!isset($config[‘images_dir’]) || !isset($config[‘cache_dir’]) || !isset($config[‘main_url’]) ||
    !isset($config[‘images_url’]) || !isset($config[‘cache_url’]))
    exit(‘”images_dir”, “cache_dir”, “main_url”, “images_url” or “cache_url” is not set! Please check your configuration.’);

    // Set configuration
    $this->config = array(
    // Directory settings
    ‘images_dir’ => $config[‘images_dir’],
    ‘cache_dir’ => $config[‘cache_dir’],

    // Url settings
    ‘main_url’ => $config[‘main_url’],
    ‘images_url’ => $config[‘images_url’],
    ‘cache_url’ => $config[‘cache_url’],

    // Sorting settings
    ‘dir_sort_by’ => isset($config[‘dir_sort_by’]) && in_array($config[‘dir_sort_by’], array(1, 2, 3)) ?
    $config[‘dir_sort_by’] : 3,
    ‘dir_sort_order’ => isset($config[‘dir_sort_order’]) ? $config[‘dir_sort_order’] : SORT_DESC,

    ‘img_sort_by’ => isset($config[‘img_sort_by’]) && in_array($config[‘img_sort_by’], array(1, 2, 3)) ?
    $config[‘img_sort_by’] : 3,
    ‘img_sort_order’ => isset($config[‘img_sort_order’]) ? $config[‘img_sort_order’] : SORT_DESC,

    // Thumbnail settings
    ‘thumbs_per_page’ => isset($config[‘thumbs_per_page’]) ? $config[‘thumbs_per_page’] : 12,
    ‘max_thumb_row’ => isset($config[‘max_thumb_row’]) ? $config[‘max_thumb_row’] : 4,
    ‘max_thumb_width’ => isset($config[‘max_thumb_width’]) ? $config[‘max_thumb_width’] : 200,
    ‘max_thumb_height’ => isset($config[‘max_thumb_height’]) ? $config[‘max_thumb_height’] : 200,

    // Time settings
    ‘time_format’ => isset($config[‘time_format’]) ? $config[‘time_format’] : ‘F jS, Y’,
    ‘time_zone’ => isset($config[‘time_zone’]) ? $config[‘time_zone’] * 3600 : 0,
    ‘enable_dst’ => isset($config[‘enable_dst’]) && $config[‘enable_dst’] ? 1 : 0,

    // Misc settings
    ‘ignore_port’ => isset($config[‘ignore_port’]) && $config[‘ignore_port’] ? true : false,
    ‘dir_thumbs’ => isset($config[‘dir_thumbs’]) && $config[‘dir_thumbs’] ? true : false,
    ‘random_thumbs’ => isset($config[‘random_thumbs’]) && $config[‘random_thumbs’] ? true : false,
    ‘read_thumb_limit’ => isset($config[‘read_thumb_limit’]) && is_numeric($config[‘read_thumb_limit’])
    && $config[‘read_thumb_limit’] >= 0 ? $config[‘read_thumb_limit’] : 0
    );

    if (!$this->config[‘random_thumbs’])
    $this->config[‘read_thumb_limit’] = 1;
    }

    public function init()
    {
    // Get current url
    $protocol = !isset($_SERVER[‘HTTPS’]) || strtolower($_SERVER[‘HTTPS’]) == ‘off’ ? ‘http://&#8217; : ‘https://&#8217;;
    $port = !$this->config[‘ignore_port’] && (isset($_SERVER[‘SERVER_PORT’]) && (($_SERVER[‘SERVER_PORT’] != ’80’
    && $protocol == ‘http://&#8217;) || ($_SERVER[‘SERVER_PORT’] != ‘443’ && $protocol == ‘https://&#8217;))
    && !strpos($_SERVER[‘HTTP_HOST’], ‘:’)) ? ‘:’.$_SERVER[‘SERVER_PORT’] : ”;
    $current_url = urldecode($protocol.$_SERVER[‘HTTP_HOST’].$port.$_SERVER[‘REQUEST_URI’]);

    // Regex – extract the path and page number from the URL
    preg_match(‘/^’.str_ireplace(‘%PATH%’, ‘(.*?)’, preg_quote($this->config[‘main_url’], ‘/’)).’$/i’, $current_url, $matches);
    //preg_match(‘/^’.str_ireplace(‘%PATH%’, ‘([A-Za-z0-9 /-_.]+)’, preg_quote($this->config[‘main_url’], ‘/’)).’$/i’,
    // $current_url, $matches);

    // Set current path/directory and page number
    $raw_path = isset($matches[1]) ? trim($matches[1], ” \/nt”) : false;

    if ($raw_path)
    {
    $this->cur_directory = str_ireplace(array(‘<', '>‘, ‘”‘, ”’, ‘&’,’ ;’, ‘..’, ‘%’), ”,
    substr($raw_path, 0, strrpos($raw_path, ‘/’)).’/’);
    $this->cur_page = (int) substr($raw_path, strrpos($raw_path, ‘/’) + 1);
    }
    else
    {
    $this->cur_directory = false;
    $this->cur_page = 1;
    }

    if ($this->cur_directory == ‘0/’ || $this->cur_directory == ‘/’)
    $this->cur_directory = false;

    $dirs = $imgs = array();
    $this->full_path = !$this->cur_directory ? $this->config[‘images_dir’].’/’ : $this->config[‘images_dir’].’/’.$this->cur_directory;

    // Read current directory and put all the directories and images in an array
    if (is_dir($this->full_path))
    {
    $files = scandir($this->full_path);

    // Scan directories and files
    foreach ($files as $file)
    {
    // Directories
    if (is_dir($this->full_path.’/’.$file) && $file != ‘.’ && $file != ‘..’)
    $dirs[] = array(0, $file, ‘dir’, filectime($this->full_path.’/’.$file));

    // Files (images)
    else if (in_array(($image_extension = $this->get_ext($file)), $this->image_types))
    $imgs[] = array(1, $file, $image_extension, filectime($this->full_path.’/’.$file));
    }

    // Sort arrays
    if (($this->count_dirs = count($dirs)) > 0)
    {
    foreach($dirs as $res) $sort_dirs[] = $res[$this->config[‘dir_sort_by’]];
    array_multisort($sort_dirs, $this->config[‘dir_sort_order’], $dirs);
    }

    if (($this->count_imgs = count($imgs)) > 0)
    {
    foreach($imgs as $res2) $sort_files[] = $res2[$this->config[‘dir_sort_by’]];
    array_multisort($sort_files, $this->config[‘dir_sort_order’], $imgs);
    }

    // Calculate pages
    $this->page_count = (int) ceil(($this->count_dirs + $this->count_imgs) / $this->config[‘thumbs_per_page’]);
    $this->cur_page = $this->cur_page > 0 && $this->cur_page <= $this->page_count ? $this->cur_page : 1;

    // Merge and slice arrays
    $this->files = array_slice(
    array_merge($dirs, $imgs),
    ($this->cur_page-1) * $this->config[‘thumbs_per_page’],
    $this->config[‘thumbs_per_page’]);

    $this->count_files = count($this->files);
    }
    else
    $this->status = 404;
    }

    // Reads the gallery directories and files
    public function browse()
    {
    // Check status code and file count
    if ($this->status === 404)
    return ‘

    ‘.”nt”.’

    This directory does not exist!

    ‘.”n”.’

    ‘.”n”;
    else if ($this->count_files === 0)
    return ‘

    ‘.”nt”.’

    There are no images or directories in this directory.

    ‘.
    “n”.’

    ‘.”n”;

    #@set_time_limit(180); // 3 Minutes
    $row_count = 1;

    // Start capturing output
    ob_start();
    echo ‘

    ‘, “nt”, ‘

    ‘, “n”;

    foreach ($this->files as $k => $file)
    {
    if ($file[0] === 1)
    {
    $image_cache_dir = md5($this->cur_directory);
    $image_thumbnail = $image_cache_dir.’/’.$file[3].’_’.$file[1]; // The name of the thumbnail

    // Create the directory where the thumbnail is stored if it doesn’t exist
    if (!is_dir($this->config[‘cache_dir’].’/’.$image_cache_dir))
    mkdir($this->config[‘cache_dir’].’/’.$image_cache_dir, 0777);

    // Generate thumbnail if there isn’t one
    if (!file_exists($this->config[‘cache_dir’].’/’.$image_thumbnail))
    $this->make_thumb($this->cur_directory, $file[1], $image_thumbnail);

    // Image thumbnail markup
    echo “tt”, ‘

    ‘, “n”;
    }
    else
    {
    if ($this->config[‘dir_thumbs’])
    {
    $dir_hash = md5($this->cur_directory.$file[1].’/’);

    // Get a list of thumbnails
    $dir_thumbs = $this->read_cache($dir_hash, $this->cur_directory.$file[1].’/’);

    // Choose a thumbnail to show
    $dir_thumbnail = isset($dir_thumbs[0]) ? ‘ style=”background-image: url(”.$this->config[‘cache_url’].’/’.
    $dir_hash.’/’.$dir_thumbs[(!$this->config[‘random_thumbs’] ? 0 :
    mt_rand(0, count($dir_thumbs)-1))].”)”‘ : null;

    // Directory thumbnail markup
    echo “tt”, ‘

    ‘, “n”;
    }
    else
    {
    // Display a directory without a thumbnail
    echo “tt”, ‘

    ‘, “nnt”, ‘

     

    ‘, “n”, ‘

    ‘, “nn”;

    // Stop capturing output
    return ob_get_clean();
    }

    // Returns the image/directory count
    public function statistics()
    {
    // Check status code
    if ($this->status === 404 || $this->count_files === 0)
    return;

    return ‘

    There ‘.($this->count_dirs !== 1 ? ‘are ‘.$this->count_dirs.’ directories’ : ‘is 1 directory’).
    ‘ and ‘.($this->count_imgs !== 1 ? $this->count_imgs.’ images’ : ‘1 image’).’ in this directory.

    ‘;
    }

    // Generate breadcrumbs
    public function breadcrumbs()
    {
    // Check status code
    if ($this->status === 404)
    return;

    $path_parts = $this->cur_directory ? explode(‘/’, trim($this->cur_directory, ‘/’)) : array();

    // Generate breadcrumb links
    if (isset($path_parts[0]))
    foreach ($path_parts as $k => $part)
    $output[] = ‘
    Breadcrumbs: config[‘main_url’]).
    ‘”>Root
    ‘.(isset($output) ? ‘ / ‘.implode(‘ / ‘, $output) : null).’

    ‘;
    }

    // Generate page navigation
    public function pagination()
    {
    // Check status code and page count
    if ($this->status === 404 || $this->page_count < 2) return; $pages = array(); $cur_dir = $this->cur_directory ? rtrim($this->cur_directory, ‘/’) : 0;
    $current_range = array(($this->cur_page < 5 ? 2 : $this->cur_page – 3), ($this->cur_page + 3 >= $this->page_count ?
    $this->page_count – 1 : $this->cur_page + 3));

    // Previous and next links
    $prev = $this->cur_page > 1 ? ‘cur_page – 1), $this->config[‘main_url’]).
    ‘”>«
    ‘ : null;
    $next = $this->cur_page < $this->page_count ? ‘cur_page + 1),
    $this->config[‘main_url’]).'”>»
    ‘ : null;

    // First and last page
    $first = $this->cur_page === 1 ? ‘1‘ : ‘‘.$this->page_count.’‘ : ‘config[‘main_url’]).'”>’.($x == $this->cur_page ? ‘‘.
    $x.’
    ‘ : $x).’
    ‘;
    }

    return ‘

    Pages: ‘.$prev.’ ‘.$first.($this->cur_page > 5 ? ‘ … ‘ : ‘ ‘).implode(‘ ‘, $pages).
    ($this->cur_page < $this->page_count – 4 ? ‘ … ‘ : ‘ ‘).$last.’ ‘.$next.’

    ‘;
    }

    // Display description of the current directory
    // Html tags are stripped from the description except the following tags:
    //

    , , , ,
    ,

    ,

    and

    public function description()
    {
    if (file_exists($this->full_path.’.desc’))
    return ‘

    ‘;
    }

    // The legendary thumbnail generater
    protected function make_thumb($image_dir, $image_name, $image_thumbnail)
    {
    $image_dir = $image_dir ? $image_dir.’/’ : null;
    $image_info = $this->get_image_info($this->config[‘images_dir’].’/’.$image_dir.’/’.$image_name);

    // Check if file is an supported image type
    if (!in_array($image_info[‘extension’], $this->image_types))
    return false;

    // Open the image so we can make a thumbnail
    if ($image_info[‘type’] === 3)
    $image = imagecreatefrompng($this->config[‘images_dir’].’/’.$image_dir.$image_name);
    else if ($image_info[‘type’] === 2)
    $image = imagecreatefromjpeg($this->config[‘images_dir’].’/’.$image_dir.$image_name);
    else if ($image_info[‘type’] === 1)
    $image = imagecreatefromgif($this->config[‘images_dir’].’/’.$image_dir.$image_name);

    // Calculate new width and height
    $zoomw = $image_info[‘width’] / $this->config[‘max_thumb_width’];
    $zoomh = $image_info[‘height’] / $this->config[‘max_thumb_height’];
    $zoom = ($zoomw > $zoomh) ? $zoomw : $zoomh;

    if ($image_info[‘width’] < $this->config[‘max_thumb_width’] && $image_info[‘height’] < $this->config[‘max_thumb_height’])
    {
    // Preserve the original dimensions of the image is smaller than the maximum height and width
    $thumb_width = $image_info[‘width’];
    $thumb_height = $image_info[‘height’];
    }
    else
    {
    $thumb_width = $image_info[‘width’] / $zoom;
    $thumb_height = $image_info[‘height’] / $zoom;
    }

    // Create an image for the thumbnail
    $thumbnail = imagecreatetruecolor($thumb_width, $thumb_height);

    // Preserve transparency in PNG
    if ($image_info[‘type’] === 3)
    {
    $alpha_color = imagecolorallocatealpha($thumbnail, 0, 0, 0, 127);
    imagefill($thumbnail, 0, 0, $alpha_color);
    imagesavealpha($thumbnail, true);
    }

    // Preserve transparency in GIF images
    else if ($image_info[‘type’] === 1 && ($transparent_index = imagecolortransparent($image)) >= 0)
    {
    $transparent_color = imagecolorsforindex($image, $transparent_index);
    $transparent_index = imagecolorallocate($thumbnail, $transparent_color[‘red’], $transparent_color[‘green’],
    $transparent_color[‘blue’]);
    imagefill($thumbnail, 0, 0, $transparent_index);
    imagecolortransparent($thumbnail, $transparent_index);
    }

    // Copy and resize image
    imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_info[‘width’], $image_info[‘height’]);

    // Save the thumbnail, but first check what kind of file it is
    if ($image_info[‘type’] === 3)
    imagepng($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail);
    else if ($image_info[‘type’] === 2)
    imagejpeg($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail, 85); // 85 is the quality of the Jpeg thumbnail
    else if ($image_info[‘type’] === 1)
    {
    imagetruecolortopalette($thumbnail, true, 256);
    imagegif($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail);
    }

    // Destroy! (cleanup)
    imagedestroy($image);
    imagedestroy($thumbnail);
    }

    // Reads the cache folder for thumbnails. If none is found it makes one thumbnail
    protected function read_cache($cache_path, $category_path)
    {
    $thumbnails = array();

    // Look for thumbnails in the cache dir
    if (is_dir($this->config[‘cache_dir’].’/’.$cache_path))
    {
    $file_count = 0;
    $files = scandir($this->config[‘cache_dir’].’/’.$cache_path);

    foreach ($files as $file)
    {
    if (in_array($this->get_ext($file), $this->image_types))
    {
    $thumbnails[] = $file;
    ++$file_count;

    if ($file_count === $this->config[‘read_thumb_limit’])
    break;
    }
    }
    }
    else
    mkdir($this->config[‘cache_dir’].’/’.$cache_path, 0777);

    // Generate a thumbnail if none is found
    if (!isset($thumbnails[0]))
    {
    $file_count = 0;
    $files = scandir($this->config[‘images_dir’].’/’.$category_path);

    foreach ($files as $file)
    {
    if (in_array($this->get_ext($file), $this->image_types))
    {
    // The name of the thumbnail
    $image_thumbnail = $cache_path.’/’.filectime($this->config[‘images_dir’].’/’.$category_path.’/’.$file).’_’.$file;

    $thumbnails[] = basename($image_thumbnail);
    $this->make_thumb($category_path, $file, $image_thumbnail);

    ++$file_count;

    // Change 1 to a higher number if you want to generate more thumbnails for a directory,
    // but this also takes more time and memory.
    if ($file_count === 1)
    break;
    }
    }
    }

    return $thumbnails;
    }

    // Format unix timestamp to a human readable date
    protected function format_time($timestamp)
    {
    return gmdate($this->config[‘time_format’], ($timestamp + $this->config[‘time_zone’]));
    }

    // Get info from image (width, height, type, extension)
    // http://php.net/manual/en/function.getimagesize.php
    protected function get_image_info($filepath)
    {
    $getimagesize = getimagesize($filepath);

    return array(
    ‘width’ => $getimagesize[0],
    ‘height’ => $getimagesize[1],
    ‘type’ => $getimagesize[2],
    ‘extension’ => $this->get_ext($filepath));
    }

    // Get extension from filename (returns the extension without the dot)
    protected function get_ext($filename)
    {
    // return strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    return strtolower(substr($filename, strrpos($filename, ‘.’) + 1)); // This is a bit faster
    }
    }

    ?>

    Thanks
    Nidhin

#69824
keol
Member

Hi,

Did you solved the problem? I have some problems too.
So if you could post your codes, if they are working – i would be happy :)

Thanks

Kenneth

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.