@@ -126,11 +126,30 @@ function find_manual_page($lang, $keyword)
126
126
// Check for all the languages
127
127
foreach ($langs as $lang) {
128
128
129
+ // @todo consider alternative schemas for this data
130
+ // @todo utilize phd to generate this data, instead of the current systems/gen-phpweb-sqlite-db.php
131
+
132
+ /* Example data:
133
+ lang = en
134
+ name = /manual/en/function.str-replace.php
135
+ keyword = str-replace
136
+ prefix = function.
137
+ prio = 2
138
+
139
+ Therefore, the query below matches: str-replace, function.str-replace and function.str-replace.php
140
+ This also applies to other sections like book.foo, language.foo, example.foo, etc.
141
+ Note: $keyword replaces _ with - above, so _ variants also work
142
+ */
129
143
if (strpos ($keyword, " ." ) > 0 ) {
130
- $SQL = " SELECT name from fs WHERE name LIKE ? AND lang = ? ORDER BY prio LIMIT 1" ;
131
-
144
+ $SQL = " SELECT name from fs WHERE lang = ? AND (name = ? OR keyword = ?) ORDER BY prio LIMIT 1" ;
145
+
146
+ $_keyword = $keyword;
147
+ if (pathinfo ($keyword, PATHINFO_EXTENSION) !== ' php' ) {
148
+ $_keyword .= ' .php' ;
149
+ }
150
+
132
151
$stm = $dbh->prepare ($SQL);
133
- $stm->execute (array (" %{$keyword}.php " , $lang ));
152
+ $stm->execute (array ($lang, " /manual/{$lang}/{$_keyword} " , $keyword ));
134
153
135
154
// Some partially specified URL is used
136
155
} else {
@@ -163,6 +182,8 @@ function find_manual_page($lang, $keyword)
163
182
164
183
// Match found
165
184
// But does the file really exist?
185
+ // @todo consider redirecting here, instead of including content within the 404
186
+ // @todo considering the file path is generated from the manual build, we can probably remove this file_exists() check
166
187
if (file_exists ($_SERVER[" DOCUMENT_ROOT" ] . $r[0 ])) {
167
188
return $r[0 ];
168
189
}
@@ -173,6 +194,9 @@ function find_manual_page($lang, $keyword)
173
194
}
174
195
175
196
// No match found
197
+ // @todo refactor. find_manual_page_slow() performs many of the same searches already performed above,
198
+ // but uses file_exists() instead of sqlite. In other words, if sqlite was used, don't perform
199
+ // all of the slow and unnecessary checks.
176
200
return find_manual_page_slow ($langs[0 ], $kw);
177
201
}
178
202
0 commit comments