Create FUNDING.yml
[mirrors/JukeBox.git] / index.php
CommitLineData
ca88871f 1<?php require_once('./http_auth.php'); /*Delete this line to disable password protection*/ ?>
1c6591f3 2<?php $exec_time = round(microtime(true), 3); /*
6dcce3ff 3Harvie's JuKe!Box (2oo7-2o1o)
1c6591f3 4/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ca88871f 5Version info:
a9beee06 6 * 0.3.6 - Now sorting also directories and have icon link support in css
1c6591f3
H
7 * 0.3.5 - Fixed security bug - directory traversal in filelisting (upgrade recommended)
8 * 0.3.4 - Generating playlist for flashplayer, searching for bugs, cleaning code and preparing for new version release
9 * 0.3.3 - Shorter URLs for flashplayer (due to discussion at #skola ;o), nicer national characters handling
10 * 0.3.2 - Better support for national charsets, few small bugfixes, css improvements, modular search engines
11 * 0.3.1 - Buckfickses in m3u generation, better navigation, magic_quotes_gpc handled, css improvements
12 * 0.3 - Migrated to standalone WPAudioPlayer (better, nicer, with more functions)
13 * 0.2 - Few new functions (search playlist, random,...)
14 * 0.1.1 - Few little fixups, written help.html in Czech language ;o)
de30f731 15 * 0.1 - All functions are working - TODO: bugfix & replace ugly code
1c6591f3 16/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ca88871f
H
17*/
18
19//Config-basic
20$title = 'Harvie\'s&nbsp;JuKe!Box'; //Title of jukebox
2fa64919 21$music_dir = 'music'; //Local path to directory with music
0e21eaf8 22$base_url = preg_replace('/[^\/]*$/', '', $_SERVER['SCRIPT_NAME']); //URL of this directory (always ends with slash)
1c6591f3 23$music_dir_url = 'http://your-server.net/jukebox/music'; //URL path to the same directory
d1c6fd3d 24$cache_passwd = ''; //You need this passwd to refresh search cache
ca88871f 25$sort = 3; //Sort? 0 = none, 1 = playlists, 2 = 1+listings; 3 = 2+search-EXPERIMENTAL! (sorting could eat lot of memory)
1c6591f3
H
26$access_limit = 40; //How many files could be accessed without using cache (while searching)
27
28//Encoding settins
29$charset = 'UTF-8'; //Charset for page
30$national_characters = 1; //Support searching in filenames with national characters? 0 = no; 1 = yes; (may slowdown search a little)
ca88871f
H
31
32//Playlist settings
33$playlist_name = 'playlist.m3u'; //Name of downloaded pl
34$m3u_exts = 'ogg|mp[0-9]|wma|wmv|wav'; //Allow only these files
35$default_random_count = 30; //How many random songs by defaul?
36
37//External files
38$indexlist = array('index.html', 'index.txt'); //Search for this file in each directory
2fa64919 39$bonus_dir = 'jbx'; //Misc. files directory
1c6591f3 40////
ca88871f 41$search_cache = $bonus_dir.'/cache.db'; //Database for searching music (php +rw) - .htaccess: Deny from all!!!
0e21eaf8
H
42$css_file = $base_url.$bonus_dir.'/themes/default/jukebox.css'; //CSS (Design)
43$favicon_file = $base_url.'favicon.png'; //favicon
ca88871f
H
44$header_file = $bonus_dir.'/header.html'; //header file
45$footer_file = $bonus_dir.'/footer.html'; //footer file
46
1c6591f3
H
47//Search engines extend search experience
48$search_engines = array(
49 'Google.com' => 'http://google.com/search?q=',
50 'Images' => 'http://google.com/images?q=',
51 'Karaoke-Lyrics.net' => 'http://www.karaoke-lyrics.net/index.php?page=find&q=',
52 'Jyxo.cz multimedia' => 'http://jyxo.cz/s?d=mm&q=',
53 'Centrum.cz mp3' => 'http://search.centrum.cz/index.php?sec=mp3&q=',
54 'YOUTube.com' => 'http://youtube.com/results?search_query='
55);
56
57//Flash MusicPlayer (info about settings: http://wpaudioplayer.com/standalone)
58$flash_player_swf = $bonus_dir.'/player.swf'; //path to musicplayer
59$flash_player_frame = 'playframe-show'; //FlashPlayer Target (playframe-show|playframe-hide) - usefull for compatibility with old music player
60$flash_player_options = '?bg=000099&loader=000000&tracker=AAAAFF&skip=FFFFFF' //.'&leftbg=000077&rightbg=000077&righticon=999999'
50b4768a 61 .'&autostart=yes&initialvolume=100&buffer=30&animation=no&soundFile='; //& arguments (urlencoded song url will be added)
1c6591f3 62
ca88871f 63//Security
1c6591f3
H
64error_reporting(0); //This will disable error reporting, wich can pass sensitive data to users
65
66//External configuration file (overrides index.php configuration)
67@include('./_config.php');
68
69//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ca88871f
H
70
71//Init
72srand(time());
1c6591f3
H
73@ini_set('magic_quotes_gpc' , 'off');
74if(get_magic_quotes_gpc()) die("Error: magic_quotes_gpc needs to be disabled!\n");
75
76//Enable flash?
77$useflash = is_file($flash_player_swf);
78
79//Little magic with directories ;o)
74524fb0 80if($_SERVER['PATH_INFO']!='') $_GET['dir']=$_SERVER['PATH_INFO'];
ca88871f 81$current_dir = ereg_replace('/+', '/', '/'.$_GET['dir'].'/');
1c6591f3
H
82if(eregi('(/|\\\\)\\.\\.(/|\\\\)', $current_dir)) { //check for directory traversal ;)
83 header('Location: ?');
84 die('Error - directory not found!');
85}
ca88871f
H
86$dir = $music_dir.$current_dir;
87$url = $music_dir_url.$current_dir;
88$parent_dir = dirname($current_dir);
89
90//FCs
91function serve_download($filename) {
92 header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
93 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
94 header('Pragma: no-cache');
95
96 //header('Content-Type: application/force-download');
97 header('Content-Type: audio/x-mpegurl');
98 header("Content-Disposition: attachment; filename={$filename}");
99 header('Content-Transfer-Encoding: binary');
100
101 header('X-PHP-Application: Harvie\'s JuKe!Box');
102}
103
1c6591f3
H
104$nchars_f = array('Á','Ä','Č','Ç','Ď','É','Ě','Ë','Í','Ň','Ó','Ö','Ř','Š','Ť','Ú','Ů','Ü','Ý','Ž','á','ä','č','ç','ď','é','ě','ë','í','ň','ó','ö','ř','š','ť','ú','ů','ü','ý','ž');
105$nchars_t = array('A','A','C','C','D','E','E','E','I','N','O','O','R','S','T','U','U','U','Y','Z','a','a','c','c','d','e','e','e','i','n','o','o','r','s','t','u','u','u','y','z');
106
107function unational($text) {
108 if(!$GLOBALS['national_characters']) return $text;
109 return(str_replace($GLOBALS['nchars_f'], $GLOBALS['nchars_t'], $text));
110}
111
112function generate_m3u($dir, $prefix='', $recursive=0, $nl="\r\n", $doubleenc=0) {
ca88871f 113 $dir = $dir . '/';
1c6591f3
H
114 if(isset($_GET['newline'])) $nl = $_GET['newline'];
115 if(!isset($_GET['search'])) {
116 $dd = opendir($dir);
117 while(($item = readdir($dd)) != false) {
118 if($item == '.' || $item == '..') continue;
119 if( is_file($dir.$item) && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item) ) {
120 if($GLOBALS['sort'] > 0) {
121 $temp[] = $item;
122 } else {
123 $item=($prefix.'/'.str_replace('%2F', '/', (rawurlencode($dir.$item))).$nl);
124 if($doubleenc) $item = rawurlencode($item);
125 echo($item);
126 }
127 }
128 if($recursive && is_dir($dir.$item)) {
129 generate_m3u($dir.$item, $prefix, $recursive, $nl, $doubleenc);
130 }
131 }
132 } else {
133 if(!($searchfp = fopen($GLOBALS['search_cache'], 'r')))
134 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
135 while(!feof($searchfp)) {
136 $line = trim(fgets($searchfp));
137 if(@eregi(str_replace(' ', '(.*)', unational($_GET['search'])), unational($line))) {
138 $line=(dirname($GLOBALS['music_dir_url']).'/'.str_replace('%2F', '/', (rawurlencode($line))).$nl);
139 if($doubleenc) $line = rawurlencode($line);
140 echo($line);
ca88871f
H
141 }
142 }
ca88871f 143 }
1c6591f3 144
ca88871f
H
145 if($GLOBALS['sort'] > 0) {
146 @sort($temp);
1c6591f3
H
147 foreach($temp as $item) {
148 $temp=($prefix.'/'.str_replace('%2F', '/', (rawurlencode($dir.$item))).$nl);
149 if($doubleenc) $temp = rawurlencode($temp);
150 echo($temp);
151 }
ca88871f
H
152 }
153}
154
155function write_search_cache($dir, $outfp) {
156 $dir = $dir . '/';
157 $dd = opendir($dir);
158 while($item = readdir($dd)) {
159 if($item == '.' || $item == '..') continue;
160 if( is_file($dir.$item) && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item) ) {
161 fwrite($outfp, $dir.$item."\n");
162 }
163 if(is_dir($dir.$item)) {
164 write_search_cache($dir.$item, $outfp);
165 }
166 }
167}
168
169function generate_search_cache($dir, $outfile) {
170 echo("Generating search cache. Please wait...<br />\n"); flush();
171 @chmod($outfile, 0755); //At least i tryed ;D
172 if(!($outfp = fopen($outfile, 'w')))
173 die("Cannot write cache to $outfile<br />You probably haven't set the permissions properly!<br />\n");
174 write_search_cache($dir, $outfp);
175 fclose($outfp);
176 $osize = filesize($outfile); clearstatcache();
177 if($GLOBALS['sort'] > 2) {
178 echo("Sorting search cache. Please wait...<br />\n"); flush();
179
180 $items = file($outfile); @sort($items);
181 $total = ' ('.sizeof($items).' files)';
182 file_put_contents($outfile, @implode('', $items));
183 unset($items);
184 if(abs(filesize($outfile)-$osize) > 2)
185 die('ERROR! Please disable sorting of search cache ($sort < 3)<br />'."\nSorted only ".
186 filesize($outfile).' of '.$osize.' bytes!!!\n');
187 }
188 echo('Total: '.filesize($outfile).' of '.$osize.' bytes'.$total.' <a href="?">DONE!</a>'.'<br /><META http-equiv="refresh" content="2;URL=?">'."\n");
189}
190
191function render_file_line($dir, $item, $dir_url, $index, $filesize, $parent = false) {
1c6591f3 192 $parclass=($index%2?'even':'odd'); $parcolor=($index%2?'lightblue':'white');
ca88871f
H
193 $temp=str_replace('&', '%26', dirname($dir_url)).'/'.str_replace('%2F', '/', (rawurlencode($dir.$item)));
194 if(is_numeric($filesize)) $filesize = round($filesize/(1024*1024), 2);
1c6591f3
H
195 echo("<tr class=\"$parclass\" bgcolor=\"$parcolor\">".'<td><a href="#up">'.$index.'</a></td><td class="btntd">');
196 echo('<a href="?download&song='.rawurlencode($temp).'" class="icon iplay">P</a>');
ca88871f
H
197 if($parent) {
198 echo('/<a href="?dir='.
199 substr(str_replace(array('&','%2F'), array('%26','/'), (rawurlencode(dirname($dir.$item)))), strlen($GLOBALS['music_dir'])).
1c6591f3 200 '" class="icon ifolder">D</a>');
ca88871f 201 }
1c6591f3
H
202 if($GLOBALS['useflash'] && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item)) {
203 echo('/<a href="?f&song='.rawurlencode($temp).
204 '" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>/'.
205 '<a href="?blank" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifstop">S</a>');
ca88871f 206 }
e6edcf42
H
207 echo('&nbsp;</td><td class="maximize-width"><a href="'.$temp.'">'.unxss(str_replace('-',' - ',str_replace('_', ' ', $item))).
208 '</a></td><td>'.$filesize."&nbsp;MiB&nbsp;</td></tr>\n");
1c6591f3
H
209}
210
4e7a2682
H
211function render_dir_line($current_dir, $item, $i) {
212 $parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
aa3a0f32
H
213 $temp=str_replace('%2F', '/', rawurlencode($current_dir)).rawurlencode($item);
214 echo("<tr class=\"$parclass directory\" bgcolor=\"$parcolor\">".
215 '<td><a href="#up">'.$i.'</a></td><td class="btntd"><a href="?download&playlist&dir='.$temp.'" class="icon iplay">P</a>/'.
216 '<a href="?download&recursive&playlist&dir='.$temp.'" class="icon irplay">R</a>');
217 if($GLOBALS['useflash']) echo('/<a href="?f&playlist&dir='.$temp.'" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>');
e6edcf42 218 echo('</td><td colspan="100%" class="maximize-width"><span class="icon ifolder">[DIR] </span><a href="?dir='.$temp.'">'.unxss(str_replace('-',' - ',str_replace('_', ' ', $item))).
aa3a0f32
H
219 "</a></td></tr>\n");
220}
221
1c6591f3
H
222function render_tr_playframe_show() {
223 if($GLOBALS['flash_player_frame'] == 'playframe-show' && $GLOBALS['useflash']) { ?>
224<tr id="playframe-tr">
3df60b68 225<td><a href="?blank" target="playframe-show" title="Stop playback" class="icon ifstop">S</a></td>
ace351a9 226<td colspan="100%" class="noradius nomarpad">
1c6591f3
H
227<iframe
228src="?blank"
229name="playframe-show"
ace351a9 230class="noradius nomarpad"
1c6591f3
H
231width="100%"
232height="24"
3df60b68 233style="border:none;"
1c6591f3
H
234transparentpagebg="yes"
235></iframe></td></tr>
236 <?php }
237}
238
239function render_footer() {
240 $quotes = array(
241 'This is NOT advertisments. This is just good text to think about... Remove it if you want!',
242 'Downloading without sharing and other forms of leeching equals STEALING! ;P',
243 'Do NOT support Microsoft!!! Use Linux! ;D',
244 'Don\'t steal! Steal and share!!! ;P',
245 'Linux is not matter of price, it\'s matter of freedom!',
246 'This software brought to you by <a href="http://blog.Harvie.cz">Harvie</a> free of charge! Of course...',
247 'Don\'t be looser, use GNU/Linux! ;P',
248 'Make love and not war!',
249 'Take your chance! Prove yourself!',
c081f974
H
250 'This software is free of charge. If you wan\'t to donate, please send some money to children in Africa/etc...',
251 'Fork <a href="http://github.com/harvie/jukebox">'.$GLOBALS['title'].'</a> on GIThub :-)<a href="http://github.com/harvie/jukebox"><img style="position: absolute; top: 0; left: 0; border: 0; height:120px; background-color:transparent;" src="http://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub" /></a>'
1c6591f3
H
252 );
253
254 echo('<span id="quote" style="float: left;"><i><small>'.$quotes[rand(0,sizeof($quotes)-1)]."</small></i></span>\n");
255 echo('<span id="exectime" style="float: right;"><small>Page was generated in '.(round(microtime(true), 3) - $GLOBALS['exec_time']).'
256seconds</small></span>');
257 @readfile($GLOBALS['footer_file']);
258 echo('</body></html>');
ca88871f
H
259}
260
261function unxss($string) {
1c6591f3
H
262 return htmlspecialchars($string);
263}
264
265function explode_path($dir) {
266 $dir = substr($dir, strlen($GLOBALS['music_dir'])+1);
267 $temp = split('/', ereg_replace('/+', '/', $dir));
268 $out = '';
269 for($j=sizeof($temp)-1;$j>0;$j--) {
270 $dir = '';
271 for($i=0;$i<(sizeof($temp)-$j);$i++) {
272 $dir.=$temp[$i].'/';
273 }
274 $out.='<a href="?dir='.rawurlencode($dir).'">'.unxss($temp[$i-1]).'</a>/';
275 }
276 return('<a href="?">.</a>/'.$out);
277}
278
279function flash_mp3_player() {
280 ?>
281<html><head><title><?=$GLOBALS['title']?>: Flash Music Player Plugin</title>
282<style> * { margin: 0; padding: 0; border: 0; } </style></head><body>
283<object width="100%" height="344">
284 <embed src="<?php
0e21eaf8 285 echo($GLOBALS['base_url'].$GLOBALS['flash_player_swf'].$GLOBALS['flash_player_options']);
1c6591f3
H
286 if(isset($_GET['song'])) echo(rawurlencode($_GET['song']));
287 if(isset($_GET['playlist'])) generate_m3u($GLOBALS['dir'], dirname($GLOBALS['music_dir_url']), isset($_GET['recursive']), ',', true);
288 ?>"
289 type="application/x-shockwave-flash"
290 allowscriptaccess="never"
291 allowfullscreen="true"
292 transparentpagebg="yes"
293 quality="low"
294 width="100%" height="24px"
c76d3a73 295 ><!-- You need Adobe Flash enabled browser to play records directly in website. --></embed>
1c6591f3
H
296</object></body></html>
297<?php die();
ca88871f
H
298}
299
300//GET
6cded674 301if(isset($_GET['dj'])) { ?><title><?php echo "DJ MODE @ $title"; ?></title><frameset cols="*,*"><frame name="dj-left" src="./"><frame name="dj-right" src="./"></frameset><?php die(); }
ca88871f 302if(isset($_GET['download'])) serve_download($playlist_name);
1c6591f3
H
303if(isset($_GET['f'])) flash_mp3_player();
304if(isset($_GET['song'])) {
305 die($_GET['song']."\r\n");
306}
307
308
ca88871f 309
d1c6fd3d 310if(isset($_POST['cache-refresh']) && $_POST['cache-refresh'] == $cache_passwd) {
ca88871f
H
311 generate_search_cache($music_dir, $search_cache);
312 die("\n");
313}
314
d1c6fd3d 315
ca88871f 316if(isset($_GET['playlist'])) {
1c6591f3
H
317 generate_m3u($dir, dirname($music_dir_url), isset($_GET['recursive']));
318 die();
ca88871f
H
319}
320
321if(isset($_GET['random'])) {
322 $flen = 0;
323 if(!($searchfp = fopen($search_cache, 'r')))
324 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
325 while(!feof($searchfp)) { fgets($searchfp); $flen++; }
326 for($i=0; $i<$_GET['random']; $i++) {
327 rewind($searchfp);
328 for($j=0; $j<rand(0, $flen-1); $j++) fgets($searchfp);
329 echo(dirname($music_dir_url).'/'.str_replace('%2F', '/', (rawurlencode(trim(fgets($searchfp)))))."\r\n");
330 }
1c6591f3
H
331 die();
332}
333
334if(isset($_GET['blank'])) {
335 ?>
336 <link rel="stylesheet" type="text/css" href="<?=$css_file?>" />
c76d3a73 337 <body class="blank"><div class="blank" title="Currently you will need FlashPlayer to get this working..."><b>Music player</b> <small><i>(click 'F' link next to the song name to start, 'S' to stop...)</i></small></div></body>
1c6591f3 338 <?php die();
ca88871f
H
339}
340
341?>
4df85024 342<!DOCTYPE html>
1c6591f3
H
343<meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>" />
344<html>
345 <head>
4df85024 346 <meta charset="<?=$charset?>" />
1c6591f3
H
347 <link rel="stylesheet" type="text/css" href="<?=$css_file?>" />
348 <link rel="shortcut icon" href="<?=$favicon_file?>" />
349 <link href="<?=$favicon_file?>" rel="icon" type="image/gif" />
350 </head>
351 <body>
ca88871f 352
00f09b5d 353<div align="right" style="position: absolute; top: 5px; right: 5px;">
1c6591f3 354 <a name="up"></a>
a74cdde6 355 <iframe src="about:blank" name="playframe-hide" width="0" height="0" style="border: none;" class="hide"></iframe><!-- -----------???--------------- -->
1c6591f3 356 <span class="icon">&lt;</span> <a href="javascript: history.go(-1)" class="icon iback">BACK</a>
6cded674 357 | <a href="?" target="_parent" class="icon ihome">HOME&nbsp;(<?=$music_dir?>)</a>
5cf5c6eb 358 | <a href="?dj" class="icon idjmode">DJ</a>
1c6591f3
H
359 | <a href="?help" class="icon ihelp">ABOUT/HELP</a>
360 | <a href="?logout" class="icon ilogout">LOGOUT</a>
ca88871f
H
361</div>
362
363<?php
364if(isset($_GET['help'])) {
365 ?><h1>About/Help</h1><?php
366 readfile($bonus_dir.'/help.html');
367 die();
368}
369
1c6591f3 370
ca88871f 371if(!isset($_GET['search'])) {
1c6591f3
H
372 echo('<title>'.$title.': '.unxss($dir).'</title>');
373 echo('<a href="?" style="color: black;"><h1 style="float: left;">'.$title.'</h1></a><h2 style="clear: left; display: inline; float: left;">Index of: '.explode_path($dir).'</h2>');
ca88871f
H
374} else {
375 echo('<title>'.$title.': '.unxss($_GET['search']).'</title>');
1c6591f3 376 echo('<a href="?" style="color: black;"><h1 style="float: left;">'.$title.'</h1></a><h2 style="clear: left; display: inline; float: left;">Searching for: '.unxss($_GET['search']).'</h2>');
ca88871f
H
377
378?>
379
1c6591f3
H
380<?php
381}
382
383?>
384<span style="float: right;">
ca88871f
H
385 <form action="?" method="GET" align="right" style="display: inline;">
386 <input type="hidden" name="download" value="" />
a6ec3d5f
H
387 <input type="number" min="1" name="random" value="<?=$default_random_count?>" style="width:4em;" title="how many randomly selected tracks should be in
388playlist?"
389/>
ca88871f
H
390 <input type="submit" value="random" title="Generate random music playlist..." />
391 </form>
392 <form action="?" method="GET" align="right" style="display: inline;">
c40ae8c7 393 <span class="icon isearch"></span><input type="search" name="search" autofocus placeholder="search regexp..."
ca88871f
H
394 title="Search in music/google/lyrics/mp3/youtube; Hint: You can use regular expressions in search query..."
395 value="<?=unxss($_GET['search'])?>"
396 />
397 <input type="submit" value="search" title="Search in this JuKe!Box..." />
398 </form>
1c6591f3 399</span><?php
ca88871f 400
1c6591f3
H
401if(!isset($_GET['search'])) {
402 echo('<br style="clear: both;" />');
403} else {
ca88871f 404
1c6591f3
H
405?>
406<span style="float: right;">
ca88871f 407 <form action="?" method="POST" align="right">
a6ec3d5f 408 <input type="password" name="cache-refresh" value="" style="width:5em;" title="Password for refreshing - good for avoiding DoS Attacks!!!" />
ca88871f 409 <input type="submit" value="refresh cache" title="You should refresh cache each time when you add new music or upgrade to newer version of JuKe!Box !!!" />
1c6591f3 410 &nbsp;
ca88871f 411 </form>
1c6591f3
H
412</span>
413<div align="right" style="clear: right;" title="Aditional search engines...">
414<br />
415<?php
416 $search_prefix = 0;
417 foreach($search_engines as $search_desc => $search_link) {
418 if(!$search_prefix) {
419 echo(unxss($_GET['search'])." @\n");
420 $search_prefix = 1;
421 }
422 echo('<a href="'.$search_link.rawurlencode($_GET['search']).'">'.$search_desc."</a>;\n");
423 }
424?>
425</div><br style="clear: both;" />
426<?php
427echo('<small>Search DB size: '.(filesize($search_cache)/1024)." kB<br /></small>\n");
ca88871f
H
428
429if(!($searchfp = fopen($search_cache, 'r')))
430 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
431
432$i = 0;
433echo('<table border="1" width="100%">');
1c6591f3 434render_tr_playframe_show();
37c84adf
H
435echo('<tr class="directory"><td>S</td><td><a href="?download&playlist&search='.unxss($_GET['search']).'" class="icon iplay">P</a>');
436if($GLOBALS['useflash']) echo('/<a href="?f&playlist&search='.unxss($_GET['search']).'" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>');
1c6591f3
H
437echo('</td><td colspan="100%">Search: '.unxss($_GET['search']).'</td></tr>');
438
ca88871f
H
439while(!feof($searchfp)) {
440 $line = trim(fgets($searchfp));
1c6591f3
H
441 $parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
442 if(@eregi(str_replace(' ', '(.*)', unational($_GET['search'])), unational($line))) {
ca88871f 443 $i++;
ca88871f
H
444 $filesize = 0; if($i <= $access_limit) $filesize = filesize($line); else $filesize = 'n/a';
445 render_file_line('', $line, $music_dir_url, $i, $filesize, true);
ca88871f
H
446 }
447}
1c6591f3
H
448echo('<tr><td colspan="100%">Total: '.$i.' results...</td></tr></table>');
449render_footer(); die();
ca88871f
H
450
451}
452@readfile($header_file);
453foreach($indexlist as $index) @readfile($dir.$index);
454?>
455<br />
456<table border="1" width="100%">
1c6591f3
H
457<?php render_tr_playframe_show(); ?>
458
459<tr class="directory"><td>&gt;</td>
a74cdde6
H
460<td><a href="?download&playlist&dir=<?=str_replace('%2F', '/', rawurlencode($current_dir))?>" class="icon iplay">P</a>/<a
461href="?download&recursive&playlist&dir=<?=str_replace('%2F', '/', rawurlencode($current_dir))?>" class="icon irplay">R</a><?php
462if($GLOBALS['useflash']) echo('/<a href="?f&playlist&dir='.str_replace('%2F', '/', rawurlencode($current_dir)).'" target="'.$GLOBALS['flash_player_frame'].'"
463class="icon ifplay">F</a>'); ?>
1c6591f3
H
464</td>
465<td colspan="100%"><?=unxss($dir)?></td></tr>
2721a24c
H
466<tr><td>^</td><td>&nbsp;</td><td colspan="100%" class="directory"><span class="icon ifolder">[DIR] </span><a href="?dir=<?=rawurlencode($parent_dir)?>">..
467(<?=$parent_dir?>)</a></td></tr>
ca88871f
H
468<?php
469
470$i = 0;
471$dd = opendir($dir);
472for($s=2;$s;$s--) { while(($item = readdir($dd)) != false) {
473 if($item == '.' || $item == '..') continue;
474 if(($s==2 && is_file($dir.$item)) || ($s!=2 && is_dir($dir.$item))) continue;
475 $i++;
aa3a0f32
H
476 //$parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
477 if($sort > 1) {
ca88871f 478 if(is_file($dir.$item)) {
aa3a0f32
H
479 $i--;
480 $itemsf[] = $item;
ca88871f
H
481 }
482 if(is_dir($dir.$item)) {
aa3a0f32
H
483 $i--;
484 $itemsd[] = $item;
485 }
486 } else {
487 if(is_file($dir.$item)) {
488 render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
ca88871f 489 }
aa3a0f32 490 if(is_dir($dir.$item)) {
4e7a2682 491 render_dir_line($current_dir, $item, $i);
aa3a0f32
H
492 }
493 }
ca88871f 494} rewinddir($dd); }
aa3a0f32 495
ca88871f 496if($sort > 1) {
aa3a0f32
H
497 @sort($itemsf);
498 @sort($itemsd);
499 foreach($itemsd as $item) {
500 $i++;
4e7a2682 501 render_dir_line($current_dir, $item, $i);
aa3a0f32
H
502 }
503 foreach($itemsf as $item) {
ca88871f
H
504 $i++;
505 render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
506 }
507}
508
509?></table>
510
511<?php
1c6591f3 512render_footer();
This page took 0.735424 seconds and 4 git commands to generate.