summaryrefslogtreecommitdiffstats
path: root/webmusic.xslt
blob: c4071195ee1b0638416c06fd0d4964f57687e553 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="UTF-8" />

	<xsl:variable name="hex" select="'0123456789ABCDEF'"/>
	<xsl:variable name="ascii"> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable>
	<xsl:variable name="safe">/!()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:variable>
	<xsl:variable name="latin1">&#160;&#161;&#162;&#163;&#164;&#165;&#166;&#167;&#168;&#169;&#170;&#171;&#172;&#173;&#174;&#175;&#176;&#177;&#178;&#179;&#180;&#181;&#182;&#183;&#184;&#185;&#186;&#187;&#188;&#189;&#190;&#191;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#215;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#247;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;</xsl:variable>

	<xsl:template name="decode">
		<xsl:param name="str"/>

		<xsl:choose>
			<xsl:when test="contains($str,'%')">
				<xsl:value-of select="substring-before($str,'%')"/>
				<xsl:variable name="hexpair" select="translate(substring(substring-after($str,'%'),1,2),'abcdef','ABCDEF')"/>
				<xsl:variable name="decimal" select="(string-length(substring-before($hex,substring($hexpair,1,1))))*16 + string-length(substring-before($hex,substring($hexpair,2,1)))"/>
				<xsl:choose>
					<xsl:when test="$decimal &lt; 127 and $decimal &gt; 31">
						<xsl:value-of select="substring($ascii,$decimal - 31,1)"/>
					</xsl:when>
					<xsl:when test="$decimal &gt; 159">
						<xsl:value-of select="substring($latin1,$decimal - 159,1)"/>
					</xsl:when>
					<xsl:otherwise>?</xsl:otherwise>
				</xsl:choose>
				<xsl:call-template name="decode">
					<xsl:with-param name="str" select="substring(substring-after($str,'%'),3)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$str"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="url-encode">
		<xsl:param name="str"/>   
		<xsl:if test="$str">
			<xsl:variable name="first-char" select="substring($str,1,1)"/>
			<xsl:choose>
				<xsl:when test="contains($safe,$first-char)">
					<xsl:value-of select="$first-char"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:variable name="codepoint">
						<xsl:choose>
							<xsl:when test="contains($ascii,$first-char)">
								<xsl:value-of select="string-length(substring-before($ascii,$first-char)) + 32"/>
							</xsl:when>
							<xsl:when test="contains($latin1,$first-char)">
								<xsl:value-of select="string-length(substring-before($latin1,$first-char)) + 160"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:message terminate="no">Warning: string contains a character that is out of range! Substituting "?".</xsl:message>
								<xsl:text>63</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:variable name="hex-digit1" select="substring($hex,floor($codepoint div 16) + 1,1)"/>
					<xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
					<xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:if test="string-length($str) &gt; 1">
				<xsl:call-template name="url-encode">
					<xsl:with-param name="str" select="substring($str,2)"/>
				</xsl:call-template>
			</xsl:if>
		</xsl:if>
	</xsl:template>


	<xsl:template match="directory">
	<li>
	<a class="action">[--] </a>
	<xsl:element name="a">
		<xsl:attribute name="href">
			<xsl:call-template name="url-encode">
				<xsl:with-param name="str" select="concat($path, current())" />
			</xsl:call-template>
		</xsl:attribute>
		<xsl:value-of select="." />
	</xsl:element>
	</li>
	</xsl:template>

	<xsl:template match="file">
	<li>
	<script>queue.push('<xsl:call-template name="url-encode"><xsl:with-param name="str" select="concat($path, current())" /></xsl:call-template>')</script>
	<xsl:element name="a">
		<xsl:attribute name="class">
			<xsl:text>action</xsl:text>
		</xsl:attribute>
		<xsl:attribute name="href">
			<xsl:call-template name="url-encode">
				<xsl:with-param name="str" select="concat($path, current())" />
			</xsl:call-template>
		</xsl:attribute>
		<xsl:attribute name="download">
		</xsl:attribute>
		<xsl:text>[DL] </xsl:text>
	</xsl:element>
	<a href="#">
		<xsl:attribute name="onclick">playSong('<xsl:call-template name="url-encode"><xsl:with-param name="str" select="concat($path, current())" /></xsl:call-template>')</xsl:attribute>
		<xsl:value-of select="." />
	</a>
	</li>
	</xsl:template>

	<xsl:template match="/">
		<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
		<html lang="en">
		<head>
			<title>webmusic not on .NET 5.0.3</title>

			<meta charset="UTF-8" />
			<meta name="viewport" content="width=device-width, initial-scale=1.0" />
			<meta name="mobile-web-app-capable" content="yes" />
			<meta name="apple-mobile-web-app-capable" content="yes" />
			<meta name="theme-color" content="#ffffff" />

			<link href="/assets/webmusic.css" rel="stylesheet" />

			<script src="/assets/howler.core.js"></script>
			<script src="/assets/webmusic.js"></script>

			<link rel="manifest" href="/assets/manifest.json" />
			<link rel="apple-touch-icon" sizes="57x57" href="/assets/favicon/apple-icon-57x57.png" />
			<link rel="apple-touch-icon" sizes="60x60" href="/assets/favicon/apple-icon-60x60.png" />
			<link rel="apple-touch-icon" sizes="72x72" href="/assets/favicon/apple-icon-72x72.png" />
			<link rel="apple-touch-icon" sizes="76x76" href="/assets/favicon/apple-icon-76x76.png" />
			<link rel="apple-touch-icon" sizes="114x114" href="/assets/favicon/apple-icon-114x114.png" />
			<link rel="apple-touch-icon" sizes="120x120" href="/assets/favicon/apple-icon-120x120.png" />
			<link rel="apple-touch-icon" sizes="144x144" href="/assets/favicon/apple-icon-144x144.png" />
			<link rel="apple-touch-icon" sizes="152x152" href="/assets/favicon/apple-icon-152x152.png" />
			<link rel="apple-touch-icon" sizes="180x180" href="/assets/favicon/apple-icon-180x180.png" />
			<link rel="icon" type="image/png" sizes="192x192" href="/assets/favicon/android-icon-192x192.png" />
			<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon/favicon-32x32.png" />
			<link rel="icon" type="image/png" sizes="96x96" href="/assets/favicon/favicon-96x96.png" />
			<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon/favicon-16x16.png" />
		</head>
		<body>
			<div id="container">
				<h2><xsl:value-of select="$path"/><xsl:text> </xsl:text><span id="state"></span><xsl:text> </xsl:text><span id="flags"></span></h2>
				<a class="action-muted">[..]</a>
				<a href=".." id="back" class="entry-muted cfont"> Go back</a>
				<br/>
				<a class="action-muted">[--]</a>
				<xsl:element name="a">
					<xsl:attribute name="class">
						<xsl:text>entry-muted cfont</xsl:text>
					</xsl:attribute>
					<xsl:attribute name="href">
						<xsl:call-template name="url-encode">
							<xsl:with-param name="str" select="concat($path, 'playlist.m3u')" />
						</xsl:call-template>
					</xsl:attribute>
					<xsl:text> Download playlist</xsl:text>
				</xsl:element>
				<br/>
				<br/>
				<xsl:apply-templates />
			</div>
		</body>
		</html>
	</xsl:template>
</xsl:stylesheet>