Location: PHPKode > projects > Thickbox Gallery > tbg2/ext/ext.inc.php
<?php
//-------------------------------------------------------------------
// ext.inc.php - Thickbox Gallery 2
// Copyright (c) 2006-2009 Yuji Takenaka <hide@address.com>
// Licensed under the MIT:
// http://www.opensource.org/licenses/mit-license.php
//-------------------------------------------------------------------
defined( "_TBG" ) or exit( "Direct access to this location is not allowed." );

//-------------------------------------------------------------------
// 1. create your function which name must start with "ext_"
// 2. add patTemplate variable same as the function name
//    in your template files
//-------------------------------------------------------------------
function ext_random_pick(){
	global $Tbg, $Js;

	$output = "";
	$limit = 5;
	$ok = false;
	$contents = $Tbg->get_gallery_content();
	for($i=0;$i<$limit;$i++){
		$n = array_rand($contents);
		$anum = $contents[$n]["anum"];
		$images = $Tbg->get_files($anum, 1, $Js, true);
		if(count($images)>0){
			$ok = true;
			break;
		}
	}
	if($ok){
		$inum = array_rand($images);
		$box_width = $images[$inum]["thumb"]["width"];
		$output = "<h4>".$Tbg->langs["term_random_pick"]."</h4>";
		$output .= "<div class=\"tbg-random-pick\">";
		$output .= "<div class=\"tbg-random-out\" style=\"width: ".($box_width+12)."px;\"><div class=\"tbg-random-in\" style=\"width: ".$box_width."px;\"><a href=\"".$contents[$n]["path"]."\">";
		$output .= "<img src=\"".$images[$inum]["thumb"]["path"]."\" alt=\"Random Pick\" width=\"".$images[$inum]["thumb"]["width"]."\" height=\"".$images[$inum]["thumb"]["height"]."\" />";
		$output .= "</a></div></div></div>";
	}
	return $output;
}

function ext_welcome_photo(){
	global $Tbg, $Js;

	$output = "";
	$limit = 5;
	$ok = false;
	$contents = $Tbg->get_gallery_content();
	for($i=0;$i<$limit;$i++){
		$n = array_rand($contents);
		$anum = $contents[$n]["anum"];
		$images = $Tbg->get_files($anum, 1, $Js, true);
		if(count($images)>0){
			$ok = true;
			break;
		}
	}
	if($ok){
		$ok = false;
		for($i=0;$i<$limit;$i++){
			$inum = array_rand($images);
			if(isset($images[$inum]["disp"]["path"]) && $images[$inum]["disp"]["path"]!=""){
				$ok = true;
				break;
			}
		}
		if($ok){
			$box_width = $images[$inum]["disp"]["width"];
			$output .= "<div class=\"tbg-random-pick\">";
			$output .= "<div class=\"tbg-random-out\" style=\"width: ".($box_width+12)."px;\"><div class=\"tbg-random-in\" style=\"width: ".$box_width."px;\"><a href=\"".$contents[$n]["path"]."\">";
			$output .= "<img src=\"".$images[$inum]["disp"]["path"]."\" alt=\"Welcome Photo\" width=\"".$images[$inum]["disp"]["width"]."\" height=\"".$images[$inum]["disp"]["height"]."\" />";
			$output .= "</a></div></div></div>";
		}
	}
	return $output;
}
Return current item: Thickbox Gallery