the recent list can now be shown public

This commit is contained in:
nilsding 2014-08-18 16:43:48 +02:00
parent 91602f4e84
commit 06f84a881b
3 changed files with 31 additions and 2 deletions

View File

@ -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);
}

View File

@ -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");

View File

@ -25,11 +25,11 @@
</div>
<input type="hidden" name="words">
</form>
{if="$recent_answers"}
{if="$recent_public"}
<h4>Recent Answers by others:</h4>
<table class="table table-responsive table-bordered table-condensed">
<tbody>
{loop="$recent"}
{loop="$words"}
<tr>
<td><b>{$value.author}</b> wrote that {$user_name} is <span class="label label-default">{$value.word1}</span>, <span class="label label-default">{$value.word2}</span> and <span class="label label-default">{$value.word3}</span></td>
</tr>