From e978bfd2b01e249cb4debf0bf4c610a049d0e627 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 30 Mar 2011 21:47:06 +1100 Subject: [PATCH] Moderator noticeboard --- inc/config.php | 8 +++++ install.sql | 19 ++++++++++++ mod.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/inc/config.php b/inc/config.php index 710edced..f2aa74f1 100644 --- a/inc/config.php +++ b/inc/config.php @@ -252,6 +252,8 @@ $config['mod']['modlog_page'] = 350; // Maximum number of results to display for a search, per board $config['mod']['search_results'] = 75; + // Maximum number of notices to display on the moderator noticeboard + $config['mod']['noticeboard_display'] = 50; // Probably best not to change these: if(!defined('JANITOR')) { @@ -337,6 +339,12 @@ $config['mod']['rebuild'] = ADMIN; // Search through posts $config['mod']['search'] = JANITOR; + // Read the moderator noticeboard + $config['mod']['noticeboard'] = JANITOR; + // Post to the moderator noticeboard + $config['mod']['noticeboard_post'] = MOD; + // Delete entries from the noticeboard + $config['mod']['noticeboard_delete'] = ADMIN; // Wait indefinitely when rebuilding everything $config['mod']['rebuild_timelimit'] = 0; diff --git a/install.sql b/install.sql index 6123bc6c..a20b1451 100644 --- a/install.sql +++ b/install.sql @@ -204,3 +204,22 @@ CREATE TABLE IF NOT EXISTS `robot` ( -- Dumping data for table `robot` -- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `noticeboard` +-- + +CREATE TABLE IF NOT EXISTS `noticeboard` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `mod` int(11) NOT NULL, + `time` int(11) NOT NULL, + `subject` text NOT NULL, + `body` text NOT NULL, + UNIQUE KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ; + +-- +-- Dumping data for table `noticeboard` +-- diff --git a/mod.php b/mod.php index 948e8b88..a15c6a3f 100644 --- a/mod.php +++ b/mod.php @@ -78,6 +78,7 @@ // Dashboard $fieldset = Array( 'Boards' => '', + 'Noticeboard' => '', 'Administration' => '', 'Search' => '', 'Logout' => '' @@ -86,6 +87,10 @@ // Boards $fieldset['Boards'] .= ulBoards(); + if($mod['type'] >= $config['mod']['noticeboard']) { + $fieldset['Noticeboard'] .= '
  • View previous entries
  • '; + } + if($mod['type'] >= $config['mod']['reports']) { $fieldset['Administration'] .= '
  • Report queue
  • '; } @@ -178,6 +183,83 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/noticeboard\/delete\/(\d+)$/', $query, $match)) { + if($mod['type'] < $config['mod']['noticeboard_delete']) error($config['error']['noaccess']); + + $query = prepare("DELETE FROM `noticeboard` WHERE `id` = :id"); + $query->bindValue(':id', $match[1], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + header('Location: ?/noticeboard', true, $config['redirect_http']); + } elseif(preg_match('/^\/noticeboard$/', $query)) { + if($mod['type'] < $config['mod']['noticeboard']) error($config['error']['noaccess']); + + $body = ''; + + if($mod['type'] >= $config['mod']['noticeboard_post']) { + if(isset($_POST['subject']) && isset($_POST['body'])) { + $query = prepare("INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)"); + $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); + $query->bindvalue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':subject', utf8tohtml($_POST['subject'])); + + markup($_POST['body']); + $query->bindValue(':body', $_POST['body']); + $query->execute() or error(db_error($query)); + } + + $body .= '
    New post
    ' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
    ' . $mod['username'] . '
    Subject
    Body
    ' . + '
    '; + } + + $query = prepare("SELECT * FROM `noticeboard` ORDER BY `id` DESC LIMIT :limit"); + $query->bindValue(':limit', $config['mod']['noticeboard_display'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + while($notice = $query->fetch()) { + $m_query = prepare("SELECT `username` FROM `mods` WHERE `id` = :id"); + $m_query->bindValue(':id', $notice['mod'], PDO::PARAM_INT); + $m_query->execute() or error(db_error($m_query)); + if(!$_mod = $m_query->fetch()) { + $_mod = Array('username' => '???'); + } + + $body .= '
    ' . + ($mod['type'] >= $config['mod']['noticeboard_delete'] ? + '[delete]' + : '') . + '

    ' . + ($notice['subject'] ? + $notice['subject'] + : + 'no subject' + ) . + ' — by ' . + $_mod['username'] . + ' at ' . + date($config['post_date'], $notice['time']) . + '

    ' . $notice['body'] . '

    '; + } + + + echo Element('page.html', Array( + 'config'=>$config, + 'title'=>'Noticeboard', + 'body'=>$body, + 'mod'=>true + ) + ); } elseif(preg_match('/^\/PM\/(\d+)$/', $query, $match)) { $id = $match[1];