<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	if ($_GET["path"] <> '') {
		$open_path = form_str_filepath($_GET["path"]);
	}
	$open_path = str_replace("\\", "/", right_slash_strip($open_path));
	if ($open_path == "") {
		if ($_SESSION['photo_open_path'] <> "") {
			$open_path = $_SESSION['photo_open_path'];
		} else {
			$open_path = $_SESSION['login_friends_album_folder_'.$_SESSION['current_id']];
			if ($open_path == "") {
				$open_path = DEFAULT_IMAGES_FOLDER;
			}
		}
	}
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		if ($_SESSION['システム管理者'] <> "YES" or photo_LIMITED_ADMIN_NOLIMIT <> 'YES') {
			$len = strlen(photo_LIMITED_IMAGES_FOLDER);
			if (substr($open_path, 0, $len) <> photo_LIMITED_IMAGES_FOLDER) {
				$open_path = photo_LIMITED_IMAGES_FOLDER;
			}
		}
	}
	if ($_GET['page'].'' <> '') {
		$page = intval($_GET['page']);
		if ($page < 1) {
			$page = 1;
		}
	} else {
		$page = 1;
	}
	$slidemode = $_GET['slidemode'].'';
	if ($_GET['auto'].'' <> '') {
		$_SESSION['slide_view_auto'] = $_GET['auto'];
	}
	if ($_GET['rep'].'' <> '') {
		$_SESSION['slide_view_repeat'] = $_GET['rep'];
	}
	if ($_SESSION['photo_open_path'] <> $open_path) {
		$_SESSION['photo_open_path'] = $open_path;
		$_SESSION['photo_subdir_count'] = 0;
		$_SESSION['photo_img_count'] = 0;
		unset($_SESSION['photo_subdir']);
		unset($_SESSION['photo_img']);
		unset($_SESSION['photo_img_type']);
		get_target_path_info($open_path);
	}
	$add_meta = '';
	if ($_SESSION['slide_view_auto'] == 'on') {
		if ($page < ceil($_SESSION['photo_img_count'])) {
			$add_meta = '<meta http-equiv="refresh" content="'.$_SESSION['slide_interval_time'].';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page='.strval($page+1);
			$add_meta .= '&path='.urlencode($open_path);
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		} elseif ($_SESSION['slide_view_repeat'] == 'on') {
			$add_meta = '<meta http-equiv="refresh" content="'.$_SESSION['slide_interval_time'].';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page=1';
			$add_meta .= '&path='.urlencode($open_path);
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		}
	}
	$filename = $_SESSION['photo_img'][$page];
	$filepath = $open_path . "/" . $filename;
	$filepath_url = urlencode($filepath);
	if ($_SESSION['photo_img_type'][$page] == 'video') {
		$getimg = "video-jpeg.php?file=".$filepath_url."&ss=".$_SESSION['video_thumb_ss'];
		$click = "video-view.php?file=".$filepath_url;
		$height_size = $_SESSION['slide_main_size'] - 2;
		$img_style = 'width: 100%;';
	} else {
		list($width, $height) = getimagesize(mb_convert_encoding($filepath, 'SJIS-win', 'UTF-8'));
		$getimg = "img-view.php?img=".$filepath_url;
		if ($width > $height) {
			$img_style = 'width: 100%;';
		} else {
			$img_style = 'height: 100%;';
		}
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<?php if ($add_meta <> '') echo $add_meta."\n"; ?>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="author" content="ok.2nd">
<title><?= $filename ?></title>
<style type="text/css">
* { margin: 0px; padding: 0px; }
html,body {
	width: 100%;
	height: 100%;
	overflow: hidden;
}
img {
	-ms-interpolation-mode: bicubic;
	<?= $img_style ?>
}
div#slide_view {
	text-align: center;
	width: 100%;
	height: 100%;
<?php 	if ($slidemode <> 'wallpaper') { ?>
	background-color: #000000; */
<?php	} ?>
}
div#move_control {
	position: absolute;
	top: 0px; left: 0px;
	width: 100%; height: 100%;
	z-index: 1;
}
#move_control table {
	width:100%; height: 100%;
}
td#left {
	height: 90%;
	text-align: left;
}
td#right {
	height: 90%;
	text-align: right;
}
td#bottom {
	height: 10%;
	text-align: center;
	vertical-align: bottom;
}
.move {
	color: #ffffff;
	text-decoration: none;
	font-size: 200%;
}
.return {
	color: #ffffff;
	text-decoration: none;
	font-size: 200%;
	margin: 0 5px;
}
.auto {
	color: #ffffff;
	text-decoration: none;
	font-size: 100%;
	margin: 0 5px;
}
.page {
	color: #ffffff;
	font-size: 100%;
	margin: 0 5px;
}
</style>
</head>
<?php 	if ($slidemode == 'wallpaper') { ?>
<body style="background-image: url('<?= $getimg ?>');">
<?php	} else {?>
<body onload="pixasticImageOnLoad()">
<script type="text/javascript" src="../scripts/cookie.js"></script>
<script type="text/javascript" src="../scripts/pixastic/pixastic.core.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/blur.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/brightness.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/coloradjust.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/desaturate.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/glow.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/hsl.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/lighten.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/posterize.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/sepia.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/sharpen.js"></script>
<script type="text/javascript" src="../scripts/pixastic/actions/solarize.js"></script>
<script type="text/javascript">
var pixasticAct = ["blur","brightness","coloradjust","desaturate","glow","hsl","lighten","posterize","sepia","sharpen","solarize"];
function pixasticImageOnLoad() {
	photo_pixastic = loadCookie("photo_pixastic_stack");
	if (photo_pixastic && photo_pixastic != "false") {
		pixastic = photo_pixastic.split(",");
		for(var ix in pixastic){
			pixasticAction(pixastic[ix]);
		}
	}
}
function pixasticAction(action) {
	if (action == "contrast") {
		Pixastic.process(document.getElementById("img_slide_main"), "brightness", {brightness:0,contrast:0.3});
	} else if (action == "red") {
		Pixastic.process(document.getElementById("img_slide_main"), "coloradjust", {red:0.1,green:0,blue:0});
	} else if (action == "green") {
		Pixastic.process(document.getElementById("img_slide_main"), "coloradjust", {red:0,green:0.1,blue:0});
	} else if (action == "blue") {
		Pixastic.process(document.getElementById("img_slide_main"), "coloradjust", {red:0,green:0,blue:0.1});
	} else if (action == "glow") {
		Pixastic.process(document.getElementById("img_slide_main"), "glow", {amount:0.1,radius:1.0});
	} else if (action == "hsl") {
		Pixastic.process(document.getElementById("img_slide_main"), "hsl", {hue:0,saturation:30,lightness:0});
	} else if (action == "lighten") {
		Pixastic.process(document.getElementById("img_slide_main"), "lighten", {amount:0.1});
	} else if (action == "posterize") {
		posterize = loadCookie("photo_pixastic_posterize");
		Pixastic.process(document.getElementById("img_slide_main"), "posterize", {levels:posterize});
	} else if (action == "sharpen") {
		Pixastic.process(document.getElementById("img_slide_main"), "sharpen", {amount:0.2});
	} else {	// desaturate, sepia, solarize, blur
		Pixastic.process(document.getElementById("img_slide_main"), action);
	}
}
</script>
<?php	} ?>
<div id="slide_view">
<?php 	if ($slidemode <> 'wallpaper') { ?>
	<?php if ($_SESSION['photo_img_count'] <> 0) { ?>
	<img id="img_slide_main" src="<?= $getimg ?>" alt="<?= $filename ?>" title="<?= $filename ?>" />
	<?php } ?>
<?php	} ?>
<div>
<div id="move_control">
<table>
<tr>
<td id="left">
<?php
	if ($page > 1) {
		$movepage = $page - 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$movepage = $_SESSION['photo_img_count'];
		} else {
			$movepage = $page;
		}
	}
