Initial add of defaria.com
[clearscm.git] / defaria.com / php / music.php
1 <?php
2 $base = "/web/Music";
3 $http_base="/Music";
4
5 function GetAlbumArt ($path) {
6   if ($handle = opendir ("$path")) {
7     while (false !== ($element = readdir ($handle))) {
8       if (strpos ($element, "AlbumArt") == 0 &&
9           strpos ($element, "Large")    != 0) {
10         return $element;
11       } // if
12     } // while
13
14     closedir ($handle);
15   } // if
16 } // GetAlbumArt
17       
18 function Banner ($path) {
19   global $http_base;
20   global $base;
21
22   $orig_path = $path;
23
24   print "<h2>";
25   while ($component = substr ($path, 0, strpos ($path, "/"))) {
26     $component_path = isset ($component_path)
27       ? $component_path . "/" . $component : $component;
28     print "<a href=\"$http_base/index.php?path=$component_path\">$component</a>:&nbsp;";
29     $path = substr ($path, strpos ($path, "/") + 1);
30   } // while
31   print "$path</h2>\n";
32
33   if ($albumart = GetAlbumArt ("$base/$orig_path")) {
34     print "<img src=\"$orig_path/$albumart\">\n";
35   } // if
36 } // Banner
37
38 function DisplayItem ($path, $element) {
39   if ($element == "." || $element == "..") {
40     return false;
41   } elseif (is_dir ($path . "/" . $element)) {
42     if ($element == "My Playlists") {
43       return false;
44     } else {
45       return true;
46     } // if
47   } elseif (strpos ($element, ".wma") ||
48             strpos ($element, ".mp3")) {
49     return true;
50   } else {
51     return false;
52   } // if
53 } // DisplayItem
54     
55 function DisplayFolders ($path) {
56   global $http_base;
57   global $base;
58
59   Banner ($path);
60
61   if ($path != "") {
62     $path = $path . "/";
63   } // if
64
65   $folder_array = array ();
66   $song_array   = array ();
67
68   if ($handle = opendir ("$base/$path")) {
69     while (false !== ($element = readdir ($handle))) {
70       if (!DisplayItem ("$base/$path", $element)) {
71         continue;
72       } // if
73       if (is_dir ("$base/$path/$element")) {
74         array_push ($folder_array, $element);
75       } else {
76         array_push ($song_array, $element);
77       } // if
78
79     } // while
80     closedir ($handle);
81   } // if
82
83   sort ($folder_array);
84   sort ($song_array);
85
86   print "<table border=1 width=100% cellspacing=0 cellpadding=5>\n";
87   print "  <tbody>\n";
88   print "    <tr>\n";
89   print "      <th bgcolor=blue><font color=white>Folders<font></th>\n";
90   print "      <th bgcolor=blue><font color=white>Songs at this level</font></th>\n";
91   print "    </tr>\n";
92
93   $song_index   = 0;
94   $folder_index = 0;
95
96   while (isset ($song_array   [$song_index]) ||
97          isset ($folder_array [$folder_index])) {
98     $song       = $song_array   [$song_index];
99     $folder     = $folder_array [$folder_index];
100     print "    <tr>\n";
101     if (isset ($folder)) {
102       print "<td><a href=\"$http_base/index.php?path=$path" . $folder . "\">$folder</a></td>\n";
103       $folder_index++;
104     } else {
105       print "<td>&nbsp;</td>\n";
106     } // if
107     if (isset ($song)) {
108       print "<td><a href=\"$http_base/$path";
109       $song_name = $song;
110
111       if (strpos ($song, ".wma") != 0) {
112         $song_name = substr ($song, 0, strpos ($song, ".wma"));
113       } elseif (strpos ($song, ".mp3") != 0) {
114         $song_name = substr ($song, 0, strpos ($song, ".mp3"));
115       } // if
116
117       print $song . "\">$song_name</a></td>\n";
118       $song_index++;
119     } else {
120       print "<td>&nbsp;</td>\n";
121     } // if
122     print "    </tr>\n";
123   } // while
124
125   print "  </tbody>\n";
126   print "</table>\n";
127 } // DisplayFolders
128 ?>