Did you have any problem with one of the YooTools called YooGallery about pagination. This tools is very beautiful if showing photo album for website. A lot of beautiful different frame, there is very nice slideshow, nice lightbox but why I cant find pagination? Why? I thought I might be missing something or maybe Im to stupid to find out or maybe there is no pagination.

btw find out more about this plugin in

http://tools.yootheme.com/extensions/yoogallery

So I started to ask uncle google about this problem, and I found this forum that giving a very good answer:

http://forum.joomla.org/viewtopic.php?p=1549058

So the guy with nickname: mejim707 modified the php code to allow us to add pagination.

Tested on Joomla 1.1+ and 1.5+ with and without sef rewrites.

How to used it:

first you set yoogallery mambot call to limit the thumbs per page  then add
pagemax=[12]
Replace 12 with whatever number you want.

So, here it goes, open the gallery.php file

change the code into this code:

<?php
/**
* YOOgallery Core
*
* @author    yootheme.com
* @copyright Copyright (C) 2008 YOOtheme. All rights reserved.
* @license    GNU/GPL
*/

// no direct access
defined(’_JEXEC’) or die(’Restricted access’);

jimport(’joomla.filesystem.file’);

if (!class_exists(’YOOThumbnail’)) {
require_once(dirname(__FILE__).’/lib/thumbnail.php’);
}