?>
	<a class="move" href="?path=<?= urlencode($open_path) ?>&page=<?= $movepage ?>&slidemode=<?= $slidemode ?>">&lt;</a>
</td>
<td id="right">
<?php
	if ($page < $_SESSION['photo_img_count']) {
		$movepage = $page + 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$movepage = 1;
		} else {
			$movepage = $page;
		}
	}
?>
	<a class="move" href="?path=<?= urlencode($open_path) ?>&page=<?= $movepage ?>&slidemode=<?= $slidemode ?>">&gt;</a>
</td>
</tr>
<tr>
<td id="bottom" colspan=2>
	<a class="return" href="index.php?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&mode=s&auto=off">×</a>
	<?php if ($_SESSION['slide_view_auto'] == 'on') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&auto=off&slidemode=<?= $slidemode ?>">Auto <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&auto=on&slidemode=<?= $slidemode ?>">Auto Off</a>
	<?php } ?>
	<?php if ($_SESSION['slide_view_repeat'] == 'on') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&rep=off&slidemode=<?= $slidemode ?>">Repeat <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&rep=on&slidemode=<?= $slidemode ?>">Repeat Off</a>
	<?php } ?>
	<?php if ($slidemode == 'wallpaper') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>">Wallpaper <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&slidemode=wallpaper">Wallpaper Off</a>
	<?php } ?>
	<span class="page"><?= $page ?> / <?= $_SESSION['photo_img_count'] ?></span>
</td>
</tr>
</table>
</div>
</body>
</html>
<?php
function get_target_path_info($open_path) {
	$path_SJIS = mb_convert_encoding($open_path, 'SJIS-win', 'UTF-8');
	if ($dir = opendir($path_SJIS)) {
		$subdir_count = 0;
		$img_count = 0;
		$files = scandir($path_SJIS);
		foreach ($files as $file) {
			if ($file != "." && $file != "..") {
				if (is_dir($path_SJIS . "/" . $file)) {
					$_SESSION['photo_subdir'][++$subdir_count]
						= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
				} elseif (is_img_filename($file)) {
					$_SESSION['photo_img'][++$img_count]
						= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
				} else {
					if (photo_VIDEO_FFMPEG == "YES") {
						if (is_video_filename($file)) {
							$_SESSION['photo_img'][++$img_count]
							= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
							$_SESSION['photo_img_type'][$img_count] = 'video';
						}
					}
				}
			}
		}
		closedir($dir);
	}
	$_SESSION['photo_subdir_count'] = $subdir_count;
	$_SESSION['photo_img_count'] = $img_count;
}
?>
