Create FUNDING.yml
[mirrors/JukeBox.git] / index.php
index 1e7a509fa8c4fa30e04a1a5e3d30cbfb30022774..704dc91d92c588a45f082f101863df8992807c04 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -1,8 +1,9 @@
 <?php require_once('./http_auth.php'); /*Delete this line to disable password protection*/ ?>
 <?php $exec_time = round(microtime(true), 3); /*
-Harvie's JuKe!Box
+Harvie's JuKe!Box (2oo7-2o1o)
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 Version info:
+ * 0.3.6 - Now sorting also directories and have icon link support in css
  * 0.3.5 - Fixed security bug - directory traversal in filelisting (upgrade recommended)
  * 0.3.4 - Generating playlist for flashplayer, searching for bugs, cleaning code and preparing for new version release
  * 0.3.3 - Shorter URLs for flashplayer (due to discussion at #skola ;o), nicer national characters handling
@@ -11,15 +12,16 @@ Version info:
  * 0.3   - Migrated to standalone WPAudioPlayer (better, nicer, with more functions)
  * 0.2   - Few new functions (search playlist, random,...)
  * 0.1.1 - Few little fixups, written help.html in Czech language ;o)
- * 0.1   - All functions works - TODO: bugfix & replace ugly code
+ * 0.1   - All functions are working - TODO: bugfix & replace ugly code
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 */
 
 //Config-basic
 $title =               'Harvie\'s&nbsp;JuKe!Box'; //Title of jukebox
-$music_dir =           './music'; //Local path to directory with music
+$music_dir =           'music'; //Local path to directory with music
+$base_url =            preg_replace('/[^\/]*$/', '', $_SERVER['SCRIPT_NAME']); //URL of this directory (always ends with slash)
 $music_dir_url =       'http://your-server.net/jukebox/music'; //URL path to the same directory
-$cache_passwd =        'renew123'; //You need this passwd to refresh search cache
+$cache_passwd =        ''; //You need this passwd to refresh search cache
 $sort =                        3; //Sort? 0 = none, 1 = playlists, 2 = 1+listings; 3 = 2+search-EXPERIMENTAL! (sorting could eat lot of memory)
 $access_limit =                40; //How many files could be accessed without using cache (while searching)
 
@@ -34,11 +36,11 @@ $default_random_count =     30; //How many random songs by defaul?
 
 //External files
 $indexlist =           array('index.html', 'index.txt'); //Search for this file in each directory
-$bonus_dir =           './jbx'; //Misc. files directory
+$bonus_dir =           'jbx'; //Misc. files directory
 ////
 $search_cache =        $bonus_dir.'/cache.db'; //Database for searching music (php +rw) - .htaccess: Deny from all!!!
-$css_file =            $bonus_dir.'/themes/default/jukebox.css'; //CSS (Design)
-$favicon_file =                './favicon.png'; //favicon
+$css_file =            $base_url.$bonus_dir.'/themes/default/jukebox.css'; //CSS (Design)
+$favicon_file =                $base_url.'favicon.png'; //favicon
 $header_file =         $bonus_dir.'/header.html'; //header file
 $footer_file =         $bonus_dir.'/footer.html'; //footer file
 
