'.
' '.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 sfpg_image($image_dir, $image_file, $func, $download=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);
exit;
}
if ($func == 'thumb')
{
if (file_exists($image_path_file))
{
header('Content-Type: image/'.$image_type);
header('Content-Disposition: filename="'.$func.'_'.$image_file.'"');
readfile($image_path_file);
exit;
}
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 ((MPO_FULL_IMAGE or MPO_STEREO_IMAGE) and (sfpg_ext($image_file)=='.mpo'))
{
if (!$image = sfpg_mpo_image($source_img))
{
exit;
}
$image_changed = TRUE;
}
elseif (!$image = imagecreatefromstring(file_get_contents($source_img)))
{
exit;
}
if (($func == 'thumb') and ($image_dir != ICONS_DIR))
{
sfpg_mkdir(DATA_ROOT.'info/'.$image_dir);
$image_info = [];
if (function_exists('exif_read_data'))
{
if (SHOW_EXIF_INFO)
{
$exif_data = @exif_read_data(GALLERY_ROOT.$image_dir.$image_file, 'IFD0');
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
{
$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))
{
$image_width = imagesx($image);
$image_height = imagesy($image);
switch ($orientation)
{
case 2:
{
$rotate = @imagecreatetruecolor($image_width, $image_height);
if (LOW_IMAGE_RESAMPLE_QUALITY)
{
imagecopyresized($rotate, $image, 0, 0, $image_width-1, 0, $image_width, $image_height, -$image_width, $image_height);
}
else
{
imagecopyresampled($rotate, $image, 0, 0, $image_width-1, 0, $image_width, $image_height, -$image_width, $image_height);
}
imagedestroy($image);
$image_changed = TRUE;
break;
}
case 3:
{
$rotate = imagerotate($image, 180, 0);
imagedestroy($image);
$image_changed = TRUE;
break;
}
case 4:
{
$rotate = @imagecreatetruecolor($image_width, $image_height);
if (LOW_IMAGE_RESAMPLE_QUALITY)
{
imagecopyresized($rotate, $image, 0, 0, 0, $image_height-1, $image_width, $image_height, $image_width, -$image_height);
}
else
{
imagecopyresampled($rotate, $image, 0, 0, 0, $image_height-1, $image_width, $image_height, $image_width, -$image_height);
}
imagedestroy($image);
$image_changed = TRUE;
break;
}
case 5:
{
$rotate = imagerotate($image, 270, 0);
imagedestroy($image);
$image = $rotate;
$rotate = @imagecreatetruecolor($image_height, $image_width);
if (LOW_IMAGE_RESAMPLE_QUALITY)
{
imagecopyresized($rotate, $image, 0, 0, 0, $image_width-1, $image_height, $image_width, $image_height, -$image_width);
}
else
{
imagecopyresampled($rotate, $image, 0, 0, 0, $image_width-1, $image_height, $image_width, $image_height, -$image_width);
}
$image_changed = TRUE;
break;
}
case 6:
{
$rotate = imagerotate($image, 270, 0);
imagedestroy($image);
$image_changed = TRUE;
break;
}
case 7:
{
$rotate = imagerotate($image, 90, 0);
imagedestroy($image);
$image = $rotate;
$rotate = @imagecreatetruecolor($image_height, $image_width);
if (LOW_IMAGE_RESAMPLE_QUALITY)
{
imagecopyresized($rotate, $image, 0, 0, 0, $image_width-1, $image_height, $image_width, $image_height, -$image_width);
}
else
{
imagecopyresampled($rotate, $image, 0, 0, 0, $image_width-1, $image_height, $image_width, $image_height, -$image_width);
}
$image_changed = TRUE;
break;
}
case 8:
{
$rotate = imagerotate($image, 90, 0);
imagedestroy($image);
$image_changed = TRUE;
break;
}
}
$image = $rotate;
}
}
}
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 (sfpg_ext($image_file)=='.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[]=$keyword;
$png_text_chunks[]=$value;
}
}
}
else
{
fseek($png_fp, $chunk_info['length']+4, SEEK_CUR); // skipping the chunk + crc
}
}
fclose($png_fp);
if(count($png_text_chunks)>0)
{
$image_info['pngChunks'] = $png_text_chunks;
}
}
}
}
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);
}
}
$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_PNG_ALPHA and ($image_type == 'png'))
{
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);
header('Content-type: image/'.$image_type);
header('Content-Disposition: filename="'.$func.'_'.$image_file.'"');
if ($image_type == 'jpeg')
{
imagejpeg($new_image, NULL, $jpeg_quality);
imagejpeg($new_image, $image_path_file, $jpeg_quality);
}
elseif ($image_type == 'png')
{
imagepng($new_image);
imagepng($new_image, $image_path_file);
}
elseif ($image_type == 'gif')
{
imagegif($new_image);
imagegif($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 "";
}
@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'