<%
include("language.html")

function FormatFileSize(bytes)
	if math.floor(bytes/1024) < 1 then
		return bytes.." Bytes"
	elseif math.floor(bytes/(1024*1024)) < 1 then
		return string.format("%0.1f KB",bytes/1024 )
	elseif math.floor(bytes/(1024*1024*1024)) < 1 then
		return string.format("%0.1f MB",bytes/(1024*1024) )
	else
		return string.format("%0.1f GB",bytes/(1024*1024*1024) )
	end
end

function urlencode_special(s)
	s = s.gsub (s, "\n", "\r\n")
	s = s.gsub (s, "([^%w ])",
		function (c) return s.format ("%%%02X", s.byte(c)) end)
	return s
end

local downloadurl = _GET["url"] or ""
downloadurl = specialhtml_encode(downloadurl)

local file_list = strContent
local files = Split(file_list, "\r\n")
local outputHTML = ""
local nCount = 0
local strColor = "#FFF"

if string.find(downloadurl,"&subfolder=") then
	outputHTML = outputHTML.."<tr><td style='padding:5px 5px 2px 10px;'> <a href='#' title='"..LANG["item_goup"].."' onclick='history.go(-1);'><img src='images/return.png' style='border:0px;'> .. </a></td><td> </td><td> </td><td> </td></tr>"
end

outputHTML = outputHTML.."</thead><tbody id='maintable'>"
for _,filename in pairs(files) do
	if filename ~= "" then
		if nCount % 2 == 1 then
			strColor = "#EEE"
		else
			strColor = "#FFF"
		end

		local arrValue = Split(filename, "||")
		local filesize = 0
		local filedate = ""
		if arrValue ~= nil and table.maxn(arrValue) == 4 then
			filename = arrValue[1]
			filesize = arrValue[2]
			filedate = arrValue[3]
			isfolder = arrValue[4]
		end

		local ext = string.lower(string.sub(filename,-4))

		if isfolder == "1" then
			if string.find(downloadurl,"&subfolder=") then
				outputHTML = outputHTML.."<tr><td style='padding:10px; word-break:break-all; background:"..strColor..";' name='"..specialhtml_encode(filename).."'><a href='"..downloadurl.."/"..urlencode_special(filename).."'><img src='icons/folder.png' style='border:0px;'> "..specialhtml_encode(filename).."</a></td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>-</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..filedate.."</td><td style='word-break:keep-all; padding:12px; background:"..strColor..";'>-</td></tr>"
			else
				outputHTML = outputHTML.."<tr><td style='padding:10px; word-break:break-all; background:"..strColor..";' name='"..specialhtml_encode(filename).."'><a href='"..downloadurl.."&subfolder="..urlencode_special(filename).."'><img src='icons/folder.png' style='border:0px;'> "..specialhtml_encode(filename).."</a></td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>-</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..filedate.."</td><td style='word-break:keep-all; padding:12px; background:"..strColor..";'>-</td></tr>"
			end
		else
			if ext == ".mp4" or ext == ".mov" then
				outputHTML = outputHTML.."<tr><td style='padding:10px; word-break:break-all; line-height:180%; background:"..strColor..";' name='"..specialhtml_encode(filename).."'>"..specialhtml_encode(filename).." <a href='#' onclick='showVideo(\""..downloadurl.."&realfilename="..urlencode_special(filename).."\", \""..specialhtml_encode(filename).."\");' style='border-radius:3px; background-color:#007BFF; color:#FFF; padding:4 8px; text-decoration:none; word-break:keep-all;'>"..LANG["video_preview"].."</a></td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..FormatFileSize(filesize).."</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..filedate.."</td><td style='word-break:keep-all; padding:12px; background:"..strColor..";'><a href='"..downloadurl.."&realfilename="..urlencode_special(filename).."' style='border-radius:4px; background-color:#007BFF; color:#FFF; padding:6 12px; text-decoration:none;'>"..LANG["button_downpicture"].."</a></td></tr>"
			elseif ext == ".mp3" or ext == ".m4a" or ext == ".ogg" or ext == ".wav" then
				outputHTML = outputHTML.."<tr><td style='padding:10px; word-break:break-all; line-height:180%; background:"..strColor..";' name='"..specialhtml_encode(filename).."'>"..specialhtml_encode(filename).." <a href='#' onclick='showAudio(\""..downloadurl.."&realfilename="..urlencode_special(filename).."\", \""..specialhtml_encode(filename).."\");' style='border-radius:3px; background-color:#007BFF; color:#FFF; padding:4 8px; text-decoration:none; word-break:keep-all;'>"..LANG["video_preview"].."</a></td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..FormatFileSize(filesize).."</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..filedate.."</td><td style='word-break:keep-all; padding:12px; background:"..strColor..";'><a href='"..downloadurl.."&realfilename="..urlencode_special(filename).."' style='border-radius:4px; background-color:#007BFF; color:#FFF; padding:6 12px; text-decoration:none;'>"..LANG["button_downpicture"].."</a></td></tr>"
			else
				outputHTML = outputHTML.."<tr><td style='padding:10px; word-break:break-all; line-height:180%; background:"..strColor..";' name='"..specialhtml_encode(filename).."'>"..specialhtml_encode(filename).."</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..FormatFileSize(filesize).."</td><td class='listdata2' style='word-break:keep-all; background:"..strColor..";'>"..filedate.."</td><td style='word-break:keep-all; padding:12px; background:"..strColor..";'><a href='"..downloadurl.."&realfilename="..urlencode_special(filename).."' style='border-radius:4px; background-color:#007BFF; color:#FFF; padding:6 12px; text-decoration:none;'>"..LANG["button_downpicture"].."</a></td></tr>"
			end
		end
		nCount = nCount+1
	end
