['ApertureFNumber', 'UserComment'], 'IFD0'=>['Make', 'Model'], 'EXIF'=>['ExposureTime', 'FNumber', 'ISOSpeedRatings', 'DateTimeOriginal', 'FocalLength'] ]); option('SHOW_INFO_BY_DEFAULT', FALSE); option('ROUND_CORNERS', 3); option('ZIP_ENABLE', FALSE); option('ZIP_FILES', FALSE); option('ZIP_FILE_THUMBS', FALSE); option('ZIP_SUB_GALLERIES', FALSE); option('ZIP_DESCRIPTIONS', FALSE); option('ZIP_COMPRESSION', FALSE); option('ZIP_CACHE_DAYS', 180); option('TEXT_ZIP_ROOT_NAME', 'Single File PHP Gallery'); option('TEXT_ZIP_NOTHING', 'Nothing to zip.'); option('TEXT_ZIP_DL', 'Download all images in this directory as a zip file:'); option('TEXT_ZIP_BUTTON', 'Generate zip-file and download'); option('TEXT_ZIP_WAIT', 'Zip is being generated. Please wait...'); option('THUMB_MAX_WIDTH', 200); option('THUMB_MAX_HEIGHT', 150); option('THUMB_SQUARE', FALSE); option('THUMB_ENLARGE', FALSE); option('THUMB_JPEG_QUALITY', 75); option('THUMB_TRANSPARENCY', TRUE); option('LOW_IMAGE_RESAMPLE_QUALITY', FALSE); option('KEYBOARD_NAVIGATION', TRUE); option('WATERMARK', ''); option('WATERMARK_FRACTION', 0.1); option('MPO_STEREO_IMAGE', TRUE); option('MPO_STEREO_DOTS', TRUE); option('MPO_STEREO_MAX_WIDTH', 300); option('MPO_STEREO_MAX_HEIGHT', 300); option('MPO_FULL_IMAGE', TRUE); option('MPO_FULL_ANAGLYPH', TRUE); option('MPO_FULL_MAX_WIDTH', 1200); option('MPO_FULL_MAX_HEIGHT', 800); option('MPO_SPACING', 20); option('INFO_BOX_WIDTH', 250); option('MENU_BOX_HEIGHT', 70); option('NAV_BAR_HEIGHT', 25); option('THUMB_BORDER_WIDTH', 1); option('THUMB_MARGIN', 10); option('THUMB_BOX_MARGIN', 7); option('THUMB_BOX_EXTRA_HEIGHT', 14); option('THUMB_CHARS_MAX', 20); option('FULLIMG_BORDER_WIDTH', 5); option('NAVI_CHARS_MAX', 100); option('OVERLAY_OPACITY', 0.9); option('SLIDESHOW_DELAY_SEC', 5); option('SHOW_MAX_IMAGES', FALSE); option('SHOW_IMAGE_DAYS', FALSE); option('DELETE_IMAGE_DAYS', FALSE); option('DELETE_EMPTY_DIRS', FALSE); option('PAYPAL_ENABLED', FALSE); option('PAYPAL_ACCOUNT', ''); option('PAYPAL_CURRENCY', 'USD'); option('PAYPAL_EXTENSION', '.sell'); option('RETURN_PROTOCOL', 'https'); option('TEXT_PAYPAL_FOR_SALE', 'Sales information'); option('TEXT_PAYPAL_PRICE', 'Price'); option('TEXT_PAYPAL_STATUS', 'Status'); option('TEXT_PAYPAL_AVAILABLE', 'Available'); option('TEXT_PAYPAL_SOLD', 'Sold'); option('TEXT_PAYPAL_ITEM_ID', 'Item ID'); option('TEXT_PAYPAL_BUY', 'Buy this item'); option('TEXT_PAYPAL_OUT_BACK', 'Item is no longer available. Click back and refresh the page to update status.'); option('TEXT_PAYPAL_THANKS', 'Thank you for your purchase. The item will remain listed as available until seller have verified the purchase. Click here to return to the gallery: '); option('TEXT_PAYPAL_REDIRECT', 'Redirecting to PayPal. Please wait...'); option('HTML_LANGUAGE', 'en-US'); option('TEXT_DAYS', "['Sun','Mon','Tue','Wed','Thu','Fri','Sat']"); option('TEXT_MONTHS', "['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']"); option('TEXT_GALLERY_NAME', 'Single File PHP Gallery'); option('TEXT_BANNER', ''); option('TEXT_HOME', 'Home'); option('TEXT_CLOSE_IMG_VIEW', 'Close Image'); option('TEXT_ACTUAL_SIZE', 'Actual Size'); option('TEXT_PREVIOUS', '◄︎ Previous'); option('TEXT_NEXT', 'Next ►︎'); option('TEXT_INFO', 'Info'); option('TEXT_INFO_LABEL', 'Information'); option('TEXT_DOWNLOAD', 'Download image'); option('TEXT_SLIDESHOW', 'Slideshow'); option('TEXT_NO_IMAGES', 'No Images in gallery'); option('TEXT_DATE', 'Date'); option('TEXT_FILESIZE', 'File size'); option('TEXT_IMAGESIZE', 'Image size'); option('TEXT_DIR_NAME', 'Gallery Name'); option('TEXT_IMAGE_NAME', 'Image Name'); option('TEXT_FILE_NAME', 'File Name'); option('TEXT_DIRS', 'Directories'); option('TEXT_DIR_MARK_START', '📁︎ '); option('TEXT_DIR_MARK_END', ''); option('TEXT_IMAGES', 'Images'); option('TEXT_IMAGE_NUMBER', 'Image number'); option('TEXT_FILES', 'Files'); option('TEXT_DESCRIPTION', 'Description'); option('TEXT_DIRECT_LINK_GALLERY', 'Direct link to Gallery'); option('TEXT_DIRECT_LINK_IMAGE', 'Direct link to Image'); option('TEXT_NO_THUMB_FOR_FILE', 'No thumbnail for file'); option('TEXT_IMAGE_LOADING', 'Image Loading '); option('TEXT_LINKS', 'Links'); option('TEXT_NOT_SCALED', 'Not Scaled'); option('TEXT_LINK_BACK', 'Back to my site'); option('TEXT_SCALED_TO', 'Scaled to'); option('TEXT_YES', 'Yes'); option('TEXT_NO', 'No'); option('TEXT_FIRST_VIEW', 'This is first view of this image. Refresh page to get information.'); option('TEXT_LOGIN', 'Login'); option('TEXT_LOGOUT', 'Logout'); option('TEXT_ADMIN', 'Admin'); option('TEXT_OK', 'OK'); option('TEXT_CANCEL', 'Cancel'); option('TEXT_DELETE', 'Delete'); option('TEXT_RENAME', 'Rename'); option('TEXT_MOVE', 'Move'); option('TEXT_MOVE_TO', 'Move to'); option('TEXT_MKDIR', 'Create Directory'); option('TEXT_SET_DIR_THUMB', 'Dir Thumb'); option('TEXT_REMOVE_THUMB', 'No images selected. Will remove current directory thumbnail and select new thumbnail.'); option('TEXT_SETTING_THUMB', 'Setting directory thumbnail to: '); option('TEXT_WRONG_FILETYPE', 'Wrong filetype selected. Filetype must be same as set in DIR_THUMB_FILE: '); option('TEXT_UPLOAD', 'Upload'); option('TEXT_INVERT_SELECTION', 'Invert Select'); option('TEXT_NOTHING', 'Nothing Selected'); option('TEXT_ONLY_ONE', 'Select only one element to use this function'); option('TEXT_ONE_IMAGE', 'Select only one image to use this function'); option('TEXT_EXIF', 'EXIF'); option('TEXT_EXIF_DATE', 'Date'); option('TEXT_EXIF_CAMERA', 'Camera'); option('TEXT_EXIF_ISO', 'ISO'); option('TEXT_EXIF_SHUTTER', 'Shutter Speed'); option('TEXT_EXIF_APERTURE', 'Aperture'); option('TEXT_EXIF_FOCAL', 'Focal Length'); option('TEXT_EXIF_FLASH', 'Flash fired'); option('TEXT_EXIF_LATITUDE', 'Latitude'); option('TEXT_EXIF_LONGITUDE', 'Longitude'); option('TEXT_EXIF_MAP', 'See on Google map'); option('EXIF_MAP_LINK', 'https://maps.google.com/maps?q=[lat],[long]'); option('TEXT_EXIF_MAP_EMBED', 'Image map'); option('EXIF_MAP_EMBED_LINK', 'https://maps.google.com/maps?q=[lat],[long]&output=embed'); option('TEXT_PNG_CHUNKS', 'PNG text chunks'); option('TEXT_WEBP_EXIF', 'WebP EXIF'); option('TEXT_IPTC', 'IPTC'); option('IPTC', [ '2#005' => 'Document Title', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#040' => 'Special Instructions', '2#055' => 'Creation Date', '2#080' => 'Author Byline', '2#085' => 'Author Title', '2#090' => 'City', '2#095' => 'State', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Source', '2#115' => 'Photo Source', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'Caption Writer', ]); option('COLOR_BODY_BACK', '#000000'); option('COLOR_BODY_TEXT', '#aaaaaa'); option('COLOR_BODY_LINK', '#ffffff'); option('COLOR_BODY_HOVER', '#aaaaaa'); option('COLOR_THUMB_BORDER', '#606060'); option('COLOR_FULLIMG_BORDER', '#ffffff'); option('COLOR_MARKED_BACK', '#ff0000'); option('COLOR_MARKED_TEXT', '#000000'); option('COLOR_DIR_BOX_BORDER', '#505050'); option('COLOR_DIR_BOX_BACK', '#000000'); option('COLOR_DIR_BOX_TEXT', '#aaaaaa'); option('COLOR_DIR_HOVER', '#ffffff'); option('COLOR_DIR_HOVER_TEXT', '#000000'); option('COLOR_IMG_BOX_BORDER', '#505050'); option('COLOR_IMG_BOX_BACK', '#202020'); option('COLOR_IMG_BOX_TEXT', '#aaaaaa'); option('COLOR_IMG_HOVER', '#ffffff'); option('COLOR_IMG_HOVER_TEXT', '#000000'); option('COLOR_FILE_BOX_BORDER', '#404040'); option('COLOR_FILE_BOX_BACK', '#101010'); option('COLOR_FILE_BOX_TEXT', '#aaaaaa'); option('COLOR_FILE_HOVER', '#ffffff'); option('COLOR_FILE_HOVER_TEXT', '#000000'); option('COLOR_DESC_BOX_BORDER', '#404040'); option('COLOR_DESC_BOX_BACK', '#202020'); option('COLOR_DESC_BOX_TEXT', '#aaaaaa'); option('COLOR_MENU_BACK', '#000000'); option('COLOR_MENU_TOP', '#303030'); option('COLOR_NAVBAR_BACK', '#202020'); option('COLOR_NAVBAR_TOP', '#303030'); option('COLOR_BUTTON_NAV_BORDER', '#404040'); option('COLOR_BUTTON_NAV_BACK', '#101010'); option('COLOR_BUTTON_NAV_TEXT', '#808080'); option('COLOR_INFO_BACK', '#000000'); option('COLOR_INFO_BORDER', '#606060'); option('COLOR_INFO_TEXT', '#aaaaaa'); option('COLOR_INFOBOX_BORDER', '#404040'); option('COLOR_INFOBOX_BACK', '#101010'); option('COLOR_BUTTON_BORDER', '#808080'); option('COLOR_BUTTON_BACK', '#000000'); option('COLOR_BUTTON_TEXT', '#aaaaaa'); option('COLOR_BUTTON_BORDER_OFF', '#505050'); option('COLOR_BUTTON_BACK_OFF', '#000000'); option('COLOR_BUTTON_TEXT_OFF', '#505050'); option('COLOR_BUTTON_HOVER', '#ffffff'); option('COLOR_BUTTON_HOVER_TEXT', '#000000'); option('COLOR_BUTTON_ON', '#aaaaaa'); option('COLOR_BUTTON_TEXT_ON', '#000000'); option('COLOR_OVERLAY', '#000000'); // ----------- CONFIGURATION END ------------ function option($name, $value) { if (!defined($name)) { define($name, $value); } } function sfpg_array_sort(&$arr, &$arr_time, $sort_by_time, $sort_reverse) { if ($sort_by_time) { if ($sort_reverse) { array_multisort ($arr_time, SORT_DESC, SORT_NUMERIC, $arr); } else { array_multisort ($arr_time, SORT_ASC, SORT_NUMERIC, $arr); } } else { if (SORT_ALL_NATURAL) { natcasesort ($arr); $arr = array_values($arr); if ($sort_reverse) { $arr = array_reverse ($arr); } } else { if ($sort_reverse) { rsort ($arr); } else { sort ($arr); } } } } function sfpg_file_size($size) { $sizename = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; return ($size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$sizename[$i] : '0 Bytes'); } function sfpg_base64url_encode($plain) { $base64 = base64_encode($plain); $base64url = strtr($base64, '+/', '-_'); return rtrim($base64url, '='); } function sfpg_base64url_decode($base64url) { if($base64url) { $base64 = strtr($base64url, '-_', '+/'); $plain = base64_decode($base64); return ($plain); } return ''; } function sfpg_url_string($dir = '', $img = '') { $res = $dir.'*'.$img.'*'; return sfpg_base64url_encode($res.hash('sha256', $res.SECURITY_PHRASE)); } function sfpg_url_decode($string) { if(is_string($string) and (strlen($string)>65)) // sha256 is 64 plus the two * { $get = explode('*', sfpg_base64url_decode($string)); if (is_array($get) and (count($get)==3) and (hash('sha256', $get[0].'*'.$get[1].'*'.SECURITY_PHRASE) === $get[2]) and (strpos(GALLERY_ROOT.$get[0].$get[1], '/../') === FALSE) and (strpos($get[0].$get[1], '\\') === FALSE)) { return [$get[0], $get[1]]; } } return FALSE; } function block_html($str) { return str_replace(['&', '"', "'", '<', '>'], ['&', '"', ''', '<', '>'], $str); } function clean_html($str) { if (HTML_DESCRIPTIONS === TRUE) { return $str; } elseif (is_string(HTML_DESCRIPTIONS) or is_array(HTML_DESCRIPTIONS)) { // allowed tags $str = strip_tags($str, HTML_DESCRIPTIONS); return $str; } return block_html($str); } function sts($str, $nl_to_br=true) { return str_replace(["\r", "\n", "\\", "\"", "'"], ["", ($nl_to_br?"
":" "), "\\\\", "\\\"", "\'"], $str); } function sfpg_display_name($name, $show_ext) { $break_pos = strpos($name, SORT_DIVIDER); if ($break_pos !== FALSE) { $display_name = substr($name, $break_pos + strlen(SORT_DIVIDER)); } else { $display_name = $name; } if (UNDERSCORE_AS_SPACE) { $display_name = str_replace('_', ' ', $display_name); } if (!$show_ext) { $display_name = substr($display_name, 0, strrpos($display_name, '.')); } return $display_name; } function sfpg_ext($file) { if (strrpos($file, '.') === FALSE) { return 'nodot'; } else { return strtolower(substr($file, strrpos($file, '.'))); } } function sfpg_image_type($file) { $type = sfpg_ext($file); if (($type == '.jpg') or ($type == '.jpeg') or ((MPO_FULL_IMAGE or MPO_STEREO_IMAGE) and ($type == '.mpo'))) { return 'jpeg'; } elseif ($type == '.png') { return 'png'; } elseif ($type == '.gif') { return 'gif'; } elseif ($type == '.webp') { return 'webp'; } return FALSE; } function sfpg_mpo_image($file) { if (!$mpo = @file_get_contents($file)) { return false; } $offset = 0; $marker = true; $imgOffset = []; $markA = chr(0xFF).chr(0xD8).chr(0xFF).chr(0xE1); $markB = chr(0xFF).chr(0xD9).chr(0xFF).chr(0xE0); while ($marker!==false) { $marker = strpos($mpo, $markA, $offset); if ($marker===false) { $marker = strpos($mpo, $markB, $offset); } if ($marker!==false) { $imgOffset[] = $marker; $offset = $marker+4; } } $imgOffset[] = strlen($mpo); if (count($imgOffset)<2) { return false; } if (count($imgOffset)>2) { $img_left = imagecreatefromstring(substr($mpo, $imgOffset[0], $imgOffset[1]-$imgOffset[0])); $img_right = imagecreatefromstring(substr($mpo, $imgOffset[1], $imgOffset[2]-$imgOffset[1])); list($mpo_stereo_width, $mpo_stereo_height) = sfpg_aspect_resize(imagesx($img_left), imagesy($img_left), MPO_STEREO_MAX_WIDTH, MPO_STEREO_MAX_HEIGHT, true); list($mpo_full_width, $mpo_full_height) = sfpg_aspect_resize(imagesx($img_left), imagesy($img_left), MPO_FULL_MAX_WIDTH, MPO_FULL_MAX_HEIGHT, false); $stereo_dot_space = 0; if (MPO_STEREO_DOTS) { $dot_size=3; $stereo_dot_space = 2*$dot_size+2*MPO_SPACING; } $stereo_align = 0; $new_img_width = 0; $new_img_height = 0; $full_offset_y = 0; if (MPO_STEREO_IMAGE) { $new_img_width += $mpo_stereo_width*2+MPO_SPACING; $new_img_height += $stereo_dot_space + $mpo_stereo_height + (MPO_FULL_IMAGE ? MPO_SPACING : 0); $full_offset_y = $mpo_stereo_height+MPO_SPACING+$stereo_dot_space; } $full_offset_x = round(($new_img_width-$mpo_full_width)/2); if (MPO_FULL_IMAGE) { if ($mpo_full_width > $new_img_width) { $new_img_width = $mpo_full_width; $stereo_align = (int)(($mpo_full_width-($mpo_stereo_width*2+MPO_SPACING))/2); $full_offset_x = 0; } $new_img_height += $mpo_full_height; } $new_image = imagecreatetruecolor($new_img_width, $new_img_height); $tmp_left = imagecreatetruecolor($mpo_full_width, $mpo_full_height); imagecopyresampled($tmp_left, $img_left, 0, 0, 0, 0, $mpo_full_width, $mpo_full_height, imagesx($img_left), imagesy($img_left)); $tmp_right = imagecreatetruecolor($mpo_full_width, $mpo_full_height); imagecopyresampled($tmp_right, $img_right, 0, 0, 0, 0, $mpo_full_width, $mpo_full_height, imagesx($img_right), imagesy($img_right)); if (MPO_FULL_IMAGE) { if (MPO_FULL_ANAGLYPH) { $anaglyph_image = imagecreatetruecolor($mpo_full_width, $mpo_full_height); imagealphablending($anaglyph_image, false); for($y=0; $y<$mpo_full_height; $y++) { for($x=0; $x<$mpo_full_width; $x++) { $left_color = imagecolorat($tmp_left, $x, $y); $r = (int)((($left_color >> 16) & 255) * 0.299 + (($left_color >> 8) & 255) * 0.587 + (($left_color) & 255) * 0.114); if ($r > 255) { $r = 255; } $g = (imagecolorat($tmp_right, $x, $y) >> 8) & 255; $b = (imagecolorat($tmp_right, $x, $y)) & 255; imagesetpixel($anaglyph_image, $x, $y, imagecolorallocate($anaglyph_image, $r, $g, $b)); } } imagecopyresampled($new_image, $anaglyph_image, $full_offset_x, $full_offset_y, 0, 0, $mpo_full_width, $mpo_full_height, $mpo_full_width, $mpo_full_height); imagedestroy($anaglyph_image); imagedestroy($tmp_left); imagedestroy($tmp_right); } else { imagecopyresampled($new_image, $img_left, $full_offset_x, $full_offset_y, 0, 0, $mpo_full_width, $mpo_full_height, imagesx($img_left), imagesy($img_left)); } } if (MPO_STEREO_IMAGE) { imagecopyresampled($new_image, $img_left, $stereo_align, $stereo_dot_space, 0, 0, $mpo_stereo_width, $mpo_stereo_height, imagesx($img_left), imagesy($img_left)); imagedestroy($img_left); imagecopyresampled($new_image, $img_right, $stereo_align+$mpo_stereo_width+MPO_SPACING, $stereo_dot_space, 0, 0, $mpo_stereo_width, $mpo_stereo_height, imagesx($img_right), imagesy($img_right)); imagedestroy($img_right); $white = imagecolorallocate($new_image, 255, 255, 255); imagefilledrectangle($new_image, $stereo_align+(int)($mpo_stereo_width/2)-3, MPO_SPACING-3, $stereo_align+(int)($mpo_stereo_width/2)+3, MPO_SPACING+3, $white); imagefilledrectangle($new_image, $stereo_align+MPO_SPACING+(int)($mpo_stereo_width*1.5)-3, MPO_SPACING-3, $stereo_align+MPO_SPACING+(int)($mpo_stereo_width*1.5)+3, MPO_SPACING+3, $white); } return $new_image; } else { $image = imagecreatefromstring(substr($mpo, $imgOffset[0], $imgOffset[1]-$imgOffset[0])); list($mpo_width, $mpo_height) = sfpg_aspect_resize(imagesx($image), imagesy($image), MPO_FULL_MAX_WIDTH, MPO_FULL_MAX_HEIGHT, false); $new_image = imagecreatetruecolor($mpo_width, $mpo_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $mpo_width, $mpo_height, imagesx($image), imagesy($image)); imagedestroy($image); return $new_image; } } function sfpg_aspect_resize($image_width, $image_height, $max_width, $max_height, $enlarge) { if (($image_width < $max_width) and ($image_height < $max_height) and !$enlarge) { $new_img_height = $image_height; $new_img_width = $image_width; } else { $aspect_x = $image_width / $max_width; $aspect_y = $image_height / $max_height; if ($aspect_x > $aspect_y) { $new_img_width = $max_width; $new_img_height = $image_height / $aspect_x; } else { $new_img_height = $max_height; $new_img_width = $image_width / $aspect_y; } } return [(int)round($new_img_width), (int)round($new_img_height)]; } function sfpg_mkdir($dir) { if (!is_dir($dir)) { mkdir($dir, 0777, TRUE); return true; } return false; } function sfpg_get_dir($dir, $for_dir_info=FALSE, $for_zip=FALSE, $for_spider=FALSE) { $dirs = []; $dirs_time = []; $images = []; $images_time = []; $files = []; $files_time = []; $misc = []; $directory_handle = @opendir(GALLERY_ROOT.$dir); if ($directory_handle != FALSE) { while(($var=readdir($directory_handle))!==false) { if (is_dir(GALLERY_ROOT.$dir.$var)) { if (($var != '.') and ($var != '..') and !in_array(strtolower($var), DIR_EXCLUDE) and !@preg_match(DIR_EXCLUDE_REGEX, $var)) { $dirs[] = $var; if (DIR_SORT_BY_TIME) { $dirs_time[] = filemtime(GALLERY_ROOT.$dir.$var.'/.'); } } } elseif (sfpg_image_type($var)) { if (($var != DIR_THUMB_FILE) and !@preg_match(IMAGE_EXCLUDE_REGEX, $var)) { if ((DELETE_IMAGE_DAYS) and (filemtime(GALLERY_ROOT.$dir.$var)<(time()-(DELETE_IMAGE_DAYS*86400)))) { unlink(GALLERY_ROOT.$dir.$var); } else { $images[] = $var; if (IMAGE_SORT_BY_TIME) { if (IMAGE_EXIF_TIME) { if ($img_info=@file_get_contents(DATA_ROOT.'info/'.$dir.$var)) { $spl=unserialize($img_info); if (isset($spl['exifDate'])) { $images_time[]=$spl['exifDate']; } else { $images_time[]=filemtime(GALLERY_ROOT.$dir.$var); } } else { $images_time[]=filemtime(GALLERY_ROOT.$dir.$var); } } else { $images_time[]=filemtime(GALLERY_ROOT.$dir.$var); } } } } } elseif (SHOW_FILES) { if (!in_array(strtolower($var), FILE_EXCLUDE) and !in_array(sfpg_ext($var), FILE_EXT_EXCLUDE) and !@preg_match(FILE_EXCLUDE_REGEX, $var)) { $files[] = $var; if (FILE_SORT_BY_TIME) { $files_time[] = filemtime(GALLERY_ROOT.$dir.$var); } } } if ((sfpg_ext($var)==DESC_EXT)or(sfpg_ext($var)==PAYPAL_EXTENSION)) { $misc[] = $var; } } closedir($directory_handle); if ($for_dir_info) { $misc = 0; } if (!$for_spider) // never remove images when for spider { if (SHOW_FILES and !($for_zip and ZIP_FILES and ZIP_FILE_THUMBS)) // removes thumbnail images from being listed as images. Unless needed for zip. { foreach ($files as $val) { $fti = array_search($val.FILE_THUMB_EXT, $images); if ($fti !== FALSE) { if ($for_dir_info) { $misc++; } else { array_splice($images, $fti, 1); array_splice($images_time, $fti, 1); } } } } } sfpg_array_sort($dirs, $dirs_time, DIR_SORT_BY_TIME, DIR_SORT_REVERSE); sfpg_array_sort($images, $images_time, IMAGE_SORT_BY_TIME, IMAGE_SORT_REVERSE); sfpg_array_sort($files, $files_time, FILE_SORT_BY_TIME, FILE_SORT_REVERSE); return [$dirs, $images, $files, $misc]; } else { if ($dir=='') { exit('GALLERY_ROOT is not accessible.'); } else { header('Location: '.$_SERVER['PHP_SELF']); } exit; } } function get_files_for_zip($dir_to_zip) { list($dirs, $images, $files, $misc) = sfpg_get_dir($dir_to_zip,FALSE,TRUE); $zip_list = $images; if (ZIP_FILES) { $zip_list = array_merge($zip_list, $files); } if (ZIP_DESCRIPTIONS) { $zip_list = array_merge($zip_list, $misc); } for($i=0; $i

'. ' '.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 '
PHP do not have access to create files in the defined DATA_ROOT ("'.DATA_ROOT.'").
See readme.txt for DATA_ROOT description.'; exit; } } if (SECURITY_PHRASE=='') { echo '
The SECURITY_PHRASE in "'.DATA_ROOT.'sp.php" cannot be empty.
See readme.txt for DATA_ROOT description.'; exit; } if (PASSWORD!=='') { session_name('SFPG_SESSID'); session_start(); if (isset($_GET['cmd']) and ($_GET['cmd']=='logout')) { session_unset(); header('Location: '.$_SERVER['PHP_SELF']); exit; } if ((($_SESSION['sfpg_access']??FALSE)!==TRUE) or ($_SESSION['sfpg_self']!==$_SERVER['PHP_SELF'])) { if (isset($_POST['pw']) and ($_POST['pw']===PASSWORD)) { $_SESSION['sfpg_access']=TRUE; $_SESSION['sfpg_self']=$_SERVER['PHP_SELF']; } else { header('Content-Type: text/html; charset="'.CHARSET.'"'); echo ''. '
'. ''. ''. '
'; session_write_close(); exit; } } session_write_close(); } $get_set = FALSE; if (isset($_GET['sfpg'])) { $get = sfpg_url_decode($_GET['sfpg']); if ($get) { define('GALLERY', $get[0]); define('IMAGE', $get[1]); $get_set = TRUE; } } if (!$get_set) { define('GALLERY', ''); define('IMAGE', ''); } if (ZIP_ENABLE and isset($_POST['zipdl'])) { sfpg_mkdir(DATA_ROOT.'zip'); $zip_link='./_sfpg_zip'; if (!is_link($zip_link)) { if (!symlink(realpath(DATA_ROOT.'zip'), $zip_link)) { echo 'Unable to create symlink for zip download.'; exit; } } if (ZIP_CACHE_DAYS !== FALSE) { cleanup_zip_days(time()-(ZIP_CACHE_DAYS*86400), DATA_ROOT.'zip'); } $files_for_zip = get_files_for_zip(GALLERY); if (count($files_for_zip)>0) { sort($files_for_zip); // sorting before hash to make sure that hash function gets input in same order every time. $zip_hash = hash('sha256', serialize($files_for_zip)); $zip_dir = DATA_ROOT.'zip/'.GALLERY; if (GALLERY == '') { $zip_name = TEXT_ZIP_ROOT_NAME.'.zip'; } else { $from = strrpos(rtrim(GALLERY, '/'), '/'); if ($from===FALSE) { $from = -1; } $zip_name = substr(GALLERY, $from+1, -1).'.zip'; } if (file_exists($zip_dir.$zip_name) and file_exists($zip_dir.$zip_name.'.hash') and ($zip_hash === file_get_contents($zip_dir.$zip_name.'.hash'))) { header('Location: '.$zip_link.'/'.GALLERY.$zip_name); exit; } else { sfpg_delete($zip_dir.$zip_name); sfpg_delete($zip_dir.$zip_name.'.hash'); } sfpg_mkdir($zip_dir); file_put_contents($zip_dir.$zip_name.'.hash', $zip_hash); $zip = new ZipArchive(); $zip->open($zip_dir.$zip_name, ZipArchive::CREATE | ZipArchive::OVERWRITE); $zip_index = 0; foreach($files_for_zip as $file) { $zip->addFile(realpath(GALLERY_ROOT.$file), substr($file, strlen(GALLERY))); if (ZIP_COMPRESSION) { $zip->setCompressionIndex($zip_index, ZipArchive::CM_DEFLATE); } else { $zip->setCompressionIndex($zip_index, ZipArchive::CM_STORE); } $zip_index++; } if ($zip->close()) { header('Location: '.$zip_link.'/'.GALLERY.$zip_name); exit; } echo 'Unable to create zip file.'; exit; } else { echo TEXT_ZIP_NOTHING; exit; } } if ($get_set) { if (isset($_GET['cmd'])) { if ($_GET['cmd'] == 'thumb') { sfpg_image(GALLERY, IMAGE, 'thumb'); exit; } if ($_GET['cmd'] == 'image') { sfpg_image(GALLERY, IMAGE, 'image'); exit; } if (($_GET['cmd'] == 'dl') and TEXT_DOWNLOAD!='') { sfpg_image(GALLERY, IMAGE, 'image', TRUE); exit; } if (SHOW_FILES and ($_GET['cmd'] == 'file')) { if (preg_match("#^(/|([A-Z]:)?(\\\\|/))#i", GALLERY_ROOT)) // if GALLERY_ROOT is an absolute path { $download_path='./_sfpg_download'; if (is_link($download_path)) { $prefix = $download_path.'/'; } elseif (symlink(rtrim(GALLERY_ROOT, '/'), $download_path)) { $prefix = $download_path.'/'; } else { echo 'Unable to access file.'; exit; } } else { $prefix = GALLERY_ROOT; } header('Location: '.$prefix.GALLERY.IMAGE); exit; } } elseif ((SPIDER_PASSWORD != '') and isset($_GET['spider']) and ($_GET['spider'] === SPIDER_PASSWORD)) { spider(GALLERY); echo 'spider_done'; exit; } } header('Content-Type: text/html; charset="'.CHARSET.'"'); if (PAYPAL_ENABLED) { if (isset($_GET['sold'])) { echo '
'.TEXT_PAYPAL_THANKS; echo ''.TEXT_HOME.''; exit(); } } if (ADMIN===TRUE) { if (isset($_POST['func'])) { if ($_POST['func']==='move') { if (isset($_POST['toFolder']) and isset($_POST['elems']) and is_array($_POST['elems']) and (count($_POST['elems']) > 0)) { $to_dir_array = sfpg_url_decode($_POST['toFolder']); if (($to_dir_array!==false) and ($to_dir_array[1]==='') and is_dir(GALLERY_ROOT.$to_dir_array[0])) { $to_dir=GALLERY_ROOT.$to_dir_array[0]; foreach ($_POST['elems'] as $elem) { $move_elem = sfpg_url_decode($elem); if ($move_elem) { if (($move_elem[1]==='') and (is_dir(GALLERY_ROOT.$move_elem[0]))) { $slash_pos=strrpos($move_elem[0],'/',-2); if($slash_pos!==FALSE) { $slash_pos+=1; } else { $slash_pos=0; } $dir_name = substr($move_elem[0],$slash_pos); rename(GALLERY_ROOT.$move_elem[0], $to_dir.$dir_name); } else { $file_to_move=GALLERY_ROOT.$move_elem[0].$move_elem[1]; rename($file_to_move, $to_dir.$move_elem[1]); if (file_exists($file_to_move.DESC_EXT)) { rename($file_to_move.DESC_EXT, $to_dir.$move_elem[1].DESC_EXT); } if (sfpg_image_type($file_to_move) and (file_exists($file_to_move.PAYPAL_EXTENSION))) { rename($file_to_move.PAYPAL_EXTENSION, $to_dir.$move_elem[1].PAYPAL_EXTENSION); } elseif (file_exists($file_to_move.FILE_THUMB_EXT)) { rename($file_to_move.FILE_THUMB_EXT, $to_dir.$move_elem[1].FILE_THUMB_EXT); } } } } } } } if ($_POST['func']==='setthumb') { if (isset($_POST['elems'])) { if (count($_POST['elems']) == 1) { $new_thumb = sfpg_url_decode($_POST['elems'][0]); if ($new_thumb) { if (sfpg_image_type($new_thumb[1])===sfpg_image_type(DIR_THUMB_FILE)) { copy(GALLERY_ROOT.$new_thumb[0].$new_thumb[1], GALLERY_ROOT.$new_thumb[0].DIR_THUMB_FILE); sfpg_set_dir_info($new_thumb[0]); } else { echo TEXT_WRONG_FILETYPE.sfpg_image_type(DIR_THUMB_FILE); exit; } } } } else { if (isset($_POST['path'])) { $path = sfpg_url_decode($_POST['path']); if ($path) { sfpg_delete(GALLERY_ROOT.$path[0].DIR_THUMB_FILE); sfpg_set_dir_info($path[0]); } } } } if ($_POST['func']==='delete') { if (isset($_POST['elems']) and is_array($_POST['elems']) and (count($_POST['elems']) > 0)) { foreach ($_POST['elems'] as $elem) { $del_elem = sfpg_url_decode($elem); if ($del_elem) { $element=GALLERY_ROOT.$del_elem[0].$del_elem[1]; sfpg_delete($element); if (!is_dir($element)) { sfpg_delete($element.DESC_EXT); if (sfpg_image_type($element)) { sfpg_delete($element.PAYPAL_EXTENSION); } else { sfpg_delete($element.FILE_THUMB_EXT); } } } } } } if (($_POST['func']==='makedir') and (isset($_POST['dir'])) and (isset($_POST['path']))) { $new_dir=$_POST['dir']; $path=$_POST['path']; if (($new_dir!=='') and $path) { $path = sfpg_url_decode($path); if ($path and ($path[1]==='')) { $path=GALLERY_ROOT.$path[0]; sfpg_mkdir($path.$new_dir); } } } if (($_POST['func']==='rename') and (isset($_POST['eleToRen'])) and (isset($_POST['newName']))) { $newName=$_POST['newName']; $eleToRen=$_POST['eleToRen']; if ($newName!=='' and $eleToRen) { $eleToRen = sfpg_url_decode($eleToRen); if ($eleToRen) { if ($eleToRen[1]!=='') { $newName.=((!SHOW_IMAGE_EXT and sfpg_image_type($eleToRen[1]))?sfpg_ext($eleToRen[1]):''); if ((!file_exists(GALLERY_ROOT.$eleToRen[0].$newName)) and (!is_dir(GALLERY_ROOT.$eleToRen[0].$newName))) { if (sfpg_image_type($eleToRen[1])) { if (file_exists(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].PAYPAL_EXTENSION)) { rename(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].PAYPAL_EXTENSION, GALLERY_ROOT.$eleToRen[0].$newName.PAYPAL_EXTENSION); } } elseif (file_exists(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].FILE_THUMB_EXT)) { rename(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].FILE_THUMB_EXT, GALLERY_ROOT.$eleToRen[0].$newName.FILE_THUMB_EXT); } if (file_exists(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].DESC_EXT)) { rename(GALLERY_ROOT.$eleToRen[0].$eleToRen[1].DESC_EXT, GALLERY_ROOT.$eleToRen[0].$newName.DESC_EXT); } rename(GALLERY_ROOT.$eleToRen[0].$eleToRen[1], GALLERY_ROOT.$eleToRen[0].$newName); } } else { $oldPath=GALLERY_ROOT.$eleToRen[0]; $oldPath=rtrim($oldPath,'/'); $newPath = substr($oldPath, 0, strrpos($oldPath, '/')+1).$newName; if ((!file_exists($newPath)) and (!is_dir($newPath))) { rename(GALLERY_ROOT.$eleToRen[0], $newPath); } } } } } if ($_POST['func']==='desc') { $action=@$_POST['action']; $text=@$_POST['text']; $ele=@$_POST['ele']; if (($action==='del') or ($text==='')) { $eleWd = sfpg_url_decode($ele); if ($eleWd) { $element=GALLERY_ROOT.$eleWd[0].$eleWd[1]; if (is_dir($element)) { sfpg_delete($element.DIR_DESC_FILE); } else { sfpg_delete($element.DESC_EXT); } } } elseif ($action==='save') { $eleWd = sfpg_url_decode($ele); if ($eleWd) { $element=GALLERY_ROOT.$eleWd[0].$eleWd[1]; if (is_dir($element)) { $element.=DIR_DESC_FILE; } else { $element.=DESC_EXT; } file_put_contents($element,$text); } } } if ($_POST['func']==='sell') { $action=$_POST['action']; $ele=$_POST['ele']; if ($action==='del') { $eleWd = sfpg_url_decode($ele); if ($eleWd) { sfpg_delete(GALLERY_ROOT.$eleWd[0].$eleWd[1].PAYPAL_EXTENSION); } } elseif ($action==='save') { $eleWd = sfpg_url_decode($ele); if ($eleWd) { file_put_contents(GALLERY_ROOT.$eleWd[0].$eleWd[1].PAYPAL_EXTENSION,$_POST['ePrice']."\r\n".$_POST['eStatus']."\r\n".$_POST['eIdent']); } } } if ($_POST['func']==='upload') { if (isset($_FILES['ulele'])) { $nrUlEle=count($_FILES['ulele']['name']); for ($i=0; $i<$nrUlEle; $i++) { if ($_FILES['ulele']['error'][$i]===0) { move_uploaded_file($_FILES['ulele']['tmp_name'][$i],GALLERY_ROOT.GALLERY.$_FILES['ulele']['name'][$i]); } } } } } if (isset($_GET['cmd']) and ($_GET['cmd'] == 'dirs')) { sfpg_browse_dirs(); exit; } } list($dirs, $images, $files, $misc) = sfpg_get_dir(GALLERY); echo ''.TEXT_GALLERY_NAME.''; sfpg_javascript(); echo ''; if (PAYPAL_ENABLED and $get_set and (@$_GET['cmd'] == 'buy') and IMAGE!='') { $sell=@file(GALLERY_ROOT.GALLERY.IMAGE.PAYPAL_EXTENSION,FILE_IGNORE_NEW_LINES); if (($sell==false) or ($sell[1]!=1)) { echo '
'.TEXT_PAYPAL_OUT_BACK.''; } else { echo ''. '
'.TEXT_PAYPAL_REDIRECT. '
'. ''. ''. ''. ''. ''. ''. ''. ''. '
'. ''; } } else { echo ''. '
'. ''. ''. ''. '
'. '
'. '
'. ''; if(SHOW_IMAGE_NAME_BELOW_FULL) { echo '
'; } echo '
'. '
'. '
'. '
'. '
'. '
'. '
'. ''; if (ADMIN===TRUE) { echo'
'; echo'
'; } echo'
'. '
'. '
'. ''; } echo ''; ?>