xref: /web-php/manual/add-note.php (revision b585014d)
1<?php
2$ip_spam_lookup_url = 'http://www.dnsbl.info/dnsbl-database-check.php?IP=';
3
4$_SERVER['BASE_PAGE'] = 'manual/add-note.php';
5include_once __DIR__ . '/../include/prepend.inc';
6include_once __DIR__ . '/../include/posttohost.inc';
7include_once __DIR__ . '/../include/shared-manual.inc';
8include __DIR__ . '/spam_challenge.php';
9
10use phpweb\UserNotes\UserNote;
11
12site_header("Add Manual Note", ['css' => 'add-note.css']);
13
14// Copy over "sect" and "redirect" from GET to POST
15if (empty($_POST['sect']) && isset($_GET['sect'])) {
16    $_POST['sect'] = $_GET['sect'];
17}
18if (empty($_POST['redirect']) && isset($_GET['redirect'])) {
19    $_POST['redirect'] = $_GET['redirect'];
20}
21// Assume English if we didn't get a language
22if (empty($_POST['repo'])) {
23    $_POST['repo'] = 'en';
24}
25
26// Decide on whether all vars are present for processing
27$process = true;
28$needed_vars = ['note', 'user', 'sect', 'redirect', 'action', 'func', 'arga', 'argb', 'answer'];
29foreach ($needed_vars as $varname) {
30    if (empty($_POST[$varname])) {
31        $process = false;
32        break;
33    }
34}
35
36// We have a submitted form to process
37if ($process) {
38
39    // Clean off leading and trailing whitespace
40    $user = trim($_POST['user']);
41    $note = trim($_POST['note']);
42
43    // Convert all line-endings to unix format,
44    // and don't allow out-of-control blank lines
45    $note = str_replace(["\r\n", "\r"], "\n", $note);
46    $note = preg_replace("/\n{2,}/", "\n\n", $note);
47
48    // Don't pass through example username
49    if ($user === "user@example.com") {
50        $user = "Anonymous";
51    }
52
53    // We don't know of any error now
54    $error = false;
55
56    // No note specified
57    if (strlen($note) == 0) {
58        $error = "You have not specified the note text.";
59    }
60
61    // SPAM challenge failed
62    elseif (!test_answer($_POST['func'], $_POST['arga'], $_POST['argb'], $_POST['answer'])) {
63        $error = 'SPAM challenge failed.';
64    }
65
66    // The user name contains a malicious character
67    elseif (stristr($user, "|")) {
68        $error = "You have included bad characters within your username. We appreciate you may want to obfuscate your email further, but we have a system in place to do this for you.";
69    }
70
71    // Check if the note is too long
72    elseif (strlen($note) >= 4096) {
73        $error = "Your note is too long. You'll have to make it shorter before you can post it. Keep in mind that this is not the place for long code examples!";
74    }
75
76    // Check if the note is not too short
77    elseif (strlen($note) < 32) {
78        $error = "Your note is too short. Trying to test the notes system? Save us the trouble of deleting your test, and don't. It works.";
79    }
80
81    // Check if any line is too long
82    else {
83
84        // Split the note by whitespace, and check length
85        foreach (preg_split("/\\s+/", $note) as $chunk) {
86            if (strlen($chunk) > 120) {
87                $error = "Your note contains a bit of text that will result in a line that is too long, even after using wordwrap().";
88                break;
89            }
90        }
91    }
92
93    // No error was found, and the submit action is required
94    if (!$error && strtolower($_POST['action']) !== "preview") {
95
96        $redirip = $_SERVER['HTTP_X_FORWARDED_FOR'] ??
97                   ($_SERVER['HTTP_VIA'] ?? '');
98
99        // Post the variables to the central user note script
100        $result = posttohost(
101            "https://main.php.net/entry/user-note.php",
102            [
103                'user' => $user,
104                'note' => $note,
105                'sect' => $_POST['sect'],
106                'ip' => $_SERVER['REMOTE_ADDR'],
107                'redirip' => $redirip,
108            ],
109        );
110
111        // If there is any non-header result, then it is an error
112        if ($result) {
113            if (strpos($result, '[TOO MANY NOTES]') !== false) {
114                echo "<p class=\"formerror\">As a security precaution, we only allow a certain number of notes to be submitted per minute. At this time, this number has been exceeded. Please re-submit your note in about a minute.</p>";
115            } elseif (($pos = strpos($result, '[SPAMMER]')) !== false) {
116                $ip = trim(substr($result, $pos + 9));
117                $spam_url = $ip_spam_lookup_url . $ip;
118                echo '<p class="formerror">Your IP is listed in one of the spammers lists we use, which aren\'t controlled by us. More information is available at <a href="' . $spam_url . '">' . $spam_url . '</a>.</p>';
119            } elseif (strpos($result, '[SPAM WORD]') !== false) {
120                echo '<p class="formerror">Your note contains a prohibited (usually SPAM) word. Please remove it and try again.</p>';
121            } elseif (strpos($result, '[CLOSED]') !== false) {
122                echo '<p class="formerror">Due to some technical problems this service isn\'t currently working. Please try again later. Sorry for any inconvenience.</p>';
123            } else {
124                echo "<!-- $result -->";
125                echo "<p class=\"formerror\">There was an internal error processing your submission. Please try to submit again later.</p>";
126            }
127        }
128
129        // There was no error returned
130        else {
131            echo '<p>Your submission was successful -- thanks for contributing! Note ',
132                 'that it will not show up for up to a few hours, ',
133                 'but it will eventually find its way.</p>';
134        }
135
136        // Print out common footer, and end page
137        site_footer();
138        exit();
139    }
140
141    // There was an error, or a preview is needed
142    // If there was an error, print out
143    if ($error) { echo "<p class=\"formerror\">$error</p>\n"; }
144
145    // Print out preview of note
146    echo '<p>This is what your entry will look like, roughly:</p>';
147    echo '<div id="usernotes">';
148    manual_note_display(new UserNote('', '', '', time(), $user, $note));
149    echo '</div><br><br>';
150}
151
152// Any needed variable was missing => display instructions
153else {
154?>
155
156<section id="add-note-usernotes" class="clearfix">
157  <h1>Adding a note to the manual</h1>
158  <div class="note_description">
159    <ul>
160      <li>
161        Please read <a href="#whatnottoenter">What not to enter</a>
162        we have many comments to moderate and there is an overwhelming number of
163        users ignoring this important section.
164      </li>
165      <li>
166        <em>Good notes rise to the top</em> as they are voted up; this makes
167        them easier to find.
168      </li>
169      <li>
170        <em>Poor notes fall to the bottom and are faded out</em> to discourage
171        their use; after certain threshold they are removed.
172      </li>
173      <li>Any form of spam is removed immediately.</li>
174    </ul>
175  </div>
176  <div class="note_example">
177    <div class="shadow"></div>
178    <div id="usernotes">
179      <h3 class="title">User Contributed Notes <span class="count">3 notes</span></h3>
180      <div class="note bad">
181        <div class="votes">
182          <div>
183            <a class="usernotes-voteu" title="Vote up!">up</a>
184          </div>
185        <div>
186          <a class="usernotes-voted" title="Vote down!">down</a>
187        </div>
188        <div class="tally">3</div>
189      </div>
190      <a class="name"><strong class="user"><em>Anonymous</em></strong></a>
191      <a class="genanchor" href="#"> ¶</a>
192      <div class="date">
193        <strong>1 year ago</strong>
194      </div>
195      <div class="text">
196        <div class="phpcode">
197          <code><span class="html">eval() is the best for all sorts of things</span></code>
198        </div>
199      </div>
200    </div>
201
202<div class="note good">
203  <div class="votes">
204    <div>
205      <a class="usernotes-voteu" title="Vote up!">up</a>
206    </div>
207    <div>
208      <a class="usernotes-voted" title="Vote down!">down</a>
209    </div>
210    <div title="" class="tally">
211      1
212    </div>
213  </div>
214  <a class="name"><strong class="user"><em>rasmus () lerdorf ! com</em></strong></a>
215  <a class="genanchor" href="#"> ¶</a>
216  <div class="date">
217    <strong>
218      2 days ago
219    </strong>
220  </div>
221  <div class="text">
222    <div class="phpcode">
223      <code><span class="html">If eval() is the answer, you're almost certainly asking the wrong question.</span></code>
224    </div>
225  </div>
226</div>
227
228<div class="note spam">
229  <div class="votes">
230    <div>
231      <a class="usernotes-voteu" title="Vote up!">up</a>
232    </div>
233    <div>
234      <a class="usernotes-voted" title="Vote down!">down</a>
235    </div>
236    <div title="" class="tally">
237      0
238    </div>
239  </div>
240  <a class="name"><strong class="user"><em>spam () spam ! spam</em></strong></a>
241  <a class="genanchor" href="#"> ¶</a>
242  <div class="date">
243    <strong>
244      1 hour ago
245    </strong>
246  </div>
247  <div class="text">
248    <div class="phpcode">
249      <code><span class="html">egg bacon sausage spam spam baked beans</span></code>
250    </div>
251  </div>
252</div>
253
254</div>
255
256</div>
257</section>
258
259
260<section id="whatnottoenter" class='clearfix'>
261<h3>Thou shall not enter! <small>(No, really, don't)</small></h3>
262<div class='columns'>
263<ul>
264  <li><strong>Bug reports &amp; Missing documentation</strong>
265    Instead <a href="https://github.com/php/doc-<?=clean($_POST['repo'])?>/issues/new?body=From%20manual%20page:%20https:%2F%2Fphp.net%2F<?=clean($_POST['sect'])?>%0A%0A---">report an issue</a>
266  for this manual page.
267  </li>
268  <li><strong>Support questions or request for help</strong> See the <a href="/support.php">support page</a> for available options. In other words, do not ask questions within the user notes.</li>
269  <li><strong>References to other notes or authors</strong>  This is not a forum; we do not encourage nor permit discussions here.  Further, if a note is referenced directly and is later removed or modified it causes confusion.
270  </li>
271  <li><strong>Code collaboration or improvements</strong> This is not to suggest that your code snippet is bad; this is simply not the place to show it off.  You should publish elsewhere (perhaps on your blog).</li>
272  <li><strong>Links to your website, blog, code, or a third-party website</strong> On occasion we permit the posting of websites such as faqs.org or the MySQL manual, but links to other sites will be removed, no matter how well-intended.</li>
273  <li><strong>Complaints that your notes keep getting deleted</strong> Most likely you didn't bother to read this page and you violated one of these rules.</li>
274  <li><strong>Notes in languages other than English</strong> 不 gach duine понимает el lenguaje जिसमें Sie sprechen.</li>
275  <li><strong>Your disdain for PHP and/or its maintainers</strong> Go learn FORTRAN instead.</li>
276</ul>
277</div>
278<p>User notes may be edited or deleted for any reason, whether in the list above or not!</p>
279</section>
280
281
282<div id="email_and_formatting" class="clearfix">
283  <section>
284    <h3>Email address conversion</h3>
285    <p>
286      We have a simple conversion in place to convert the @ signs and dots in your
287      address. You may still want to include a part in the email address
288      that is understandable only by humans as our conversion can be performed in
289      the opposite direction. You may submit your email address as
290      <code>user@NOSPAM.example.com</code> for example (which will be displayed
291      as <code>user at NOSPAM dot example dot com</code>. If we remove your note we can
292      only send an email if you use your real email address.
293    </p>
294  </section>
295  <section>
296    <h3>Formatting</h3>
297    <p>
298      Note that HTML tags are not allowed in the posts, but the note formatting
299      is preserved. URLs will be turned into clickable links, PHP code blocks
300      enclosed in the PHP tags &lt;?php and ?&gt; will
301      be source highlighted automatically. So always enclose PHP snippets in
302      these tags. <em>Double-check that your note appears
303      as you want during the preview; that's why it is there!</em>
304    </p>
305  </section>
306</div>
307
308<div class="row-fluid clearfix">
309<div class="span12">
310<h3>Additional information</h3>
311<p>
312 Please note that periodically the developers go through the notes and
313 may incorporate information from them into the documentation. This means
314 that any note submitted here becomes the property of the PHP Documentation
315 Group and will be available under the <a href="/license/index.php#doc-lic">same license</a> as the documentation.
316</p>
317<p>
318 Your IP Address will be logged with the submitted note and made public on the
319 PHP manual user notes mailing list. The IP address is logged as part of the
320 notes moderation process, and won't be shown within the PHP manual itself.
321</p>
322<p>It may take up to an hour for your note to appear in the documentation.</p>
323<p>
324 The SPAM challenge requires numbers to written out in English, so, an appropriate
325 answer may be <em>nine</em> but not <em>9</em>.
326</p>
327</div>
328</div>
329
330<?php
331}
332
333// If the user name was not specified, provide a default
334if (empty($_POST['user'])) { $_POST['user'] = "user@example.com"; }
335
336// There is no section to add note to
337if (!isset($_POST['sect'], $_POST['redirect'])) {
338    echo '<p class="formerror">To add a note, you must click on the "Add Note" button (the plus sign)  ',
339         'on the bottom of a manual page so we know where to add the note!</p>';
340}
341
342// Everything is in place, so we can display the form
343else {?>
344<form method="post" action="/manual/add-note.php">
345 <p>
346  <input type="hidden" name="sect" value="<?php echo clean($_POST['sect']); ?>">
347  <input type="hidden" name="redirect" value="<?php echo clean($_POST['redirect']); ?>">
348 </p>
349 <table border="0" cellpadding="3" class="standard">
350  <tr>
351   <td colspan="2">
352    <b>
353     <a href="/support.php">Click here to go to the support pages.</a><br>
354     <a href="https://github.com/php/doc-<?=clean($_POST['repo'])?>/issues/new?body=From%20manual%20page:%20https:%2F%2Fphp.net%2F<?=clean($_POST['sect'])?>%0A%0A---">Click here to submit an issue about the documentation.</a><br>
355     <a href="https://github.com/php/php-src/issues/new?body=From%20manual%20page:%20https:%2F%2Fphp.net%2F<?=clean($_POST['sect'])?>%0A%0A---">Click here to submit an issue about PHP itself.</a><br>
356     (Again, please note, if you ask a question, report an issue, or request a feature,
357     your note <i>will be deleted</i>.)
358    </b>
359   </td>
360  </tr>
361  <tr>
362   <th class="subr"><label for="form-user">Your email address</label>:</th>
363   <td><input id="form-user" type="email" name="user" size="60" maxlength="40" required value="<?php echo clean($_POST['user']); ?>"></td>
364  </tr>
365  <tr>
366   <th class="subr"><label for="form-note">Your notes</label>:</th>
367   <td><textarea id="form-note" name="note" rows="20" cols="60" wrap="virtual" required maxlength="4095" minlength="32"><?php if (isset($_POST['note'])) { echo clean($_POST['note']); } ?></textarea>
368   <br>
369  </td>
370  </tr>
371  <tr>
372   <th class="subr"><label for="form-answer">Answer to this simple question (SPAM challenge)</label>:<br>
373   <?php $c = gen_challenge(); echo $c[3]; ?>?</th>
374   <td><input id="form-answer" type="text" name="answer" size="60" maxlength="10" required> (Example: nine)</td>
375  </tr>
376  <tr>
377   <th colspan="2">
378    <input type="hidden" name="func" value="<?php echo $c[0]; ?>">
379    <input type="hidden" name="arga" value="<?php echo $c[1]; ?>">
380    <input type="hidden" name="argb" value="<?php echo $c[2]; ?>">
381    <input type="submit" name="action" value="Preview">
382    <input type="submit" name="action" value="Add Note">
383   </th>
384  </tr>
385 </table>
386</form>
387<?php
388}
389
390// Print out common footer
391site_footer();
392?>
393