From 9a3fbae4fdc3688b8c62b0c1e7db7eb89ae2aeb3 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 13 May 2007 19:43:39 +0000 Subject: [PATCH] + Button at the top now lights up to let you know what mode you're at. + 'Add' and 'Play' buttons now recurse down the file tree. Be careful about hitting this button at the top level if you've got a big library! ~ Playlist now highlights currently playing track. --- config/config.inc.php | 2 +- lib/actions.php | 128 +++++++---- lib/global.php | 78 +++---- lib/page.php | 283 ++++++++++++++----------- templates/default/browse.html | 2 +- templates/default/browselist_item.html | 14 +- templates/default/index.html | 10 +- templates/default/menu.html | 6 + templates/default/playlist_item.html | 2 +- templates/default/styles.css | 22 +- 10 files changed, 328 insertions(+), 219 deletions(-) create mode 100644 templates/default/menu.html diff --git a/config/config.inc.php b/config/config.inc.php index b8eb4f9..5d4ec2b 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -14,7 +14,7 @@ $_CONFIG['template'] = 'default'; /* Browse mode can be 'filesystem' or 'metadata' */ - $_CONFIG['browse_mode'] = 'metadata'; + $_CONFIG['browse_mode'] = 'filesystem'; $_CONFIG['sort_by_tracknumber'] = true; diff --git a/lib/actions.php b/lib/actions.php index c366e24..c51ce9f 100644 --- a/lib/actions.php +++ b/lib/actions.php @@ -1,65 +1,41 @@ SkipTo($_GET['skipto']); } - + switch($_GET['action']) { case "clear": $mympd->PLClear(); break; - + case "remove": $mympd->PLRemove($_GET['id']); break; - + case "fileadd": $mympd->PLAdd($_GET['file']); break; - + case "addall": - /* create the array of files for the playlist add */ - if ($browse == '/') { - $browse = ''; - } - - $browselist = $mympd->GetDir($browse); - - foreach($browselist as $browselist_item) { - if ($browselist_item['file']) { - $addlist[] = $browselist_item['file']; - } - } - - $mympd->PLAddBulk($addlist); + addall($_COOKIE['browse']); $page = 'playlist'; setcookie('page', $page); header("Location: index.php"); break; - + case "playall": $mympd->PLClear(); - /* create the array of files for the playlist add */ - if ($browse == '/') { - $browse = ''; - } - - $browselist = $mympd->GetDir($browse); - - foreach($browselist as $browselist_item) { - if ($browselist_item['file']) { - $addlist[] = $browselist_item['file']; - } - } - - $mympd->PLAddBulk($addlist); + + addall($_COOKIE['browse']); + $page = 'control'; setcookie('page', $page); $mympd->Play(); header("Location: index.php"); break; - + case "fileplay": $mympd->PLClear(); $mympd->PLAdd($_GET['file']); @@ -68,30 +44,100 @@ $mympd->Play(); header("Location: index.php"); break; - + case "play": $mympd->Play(); header("Location: index.php"); break; - + case "stop": $mympd->Stop(); header("Location: index.php"); break; - + case "pause": $mympd->Pause(); header("Location: index.php"); break; - + case "prev": $mympd->Previous(); header("Location: index.php"); break; - + case "next": $mympd->Next(); header("Location: index.php"); break; } -?> + + function addall($browse) { + + global $_CONFIG, $mympd; + + if ($browse == '/') { + $browse = ''; + } + + switch ($_CONFIG['browse_mode']) { + + case 'filesystem': + + function get_browselist($path) { + + global $mympd; + + $browselist = $mympd->GetDir($path); + + foreach ($browselist as $browseitem) { + if ($browseitem['directory']) { + //echo $browseitem.directory; + $browselist = array_merge($browselist, get_browselist($browseitem['directory'])); + } + } + + return $browselist; + + } + + /* create the array of files for the playlist add */ + $browselist = get_browselist($browse); + + break; + + case 'metadata': + + $browse_bits = split('/', $browse); + + if (is_array($browse_bits)) { + + if ($browse_bits[1]) { + $album = $browse_bits[1]; + $browselist = $mympd->Find(MPD_SEARCH_ALBUM, $album); + } + elseif ($browse_bits[0]) { + $artist = $browse_bits[0]; + $browselist = $mympd->Find(MPD_SEARCH_ARTIST, $artist); + } + + } + else { + //$browselist = $mympd->Search(MPD_SEARCH_TITLE, ''); + } + + break; + } + + if (is_array($browselist)) { + + foreach($browselist as $browselist_item) { + if ($browselist_item['file']) { + $addlist[] = $browselist_item['file']; + } + } + + $mympd->PLAddBulk($addlist); + } + + } +?> diff --git a/lib/global.php b/lib/global.php index 03e82c5..2df1520 100644 --- a/lib/global.php +++ b/lib/global.php @@ -1,6 +1,8 @@ compile_dir = 'smarty/templates_c/'; $smarty->config_dir = 'smarty/configs/'; $smarty->cache_dir = 'smarty/cache/'; - + + $smarty->assign('version', $version); + include('lib/mpd.class.php'); $mympd = new mpd('localhost',6600); - + if (!$mympd->connected) { echo "

Problem connecting to MPD!

"; exit; - } - - /* track number sorting function */ - - function track_sort($a, $b) { - if ($a['directory'] && $b['directory']) { - if ($a['directory'] < $b['directory']) { - return -1; - } - elseif ($a['directory'] > $b['directory']) { - return 1; - } - else { - return 0; - } - } - elseif ($a['directory'] && !$b['directory']) { - return 1; - } - elseif (!$a['directory'] && $b['directory']) { - return -1; - } - else { - return $a['Track'] - $b['Track']; - } } - + + /* track number sorting function */ + + function track_sort($a, $b) { + if ($a['directory'] && $b['directory']) { + if ($a['directory'] < $b['directory']) { + return -1; + } + elseif ($a['directory'] > $b['directory']) { + return 1; + } + else { + return 0; + } + } + elseif ($a['directory'] && !$b['directory']) { + return 1; + } + elseif (!$a['directory'] && $b['directory']) { + return -1; + } + else { + return $a['Track'] - $b['Track']; + } + } + /* setup some global vars */ $smarty->assign('browse_link', 'index.php?page=browse'); $smarty->assign('playlist_link', 'index.php?page=playlist'); $smarty->assign('browselist_play_link', 'index.php?action=fileplay&file='); $smarty->assign('browselist_add_link', 'index.php?action=fileadd&file='); $smarty->assign('playlist_remove_link', 'index.php?action=remove&id='); - $smarty->assign('control_link', 'index.php?page=control'); - $smarty->assign('playlist_play_link', 'index.php?page=control&action=play&skipto='); + $smarty->assign('control_link', 'index.php?page=control'); + $smarty->assign('playlist_play_link', 'index.php?page=control&action=play&skipto='); $smarty->assign('playlist_clear_link', 'index.php?action=clear'); - /* first check for a page cookie, and default to displaying the playlist */ + /* first check for a page cookie, and default to displaying the playlist */ if ($_GET['page']) { $page = $_GET['page']; setcookie('page', $page); @@ -62,9 +66,11 @@ else { $page = $_COOKIE['page']; } - + if (!$page) { $page = 'playlist'; } - -?> + + $smarty->assign('page', $page); + +?> diff --git a/lib/page.php b/lib/page.php index 32c65b5..2ea78a2 100644 --- a/lib/page.php +++ b/lib/page.php @@ -1,178 +1,209 @@ -assign('page', $page); - - /* print_r($mympd->playlist); */ - - switch ($page) { - case "playlist": - $smarty->assign('playlist', $mympd->playlist); - break; - case "control": - /* get the currently playing track */ - $current_track = $mympd->playlist[$mympd->current_track_id]; - $smarty->assign('current_track_no', $current_track['Track']); - $smarty->assign('current_title', $current_track['Title']); - $smarty->assign('current_album', $current_track['Album']); - $smarty->assign('current_artist', $current_track['Artist']); - $smarty->assign('current_file', $current_track['file']); - break; +assign('page', $page); + + /* print_r($mympd->playlist); */ + + switch ($page) { + case "playlist": + /* + echo '
';
+			print_r($mympd->playlist);
+			echo '
'; + //*/ + + $smarty->assign('playlist', $mympd->playlist); + $smarty->assign('playing', $mympd->current_track_id); + break; + case "control": + /* get the currently playing track */ + $current_track = $mympd->playlist[$mympd->current_track_id]; + $smarty->assign('current_track_no', $current_track['Track']); + $smarty->assign('current_title', $current_track['Title']); + $smarty->assign('current_album', $current_track['Album']); + $smarty->assign('current_artist', $current_track['Artist']); + $smarty->assign('current_file', $current_track['file']); + break; case "browse": - + switch ($_CONFIG['browse_mode']) { - + case 'metadata': /* metadata based browsing. this will list artists->albums->tracks */ - + /* split the browse get var if present */ if ($_GET['browse']) { + setcookie('browse', stripslashes($_GET['browse'])); if ($_GET['browse'] == '/') { - $browse_bits[0] = 'artists'; + $meta_level = 'artists'; } else { - $browse_bits = split('::', $_GET['browse']); - } + $browse_bits = split('/', $_GET['browse']); + if ($browse_bits[0]) { + $artist = $browse_bits[0]; + $meta_level = 'albums'; + } + if ($browse_bits[1]) { + $album = $browse_bits[1]; + $meta_level = 'tracks'; + } + } } - - //print_r($browse_bits); - - /* set the meta_level */ - if ($browse_bits[0]) { - $meta_level = $browse_bits[0]; - } - elseif ($_COOKIE['meta_level']) { - $meta_level = $_COOKIE['meta_level']; + elseif ($_COOKIE['browse']) { + if ($_COOKIE['browse'] == '/') { + $meta_level = 'artists'; + } + else { + $browse_bits = split('/', $_COOKIE['browse']); + if ($browse_bits[0]) { + $artist = $browse_bits[0]; + $meta_level = 'albums'; + } + if ($browse_bits[1]) { + $album = $browse_bits[1]; + $meta_level = 'tracks'; + } + } + } else { $meta_level = 'artists'; } - + + //print_r($browse_bits); + switch ($meta_level) { /* we need to get the information differently for different meta levels */ - + case 'artists': $artists = $mympd->GetArtists(); - - foreach ($artists as $artist) { - $browselist[]['metaArtist'] = $artist; + + foreach ($artists as $the_artist) { + $browselist[] = array('metaArtist' => $the_artist, 'path' => stripslashes($the_artist)); } - + break; - + case 'albums': - $albums = $mympd->GetAlbums($browse_bits[1]); - - foreach ($albums as $album) { - $browselist[]['metaAlbum'] = $album; + $albums = $mympd->GetAlbums($artist); + + foreach ($albums as $the_album) { + $browselist[] = array('metaAlbum' => $the_album, 'path' => stripslashes($artist . '/' . $the_album)); } - + + $dir_list = array(array('name' => stripslashes($artist), 'path' => urlencode(stripslashes($artist)))); + break; - + case 'tracks': - - $tracks = $mympd->Find(MPD_SEARCH_ALBUM, $browse_bits[1]); - + + $tracks = $mympd->Find(MPD_SEARCH_ALBUM, $album); + /* echo '
';
 							print_r($tracks);
 							echo '
'; - //*/ - + //*/ + /* foreach ($albums as $album) { $browselist[]['metaAlbum'] = $album; } */ - + $browselist = $tracks; if ($_CONFIG['sort_by_tracknumber']) { usort($browselist, "track_sort"); } - + + $dir_list = array(array('name' => stripslashes($artist), 'path' => urlencode(stripslashes($artist))), array('name' => stripslashes($album), 'path' => urlencode(stripslashes($artist . '/' . $album)))); + break; } - + + $smarty->assign('dir_list', $dir_list); $smarty->assign('browselist', $browselist); - + break; - - case 'filesystem': /* filesystem based browsing. this will follow the filesystem tree */ - - /* get the browse position from the cookie or from get */ - if ($_GET['browse']) { - $browse = $_GET['browse']; - setcookie('browse', stripslashes($browse)); - } - else { - $browse = $_COOKIE['browse']; + + case 'filesystem': /* filesystem based browsing. this will follow the filesystem tree */ + + /* get the browse position from the cookie or from get */ + if ($_GET['browse']) { + $browse = $_GET['browse']; + setcookie('browse', stripslashes($browse)); } - - $browse = stripslashes($browse); - - /* make the path array */ - - if ($browse == '/') { - $browse = ''; - } - + else { + $browse = $_COOKIE['browse']; + } + + $browse = stripslashes($browse); + + /* make the path array */ + + if ($browse == '/') { + $browse = ''; + } + $browse_list = explode('/', $browse); - - //print_r($browse); - - if ($browse) { - - foreach ($browse_list as $browse_item) { - $path .= $browse_item . '/'; - $dir_list[] = array('path' => trim($path, '/'), 'name' => $browse_item); - } - - } - - $smarty->assign('dir_list', $dir_list); - - if (!$browselist) { - $browselist = $mympd->GetDir($browse); + + //print_r($browse); + + if ($browse) { + + foreach ($browse_list as $browse_item) { + $path .= $browse_item . '/'; + $dir_list[] = array('path' => urlencode(trim($path, '/')), 'name' => $browse_item); + } + } - + + $smarty->assign('dir_list', $dir_list); + + if (!$browselist) { + $browselist = $mympd->GetDir($browse); + } + if ($_CONFIG['sort_by_tracknumber']) { usort($browselist, "track_sort"); } - + /* echo '
';
 					print_r($browselist);
 					echo '
'; //*/ - - foreach ($browselist as $key => $browselist_item) { - - - if ($browselist_item['directory']) { - $lastpos = strrpos($browselist_item['directory'], '/'); - if ($lastpos !== false) { - $browselist[$key]['directory_name'] = substr($browselist_item['directory'], $lastpos + 1); - } - else { - $browselist[$key]['directory_name'] = $browselist_item['directory']; - } - } - - - /* add a token for files currently on the playlist */ - foreach($mympd->playlist as $playlist_item) { - if ($browselist_item['file'] == $playlist_item['file']) { - $browselist[$key]['in_playlist'] = "1"; - } - } - } - - + + foreach ($browselist as $key => $browselist_item) { + + + if ($browselist_item['directory']) { + $lastpos = strrpos($browselist_item['directory'], '/'); + if ($lastpos !== false) { + $browselist[$key]['directory_name'] = substr($browselist_item['directory'], $lastpos + 1); + } + else { + $browselist[$key]['directory_name'] = $browselist_item['directory']; + } + } + + + /* add a token for files currently on the playlist */ + foreach($mympd->playlist as $playlist_item) { + if ($browselist_item['file'] == $playlist_item['file']) { + $browselist[$key]['in_playlist'] = "1"; + } + } + } + + //print_r($browselist); + $smarty->assign('browselist', $browselist); - + break; - } - - //echo '
';			
-			//print_r($mympd->GetDir($browse));			
-			//echo '
'; - - break; - } + } + + //echo '
';
+			//print_r($mympd->GetDir($browse));
+			//echo '
'; + + break; + } ?> diff --git a/templates/default/browse.html b/templates/default/browse.html index 3d592fa..d492811 100644 --- a/templates/default/browse.html +++ b/templates/default/browse.html @@ -3,7 +3,7 @@
  • Home
  • {foreach from=$dir_list item=dir_list_item} -
  • {$dir_list_item.name|escape:'html'}
  • +
  • {$dir_list_item.name|escape:'html'}
  • {/foreach} diff --git a/templates/default/browselist_item.html b/templates/default/browselist_item.html index 5ed7ed7..8b8334f 100644 --- a/templates/default/browselist_item.html +++ b/templates/default/browselist_item.html @@ -1,18 +1,18 @@ {if $browselist_item.directory} -
  • {$browselist_item.directory_name|escape:'html'}
  • - +
  • {$browselist_item.directory_name|escape:'html'}
  • + {elseif $browselist_item.metaArtist} -
  • {$browselist_item.metaArtist|escape:'html'}
  • - +
  • {$browselist_item.metaArtist|escape:'html'}
  • + {elseif $browselist_item.metaAlbum} -
  • {$browselist_item.metaAlbum|escape:'html'}
  • - +
  • {$browselist_item.metaAlbum|escape:'html'}
  • + {elseif $browselist_item.Title} - {if $browselist_item.in_playlist}
  • {else}
  • {/if}AddPlay {if $browselist_item.Title|escape:'html'}{$browselist_item.Title|escape:'html'}
    {$browselist_item.Artist|escape:'html'} ({$browselist_item.Album|escape:'html'}){else}{$browselist_item.file|escape:'html'}{/if}
  • + {if $browselist_item.in_playlist}
  • {else}
  • {/if}AddPlay {if $browselist_item.Title|escape:'html'}{$browselist_item.Title|escape:'html'}
    {$browselist_item.Artist|escape:'html'} ({$browselist_item.Album|escape:'html'}){else}{$browselist_item.file|escape:'html'}{/if}
  • {/if} diff --git a/templates/default/index.html b/templates/default/index.html index 72b8e78..c733ac4 100644 --- a/templates/default/index.html +++ b/templates/default/index.html @@ -1,9 +1,9 @@ - - + + - Neo MPC 0.2 + Neo MPC {$version}