>'); define('TEXT_INFO', 'Information'); define('TEXT_DOWNLOAD', 'Download full-size image'); define('TEXT_SLIDESHOW', 'Slideshow'); define('TEXT_NO_IMAGES', 'No Images in gallery'); define('TEXT_DATE', 'Date'); define('TEXT_FILESIZE', 'File size'); define('TEXT_IMAGESIZE', 'Full Image'); define('TEXT_DISPLAYED_IMAGE', 'Displayed Image'); define('TEXT_DIR_NAME', 'Gallery Name'); define('TEXT_IMAGE_NAME', 'Image Name'); define('TEXT_FILE_NAME', 'File Name'); define('TEXT_DIRS', 'Directories'); define('TEXT_IMAGES', 'Images'); define('TEXT_IMAGE_NUMBER', 'Image number'); define('TEXT_FILES', 'Files'); define('TEXT_DESCRIPTION', 'Description'); define('TEXT_DIRECT_LINK_GALLERY', 'Direct link to Gallery'); define('TEXT_DIRECT_LINK_IMAGE', 'Direct link to Image'); define('TEXT_NO_PREVIEW_FILE', 'No Preview for file'); define('TEXT_IMAGE_LOADING', 'Image Loading '); define('TEXT_LINKS', 'Links'); define('TEXT_NOT_SCALED', 'Not Scaled'); define('TEXT_LINK_BACK', 'Back to my site'); define('TEXT_THIS_IS_FULL', 'Full'); define('TEXT_THIS_IS_PREVIEW', 'Preview'); define('TEXT_SCALED_TO', 'Scaled to'); define('TEXT_YES', 'Yes'); define('TEXT_NO', 'No'); define('TEXT_FIRST_VIEW', 'This is first view of this image. Refresh page to get information.'); define('TEXT_LOGIN', 'Login'); define('TEXT_LOGOUT', 'Logout'); define('TEXT_ADMIN', 'Admin'); define('TEXT_OK', 'OK'); define('TEXT_CANCEL', 'Cancel'); define('TEXT_DELETE', 'Delete'); define('TEXT_RENAME', 'Rename'); define('TEXT_MOVE', 'Move'); define('TEXT_MOVE_TO', 'Move to'); define('TEXT_MKDIR', 'Create Directory'); define('TEXT_UPLOAD', 'Upload'); define('TEXT_NOTHING', 'Nothing Selected'); define('TEXT_ONLY_ONE', 'Select only one element to use this function'); define('TEXT_ONE_IMAGE', 'Select only one image to use this function'); define('TEXT_EXIF', 'EXIF'); define('TEXT_EXIF_DATE', 'Date'); define('TEXT_EXIF_CAMERA', 'Camera'); define('TEXT_EXIF_ISO', 'ISO'); define('TEXT_EXIF_SHUTTER', 'Shutter Speed'); define('TEXT_EXIF_APERTURE', 'Aperture'); define('TEXT_EXIF_FOCAL', 'Focal Length'); define('TEXT_EXIF_FLASH', 'Flash fired'); define('TEXT_EXIF_MISSING', 'No EXIF information in image'); define('TEXT_IPTC', 'IPTC'); define('TEXT_IPTC_TITLE', 'Document Title'); define('TEXT_IPTC_URGENCY', 'Urgency'); define('TEXT_IPTC_CATEGORY', 'Category'); define('TEXT_IPTC_SUBCATEGORIES', 'Subcategories'); define('TEXT_IPTC_SPECIALINSTRUCTIONS', 'Special Instructions'); define('TEXT_IPTC_CREATIONDATE', 'Creation Date'); define('TEXT_IPTC_AUTHORBYLINE', 'Author Byline'); define('TEXT_IPTC_AUTHORTITLE', 'Author Title'); define('TEXT_IPTC_CITY', 'City'); define('TEXT_IPTC_STATE', 'State'); define('TEXT_IPTC_COUNTRY', 'Country'); define('TEXT_IPTC_OTR', 'OTR'); define('TEXT_IPTC_HEADLINE', 'Headline'); define('TEXT_IPTC_SOURCE', 'Source'); define('TEXT_IPTC_PHOTOSOURCE', 'Photo Source'); define('TEXT_IPTC_COPYRIGHT', 'Copyright'); define('TEXT_IPTC_CAPTION', 'Caption'); define('TEXT_IPTC_CAPTIONWRITER', 'Caption Writer'); define('TEXT_IPTC_MISSING', 'No IPTC information in image'); $color_body_back = '#fff'; $color_body_text = '#aaaaaa'; $color_body_link = '#ffffff'; $color_body_hover = '#aaaaaa'; $color_thumb_border = '#606060'; $color_fullimg_border = '#ffffff'; $color_marked_back = '#271b4a'; $color_marked_text = '#000000'; $color_dir_box_border = '#505050'; $color_dir_box_back = '#271b4a'; $color_dir_box_text = '#fff'; $color_dir_hover = '#ffffff'; $color_dir_hover_text = '#000000'; $color_img_box_border = '#505050'; $color_img_box_back = '#271b4a'; $color_img_box_text = '#fff'; $color_img_hover = '#ffffff'; $color_img_hover_text = '#000000'; $color_file_box_border = '#404040'; $color_file_box_back = '#271b4a'; $color_file_box_text = '#aaaaaa'; $color_file_hover = '#ffffff'; $color_file_hover_text = '#000000'; $color_desc_box_border = '#404040'; $color_desc_box_back = '#271b4a'; $color_desc_box_text = '#aaaaaa'; $color_menu_back = '#fff'; $color_menu_top = '#fff'; $color_navbar_back = '#fff'; $color_navbar_top = '#fff'; $color_button_nav_border = '#404040'; $color_button_nav_back = '#ffffff'; $color_button_nav_text ='#000'; $color_info_back = '#271b4a'; $color_info_border = '#606060'; $color_info_text = '#ffffff'; $color_infobox_border = '#271b4a'; $color_infobox_back ='#101010'; $color_button_border = '#271b4a'; $color_button_back = '#ffffff'; $color_button_text = '#aaaaaa'; $color_button_border_off = '#271b4a'; $color_button_back_off = '#ffffff'; $color_button_text_off = '#271b4a'; $color_button_hover = '#c1bdbd'; $color_button_hover_text = '#000000'; $color_button_on = '#aaaaaa'; $color_button_text_on = '#000000'; $color_overlay = '#271b4a'; // ----------- CONFIGURATION END ------------ 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 = array('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) { $base64 = strtr($base64url, '-_', '+/'); $plain = base64_decode($base64); return ($plain); } function sfpg_url_string($dir = '', $img = '') { $res = $dir.'*'.$img.'*'; return sfpg_base64url_encode($res.hash('sha256', $res.SECURITY_PHRASE)); } function sfpg_url_decode($string) { $get = explode('*', sfpg_base64url_decode($string)); if ((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 array($get[0], $get[1]); } else { return FALSE; } } function sts($str, $block_html_tags=false, $nl_to_br=true) { $str = str_replace("\r", "", $str); $str = str_replace("\n", ($nl_to_br?"
":""), $str); $str = str_replace("\\", "\\\\", $str); $str = str_replace("\"", "\\\"", $str); $str = str_replace("'", "\'", $str); if ($block_html_tags) { $str = str_replace("<", "<", $str); } return $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'; } return FALSE; } function sfpg_mpo_image($file) { if (!$mpo = @file_get_contents($file)) { return false; } $offset = 0; $marker = true; $imgOffset = array(); $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 array($new_img_width, $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) { global $dir_exclude, $file_exclude, $file_ext_exclude; $dirs = array(); $dirs_time = array(); $images = array(); $images_time = array(); $files = array(); $files_time = array(); $misc = array(); $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=explode('|', $img_info); $images_time[]=$spl[4]; } 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; } } if ($for_dir_info) { $misc = 0; } if (SHOW_FILES) { 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); } } } } closedir($directory_handle); 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 array($dirs, $images, $files, $misc); } else { header('Location: '.$_SERVER['PHP_SELF']); exit; } } function sfpg_browse_dirs() { echo '

