Debian Codegraph @

php/phpAiksaur_popup_searchframe.php

raw
1 <?
2 /*
3 * phpAiksaur - A Web Interface to the AikSaurus Thesaurus Library
4 * Copyright (C) 2001 by Jared Davis
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21
22 // Set the title of your window here.
23 define(TITLE, "Thesaurus: Synonyms for " . ucwords(strtolower($lookup)));
24
25
26 // This path also needs to be correct. Usually you just put
27 // phpAiksaurusClass.php in the same directory with this file.
28 include_once("phpAiksaur.php");
29
30
31 // Define this so that words will be hyperlinks.
32 define(LINK_URL, $PHP_SELF . "?lookup=");
33
34
35 function makeLink($word)
36 {
37 return "<a href=\"" . LINK_URL . rawurlencode($word) . "\">$word</a>";
38 }
39
40
41 function printResults($res, $title)
42 {
43 if (count($res) == 0)
44 return;
45
46 usort($res, strcasecmp);
47
48 switch( count($res) % 4 )
49 {
50 case 0:
51 case 3:
52 $stop1 = count($res) / 4;
53 $stop2 = 2 * $stop1;
54 $stop3 = 3 * $stop1;
55 $stop4 = count($res);
56 break;
57
58 case 1:
59 $stop1 = (count($res) / 4);
60 $stop2 = $stop1 + count($res) / 4;
61 $stop3 = $stop2 + count($res) / 4;
62 $stop4 = count($res);
63 break;
64
65 case 2:
66 $stop1 = count($res) / 4;
67 $stop2 = 1 + $stop1 + count($res) / 4;
68 $stop3 = $stop2 + count($res) / 4;
69 $stop4 = count($res);
70 break;
71 }
72
73 print "<table border=\"0\" width=\"100%\" align=\"center\" cellspacing=\"0\" cellpadding=\"5\">";
74 print "<tr valign=\"top\">";
75 print "<td colspan=\"4\" width=\"100%\" bgcolor=\"#eeeeee\">";
76 print "<big>" . count($res) . " $title</big>";
77 print "</td></tr><tr><td width=\"20%\" valign=\"top\">";
78 for($i = 0;$i < $stop1;++$i)
79 {
80 print makeLink($res[$i]) . "<br>";
81 }
82 print "</td><td width=\"20%\" valign=\"top\">";
83 for(; $i < $stop2; ++$i)
84 {
85 print makeLink($res[$i]) . "<br>";
86 }
87 print "</td><td width=\"20%\" valign=\"top\">";
88 for(; $i < $stop3; ++$i)
89 {
90 print makeLink($res[$i]) . "<br>";
91 }
92 print "</td><td width=\"20%\" valign=\"top\">";
93 for(; $i < $stop4; ++$i)
94 {
95 print makeLink($res[$i]) . "<br>";
96 }
97 print "</td></tr></table><br>";
98 }
99 ?>
100
101 <html>
102 <head>
103 <title><? print TITLE; ?></title>
104 <style>
105 <!--
106 body {
107 margin-left: 0px;
108 margin-right: 0px;
109 margin-top: 0px;
110 margin-bottom: 0px;
111 }
112 -->
113 </style>
114 </head>
115 <body bgcolor="#ffffff" text="#000000">
116
117 <form name="NewSearch" method="post" action="<? print $PHP_SELF; ?>">
118 <table bgcolor="#fffff0" border="0" width="100%" height="45">
119 <tr><td width="100%">
120 <big> &nbsp;
121 <?
122 $thesaurus = new phpAiksaur;
123 $synonyms = $thesaurus->doSearch($lookup);
124 print (($synonyms) ? ("Synonyms for ") : ("Synonyms for "));
125 print "<font color=\"#ff0000\">" . ucwords(strtolower($lookup)) . "</font>\n";
126 ?>
127 </big>
128 </td>
129 <td align="right">
130 <nobr>Look up:</nobr>
131 </td><td>
132 <nobr>
133 <input type="text" name="lookup" size="15" />
134 <input type="submit" value="Go" />
135 &nbsp; </nobr></td></tr>
136 </table>
137
138 <script language="JavaScript1.1">
139 <!--
140 document.NewSearch.lookup.focus();
141 // -->
142 </script>
143
144
145 <?
146
147 if ($synonyms)
148 {
149 printResults($thesaurus->getNouns(), "Nouns");
150 printResults($thesaurus->getVerbs(), "Verbs");
151 printResults($thesaurus->getAdjectives(), "Adjectives");
152 printResults($thesaurus->getAdverbs(), "Adverbs");
153 printResults($thesaurus->getOthers(), "Others");
154 printResults($thesaurus->getUnknowns(), "Unknowns");
155 }
156
157
158 else
159 {
160 $similar = $thesaurus->getSimilar();
161
162 print "<p> &nbsp; <strong>No Synonyms Found.</strong><br />";
163 print " &nbsp; Alphabetically nearby known words:</p>";
164 print "<table border=\"0\" width=\"100%\">";
165 print "<tr><td width=\"50%\">";
166 print "<ul>";
167 for($i = 0;$i < count($similar) / 2;++$i)
168 {
169 print "<li>" . makeLink($similar[$i]) . "</li>";
170 }
171 print "</ul>";
172 print "</td><td width=\"50%\">";
173 print "<ul>";
174 for(;$i < count($similar);++$i)
175 {
176 print "<li>" . makeLink($similar[$i]) . "</li>";
177 }
178 print "</ul>";
179 print "</td></tr>";
180 print "</table>";
181 }
182
183 ?>
184 </form>
185 </body>
186 </html>
187