>"); 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 in bytes"); define("TEXT_IMAGESIZE", "Full Image Dimensions"); define("TEXT_DISPLAYED_IMAGE", "Displayed Image Dimensions"); 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 main page"); define("TEXT_THIS_IS_FULL", "Full"); define("TEXT_THIS_IS_PREVIEW", "Preview"); define("TEXT_SCALED_TO", "Scaled to: "); define("GALLERY_ROOT", "./"); define("DATA_ROOT", "./.sfpg_data/"); define("SECURITY_PHRASE", "1234567890"); define("DIR_NAME_FILE", ".sfpg_name.txt"); define("DIR_IMAGE_FILE", ".sfpg_image.jpg"); define("DIR_DESC_FILE", ".sfpg_desc.txt"); define("DIR_SORT_REVERSE", FALSE); define("DIR_SORT_BY_TIME", FALSE); $dir_exclude = array(".sfpg_data"); define("SHOW_IMAGE_EXT", FALSE); define("IMAGE_SORT_REVERSE", FALSE); define("IMAGE_SORT_BY_TIME", FALSE); define("SHOW_FILES", TRUE); define("SHOW_FILE_EXT", TRUE); define("FILE_IN_NEW_WINDOW", TRUE); define("FILE_THUMB_EXT", ".jpg"); define("FILE_SORT_REVERSE", FALSE); define("FILE_SORT_BY_TIME", FALSE); $file_exclude = array(); $file_ext_exclude = array(".php", ".txt"); define("LINK_BACK", ""); define("CHARSET", "iso-8859-1"); define("DATE_FORMAT", "Y-m-d h:i:s"); define("DESC_EXT", ".txt"); define("SORT_DIVIDER", "--"); define("SORT_NATURAL", TRUE); define("FONT_SIZE", 12); define("UNDERSCORE_AS_SPACE", TRUE); define("NL_TO_BR", FALSE); define("THUMB_MAX_WIDTH", 160); define("THUMB_MAX_HEIGHT", 120); define("THUMB_ENLARGE", TRUE); define("THUMB_JPEG_QUALITY", 75); define("USE_PREVIEW", FALSE); define("PREVIEW_MAX_WIDTH", 600); define("PREVIEW_MAX_HEIGHT", 400); define("PREVIEW_ENLARGE", FALSE); define("PREVIEW_JPEG_QUALITY", 75); define("INFO_BOX_WIDTH", 250); define("MENU_BOX_HEIGHT", 70); define("NAV_BAR_HEIGHT", 25); define("THUMB_BORDER_WIDTH", 1); define("THUMB_MARGIN", 10); define("THUMB_BOX_MARGIN", 7); define("THUMB_BOX_EXTRA_HEIGHT", 14); define("THUMB_CHARS_MAX", 80); define("FULLIMG_BORDER_WIDTH", 5); define("NAVI_CHARS_MAX", 100); define("OVERLAY_OPACITY", 90); define("FADE_FRAME_PER_SEC", 30); define("FADE_DURATION_MS", 300); define("LOAD_FADE_GRACE", 500); $color_body_back = "#000020"; $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_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_image_type($file) { $type = strtolower(substr($file, strrpos($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(strtolower(substr($var, strrpos($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_thumb($image_dir, $image_file, $preview=FALSE) { if($preview) { $max_width = PREVIEW_MAX_WIDTH; $max_height = PREVIEW_MAX_HEIGHT; $enlarge = PREVIEW_ENLARGE; $jpeg_quality = PREVIEW_JPEG_QUALITY; $dirname = "preview"; } else { $max_width = THUMB_MAX_WIDTH; $max_height = THUMB_MAX_HEIGHT; $enlarge = THUMB_ENLARGE; $jpeg_quality = THUMB_JPEG_QUALITY; $dirname = "thumb"; } $thumb_file = DATA_ROOT . $dirname . "/" . $image_dir . $image_file; $thumb_type = sfpg_image_type($thumb_file); if (file_exists($thumb_file) and $thumb_type) { header("Content-type: image/" . $thumb_type); header("Content-Disposition: inline; filename=\"" . $dirname . "_" . $image_file . "\""); readfile($thumb_file); exit; } else { $img_type = sfpg_image_type($image_file); if ($img_type == "jpeg") { if (!$image = imagecreatefromjpeg(GALLERY_ROOT . $image_dir . $image_file)) { exit; } } elseif ($img_type == "png") { if (!$image = imagecreatefrompng(GALLERY_ROOT . $image_dir . $image_file)) { exit; } } elseif ($img_type == "gif") { if (!$image = imagecreatefromgif(GALLERY_ROOT . $image_dir . $image_file)) { exit; } } else { exit; } $image_size = getimagesize(GALLERY_ROOT . $image_dir . $image_file); $image_width = $image_size[0]; $image_height = $image_size[1]; if (($image_width < $max_width) and ($image_height < $max_height) and !$enlarge) { $thumb_height = $image_height; $thumb_width = $image_width; } else { $aspect_x = $image_width / $max_width; $aspect_y = $image_height / $max_height; if ($aspect_x > $aspect_y) { $thumb_width = $max_width; $thumb_height = $image_height / $aspect_x; } else { $thumb_height = $max_height; $thumb_width = $image_width / $aspect_y; } } $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, imagesx($image), imagesy($image)); imagedestroy($image); if (!is_dir(DATA_ROOT . $dirname . "/" . $image_dir)) { mkdir(DATA_ROOT . $dirname . "/" . $image_dir, 0777, TRUE); } if (!$preview) { if (!is_dir(DATA_ROOT . "info/" . $image_dir)) { mkdir(DATA_ROOT . "info/" . $image_dir, 0777, TRUE); } $fp = fopen(DATA_ROOT . "info/" . $image_dir . $image_file . ".sfpg", "w"); fwrite($fp, date(DATE_FORMAT, filemtime(GALLERY_ROOT . $image_dir . $image_file)) . "|" . number_format(filesize(GALLERY_ROOT . $image_dir . $image_file), 0, '', '.') . "|" . $image_width . "|" . $image_height); fclose($fp); } header("Content-type: image/" . $thumb_type); header("Content-Disposition: inline; filename=\"" . $dirname . "_" . $image_file . "\""); if ($img_type == "jpeg") { imagejpeg($thumb, NULL, $jpeg_quality); imagejpeg($thumb, $thumb_file, $jpeg_quality); } elseif ($img_type == "png") { imagepng($thumb); imagepng($thumb, $thumb_file); } elseif ($img_type == "gif") { imagegif($thumb); imagegif($thumb, $thumb_file); } imagedestroy($thumb); } } 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; 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_thumb(GALLERY, IMAGE); exit; } if ($_GET["cmd"] == "preview") { if (USE_PREVIEW) { sfpg_thumb(GALLERY, IMAGE, TRUE); } exit; } if ($_GET["cmd"] == "file") { header("Location: " . GALLERY_ROOT . GALLERY . IMAGE); exit; } if (($_GET["cmd"] == "image") or (($_GET["cmd"] == "dl") and TEXT_DOWNLOAD)) { $image_file = GALLERY_ROOT . GALLERY . IMAGE; $img_type = sfpg_image_type($image_file); if (file_exists($image_file) and $img_type) { if ($_GET["cmd"] == "dl") { header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . IMAGE . "\""); } else { header("Content-Type: image/" . $img_type); header("Content-Disposition: inline; filename=\"" . IMAGE . "\""); } readfile($image_file); } exit; } } list($dirs, $images, $files) = sfpg_get_dir(GALLERY); echo "" . "" . "" . TEXT_GALLERY_NAME . ""; sfpg_javascript(); echo "" . "
" . "" . "" . "" . "
" . "
" . "
" . "
" . "
" . "
" . "
" . "" . "" . "
" . "\"\"" . "
" . "
" . "
" . "" . "" . "
" . "
" . "
" . "
" . "
" . "" . "" . "
" . "
" . "
" . "
" . "
" . "
" . ""; ?>