Initial add of defaria.com
[clearscm.git] / defaria.com / bluegrass / songbook.php
1 <?php
2 $baseDir = getcwd();
3 $songs   = glob ($baseDir . "/Songs/*.pro");
4
5 function songsDropdown () {
6   global $songs;
7
8   print "<form method=\"post\" action=\"webchord.cgi\" name=\"song\">";
9   print "Songs:&nbsp;&nbsp;";
10   print "<select name=\"chordpro\">";
11
12   sort ($songs);
13   foreach ($songs as $song) {
14     $title = basename ($song, ".pro");
15     $artist = getArtist ($song);
16
17     if ($artist != "") {
18       $title .= "&nbsp;($artist)";
19     } // if
20
21     print "<option value=\"$song\">$title</option>";
22   } // foreach
23
24   print "<input type=\"submit\" value=\"Go\">";
25   print "</select>";
26   print "</form>";
27 } // songsDropdown
28
29 function artistsDropdown () {
30   global $songs;
31
32   $artists = getArtists ($songs);
33
34   print "<form method=\"post\" action=\"displayartist.php\" name=\"artist\">";
35   print "Artists:&nbsp;&nbsp;";
36   print "<select name=\"artist\">";
37
38   sort ($artists);
39   foreach ($artists as $artist) {
40     print "<option>$artist</option>";
41   } // foreach
42
43   print "<input type=\"submit\" value=\"Go\">";
44   print "</select>";
45   print "</form>";
46 } // artistsDropdown
47
48 function getArtist ($song) {
49   $lyrics = file_get_contents ($song);
50
51   if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
52     return trim ($matches[2]);
53   } else {
54     return "";
55   } // if
56 } // getArtist
57
58 function getArtists ($songs) {
59   $artists = array();
60
61   foreach ($songs as $song) {
62     $artist = getArtist ($song);
63
64     if ($artist != '') {
65       $artists[$artist] = 1;
66     } // if
67   } // foreach
68
69   return array_keys ($artists);
70 } // getArtists
71
72 function formatTable ($songs) {
73   echo "<ol>";
74
75   foreach ($songs as $song) {
76     $artist = getArtist ($song);
77
78     $title = basename ($song, ".pro");
79
80     echo "<li><a href=\"webchord.cgi?chordpro=$song\">$title</a>";
81
82     if ($artist != "") {
83     echo "&nbsp;($artist)";
84     } // if
85   } // foreach
86
87   echo "</ol>";
88 } // formatTable