@@ -23,10 +23,16 @@ $PGI = []; $SIDEBAR_DATA = '';
23
23
// =============================================================================
24
24
25
25
require_once __DIR__ . ' /../autoload.php' ;
26
- use phpweb\UserNotes\Sorter;
27
26
28
- // Print out all user notes for this manual page
29
- function manual_notes ($notes) {
27
+ use phpweb\UserNotes\Sorter;
28
+ use phpweb\UserNotes\UserNote;
29
+
30
+ /* *
31
+ * Print out all user notes for this manual page
32
+ *
33
+ * @param array<string, UserNote> $notes
34
+ */
35
+ function manual_notes ($notes):void {
30
36
// Get needed values
31
37
list ($filename) = $GLOBALS[' PGI' ][' this' ];
32
38
@@ -68,68 +74,63 @@ END_USERNOTE_HEADER;
68
74
// If we have notes, print them out
69
75
echo ' <div id="allnotes">' ;
70
76
foreach ($notes as $note) {
71
- manual_note_display (
72
- $note[' xwhen' ], $note[' user' ], $note[' note' ], $note[' id' ], $note[' votes' ]
73
- );
77
+ manual_note_display ($note);
74
78
}
75
79
echo " </div>\n " ;
76
80
echo " <div class=\" foot\" >$addnotesnippet</div>\n " ;
77
81
}
78
82
echo " </section>" ;
79
83
}
80
- // Get user notes from the appropriate text dump
81
- function manual_notes_load ($id)
84
+
85
+ /* *
86
+ * Get user notes from the appropriate text dump
87
+ *
88
+ * @return array<string, UserNote>
89
+ */
90
+ function manual_notes_load (string $id): array
82
91
{
83
- // Initialize values
84
- $notes = [];
85
92
$hash = substr (md5 ($id), 0 , 16 );
86
93
$notes_file = $_SERVER[' DOCUMENT_ROOT' ] . " /backend/notes/" .
87
94
substr ($hash, 0 , 2 ) . " /$hash" ;
88
95
89
96
// Open the note file for reading and get the data (12KB)
90
97
// ..if it exists
91
98
if (!file_exists ($notes_file)) {
92
- return $notes ;
99
+ return [] ;
93
100
}
101
+ $notes = [];
94
102
if ($fp = @fopen ($notes_file, " r" )) {
95
103
while (!feof ($fp)) {
96
104
$line = chop (fgets ($fp, 12288 ));
97
105
if ($line == " " ) { continue ; }
98
106
@list ($id, $sect, $rate, $ts, $user, $note, $up, $down) = explode (" |" , $line);
99
- $notes[$id] = [
100
- " id" => $id,
101
- " sect" => $sect,
102
- " rate" => $rate,
103
- " xwhen" => $ts,
104
- " user" => $user,
105
- " note" => base64_decode ($note, true ),
106
- " votes" => [" up" => (int )$up, " down" => (int )$down]
107
- ];
107
+ $notes[$id] = new UserNote ($id, $sect, $rate, $ts, $user, base64_decode ($note, true ), (int ) $up, (int ) $down);
108
108
}
109
109
fclose ($fp);
110
110
}
111
111
return $notes;
112
112
}
113
113
114
114
// Print out one user note entry
115
- function manual_note_display ($date, $name, $text, $id, $votes = [ ' up ' => 0 , ' down ' => 0 ] , $voteOption = true )
115
+ function manual_note_display (UserNote $note , $voteOption = true )
116
116
{
117
- if ($name ) {
118
- $name = " \n <strong class=\" user\" ><em>" . htmlspecialchars ($name ) . " </em></strong>" ;
117
+ if ($note-> user ) {
118
+ $name = " \n <strong class=\" user\" ><em>" . htmlspecialchars ($note-> user ) . " </em></strong>" ;
119
119
} else {
120
120
$name = " <strong class=\" user\" ><em>Anonymous</em></strong>" ;
121
121
}
122
- $name = ($id ? " \n <a href=\" #$id \" class=\" name\" >$name</a><a class=\" genanchor\" href=\" #$id \" > ¶</a>" : " \n $name" );
122
+ $name = ($note-> id ? " \n <a href=\" #{$note->id} \" class=\" name\" >$name</a><a class=\" genanchor\" href=\" #{$note->id} \" > ¶</a>" : " \n $name" );
123
123
124
124
// New date style will be relative time
125
- $datestr = relTime (new DateTime (" @{$date}" ));
126
- $fdatestr = date (" Y-m-d h:i" , $date);
127
- $text = clean_note ($text);
125
+ $date = new DateTime (" @{$note->ts}" );
126
+ $datestr = relTime ($date);
127
+ $fdatestr = $date->format (" Y-m-d h:i" );
128
+ $text = clean_note ($note->text );
128
129
129
130
// Calculate note rating by up/down votes
130
- $vote = $votes[ ' up ' ] - $votes[ ' down ' ] ;
131
- $p = floor (($votes[ ' up ' ] / (($votes[ ' up ' ] + $votes[ ' down ' ] ) ?: 1 )) * 100 );
132
- $rate = !$p && !($votes[ ' up ' ] + $votes[ ' down ' ] ) ? " no votes..." : " $p% like this..." ;
131
+ $vote = $note-> upvotes - $note-> downvotes ;
132
+ $p = floor (($note-> upvotes / (($note-> upvotes + $note-> downvotes ) ?: 1 )) * 100 );
133
+ $rate = !$p && !($note-> upvotes + $note-> downvotes ) ? " no votes..." : " $p% like this..." ;
133
134
134
135
// Vote User Notes Div
135
136
if ($voteOption) {
@@ -140,13 +141,13 @@ function manual_note_display($date, $name, $text, $id, $votes = ['up' => 0, 'dow
140
141
$rredir_filename = urlencode ($redir_filename);
141
142
$votediv = <<<VOTEDIV
142
143
<div class =" votes" >
143
- <div id=" Vu{$id}" >
144
- <a href=" /manual/vote-note.php?id={$id}&page={$rredir_filename}&vote=up" title=" Vote up!" class =" usernotes-voteu" >up</a>
144
+ <div id=" Vu{$note-> id}" >
145
+ <a href=" /manual/vote-note.php?id={$note-> id}&page={$rredir_filename}&vote=up" title=" Vote up!" class =" usernotes-voteu" >up</a>
145
146
</div>
146
- <div id=" Vd{$id}" >
147
- <a href=" /manual/vote-note.php?id={$id}&page={$rredir_filename}&vote=down" title=" Vote down!" class =" usernotes-voted" >down</a>
147
+ <div id=" Vd{$note-> id}" >
148
+ <a href=" /manual/vote-note.php?id={$note-> id}&page={$rredir_filename}&vote=down" title=" Vote down!" class =" usernotes-voted" >down</a>
148
149
</div>
149
- <div class =" tally" id=" V{$id}" title=" {$rate}" >
150
+ <div class =" tally" id=" V{$note-> id}" title=" {$rate}" >
150
151
{$vote}
151
152
</div>
152
153
</div>
@@ -156,26 +157,26 @@ VOTEDIV;
156
157
}
157
158
158
159
// If the viewer is logged in, show admin options
159
- if (isset ($_COOKIE[' IS_DEV' ]) && $id) {
160
+ if (isset ($_COOKIE[' IS_DEV' ]) && $note-> id ) {
160
161
161
162
$admin = " \n <span class=\" admin\" >\n " .
162
163
163
164
make_popup_link (
164
- ' https://main.php.net/manage/user-notes.php?action=edit+' . $id,
165
+ ' https://main.php.net/manage/user-notes.php?action=edit+' . $note-> id ,
165
166
' <img src="/images/[email protected] " height="12" width="12" alt="edit note">' ,
166
167
' admin' ,
167
168
' scrollbars=yes,width=650,height=400'
168
169
) . " \n " .
169
170
170
171
make_popup_link (
171
- ' https://main.php.net/manage/user-notes.php?action=reject+' . $id,
172
+ ' https://main.php.net/manage/user-notes.php?action=reject+' . $note-> id ,
172
173
' <img src="/images/[email protected] " height="12" width="12" alt="reject note">' ,
173
174
' admin' ,
174
175
' scrollbars=no,width=300,height=200'
175
176
) . " \n " .
176
177
177
178
make_popup_link (
178
- ' https://main.php.net/manage/user-notes.php?action=delete+' . $id,
179
+ ' https://main.php.net/manage/user-notes.php?action=delete+' . $note-> id ,
179
180
' <img src="/images/[email protected] " height="12" width="12" alt="delete note">' ,
180
181
' admin' ,
181
182
' scrollbars=no,width=300,height=200'
@@ -187,8 +188,8 @@ VOTEDIV;
187
188
188
189
echo <<<USER_NOTE_TEXT
189
190
190
- <div class =" note" id=" $id " >{$votediv}{$name}{$admin}<div class =" date" title=" $fdatestr" ><strong>{$datestr}</strong></div>
191
- <div class =" text" id=" Hcom{$id}" >
191
+ <div class =" note" id=" {$note->id} " >{$votediv}{$name}{$admin}<div class =" date" title=" $fdatestr" ><strong>{$datestr}</strong></div>
192
+ <div class =" text" id=" Hcom{$note-> id}" >
192
193
{$text}
193
194
</div>
194
195
</div>
@@ -295,7 +296,7 @@ function manual_setup($setup) {
295
296
$USERNOTES = manual_notes_load ($filename);
296
297
if ($USERNOTES) {
297
298
$note = current ($USERNOTES);
298
- $timestamps[] = $note[ " xwhen " ] ;
299
+ $timestamps[] = $note-> ts ;
299
300
}
300
301
301
302
$lastmod = max ($timestamps);
0 commit comments