@@ -56,7 +58,7 @@ $search_engines = array(
 $flash_player_swf =    $bonus_dir.'/player.swf'; //path to musicplayer
 $flash_player_frame =  'playframe-show'; //FlashPlayer Target (playframe-show|playframe-hide) - usefull for compatibility with old music player
 $flash_player_options = '?bg=000099&loader=000000&tracker=AAAAFF&skip=FFFFFF' //.'&leftbg=000077&rightbg=000077&righticon=999999'
-                        .'&autostart=yes&initialvolume=100&soundFile='; //& arguments (urlencoded song url will be added)
+                        .'&autostart=yes&initialvolume=100&buffer=30&animation=no&soundFile='; //& arguments (urlencoded song url will be added)
 
 //Security
 error_reporting(0); //This will disable error reporting, wich can pass sensitive data to users
@@ -75,6 +77,7 @@ if(get_magic_quotes_gpc()) die("Error: magic_quotes_gpc needs to be disabled!\n"
 $useflash = is_file($flash_player_swf);
 
 //Little magic with directories ;o)
+if($_SERVER['PATH_INFO']!='') $_GET['dir']=$_SERVER['PATH_INFO'];
 $current_dir = ereg_replace('/+', '/', '/'.$_GET['dir'].'/');
 if(eregi('(/|\\\\)\\.\\.(/|\\\\)', $current_dir)) { //check for directory traversal ;)
        header('Location: ?');
@@ -201,20 +204,33 @@ function render_file_line($dir, $item, $dir_url, $index, $filesize, $parent = fa
                        '" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>/'.
                        '<a href="?blank" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifstop">S</a>');
        }
-       echo('&nbsp;</td><td><a href="'.$temp.'">'.unxss(str_replace('_', ' ', $item)).'</a></td><td>'.$filesize."&nbsp;MiB&nbsp;</td></tr>\n");                        
+       echo('&nbsp;</td><td class="maximize-width"><a href="'.$temp.'">'.unxss(str_replace('-',' - ',str_replace('_', ' ', $item))).
+       '</a></td><td>'.$filesize."&nbsp;MiB&nbsp;</td></tr>\n");
+}
+
+function render_dir_line($current_dir, $item, $i) {
+       $parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
+       $temp=str_replace('%2F', '/', rawurlencode($current_dir)).rawurlencode($item);
+       echo("<tr class=\"$parclass directory\" bgcolor=\"$parcolor\">".
+       '<td><a href="#up">'.$i.'</a></td><td class="btntd"><a href="?download&playlist&dir='.$temp.'" class="icon iplay">P</a>/'.
+       '<a href="?download&recursive&playlist&dir='.$temp.'" class="icon irplay">R</a>');
+       if($GLOBALS['useflash']) echo('/<a href="?f&playlist&dir='.$temp.'" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>');
+       echo('</td><td colspan="100%" class="maximize-width"><span class="icon ifolder">[DIR] </span><a href="?dir='.$temp.'">'.unxss(str_replace('-',' - ',str_replace('_', ' ', $item))).
+       "</a></td></tr>\n");
 }
 
 function render_tr_playframe_show() {
        if($GLOBALS['flash_player_frame'] == 'playframe-show' && $GLOBALS['useflash']) { ?>
 <tr id="playframe-tr">
-<td><a href="?blank" target="playframe-show" title="Stop playback">S</a></td>
-<td colspan="100%">
+<td><a href="?blank" target="playframe-show" title="Stop playback" class="icon ifstop">S</a></td>
+<td colspan="100%" class="noradius nomarpad">
 <iframe
 src="?blank"
 name="playframe-show"
+class="noradius nomarpad"
 width="100%"
 height="24"
-style="border: none;"
+style="border:none;"
 transparentpagebg="yes"
 ></iframe></td></tr>
        <?php }
@@ -231,7 +247,8 @@ function render_footer() {
                'Don\'t be looser, use GNU/Linux! ;P',
                'Make love and not war!',
                'Take your chance! Prove yourself!',
-               'This software is free of charge. If you wan\'t to donate, please send some money to children in Africa/etc...'
+               'This software is free of charge. If you wan\'t to donate, please send some money to children in Africa/etc...',
+               '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>'
        );
 
        echo('<span id="quote" style="float: left;"><i><small>'.$quotes[rand(0,sizeof($quotes)-1)]."</small></i></span>\n");
@@ -265,7 +282,7 @@ function flash_mp3_player() {
 <style> * { margin: 0; padding: 0; border: 0; } </style></head><body>
 <object width="100%" height="344">
         <embed src="<?php
-               echo($GLOBALS['flash_player_swf'].$GLOBALS['flash_player_options']);
+               echo($GLOBALS['base_url'].$GLOBALS['flash_player_swf'].$GLOBALS['flash_player_options']);
                if(isset($_GET['song'])) echo(rawurlencode($_GET['song']));
                if(isset($_GET['playlist'])) generate_m3u($GLOBALS['dir'], dirname($GLOBALS['music_dir_url']), isset($_GET['recursive']), ',', true);
        ?>"
@@ -275,12 +292,13 @@ function flash_mp3_player() {
                 transparentpagebg="yes" 
                 quality="low"
                 width="100%" height="24px"                
-        >You need Adobe Flash enabled browser to play records directly in website.</embed>
+        ><!-- You need Adobe Flash enabled browser to play records directly in website. --></embed>
 </object></body></html>
 <?php die();
 }
 
 //GET
+if(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(); }
 if(isset($_GET['download'])) serve_download($playlist_name);
 if(isset($_GET['f'])) flash_mp3_player();
 if(isset($_GET['song'])) {
@@ -289,11 +307,12 @@ if(isset($_GET['song'])) {
 
 
 
-if($_POST['cache-refresh'] == $cache_passwd) {
+if(isset($_POST['cache-refresh']) && $_POST['cache-refresh'] == $cache_passwd) {
        generate_search_cache($music_dir, $search_cache);
        die("\n");
 }
 
+
 if(isset($_GET['playlist'])) {
        generate_m3u($dir, dirname($music_dir_url), isset($_GET['recursive']));
        die();
@@ -315,26 +334,28 @@ if(isset($_GET['random'])) {
 if(isset($_GET['blank'])) {
        ?>
        <link rel="stylesheet" type="text/css" href="<?=$css_file?>" />
-       <body class="blank"><div class="blank"><b>Music player</b> <small><i>(click 'F' link next to the song name to start, 'S' to stop...)</i></small></div></body>
+       <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>
        <?php die();
 }
 
 ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html>
 <meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>" />
 <html>
        <head>
+               <meta charset="<?=$charset?>" />
                <link rel="stylesheet" type="text/css" href="<?=$css_file?>" />
                <link rel="shortcut icon" href="<?=$favicon_file?>" />
                <link href="<?=$favicon_file?>" rel="icon" type="image/gif" />
        </head>
        <body>
 
-<div align="right" style="position: absolute; top: 5px; right: 0px;">
+<div align="right" style="position: absolute; top: 5px; right: 5px;">
        <a name="up"></a>
        <iframe src="about:blank" name="playframe-hide" width="0" height="0" style="border: none;" class="hide"></iframe><!-- -----------???--------------- -->
        <span class="icon">&lt;</span> <a href="javascript: history.go(-1)" class="icon iback">BACK</a>
-       | <a href="?"><span class="icon ihome">HOME</span> (<?=$music_dir?>)</a>
+       | <a href="?" target="_parent" class="icon ihome">HOME&nbsp;(<?=$music_dir?>)</a>
+       | <a href="?dj" class="icon idjmode">DJ</a>
        | <a href="?help" class="icon ihelp">ABOUT/HELP</a>
        | <a href="?logout" class="icon ilogout">LOGOUT</a>
 </div>
@@ -363,11 +384,13 @@ if(!isset($_GET['search'])) {
 <span style="float: right;">
        <form action="?" method="GET" align="right" style="display: inline;">
                <input type="hidden" name="download" value="" />
-               <input type="number" name="random" value="<?=$default_random_count?>" />
+               <input type="number" min="1" name="random" value="<?=$default_random_count?>" style="width:4em;" title="how many randomly selected tracks should be in 
+playlist?" 
+/>
                <input type="submit" value="random" title="Generate random music playlist..." />
        </form>
        <form action="?" method="GET" align="right" style="display: inline;">
-               <input type="search" name="search" autofocus placeholder="search regexp..."
+               <span class="icon isearch"></span><input type="search" name="search" autofocus placeholder="search regexp..."
                        title="Search in music/google/lyrics/mp3/youtube; Hint: You can use regular expressions in search query..."
                        value="<?=unxss($_GET['search'])?>"
                />
@@ -382,7 +405,7 @@ if(!isset($_GET['search'])) {
 ?>
 <span style="float: right;">
        <form action="?" method="POST" align="right">
-               <input type="password" name="cache-refresh" value="" title="Password for refreshing - good for avoiding DoS Attacks!!!" />
+               <input type="password" name="cache-refresh" value="" style="width:5em;" title="Password for refreshing - good for avoiding DoS Attacks!!!" />
                <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 !!!" />
        &nbsp;
        </form>
@@ -409,8 +432,8 @@ if(!($searchfp = fopen($search_cache, 'r')))
 $i = 0;
 echo('<table border="1" width="100%">');
 render_tr_playframe_show();
-echo('<tr><td>S</td><td><a href="?download&playlist&search='.unxss($_GET['search']).'">P</a>');
-if($GLOBALS['useflash']) echo('/<a href="?f&playlist&search='.unxss($_GET['search']).'" target="'.$GLOBALS['flash_player_frame'].'">F</a>');
+echo('<tr class="directory"><td>S</td><td><a href="?download&playlist&search='.unxss($_GET['search']).'" class="icon iplay">P</a>');
+if($GLOBALS['useflash']) echo('/<a href="?f&playlist&search='.unxss($_GET['search']).'" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>');
 echo('</td><td colspan="100%">Search: '.unxss($_GET['search']).'</td></tr>');
 
 while(!feof($searchfp)) {
@@ -440,7 +463,8 @@ if($GLOBALS['useflash']) echo('/<a href="?f&playlist&dir='.str_replace('%2F', '/
 class="icon ifplay">F</a>'); ?>
 </td>
 <td colspan="100%"><?=unxss($dir)?></td></tr>
-<tr><td>^</td><td>&nbsp;</td><td colspan="100%" class="directory"><span class="icon ifolder">[DIR]</span> <a href="?dir=<?=rawurlencode($parent_dir)?>">.. (<?=$parent_dir?>)</a></td></tr>
+<tr><td>^</td><td>&nbsp;</td><td colspan="100%" class="directory"><span class="icon ifolder">[DIR] </span><a href="?dir=<?=rawurlencode($parent_dir)?>">.. 
+(<?=$parent_dir?>)</a></td></tr>
 <?php
 
 $i = 0;
@@ -449,27 +473,34 @@ for($s=2;$s;$s--) { while(($item = readdir($dd)) != false) {
        if($item == '.' || $item == '..') continue;
        if(($s==2 && is_file($dir.$item)) || ($s!=2 && is_dir($dir.$item))) continue;
        $i++;
-       $parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
+       //$parclass=($i%2?'even':'odd'); $parcolor=($i%2?'lightblue':'white');
+       if($sort > 1) {
                if(is_file($dir.$item)) {
-                       if($sort > 1) {
-                               $i--;
-                               $items[] = $item;
-                       } else {
-                               render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
-                       }
+                       $i--;
+                       $itemsf[] = $item;
                }
                if(is_dir($dir.$item)) {
-                       $temp=str_replace('%2F', '/', rawurlencode($current_dir)).rawurlencode($item);
-                       echo("<tr class=\"$parclass directory\" bgcolor=\"$parcolor\">".
-                       '<td><a href="#up">'.$i.'</a></td><td class="btntd"><a href="?download&playlist&dir='.$temp.'" class="icon iplay">P</a>/'.
-                       '<a href="?download&recursive&playlist&dir='.$temp.'" class="icon irplay">R</a>');
-                       if($GLOBALS['useflash']) echo('/<a href="?f&playlist&dir='.$temp.'" target="'.$GLOBALS['flash_player_frame'].'" class="icon ifplay">F</a>');
-                       echo('</td><td colspan="100%"><span class="icon ifolder">[DIR]</span> <a href="?dir='.$temp.'">'.unxss(str_replace('_', ' ', $item))."</a></td></tr>\n");
+                       $i--;
+                       $itemsd[] = $item;
                }
+       } else {
+               if(is_file($dir.$item)) {
+                       render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
+               }
+               if(is_dir($dir.$item)) {
+                       render_dir_line($current_dir, $item, $i);
+               }
+       }
 } rewinddir($dd); }
+
 if($sort > 1) {
-       @sort($items);
-       foreach($items as $item) {
+       @sort($itemsf);
+       @sort($itemsd);
+       foreach($itemsd as $item) {
+               $i++;
+               render_dir_line($current_dir, $item, $i);
+       }
+       foreach($itemsf as $item) {
                $i++;
                render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
        }
This page took 0.171936 seconds and 4 git commands to generate.