end
outputHTML = outputHTML.."</tbody>"

if string.find(downloadurl,"?download&weblink=") then
%>
<html>
<head>
<title>Wing FTP Server - Weblink Download</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" /> 
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<link rel="Shortcut Icon" href="images/logo.ico" type="image/x-icon">
<style type="text/css">
<!--
body{
background:#60605E;
font-family: Tahoma, sans-serif;
text-align: center;
font-size:11px;
font-weight:bold;
color:#000000;
overflow: auto;
}
.font{
font-size:12px;
font-weight:bold;
color:#000000;
}

.listhead
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #E1E2E3;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EFEFEF; overflow:hidden;
}

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #E1E2E3;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EFEFEF; overflow:hidden;
}

.listdata2
{
	padding:12px; word-break:break-all;
}

a:link,a:visited,a:active,a:hover{color: #000;text-decoration:none;}

@media only screen and (max-width: 767px), only screen and (max-device-width: 767px) {
.listhead2 {display:none;}
.listdata2 {display:none;}
}
-->
</style>

</head>
<script language="javascript" src="include/common.js?v=6"></script>
<script language="javascript">
	function showVideo(url, filename)
	{
		if(window.screen.width >= 1024)
		{
			showMessagebox("<span title='"+filename+"'>"+htmlencode(filename.substr(0,65))+(filename.length > 65 ? "...":"")+"</span>","<div style='text-align:center'><video style='margin-top:0px;' src='"+url+"' autoplay controls width='1000' height='580'>Your browser doesn't support HTML5</video></div>", null, 1020, 600);
		}
		else
		{
			var wndWidth = window.screen.width - 10;
			var wndHeight = parseInt(window.screen.height / 2);
			if(wndHeight < 320) wndHeight = 320;
			showMessagebox("<span title='"+filename+"'>"+htmlencode(filename.substr(0,30))+(filename.length > 30 ? "...":"")+"</span>","<div style='text-align:center'><video style='margin-top:0px;' src='"+url+"' autoplay controls width='"+wndWidth+"' height='"+wndHeight+"'>Your browser doesn't support HTML5</video></div>", null, wndWidth, wndHeight);
		}
	}

	function showAudio(url, filename)
	{
		if(window.screen.width >= 1024)
		{
			showMessagebox("<span title='"+filename+"'>"+htmlencode(filename.substr(0,65))+(filename.length > 65 ? "...":"")+"</span>","<div style='text-align:center'><audio style='width:98%;margin-top:110px;' src='"+url+"' autoplay controls width='660' height='280'>Your browser doesn't support HTML5</audio></div>", null, 680, 300);
		}
		else
		{
			var wndWidth = window.screen.width - 10;
			showMessagebox("<span title='"+filename+"'>"+htmlencode(filename.substr(0,30))+(filename.length > 30 ? "...":"")+"</span>","<div style='text-align:center'><audio style='width:98%;margin-top:70px;' src='"+url+"' autoplay controls width='"+wndWidth+"' height='220'>Your browser doesn't support HTML5</audio></div>", null, wndWidth, 220);
		}
	}
</script>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
	<td align="center" valign="top" style="padding-top:30px;"> 
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="max-width: 980px; _width: 980px;">
		<tr>
			<td style="background:#FFF;" height="88">
				<a href="https://www.wftpserver.com/" target="_blank"><img src="images/logo_s.png" border="0"></a>
				<hr />
			</td>
		</tr>
		<tr> 
		  <td style="background:#FFF; padding:0px 5px 50px 5px;">
				<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="filelist">
					<thead>
					<tr> 
					  <td height="30" width="60%" class="listhead" onmousedown="sortTable(this,'filelist', 0, 'listname');"><%=LANG["thread_name"]%></td><td height="30" class="listhead2" onmousedown="sortTable(this,'filelist', 1, 'size');"><%=LANG["thread_size"]%></td><td height="30" class="listhead2" onmousedown="sortTable(this,'filelist', 2);"><%=LANG["thread_modify"]%></td><td height="30" class="listhead"><%=LANG["geturl_title"]%></td>
					</tr>
					<%=outputHTML%>
				</table>
			</td>
		</tr>
		<tr> 
		<td height="35" style="font-size:12px;color:#FFF;">
		<a href="https://www.wftpserver.com/" target="_blank" style="color:#FFF;">Wing FTP Server</a> ©2003-2026 <b>wftpserver.com</b> All Rights Reserved
		</td>
		</tr>
	  </table>
	  </td>
  </tr>
</table>
</body>
</html>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('The web link does not exist!');</script>")
end 
%>
