Browse Source
Re-written to not require JavaScript or cookies to view or edit. Co-Authored-By: Discomrade <[email protected]>main
PupperWoff
7 years ago
committed by
discomrade
17 changed files with 398 additions and 0 deletions
@ -0,0 +1,155 @@ |
|||
<?php |
|||
|
|||
// Wrap functions in a class so they don't interfere with normal Tinyboard operations |
|||
class Announcements { |
|||
|
|||
static public function new_announcement($announcement, $mod_id = false) { |
|||
global $mod, $config; |
|||
|
|||
if ($mod_id === false) { |
|||
$mod_id = isset($mod['id']) ? $mod['id'] : -1; |
|||
} |
|||
|
|||
$query = prepare("INSERT INTO ``announcements`` VALUES (NULL, :mod, :time, :text)"); |
|||
$query->bindValue(':mod', $mod_id); |
|||
$query->bindValue(':time', time()); |
|||
if ($announcement !== '') { |
|||
$announcement = escape_markup_modifiers($announcement); |
|||
markup($announcement); |
|||
$query->bindValue(':text', $announcement); |
|||
} else |
|||
error(sprintf($config['error']['required'], "Announcement")); |
|||
|
|||
$query->execute() or error(db_error($query)); |
|||
|
|||
modLog("Created a new announcement: " . utf8tohtml($announcement)); |
|||
self::buildAnnouncements(); |
|||
} |
|||
|
|||
static public function edit_announcement($id, $announcement) { |
|||
global $mod, $config; |
|||
|
|||
$query = prepare(sprintf("UPDATE ``announcements`` SET `text` = :text WHERE `id` = %d", (int)$id)); |
|||
if ($announcement !== '') { |
|||
$teannouncementxt = escape_markup_modifiers($announcement); |
|||
markup($announcement); |
|||
$query->bindValue(':text', $announcement); |
|||
} else |
|||
error(sprintf($config['error']['required'], "Announcement")); |
|||
|
|||
$query->execute() or error(db_error($query)); |
|||
|
|||
modLog("Edited announcement #" . $id . " - New Text: " . utf8tohtml($announcement)); |
|||
self::buildAnnouncements(); |
|||
} |
|||
|
|||
static public function delete_announcement($id) { |
|||
$query = prepare(sprintf("DELETE FROM ``announcements`` WHERE `id` = %d", (int)$id)); |
|||
$query->execute() or error(db_error($query)); |
|||
|
|||
modLog("Deleted announcement #" . $id); |
|||
self::buildAnnouncements(); |
|||
} |
|||
|
|||
static public function buildAnnouncements() { |
|||
self::buildShortAnnouncementTable(); |
|||
self::buildAnnouncementPages(); |
|||
} |
|||
|
|||
static public function buildShortAnnouncementTable() { |
|||
global $config; |
|||
|
|||
$count = $config['announcements']['show_count']; |
|||
$query = query("SELECT `text`,`date` FROM ``announcements`` ORDER BY `date` DESC" . (($count === false)?"":" LIMIT " . (int)$count)) or error(db_error($query)); |
|||
$announcements = $query->fetchAll(PDO::FETCH_ASSOC); |
|||
|
|||
foreach ($announcements as &$announce) { |
|||
$announce['date_formated'] = strftime($config['announcements']['date_format'], $announce['date']); |
|||
} |
|||
|
|||
$announcements_short = Element('announcements.html', array( |
|||
'announcements' => $announcements, |
|||
)); |
|||
|
|||
file_write($config['dir']['home'] . "templates/generated/announcements_short.html", $announcements_short); |
|||
} |
|||
|
|||
|
|||
static public function buildAnnouncementPages() { |
|||
global $config; |
|||
|
|||
// Generate page for full list of announcements |
|||
if($config['announcements']['page']) |
|||
{ |
|||
// Generate JSON file for full list of announcements |
|||
//file_write($config['dir']['home'] . "announcements.json", self::gen_public_json($config['announcements']['date_format'], false)); |
|||
|
|||
$query = query("SELECT ``announcements``.* FROM ``announcements`` |
|||
ORDER BY `date` DESC") or error(db_error($query)); |
|||
$announcements = $query->fetchAll(PDO::FETCH_ASSOC); |
|||
|
|||
foreach ($announcements as &$announce) { |
|||
$announce['date_formated'] = strftime($config['announcements']['date_format'], $announce['date']); |
|||
} |
|||
|
|||
// Generate page for full list of announcements |
|||
$announcement_page = Element('page.html', array( |
|||
'config' => $config, |
|||
'mod' => false, |
|||
'hide_dashboard_link' => true, |
|||
'boardlist' => createBoardList(false), |
|||
'title' => _("Announcements"), |
|||
'subtitle' => "", |
|||
'nojavascript' => true, |
|||
'body' => Element('announcements_list.html', array( |
|||
'announcements' => $announcements, |
|||
'mod' => false, |
|||
'token_json' => false, |
|||
)) |
|||
)); |
|||
file_write($config['dir']['home'] . $config['announcements']['page_html'], $announcement_page); |
|||
} |
|||
} |
|||
|
|||
/* Might be used later for mobile API |
|||
static public function stream_json($out = false, $filter_staff = false, $date_format, $count = false) { |
|||
$query = query("SELECT ``announcements``.*, `username` FROM ``announcements`` |
|||
LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` |
|||
ORDER BY `date` DESC" . (($count === false)?"":" LIMIT " . (int)$count)) or error(db_error($query)); |
|||
$announcements = $query->fetchAll(PDO::FETCH_ASSOC); |
|||
|
|||
$out ? fputs($out, "[") : print("["); |
|||
|
|||
// Last entry for json end check |
|||
$end = end($announcements); |
|||
|
|||
foreach ($announcements as &$announce) { |
|||
|
|||
if($filter_staff) |
|||
$announce['username'] = '?'; |
|||
|
|||
$announce['date_formated'] = strftime($date_format, $announce['date']); |
|||
|
|||
$json = json_encode($announce); |
|||
$out ? fputs($out, $json) : print($json); |
|||
|
|||
if ($announce['id'] != $end['id']) { |
|||
$out ? fputs($out, ",") : print(","); |
|||
} |
|||
} |
|||
|
|||
$out ? fputs($out, "]") : print("]"); |
|||
} |
|||
|
|||
// Returns json content to be written to json file. |
|||
static public function gen_public_json($date_format, $count = false) { |
|||
ob_start(); |
|||
self::stream_json(false, true, $date_format, $count); |
|||
$out = ob_get_contents(); |
|||
ob_end_clean(); |
|||
return $out; |
|||
} |
|||
*/ |
|||
}; |
|||
|
|||
?> |
@ -0,0 +1,21 @@ |
|||
<table class="announcements" id="announcements"> |
|||
<thead> |
|||
<tr> |
|||
<td colspan="2"> </td> |
|||
</tr> |
|||
</thead> |
|||
<tbody id="announcements-body"> |
|||
{% for announcement in announcements %} |
|||
<tr> |
|||
<td class="announcement-date">{{ announcement.date_formated }}</td><td class="announcement-content">{{ announcement.text }}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
<tfoot> |
|||
<tr> |
|||
<td colspan="2"> |
|||
<span id="announcements-show-all">[<a href="/announcements.html" target="_blank">Show All</a>]</span> |
|||
</td> |
|||
</tr> |
|||
</tfoot> |
|||
</table> |
@ -0,0 +1,66 @@ |
|||
|
|||
<script src='main.js'></script> |
|||
<script src='js/jquery.min.js'></script> |
|||
<script src='js/mobile-style.js'></script> |
|||
|
|||
{% if mod %} |
|||
<center> |
|||
<p>To remove an announcement, make it empty then press Update.</p> |
|||
<p>You will need to <a href="?/rebuild">{% trans 'Rebuild' %}</a> pages after this to display the new announcements.</p> |
|||
</center> |
|||
<table id="announcements-list" class="announcements-list modlog"> |
|||
<thead> |
|||
<tr> |
|||
<th>Date</th> |
|||
<th>Announcement</th> |
|||
<th>Staff</th> |
|||
<th width='100px'>Action</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
<form style="margin:0" action="" method="post"> |
|||
<input type="hidden" name="id" value="-1"> |
|||
{% if token %} |
|||
<input type="hidden" name="token" value="{{ token }}"> |
|||
{% endif %} |
|||
<tr> |
|||
<td><center>-></center></td> |
|||
<td><input type="text" name="announcement" placeholder="Add a new announcement..." required="required" style="width:100%" value=""></td> |
|||
<td>-</td> |
|||
<td><input type="submit" value="Add new"</input></td> |
|||
</tr> |
|||
</form> |
|||
{% for announcement in announcements %} |
|||
<form style="margin:0" action="" method="post"> |
|||
<input type="hidden" name="id" value="{{ announcement.id }}"> |
|||
{% if token %} |
|||
<input type="hidden" name="token" value="{{ token }}"> |
|||
{% endif %} |
|||
<tr> |
|||
<td><center>{{ announcement.date_formated }}</center></td> |
|||
<td><input type="text" name="announcement" style="width:100%" value="{{ announcement.text }}"></td> |
|||
<td><a href='?/new_PM/{{ announcement.username }}'>{{ announcement.username }}</td> |
|||
<td><input type="submit" value="Update"</input></td> |
|||
</tr> |
|||
</form> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
{% else %} |
|||
<table id="announcements-list" class="announcements-list modlog"> |
|||
<thead> |
|||
<tr> |
|||
<th>Date</th> |
|||
<th>Announcement</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for announcement in announcements %} |
|||
<tr> |
|||
<td>{{ announcement.date_formated }}</td> |
|||
<td>{{ announcement.text }}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
{% endif %} |
Loading…
Reference in new issue