$notes
*/
function manual_notes($notes):void {
// Get needed values
list($filename) = $GLOBALS['PGI']['this'];
// Drop file extension from the name
if (substr($filename, -4) == '.php') {
$filename = substr($filename, 0, -4);
}
$sorter = new Sorter();
$sorter->sort($notes);
// Link target to add a note to the current manual page,
// and it's extended form with a [+] image
$addnotelink = '/manual/add-note.php?sect=' . $filename .
'&redirect=' . $_SERVER['BASE_HREF'];
$addnotesnippet = make_link(
$addnotelink,
"+add a note",
);
$num_notes = count($notes);
$noteCountHtml = '';
if ($num_notes) {
$noteCountHtml = "$num_notes note" . ($num_notes == 1 ? '' : 's') . "";
}
echo <<
{$addnotesnippet}
User Contributed Notes {$noteCountHtml}
END_USERNOTE_HEADER;
// If we have no notes, then inform the user
if ($num_notes === 0) {
echo "\n
There are no user contributed notes for this page.
";
} else {
// If we have notes, print them out
echo '
';
foreach ($notes as $note) {
manual_note_display($note);
}
echo "
\n";
echo "
$addnotesnippet
\n";
}
echo "";
}
/**
* Get user notes from the appropriate text dump
*
* @return array
*/
function manual_notes_load(string $id): array
{
$hash = substr(md5($id), 0, 16);
$notes_file = $_SERVER['DOCUMENT_ROOT'] . "/backend/notes/" .
substr($hash, 0, 2) . "/$hash";
// Open the note file for reading and get the data (12KB)
// ..if it exists
if (!file_exists($notes_file)) {
return [];
}
$notes = [];
if ($fp = @fopen($notes_file, "r")) {
while (!feof($fp)) {
$line = chop(fgets($fp, 12288));
if ($line == "") { continue; }
@list($id, $sect, $rate, $ts, $user, $note, $up, $down) = explode("|", $line);
$notes[$id] = new UserNote($id, $sect, $rate, $ts, $user, base64_decode($note, true), (int) $up, (int) $down);
}
fclose($fp);
}
return $notes;
}
// Print out one user note entry
function manual_note_display(UserNote $note, $voteOption = true): void
{
if ($note->user) {
$name = "\n " . htmlspecialchars($note->user) . "";
} else {
$name = "Anonymous";
}
$name = ($note->id ? "\n id}\" class=\"name\">$nameid}\"> ¶" : "\n $name");
// New date style will be relative time
$date = new DateTime("@{$note->ts}");
$datestr = relTime($date);
$fdatestr = $date->format("Y-m-d h:i");
$text = clean_note($note->text);
// Calculate note rating by up/down votes
$vote = $note->upvotes - $note->downvotes;
$p = floor(($note->upvotes / (($note->upvotes + $note->downvotes) ?: 1)) * 100);
$rate = !$p && !($note->upvotes + $note->downvotes) ? "no votes..." : "$p% like this...";
// Vote User Notes Div
if ($voteOption) {
list($redir_filename) = $GLOBALS['PGI']['this'];
if (substr($redir_filename, -4) == '.php') {
$redir_filename = substr($redir_filename, 0, -4);
}
$rredir_filename = urlencode($redir_filename);
$votediv = <<