/*
######################### MyGallery 1.7.2 ###########################
### |-----------------------------------------------------------| ###
### | COPYRIGHT 2004 by Lukas Stalder, planetluc.com | ###
### | DO NOT REDISTRIBUTE OR RESELL THIS SCRIPT | ###
### | ANY WAYS WITHOUT MY EXPLICIT PERMISSION! | ###
### | For support use support@planetluc.com but | ###
### | please read README.txt for installation first! | ###
### | Or visit the board at www.planetluc.com | ###
### |-----------------------------------------------------------| ###
#####################################################################
*/
// load config
global $mgConf;
include_once("config.inc.php");
// ********************************************************************
// ********************* DON'T CHANGE BELOW HERE **********************
// ********************************************************************
// xxs preventing
foreach ($_GET as $key => $val){
$_GET[$key] = strip_tags($val);
$_REQUEST[$key] = strip_tags($val);
}
$serverpath = substr(__FILE__, 0, strrpos(__FILE__, "/"));
$mgConf['serverpath'] = $serverpath;
$mgConf['imgdir'] = $mgConf['serverpath']."/images/";
$imgdir = $mgConf['imgdir'];
$me=$_SERVER['PHP_SELF'];
$version="1.8.1";
$now=time();
$logfile=$serverpath."/log.dat.php";
$galfile=$serverpath."/galleries.dat";
$tplfile=$serverpath."/templates.tpl";
$showedit=false;
// ********************** CLASSES/FUNCTIONS **********************
// ***************************************************************
class mdasort {
var $data;//the array we want to sort.
var $sortkeys;//the order in which we want the array to be sorted.
function _sortcmp($a, $b, $i=0) {
$r = strnatcmp($a[$this->sortkeys[$i][0]],$b[$this->sortkeys[$i][0]]);
if ($this->sortkeys[$i][1] == "DESC") $r = $r * -1;
if($r==0) {
$i++;
if ($this->sortkeys[$i]) $r = $this->_sortcmp($a, $b, $i);
}
return $r;
}
function sort() {
if(count($this->sortkeys)) {
usort($this->data,array($this,"_sortcmp"));
}
}
}
function savegals($gal, $galfile){
$fp=fopen($galfile, "w");
ksort($gal);
foreach($gal as $g) fputs($fp, "$g[0]|$g[1]|$g[2]\n");
fclose($fp);
}
function adminloggedin($logfile) {
global $mgConf;
if ($mgConf['is_cmsms_module']){
global $gCms;
if (quick_check_authorship($gCms->variables['content_id'], author_pages(get_userid(false))) &&
get_userid(false) > 0){
return true;
}else{
return false;
}
}else{
include($logfile);
$logged = false;
if (count($admins)>0){
foreach ($admins as $line){
if ($line['hash'] == md5($_REQUEST['mghash'])) $logged = true;
}
}
return $logged;
}
}
function clearoldadmins($logfile, $now) {
global $mgConf;
include($logfile);
if (count($admins)>0){
$i=0;
$fp=fopen($logfile, "w");
fputs($fp, "\n");
foreach ($admins as $line){
if ($now-$line['time'] < $mgConf['adminexpire'])
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
fputs($fp, "?>");
fclose($fp);
}
}
function mkthumbnail($src, $dst, $mode="w", $width, $height, $quality=80, $watermark=false){
$info = getimagesize($src);
$cropmode = false;
global $mgConf;
if ($info[2] == 2){ // if it's jpg
$srcx = 0;
$srcy = 0;
$srcw = $info[0];
$srch = $info[1];
$destw = $width;
$desth = $height;
if ($mode == "w"){
$destw = $width;
$desth = round(($info[1]*$width)/$info[0], 0);
}else if ($mode == "h"){
$desth=$height;
$destw=round(($info[0]*$height)/$info[1], 0);
}else if ($mode == "m"){
// landscape
if ($srcw > $srch){
$destw = $width;
$desth = round(($info[1]*$width)/$info[0], 0);
// portrait
}else{
$desth=$height;
$destw=round(($info[0]*$height)/$info[1], 0);
}
// crop image
}else if ($mode == "c"){
// thumb is square
if ($width == $height){
if ($srcw > $srch) $cropmode = "w";
else $cropmode = "h";
// thumb is landscape
}else if ($width > $height){
$cropmode = "h";
// thumb is portrait
}else{
$cropmode = "w";
}
if ($cropmode == "w"){
$srcw = round(($width*$srch) / $height, 0);
$srcx = floor(($info[0] - $srcw) / 2);
}else if ($cropmode == "h"){
$srch = round(($height*$srcw) / $width, 0);
$srcy = floor(($info[1] - $srch) / 2);
}
}
$src_p=imagecreatefromjpeg($src);
$dst_p=imagecreatetruecolor($destw, $desth);
imagecopyresampled($dst_p, $src_p, 0, 0, $srcx, $srcy, $destw, $desth, $srcw, $srch);
// add watermark
if ($watermark === true && $mgConf['watermarkimg'] != ""){
waterMark($dst_p, $mgConf['watermarkimg']);
}
imagejpeg($dst_p, $dst, $quality);
imagedestroy($src_p);
imagedestroy($dst_p);
return true;
}else return false;
}
function waterMark(&$sourcefile_id, $watermarkfile) {
global $mgConf;
$watermarkfile = $mgConf['serverpath']."/".$watermarkfile;
//Get the resource ids of the pictures
$watermarkfile_id = imagecreatefrompng($watermarkfile);
imageAlphaBlending($watermarkfile_id, false);
imageSaveAlpha($watermarkfile_id, true);
// get destination position of wm image
$dest_x = ($mgConf['watermark_x'] < 0) ? imagesx($sourcefile_id) + $mgConf['watermark_x'] : $mgConf['watermark_x'];
$dest_y = ($mgConf['watermark_y'] < 0) ? imagesy($sourcefile_id) + $mgConf['watermark_y'] : $mgConf['watermark_y'];
imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, imagesx($watermarkfile_id), imagesy($watermarkfile_id));
}
function getpics($gal, $imgdir){
global $mgConf;
$dir="$imgdir$gal";
$dp=opendir($dir);
$pictures= new mdasort;
$i=0;
while ($file=readdir($dp)){
if ($file!="." && $file!=".."){
if (strpos($file, "thumb")===false && $file!="captions.dat"){
$pictures->data[$i]['id']=substr($file, 0, strrpos($file, "."));
$pictures->data[$i]['pic']=$mgConf['pathtoscript']."images/$gal/$file";
if ($mgConf['thumbnails']) $pictures->data[$i]['thumb'] = $mgConf['pathtoscript']."images/$gal/thumb_$file";
$i++;
}
}
}
if ($i>0){
$pictures->sortkeys = array(array('id','ASC'));
$pictures->sort();
return $pictures->data;
}else return false;
}
function getImageName($gal, $name){
global $imgdir, $mgConf;
$name = substr($name, 0, strrpos($name, "."));
$name = strtolower(preg_replace("/[^a-zA-Z0-9]/", "_", $name)).".jpg";
$images = getpics($gal, $imgdir, $mgConf['pathtoscript'], $mgConf['thumbnails']);
if (is_array($images)){
foreach ($images as $img){
// if file exists rename it
if ($img['id'].".jpg" == $name){
$version=1;
$versionext="";
while(file_exists($imgdir.$gal."/".$name)){
$name=substr($name, 0, strrpos($name, "$versionext."))."_$version".substr($name, strrpos($name, "."));
$versionext="_$version";
$version++;
}
}
}
}
return substr($name, 0, strrpos($name, "."));;
}
function getcaps($gal, $imgdir){
$caps=false;
$cappath=$imgdir.$gal."/captions.dat";
if (file_exists($cappath)){
$stuff=file($cappath);
foreach ($stuff as $line){
$cap=explode("|", rtrim($line));
$caps[$cap[0]]=$cap[1];
}
}
return $caps;
}
function nltobr($str){
return str_replace(array("\n", "\r"), array("
", ""), $str);
}
function brtonl($str){
return str_replace("
", "\n", $str);
}
function isBigger($path, $mode, $width, $height){
$img = getimagesize($path);
if ($mode == "w"){
if ($img[0] > $width) return true;
else return false;
}else if ($mode == "h"){
if ($img[1] > $height) return true;
else return false;
}else if ($mode == "c"){
return true;
}else if ($mode == "m"){
// landscape
if ($img[0] > $img[1]){
if ($img[0] > $width) return true;
else return false;
// portrait
}else{
if ($img[1] > $height) return true;
else return false;
}
}
}
function getTemplate($tpl, $html){
$match="/<\!\-\-$tpl\-\->(.*?)<\!\-\-$tpl\-\->/s";
preg_match($match, $html, $tmp);
return $tmp[1];
}
function paging(
$pages,
$pagevar="mgpage",
$ppv=10,
$first ="««« ",
$firsts ="««« ",
$prev ="«« ",
$prevs ="«« ",
$num ="{page}",
$nums ="{page}",
$sep =" | ",
$more ="[...]",
$next =" »»",
$nexts =" »»",
$last =" »»»",
$lasts =" »»»"){
// get URI parameters
$getvars=$_SERVER['PHP_SELF']."?";
foreach ($_GET as $key => $val){
if ($key!=$pagevar){
if (isset($val) && $val!=""){
$getvars.="$key=$val&";
}else{
$getvars.="$key&";
}
}
}
$page=(is_numeric($_GET[$pagevar])) ? $_GET[$pagevar] : 1;
$page=($page>$pages) ? $pages : $page;
$prevpage=($page>1) ? $page-1 : 1;
$nextpage=($page < $pages) ? $page+1 : $pages;
$paging="";
if ($pages>1){
// first
$paging.=($page>1) ? str_replace("{url}", "$getvars$pagevar=1", $first) : $firsts;
// prev
$paging.=($page>1) ? str_replace("{url}", "$getvars$pagevar=$prevpage", $prev) : $prevs;
// pages
$ppvrange=ceil($page/$ppv);
$start=($ppvrange-1)*$ppv;
$end=($ppvrange-1)*$ppv+$ppv;
$end=($end>$pages) ? $pages : $end;
$paging.=($start>1) ? str_replace("{url}", "$getvars$pagevar=".($start-1), $more).$sep : "";
for ($i=1; $i<=$pages; $i++){
if ($i>$start && $i<= $end){
$paging.=($page==$i) ? str_replace("{page}", $i, $nums).(($i<$end) ? $sep : "") : str_replace(array("{url}", "{page}"), array("$getvars$pagevar=$i", $i), $num).(($i<$end) ? $sep : "");
}
}
$paging.=($end<$pages) ? $sep.str_replace("{url}", "$getvars$pagevar=".($end+1), $more) : "" ;
// next
$paging.=($page<$pages) ? str_replace("{url}", "$getvars$pagevar=$nextpage", $next) : $nexts;
// last
$paging.=($page<$pages) ? str_replace("{url}", "$getvars$pagevar=$pages", $last) : $lasts;
}
return $paging;
}
function execTemplate($html){
global $mgConf;
ob_start();
eval("?>".$html."");
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function FtpMkdir($ftpnewDir, $ftpchmod) {
global $mgConf;
// create connection
$ftpconnection = ftp_connect($mgConf['ftpserver']);
// login to ftp server
$ftpresult = ftp_login($ftpconnection, $mgConf['ftpuser'], $mgConf['ftppass']);
// check if connection was made
if ((!$ftpconnection) || (!$ftpresult)) {
return false;
exit();
}else{
ftp_chdir($ftpconnection, $mgConf['ftpimagepath']); // go to destination dir
$ftpcreateDir = @ftp_mkdir($ftpconnection, $ftpnewDir); // create directory
if ($ftpcreateDir == true){
$ftpexecDir = @ftp_site($ftpconnection, 'chmod 0777 '.$ftpnewDir.'/');
}else{
$error.= $txtnodir;
}
if ($ftpexecDir == true){
return true;
}else{
$error.= $txtnochmod;
}
ftp_close($ftpconnection); // close connection
}
}
// **************************** INIT *****************************
// ***************************************************************
if (!isset($_REQUEST['mghash']) || $_REQUEST['mghash']=="") {
srand($now);
for ($i=0; $i<16 ; $i++) $secret.=chr(rand(60, 127));
$secret=md5($secret);
$hash=md5($_SERVER['HTTP_USER_AGENT'].$now.$secret);
}else $hash= $_REQUEST['mghash'];
// append GET vars
$getvars = "";
foreach ($mgConf['getvars'] as $get){
if (isset($_GET[$get]) && $_GET[$get] != ""){
$getvars .= ($getvars != "") ? "&" : "";
$getvars .= $get."=".$_GET[$get];
}
}
$getvars = "?".(($mgConf['phpwcmsalias']!="") ? $mgConf['phpwcmsalias']."&" : "")."mghash=".$hash.(($getvars != "") ? "&".$getvars : "");
clearoldadmins($logfile, $now);
// **************************** ADMIN ****************************
// ***************************************************************
if ($_REQUEST['mgdo']=="admin"){
// if login
if ($_REQUEST['mgaction']=="login"){
if ($_REQUEST['mglogin']==$mgConf['adminlogin'] && $_REQUEST['mgpwd']==$mgConf['adminpwd']){
include($logfile);
$fp=fopen($logfile, "w");
fputs($fp, "\n");
$i=0;
if (count($admins)>0){
foreach ($admins as $line){
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
}
fputs($fp, "\$admins[$i]['time']=".$now."; \$admins[$i]['hash']='".md5($hash)."';\n?>");
fclose($fp);
}
}
if (adminloggedin($logfile)){
// get gallery list from data file
$galleries=false;
if ($gals=file($galfile)){
foreach ($gals as $gal){
$gal= explode('|', rtrim($gal));
$galleries[$gal[0]] = array($gal[0], $gal[1], $gal[2]);
}
krsort($galleries, SORT_NUMERIC);
reset($galleries);
$nextindex=key($galleries)+1;
}else $nextindex=1;
// delete a gallery
if ($_REQUEST['mgaction']=="delete" && is_numeric($_REQUEST['mgid'])){
unset($galleries[$_REQUEST['mgid']]);
savegals($galleries, $galfile);
$dir="$imgdir".$_REQUEST['mgid']."/";
$dp=opendir($dir);
while ($file=readdir($dp)){
if ($file!="." && $file!="..") unlink($dir.$file);
}
closedir($dp);
rmdir($dir);
}
// move gallery upwards or downwards
if ($_REQUEST['mgaction']=="move" && is_numeric($_REQUEST['mgid']) && isset($_REQUEST['mgcmd'])){
$id=$_REQUEST['mgid'];
$cmd=$_REQUEST['mgcmd'];
$keys=array_keys($galleries);
if ($cmd=="up") sort($keys);
else if ($cmd=="down") rsort($keys);
$oid=false;
foreach ($keys as $key){
if ($cmd=="up"){
if ($key>$id){
$oid=$key;
break;
}
}else{
if ($key<$id){
$oid=$key;
break;
}
}
}
if ($oid!==false){
// exchanging the 2 array elements
$galleries[$id][0]=$oid;
$galleries[$oid][0]=$id;
list ($galleries[$id], $galleries[$oid]) = array($galleries[$oid], $galleries[$id]);
savegals($galleries, $galfile);
$tmpdir=$imgdir.$id."_tmp";
rename($imgdir.$id, $tmpdir);
rename($imgdir.$oid, $imgdir.$id);
rename($tmpdir, $imgdir.$oid);
}
}
// save edited gallery
if ($_REQUEST['mgaction']=="savegal" && isset($_REQUEST['mggal'])){
if ($_REQUEST['mggallery']!=""){
$gal=$_REQUEST['mggal'];
// delete pics?
if (is_array($_REQUEST['mgtodel'])){
foreach ($_REQUEST['mgtodel'] as $id => $val){
// delete pic
unlink($imgdir.$gal."/$id.jpg");
if ($mgConf['thumbnails']) unlink($imgdir.$gal."/thumb_$id.jpg");
unset($_REQUEST['mgfilename'][$id]);
}
}
// file renaming
$caps="";
foreach ($_REQUEST['mgfilename'] as $id => $newid){
$ok = true;
if ($id != $newid){
$newid = getImageName($gal, $newid.".jpg");
if (rename($imgdir.$gal."/$id.jpg", $imgdir.$gal."/$newid.jpg")) $ok = true;
else $ok = false;
if (rename($imgdir.$gal."/thumb_$id.jpg", $imgdir.$gal."/thumb_$newid.jpg")) $ok = true;
else $ok = false;
}
$cap = $_REQUEST['mgcap'][$id];
if ($cap!=""){
if ($ok===false) $newid=$id;
$caps.="$newid|".htmlentities($cap, ENT_QUOTES)."\n";
}
}
$fp=fopen($imgdir.$gal."/captions.dat", "w");
fputs($fp, $caps);
fclose($fp);
$galleries[$gal][1]=htmlentities($_REQUEST['mggallery'], ENT_QUOTES);
$galleries[$gal][2]=nltobr(htmlentities($_REQUEST['mgdescr'], ENT_QUOTES));
savegals($galleries, $galfile);
$output= $txtsavedchanges;
}else $output=$txtnoname;
$showedit=true;
}
// save new or edited gallery pictures
if ($_REQUEST['mgaction'] == "upload"){
$error=false;
if (is_numeric($_REQUEST['mggal'])){
$gal=$_REQUEST['mggal'];
$showedit=true;
}else $gal=false;
if ($gal===false && $_REQUEST['mggallery']=="") $error=$txtnozip;
if ($error===false && is_uploaded_file($_FILES['mgfile']['tmp_name']) && $_FILES['mgfile']['size']>0){
// check whether new gallery or adding pics to existing one
if ($gal===false){
// if SAFE_MODE workaround
if ($mgConf['ftp_mkdir'] === true){
FtpMkdir($nextindex);
}else{
if (!mkdir("$imgdir$nextindex", 0777)) $error.=$txtnodir;
}
$galleries[$nextindex]=array($nextindex, htmlentities($_REQUEST['mggallery'], ENT_QUOTES), nltobr(htmlentities($_REQUEST['mgdescr'], ENT_QUOTES)));
krsort($galleries);
savegals($galleries, $galfile);
$i=1;
}else if (is_numeric($gal)){
if ($pictures=getpics($gal, $imgdir, $mgConf['pathtoscript'], $mgConf['thumbnails'])){
foreach ($pictures as $pic){
$ids[]=$pic['id'];
}
rsort($ids);
$i=$ids[0]+1;
}else $i=1;
$nextindex=$gal;
}
$addWatermark = ($_REQUEST['mgwatermark'] == "on") ? true : false;
// handling single jpg upload
if ($_FILES['mgfile']['type']=="image/jpeg" || $_FILES['mgfile']['type']=="image/pjpeg"){
$name = getImageName($nextindex, $_FILES['mgfile']['name']);
if (move_uploaded_file($_FILES['mgfile']['tmp_name'], "$imgdir$nextindex/$name.jpg")){
chmod("$imgdir$nextindex/$name.jpg", 0777);
// thumb image
if ($mgConf['thumbnails']) mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/thumb_$name.jpg", $mgConf['thumbmode'], $mgConf['thumbwidth'], $mgConf['thumbheight'], $mgConf['jpgquality']);
// fullsize image
if (isBigger("$imgdir$nextindex/$name.jpg", $mgConf['imagemode'], $mgConf['imagewidth'], $mgConf['imageheight'])) mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/$name.jpg", $mgConf['imagemode'], $mgConf['imagewidth'], $mgConf['imageheight'], $mgConf['jpgquality'], $addWatermark);
else if ($mgConf['watermarkimg'] != "" && $addWatermark){
$imginfo = getimagesize("$imgdir$nextindex/$name.jpg");
mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/$name.jpg", "w", $imginfo[0], $imginfo[1], $mgConf['jpgquality'], true);
}
}
// handling zip uploads
}else{
// thanks to 'ivugrinec2' from the planetluc.com boards for this zip mod!
include_once ('pclzip.lib.php');
if ($zip = new PclZip($_FILES['mgfile']['tmp_name'])){
if (($list = $zip->listContent()) == 0) {
die($error=$zip->errorInfo(true));
}
$tmpnames = array();
foreach ($list as $row) $tmpnames[] = $row['stored_filename'];
$tmplist = $zip->extract(PCLZIP_OPT_BY_NAME, $tmpnames, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $mgConf['imgdir']."_tmp/");
if ($tmplist == 0) $error=$zip->errorInfo(true);
foreach ($tmpnames as $name){
$newname = getImageName($nextindex, $name);
if (substr($name, -1) != "/" ){
$name = (strpos($name, "/") !== false) ? substr($name, strrpos($name, "/")+1) : $name;
rename($mgConf['imgdir']."_tmp/$name", $mgConf['imgdir']."$nextindex/$newname.jpg");
chmod($mgConf['imgdir']."$nextindex/$newname.jpg", 0777);
// if file is not a jpeg file delet it
$imginfo = getimagesize($mgConf['imgdir']."$nextindex/$newname.jpg");
if (in_array($imginfo['mime'], array("image/jpeg", "image/pjpeg")) === false){
unlink($mgConf['imgdir']."$nextindex/$newname.jpg");
}
// thumb image
if ($mgConf['thumbnails']) mkthumbnail("$imgdir$nextindex/$newname.jpg", "$imgdir$nextindex/thumb_$newname.jpg", $mgConf['thumbmode'], $mgConf['thumbwidth'], $mgConf['thumbheight'], $mgConf['jpgquality']);
// fullsize image
if (isBigger("$imgdir$nextindex/$newname.jpg", $mgConf['imagemode'], $mgConf['imagewidth'], $mgConf['imageheight'])) mkthumbnail("$imgdir$nextindex/$newname.jpg", "$imgdir$nextindex/$newname.jpg", $mgConf['imagemode'], $mgConf['imagewidth'], $mgConf['imageheight'], $mgConf['jpgquality'], $addWatermark);
else if ($mgConf['watermarkimg'] != "" && $addWatermark){
$imginfo = getimagesize("$imgdir$nextindex/$newname.jpg");
mkthumbnail("$imgdir$nextindex/$newname.jpg", "$imgdir$nextindex/$newname.jpg", "w", $imginfo[0], $imginfo[1], $mgConf['jpgquality'], true);
}
}
}
}
}// endif zip handling
}else $error=$txtnozip;
if ($error!==false) $output=$error;
} // end save new or edited gallery pictures
// display admin cp header
echo "
\n";
echo "\n";
echo "\n";
echo "| MyGallery Admin CP | \n";
echo "[$txtlogout] | \n";
echo " \n";
echo " |
\n";
// if in gallery edit mode
if ($showedit || $_REQUEST['mgaction']=="edit"){
$gal=$_REQUEST['mggal'];
echo "\n";
echo "$txtediting ".$galleries[$gal][1]."
\n";
echo " \n";
$caps=getcaps($gal, $imgdir);
$i=1;
$pictures = getpics($gal, $imgdir, $mgConf['pathtoscript'], $mgConf['thumbnails']);
if ($pictures!==false){
echo "\n";
}// endif $pictures!==false
echo " |
\n";
// else in not edit mode
}else{
// upload new gallery form
echo "| \n";
echo " |
\n";
// show gallery list
if($galleries!==false){
echo "$txtexgals
\n";
echo "\n";
echo "\n";
echo "| # | \n";
echo "$txtname | \n";
echo " | \n";
echo " \n";
$i=1;
$bgcol[0]="";
$bgcol[1]="class='mgaltbgcol'";
krsort($galleries);
//print_r($galleries);
foreach($galleries as $gal){
$name = (strlen($gal[1]) > 38) ? substr($gal[1], 0, 38)."..." : $gal[1];
echo "\n";
echo "| $i | \n";
echo "".stripslashes($name)." | \n";
echo "";
echo "$txtup \n";
echo "$txtdown \n";
echo "$txtedit \n";
echo "$txtdelete\n";
echo " | \n";
echo " \n";
$i++;
}
echo " \n";
echo " |
\n";
}
}// endif (not edit mode)
echo "
\n";
// if not logged in -> admin login form
}else{
echo "
 |
|
|
|
\n";
echo "
ëðéñä ìîòøëú ðäåì äâìøéä
\n";
echo "\n";
echo "\n";
//echo "| îòøëú ðéäåì âìøéä-Bar-Man.co.il |
\n";
echo "| \n";
echo "\n";
echo " |
 |
\n";
}
// ***************************** MAIN *****************************
// ****************************************************************
// if not in admin mode
}else{
if ($mgConf['is_cmsms_module'] === true && adminloggedin($logfile)){
echo "$txtadmin
";
}
// get gallery list from data file
$galleries=false;
if ($gals=file($galfile)){
foreach ($gals as $gal){
$gal= explode('|', rtrim($gal));
$galleries[$gal[0]] = array($gal[0], $gal[1], $gal[2]);
}
krsort($galleries, SORT_NUMERIC);
}
// show the gallery list
if (!isset($_REQUEST['mggal'])){
if ($galleries!==false){
// reorganize $galleries array
$foo=$galleries;
$galleries=array();
foreach ($foo as $g) $galleries[]=$g;
// paging
$page=(is_numeric($_REQUEST['mgpage'])) ? $_REQUEST['mgpage'] : 1;
$start= ($page-1) * $mgConf['gpp'];
$numgals=count($galleries);
$pages=ceil($numgals/$mgConf['gpp']);
$paging=paging($pages, "mgpage");
// get template for gallleries list
$tpl=getTemplate("GALLERIES", implode("", file($tplfile)));
$tplrow=getTemplate("ROW", $tpl);
$rows="";
for ($i=$start; $i<($start+$mgConf['gpp']); $i++){
if (is_array($galleries[$i])){
$gal=$galleries[$i];
// get random preview thumbnail
$pictures = getpics($gal[0], $imgdir, $mgConf['pathtoscript'], $mgConf['thumbnails']);
$c=count($pictures);
$imgsrc=$pictures[rand(0, ($c-1))]['thumb'];
$match=array("{urlthumb}", "{title}", "{description}", "{urlgallery}");
$replace=array($imgsrc, stripslashes($gal[1]), $gal[2], $me.$getvars."&mggal=".$gal[0]);
$rows.=str_replace($match, $replace, $tplrow);
}
}
$match= array("/\{paging\}/", "/<\!\-\-ROW\-\->(.*?)<\!\-\-ROW\-\->/s");
$replace= array($paging, $rows);
$html = preg_replace($match, $replace, $tpl);
echo execTemplate($html);
}// endif $galleries!==false)
// show specific gallery
}else{
$gal=$_REQUEST['mggal'];
if ($pictures = getpics($gal, $imgdir)){
$numpics=count($pictures);
// show thumbnails page
if (!isset($_REQUEST['mgid']) && $mgConf['thumbnails']){
// paging
$page = (is_numeric($_REQUEST['mgpage'])) ? $_REQUEST['mgpage'] : 1;
$start = ($page-1) * $mgConf['tpp'];
$end = ($start + $mgConf['tpp'] > $numpics) ? $numpics : ($start + $mgConf['tpp']);
$pages = ceil($numpics/$mgConf['tpp']);
$paging = paging($pages, "mgpage");
// get template for this gallery
$tpl = getTemplate("GALLERY", implode("", file($tplfile)));
$tplpic = getTemplate("PIC", $tpl);
$pictable = "\n";
$i = 0;
$caps = getcaps($gal, $imgdir);
for ($z = $start; $z < $end; $z++){
$pic = $pictures[$z];
$pictable.= "| ";
$match= array("{urlpicture}", "{urlthumb}", "{captionpicture}", "{cycle}");
if ($mgConf['lightbox']) $replace = array($pic['pic'], $pic['thumb'], stripslashes($caps[$pic['id']]), $i );
else $replace= array("$me$getvars&mggal=$gal&mgid=$i&mgcmd=noslide", $pic['thumb'], stripslashes($caps[$pic['id']]), $i);
$pictable.= str_replace($match, $replace, $tplpic);
$pictable.= " | \n";
if (fmod(($i+1), $mgConf['thumbcols'])==0) $pictable.= "
\n";
$i++;
}
$pictable.= "
\n";
$match = array("/\{captiongallery\}/", "/\{urlslideshow\}/", "/\{urlbacktoindex\}/", "/<\!\-\-PIC\-\->(.*?)<\!\-\-PIC\-\->/s", "/\{paging\}/" , "/\{description\}/");
if ($mgConf['fancyslideshow']) $replace = array(stripslashes($galleries[$gal][1]), "#", $me.$getvars, $pictable, $paging, $galleries[$gal][2]);
else $replace = array(stripslashes($galleries[$gal][1]), $me.$getvars."&mggal=$gal&mgid=0", $me.$getvars, $pictable, $paging, $galleries[$gal][2]);
$html = preg_replace($match, $replace, $tpl);
echo execTemplate($html);
// show specific pic
}else {
if (!isset($_REQUEST['mgid'])) $id=0;
else $id=$_REQUEST['mgid'];
$backurl="$me$getvars".(($mgConf['thumbnails']) ? "&mggal=$gal" : "");
if ($id==($numpics-1)) $nexturl=$backurl;
else $nexturl="$me$getvars&mggal=$gal&mgid=".($id+1);
// get caps
$caps=getcaps($gal, $imgdir);
// get template for this picture
$tpl=getTemplate("PICTURE", implode("", file($tplfile)));
$match= array("{captiongallery}", "{info}", "{urlpic}", "{captionpicture}", "{urlbacktoindex}", "{urlnextpicture}", "{urlnextpictureslideshow}");
$replace= array( stripslashes($galleries[$gal][1]),
(($_REQUEST['mgcmd']!="noslide" && $mgConf['slideshow']) ? "$txtnextslide
$txtclickpic" : $txtclickpic),
$pictures[$id]['pic'],
stripslashes($caps[$pictures[$id]['id']]),
$backurl,
$nexturl."&mgcmd=noslide",
$nexturl);
$html = str_replace($match, $replace, $tpl);
echo execTemplate($html);
if ($_REQUEST['mgcmd']!="noslide" && $mgConf['slideshow']) echo "\n";
}
}else echo "$txtback";
}
}
if ($mgConf['is_cmsms_module'] !== true){
echo "
[$txtadmin] :: Powered by MyGallery $version";
}else{
echo "
Powered by MyGallery $version";
}
?>