class YOOGallery {

// gallery params
var $params;

// gallery path
var $path;

// gallery uri
var $uri;

// joomla root
var $jroot;

// joomla uri
var $juri;

function YOOGallery($params) {
$this->params = $params;
$this->jroot  = $params->get(’cfg_jroot’);
$this->juri   = $params->get(’cfg_juri’);
$this->path   = $params->get(’cfg_path’);
$this->uri    = $this->juri.$this->path;
}

function render() {

// init vars
// CUSTOM PAGE MAX
$max       = $this->params->get(’pagemax’, 10);
$src           = ‘/’.trim(trim($this->params->get(’src’, ”)), ‘/’).’/';
$title         = $this->params->get(’title’, ”);
$style         = $this->params->get(’style’, ‘lightbox’);
$effect        = $this->params->get(’effect’, ‘fade’);
$thumb_style   = $this->params->get(’thumb’, ‘default’);
$order         = $this->params->get(’order’, ‘asc’);
$width         = $this->params->get(’width’);
$height        = $this->params->get(’height’);
$resize        = $this->params->get(’resize’, 1);
$count         = $this->params->get(’count’, 0);
$spotlight     = $this->params->get(’spotlight’, 0);
$prefix        = $this->params->get(’prefix’, ‘thumb_’);
$cache_dir     = $this->params->get(’thumb_cache_dir’, ‘thumbs’);
$cache_time    = $this->params->get(’thumb_cache_time’, 1440) * 60;
$rel           = $this->params->get(’rel’, ”);
$load_lightbox = $this->params->get(’load_lightbox’, 1);
$tmpl_style    = dirname(__FILE__).’/tmpl/’.$style.’.php’;
$tmpl_thumb    = dirname(__FILE__).’/tmpl/_thumbnail_’.$thumb_style.’.php’;

// check gd image processing library
if (!YOOThumbnail::check()) {
return $this->getAlertMessage(”PHP GD image processing library is not installed (<a href=\”http://www.php.net/gd\” target=\”_blank\”>http://www.php.net/gd</a>)”);
}

// check thumbnail template files
if (!is_readable($tmpl_style) || !is_readable($tmpl_thumb)) {
return $this->getAlertMessage(”Unable to read the thumbnail style template files”);
}

// check source if directory exists
if (!is_dir($this->jroot.$src)) {
return $this->getAlertMessage(”Unable to find the source directory (”.$this->jroot.$src.”), please check if your source directory exists”);
}

// check source if directory is readable/writable
if (!is_writable($this->jroot.$src)) {
return $this->getAlertMessage(”Unable to read/write the source directory (”.$this->jroot.$src.”), please verify the directory permissions (<a href=\”http://tutorials.yootheme.com/index.php?option=com_mtree&task=viewlink&link_id=122&Itemid=2\” target=\”_blank\”>Go to: Fix permissions tutorial</a>)”);
}

// set thumbnail cache directory
if (!$this->getCacheDirectory($this->jroot.$src.$cache_dir.’/')) {
return $this->getAlertMessage(”Unable to read/write the thumbnail cache directory (”.$this->jroot.$src.$cache_dir.’/’.”), please verify the directory permissions (<a href=\”http://tutorials.yootheme.com/index.php?option=com_mtree&task=viewlink&link_id=122&Itemid=2\” target=\”_blank\”>Go to: Fix permissions tutorial</a>)”);
}

// get thumbnails
$thumbs = $this->getThumbnails($title, $src, $width, $height, $resize, $prefix, $cache_dir, $cache_time, $max);

// no thumbnails found
if (!count($thumbs)) {
return $this->getAlertMessage(”No thumbnails found”);
}

// sort thumbnails
$this->sortThumbnails($thumbs, $order);

// limit thumbnails to count
$count = intval($count);
if ($count > 0 && $count < count($thumbs)) {
$thumbs = array_slice($thumbs, 0, $count);
}

// add css
if ($this->includeOnce(’YOO_GALLERY_CSS’)) {
$document =& JFactory::getDocument();
$document->addStyleSheet($this->uri.’gallery.css.php’);
}

// init template vars
static $gallery_count = 1;
$gallery_id = ‘yoo-gallery-’.$gallery_count++;

// get template output
$html = ”;
ob_start();
include($tmpl_style);
$html = ob_get_contents();
ob_end_clean();

return $html;
}

function getThumbnails($title, $path, $width, $height, $resize, $prefix, $cache_dir, $cache_time, $max) {
$thumbs = array();
$files  = $this->getFiles($this->jroot.$path);

// set default thumbnail size, if incorrect sizes defined
$width  = intval($width);
$height = intval($height);
if ($width < 1 && $height < 1) {
$width  = 100;
$height = null;
}

foreach ($files as $file) {
$filename = basename($file);
$thumb    = $this->jroot.$path.$cache_dir.’/’.$prefix.$filename;

// create or re-cache thumbnail
if (!is_file($thumb) || ($cache_time > 0 && time() > (filemtime($thumb) + $cache_time))) {
$thumbnail = new YOOThumbnail($file);

// set thumbnail size
if ($width && $height) {
$thumbnail->setSize($width, $height);
} elseif ($height) {
$thumbnail->sizeHeight($height);
} else {
$thumbnail->sizeWidth($width);
}

$thumbnail->setResize($resize);
$thumbnail->save($thumb);
}

// if thumbnail exists, add it to return value
if (is_file($thumb)) {

// set image name or title if exsist
if ($title != ”) {
$name = $title;
} else {
$name = JFile::stripExt($filename);
$name = JString::str_ireplace(’_', ‘ ‘, $name);
$name = JString::ucwords($name);
}

// get image info
list($thumb_width, $thumb_height) = @getimagesize($thumb);

$thumbs[] = array(
‘name’         => $name,
‘filename’     => $filename,
‘img’          => $this->juri.ltrim($path, ‘/’).$filename,
‘img_file’     => $file,
‘thumb’        => $this->juri.ltrim($path, ‘/’).$cache_dir.’/’.$prefix.$filename,
‘thumb_width’  => $thumb_width,
‘thumb_height’ => $thumb_height
);
}
}

// BEGIN CUSTOM GELLERY PAGINATION
if($_GET['page']) // Is page defined?
{
$page = $_GET['page']; // Set to the page defined
}else{
$page = 1; // Set to default page 1
}
$pageURL = ‘http’;
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER["SERVER_PORT"] != “80″) {
$pageURL .= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL = str_replace(’&page=’.$page, ”, $pageURL);
$counttotal = count($thumbs); // count records
$newmax = ($counttotal – (($page – 1) * $max));
if ($newmax < $max ) {
$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show
$cur = (($page * $max) – $max); // Work out what results to show
$thumbsPaged = array_slice($thumbs,$cur – $max,$newmax);
} else {
$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show
$cur = (($page * $max) – $max); // Work out what results to show
$thumbsPaged = array_slice($thumbs,$cur – $max,$max);
}
echo ‘<div align=”center” width=”100%” style=”padding-top: 10px;”>’;
if($page > 1){ // is the page number more than 1?
$prev = ($page – 1); // if so, do the following. take 1 away from the current page number
echo ‘<a href=”‘.$pageURL.’&page=’ . $prev . ‘”>< PREV</a>’; // echo a previous page link
}
for($i = 1; $i <= $total_pages; $i++) // for each page number
{
if($page == $i) // if this page were about to echo = the current page
{
echo’<b>’ . $i .’</b> ‘; // echo the page number bold
} else {
echo ‘<a href=”‘.$pageURL.’&page=’ . $i .’”>’ . $i . ‘</a> ‘; // echo a link to the page
}
}
if($page < $total_pages){ // is there a next page?
$next = ($page + 1); // if so, add 1 to the current
echo ‘<a href=”‘.$pageURL.’&page=’ . $next  . ‘”>NEXT ></a>’; // echo the next page link
}
echo ‘</div>’;
return $thumbsPaged;
// END CUSTOM GALLERY PAGINATION
}

function sortThumbnails(&$thumbs, $order) {
usort($thumbs, array(’YOOGallery’, ‘compareThumbnails’));
if ($order == ‘random’) shuffle($thumbs);
if ($order == ‘desc’)   $thumbs =& array_reverse($thumbs);
}

function compareThumbnails($a, $b) {
return strcmp($a['filename'], $b['filename']);
}

function getFiles($path) {
$path   = rtrim($path, ‘/’);
$files  = array();
$ignore = array(’cgi-bin’, ‘.’, ‘..’,’.svn’,’.DS_Store’);
$dh     = @opendir($path);

while (false !== $file = readdir($dh)) {
if (!in_array($file, $ignore) && is_file($path.’/’.$file)) {
$files[] = $path.’/’.$file;
}
}

closedir($dh);
return $files;
}

function getCacheDirectory($path) {
$path = rtrim($path, ‘/’);

if (!is_dir($path)) {
@mkdir($path);
}

return is_dir($path);
}

function getAlertMessage($msg) {
return “<div class=\”alert\”><strong>”.$msg.”</strong></div>\n”;
}

function includeOnce($name) {
if (!defined($name)) {
define($name, true);
return true;
}

return false;
}

}

the result will be like this: (Check the  1 2 3 4 NEXT>)

yougallery

yougallery

Info: :) Dont ask me how in the red hell this code works, php is really not my fields. This is the reason im using joomla to build a website, cos my web programming is crap ehehheehe. Just test and used it, thats all ok.


  • Share/Bookmark