Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions gen-phpweb-sqlite-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,31 @@ function scan($dir, $lang)
$dbh->exec("INSERT INTO fs (lang, prefix, keyword, name, prio) values ('$lang', '$prefix', '" . metaphone($keyword) . "', '$doc_rel', ".($prio+10).")");

}

if ($f === 'reserved.keywords.php') {
// Yes, this is fragile.
$handle = fopen($file, 'r');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no error handling here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What sort of handling would you like to see here? Would it be enough to move this into the above if statement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least not try to run any code if you can't open the file. Right now ,that would error on line 173 with the fgets.

$stm = $dbh->prepare('INSERT INTO fs (lang, prefix, keyword, name, prio) VALUES (?, ?, ?, ?, ?)');
$path_base = dirname($doc_rel);
while ($stm && false !== ($line = fgets($handle))) {
if (strpos($line, '<a href=') === false) {
continue;
}

if (!preg_match('!<a href="([^"]+)" class="[^"]+">([^<]+)</a>!', $line, $matches)) {
continue;
}

$keyword = strtolower(rtrim($matches[2], '()'));
$href = $matches[1];

if ($x = strpos($href, '#')) {
$href = substr($href, 0, $x);
}

$stm->execute([$lang, $prefix ?? '', $keyword, $path_base . '/' . $href, $prio ?? 200]);
}
}
}
closedir($d);

Expand Down