Initial add of defaria.com
[clearscm.git] / defaria.com / bluegrass / search.php
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2    "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6   <meta name="GENERATOR" content="Mozilla/4.61 [en] (Win98; U) [Netscape]">
7   <title>Songbook" Artist</title>
8   <link rel="stylesheet" type="text/css" media="screen" href="/css/Music.css">
9   <link rel="stylesheet" type="text/css" media="print" href="/css/Print.css">
10   <link rel="SHORTCUT ICON" href="http://defaria.com/favicon.ico" type="image/png">
11
12 <?php
13 include_once "songbook.php";
14 $searchterm = $_REQUEST ["searchterm"];
15 $songmatches = array();
16
17 function getSongText ($song) {
18   return join ("\n", file ($song));
19 } // getSongText
20
21 function search ($searchterm) {
22   global $songs;
23   global $songmatches;
24
25   $tokens = preg_split ("/\s+/", $searchterm);
26   $searchfor = join (".*", $tokens);
27
28         foreach ($songs as $song) {
29     $text = getSongText ($song);
30
31     preg_match ("/$searchfor/i", $text, $matches);
32
33     if ($matches) {
34       array_push ($songmatches, $song);
35     } // if
36   } // foreach
37
38   return $songmatches;
39 } // search
40
41 $songmatches = search ($searchterm);
42 ?>
43 </head>
44
45 <body>
46
47 <div class="heading">
48 <a href="/songbook"><img src="/Icons/Home.png" alt="Home"></a>
49   <h1 class="centered">Andrew DeFaria's Songbook</h1>
50
51   <h2><?php
52 if (count ($songmatches) == 0) {
53   print "No songs matched \"$searchterm\"";
54 } elseif (count ($songmatches) == 1) {
55   print "One song matched \"$searchterm\"";
56 } else {
57   print count ($songmatches) . " songs matched \"$searchterm\"";
58 } // if
59 ?></h2>
60 </div>
61
62 <div id="content">
63
64 <?php
65 if (count ($songmatches) > 0) {
66   print "<ol>";
67 } // if
68
69 foreach ($songmatches as $songmatch) {
70   $artist = getArtist ($songmatch);
71   $title  = basename ($songmatch, ".pro");
72   print "<li><a href=\"webchord.cgi?chordpro=$songmatch\">$title</a>";
73   print "&nbsp;(<a href=\"displayartist.php?artist=$artist\">$artist</a>)</li>";
74 } // foreach
75
76 if (count ($songmatches) > 0) {
77   print "</ol>";
78 } // if
79 ?>
80
81 </div>
82 </body>
83 </html>
84