mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-30 18:24:29 +01:00
news
This commit is contained in:
parent
99b1ffe35a
commit
d17e756881
@ -402,6 +402,12 @@
|
||||
$config['mod']['public_ban'] = MOD;
|
||||
// Manage and install themes for homepage
|
||||
$config['mod']['themes'] = ADMIN;
|
||||
// Post news entries
|
||||
$config['mod']['news'] = ADMIN;
|
||||
// Custom name when posting news
|
||||
$config['mod']['news_custom'] = ADMIN;
|
||||
// Delete news entries
|
||||
$config['mod']['news_delete'] = ADMIN;
|
||||
|
||||
// Mod links (full HTML)
|
||||
// Correspond to above permission directives
|
||||
|
36
install.sql
36
install.sql
@ -247,3 +247,39 @@ CREATE TABLE IF NOT EXISTS `robot` (
|
||||
-- Dumping data for table `robot`
|
||||
--
|
||||
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `theme_settings`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `theme_settings` (
|
||||
`name` varchar(40) NOT NULL,
|
||||
`value` text,
|
||||
UNIQUE KEY `name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Dumping data for table `theme_settings`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `news`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `news` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` text 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=1 ;
|
||||
|
||||
--
|
||||
-- Dumping data for table `news`
|
||||
--
|
||||
|
||||
|
79
mod.php
79
mod.php
@ -135,6 +135,8 @@
|
||||
' <strong>(' . $count . ' unread)</strong>'
|
||||
: '') .
|
||||
'</a></li>';
|
||||
|
||||
$fieldset['Noticeboard'] .= '<li><a href="?/news">News</a></li>';
|
||||
}
|
||||
|
||||
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 .= '<fieldset><legend>New post</legend><form style="display:inline" action="" method="post"><table>' .
|
||||
'<tr>' .
|
||||
'<th><label for="subject">Name</label></th>' .
|
||||
($mod['type'] >= $config['mod']['news_custom'] ?
|
||||
'<td><input type="text" size="55" name="subject" id="subject" value="' . htmlentities($mod['username']) . '" /></td>'
|
||||
:
|
||||
'<td>' . $mod['username'] . '</td>') .
|
||||
'</tr><tr>' .
|
||||
'<th>Subject</th>' .
|
||||
'<td><input type="text" size="55" name="subject" id="subject" /></td>' .
|
||||
'</tr><tr>' .
|
||||
'<th>Body</th>' .
|
||||
'<td><textarea name="body" style="width:100%;height:100px"></textarea></td>' .
|
||||
'</tr><tr>' .
|
||||
'<td></td><td><input type="submit" value="Post to news" /></td>' .
|
||||
'</tr></table>' .
|
||||
'</form></fieldset>';
|
||||
}
|
||||
|
||||
$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 .= '<div class="ban">' .
|
||||
($mod['type'] >= $config['mod']['news_delete'] ?
|
||||
'<span style="float:right;padding:2px"><a class="unimportant" href="?/news/delete/' . $news['id'] . '">[delete]</a></span>'
|
||||
: '') .
|
||||
'<h2 id="' . $news['id'] . '">' .
|
||||
($news['subject'] ?
|
||||
$news['subject']
|
||||
:
|
||||
'<em>no subject</em>'
|
||||
) .
|
||||
'<span class="unimportant"> — by ' .
|
||||
$news['name'] .
|
||||
' at ' .
|
||||
date($config['post_date'], $news['time']) .
|
||||
'</span></h2><p>' . $news['body'] . '</p></div>';
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
@ -12,12 +12,19 @@ Users never have to leave the homepage; they can do all their browsing from the
|
||||
|
||||
// Theme configuration
|
||||
$theme['config'] = Array();
|
||||
|
||||
$theme['config'][] = Array(
|
||||
'title' => 'Page title',
|
||||
'title' => 'Title',
|
||||
'name' => 'title',
|
||||
'type' => 'text'
|
||||
);
|
||||
|
||||
$theme['config'][] = Array(
|
||||
'title' => 'Slogan',
|
||||
'name' => 'subtitle',
|
||||
'type' => 'text'
|
||||
);
|
||||
|
||||
// Unique function name for building everything
|
||||
$config['build_function'] = 'frameset_build';
|
||||
|
||||
@ -32,6 +39,7 @@ Users never have to leave the homepage; they can do all their browsing from the
|
||||
|
||||
file_put_contents($config['dir']['home'] . $config['file_index'], Frameset::homepage($settings));
|
||||
file_put_contents($config['dir']['home'] . 'sidebar.html', Frameset::sidebar($settings));
|
||||
file_put_contents($config['dir']['home'] . 'news.html', Frameset::news($settings));
|
||||
}
|
||||
|
||||
// Build homepage
|
||||
@ -52,11 +60,52 @@ Users never have to leave the homepage; they can do all their browsing from the
|
||||
// Sidebar
|
||||
. '<iframe src="sidebar.html" id="sidebar"></iframe>'
|
||||
// Main
|
||||
. '<iframe src="b" id="main"></iframe>'
|
||||
. '<iframe src="news.html" id="main"></iframe>'
|
||||
// Finish page
|
||||
. '</body></html>';
|
||||
}
|
||||
|
||||
// Build news page
|
||||
public static function news($settings) {
|
||||
global $config;
|
||||
|
||||
// HTML5
|
||||
$body = '<!DOCTYPE html><html>'
|
||||
. '<head>'
|
||||
. '<link rel="stylesheet" media="screen" href="' . $config['url_stylesheet'] . '"/>'
|
||||
. '<title>News</title>'
|
||||
. '</head><body>';
|
||||
|
||||
$body .= '<h1>' . $settings['title'] . '</h1>'
|
||||
. '<div class="title">' . ($settings['subtitle'] ? utf8tohtml($settings['subtitle']) : '') . '</div>';
|
||||
|
||||
$query = query("SELECT * FROM `news` ORDER BY `time` DESC") or error(db_error());
|
||||
if($query->rowCount() == 0) {
|
||||
$body .= '<p style="text-align:center" class="unimportant">(No news to show.)</p>';
|
||||
} else {
|
||||
// List news
|
||||
while($news = $query->fetch()) {
|
||||
$body .= '<div class="ban">' .
|
||||
'<h2 id="' . $news['id'] . '">' .
|
||||
($news['subject'] ?
|
||||
$news['subject']
|
||||
:
|
||||
'<em>no subject</em>'
|
||||
) .
|
||||
'<span class="unimportant"> — by ' .
|
||||
$news['name'] .
|
||||
' at ' .
|
||||
date($config['post_date'], $news['time']) .
|
||||
'</span></h2><p>' . $news['body'] . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Finish page
|
||||
$body .= '</body></html>';
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
// Build sidebar
|
||||
public static function sidebar($settings) {
|
||||
global $config, $board;
|
||||
|
Loading…
Reference in New Issue
Block a user