Location: PHPKode > projects > Thickbox Gallery > tbg2/index.php
<?php
//-------------------------------------------------------------------
// index.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
//-------------------------------------------------------------------
ini_set("session.use_trans_sid", false);
session_start();
define("_TBG", 1);

//-------------------------------------------------------------------
// set installed path
// '/' required in the end of the path if not blank
//-------------------------------------------------------------------
$Path = "";

//-------------------------------------------------------------------
// check security issues
//-------------------------------------------------------------------
if(file_exists($Path."install.php")){
	exit("If you have already run the installation script, you must erase that file to continue. If you have not yet gone through the installation script, you better run that first.");
}
if(file_exists($Path."admin.php") && !file_exists($Path."conf/admins.php") && is_writable($Path."conf/")){
	exit("There is the admin.php without your user information. If you do not use the administrator page, delete admin.php. If you use it, access admin.php with your browser in order to create your username and password.");
}

//-------------------------------------------------------------------
// check installation
//-------------------------------------------------------------------
if(!file_exists($Path."conf/settings.php")){
	exit("The setting file does not exist. You need to create conf/settings.php by renaming conf/settings.php.dist or using the install script.");
}

//-------------------------------------------------------------------
// set language
//-------------------------------------------------------------------
$Lang = !empty($_GET["ln"]) ? htmlspecialchars($_GET["ln"]) : "";
if($Lang=="" && isset($_SESSION["language"])){
	$Lang = $_SESSION["language"];
}

//-------------------------------------------------------------------
// include core class and create core object
//-------------------------------------------------------------------
include_once($Path."inc/tbg.class.php");
$Tbg = new tbgMain($Path, $Lang);

//-------------------------------------------------------------------
// include patTemplate and create template object
//-------------------------------------------------------------------
include_once($Path."inc/patTemplate/patTemplate.php");
include_once($Path."inc/patTemplate/patErrorManager.php");
include_once($Path."inc/patTemplate/patError.php");
$Tmpl = new patTemplate();
$Tmpl->applyOutputFilter("Tidy", array("output-xhtml"=>true, "clean"=>true));
if($Tbg->conf["TmplCache"]==1){
	$Tmpl->useTemplateCache("File", array("cacheFolder"=>$Path."tmpl/cache", "lifetime"=>60));
}

//-------------------------------------------------------------------
// include html output class and create html object
//-------------------------------------------------------------------
include_once($Path."inc/output.class.php");
$Html = new tbgOutput();

//-------------------------------------------------------------------
// include extension files
//-------------------------------------------------------------------
$ext_folder = $Path."ext/";
if($ext_handle=opendir($ext_folder)){
	while(false!==($ext_file=readdir($ext_handle))){
		$ext_path = $ext_folder.$ext_file;
		if(!is_dir($ext_path) && $ext_file!="index.html"){
			include_once($ext_path);
		}
	}
	closedir($ext_handle);
}

//-------------------------------------------------------------------
// set some variables
//-------------------------------------------------------------------
$ANum = -1;
if(isset($_GET["a"])){
	$ANum = intval($_GET["a"]);
	if($ANum<0){
		$ANum = -1;
	}
}
$PNum = !empty($_GET["p"]) ? intval($_GET["p"]) : 1;
if($PNum==0){
	$PNum = 1;
}
$Action = !empty($_REQUEST["z"]) ? htmlspecialchars($_REQUEST["z"]) : "";
$Js = "";
if(isset($_POST["tbg-js-selector"])){
	$Js = intval($_POST["tbg-js-selector"]);
}
$Js = $Tbg->get_js_library($Js);
$ThisUrl = $Tbg->get_proper_url($ANum, "", "", $PNum, "", "", false);

$Message = "";

//-------------------------------------------------------------------
// output...
//-------------------------------------------------------------------
if($Action!=""){
	$Filename = !empty($_REQUEST["v"]) ? htmlspecialchars($_REQUEST["v"]) : "";
	$Text = !empty($_REQUEST["v1"]) ? trim(htmlspecialchars($_REQUEST["v1"])) : "";
	$Number = !empty($_REQUEST["v2"]) ? intval($_REQUEST["v2"]) : 0;
	if($Action=="description"){
		$Tbg->add_description($ANum, $Filename, $Text);
		exit();
	}elseif($Action=="download"){
		$Messsage = $Tbg->download_file($ANum, $Filename);
		if($Message!=""){
			$Html->output_album($ANum, $PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
		}
		exit();
	}elseif($Action=="refresh"){
		$Message = $Tbg->refresh_thumbnail($ANum, $Filename);
	}elseif($Action=="rotate"){
		if($Number!=0){
			$Message = $Tbg->rotate_image($ANum, $Filename, $Number);
		}
	}elseif($Action=="delete"){
		$Message = $Tbg->delete_file($ANum, $Filename);
	}elseif($Action=="move"){
		$Message = $Tbg->move_file($ANum, $Number, $Filename);
	}elseif($Action=="upload"){
		$Message = $Tbg->upload_file($ANum);
	}elseif($Action=="print"){
		$Html->output_printable($ANum, $Tbg, $Tmpl);
		exit();
	}elseif($Action=="atom"){
		$Html->output_atom($ANum, $Tbg, $Tmpl);
		exit();
	}else{
		$Message = $Tbg->langs["alert_bad_action"];
		if($ANum==-1){
			$Html->output_front($PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
		}else{
			$Html->output_album($ANum, $PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
		}
		exit();
	}
	if($Message!=""){
		$Html->output_album($ANum, $PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
	}else{
		header("location: ".$ThisUrl);
	}
}else{
	if($ANum==-1){
		$Html->output_front($PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
	}else{
		$Html->output_album($ANum, $PNum, $Js, $Tbg, $Tmpl, $ThisUrl, $Message, false);
	}
}
Return current item: Thickbox Gallery