From 91602f4e84f9c900da41e435db6b80a79c8a55e7 Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 18 Aug 2014 16:35:47 +0200 Subject: [PATCH 1/3] modified install script a bit --- install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.php b/install.php index 042c036..e091dfa 100644 --- a/install.php +++ b/install.php @@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS `words` ( `word3` VARCHAR(45) NULL, `author` VARCHAR(45) NULL, `new` BOOLEAN, - `created_at` TIMESTAMP NULL, + `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; From 06f84a881b7b3c43a33b70c9aad1d17073fa1e39 Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 18 Aug 2014 16:43:48 +0200 Subject: [PATCH 2/3] the recent list can now be shown public --- config.php | 11 +++++++++++ index.php | 18 ++++++++++++++++++ views/index.html | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config.php b/config.php index 2d75ee9..0ca918f 100644 --- a/config.php +++ b/config.php @@ -72,6 +72,15 @@ if (!isset($notemplate)) { $res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"username\";")->fetch_assoc(); $user_name = htmlspecialchars($res['value']); + // show recent? + $res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_public\";")->fetch_assoc(); + $recent_public = $res['value'] === "true" ? true : false; + $recent_count = 0; + if ($recent_public) { + $res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_public\";")->fetch_assoc(); + $recent_count = (int) $res['value']; + } + // the flash $message = null; if (isset($_SESSION['flash'])) { @@ -84,5 +93,7 @@ if (!isset($notemplate)) { $tpl->assign("user_name", $user_name); $tpl->assign("words_total", $words_total_count); $tpl->assign("inbox_count", $new_words_count); + $tpl->assign("recent_public", $recent_public); + $tpl->assign("recent_count", $recent_count); $tpl->assign("message", $message); } \ No newline at end of file diff --git a/index.php b/index.php index 8083457..5366fa7 100644 --- a/index.php +++ b/index.php @@ -64,4 +64,22 @@ if (isset($_POST['words'])) { exit(); } +$words = array(); + +if ($recent_public) { + $sql_str = "SELECT `word1`, `word2`, `word3`, `author`, `new` FROM `words` ORDER BY `id` DESC LIMIT " . $recent_count . ";"; + $res = $sql->query($sql_str); + + while ($r = $res->fetch_assoc()) { + array_push($words, array( + "word1" => $r['word1'], + "word2" => $r['word2'], + "word3" => $r['word3'], + "author" => $r['author'], + "new" => ($r['new'] == 1 ? true : false) + )); + } +} + +$tpl->assign("words", $words); $tpl->draw("index"); \ No newline at end of file diff --git a/views/index.html b/views/index.html index 9f50735..3c056bf 100644 --- a/views/index.html +++ b/views/index.html @@ -25,11 +25,11 @@ -{if="$recent_answers"} +{if="$recent_public"}

Recent Answers by others:

- {loop="$recent"} + {loop="$words"} From 95c4db170369fc5edd52d9277936175e39c5816c Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 18 Aug 2014 16:46:14 +0200 Subject: [PATCH 3/3] bugFuchs --- config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.php b/config.php index 0ca918f..c489355 100644 --- a/config.php +++ b/config.php @@ -77,7 +77,7 @@ if (!isset($notemplate)) { $recent_public = $res['value'] === "true" ? true : false; $recent_count = 0; if ($recent_public) { - $res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_public\";")->fetch_assoc(); + $res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_count\";")->fetch_assoc(); $recent_count = (int) $res['value']; }
{$value.author} wrote that {$user_name} is {$value.word1}, {$value.word2} and {$value.word3}