config.php ignored now, fix weirdo DBO issue
[miniqdb.git] / submitbulk.php
blob06e7a212c03aa49515be5af7331359f1cb3b45d1
1 <?php
3 /* miniqdb - A minimalistic quote database
4 Copyright (C) 2008 Ian Weller <ianweller@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
20 require "header.php";
22 // Gets args from POST
23 $quote = stripslashes_if_gpc_magic_quotes($_POST["quote"]);
25 // Explode that text.
26 $kaboom = explode("\r\n\r\n", $quote);
28 $ids = array();
30 foreach($kaboom as $quote) {
32 global $ids;
34 // Replace IRC "<" and ">" characters with the HTML equivalent.
35 // Then strip newlines from the top and bottom of the quote.
36 $quote_lt = ereg_replace('<', '&lt;' , $quote);
37 $quote_gt = ereg_replace('>', '&gt;' , $quote_lt);
38 $quote_lb = trim($quote_gt);
40 // Check to make sure we have contents being put in the database, otherwise
41 // an empty quote will occur
42 if (strlen($quote_lb) <= 0) {
43 continue;
46 // Insert into database as new. We leave out ID number cause the
47 // database will autoincrement that field by itself.
49 $st = $db->prepare('INSERT INTO miniqdb (epoch,quote) VALUES (?,?)');
50 $st->execute(array(date('U'), $quote_lb));
51 $ids[] = $db->lastInsertId();
55 $qcount = count($ids);
56 if ($qcount == 0) {
57 echo "<p>No quote was submitted.</p>";
58 } else {
59 echo "<p>$qcount quotes posted</p>";
60 echo "<p>The following $qcount quotes were added:</p>";
61 foreach($ids as $id) {
62 $idstrs[] = "<a href=\"quote.php?id=$id\">$id</a>";
64 $quotes = implode(' ', $idstrs);
65 echo "<p>$quotes</p>";
66 echo "<p><a href=\"index.php\">Go back to the QDB</a></p>";
69 echo $footer;