>"); define("TEXT_INFO", "Information"); define("TEXT_DOWNLOAD", "Download full-size image"); 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", "Sub galleries"); 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_EXIF_DATE", "EXIF 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 informatin in image"); $color_body_back = "#000000"; $color_body_text = "#aaaaaa"; $color_body_link = "#b0b0b0"; $color_body_hover = "#ffffff"; $color_thumb_border = "#606060"; $color_fullimg_border = "#ffffff"; $color_dir_box_border = "#505050"; $color_dir_box_back = "#000000"; $color_dir_box_text = "#aaaaaa"; $color_dir_hover = "#ffffff"; $color_dir_hover_text = "#000000"; $color_img_box_border = "#505050"; $color_img_box_back = "#202020"; $color_img_box_text = "#aaaaaa"; $color_img_hover = "#ffffff"; $color_img_hover_text = "#000000"; $color_file_box_border = "#404040"; $color_file_box_back = "#101010"; $color_file_box_text = "#aaaaaa"; $color_file_hover = "#ffffff"; $color_file_hover_text = "#000000"; $color_button_border = "#808080"; $color_button_back = "#000000"; $color_button_text = "#aaaaaa"; $color_button_border_off = "#505050"; $color_button_back_off = "#000000"; $color_button_text_off = "#505050"; $color_button_hover = "#ffffff"; $color_button_hover_text = "#000000"; $color_button_on = "#aaaaaa"; $color_button_text_on = "#000000"; $color_overlay = "#000000"; $color_menu_hover = "#ffffff"; // ----------- 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_NATURAL) { natcasesort ($arr); if ($sort_reverse) { 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 . md5($res . SECURITY_PHRASE)); } function str_to_script($str) { return str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\\\"", str_replace("'", "\'", (NL_TO_BR ? nl2br($str) : $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) { return strtolower(substr($file, strrpos($file, "."))); } function sfpg_image_type($file) { $type = sfpg_ext($file); if (($type == ".jpg") or ($type == ".jpeg")) { return "jpeg"; } elseif ($type == ".png") { return "png"; } elseif ($type == ".gif") { return "gif"; } return FALSE; } function sfpg_get_dir($dir) { global $dir_exclude, $file_exclude, $file_ext_exclude; $dirs = array(); $dirs_time = array(); $images = array(); $images_time = array(); $files = array(); $files_time = array(); $directory_handle = opendir(GALLERY_ROOT . $dir); if ($directory_handle != FALSE) { while($var = readdir($directory_handle)) { if (is_dir(GALLERY_ROOT . $dir . $var)) { if (($var != ".") and ($var != "..") and !in_array(strtolower($var), $dir_exclude)) { $dirs[] = $var; if (DIR_SORT_BY_TIME) { $dirs_time[] = filemtime(GALLERY_ROOT . $dir . $var . "/."); } } } elseif (sfpg_image_type($var)) { if ($var != DIR_IMAGE_FILE) { $images[] = $var; if (IMAGE_SORT_BY_TIME) { $images_time[] = filemtime(GALLERY_ROOT . $dir . $var); } } } elseif (SHOW_FILES) { if (!in_array(strtolower($var), $file_exclude) and !((strrpos($var, ".") !== FALSE) and in_array(sfpg_ext($var), $file_ext_exclude))) { $files[] = $var; if (FILE_SORT_BY_TIME) { $files_time[] = filemtime(GALLERY_ROOT . $dir . $var); } } } } if (SHOW_FILES) { foreach ($files as $val) { $fti = array_search($val . FILE_THUMB_EXT, $images); if ($fti !== FALSE) { 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 array($dirs, $images, $files); } else { header("Location: " . $_SERVER["PHP_SELF"]); exit; } } 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_path_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; } } if (!$image = imagecreatefromstring(file_get_contents($source_img))) { exit; } if (($func == "thumb") and ($image_dir != "_sfpg_icons/")) { $image_changed = FALSE; if (!is_dir(DATA_ROOT . "info/" . $image_dir)) { mkdir(DATA_ROOT . "info/" . $image_dir, 0777, TRUE); } $exif_info = ""; if (function_exists("read_exif_data")) { if (SHOW_EXIF_INFO) { $exif_data = exif_read_data(GALLERY_ROOT . $image_dir . $image_file, "IFD0"); if ($exif_data !== FALSE) { $exif_info .= TEXT_EXIF_DATE . ": " . $exif_data["DateTimeOriginal"] ."
"; $exif_info .= TEXT_EXIF_CAMERA . ": " . $exif_data["Model"] ."
"; $exif_info .= TEXT_EXIF_ISO . ": "; if(isset($exif_data["ISOSpeedRatings"])) { $exif_info .= $exif_data["ISOSpeedRatings"]; } else { $exif_info .= "n/a"; } $exif_info .= "
"; $exif_info .= TEXT_EXIF_SHUTTER . ": "; 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"; } else { $exif_info .= "n/a"; } $exif_info .= "
"; $exif_info .= TEXT_EXIF_APERTURE . ": "; if(isset($exif_data["FNumber"])) { $exif_FNumber=create_function('','return number_format(round('.$exif_data["FNumber"].',1),1);'); $exif_info .= "f".$exif_FNumber(); } else { $exif_info .= "n/a"; } $exif_info .= "
"; $exif_info .= TEXT_EXIF_FOCAL . ": "; if(isset($exif_data["FocalLength"])) { $exif_FocalLength=create_function('','return number_format(round('.$exif_data["FocalLength"].',1),1);'); $exif_info .= $exif_FocalLength(); } else { $exif_info .= "n/a"; } $exif_info .= "mm
"; $exif_info .= TEXT_EXIF_FLASH . ": "; if(isset($exif_data["Flash"])) { $exif_info .= (($exif_data["Flash"] & 1) ? TEXT_YES : TEXT_NO); } else { $exif_info .= "n/a"; } $exif_info .= "
"; } else { $exif_info .= TEXT_EXIF_MISSING . "
"; } } 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); 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); 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); 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); 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; } } if (WATERMARK) { $wm_file = GALLERY_ROOT . "_sfpg_icons/" . 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); imagecopy($image, $watermark, $image_width-$ww, $image_height-$wh, 0, 0, $ww, $wh); imagedestroy($watermark); $image_changed = TRUE; } } } if ($image_changed) { if (!is_dir(DATA_ROOT . "image/" . $image_dir)) { mkdir(DATA_ROOT . "image/" . $image_dir, 0777, TRUE); } $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 . ".sfpg", "w"); fwrite($fp, date(DATE_FORMAT, filemtime(GALLERY_ROOT . $image_dir . $image_file)) . "|" . sfpg_file_size(filesize(GALLERY_ROOT . $image_dir . $image_file)) . "|" . imagesx($image) . "|" . imagesy($image) . "|" . $exif_info); fclose($fp); } $image_width = imagesx($image); $image_height = imagesy($image); 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; } } $new_image = imagecreatetruecolor($new_img_width, $new_img_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_img_width, $new_img_height, imagesx($image), imagesy($image)); imagedestroy($image); if (!is_dir(DATA_ROOT . $func . "/" . $image_dir)) { mkdir(DATA_ROOT . $func . "/" . $image_dir, 0777, TRUE); } 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($directory, $initial=TRUE) { list($dirs, $images, $files) = sfpg_get_dir($directory); if ($initial) { $info = count($dirs) . "|" . count($images) . "|" . count($files) . "|" . date(DATE_FORMAT, filemtime(GALLERY_ROOT . GALLERY . ".")) . "|"; } else { $info = ""; } if ((DIR_IMAGE_FILE) and file_exists(GALLERY_ROOT . $directory . DIR_IMAGE_FILE)) { return $info . sfpg_url_string($directory, DIR_IMAGE_FILE); } if (isset($images[0])) { return $info . sfpg_url_string($directory, $images[0]); } else { foreach ($dirs as $subdir) { $subresult = sfpg_dir_info($directory . $subdir . "/", FALSE); if ($subresult != "") { return $info . $subresult; } } } return $info; } function sfpg_set_dir_info($directory) { if (!is_dir(DATA_ROOT . "info/" . $directory)) { mkdir(DATA_ROOT . "info/" . $directory, 0777, TRUE); } if ($fp = fopen(DATA_ROOT . "info/" . $directory . "_info.sfpg", "w")) { fwrite($fp, sfpg_dir_info($directory)); fclose($fp); } } function sfpg_javascript() { global $dirs, $images, $files, $file_ext_thumbs; echo ""; } $get_set = FALSE; if (isset($_GET["sfpg"])) { $get = explode("*", sfpg_base64url_decode($_GET["sfpg"])); if ((md5($get[0] . "*" . $get[1] . "*" . SECURITY_PHRASE) === $get[2]) and (strpos($get[0] . $get[1], "..") === FALSE)) { define("GALLERY", $get[0]); define("IMAGE", $get[1]); $get_set = TRUE; } } if (!$get_set) { define("GALLERY", ""); define("IMAGE", ""); } if (isset($_GET["cmd"])) { if ($_GET["cmd"] == "css") { header("Content-type: text/css"); echo " img { -ms-interpolation-mode : bicubic; } body.sfpg { background : $color_body_back; color: $color_body_text; font-family: Arial, Helvetica, sans-serif; font-size: ".FONT_SIZE."px; font-weight: normal; margin:0px; padding:0px; overflow:hidden; } body.sfpg a:active, body.sfpg a:link, body.sfpg a:visited, body.sfpg a:focus { color : $color_body_link; text-decoration : none; } body.sfpg a:hover { color : $color_body_hover; text-decoration : none; } table { font-size: ".FONT_SIZE."px; height:100%; width:100%; } table.info td { padding : 10px; vertical-align : top; } table.sfpg_disp { text-align : center; padding : 0px; } table.sfpg_disp td.menu { background : #000000; border-top : 1px solid #303030; vertical-align : middle; white-space: nowrap; } table.sfpg_disp td.navi { height: ".NAV_BAR_HEIGHT."px; background : #202020; border-top : 1px solid #303030; vertical-align : middle; white-space: nowrap; } table.sfpg_disp td.mid { vertical-align : middle; } .sfpg_info_text, .loading { background : #000000; border : 1px solid #606060; color : #aaaaaa; padding : 1px 4px 1px 4px; width : 200px; } .loading { padding : 20px 20px 20px 20px; margin-right: auto; margin-left: auto; } .sfpg_button, .sfpg_button_hover, .sfpg_button_on, .sfpg_button_nav, .sfpg_button_disabled { cursor : pointer; background : $color_button_back; border : 1px solid $color_button_border; color : $color_button_text; padding : 0px 5px 0px 5px; margin : 0px 5px 0px 5px; white-space: nowrap; } .sfpg_button_hover { background : $color_button_hover; color : $color_button_hover_text; } .sfpg_button_on { background : $color_button_on; color : $color_button_text_on; } .sfpg_button_disabled { cursor : default; border : 1px solid $color_button_border_off; background : $color_button_back_off; color : $color_button_text_off; } .sfpg_button_nav { border : 1px solid #404040; background:#101010; color:#808080; } .thumbbox { vertical-align : top; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width: " . ((2 * (THUMB_BORDER_WIDTH + THUMB_MARGIN + THUMB_BOX_MARGIN)) + THUMB_MAX_WIDTH + 2) . "px; height: " . ((2 * (THUMB_BORDER_WIDTH + THUMB_MARGIN + THUMB_BOX_MARGIN)) + THUMB_MAX_HEIGHT + 2 + THUMB_BOX_EXTRA_HEIGHT) . "px; margin: 0px; padding: 0px; } .thumbimgbox { width: " . ((2 * (THUMB_BORDER_WIDTH + THUMB_MARGIN)) + THUMB_MAX_WIDTH) . "px; height: " . ((THUMB_BORDER_WIDTH * 2) + THUMB_MARGIN + THUMB_MAX_HEIGHT + 6) . "px; margin: 0px; padding: 0px; } .innerboxdir, .innerboximg, .innerboxfile, .innerboxdir_hover, .innerboximg_hover, .innerboxfile_hover { cursor:pointer; margin: " . THUMB_BOX_MARGIN . "px; padding: 0px; width: " . ((2 * (THUMB_BORDER_WIDTH + THUMB_MARGIN)) + THUMB_MAX_WIDTH + 2) . "px; height: " . ((2 * (THUMB_BORDER_WIDTH + THUMB_MARGIN)) + THUMB_MAX_HEIGHT + 2 + THUMB_BOX_EXTRA_HEIGHT) . "px; } .innerboxdir, .innerboxdir_hover { border: 1px solid $color_dir_box_border; background : $color_dir_box_back; color : $color_dir_box_text; } .innerboximg, .innerboximg_hover { border: 1px solid $color_img_box_border; background : $color_img_box_back; color : $color_img_box_text; } .innerboxfile, .innerboxfile_hover { border: 1px solid $color_file_box_border; background : $color_file_box_back; color : $color_file_box_text; } .innerboxdir_hover { background : $color_dir_hover; color : $color_dir_hover_text; } .innerboximg_hover { background : $color_img_hover; color : $color_img_hover_text; } .innerboxfile_hover { background : $color_file_hover; color : $color_file_hover_text; } .full_image { cursor:pointer; border : ".FULLIMG_BORDER_WIDTH."px solid $color_fullimg_border; } .thumb { margin: " . THUMB_MARGIN . "px " . THUMB_MARGIN . "px 5px " . THUMB_MARGIN . "px; border : ".THUMB_BORDER_WIDTH."px solid $color_thumb_border; } .box_image { position:absolute; bottom:".MENU_BOX_HEIGHT."px; right:0; z-index:1020; overflow:auto; visibility:hidden; text-align : center; } .box_wait { position:absolute; bottom:".MENU_BOX_HEIGHT."px; right:0; z-index:1015; overflow:auto; visibility:hidden; text-align : center; } .box_navi { position:absolute; bottom:0; left:0; height:".MENU_BOX_HEIGHT."px; width:100%; z-index:1120; overflow:hidden; text-align : center; } .box_info { position:absolute; top:10px; left:10px; width:".INFO_BOX_WIDTH."px; z-index:1040; visibility:hidden; overflow:auto; border : 1px solid #404040; background: #101010; } .box_overlay { position:absolute; bottom:".MENU_BOX_HEIGHT."px; left:0; height:100%; width:100%; z-index:1010; overflow:hidden; visibility:hidden; background:$color_overlay; } .box_gallery { text-align:center; position:absolute; top:0; right:0; z-index:1000; overflow:auto; } "; exit; } if ($_GET["cmd"] == "thumb") { sfpg_image(GALLERY, IMAGE, "thumb"); exit; } if ($_GET["cmd"] == "preview") { if (USE_PREVIEW) { sfpg_image(GALLERY, IMAGE, "preview"); } 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 ($_GET["cmd"] == "file") { header("Location: " . GALLERY_ROOT . GALLERY . IMAGE); exit; } } list($dirs, $images, $files) = sfpg_get_dir(GALLERY); echo "" . "" . "" . TEXT_GALLERY_NAME . ""; sfpg_javascript(); echo "" . "
" . "" . "" . "" . "
" . "
" . "
" . "
" . "
" . "
" . "
" . "" . "" . "
" . "\"\"" . "
" . "
" . "
" . "" . "" . "
" . "
" . "
" . "
" . "
" . "" . "" . "
" . "
" . "
" . "
" . "
" . "
" . ""; ?>