'. ' '.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_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') or ($func == 'preview')) { 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 { if($func == 'thumb') { $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; } else { $max_width = PREVIEW_MAX_WIDTH; $max_height = PREVIEW_MAX_HEIGHT; $enlarge = PREVIEW_ENLARGE; $jpeg_quality = PREVIEW_JPEG_QUALITY; $source_img = DATA_ROOT.'image/'.$image_dir.$image_file; if (!file_exists($source_img)) { $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') and ($func != 'preview')) { 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); $exif_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) { $exif_info = ''; if(isset($exif_data['DateTimeOriginal'])) { $exif_time = explode(':', str_replace(' ', ':', $exif_data['DateTimeOriginal'])); $exif_info .= mktime($exif_time[3], $exif_time[4], $exif_time[5], $exif_time[1], $exif_time[2], $exif_time[0]); } $exif_info .= '|'; $exif_info .= (isset($exif_data['Model'])?$exif_data['Model']:'').'|'; $exif_info .= (isset($exif_data['ISOSpeedRatings'])?$exif_data['ISOSpeedRatings']:'').'|'; if(isset($exif_data['ExposureTime'])) { $exif_ExposureTime=create_function('','return '.$exif_data['ExposureTime'].';'); $exp_time = $exif_ExposureTime(); if ($exp_time > 0.25) { $exif_info .= $exp_time; } else { $exif_info .= $exif_data['ExposureTime']; } $exif_info .= 's'; } $exif_info .= '|'; if(isset($exif_data['FNumber'])) { $exif_FNumber=create_function('','return number_format(round('.$exif_data['FNumber'].',1),1);'); $exif_info .= 'f'.$exif_FNumber(); } $exif_info .= '|'; if(isset($exif_data['FocalLength'])) { $exif_FocalLength=create_function('','return number_format(round('.$exif_data['FocalLength'].',1),1);'); $exif_info .= $exif_FocalLength().'mm'; } $exif_info .= '|'; if(isset($exif_data['Flash'])) { $exif_info .= (($exif_data['Flash'] & 1) ? TEXT_YES : TEXT_NO); } } else { $exif_info = 'sfpg_no_exif_data_in_file||||||'; } } if (ROTATE_IMAGES and isset($exif_data['Orientation'])) { $image_width = imagesx($image); $image_height = imagesy($image); switch ($exif_data['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; } default: $rotate = $image; } $image = $rotate; } } $iptc_info = '||||||||||||||||||'; if(SHOW_IPTC_INFO) { $only_used_for_iptc = getimagesize(GALLERY_ROOT.$image_dir.$image_file, $info); if (isset($info['APP13'])) { $iptc_info = ''; $iptc = iptcparse($info['APP13']); $iptc_info .= (isset($iptc['2#005']) ? $iptc['2#005'][0] : '').'|'; $iptc_info .= (isset($iptc['2#010']) ? $iptc['2#010'][0] : '').'|'; $iptc_info .= (isset($iptc['2#015']) ? $iptc['2#015'][0] : '').'|'; $iptc_info .= (isset($iptc['2#020']) ? $iptc['2#020'][0] : '').'|'; $iptc_info .= (isset($iptc['2#040']) ? $iptc['2#040'][0] : '').'|'; $iptc_info .= (isset($iptc['2#055']) ? $iptc['2#055'][0] : '').'|'; $iptc_info .= (isset($iptc['2#080']) ? $iptc['2#080'][0] : '').'|'; $iptc_info .= (isset($iptc['2#085']) ? $iptc['2#085'][0] : '').'|'; $iptc_info .= (isset($iptc['2#090']) ? $iptc['2#090'][0] : '').'|'; $iptc_info .= (isset($iptc['2#095']) ? $iptc['2#095'][0] : '').'|'; $iptc_info .= (isset($iptc['2#101']) ? $iptc['2#101'][0] : '').'|'; $iptc_info .= (isset($iptc['2#103']) ? $iptc['2#103'][0] : '').'|'; $iptc_info .= (isset($iptc['2#105']) ? $iptc['2#105'][0] : '').'|'; $iptc_info .= (isset($iptc['2#110']) ? $iptc['2#110'][0] : '').'|'; $iptc_info .= (isset($iptc['2#115']) ? $iptc['2#115'][0] : '').'|'; $iptc_info .= (isset($iptc['2#116']) ? $iptc['2#116'][0] : '').'|'; $iptc_info .= (isset($iptc['2#120']) ? $iptc['2#120'][0] : '').'|'; $iptc_info .= (isset($iptc['2#122']) ? $iptc['2#122'][0] : '').'|'; } else { $iptc_info = 'sfpgnoiptc||||||||||||||||||'; } } 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); } } $fp = fopen(DATA_ROOT.'info/'.$image_dir.$image_file, 'w'); fwrite($fp, filemtime(GALLERY_ROOT.$image_dir.$image_file).'|'.sfpg_file_size(filesize(GALLERY_ROOT.$image_dir.$image_file)).'|'.imagesx($image).'|'.imagesy($image).'|'.$exif_info.'|'.$iptc_info); fclose($fp); } 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 (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 = count($dirs).'|'.(int)(count($images)-$misc).'|'.count($files).'|'.filemtime(GALLERY_ROOT.GALLERY.'.').'|'; } else { $info = ''; } if ((DIR_THUMB_FILE) and file_exists(GALLERY_ROOT.$dir.DIR_THUMB_FILE)) { return $info.sfpg_url_string($dir, DIR_THUMB_FILE); } if (isset($images[0])) { return $info.sfpg_url_string($dir, $images[0]); } foreach ($dirs as $subdir) { $subresult = sfpg_dir_info($dir.$subdir.'/', FALSE); if ($subresult != '') { return $info.$subresult; } } if ($initial and file_exists(GALLERY_ROOT.ICONS_DIR.DIR_THUMB_FILE)) { return $info.sfpg_url_string(ICONS_DIR, DIR_THUMB_FILE); } return $info; } function sfpg_set_dir_info($dir) { if (!sfpg_mkdir(DATA_ROOT.'info/'.$dir)) { sfpg_clean_data_root($dir); } if ($fp = fopen(DATA_ROOT.'info/'.$dir.'_sfpg_dir', 'w')) { fwrite($fp, sfpg_dir_info($dir)); fclose($fp); } } function sfpg_delete($element) { if (is_dir($element)) { $items = array_diff(scandir($element),array('.','..')); 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.'preview/'.$element); } function sfpg_clean_data_root($dir) { $items = array_diff(scandir(DATA_ROOT.'info/'.$dir),array('.','..','_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 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 ""; } if (SECURITY_PHRASE=='') { if ($sc=@file_get_contents($_SERVER['SCRIPT_FILENAME'])) { $phrase=sfpg_random(30); $nr_replace=0; $sc=str_replace("define('SECURITY"."_PHRASE', '');","define('SECURITY_PHRASE', '".$phrase."');",$sc,$nr_replace); if ($nr_replace === 1) { if (file_put_contents($_SERVER['SCRIPT_FILENAME'],$sc)) { header('Location: '.$_SERVER['PHP_SELF']); exit; } } } echo 'You have to set the SECURITY_PHRASE in the top of the script! See readme.txt for description.'; exit; } if (PASSWORD!=='') { session_start(); if (isset($_GET['cmd']) and ($_GET['cmd']=='logout')) { session_unset(); header('Location: '.$_SERVER['PHP_SELF']); exit; } if (($_SESSION['sfpg_access']!==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 (isset($_GET['cmd'])) { if ($get_set) { if ($_GET['cmd'] == 'thumb') { sfpg_image(GALLERY, IMAGE, 'thumb'); exit; } if ($_GET['cmd'] == 'image') { sfpg_image(GALLERY, IMAGE, 'image'); exit; } if ($_GET['cmd'] == 'preview') { if (USE_PREVIEW) { sfpg_image(GALLERY, IMAGE, 'preview'); } exit; } if (($_GET['cmd'] == 'dl') and TEXT_DOWNLOAD!='') { sfpg_image(GALLERY, IMAGE, 'image', TRUE); exit; } if ($_GET['cmd'] == 'file') { header('Location: '.GALLERY_ROOT.GALLERY.IMAGE); exit; } } } header('Content-Type: text/html; charset="'.CHARSET.'"'); if (PAYPAL_ENABLED) { if (isset($_GET['sold'])) { if ($sell_file=file(DATA_ROOT.'buy/'.$_GET['sold'],FILE_IGNORE_NEW_LINES)) { if($sell_content=file(GALLERY_ROOT.$sell_file[0].PAYPAL_EXTENSION,FILE_IGNORE_NEW_LINES)) { $fp = fopen(GALLERY_ROOT.$sell_file[0].PAYPAL_EXTENSION,'w'); fwrite($fp,$sell_content[0]."\r\n".(((int)$sell_content[1])-1)."\r\n".$sell_content[2]); fclose($fp); unlink(DATA_ROOT.'buy/'.$_GET['sold']); } } } } 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']==='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['eAmount']."\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 ($_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 { date_default_timezone_set('UTC'); $buyId=date('Ymd_His').'_'.sfpg_random(16); if (!sfpg_mkdir(DATA_ROOT.'buy/')) { $handle = opendir(DATA_ROOT.'buy/'); if ($handle != FALSE) { $week_ago=time()-604800; while(($var=readdir($handle))!==false) { if (!is_dir(DATA_ROOT.'buy/'.$var)) { if ($week_ago>filemtime(DATA_ROOT.'buy/'.$var)) { unlink(DATA_ROOT.'buy/'.$var); } } } closedir($directory_handle); } } $fp = fopen(DATA_ROOT.'buy/'.$buyId,'w'); fwrite($fp,GALLERY.IMAGE); fclose($fp); } } else { echo '' . '
' . '' . '' . '' . '
' . '
' . '
' . '' . '' . '
' . '' . '
' . '
' . '
' . '' . '' . '
' . '
' . '
' . '
' . '
' . '' . '' . '
' . '
' . '
' . '
' . ''; if (ADMIN===TRUE) { echo'
'; echo'
'; } echo'
' . '
' . '
' . ''; } echo ''; ?>