"; echo "
"; echo " Welcome to phpAlbum_$phpalbum_version
"; echo " You have to edit config_change_it.php and rename it to config.php.
"; echo " You have to define data directory, because of security issues it is recommended that this is not data/ but"; echo " something like \"data_Ab6Lkj88KJ/\""; echo "
"; generate_footer(); return; } if ( !check_writable($data_dir)){ //generate_header(); echo ""; echo "
"; echo " Welcome to phpAlbum_$phpalbum_version
"; echo "Your data directory $data_dir is eather not existing or not writable
"; echo "Please check for existing of this directory and setup the access rights with CHMOD 777"; echo "
"; generate_footer(); return; } $pa_setup=Array(); $pa_quality=Array(); $pa_theme=Array(); $pa_lang=Array(); $pa_color_map=Array(); $themes_dir="themes/"; //$quality_settings = Array(); //$theme_params= Array(); $phpalbum_version="0.4.1"; $site_engine="phptemplate"; $act_dir_sorting="default"; /* header buffering */ $sent_header=Array(); /*testing for modules*/ if(function_exists("ftp_login")){ $ftp_support=true; }else{ $ftp_support=false; } if(function_exists("mb_get_info")){ $mbstring=true; $_mb_info=mb_get_info('all'); if(isset($_mb_info['internal_encoding'])){ $int_encoding=$_mb_info['internal_encoding']; }else{ $int_encoding='ISO-8859-1';//default } }else{ $mbstring=false; } error_reporting(E_WARNING | E_ERROR); $old_error_handler = set_error_handler("userErrorHandler"); $error_logging=true; function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { global $data_dir,$error_logging; // timestamp for the error entry if($error_logging){ $dt = date("y/m/d H:i:s"); // define an assoc array of error string // in reality the only entries we should // consider are E_WARNING, E_NOTICE, E_USER_ERROR, // E_USER_WARNING and E_USER_NOTICE $errortype = array ( E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parsing Error", E_NOTICE => "Notice", E_CORE_ERROR => "Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", E_COMPILE_WARNING => "Compile Warning", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice", E_STRICT => "Runtime Notice" ); // set of errors for which a var trace will be saved //$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); if($errno==E_NOTICE || $errno==E_STRICT){ return; } $err = "\$phpalbum_Errors[]= Array(\"datetime\" => \"$dt\","; $err .= "\"errornum\" => \"$errno\","; $err .= "\"errortype\" => \"".$errortype[$errno]."\","; $err .= "\"errormsg\" => \"$errmsg\","; $err .= "\"scriptname\" => \"$filename\","; $err .= "\"scriptlinenum\" => \"$linenum\""; $err .= ");"; if(file_exists($data_dir."error.log")){ if(filesize($data_dir."error.log")>1024*1024*2){ unlink($data_dir."error.log"); } } $ff=fopen($data_dir."error.log","a"); fwrite($ff,"\n"); fclose($ff); } } function pa_readfile($path){ /*fixed bug where if readfile disabled phpAlbum doesn't work*/ if(!function_exists("readfile")){ $file=fopen($path,"rb"); $doc=fread($file,filesize($path)); fclose($file); echo $doc; }else{ readfile($path); } } function conv_out($string){ global $pa_setup,$mbstring,$pa_lang; if($mbstring){ return mb_convert_encoding($string,$pa_lang["character_set"]); }else{ return $string; } } function prepit($text){ //prepare text from db to be in input type="text" return str_replace('"','"',$text); } function prepdb($text){ //adding slash for all but " $ret=addslashes($text); $ret=str_replace('\"','"',$ret); return $ret; } function conv_in($string){ global $pa_setup,$int_encoding,$mbstring,$pa_lang; if($mbstring){ return mb_convert_encoding($string,$int_encoding,$pa_lang["character_set"]); }else{ return $string; } } function conv_out_header ($string){ global $pa_setup,$mbstring,$pa_lang; if($mbstring){ return mb_encode_mimeheader($string,$pa_lang["character_set"]); }else{ return $string; } } function send_header($text){ global $sent_header; header($text); $sent_header[]=$text; /*store for later use*/ } function store_header($file_name){ global $sent_header; if(is_array($sent_header)){ $f=fopen($file_name,"w"); foreach($sent_header as $header){ fwrite($f,$header."\n"); } fclose($f); } } function resend_header($file_name){ $file=file($file_name); foreach($file as $line){ header(substr($line,0,strlen($line)-1)); } } function sent_header(){ global $sent_header; if(sizeof($sent_header)>0){ return true; }else{ return false; } } /*assertion*/ /****************************************/ /* Functions */ /****************************************/ function UnsharpMask($img, $amount, $radius,$threshold) { //////////////////////////////////////////////////////////////////////////////////////////////// //// //// Unsharp Mask for PHP - version 2.0 //// //// Unsharp mask algorithm by Torstein H?nsi 2003-06. //// thoensi_at_netcom_dot_no. //// Please leave this notice. //// /////////////////////////////////////////////////////////////////////////////////////////////// // $img is an image that is already created within php using // imgcreatetruecolor. No url! $img must be a truecolor image. // Attempt to calibrate the parameters to Photoshop: if ($amount > 500) $amount = 500; $amount = $amount * 0.016; if ($radius > 50) $radius = 50; $radius = $radius * 2; $radius = abs(round($radius)); // Only integers make sense. if ($radius == 0) return $img; $w = imagesx($img); $h = imagesy($img); $imgBlur = imagecreatetruecolor($w, $h); // Gaussian blur matrix: // // 1 2 1 // 2 4 2 // 1 2 1 // ////////////////////////////////////////////////// imagecopy($imgBlur, $img, 0, 0, 0, 0, $w, $h); // background for ($i = 0; $i < $radius; $i++) { if (function_exists('imageconvolution')) { // PHP >= 5.1 $matrix = array( array( 1, 2, 1 ), array( 2, 4, 2 ), array( 1, 2, 1 ) ); imageconvolution($imgCanvas, $matrix, 16, 0); } else { // Move copies of the image around one pixel at the time and merge them with weight // according to the matrix. The same matrix is simply repeated for higher radii. imagecopy ($imgBlur, $img, 0, 0, 1, 1, $w - 1, $h - 1); // up left imagecopymerge ($imgBlur, $img, 1, 1, 0, 0, $w, $h, 50); // down right imagecopymerge ($imgBlur, $img, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left imagecopymerge ($imgBlur, $img, 1, 0, 0, 1, $w, $h - 1, 25); // up right imagecopymerge ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 25); // right imagecopymerge ($imgBlur, $img, 0, 0, 0, 1, $w, $h - 1, 20 ); // up imagecopymerge ($imgBlur, $img, 0, 1, 0, 0, $w, $h, 16.666667); // down imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center // During the loop above the blurred copy darkens, possibly due to a roundoff // error. Therefore the sharp picture has to go through the same loop to // produce a similar image for comparison. This is not a good thing, as processing // time increases heavily. // imagecopy ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h); /* imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20 ); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667); imagecopymerge ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50); imagecopy ($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h); */ } } // Calculate the difference between the blurred pixels and the original // and set the pixels for ($x = 0; $x < $w; $x++) { // each row for ($y = 0; $y < $h; $y++) { // each pixel $rgbOrig = ImageColorAt($img, $x, $y); $rOrig = (($rgbOrig >> 16) & 0xFF); $gOrig = (($rgbOrig >> 8) & 0xFF); $bOrig = ($rgbOrig & 0xFF); $rgbBlur = ImageColorAt($imgBlur, $x, $y); $rBlur = (($rgbBlur >> 16) & 0xFF); $gBlur = (($rgbBlur >> 8) & 0xFF); $bBlur = ($rgbBlur & 0xFF); // When the masked pixels differ less from the original // than the threshold specifies, they are set to their original value. $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig; $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig; $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig; if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew); ImageSetPixel($img, $x, $y, $pixCol); } } } return $img; } function imagecreatefrom($file){ if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){ $image=imagecreatefromjpeg($file); } if(strtoupper(substr($file,-3,3))=="PNG"){ $image=imagecreatefrompng($file); } if(strtoupper(substr($file,-3,3))=="GIF"){ $image=imagecreatefromgif($file); } return $image; } function image_same_type($file,$image,$quality = 100){ if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){ imagejpeg($image,null,$quality); } if(strtoupper(substr($file,-3,3))=="PNG"){ imagepng($image); } if(strtoupper(substr($file,-3,3))=="GIF"){ imagegif($image); } } function check_gd(){ if(function_exists("gd_info")){ $info=gd_info(); if(strstr($info['GD Version'],"2.")){ return true; }else{ return false; } } return false; } function string2store($string){ $str=str_replace("\n","",$string); $str=str_replace("\r","",$str); return $str; } function store2string($string){ $str=str_replace("","\n",$string); return $str; } function pa_html_encode($string){ return str_replace( array ( '&', '"', "'", '<', '>'), array ( '&' , '"', ''' , '<' , '>' ),$string); } function pa_html_decode($string){ return str_replace( array ( '&' , '"', ''' , '<' , '>' ),array ( '&', '"', "'", '<', '>'),$string); } /****************************************/ /* SETTINGS */ /****************************************/ function read_settings(){ global $pa_setup,$pa_theme,$pa_color_map,$pa_lang; $rec=db_select_all("setup"); $pa_setup=$rec[0]; $rec=db_select_all("theme","name=='".$pa_setup["site_theme"]."'"); if(count($rec)==0){ //used new theme, never used before db_insert("theme",Array( "name"=>$pa_setup["site_theme"])); $rec=db_select_all("theme","name=='".$pa_setup["site_theme"]."'"); } $pa_theme=$rec[0]; $rec=db_select_all("color_map","id==".$pa_theme["color_map"]); $pa_color_map=$rec[0]; $rec=db_select_all("languages","name=='".$pa_setup["language"]."'"); $pa_lang=$rec[0]; //echo db_get_last_error_text(); } function print_error($error,$par=null){ //echo "
$error
"; if($par){ printf("
".$error."
",$par); }else{ printf("
".$error."
"); } } function print_warning($error){ echo "
WARNING:$error
"; } function get_password_for_cmd($cmd,$var1){ global $setup_password,$demo_functionality; global $album_dir,$passwd; if (!strcmp($cmd,"setup")){ return $setup_password; } if (!strcmp($cmd,"delcache")){ return $setup_password; } if (!strcmp($cmd,"phpinfo")){ return $setup_password; } if( !strcmp($cmd,"album") || !strcmp($cmd,"image") || !strcmp($cmd,"imageview") || !strcmp($cmd,"thmb")){ if( $cmd!="album" ){ $var1=dirname($var1); } $dirs=explode("/",$var1); $dir=""; $sett=get_directory_settings($dir,0); if(strlen($sett[0][1])>0 && !strstr($passwd,$sett[0][1])){ return $sett[0][1]; } foreach($dirs as $num => $file){ $dir=$dir."/".$file; $sett=get_directory_settings($dir,0); // echo $dir." ".$sett[0][1]."
"; if(strlen($sett[0][1])>0 && !strstr($passwd,$sett[0][1])){ return $sett[0][1]; } } } return ""; } function generate_password_page($cmd,$var1="",$var2=""){ $content="
"; if (strlen($var2)>0){ $content.= t("ID_ENTER_PASSWD")."
"; }else{ $content.= t("ID_ENTER_PASSWD").""; } $content.= "
"; $content.= ""; theme_generate_setup_page($content); } function get_dir_size($dir){ $list = dir($dir); $size=0; if($list){ while ($filename = $list->read()){ if ($filename == '.' || $filename == '..') continue; $size=$size+filesize($dir.$filename); } } return $size; } function is_cachable($text,$var1){ global $pa_setup; if ($text == "logo" || $text == "themeimage") return true; if ($text == "theme") return false; if ($text == "image") { if($pa_setup["cache_resized_photos"]=="true"){ return true;}else{ return false;} } if ($text == "setup") return false; if ($text == "delcache") return false; if ($text == "setquality") return false; if ($text == "album") return false; if ($text == "imageview") return false; if ( strlen($text)==0) return false; if ($text == "thmb"){ if($pa_setup["cache_thumbnails"]=="true"){ return true;}else{ return false;} } return false; } function is_movie($var1){ $t=strtoupper(substr($var1,-3,3)); $t2=strtoupper(substr($var1,-4,4)); if($t=="AVI" ||$t=="MPG" ||$t2=="MPEG" ||$t=="MOV" ||$t=="WMV" ||$t=="VOB") return true; return false; } function is_audio($var1){ $t=strtoupper(substr($var1,-3,3)); if($t=="MP3" ||$t=="WMA" ||$t=="WAV") return true; return false; } function is_image($var1){ $t=strtoupper(substr($var1,-3,3)); $t2=strtoupper(substr($var1,-4,4)); if($t=="GIF" ||$t=="PNG" ||$t=="JPG" ||$t2=="JPEG") return true; return false; } function is_cached($cmd,$var1,$var2,$var3,$quality){ global $pa_setup; $cache_dir=$pa_setup["cache_dir"]; //return false; $fn=get_cache_file_name($cache_dir,$cmd,$var1,$var2,$var3,$quality); return file_exists($fn); } function load_from_cache($cmd,$var1,$var2,$var3,$quality){ global $pa_setup; $cache_dir=$pa_setup["cache_dir"]; $fn=get_cache_file_name($cache_dir,$cmd,$var1,$var2,$var3,$quality); /*$file=fopen($fn,"rb"); $doc=fread($file,filesize($fn)); fclose($file); echo $doc;*/ if($cmd == "thmb" || $cmd == "logo" || $cmd == "dir_logo" || $cmd == "image" ){ //$headers=getallheaders();-- not supported by others then apache if (isset( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ){ if ( date("D, d M Y H:i:s T",filemtime($fn)) == $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) { header('HTTP/1.0 304 Not Modified'); exit; } } } if(file_exists($fn.".hdr")){ resend_header($fn.".hdr"); } pa_readfile($fn); } function get_cache_file_name($cache_dir,$cmd,$var1,$var2,$var3,$quality){ $filename=$cache_dir . "cache_"; $filename.=$cmd; $filename.="_".str_replace(" ","_",str_replace("/","_",$var1)); $filename.="_".str_replace(" ","_",str_replace("/","_",$var2)); $filename.="_".str_replace(" ","_",str_replace("/","_",$var3)); $filename.="_".$quality; $filename.=".cache"; return $filename; } function get_data_file_name($var1){ global $data_dir; $filename.=$data_dir."_".str_replace(" ","_",str_replace("/","_",$var1)); return $filename; } function cache_document($cmd,$var1,$var2,$var3,$quality){ global $pa_setup; $cache_dir=$pa_setup["cache_dir"]; $doc=ob_get_contents(); //echo ob_get_length(); $filename=get_cache_file_name($cache_dir,$cmd,$var1,$var2,$var3,$quality); //echo $filename; $file=fopen($filename,"wb"); fwrite($file,$doc); fclose($file); $m_time= filemtime($filename); send_header("Last-Modified: ".date("D, d M Y H:i:s T",$m_time) ); if(sent_header()){ /*cache header*/ store_header($filename.".hdr"); } } function generate_header() { global $logo_path,$logo_enabled,$site_name,$site_theme,$theme_params,$phpalbum_version,$character_set; include '../header.inc'; // send_header("Content-type: text/html; charset=$character_set"); // echo ''; // echo "\n$site_name"; // echo ""; } function get_file_for_screenshot($scr,$dw){ $scr_base=substr($scr,0,strlen($scr)-4); foreach($dw as $file){ if(!is_image($file)){ if($scr_base==$file || $scr_base."."== substr($file,0,strlen($scr_base."."))){ return $file; } } } return ""; } function get_screanshot_for_file($file,$fl){ foreach($fl as $scr){ if( is_image($scr)){ $scr_base=substr($scr,0,strlen($scr)-4); if($scr_base==$file || $scr_base."." == substr($file,0,strlen($scr_base."."))){ return $scr; } } } return ""; } function get_thmb_standard_link($file){ global $pa_quality; if($pa_quality["thmb_sharp_use"]=='true'){ $sharpen_str="_".$pa_quality["thmb_sharp_amount"]."_".$pa_quality["thmb_sharp_radius"]."_".$pa_quality["thmb_sharp_treshold"]; }else{ $sharpen_str=""; } return "main.php?cmd=thmb&var1=". urlencode($file)."&var2=".$pa_quality["thmb_size"]."_".$pa_quality["thmb_qual"]."_".$pa_quality["square_thumbnails"].$sharpen_str; } function get_thmb_dir_link($file){ global $pa_quality,$pa_theme; if($pa_quality["thmb_sharp_use"]=='true'){ $sharpen_str="_".$pa_quality["thmb_sharp_amount"]."_".$pa_quality["thmb_sharp_radius"]."_".$pa_quality["thmb_sharp_treshold"]; }else{ $sharpen_str=""; } if($pa_theme["dir_logo_style"]=="pic_other_size"){ return "main.php?cmd=thmb&var1=". urlencode($file)."&var2=".$pa_theme["dir_logo_size"]."_".$pa_theme["dir_logo_quality"]."_".$pa_theme["dir_logo_square_thumbnail"].$sharpen_str."_".$pa_color_map["bg_color"]."&var3=DIR"; }else{ return "main.php?cmd=thmb&var1=". urlencode($file)."&var2=".$pa_quality["thmb_size"]."_".$pa_quality["thmb_qual"]."_".$pa_quality["square_thumbnails"].$sharpen_str."_".$pa_color_map["bg_color"]."&var3=DIR"; } } function check_access_to_dir($dir){ global $pa_user; if(isset($pa_user["groups"]["superuser"])){ return true; } $sett_1=get_directory_settings($dir,0); $sett=$sett_1[0]; if((!is_array($sett["groups"]) || count($sett["groups"])==0) && (!is_array($sett["inh_groups"]) || count($sett["inh_groups"])==0)){ return true;} if(is_array($pa_user["groups"])){ foreach($sett["groups"] as $key => $value){ if(isset($pa_user["groups"][$key])){ return true; } } foreach($sett["inh_groups"] as $key => $value){ if(isset($pa_user["groups"][$key])){ return true; } } return false; }else{ if(count($sett["groups"])>0){ return false; } } return true; } function generate_album($var1,$passwd,$start_with=0){ global $pa_setup,$pa_quality,$pa_theme,$pa_color_map; global $act_dir_sorting; if ($pa_theme["directory_style"]=="flowing"){ $number_of_thmbs=$pa_theme["maximum_photos_per_page"]; }else{ $number_of_thmbs=$pa_theme["raster_dir_x"]*$pa_theme["raster_dir_y"]; } if($number_of_thmbs==0 || $number_of_thmbs<0){ $number_of_thmbs=1000000;/*i hope nobody will make more then million photos in one dir, if yes, i'm sorry :)*/ } $ss=get_directory_settings("/".$var1); $dir_settings=$ss[0]; $files_settings=$ss[1]; if(isset($dir_settings["sorting"])){ $act_dir_sorting=$dir_settings["sorting"]; } $act_dir_sorting=$dir_settings["sorting"]; if($act_dir_sorting=='default'){ $act_dir_sorting=$pa_setup["default_sorting"]; } $dir_path[0]['name']=t('ID_PHOTO_DIR'); $dir_path[0]['link']="main.php?cmd=album"; $dirs=explode('/',$var1); $act_dir=""; for($i=0;$i0){ $dir_path[$i+1]['name']=pa_html_decode($ss[0][4]); }else{ $dir_path[$i+1]['name']=conv_out($dirs[$i]); } $dir_path[$i+1]['link']="main.php?cmd=album&var1=".urlencode($act_dir); } $qualities=db_select_all("quality","enabled=='true'"); // select all enabled qualities $quality_links=Array(); if(count($qualities)>1){ foreach($qualities as $key=>$val){ $quality_links[]=Array("name"=>$val["name"], "link"=>"main.php?cmd=setquality&var1=".$val["id"]."&var2=album&var3=".urlencode($var1)."&var4=$start_with", "actual" => ($val["id"]==$pa_quality["id"])?1:0 ); } } $dir=$pa_setup["album_dir"] . $var1; /*directory description*/ $dir_long_desc=store2string(pa_html_decode($dir_settings["long_desc"])); /*openning directories*/ if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if( filetype($dir . $file)=="dir" ) { if($file !="." && $file !=".."){ $sett_all=get_directory_settings($var1.$file,0); $sett=$sett_all[0]; if($sett["visibility"]=="true" && check_access_to_dir($var1.$file)){ //visible if(strlen($sett["alias"])>0){ $name=$sett["alias"]; }else{ $name=$file; } $file_array=Array("filename"=>$file,"time"=>filectime($dir . $file),"name"=>$name,"desc"=>$sett["desc"]); $filelist[]=$file_array; } } } } closedir($dh); $directories=Array(); $directories_cnt=0; if(sizeof($filelist)>0){ usort($filelist,"file_array_cmp"); while ( list($key,$file_array)=each($filelist)){ /*visibility*/ $file=$file_array['filename']; $blocked=false; $rec=get_directory_settings("/".$var1.$file); $under_dir_sett=$rec[0]; if(strlen(get_password_for_cmd("album",$var1.$file))>0){ if(!strstr($passwd,get_password_for_cmd("album",$var1.$file))){ $blocked=true;}; } if( $blocked ){ $dir_pic="main.php?cmd=themeimage&var1=dir_passwd.png&var2=".$pa_color_map["bg_color"]; $directories[$directories_cnt]['stat']='PASSWD'; }else{ /*test if there is some new images*/ $diff = (time() - filemtime($dir.$file))/60/60; if ($diff < $pa_setup["new_dir_indic"] ){ $dir_pic="main.php?cmd=themeimage&var1=dir_new.png&var2=".$pa_color_map["bg_color"]; $directories[$directories_cnt]['stat']='NEW'; }else{ $dir_pic="main.php?cmd=themeimage&var1=dir.png&var2=".$pa_color_map["bg_color"]; $directories[$directories_cnt]['stat']='NORM'; } } if($pa_theme["dir_logo_style"]=="pic_thmb_size" || $pa_theme["dir_logo_style"]=="pic_other_size"){ $dir_logo=db_select_all("files_".$under_dir_sett["seq_files"],"use_for_logo=='true'"); if(!$dir_logo){ $dir_logo=db_select_all("files_".$under_dir_sett["seq_files"],"visible=='true'"); } if($dir_logo){ $dir_pic=get_thmb_dir_link($under_dir_sett["path"].$dir_logo[0]["file_name"]); }else{ $dir_pic=get_thmb_dir_link("[NOPIC]"); } } /*defining variable*/ $directories[$directories_cnt]['link']="main.php?cmd=album&var1=".urlencode($var1.$file)."/"; $directories[$directories_cnt]['logo']=$dir_pic; if($file_array['name']==$file_array['filename']){ /*it is filename and should be converted*/ $directories[$directories_cnt]['name']=conv_out($file_array['filename']); }else{ $directories[$directories_cnt]['name']=pa_html_decode($file_array['name']); } $directories[$directories_cnt]['desc']=pa_html_decode($file_array['desc']); $directories_cnt++; } } } } /*openning files*/ $done_files[]=""; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if( filetype($dir . $file)=="file" || filetype($dir . $file)=="link" ) { $i=1; $img_desc=""; while(isset($files_settings[$i]["file_name"])){ if($files_settings[$i]["file_name"]==$file){ $img_desc=$files_settings[$i]["desc"]; break; } $i=$i+1; } if(strlen($img_desc)==0 && $pa_theme["show_filenames"]=="true"){ $img_desc=$file; } $file_array=Array("filename"=>$file,"time"=>filectime($dir . $file),"name"=>$img_desc); $filelist2[]=$file_array; $file_scr[]=$file; } } closedir($dh); if(sizeof($filelist2)>0){ usort($filelist2,"file_array_cmp"); $qq=$pa_quality["thmb_size"]."_".$pa_quality["thmb_qual"]; $qpic=$pa_quality["photo_size"]."_".$pa_quality["photo_qual"]; $thumbnails=Array(); $thumbnails_cnt=0; $cnt=0; if($start_with>(sizeof($filelist2)-1)|| $start_with<0){ $start_with=0; /*just to be sure*/ } while ( list($key,$file_array)=each($filelist2)){ $file=$file_array['filename']; $file_ok=false; $rec=db_select_all("files_".$dir_settings["seq_files"],"file_name=='".addslashes($file)."'"); $record=$rec[0]; if($record["visible"]=="true"){ if($cnt>=$start_with and $cnt<$start_with+$number_of_thmbs){ if(is_image($file)){ $file_ok=true; $i=1; $img_desc=""; while(isset($dir_settings[$i][0])){ if($dir_settings[$i][0]==$file){ $img_desc=$dir_settings[$i][1]; break; } $i=$i+1; } $scr=get_file_for_screenshot($file,$file_scr); if($scr!=""){ $done_files[]=$scr; $thumbnails[$thumbnails_cnt]['thmb']=get_thmb_standard_link($var1.$file); $thumbnails[$thumbnails_cnt]['desc']=pa_html_decode($img_desc); if($pa_theme["show_filenames"]=="true" && $thumbnails[$thumbnails_cnt]['desc']==""){ $thumbnails[$thumbnails_cnt]['desc']=conv_out($scr); } $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=image&var1=".urlencode($var1.$scr); }else{ $thumbnails[$thumbnails_cnt]['thmb']=get_thmb_standard_link($var1.$file);; $thumbnails[$thumbnails_cnt]['desc']=pa_html_decode($img_desc); if($pa_theme["show_filenames"]=="true" && $thumbnails[$thumbnails_cnt]['desc']==""){ $thumbnails[$thumbnails_cnt]['desc']=conv_out($file); } $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=imageview&var1=".urlencode($var1.$file); } } if(is_movie($file) && !array_search($file,$done_files)){ $file_ok=true; $scr=get_screanshot_for_file($file,$file_scr); if($scr!=""){ $file_ok=false; /*$thumbnails[$thumbnails_cnt]['thmb']="main.php?cmd=thmb&var1=".urlencode($var1.$scr)."&var2=".$qq."&var3=".theme_get_id(); $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=image&var1=".urlencode($var1.$file)."&var2=".$quality; $thumbnails[$thumbnails_cnt]['desc']=$file; */ }else{ $thumbnails[$thumbnails_cnt]['thmb']="main.php?cmd=thmb&var1=[movie]&var2=".$qq."&var3=".theme_get_id(); $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=image&var1=".urlencode($var1.$file); $thumbnails[$thumbnails_cnt]['desc']=conv_out($file); } } if(is_audio($file) && !array_search($file,$done_files)){ $file_ok=true; $scr=get_screanshot_for_file($file,$file_scr); if($scr!=""){ $file_ok=false; /* $thumbnails[$thumbnails_cnt]['thmb']="main.php?cmd=thmb&var1=".urlencode($var1.$scr)."&var2=".$qq."&var3=".theme_get_id(); $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=image&var1=".urlencode($var1.$file)."&var2=".$quality; $thumbnails[$thumbnails_cnt]['desc']=$file; */ }else{ $thumbnails[$thumbnails_cnt]['thmb']="main.php?cmd=thmb&var1=[audio]&var2=".$qq."&var3=".theme_get_id(); $thumbnails[$thumbnails_cnt]['link']="main.php?cmd=image&var1=".urlencode($var1.$file); $thumbnails[$thumbnails_cnt]['desc']=conv_out($file); } } if($file_ok){ $thumbnails[$thumbnails_cnt]['width']=$pa_quality["thmb_size"]+$pa_theme["additional_thmb_width"]; $thumbnails[$thumbnails_cnt]['height']=$pa_quality["thmb_size"]+$pa_theme["additional_thmb_height"]; $thumbnails[$thumbnails_cnt]['view_count']=$record["view_count"]; $thumbnails[$thumbnails_cnt]['vote_count']=$record["vote_count"]; $thumbnails[$thumbnails_cnt]['vote_avg']=$record["vote_avg"]; $thumbnails[$thumbnails_cnt]['comment_count']=$record["comment_count"]; $thumbnails_cnt++; } } } $cnt++; } } } } if ( sizeof($filelist2)<=$start_with+$number_of_thmbs){ //no next page $next_start_with=-1; }else{ $next_start_with=$start_with+$number_of_thmbs; } if ( $start_with==0){ //no next page $previous_start_with=-1; }else{ $previous_start_with=$start_with-$number_of_thmbs; if($previous_start_with<0){$previous_start_with=0;} } /*call theme function to generate page*/ theme_generate_album_page($dir_path,$quality_links,$directories,$thumbnails,$dir_long_desc,$next_start_with,$previous_start_with,$var1,$quality); return true; } function file_array_cmp($a,$b){ global $act_dir_sorting; switch($act_dir_sorting){ case "date_asc": if ($a['time'] == $b['time']) { return 0; } return ($a['time'] < $b['time']) ? -1 : 1; break; case "date_desc": if ($a['time'] == $b['time']) { return 0; } return ($a['time'] < $b['time']) ? 1 : -1; break; case "filename_asc": if ($a['filename'] == $b['filename']) { return 0; } return ($a['filename'] < $b['filename']) ? -1 : 1; break; case "filename_desc": if ($a['filename'] == $b['filename']) { return 0; } return ($a['filename'] < $b['filename']) ? 1 : -1; break; case "name_asc": if ($a['name'] == $b['name']) { return 0; } return ($a['name'] < $b['name']) ? -1 : 1; break; case "name_desc": if ($a['name'] == $b['name']) { return 0; } return ($a['name'] < $b['name']) ? 1 : -1; break; default: return 0; } } function get_directory_settings($dir,$full=1){ global $data_dir,$pa_setup; if ($dir=="\\") $dir=""; if(substr($dir,0,1)!="/"){ $dir="/".$dir; } if(substr($dir,-1,1)!="/"){ $dir=$dir."/"; } $inh_groups=Array(); if(!db_select_exists("directory","path=='".addslashes($dir)."'")){ // not found, first time visiting directory, do insert if($dir!="/"){ //inheriting directory permissions for new directory. $up_dir=dirname($dir); if(substr($up_dir,-1,1)!="/"){ $up_dir=$up_dir."/"; } $rec=db_select_all("directory","path=='".addslashes($up_dir)."'"); $grps=db_select_all("group"); foreach($grps as $group){ if(isset($rec[0]["groups"][$group["name"]])){ $inh_groups[$group["name"]]=$rec[0]["seq_files"]; }else{ if(isset($rec[0]["inh_groups"][$group["name"]])){ $inh_groups[$group["name"]]=$rec[0]["inh_groups"][$group["name"]]; } } } } $seq_files=db_get_seq_nextval("seq_files"); db_insert("directory",Array("path"=>$dir,"seq_files"=>$seq_files)); db_update("directory","inh_groups=".var_export($inh_groups,true).";","seq_files==".$seq_files); db_create_table("files_$seq_files",Array( "file_name"=>"", "visible"=>"true", "desc"=>"", "long_desc"=>"", "params"=>"", "dir_logo"=>"true", "view_count"=>0, "vote_count"=>0, "vote_avg"=>0, "comment_count"=>0, "use_for_logo"=>"false" )); db_create_table("comments_$seq_files",Array( "id"=>"", "file_name"=>"", "time"=>"", "name"=>"", "email"=>"", "text"=>"" )); } $rec=db_select_all("directory","path=='".addslashes($dir)."'"); if($full!=1){ return Array($rec[0],null); } $seq_files=$rec[0]["seq_files"]; //continue for files settings $changed=false; $files=db_select_all("files_$seq_files",null,true); //delete not existing files $dir_path=substr($dir,1);//delete leading slash if(is_array($files)){ foreach($files as $key=>$record){ if(!file_exists($pa_setup["album_dir"].$dir_path.$record["file_name"])){ db_delete("files_$seq_files","file_name=='".$record["file_name"]."'"); $changed=true; }else{ $files_exists[$record["file_name"]]="Y"; } } } //add new files if needed if(file_exists($pa_setup["album_dir"].$dir_path)){ if ($dh = opendir($pa_setup["album_dir"].$dir_path)) { while (($file = readdir($dh)) !== false) { if( (filetype($pa_setup["album_dir"].$dir_path. $file)=="file" || filetype($pa_setup["album_dir"].$dir_path. $file)=="link" ) && is_image($file) ){ if(!isset($files_exists[$file])){ db_insert("files_$seq_files",Array("file_name"=>$file)); db_insert("stat_newest_photos",Array("dir_path"=>"/".$dir_path,"file_name"=>$file,"time"=>filectime($pa_setup["album_dir"].$dir_path. $file))); $changed=true; } } } closedir($dh); } } /*clipping statistics of new files if needed*/ $recx=db_select_all("stat_newest_photos",null,"time"); if(is_array($recx)){ if(count($recx)>$pa_setup["statistic_count"]){ $diff=count($recx)-$pa_setup["statistic_count"]; $time=$recx[$diff]["time"]; db_delete("stat_newest_photos","time<=".$time); } } /*rereading of files*/ if($changed){ $files=db_select_all("files_$seq_files"); } if($rec[0]["photo_count"]!=count($files)){ db_update("directory","photo_count=".count($files).";","path=='".addslashes($dir)."'"); } return Array($rec[0],$files); } function get_all_sortings(){ $sorts= Array ( "default"=> "Default", "date_asc"=> "Date - Ascending", "date_desc"=> "Date - Descending", "filename_asc"=> "Filename - Ascending", "filename_desc"=> "Filename - Descending", "name_asc"=> "Name - Ascending", "name_desc"=> "Name - Descending" ); return $sorts; } function scan_photos_directories($dir,$level=0){ global $pa_setup; $album_dir=$pa_setup["album_dir"]; $sett=get_directory_settings($dir,1);// if (is_dir($album_dir.$dir)) { if ($dh = opendir($album_dir.$dir)) { while (($file = readdir($dh)) !== false) { if( filetype($album_dir.$dir.$file)=="dir" && $file!="." && $file !="..") { scan_photos_directories($dir.$file."/",$level+1); } } closedir($dh); } } db_commit(true); if($level==0){ //delete not existing directories from db if($dir==""){ //only once and if the whole directory is scanned $rec=db_select_all("directory"); foreach($rec as $record){ if(!file_exists(substr($pa_setup["album_dir"],0,-1).$record["path"])){ db_drop_table("files_".$record["seq_files"]); db_drop_table("comments_".$record["seq_files"]); db_delete("directory","seq_files==".$record["seq_files"]); db_delete("stat_newest_photos","dir_path=='".addslashes($record["path"])."'"); } } } db_update("directory","photo_count_r=0;"); $rec=db_select_all("directory"); foreach($rec as $record){ if($record["photo_count"]>0){ db_update("directory","photo_count_r+=".$record["photo_count"].";","substr('".addslashes($record["path"])."',0,strlen(path))==path"); } } $t=time(); db_update("setup","last_dir_scan=".$t.";"); $pa_setup["last_dir_scan"]=$t; db_commit(true); } } function get_themes(){ global $themes_dir; $dir=$themes_dir; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if( filetype($dir . $file)=="dir" && $file!="." && $file !=".." && $file !="engines") { $filelist[]=$file; } } closedir($dh); } } return $filelist; } /****************************************/ /* THMB */ /****************************************/ function generate_thumb($var1,$var3){ global $pa_setup,$pa_quality,$pa_theme; $sharp=true; if($pa_theme["dir_logo_style"]=="pic_other_size" && $var3=="DIR"){ $width = $pa_theme["dir_logo_size"]; $height = $pa_theme["dir_logo_size"]; $square = $pa_theme["dir_logo_square_thumbnail"]; $thmb_quality =$pa_theme["dir_logo_quality"]; }else{ $width = $pa_quality["thmb_size"]; $height = $pa_quality["thmb_size"]; $square = $pa_quality["square_thumbnails"]; $thmb_quality =$pa_quality["thmb_qual"]; } $var1=stripslashes($var1); // Content type if(is_image($var1)){ $mime=get_mime($var1); send_header("Content-type: ".$mime); }else{ send_header('Content-type: image/png'); // for movie.png and video.png } send_header("Content-Disposition: filename=thmb_".conv_out_header(basename($var1),$character_set)." "); if($var1=="[movie]"){$var1="res/movie.png"; $sharp=false;} else if($var1=="[audio]"){$var1="res/audio.png"; $sharp=false;} else if($var1=="[NOPIC]"){$var1="res/nopic.png"; $sharp=false;} else{$var1=$pa_setup["album_dir"].$var1;} // Get new dimensions list($width_orig, $height_orig) = getimagesize($var1); //$image_p = imagecreatetruecolor($width+10, $height+10); //$color=ImageColorAllocate( $image_p, 32, 32, 32 ); //imagefill($image_p,0,0,$color); if($square=="true"){ if ($width_orig < $height_orig) { $src_x=0; $src_y=($height_orig-$width_orig)/2; $height_orig=$width_orig; }else{ $src_y=0; $src_x=($width_orig-$height_orig)/2; $width_orig=$height_orig; } }else{ //keep aspect ratio $src_x=0; $src_y=0; if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } } // Resample $image=imagecreatefrom($var1); $image_p = imagecreatetruecolor($width, $height); $bgcol=theme_get_bgcolor(); $color = ImageColorAllocate( $image_p,$bgcol[0] ,$bgcol[1] ,$bgcol[2] ); imagefill($image_p,0,0,$color); imagecopyresampled($image_p, $image, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig); //$image_p=UnsharpMask($image_p,50,1,3); // Output //sharpening if($pa_quality["thmb_sharp_use"]=='true' && $sharp){ $image_p=UnsharpMask($image_p, $pa_quality["thmb_sharp_amount"], $pa_quality["thmb_sharp_radius"],$pa_quality["thmb_sharp_treshold"]); } image_same_type($var1,$image_p,$thmb_quality); } /****************************************/ /* IMAGE */ /****************************************/ function get_mime($var1){ $t=strtoupper(substr($var1,-4,4)); switch($t){ case ".JPG": case "JPEG": return "image/jpeg"; break; case ".GIF": return "image/gif"; break; case ".PNG": return "image/png"; break; default: return ""; break; } } function get_resized_imagesize($var1){ global $pa_setup,$pa_quality; list($width_orig, $height_orig) = getimagesize($pa_setup["album_dir"].$var1); if( $pa_quality["photo_size"] > 0){ $image_low_size=$pa_quality["photo_size"]; if($pa_quality["resize_if_bigger"]=="true"){ if( ($width_orig <= $image_low_size && $pa_quality["resize_photo_to_fit"]=="width") || ($height_orig <= $image_low_size && $pa_quality["resize_photo_to_fit"]=="height") || ($width_orig <= $image_low_size && $height_orig <= $image_low_size && $pa_quality["resize_photo_to_fit"]=="both") ){ return Array($width_orig,$height_orig,false); } } if($pa_quality["resize_photo_to_fit"]=="both"){ $width=$image_low_size; $height=$image_low_size; // Get new dimensions if ($width_orig < $height_orig) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } } if($pa_quality["resize_photo_to_fit"]=="width"){ $width=$image_low_size; $height = ($width / $width_orig) * $height_orig; } if($pa_quality["resize_photo_to_fit"]=="height"){ $height=$image_low_size; $width = ($height / $height_orig) * $width_orig; } return Array($width,$height,true); }else{ return Array($width_orig,$height_orig,false); } } function generate_image($var1,$quality,$original=false){ global $pa_quality,$pa_setup; $var1=stripslashes($var1); $m_time=filemtime($pa_setup["album_dir"].$var1); //$headers=getallheaders(); --not supported by others then apache if (isset( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ){ if ( date("D, d M Y H:i:s T",$m_time) == $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) { send_header('HTTP/1.0 304 Not Modified'); exit; } } if(is_image($var1)){ // Content type send_header("Last-Modified: ".date("D, d M Y H:i:s T",$m_time)); $mime=get_mime($var1); send_header("Content-type: ".$mime); send_header("Content-Disposition: filename=".conv_out_header(basename($var1))." "); list($width_orig, $height_orig) = getimagesize($pa_setup["album_dir"].$var1); list($width,$height,$resize) = get_resized_imagesize($var1); if((!$original) && ($resize || is_file($pa_quality["watermark_file"]))){ if($resize){ $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefrom($pa_setup["album_dir"].$var1); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); }else{ $image_p = imagecreatefrom($pa_setup["album_dir"].$var1); } if(is_file($pa_quality["watermark_file"])){ // should be placed a watermark list($width_wat,$height_wat) = getimagesize($pa_quality["watermark_file"]); $image_w=imagecreatefrom($pa_quality["watermark_file"]); $x_wat=$width/2-$width_wat/2; $y_wat=$height/2-$height_wat/2; if(strstr($pa_quality["watermark_position"],"L")){ $x_wat=0; } if(strstr($pa_quality["watermark_position"],"R")){ $x_wat=$width-$width_wat; } if(strstr($pa_quality["watermark_position"],"U")){ $y_wat=0; } if(strstr($pa_quality["watermark_position"],"D")){ $y_wat=$height-$height_wat; } imagecopy($image_p,$image_w,$x_wat,$y_wat,0,0,$width_wat,$height_wat); } //$image_s=UnsharpMask($image_p, 20, 1,0); image_same_type($var1,$image_p,$pa_quality["photo_qual"]); return true; // cache it }else{ pa_readfile($pa_setup["album_dir"].$var1); return false; //don't cache } } if(!is_image($var1)){ ob_end_clean(); send_header("Content-type: application/download; name=\"".basename($var1)."\""); send_header("Content-Disposition: attachment; filename=\"".basename($var1)."\" "); send_header("Content-Length: ".filesize($pa_setup["album_dir"].$var1)." "); send_header("Last-Modified: ".date("D, d M Y H:i:s T",$m_time)." " ); send_header("Last-Modified: ".date("D, d M Y H:i:s T",$m_time)." " ); pa_readfile($pa_setup["album_dir"].$var1); return false; } } /****************************************/ /* DELTE CACHE */ /****************************************/ function delete_cache($cache_dir,$display=1){ if ($dh = opendir($cache_dir)) { while (($file = readdir($dh)) !== false) { if($file != "." && $file!=".."){ unlink ( $cache_dir . $file); if($display==1) echo "deleting : ".$cache_dir.$file."
"; } } closedir($dh); } } /****************************************/ /* NEXT PREV IMAGE */ /****************************************/ function get_next_prev_image ($var1){ global $pa_setup,$act_dir_sorting; $tmp="null"; $dirname=dirname($var1); if($dirname=="."){ $dirname=""; }else{ $dirname.="/"; } $dir_settings=get_directory_settings($dirname); $act_dir_sorting=$dir_settings[0]["sorting"]; if($act_dir_sorting=='default'){ $act_dir_sorting=$pa_setup["default_sorting"]; } if ($dh = opendir(dirname($pa_setup["album_dir"].$var1))) { while (($file = readdir($dh)) !== false) { if($file != "." && $file!=".." && (filetype(dirname($pa_setup["album_dir"].$var1)."/".$file)=="file" ||filetype(dirname($pa_setup["album_dir"].$var1)."/".$file)=="link") && is_image($file)){ $i=1; $img_desc=""; while(isset($dir_settings[$i][0])){ if($dir_settings[$i][0]==$file){ $img_desc=$dir_settings[$i][1]; break; } $i=$i+1; } if(strlen($img_desc)==0){ $img_desc=$file; } $file_array=Array("filename"=>$file,"time"=>filectime(dirname($pa_setup["album_dir"].$var1)."/".$file),"name"=>$img_desc); $file_scr[]=$file; $filelist[]=$file_array; }else{ $dw[]=$file; } } closedir($dh); if(sizeof($filelist)>0) { usort($filelist,'file_array_cmp'); while(list($key,$file_array)=each($filelist)){ $file=$file_array['filename']; if ($file == basename($var1)){ if($tmp!="null"){ $names[]=$dirname.$tmp; }else{ $names[]="null"; } while(list($key,$file_array)=each($filelist)){ $file=$file_array['filename']; if(!get_file_for_screenshot($file,$dw)) break; } //echo "KEY=".$key; //echo "FILE=".$file; if($file_array !== null){ $names[]= $dirname.$file; }else{ $names[]= "null"; } } if(!get_file_for_screenshot($file,$dw)){ $tmp=$file; } } } return $names; } } function get_dir_from_photo_var($var){ $dir=dirname($var); if($dir!="."){ $dir="/".dirname($var)."/"; $dir=str_replace("//","/",$dir); }else{ $dir="/"; } return $dir; } function update_stats($for_what,$var,$var2,$var3=null){ global $pa_setup; if($for_what=="imageview"){ $dir=get_dir_from_photo_var($var); $file=basename($var); $rec=db_select_all("directory","path=='". addslashes($dir) ."'"); $set=""; if($var2=="view"){ $set.="view_count=view_count+1;"; } if($var2=="comment"){ if($var3=="add"){ $set.="comment_count=comment_count+1;"; }else{ $set.="comment_count=comment_count-1;"; } } if($var2=="vote"){ $set.="vote_count=vote_count+1;vote_avg=((vote_avg*vote_count)+$var3)/(vote_count+1);"; } db_update("files_".$rec[0]["seq_files"],$set,"file_name=='".$file."'"); $act=db_select_all("files_".$rec[0]["seq_files"],"file_name=='".$file."'"); if($var2=="view"){ // update stat_photo_views $rec=db_select_all("stat_photo_views",null,"view_count",true); if(db_update("stat_photo_views", "view_count=".$act[0]["view_count"].";", "dir_path=='".prepdb($dir)."' && file_name=='".$file."'") == 0){ if(isset($rec[0]) && count($rec) >= $pa_setup["statistic_count"]){ if($rec[0]["view_count"]<$act[0]["view_count"]){ db_insert("stat_photo_views",Array("dir_path"=>$dir,"file_name"=>$file,"view_count"=>$act[0]["view_count"])); db_delete("stat_photo_views","dir_path=='".$rec[0]["dir_path"]."' && file_name=='".$rec[0]["file_name"]."'"); } }else{ db_insert("stat_photo_views",Array("dir_path"=>prepdb($dir),"file_name"=>$file,"view_count"=>$act[0]["view_count"])); } } } if($var2=="comment"){ // update stat_photo_comments $rec=db_select_all("stat_photo_comments",null,"comment_count",true); if($act[0]["comment_count"]==0){ db_delete("stat_photo_comments","dir_path=='".prepdb($dir)."' && file_name=='".$file."'"); }else{ if(db_update("stat_photo_comments", "comment_count=".$act[0]["comment_count"], "dir_path=='".prepdb($dir)."' && file_name=='".$file."'") == 0){ if(isset($rec[0]) && count($rec) >= $pa_setup["statistic_count"]){ if($rec[0]["comment_count"]<$act[0]["comment_count"]){ db_insert("stat_photo_comments",Array("dir_path"=>$dir,"file_name"=>$file,"comment_count"=>$act[0]["comment_count"])); db_delete("stat_photo_comments","dir_path=='".$rec[0]["dir_path"]."' && file_name=='".$rec[0]["file_name"]."'"); } }else{ db_insert("stat_photo_comments",Array("dir_path"=>$dir,"file_name"=>$file,"comment_count"=>$act[0]["comment_count"])); } } } } if($var2=="vote"){ // update stat_photo_votes $rec=db_select_all("stat_photo_votes",null,"vote_avg",true); if(db_update("stat_photo_votes", "vote_avg=".$act[0]["vote_avg"].";vote_count=".$act[0]["vote_count"].";", "dir_path=='".prepdb($dir)."' && file_name=='".$file."'") == 0){ if(isset($rec[0]) && count($rec) >= $pa_setup["statistic_count"]){ if($rec[0]["vote_avg"]<$act[0]["vote_avg"]){ db_insert("stat_photo_votes",Array("dir_path"=>$dir,"file_name"=>$file,"vote_avg"=>$act[0]["vote_avg"],"vote_count"=>$act[0]["vote_count"])); db_delete("stat_photo_votes","dir_path=='".$rec[0]["dir_path"]."' && file_name=='".$rec[0]["file_name"]."'"); } }else{ db_insert("stat_photo_votes",Array("dir_path"=>$dir,"file_name"=>$file,"vote_avg"=>$act[0]["vote_avg"],"vote_count"=>$act[0]["vote_count"])); } } } db_commit(); return; } } /****************************************/ /* IMAGE VIEW */ /****************************************/ function generate_image_view($var1,$quality,$var3){ global $pa_quality,$pa_setup,$pa_theme; $var1=stripslashes($var1); $qq=$pa_quality["photo_size"]."_".$pa_quality["photo_qual"]; if(is_file($pa_quality["watermark_file"])){ $qq.="_".$pa_quality["watermark_file"]."_".$pa_quality["watermark_position"]; } if(file_exists($pa_setup["album_dir"].$var1)){ list($width_orig, $height_orig) = getimagesize($pa_setup["album_dir"].$var1); $sys_par["width"]=$width_orig; $sys_par["height"]=$height_orig; $sys_par["size"]=filesize($pa_setup["album_dir"].$var1); $sys_par["time"]=filectime($pa_setup["album_dir"].$var1); $sys_par["name"]=basename($var1); $sys_par["link"]="main.php?cmd=imageorig&var1=".urlencode($var1); // exif stuff if(function_exists("read_exif_data")){ $info= read_exif_data($pa_setup["album_dir"].$var1); //var_dump($info); if(isset($info["FNumber"])){ $f_func=create_function('','$fnum=round('.$info["FNumber"].',1);return $fnum;'); $sys_par["exif_f"]=number_format($f_func(),1); } $sys_par["exif_model"]=$info["Model"]; if(isset($info["ExposureTime"])){ $e_func=create_function('','$fnum='.$info["ExposureTime"].';return $fnum;'); $time=$e_func(); if($time>1){ $sys_par["exif_exp_time"]=$time; }else{ $sys_par["exif_exp_time"]="1/".(1/$time); } } $sys_par["exif_iso"]=$info["ISOSpeedRatings"]; } //var_dump($info); } $dir_path[0]['name']=t('ID_PHOTO_DIR'); $dir_path[0]['link']="main.php?cmd=album&var2=".$quality; $dirs=explode('/',$var1); $act_dir=""; for($i=0;$i0){ $dir_path[$i+1]['name']=pa_html_decode($ss[0][4]); }else{ $dir_path[$i+1]['name']=conv_out($dirs[$i]); } $dir_path[$i+1]['link']="main.php?cmd=album&var1=".urlencode($act_dir)."&var2=".$quality; } $qualities=db_select_all("quality","enabled=='true'"); // select all enabled qualities $quality_links=Array(); if(count($qualities)>1){ foreach($qualities as $key=>$val){ $quality_links[]=Array("name"=>$val["name"], "link"=>"main.php?cmd=setquality&var1=".$val["id"]."&var2=imageview&var3=".urlencode($var1), "actual" => ($val["id"]==$pa_quality["id"])?1:0 ); } } /*testing for next and previous image ..*/ list( $prev,$next) = get_next_prev_image($var1); list($width, $height) = get_resized_imagesize($var1); if( $prev != "null" ) { $prev_link = "main.php?cmd=imageview&var1=".urlencode($prev); }else{ $prev_link =""; }; if( $next != "null" ) { $next_link = "main.php?cmd=imageview&var1=".urlencode($next); }else{ $next_link = ""; }; $image_link="main.php?cmd=image&var1=".urlencode($var1)."&var2=".$qq; $imageview_link="main.php?cmd=imageview&var1=".urlencode($var1); $sett_b=get_directory_settings(dirname("/".$var1)); $sett=$sett_b[0];//dir settings $rec=db_select_all("files_".$sett["seq_files"],"file_name=='".basename($var1)."'"); $file=$rec[0]; $img_desc=$file["desc"]; if($pa_theme["show_filenames"]=="true" && $img_desc==""){ $img_desc=conv_out(basename($var1)); } $img_desc_long=$file["long_desc"]; /* store typed comments*/ if(!$var3){ update_stats("imageview",$var1,"view"); } if($var3=="save_comment"){ update_stats("imageview",$var1,"comment","add"); if(isset($_POST['p_text'])){ if(strlen($_POST['p_name'])==0){ $p_name="Anonymous"; }else{ $p_name=$_POST['p_name']; } if( isset($_POST['p_name']))setcookie("comment_name",$_POST['p_name'],time()+60*60*24*365); if( isset($_POST['p_email']))setcookie("comment_email",$_POST['p_email'],time()+60*60*24*365); save_comment($var1,$_POST['p_text'],$p_name,$_POST['p_email'],time()); } } if(substr($var3,0,15)=="delete_comment-"){ update_stats("imageview",$var1,"comment","del"); $id=substr($var3,15); delete_comment($var1,$id); } $comments=get_comments($var1); /*parameters*/ $rec=db_select_all("photo_param"); if($rec)foreach($rec as $param){ if($sett["show_parameters"]=="default" && $param["default_displayed"]=="true" || isset($sett["show_parameters_custom_id"][$param["id"]]) ){ if($param["type"]=="user"){ if(isset($file["params"][$param["id"]]) && strlen($file["params"][$param["id"]])>0 ){ $parameters[$param["name"]]=$file["params"][$param["id"]]; }elseif(isset($param["default"]) && strlen($param["default"])>0){ $parameters[$param["name"]]=$param["default"]; } } if($param["type"]=="userlov"){ if(isset($file["params"][$param["id"]]) && $file["params"][$param["id"]]>=0 ){ $parameters[$param["name"]]=$param["lov"][$file["params"][$param["id"]]]; }elseif(isset($param["default_lov"]) && $param["default_lov"] >=0){ $parameters[$param["name"]]=$param["lov"][$param["default_lov"]]; } } if($param["type"]=="system"){ /*"dim"=>"Picture dimensions", "siz"=>"File size in KB", "cdt"=>"Creation date of picture", "fnm"=>"Filename", "fnl"=>"Filename with fullsize download link", "dwl"=>"Fullsize download link"*/ switch($param["default_lov"]){ case "siz": $parameters[$param["name"]]=t("ID_SYS_PAR_SIZ",round($sys_par["size"]/1024,1)); break; case "dim": $parameters[$param["name"]]=t("ID_SYS_PAR_DIM",$sys_par["width"],$sys_par["height"]); break; case "fnm": $parameters[$param["name"]]=t("ID_SYS_PAR_FNM",$sys_par["name"]); break; case "fnl": $parameters[$param["name"]]=t("ID_SYS_PAR_FNL",$sys_par["link"],$sys_par["name"]); break; case "dwl": $parameters[$param["name"]]=t("ID_SYS_PAR_DWL",$sys_par["link"]); break; case "cdt": $parameters[$param["name"]]=t("ID_SYS_PAR_CDT",date($pa_setup["date_format"],$sys_par["time"])); break; case "exif_iso": if(isset($sys_par["exif_iso"])) $parameters[$param["name"]]=t("ID_SYS_PAR_EXIF_ISO",$sys_par["exif_iso"]); break; case "exif_f": if(isset($sys_par["exif_f"])) $parameters[$param["name"]]=t("ID_SYS_PAR_EXIF_F",$sys_par["exif_f"]); break; case "exif_model": if(isset($sys_par["exif_model"])) $parameters[$param["name"]]=$sys_par["exif_model"]; break; case "exif_exp_time": if(isset($sys_par["exif_exp_time"])) $parameters[$param["name"]]=t("ID_SYS_PAR_EXIF_EXP_TIME",$sys_par["exif_exp_time"]); break; } } } } theme_generate_imageview_page($dir_path,$quality_links,$img_desc,$img_desc_long,$next_link,$prev_link,$image_link,$imageview_link,$width,$height,$var3,$comments,$parameters); } function approve_comment($var1,$id){ global $pa_grants; if(isset($pa_grants["comments"])){ db_delete("new_comments","id=='".$id."'"); } } function delete_comment($var1,$id){ global $pa_grants; if(isset($pa_grants["comments"])){ $dir=get_dir_from_photo_var($var1); $file=basename($var1); $rec=db_select_all("directory","path=='". $dir ."'"); db_delete("comments_".$rec[0]["seq_files"],"id=='".$id."'"); db_delete("new_comments","id=='".$id."'"); } } function save_comment($var1,$text,$name,$email,$time){ global $pa_setup; $t_text=pa_html_encode(stripslashes($text)); $t_text=str_replace("\n","
",$t_text); $t_text=str_replace("\r","",$t_text); $dir=get_dir_from_photo_var($var1); $file=basename($var1); $rec=db_select_all("directory","path=='". $dir ."'"); $id=db_get_seq_nextval("comment_id"); db_insert("comments_".$rec[0]["seq_files"],Array( "id"=>$id, "file_name"=>$file, "name"=>pa_html_encode($name), "time"=>$time, "email"=>pa_html_encode($email), "text"=>$t_text )); $new_comments=db_select_all("new_comments",null,"time",true); if(count($new_comments)>=$pa_setup["comments_approve_queue_size"]){ db_delete("new_comments","id==".$new_comments[0]["id"]); } db_insert("new_comments",Array( "seq_files"=>$rec[0]["seq_files"], "id"=>$id, "pic_link"=>$var1, "file_name"=>$file, "name"=>pa_html_encode($name), "time"=>$time, "email"=>pa_html_encode($email), "text"=>$t_text )); db_commit(); } function get_comments($var1){ $dir=get_dir_from_photo_var($var1); $file=basename($var1); $rec=db_select_all("directory","path=='". $dir ."'"); $comments=db_select_all("comments_".$rec[0]["seq_files"],"file_name=='".$file."'","time-"); return $comments; } function get_all_comments(){ global $data_dir; $comments=db_select_all("new_comments",null); return $comments; } /****************************************/ /* FOOTER */ /****************************************/ function generate_footer(){ /* echo "
Powered by PHP Photo Album
"; */ include '../footer.php'; // echo'"'; } function check_writable($dir){ $file=fopen($dir."writablity_test","w"); fclose($file); // unlink($dir."writablity_test"); return $file; } /****************************************/ /* SETUP COMMAND */ /****************************************/ function generate_setup_page(){ global $var1; global $var2; global $var3; global $var4; global $data_dir,$site_engine,$themes_dir,$pa_theme,$pa_color_map; global $phpalbum_version; global $pa_texts,$pa_translated_texts; global $pa_setup,$pa_lang,$pa_user,$pa_grants; ////////menu generating///////////// if(isset($pa_user["name"])){ $menus=Array("user"=>t("ID_SETUP_MY_ACCOUNT"), "main"=>t("ID_SETUP_MENU_MAIN"), "themes"=>t("ID_SETUP_MENU_THEMES"), "thumbnails"=>t("ID_SETUP_MENU_THUMBNAILS"), "dirs"=>t("ID_SETUP_MENU_DIRS"), "pics"=>t("ID_SETUP_MENU_PICS"), "params"=>t("ID_SETUP_MENU_PARAMS"), "users"=>t("ID_SETUP_MENU_USERS"), "groups"=>t("ID_SETUP_MENU_GROUPS"), "admin"=>t("ID_SETUP_MENU_ADMIN"), "comments"=>t("ID_SETUP_MENU_COMMENTS"), "texts"=>t("ID_SETUP_MENU_TEXTS"), "cache"=>t("ID_SETUP_MENU_CACHE"), "logs"=>t("ID_SETUP_MENU_LOGS"), "errorlog"=>t("ID_SETUP_MENU_ERRORLOG"), "syscheck"=>t("ID_SETUP_MENU_SYSCHECK"), ); }else{ $menus=Array("my_account"=>t("ID_SETUP_MY_ACCOUNT")); $var1="user"; if($pa_user["name"]=="guest"){ $var2="insert"; } } //filter out menu where no grants exists foreach($menus as $key => $value){ if(!isset($pa_grants[$key]) && $key!="user"){ unset($menus[$key]); if($var1==$key){ $var1="user"; $var2=""; } } } //generate menu table $menu="\n"; if($var1==""){ $var1="user"; } foreach($menus as $cmd=>$text){ if($cmd==$var1){ $menu.="\n"; }else{ if(($cmd =="pics" || $cmd == "dirs") && ($var1=="pics" || $var1=="dirs")){ $menu.="\n"; }else{ $menu.="\n"; } } } $menu.="\n"; $menu.="\n"; $menu.="
".t("ID_SETUP_MENU")."
 $text
 $text
 $text
 ".t("ID_LOGOUT")."

<<<   Album

"; ///////end generating menu////////// if($var1=="params"){ if($var2=="save"){ if(isset($_POST["p_lov_edit"])){ $lov=Array(); foreach($_POST as $key=>$value){ if(substr($key,0,12)=="p_lov_value_"){ $lov[substr($key,12)]=$value; } } if(strlen($_POST["p_lov_new"])>0){ $lov[]=$_POST["p_lov_new"]; } db_update("photo_param","lov=".var_export($lov,true).";","id==".$_POST["p_lov_edit"]); } $cnt=1; while(isset($_POST["p_id$cnt"])){ $set=""; if(strlen($_POST["p_name$cnt"])>0){ $set.="name='".$_POST["p_name$cnt"]."';"; } if(isset($_POST["p_default$cnt"])){ $set.="default='".$_POST["p_default$cnt"]."';"; } if(isset($_POST["p_default_lov$cnt"])){ $set.="default_lov=".$_POST["p_default_lov$cnt"].";"; } if(isset($_POST["p_allow_html$cnt"])){ $set.="allow_html='true';"; }else{ $set.="allow_html='false';"; } if(isset($_POST["p_default_displayed$cnt"])){ $set.="default_displayed='true';"; }else{ $set.="default_displayed='false';"; } db_update("photo_param",$set,"id==".$_POST["p_id$cnt"]); $cnt++; } } if($var2=="dellov"){ db_update("photo_param","unset(lov[$var4]);","id==$var3"); } if($var2=="add"){ $noerrors=true; if(strlen($_POST["p_name"])==0){ $errors[]=t("ID_MSG_PARAM_MANDATORY"); $err_name=" error"; $noerrors=false; } $rec=db_select_all("photo_param","name=='".$_POST["p_name"]."'"); if(isset($rec[0])){ $errors[]=t("ID_MSG_PARAM_EXISTS",$_POST["p_name"]); $noerrors=false; $err_name=" error"; } if($noerrors){ $id=db_get_seq_nextval("photo_param_id"); db_insert("photo_param",Array("id"=>$id,"name"=>$_POST["p_name"],"type"=>$_POST["p_type"])); } } if($var2=="del"){ db_delete("photo_param","id==".$var3); //delete the parameter } ob_start();require("setup_params.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="users"){ if($var2=="delete"){ db_delete("user","id==".$var3); } ob_start();require("setup_users.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="groups"){ if($var2=="delete"){ db_delete("group","name=='".prepdb($var3)."'"); } if($var2=="add"){ if($_POST["p_new_group_name"]){ $rec=db_select_all("group","name=='".$_POST["p_new_group_name"]."'"); if(isset($rec[0])){ $errors[]=t("ID_MSG_GROUP_EXISTS",$_POST["p_new_group_name"]); $err_group=" error"; $new_group=$_POST["p_new_group_name"]; }else{ db_insert("group",Array("name"=>$_POST["p_new_group_name"])); } } } if($var2=="grant"){ db_update("group","grants['".$var4."']='1';","name=='".prepdb($var3)."'"); } if($var2=="revoke"){ db_update("group","unset(grants['".$var4."']);","name=='".prepdb($var3)."'"); } if($var2=="save"){ // save changes on groups db_update("group","default='false';"); foreach($_POST as $key =>$value){ if(substr($key,0,9)=="p_default"){ db_update("group","default='true';","name=='".$value."';"); } } } ob_start();require("setup_groups.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="user"){ $superuser=false; if(isset($pa_user["groups"]["superuser"])){ $superuser=true; } if($var3>0){ //editing users by superuser if(isset($pa_user["groups"]["superuser"])){ $superuser=true; $rec=db_select_all("user","id==".$var3); if(isset($rec[0])){ $pa_user=$rec[0]; } } } if($var2=="update"){ $set=""; /*check for new name*/ if($pa_user["name"]!=$_POST["p_username_f"]){ $rec=db_select_all("user","name=='".$_POST["p_username_f"]."'"); if(isset($rec[0]) || $_POST["p_username_f"]=="guest"){ $errors[]=t("ID_MSG_USERNAME_EXISTS",$_POST["p_username_f"]); $err_name=" error"; }else{ $set.="name='".$_POST["p_username_f"]."';"; } } if($_POST["p_password_f"]!=$_POST["p_retype_password_f"]){ $errors[]=t("ID_MSG_PASSWORD_ERROR"); $err_pass=" error"; }else if($_POST["p_password_f"]!=""){ $set.="password='".md5($_POST["p_password_f"])."';"; if(!isset($var3)){ setcookie("userpassword",md5($_POST["p_password_f"])); } } if($_POST["p_email_f"]==""){ $errors[]=t("ID_MSG_EMAIL_REQUIRED"); $err_email=" error"; }else{ $set.="email='".$_POST["p_email_f"]."';"; } $set.="homepage='".$_POST["p_homepage_f"]."';"; if($superuser){ //check the groups $groups=Array(); foreach($_POST as $key => $post){ if(substr($key,0,7)=="p_group"){ $groups[$post]="1"; } } $set.="groups=".var_export($groups,true).";"; } db_update("user",$set,"id==".$pa_user["id"].""); $rec=db_select_all("user","id==".$pa_user["id"]); $pa_user=$rec[0]; } if($var2=="insert"){ $noerrors=true; /*check for new name*/ $pa_user["name"]=$_POST["p_username_f"]; $rec=db_select_all("user","name=='".$_POST["p_username_f"]."'"); if(isset($rec[0]) || $_POST["p_username_f"]=="guest"){ $errors[]=t("ID_MSG_USERNAME_EXISTS",$_POST["p_username_f"]); $err_name=" error"; $noerrors=false; } if(strlen($_POST["p_username_f"])==0){ $errors[]=t("ID_MSG_USERNAME_MANDATORY"); $err_name=" error"; $noerrors=false; } if($_POST["p_password_f"]!=$_POST["p_retype_password_f"]){ $errors[]=t("ID_MSG_PASSWORD_ERROR"); $err_pass=" error"; $noerrors=false; }else if($_POST["p_password_f"]!=""){ $pa_user["password"]=md5($_POST["p_password_f"]); }else{ $errors[]=t("ID_MSG_PASSWORD_REQUIRED"); $err_pass=" error"; $noerrors=false; } if($_POST["p_email_f"]==""){ $errors[]=t("ID_MSG_EMAIL_REQUIRED"); $err_email=" error"; $noerrors=false; } $pa_user["email"]=$_POST["p_email_f"]; $pa_user["homepage"]=$_POST["p_homepage_f"]; if($noerrors){ $var2=""; $message=t("ID_THANKS_FOR_REGISTER"); $pa_user["id"]=db_get_seq_nextval("user_id"); $rec=db_select_all("group","default=='true'"); foreach($rec as $record){ $pa_user["groups"][$record["name"]]='1'; } db_insert("user",$pa_user); setcookie("userpassword",$pa_user["password"]); setcookie("userid",$pa_user["id"]); //$rec=db_select_all("user","name=='".$username."' && password=='".$userpassword."'"); //$pa_user=$rec[0]; } } ob_start();require("setup_user.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="themes"){ if($var2=="add_color"){ $seq=db_get_seq_nextval("color_map_id"); db_insert("color_map",Array("id"=>$seq)); db_update("theme","color_map=".$seq,"name=='".$pa_setup["site_theme"]."'"); } if($var2=="del_color"){ db_delete("color_map","id==".$pa_color_map["id"]); $mm=db_select_all("color_map",null,"id"); db_update("theme","color_map=".$mm[0]["id"],"name=='".$pa_setup["site_theme"]."'"); } if($var2=="save"){ if($_POST["p_theme"]!=$pa_setup["site_theme"]){ db_update("setup","site_theme='".$_POST["p_theme"]."'"); }else{ $set="logo_path='".$_POST['p_logo_path']."';"; $set.="logo_text='".$_POST['p_logo_text']."';"; $set.="logo_style='".$_POST['p_logo_style']."';"; if(isset($_POST['p_show_filenames'] )){ $set.="show_filenames='true';"; }else{ $set.="show_filenames='false';"; } if(isset($_POST['p_disable_bottom_nextprev'] )){ $set.="disable_bottom_nextprev='true';"; }else{ $set.="disable_bottom_nextprev='false';"; } $set.="directory_style='".$_POST['p_directory_style']."';"; $set.="maximum_photos_per_page='".$_POST['p_maximum_photos_per_page']."';"; $set.="raster_dir_x='".$_POST['p_raster_dir_x']."';"; $set.="raster_dir_y='".$_POST['p_raster_dir_y']."';"; $set.="picture_border_size='".$_POST["p_picture_border_size"]."';"; $set.="thumbnail_border_size='".$_POST["p_thumbnail_border_size"]."';"; $set.="dir_logo_style='".$_POST["p_dir_logo_style"]."';"; if(isset($_POST["p_dir_logo_size"])){ $set.="dir_logo_size='".$_POST["p_dir_logo_size"]."';"; } if(isset($_POST["p_dir_logo_quality"])){ $set.="dir_logo_quality='".$_POST["p_dir_logo_quality"]."';"; } if(isset($_POST["p_dir_logo_square_thumbnail"])){ $set.="dir_logo_square_thumbnail='true';"; }else{ $set.="dir_logo_square_thumbnail='false';"; } if(isset($_POST['p_display_shadows'] )){ $set.="display_shadows='true';"; }else{ $set.="display_shadows='false';"; } $set.="additional_thmb_height='".$_POST["p_additional_thmb_height"]."';"; $set.="additional_thmb_width='".$_POST["p_additional_thmb_width"]."';"; db_update("theme",$set,"name=='".$pa_setup["site_theme"]."'"); } if($_POST["p_color_map"]!=$pa_theme["color_map"]){ // color map was changed db_update("theme","color_map=".$_POST["p_color_map"],"name=='".$pa_setup["site_theme"]."'"); }else{ $set="bg_color='".$_POST["p_bg_color"]."';"; $set.="link_color='".$_POST["p_link_color"]."';"; $set.="dir_desc_color='".$_POST["p_dir_desc_color"]."';"; $set.="photo_desc_color='".$_POST["p_photo_desc_color"]."';"; $set.="border_color='".$_POST["p_border_color"]."';"; $set.="logo_color='".$_POST["p_logo_color"]."';"; $set.="name='".$_POST["p_color_name"]."';"; db_update("color_map",$set,"id==".$pa_color_map["id"]); } } read_settings(); ob_start();require("setup_themes.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="thumbnails" ){ if($var2=="del"){ db_delete("quality","id==".$var3); } if($var2=="add"){ $seq=db_get_seq_nextval("seq_quality_id"); db_insert("quality",Array("id"=>$seq)); } if($var2=="save"){ $q=db_select_all("quality"); foreach($q as $rec){ $id=$rec["id"]; if(isset($_POST["p_q_desc$id"])){ $set= "name='".$_POST["p_q_desc$id"]."';"; $set.="thmb_size='".$_POST["p_q_thmbs$id"]."';"; if($_POST["p_q_thmbq$id"]<=0){ $set.="thmb_qual='85';"; }else{ $set.="thmb_qual='".$_POST["p_q_thmbq$id"]."';"; } $set.="photo_size='".$_POST["p_q_pics$id"]."';"; if($_POST["p_q_picq$id"] <=0 ){ $set.="photo_qual='85';"; }else{ $set.="photo_qual='".$_POST["p_q_picq$id"]."';"; } $set.="resize_photo_to_fit='".$_POST["p_resize_photo_to_fit$id"]."';"; $set.="watermark_file='".$_POST["p_watermark_file$id"]."';"; $set.="watermark_position='".$_POST["p_watermark_position$id"]."';"; $set.="thmb_sharp_amount='".$_POST["p_thmb_sharp_amount$id"]."';"; $set.="thmb_sharp_radius='".$_POST["p_thmb_sharp_radius$id"]."';"; //$set.="thmb_sharp_treshold='".$_POST["p_thmb_sharp_treshold$id"]."';"; if($_POST["p_q_default"]==$rec["id"]){ $set.="default='true';"; $set.="enabled='true';"; }else{ $set.="default='false';"; if(isset($_POST["p_q_enabled$id"])){ $set.="enabled='true';"; }else{ $set.="enabled='false';"; } } if(isset($_POST["p_q_resizeifbigger$id"])){ $set.="resize_if_bigger='true';"; }else{ $set.="resize_if_bigger='false';"; } if(isset($_POST["p_q_square_thumbnails$id"])){ $set.="square_thumbnails='true';"; }else{ $set.="square_thumbnails='false';"; } if(isset($_POST["p_thmb_sharp_use$id"])){ $set.="thmb_sharp_use='true';"; }else{ $set.="thmb_sharp_use='false';"; } if(isset($_POST["p_thmb_show_views$id"])){ $set.="thmb_show_views='true';"; }else{ $set.="thmb_show_views='false';"; } if(isset($_POST["p_thmb_show_comments$id"])){ $set.="thmb_show_comments='true';"; }else{ $set.="thmb_show_comments='false';"; } if(isset($_POST["p_thmb_show_votes$id"])){ $set.="thmb_show_votes='true';"; }else{ $set.="thmb_show_votes='false';"; } } db_update("quality",$set,"id==$id"); } } /*check for at least one existing enabled and default*/ $rec=db_select_all("quality"); $default_found=false; $enabled_found=false; $id_found=false; foreach($rec as $qual){ if($qual["default"]=="true"){ $default_found=$qual["id"]; } if($qual["enabled"]=="true"){ $enabled_found=$qual["id"]; } $id_found=$qual["id"]; } if(!$enabled_found){ if(!$default_found){ db_update("quality","enabled='true';default='true'","id==$id_found"); }else{ db_update("quality","enabled='true'","id==$default_found"); } }else{ if(!$default_found){ db_update("quality","default='true'","id==$enabled_found"); }else{ /*everything is ok*/ } } ob_start();require("setup_thumbnails.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="main"){ if($var2=="save"){ $set=""; $p_pd=$_POST['p_album_dir']; $p_cd=$_POST['p_cache_dir']; $old_pd=$pa_setup["album_dir"];//storing for later comparsion. if(substr($p_cd,-1,1)!="/"){ $p_cd=$p_cd."/"; } if(substr($p_pd,-1,1)!="/"){ $p_pd=$p_pd."/"; } $set.="album_dir='".$p_pd."';"; $set.="cache_dir='".$p_cd."';"; $set.="site_name='".$_POST['p_site_name']."';"; $set.="return_home_url='".$_POST['p_return_home_url']."';"; $set.="new_dir_indic='".$_POST['p_new_dir_indic']."';"; $set.="language='".$_POST['p_language']."';"; $set.="date_format='".$_POST['p_date_format']."';"; $set.="cookie_password_hours='".$_POST['p_cookie_password_hours']."';"; //0.3.0 $set.="ftp_server='".$_POST['p_ftp_server']."';"; $set.="ftp_server_photos_dir='".$_POST['p_ftp_server_photos_dir']."';"; $set.="default_sorting='".$_POST['p_default_sorting']."';"; db_update("setup",$set); read_settings(); } //scan photodirectory if it was changed if($old_pd!=$p_pd){ scan_photos_directories(""); } // /save_quality_settings(); ob_start();require("setup_main.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="logs"){ if($var2=="save"){ if(isset($_POST["p_enabled"])){ $set="logs_enabled='true';"; }else{ $set="logs_enabled='false';"; } $set.="logs_filename='".$_POST['p_filename']."';"; $set.="logs_exclude='".$_POST['p_exclude']."';"; db_update("setup",$set); read_settings(); } ob_start();require("setup_logs.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="pics"){ if(strlen($var3)==0){ $rec=db_select_all("directory","path=='/'"); $var3=$rec[0]["seq_files"]; } if($var2=="scan_dirs"){ scan_photos_directories(""); } $params=db_select_all("photo_param"); if($var2=="save"){ $cnt=1; while( isset($_POST["p_file_name$cnt"])){ $set=""; $set.="desc='".$_POST["p_desc$cnt"]."';"; $set.="long_desc='".$_POST["p_long_desc$cnt"]."';"; if(isset($_POST["p_visible$cnt"])){ $set.="visible='true';"; }else{ $set.="visible='false';"; } if(isset($_POST["p_use_for_logo$cnt"])){ $set.="use_for_logo='true';"; }else{ $set.="use_for_logo='false';"; } //photo parameters $p=Array(); foreach($params as $param){ if(isset($_POST["p_param".$cnt."_".$param["id"]])){ $p[$param["id"]]=$_POST["p_param".$cnt."_".$param["id"]]; } } $set.="params=".var_export($p,true).";"; db_update("files_$var3",$set,"file_name=='".$_POST["p_file_name$cnt"]."'"); $cnt++; } } ob_start();require("setup_photos.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="dirs"){ if(strlen($var3)==0){ $rec=db_select_all("directory","path=='/'"); $var3=$rec[0]["seq_files"]; } if($var2=="scan_dirs"){ scan_photos_directories(""); } if($var2=="save"){ /*save settings*/ $rec=db_select_all("directory","seq_files=='$var3'",null,true); $dir=$rec[0]; $set="alias='".$_POST["p_alias"]."';"; if(isset($_POST["p_visibility"])){ $set.="visibility='true';"; }else{ $set.="visibility='false';"; } $set.="desc='".$_POST["p_desc"]."';"; $set.="long_desc='".$_POST["p_long_desc"]."';"; $set.="sorting='".$_POST["p_sorting"]."';"; $set.="show_parameters='".$_POST["p_show_parameters"]."';"; if($_POST["p_show_parameters"]=="custom" && isset($_POST["p_default"])){ //switched from default to custom, select default params as default $rec=db_select_all("photo_param","default_displayed=='true'"); foreach($rec as $param){ $set_custom_ids[$param["id"]]='1'; } }else{ foreach($_POST as $key => $post){ if(substr($key,0,7)=="p_param"){ $set_custom_ids[$post]='1'; } } } $set.="show_parameters_custom_id=".var_export($set_custom_ids,true ).";"; //groups $set_inh=""; //select all groups $grps=db_select_all("group"); foreach($grps as $group){ $group_found=false; foreach($_POST as $key => $post){ if(substr($key,0,7)=="p_group" && $post==$group["name"]){ if(!isset($dir["inh_groups"][$post])){ //if it was not inherited then $new_groups[$post]="1"; $set_inh.="if(!isset(inh_groups[$post])){inh_groups[$post]=$var3;}"; $group_found=true; } } } if(!$group_found){ $set_inh.="if(inh_groups[".$group["name"]."]==$var3){unset(inh_groups[".$group["name"]."]);}"; } } $set.="groups=".var_export($new_groups,true).";"; db_update("directory",$set,"seq_files=='$var3'"); //$set_inh="inh_groups=".var_export($inh_groups,true).";"; $len=strlen($dir["path"]); db_update("directory",$set_inh,"substr(path,0,$len)=='".$dir["path"]."' && path!='".$dir["path"]."'"); } ob_start();require("setup_dirs.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="comments"){ if($var2=="delete"){ if($var3 && $var4){ delete_comment($var3,$var4); update_stats("imageview",$var3,"comment","del"); } } if($var2=="approve"){ if($var3 && $var4){ approve_comment($var3,$var4); } } if($var2=="save"){ $set=""; if(isset($_POST['p_comments_enabled'] )){ $set.="comments_enabled='true';"; }else{ $set.="comments_enabled='false';"; } $set.="comments_approve_queue_size=".$_POST["p_comments_approve_queue_size"].";"; db_update("setup",$set); read_settings(); } ob_start();require("setup_comments.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="cache"){ if($var2=="delete"){ delete_cache($pa_setup["cache_dir"],0); } if($var2=="save"){ $set=""; if(isset($_POST['p_cache_thumbnails'] )){ $set.="cache_thumbnails='true';"; }else{ $set.="cache_thumbnails='false';"; } if(isset($_POST['p_cache_resized_photos'] )){ $set.="cache_resized_photos='true';"; }else{ $set.="cache_resized_photos='false';"; } db_update("setup",$set); read_settings(); } ob_start();require("setup_cache.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="errorlog"){ ob_start();include("setup_errorlog.inc"); $contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="texts"){ if($var2=="save"){ if(file_exists($data_dir.$pa_lang["translate_file"])){ /*delete*/ unlink($data_dir.$pa_lang["translate_file"]); } $first=true; foreach($_POST as $key => $text){ if(substr($key,0,3)=="ID_" && strlen($text)>0){ $text=str_replace(Array('\\','"'),Array('\\\\','\"'),stripslashes($text)); /*this is an id translation*/ if($first){ $file=fopen($data_dir.$pa_lang["translate_file"],"w"); $first=false; fwrite($file," \"$text\"\n"); }else{ fwrite($file,",\"$key\" => \"$text\"\n"); } } } if(!$first){ fwrite($file,");\n?>\n"); fclose($file); } if(file_exists($data_dir.$pa_lang["translate_file"])){ unset($pa_translated_texts); include($data_dir.$pa_lang["translate_file"]); }else{ unset($pa_translated_texts); } } ob_start();require("setup_texts.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var1=="admin"){ if(isset($_COOKIE['p_pass'])){ $p_pass=$_COOKIE['p_pass']; } if(isset($_COOKIE['p_user'])){ $p_user=$_COOKIE['p_user']; } if(isset($_COOKIE['p_actdir'])){ $p_actdir=$_COOKIE['p_actdir']; } if(isset($_POST['p_user'])){ $p_user=$_POST['p_user']; } if(isset($_POST['p_pass'])){ $p_pass=$_POST['p_pass']; } if(isset($_POST['p_dir'])){ $p_dir=conv_in($_POST['p_dir']); } if(isset($_GET['p_dir'])){ $p_dir=conv_in($_GET['p_dir']); } if(isset($_POST['p_file_name'])){ $p_file_name=conv_in($_POST['p_file_name']); } if(isset($_GET['p_file_name'])){ $p_file_name=conv_in($_GET['p_file_name']); } if(!$var2){ ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="login"){ if( !($ftp_error=ftp_check_login($p_user,$p_pass)) ){ /*set cookie*/ setcookie("p_user",$p_user); setcookie("p_pass",$p_pass); setcookie("p_actdir",""); $p_actdir=""; ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; }else{ $var2=""; ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } } if($var2=="chdir"){ $p_actdir=$p_dir; setcookie("p_actdir",$p_actdir); ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="mkdir"){ $ftp_error=ftp_setup_mkdir($p_user,$p_pass,$p_actdir,$p_dir); ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="rmdir"){ $ftp_error=ftp_setup_rmdir($p_user,$p_pass,$p_actdir,$p_dir); ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="delete"){ $ftp_error=ftp_setup_delete($p_user,$p_pass,$p_actdir,$p_file_name); ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="upload"){ $uploaddir = $pa_setup["cache_dir"]; if (move_uploaded_file($_FILES['p_file']['tmp_name'], $uploaddir . conv_in($_FILES['p_file']['name']))) { $ftp_error=ftp_setup_put_file($p_user,$p_pass,$p_actdir,$uploaddir . conv_in($_FILES['p_file']['name']),conv_in($_FILES['p_file']['name'])); /*deleted from cache*/ unlink($uploaddir . $_FILES['p_file']['name']); } else { $ftp_error=t("ID_MSG_FTP_FILE_UPLOAD_ATTACK"); } ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } if($var2=="uploadzip"){ $uploaddir = $pa_setup["cache_dir"]; if (move_uploaded_file($_FILES['p_file']['tmp_name'], $uploaddir . conv_in($_FILES['p_file']['name']))) { $ftp_error=ftp_setup_put_zip_file($p_user,$p_pass,$p_actdir,$uploaddir . conv_in($_FILES['p_file']['name']),conv_in($_FILES['p_file']['name'])); /*deleted from cache*/ unlink($uploaddir . $_FILES['p_file']['name']); } else { $ftp_error=t("ID_MSG_FTP_FILE_UPLOAD_ATTACK"); } ob_start();require("setup_admin.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); return; } } //ob_start();require("setup.inc");$contents = ob_get_contents();ob_end_clean();theme_generate_setup_page($menu,$contents); } /**********************************************************/ /****************** FTP Functions *************************/ /**********************************************************/ function create_dir($conn,$remote_directory){ global $error_logging; $error_logging=false; $dir=split("/", $remote_directory); $path=""; $result = true; for ($i=1;$i0){ if (zip_entry_open($zip, $zip_entry, "rb")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $ft=fopen($tmp,"wb"); if($ft){ fwrite($ft,$buf,zip_entry_filesize($zip_entry)); fclose($ft); }else{ ftp_close($conn);return t("ID_MSG_FTP_UNABLE_OPEN_TMP"); } if(!ftp_put($conn,$pa_setup["ftp_server_photos_dir"].$p_actdir.zip_entry_name($zip_entry),$tmp,FTP_BINARY)){ $result=create_dir($conn,$pa_setup["ftp_server_photos_dir"].$p_actdir.dirname(zip_entry_name($zip_entry))); if(!$result){ ftp_close($conn);return t("ID_MSG_FTP_UNABLE_MKDIR",dirname(zip_entry_name($zip_entry)));} if(!ftp_put($conn,$pa_setup["ftp_server_photos_dir"].$p_actdir.zip_entry_name($zip_entry),$tmp,FTP_BINARY)){ftp_close($conn);return "Unable to upload file ".zip_entry_name($zip_entry);} } zip_entry_close($zip_entry); } }else{ $result=create_dir($conn,$pa_setup["ftp_server_photos_dir"].$p_actdir.zip_entry_name($zip_entry)); if(!$result){ ftp_close($conn);return t("ID_MSG_FTP_UNABLE_MKDIR",$p_dir); } } } }else{ ftp_close($conn);return t("ID_MSG_FTP_NOT_ZIP"); } }else{ ftp_close($conn);return t("ID_MSG_FTP_ZIP_UNSUPPORTED"); } $result=ftp_close($conn); return ""; } function ftp_check_login($p_user,$p_pass){ /*create test file, upload and thest if it comes to the right directory*/ global $pa_setup; $conn=ftp_connect($pa_setup["ftp_server"]); if (!$conn ){ return t("ID_MSG_FTP_UNABLE_CONNECT",$pa_setup["ftp_server"]); } $result = ftp_login($conn,$p_user,$p_pass); if(!$result){ ftp_close($conn); return t("ID_MSG_FTP_INVALID_LOGIN"); } $result = ftp_pasv($conn,true); if(!$result){ ftp_close($conn); return t("ID_MSG_FTP_PASSIVE_MODE"); } /*reading install script and doing what to do is*/ $result=ftp_chdir($conn,$pa_setup["ftp_server_photos_dir"]."."); if(!$result){ ftp_close($conn); return t("ID_MSG_FTP_UNABLE_CHDIR",$pa_setup["ftp_server_photos_dir"].$p_actdir); } $test=md5(time()); $f=fopen($pa_setup["cache_dir"].".test","w"); fwrite($f,$test); fclose($f); if(!ftp_put($conn,".test",$pa_setup["cache_dir"].".test",FTP_BINARY)){ftp_close($conn); return t("ID_MSG_FTP_UNABLE_UPLOAD","testfile");} $ff=file($pa_setup["album_dir"].".test"); if($ff[0]!=$test){ ftp_close($conn); return t("ID_MSG_FTP_PHOTO_DIR"); } $result=ftp_delete($conn,".test"); $result=ftp_close($conn); return ""; } function my_cmp($a,$b){ if($a['type']==$b['type']){ if($a['name']==$b['name']) return 0; return ($a['name'] < $b['name']) ? -1 : 1; } if($a['type']=="dir") return -1; return 1; } function ftp_get_files($actdir){ global $pa_setup; $files=Array(); $dir=$pa_setup["album_dir"].$actdir; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $f=Array(); if( filetype($dir . $file)=="dir" ){ $f['type']="dir"; }else{ $f['type']="file"; } $f['name']=$file; $f['size']=filesize($dir."/".$file)." B"; if(is_image($file)){ list($width,$height)=getimagesize($dir."/".$file); $f['image_size']=$width." x ".$height; } if(function_exists('posix_getpwuid')){ $ow=posix_getpwuid(fileowner($dir."/".$file)); $f['owner']=$ow['name']; }else{ $f['owner']=fileowner($dir."/".$file); } if(function_exists('posix_getgrgid')){ $gr=posix_getgrgid(filegroup($dir."/".$file)); $f['group']=$gr['name']; }else{ $f['group']=filegroup($dir."/".$file); } $f['time']=date("d.m.Y H:i:s",filectime($dir."/".$file)); if($f['type']=="dir" && $f['name']!=".." && $f['name']!="."){ $f['func']="remove_dir"; }else if($f['type']=="file"){ $f['func']="delete"; } $files[]=$f; } closedir($dh); } } if(is_array($files)) usort($files,"my_cmp"); return $files; } /**********************************************************/ /**************END FTP Functions *************************/ /**********************************************************/ function write_log(){ global $pa_setup,$cmd,$var1,$passwd,$comment_name; if($pa_setup["logs_enabled"]=="true"){ $strings=explode(";",$pa_setup["logs_exclude"]); $found="false"; $host=gethostbyaddr($_SERVER['REMOTE_ADDR']); foreach($strings as $num=>$string){ if(strlen($string)>0) if(strstr($host,$string))$found="true"; } if($found=="false"){ $file_log=fopen($pa_setup["cache_dir"].$pa_setup["logs_filename"],"a"); fwrite($file_log,date("D.M.j G:i:s")."|".$cmd."|".$var1."|".$comment_name."|".$host."|".$passwd."|\n"); fclose($file_log); } } } function generate_theme($var1){ if($var1=="style_css"){ theme_get_style_css(); return; } } function install_database(){ global $data_dir; require("install_db.php"); } /****************************************/ /* Start Program v0. */ /****************************************/ /* foreach($_POST as $key=>$value){ $_POST[$key]=stripslashes($value); } */ if(isset($_GET['cmd'])){ $cmd=$_GET['cmd']; } if(isset($_GET['var1'])){ $var1=stripslashes($_GET['var1']); } if(isset($_GET['var2'])){ $var2=stripslashes($_GET['var2']); } if(isset($_GET['var3'])){ $var3=stripslashes($_GET['var3']); } if(isset($_GET['var4'])){ $var4=stripslashes($_GET['var4']); } if(isset($_POST['cmd'])){ $cmd=$_POST['cmd']; } if(isset($_POST['var1'])){ $var1=$_POST['var1']; } if(isset($_POST['var2'])){ $var2=$_POST['var2']; } if(isset($_POST['var3'])){ $var3=$_POST['var3']; } if(isset($_POST['var4'])){ $var4=$_POST['var4']; } if($cmd!="album" && $cmd!="phpinfo" && $cmd!="thmb" && $cmd!="imageorig" && $cmd!="image" && $cmd!="imageview" && $cmd!="setup" && $cmd!="delcache" && $cmd!="logo" && $cmd!="theme" && $cmd!="themeimage" && //$cmd!="system_check" && $cmd!="setquality"){ $cmd="album"; } require("phpdatabase.php"); /*if(!db_startup_database("album",$data_dir)){ install_database(); }*/ if(!db_startup_database("album",$data_dir)){ db_create_database("album",$data_dir); install_database(); } db_set_auto_commit(false); read_settings(); require($themes_dir."engines/".$site_engine."/engine.php"); require("language.php"); if($cmd=="setquality"){ if(!($rec=db_select_all("quality","id=='$var1'"))){ //setted quality not found $rec=db_select_all("quality","default=='true'"); } $pa_quality=$rec[0]; setcookie("phpAlbum_quality",$pa_quality["id"],time()+60*60*24*365); $cmd=$var2;$var1=$var3;$var2="";$var3=""; if(isset($var3)){ $var2=$var3;} if(isset($var4)){ $var3=$var4;} }else{ if(isset($_COOKIE["phpAlbum_quality"])){ if(!($rec=db_select_all("quality","id=='".$_COOKIE["phpAlbum_quality"]."'"))){ //setted quality not found $rec=db_select_all("quality","default=='true'"); } }else{ $rec=db_select_all("quality","default=='true'"); } $pa_quality=$rec[0]; } if(strstr($var1,"..")){ $var1=""; } if(isset($_GET["logout"])){ setcookie("userid","",time()-60*60*24*365); setcookie("userpassword","",time()-60*60*24*365); }else{ if(isset($_COOKIE['userid'])){ $userid=$_COOKIE['userid']; } if(isset($_COOKIE['userpassword'])){ $userpassword=$_COOKIE['userpassword']; } } if(isset($_POST["p_username"])){ $username=$_POST["p_username"]; $userpassword=md5($_POST["p_userpassword"]); $rec=db_select_all("user","name=='".$username."' && password=='".$userpassword."'"); if(isset($rec[0])){ $pa_user=$rec[0]; if(!isset($_POST["p_storepassword"])){ setcookie("userid",$pa_user["id"]); setcookie("userpassword",$userpassword); }else{ setcookie("userid",$pa_user["id"],time()+60*60*24*365); setcookie("userpassword",$userpassword,time()+60*60*24*365); } }else{ $pa_user=Array("name"=>"guest","groups"=>Array("guest"=>"1")); } }else{ $rec=db_select_all("user","id=='".$userid."' && password=='".$userpassword."'"); if(isset($rec[0])){ $pa_user=$rec[0]; }else{ $pa_user=Array("name"=>"guest","groups"=>Array("guest"=>"1")); } } //take all groups where the user is a member //and merge the grants to be easy to check it later if needed $where=""; foreach($pa_user["groups"] as $key => $value){ if($where ==""){ $where = $where . "name=='".$key."'"; }else{ $where = $where . "|| name=='".$key."'"; } } $rec=db_select_all("group",$where); $pa_grants=Array(); foreach($rec as $record){ $pa_grants =array_merge($pa_grants,$record["grants"]); } /*full-scanning directories evry 1 day*/ if($pa_setup["last_dir_scan"]Loaded from cache"; return; } } /*header("Last-Modified: ".date("D, d M Y H:i:s T",time()) ); */ /*testing for php-info*/ $cache_this_doc=true; if($this_is_cachable){ob_start();} /*testing for password */ if($cmd=="phpinfo"){ phpinfo(); }else if($cmd=="album"){ write_log(); $cache_this_doc=generate_album($var1,$passwd,$var3); }else if($cmd=="thmb"){ generate_thumb($var1,$var3); }else if($cmd=="image"){ if(is_movie($var1) || is_audio($var1)){ write_log(); } $cache_this_doc=generate_image($var1,$quality);/* original photos, videos and audios should not be cached.*/ }else if($cmd=="imageorig"){ if(is_movie($var1) || is_audio($var1)){ write_log(); } $cache_this_doc=generate_image($var1,$quality,true);/* original photos, videos and audios should not be cached.*/ }else if($cmd=="imageview"){ write_log(); generate_image_view($var1,$quality,$var3); }else if($cmd=="setup"){ generate_setup_page(); }else if($cmd=="system_check"){ generate_system_check(); }else if($cmd=="delcache"){ delete_cache($pa_setup["cache_dir"]); echo "Cache Deleted!"; }else if($cmd=="theme"){ generate_theme($var1); }else if($cmd=="logo"){ theme_generate_logo(); }else if($cmd=="themeimage"){ if(!isset($var3)){$var3=100;}//no scaling if not defined $cache_this_doc=theme_generate_theme_image($var1,$var2,$var3); }else{ //include("header.inc"); echo "File Not Found"; } /*caching output*/ db_commit();// just to be sure if($this_is_cachable){ if(is_cachable($cmd,$var1) && $cache_this_doc){ cache_document($cmd,$var1,$var2,$var3,$quality); } ob_end_flush(); } ?>