From d17e756881e009031519ae7e62361cefe0442daf Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 14 Apr 2011 00:24:49 +1000 Subject: news --- mod.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 3f0ad157..908bc167 100644 --- a/mod.php +++ b/mod.php @@ -135,6 +135,8 @@ ' (' . $count . ' unread)' : '') . ''; + + $fieldset['Noticeboard'] .= '
  • News
  • '; } if($mod['type'] >= $config['mod']['reports']) { @@ -449,6 +451,83 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/news\/delete\/(\d+)$/', $query, $match)) { + if($mod['type'] < $config['mod']['noticeboard_delete']) error($config['error']['noaccess']); + + $query = prepare("DELETE FROM `news` WHERE `id` = :id"); + $query->bindValue(':id', $match[1], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + header('Location: ?/news', true, $config['redirect_http']); + } elseif(preg_match('/^\/news$/', $query)) { + $body = ''; + + if($mod['type'] >= $config['mod']['news']) { + if(isset($_POST['subject']) && isset($_POST['body']) && !empty($_POST['body'])) { + $query = prepare("INSERT INTO `news` VALUES (NULL, :name, :time, :subject, :body)"); + + if(isset($_POST['name']) && $mod['type'] >= $config['mod']['news_custom']) + $name = $_POST['name']; + else + $name = $mod['username']; + + $query->bindValue(':name', utf8tohtml($name), 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['type'] >= $config['mod']['news_custom'] ? + '' + : + '') . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
    ' . $mod['username'] . '
    Subject
    Body
    ' . + '
    '; + } + + $query = prepare("SELECT * FROM `news` ORDER BY `id` DESC LIMIT :limit"); + $query->bindValue(':limit', $config['mod']['noticeboard_display'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + while($news = $query->fetch()) { + $body .= '
    ' . + ($mod['type'] >= $config['mod']['news_delete'] ? + '[delete]' + : '') . + '

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

    ' . $news['body'] . '

    '; + } + + + echo Element('page.html', Array( + 'config'=>$config, + 'title'=>'News', + 'body'=>$body, + 'mod'=>true + ) + ); } elseif(preg_match('/^\/inbox$/', $query, $match)) { $query = prepare("SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC"); $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); -- cgit v1.3