You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
5.5 KiB
164 lines
5.5 KiB
<?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 pages 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,
|
|
'uri_json' => $config['root'] . $config['announcements']['file_json'],
|
|
))
|
|
));
|
|
file_write($config['dir']['home'] . $config['announcements']['page_html'], $announcement_page);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static public function stream_json($out = false, $filter_staff = false, $date_format = "%m/%d/%Y", $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);
|
|
}
|
|
/* 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;
|
|
}
|
|
*/
|
|
};
|
|
|
|
?>
|