'.
' '.TEXT_MOVE_TO.':
'.TEXT_HOME.'/'.GALLERY.''.
'
OK'.
'
'.TEXT_CANCEL.''.
'
'.TEXT_HOME.'';
$dirs=explode('/',GALLERY);
$path='';
$postDiv='';
foreach($dirs as $dir)
{
if ($dir)
{
$path.=$dir.'/';
echo '
'.$dir.'';
$postDiv.='
';
}
}
$items=@scandir(GALLERY_ROOT.GALLERY);
if ($items!==false)
{
echo '
';
foreach($items as $var)
{
if ((is_dir(GALLERY_ROOT.GALLERY.$var)) and ($var != '.') and ($var != '..'))
{
echo ''.$var.'
';
}
}
}
echo $postDiv.'
';
}
function sfpg_div_num($input)
{
$tmp = explode('/', $input);
if (count($tmp)==2) // if input contains one /, like: "1/250"
{
if(is_numeric($tmp[0]) and is_numeric($tmp[1]) and ($tmp[1]!=0)) // if both sides are numbers and $tmp[1] is not 0.
{
return $tmp[0]/$tmp[1];
}
}
if (is_numeric($input))
{
return $input;
}
return 0;
}
function data_as_str($data)
{
if(is_array($data))
{
$res='';
foreach($data as $d)
{
$res.=($res!=''?', ':'').data_as_str($d);
}
return $res;
}
else
{
if(isset($data))
{
return trim((string)$data);
}
else
{
return '';
}
}
}
function sfpg_image($image_dir, $image_file, $func, $download=FALSE, $spider=FALSE)
{
$image_path_file = DATA_ROOT.$func.'/'.$image_dir.$image_file;
$image_type = sfpg_image_type($image_file);
if ($func == 'image')
{
if (!file_exists($image_path_file))
{
$image_path_file = GALLERY_ROOT.$image_dir.$image_file;
}
if ($download)
{
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$image_file.'"');
}
else
{
header('Content-Type: image/'.$image_type);
header('Content-Disposition: filename="'.$image_file.'"');
}
readfile($image_path_file);
return;
}
if ($func == 'thumb')
{
if (file_exists($image_path_file))
{
if (!$spider)
{
header('Content-Type: image/'.$image_type);
header('Content-Disposition: filename="'.$func.'_'.$image_file.'"');
readfile($image_path_file);
}
return;
}
else
{
$max_width = THUMB_MAX_WIDTH;
$max_height = THUMB_MAX_HEIGHT;
$enlarge = THUMB_ENLARGE;
$jpeg_quality = THUMB_JPEG_QUALITY;
$source_img = GALLERY_ROOT.$image_dir.$image_file;
$image_changed = FALSE;
if ($image_type=='webp') // the imagecreatefromstring function can't handle animated WebP images. So check for this and return/skip if found. When it gets fixed by PHP, this 'if' can be removed.
{
if (stripos(file_get_contents($source_img, false, null, 0, 40),'ANIM')!==FALSE)
{
return;
}
}
if ((MPO_FULL_IMAGE or MPO_STEREO_IMAGE) and (sfpg_ext($image_file)=='.mpo'))
{
if (!$image = sfpg_mpo_image($source_img))
{
return;
}
$image_changed = TRUE;
}
elseif (!$image = imagecreatefromstring(file_get_contents($source_img)))
{
return;
}
if (($func == 'thumb') and ($image_dir != ICONS_DIR))
{
sfpg_mkdir(DATA_ROOT.'info/'.$image_dir);
$image_info = [];
if ((SHOW_EXIF_INFO or ROTATE_IMAGES) and function_exists('exif_read_data') and ($image_type!='webp')) // exif_read_data do not yet support the WebP format.
{
$exif_data = @exif_read_data(GALLERY_ROOT.$image_dir.$image_file, 'IFD0');
if (SHOW_EXIF_INFO)
{
if ($exif_data !== FALSE)
{
if(isset($exif_data['DateTimeOriginal']))
{
$exif_time = explode(':', str_replace(' ', ':', $exif_data['DateTimeOriginal']));
if(count($exif_time)==6)
{
$image_info['exifDate'] = block_html(mktime((int)$exif_time[3], (int)$exif_time[4], (int)$exif_time[5], (int)$exif_time[1], (int)$exif_time[2], (int)$exif_time[0]));
}
}
if (isset($exif_data['Model']))
{
$image_info['exifModel'] = block_html($exif_data['Model']);
}
if (isset($exif_data['ISOSpeedRatings']))
{
$image_info['exifISOSpeedRatings'] = block_html($exif_data['ISOSpeedRatings']);
}
if(isset($exif_data['ExposureTime']))
{
$exp_time = round(sfpg_div_num($exif_data['ExposureTime']),2);
if ($exp_time > 0.25)
{
$image_info['exifExposureTime'] = block_html($exp_time.'s');
}
else
{
$tmp = explode('/', $exif_data['ExposureTime']);
if (count($tmp)==2) // if input contains one /, like: "1/250"
{
$as=(string)($tmp[0]);
$bs=(string)($tmp[1]);
while ((substr($as,-1)=='0') and (substr($bs,-1)=='0') and (strlen($as)>1) and (strlen($bs)>1)) // removed tailing 0 if both sides have them, like 10/10000
{
$as=substr($as,0,-1);
$bs=substr($bs,0,-1);
}
$image_info['exifExposureTime'] = block_html($as.'/'.$bs.'s');
}
else
{
$image_info['exifExposureTime'] = block_html($exif_data['ExposureTime'].'s');
}
}
}
if(isset($exif_data['FNumber']))
{
$image_info['exifFNumber'] = block_html('f'.number_format(round(sfpg_div_num($exif_data['FNumber']),1),1));
}
if(isset($exif_data['FocalLength']))
{
$image_info['exifFocalLength'] = block_html(number_format(round(sfpg_div_num($exif_data['FocalLength']),1),1).'mm');
}
if(isset($exif_data['Flash']))
{
$image_info['exifFlash'] = block_html((($exif_data['Flash'] & 1) ? TEXT_YES : TEXT_NO));
}
if (isset($exif_data['GPSLatitude']) and isset($exif_data['GPSLongitude']))
{
$lat = $exif_data['GPSLatitude'];
$lng = $exif_data['GPSLongitude'];
$image_info['exifGPSLatitude'] = block_html(sfpg_div_num($lat[0])).'°'.block_html(sfpg_div_num($lat[1]).'\''.sfpg_div_num($lat[2]).'"'.@$exif_data['GPSLatitudeRef']);
$image_info['exifGPSLongitude'] = block_html(sfpg_div_num($lng[0])).'°'.block_html(sfpg_div_num($lng[1]).'\''.sfpg_div_num($lng[2]).'"'.@$exif_data['GPSLongitudeRef']);
$image_info['exifGPSLatitudeDec'] = block_html(round(((sfpg_div_num($lat[0]) + sfpg_div_num($lat[1])/60 + sfpg_div_num($lat[2])/3600)*(@$exif_data['GPSLatitudeRef']=='N'?1:-1)),12)); // limited to 12 decimals
$image_info['exifGPSLongitudeDec'] = block_html(round(((sfpg_div_num($lng[0]) + sfpg_div_num($lng[1])/60 + sfpg_div_num($lng[2])/3600)*(@$exif_data['GPSLongitudeRef']=='W'?-1:1)),12)); // limited to 12 decimals
}
}
}
if (ROTATE_IMAGES and isset($exif_data['Orientation']))
{
$orientation = (int)$exif_data['Orientation'];
if (($orientation>1) and ($orientation<9))
{
if (($orientation==3) or ($orientation==4))
{
$image = imagerotate($image, 180, 0);
}
elseif (($orientation==5) or ($orientation==6))
{
$image = imagerotate($image, -90, 0);
}
elseif (($orientation==7) or ($orientation==8))
{
$image = imagerotate($image, 90, 0);
}
if (($orientation==2) or ($orientation==4) or ($orientation==5) or ($orientation==7))
{
imageflip($image, IMG_FLIP_HORIZONTAL);
}
$image_changed = TRUE;
}
}
}
if(SHOW_IPTC_INFO)
{
$only_used_for_iptc = getimagesize(GALLERY_ROOT.$image_dir.$image_file, $info);
if (isset($info['APP13']))
{
$iptcParsed = iptcparse($info['APP13']);
foreach(IPTC as $iptcID => $iptcText)
{
if (isset($iptcParsed[$iptcID]))
{
$image_info[$iptcID] = block_html($iptcParsed[$iptcID][0]);
}
}
}
}
if (PNG_TEXT_CHUNKS and ($image_type=='png'))
{
if ($png_fp = @fopen(GALLERY_ROOT.$image_dir.$image_file, 'rb'))
{
if("\x89PNG\x0d\x0a\x1a\x0a" === fread($png_fp, 8)) // first 8 bytes in a PNG must be like this
{
$png_text_chunks=[];
while(!feof($png_fp))
{
$chunk_info = @unpack('Nlength/a4type', fread($png_fp, 8));
if(!$chunk_info or ($chunk_info['type'] == 'IEND'))
{
break;
}
if($chunk_info['type'] == 'tEXt')
{
$chunk_data = fread($png_fp, $chunk_info['length']);
$chunk_crc = @unpack('Ncrc', fread($png_fp, 4));
if($chunk_crc and ($chunk_crc['crc'] === crc32($chunk_info['type'].$chunk_data)))
{
list($keyword, $value) = explode("\0", $chunk_data);
if((PNG_TEXT_CHUNKS === TRUE) or ((is_array(PNG_TEXT_CHUNKS)) and (in_array(strtolower($keyword), PNG_TEXT_CHUNKS))))
{
$png_text_chunks[]=block_html($keyword);
$png_text_chunks[]=block_html($value);
}
}
}
else
{
fseek($png_fp, $chunk_info['length']+4, SEEK_CUR); // skip the chunk + crc
}
}
fclose($png_fp);
if(count($png_text_chunks)>0)
{
$image_info['pngChunks'] = $png_text_chunks;
}
}
}
}
if (WEBP_EXIF and ($image_type=='webp'))
{
if ($webp_fp = @fopen(GALLERY_ROOT.$image_dir.$image_file, 'rb'))
{
$webp_exif=[];
$webp_header = @unpack('a4riff/I1size/a4webp', fread($webp_fp, 12));
if (($webp_header['riff']=='RIFF') and ($webp_header['webp']=='WEBP')) // required WebP header
{
while(!feof($webp_fp))
{
$chunk_info = @unpack('a4type/I1size', fread($webp_fp, 8));
if(!$chunk_info)
{
break;
}
if($chunk_info['type'] == 'EXIF')
{
$chunk_data = fread($webp_fp, $chunk_info['size']); // read EXIF chunk from image
$php_mem = fopen('php://memory', 'w+'); // create php memory stream
fputs($php_mem, $chunk_data);
rewind($php_mem);
$exif=@exif_read_data($php_mem, null, true);
fclose($php_mem);
foreach(WEBP_EXIF as $key=>$data)
{
foreach($data as $id)
{
if(isset($exif[$key][$id]))
{
$exif_data_str=data_as_str($exif[$key][$id]);
if($exif_data_str!='')
{
$webp_exif[]=block_html($id);
$webp_exif[]=block_html($exif_data_str);
}
}
}
}
break; // stop searching as only one EXIF section is allowed
}
else
{
fseek($webp_fp, $chunk_info['size'], SEEK_CUR); // skip the chunk
}
if ($chunk_info['size'] & 1) // if chunk size is odd, skip the padding byte
{
fseek($webp_fp, 1, SEEK_CUR);
}
}
fclose($webp_fp);
if(count($webp_exif)>0)
{
$image_info['webpExif'] = $webp_exif;
}
}
}
}
if (WATERMARK)
{
$wm_file = GALLERY_ROOT.ICONS_DIR.WATERMARK;
if (file_exists($wm_file))
{
if ($watermark = imagecreatefromstring(file_get_contents($wm_file)))
{
$image_width = imagesx($image);
$image_height = imagesy($image);
$ww = imagesx($watermark);
$wh = imagesy($watermark);
if (WATERMARK_FRACTION)
{
if ($image_width < $image_height)
{
$ww_new = round($image_width * WATERMARK_FRACTION);
}
else
{
$ww_new = round($image_height * WATERMARK_FRACTION);
}
$wh_new = round($wh * ($ww_new / $ww));
}
else
{
$ww_new = $ww;
$wh_new = $wh;
}
imagecopyresampled ($image, $watermark, $image_width-$ww_new, $image_height-$wh_new, 0, 0, $ww_new, $wh_new, $ww, $wh);
imagedestroy($watermark);
$image_changed = TRUE;
}
}
}
if ($image_changed)
{
sfpg_mkdir(DATA_ROOT.'image/'.$image_dir);
$new_full_img = DATA_ROOT.'image/'.$image_dir.$image_file;
if ($image_type == 'jpeg')
{
imagejpeg($image, $new_full_img, IMAGE_JPEG_QUALITY);
}
elseif ($image_type == 'png')
{
imagepng($image, $new_full_img);
}
elseif ($image_type == 'gif')
{
imagegif($image, $new_full_img);
}
elseif ($image_type == 'webp')
{
imagewebp($image, $new_full_img);
}
}
$image_info['fileMTime'] = filemtime(GALLERY_ROOT.$image_dir.$image_file); // also used for deleting data if time have changed
$image_info['fileSize'] = sfpg_file_size(filesize(GALLERY_ROOT.$image_dir.$image_file));
$image_info['imageSizeX'] = block_html(imagesx($image));
$image_info['imageSizeY'] = block_html(imagesy($image));
file_put_contents(DATA_ROOT.'info/'.$image_dir.$image_file, serialize($image_info));
}
list($new_img_width, $new_img_height) = sfpg_aspect_resize(imagesx($image), imagesy($image), $max_width, $max_height, $enlarge);
if(THUMB_SQUARE)
{
$new_img_width = $max_width;
$new_img_height = $max_width;
}
$new_image = imagecreatetruecolor($new_img_width, $new_img_height);
if(THUMB_TRANSPARENCY and (($image_type == 'png') or ($image_type == 'webp')))
{
imagealphablending($new_image, false);
imagesavealpha($new_image,true);
}
if(LOW_IMAGE_RESAMPLE_QUALITY)
{
if(THUMB_SQUARE)
{
$min_size = min(imagesx($image), imagesy($image));
imagecopyresized($new_image, $image, 0, 0, round((imagesx($image)- $min_size)/2), 0, $new_img_width, $new_img_height, $min_size, $min_size);
}
else
{
imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_img_width, $new_img_height, imagesx($image), imagesy($image));
}
}
else
{
if(THUMB_SQUARE)
{
$min_size = min(imagesx($image), imagesy($image));
imagecopyresampled($new_image, $image, 0, 0, round((imagesx($image)- $min_size)/2), 0, $new_img_width, $new_img_height, $min_size, $min_size);
}
else
{
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_img_width, $new_img_height, imagesx($image), imagesy($image));
}
}
imagedestroy($image);
sfpg_mkdir(DATA_ROOT.$func.'/'.$image_dir);
if (!$spider)
{
header('Content-type: image/'.$image_type);
header('Content-Disposition: filename="'.$func.'_'.$image_file.'"');
}
if ($image_type == 'jpeg')
{
if (!$spider)
{
imagejpeg($new_image, null, $jpeg_quality);
}
imagejpeg($new_image, $image_path_file, $jpeg_quality);
}
elseif ($image_type == 'png')
{
if (!$spider)
{
imagepng($new_image);
}
imagepng($new_image, $image_path_file);
}
elseif ($image_type == 'gif')
{
if (!$spider)
{
imagegif($new_image);
}
imagegif($new_image, $image_path_file);
}
elseif ($image_type == 'webp')
{
if (!$spider)
{
imagewebp($new_image);
}
imagewebp($new_image, $image_path_file);
}
imagedestroy($new_image);
}
}
}
function sfpg_dir_info($dir, $initial=TRUE)
{
list($dirs, $images, $files, $misc) = sfpg_get_dir($dir, TRUE);
if ($initial)
{
$info['dirDirs'] = count($dirs);
$info['dirImages'] = (int)(count($images)-$misc);
$info['dirFiles'] = count($files);
$info['dirTime'] = filemtime(GALLERY_ROOT.GALLERY.'.');
}
else
{
$info = [];
}
if ((DIR_THUMB_FILE) and file_exists(GALLERY_ROOT.$dir.DIR_THUMB_FILE))
{
$info['dirThumb'] = sfpg_url_string($dir, DIR_THUMB_FILE);
return $info;
}
if (DIR_THUMB_FROM_ICONS_DIR and file_exists(GALLERY_ROOT.ICONS_DIR.DIR_THUMB_FILE))
{
$info['dirThumb'] = sfpg_url_string(ICONS_DIR, DIR_THUMB_FILE);
return $info;
}
if (isset($images[0]))
{
$info['dirThumb'] = sfpg_url_string($dir, $images[0]);
return $info;
}
foreach ($dirs as $subdir) // searching for dir-thumb in subdirs
{
$subresult = sfpg_dir_info($dir.$subdir.'/', FALSE);
if (isset($subresult['dirThumb']))
{
$info['dirThumb'] = $subresult['dirThumb'];
return $info;
}
}
if ($initial and file_exists(GALLERY_ROOT.ICONS_DIR.DIR_THUMB_FILE))
{
$info['dirThumb'] = sfpg_url_string(ICONS_DIR, DIR_THUMB_FILE);
return $info;
}
return $info;
}
function sfpg_set_dir_info($dir)
{
if (!sfpg_mkdir(DATA_ROOT.'info/'.$dir))
{
sfpg_clean_data_root($dir);
}
file_put_contents(DATA_ROOT.'info/'.$dir.'_sfpg_dir', serialize(sfpg_dir_info($dir)));
}
function sfpg_delete($element)
{
if (is_dir($element))
{
$items = array_diff(scandir($element),['.','..']);
foreach ($items as $item)
{
sfpg_delete($element.'/'.$item);
}
rmdir($element);
}
elseif (file_exists($element))
{
unlink($element);
}
}
function sfpg_delete_from_data_root($element)
{
sfpg_delete(DATA_ROOT.'info/'.$element);
sfpg_delete(DATA_ROOT.'thumb/'.$element);
sfpg_delete(DATA_ROOT.'image/'.$element);
sfpg_delete(DATA_ROOT.'zip/'.$element);
}
function sfpg_clean_data_root($dir)
{
$items = array_diff(scandir(DATA_ROOT.'info/'.$dir),['.','..','_sfpg_dir']);
foreach($items as $item)
{
if (!is_dir(GALLERY_ROOT.$dir.$item) and !file_exists(GALLERY_ROOT.$dir.$item))
{
sfpg_delete_from_data_root($dir.$item);
}
}
$path='';
$dirs=explode('/',$dir);
foreach($dirs as $dirout)
{
if(file_exists(DATA_ROOT.'info/'.$path.'_sfpg_dir'))
{
unlink(DATA_ROOT.'info/'.$path.'_sfpg_dir');
}
$path.=$dirout.'/';
}
}
function echo_js_array($name, $id, $array, $nl_to_br=true)
{
if(is_array($array))
{
$sep='';
echo $name.'['.$id.'] = {';
foreach($array as $key=>$val)
{
if(is_array($val))
{
$arrSep='';
echo $sep.'"'.$key.'":[';
foreach($val as $v)
{
echo $arrSep.'"'.sts($v, $nl_to_br).'"';
$arrSep=', ';
}
echo ']';
}
else
{
echo $sep.'"'.$key.'":"'.sts($val, $nl_to_br).'"';
}
$sep=', ';
}
echo "};\n";
}
}
function sfpg_random($nr)
{
$a='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$res='';
for($i = 0; $i<$nr; $i++)
{
$res.=$a[mt_rand(0,strlen($a)-1)];
}
return $res;
}
function sfpg_javascript()
{
global $dirs, $images, $files, $misc;
echo "";
}
function spider($dir)
{
list($dirs, $images, $files, $misc) = sfpg_get_dir($dir,FALSE,FALSE,TRUE);
unset($files);
unset($misc);
foreach($images as $image)
{
sfpg_image($dir, $image, 'thumb', FALSE, TRUE);
}
unset($images);
foreach($dirs as $sub_dir)
{
spider($dir.$sub_dir.'/');
}
}
@include(DATA_ROOT.'sp.php');
if (!defined('SECURITY_PHRASE'))
{
sfpg_mkdir(DATA_ROOT);
file_put_contents(DATA_ROOT.'sp.php',"");
@include(DATA_ROOT.'sp.php');
if (!defined('SECURITY_PHRASE'))
{
echo '';
$banner_file=FALSE;
if (file_exists(GALLERY_ROOT.GALLERY.DIR_BANNER_FILE))
{
$banner_file=GALLERY_ROOT.GALLERY.DIR_BANNER_FILE;
}
elseif (DIR_ROOT_BANNER_IN_SUBDIRS and file_exists(GALLERY_ROOT.DIR_BANNER_FILE))
{
$banner_file=GALLERY_ROOT.DIR_BANNER_FILE;
}
if ($banner_file)
{
echo '
'.clean_html(@file_get_contents($banner_file)).'
';
}
elseif (TEXT_BANNER)
{
echo '
'.TEXT_BANNER.'
';
}
echo '
';
if (ADMIN===TRUE)
{
echo'