Added Bob's list
[songbook.git] / web / songbook.php
1 <?php
2 $baseDir = getcwd();
3 $songDir = "/opt/songbook/Songs";
4
5 if (isset ($_REQUEST['debug'])) {
6   $debug = $_REQUEST['debug'];
7 } // if
8
9 // Initialize music objects
10 $songs   = getSongs($songDir);
11 $sets    = getSets($songDir);
12 $artists = getArtists($songs);
13
14 function debug ($msg) {
15   global $debug;
16
17   if (isset ($debug)) {
18     echo "<font color=red>DEBUG:</font> $msg<br>";
19   } // if
20 } // debug
21
22 function getSongs ($songDir) {
23   return glob("$songDir/*.pro");
24 } // getSongs
25
26 function getSets ($songDir) {
27   return glob("$songDir/*.lst");
28 } // getSets
29
30 function songsDropdown () {
31   global $songs;
32
33   print "<form method=\"get\" action=\"webchord.cgi\" name=\"song\">";
34   print "Songs:&nbsp;&nbsp;";
35   print "<select name=\"chordpro\">";
36
37   sort ($songs);
38   foreach ($songs as $song) {
39     $title = basename ($song, ".pro");
40     $artist = getArtist ($song);
41
42     print "<option value=\"$title.pro\">$title</option>";
43
44     if ($artist != "") {
45       $title .= "&nbsp;($artist)";
46     } // if
47   } // foreach
48
49   print "</select>";
50   print "&nbsp;<input type=\"submit\" value=\"Go\">";
51   print "</form>";
52 } // songsDropdown
53
54 function artistsDropdown () {
55   global $artists;
56
57   print "<form method=\"get\" action=\"displayartist.php\" name=\"artist\">";
58   print "Artists:&nbsp;&nbsp;";
59   print "<select name=\"artist\">";
60
61   sort ($artists);
62   foreach ($artists as $artist) {
63     print "<option>$artist</option>";
64   } // foreach
65
66   print "</select>";
67   print "&nbsp;<input type=\"submit\" value=\"Go\">";
68   print "</form>";
69 } // artistsDropdown
70
71 function setsDropdown () {
72   global $sets;
73
74   print "<form method=\"get\" action=\"displayset.php\" name=\"set\">";
75   print "Sets:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
76   print "<select name=\"set\">";
77
78   sort ($sets);
79   foreach ($sets as $set) {
80     print "Processing set<br>";
81     $title = basename ($set, ".lst");
82
83     print "<option value=\"$title.lst\">$title</option>";
84   } // foreach
85
86   print "</select>";
87   print "&nbsp;<input type=\"submit\" value=\"Go\">";
88   print "</form>";
89 } // setsDropdown
90
91 function getArtist ($song) {
92   $lyrics = @file_get_contents ($song);
93
94   if (preg_match ("/\{(st|subtitle):(.*)\}/", $lyrics, $matches)) {
95     return trim ($matches[2]);
96   } else {
97     return "";
98   } // if
99 } // getArtist
100
101 function getArtists ($songs) {
102   foreach ($songs as $song) {
103     $artist = getArtist ($song);
104
105     if ($artist != '') {
106       $artists[$artist] = 1;
107     } // if
108   } // foreach
109
110   return array_keys ($artists);
111 } // getArtists
112