Gazelle/sections/blog/index.php

175 lines
6.0 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
enforce_login();
define('ANNOUNCEMENT_FORUM_ID', 19);
2012-10-11 08:00:15 +00:00
View::show_header('Blog','bbcode');
2011-03-28 14:21:28 +00:00
require(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
2013-04-19 08:00:55 +00:00
if (check_perms('admin_manage_blog')) {
if (!empty($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
2011-03-28 14:21:28 +00:00
case 'deadthread' :
2013-04-20 08:01:01 +00:00
if (is_number($_GET['id'])) {
2011-03-28 14:21:28 +00:00
$DB->query("UPDATE blog SET ThreadID=NULL WHERE ID=".$_GET['id']);
$Cache->delete_value('blog');
$Cache->delete_value('feed_blog');
}
header('Location: blog.php');
break;
case 'takeeditblog':
authorize();
2013-04-20 08:01:01 +00:00
if (is_number($_POST['blogid']) && is_number($_POST['thread'])) {
2011-03-28 14:21:28 +00:00
$DB->query("UPDATE blog SET Title='".db_string($_POST['title'])."', Body='".db_string($_POST['body'])."', ThreadID=".$_POST['thread']." WHERE ID='".db_string($_POST['blogid'])."'");
$Cache->delete_value('blog');
$Cache->delete_value('feed_blog');
}
header('Location: blog.php');
break;
case 'editblog':
2013-04-20 08:01:01 +00:00
if (is_number($_GET['id'])) {
2011-03-28 14:21:28 +00:00
$BlogID = $_GET['id'];
$DB->query("SELECT Title, Body, ThreadID FROM blog WHERE ID=$BlogID");
list($Title, $Body, $ThreadID) = $DB->next_record();
}
break;
case 'deleteblog':
2013-04-20 08:01:01 +00:00
if (is_number($_GET['id'])) {
2011-03-28 14:21:28 +00:00
authorize();
$DB->query("DELETE FROM blog WHERE ID='".db_string($_GET['id'])."'");
$Cache->delete_value('blog');
$Cache->delete_value('feed_blog');
}
header('Location: blog.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'takenewblog':
authorize();
$Title = db_string($_POST['title']);
$Body = db_string($_POST['body']);
$ThreadID = $_POST['thread'];
2013-04-19 08:00:55 +00:00
if ($ThreadID && is_number($ThreadID)) {
2011-03-28 14:21:28 +00:00
$DB->query("SELECT ForumID FROM forums_topics WHERE ID=".$ThreadID);
2013-04-19 08:00:55 +00:00
if ($DB->record_count() < 1) {
2011-03-28 14:21:28 +00:00
error("No such thread exists!");
header('Location: blog.php');
2013-02-22 08:00:24 +00:00
}
2011-03-28 14:21:28 +00:00
} else {
2012-10-11 08:00:15 +00:00
$ThreadID = Misc::create_thread(ANNOUNCEMENT_FORUM_ID, $LoggedUser[ID], $Title, $Body);
2013-04-19 08:00:55 +00:00
if ($ThreadID < 1) {
2011-03-28 14:21:28 +00:00
error(0);
}
}
2013-02-22 08:00:24 +00:00
$DB->query("INSERT INTO blog (UserID, Title, Body, Time, ThreadID, Important)
2013-04-19 08:00:55 +00:00
VALUES ('".$LoggedUser['ID']."',
'".db_string($_POST['title'])."',
'".db_string($_POST['body'])."',
'".sqltime()."',
$ThreadID,
'".(($_POST['important'] == '1') ? '1' : '0')."')");
2011-03-28 14:21:28 +00:00
$Cache->delete_value('blog');
2013-04-19 08:00:55 +00:00
if ($_POST['important'] == '1') {
2012-05-29 08:00:10 +00:00
$Cache->delete_value('blog_latest_id');
}
2013-04-19 08:00:55 +00:00
if (isset($_POST['subscribe'])) {
2011-03-28 14:21:28 +00:00
$DB->query("INSERT IGNORE INTO users_subscriptions VALUES ('$LoggedUser[ID]', $ThreadID)");
$Cache->delete_value('subscriptions_user_'.$LoggedUser['ID']);
}
2012-08-04 08:00:19 +00:00
2011-03-28 14:21:28 +00:00
header('Location: blog.php');
break;
}
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
?>
<div class="box thin">
<div class="head">
<?=((empty($_GET['action'])) ? 'Create a blog post' : 'Edit blog post')?>
</div>
2012-09-15 08:00:25 +00:00
<form class="<?=empty($_GET['action'])?'create_form':'edit_form'?>" name="blog_post" action="blog.php" method="post">
2011-03-28 14:21:28 +00:00
<div class="pad">
<input type="hidden" name="action" value="<?=((empty($_GET['action'])) ? 'takenewblog' : 'takeeditblog')?>" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
2013-04-20 08:01:01 +00:00
<? if (!empty($_GET['action']) && $_GET['action'] == 'editblog') { ?>
2011-03-28 14:21:28 +00:00
<input type="hidden" name="blogid" value="<?=$BlogID; ?>" />
2013-04-19 08:00:55 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
<h3>Title</h3>
2013-04-19 08:00:55 +00:00
<input type="text" name="title" size="95"<? if (!empty($Title)) { echo ' value="'.display_str($Title).'"'; } ?> /><br />
2011-03-28 14:21:28 +00:00
<h3>Body</h3>
2013-04-19 08:00:55 +00:00
<textarea name="body" cols="95" rows="15"><? if (!empty($Body)) { echo display_str($Body); } ?></textarea> <br />
<input type="checkbox" value="1" name="important" id="important"<?=$Important ? ' checked="checked"' : '' ?> /><label for="important">Important</label><br />
2011-03-28 14:21:28 +00:00
<h3>Thread ID</h3>
2013-04-19 08:00:55 +00:00
<input type="text" name="thread" size="8"<? if (!empty($ThreadID)) { echo ' value="'.display_str($ThreadID).'"'; } ?> />
2011-03-28 14:21:28 +00:00
(Leave blank to create thread automatically)
<br /><br />
2013-04-19 08:00:55 +00:00
<input id="subscribebox" type="checkbox" name="subscribe"<?=!empty($HeavyInfo['AutoSubscribe']) ? ' checked="checked"' : '' ?> tabindex="2" />
2011-03-28 14:21:28 +00:00
<label for="subscribebox">Subscribe</label>
2012-08-03 08:00:17 +00:00
2011-03-28 14:21:28 +00:00
<div class="center">
<input type="submit" value="<?=((!isset($_GET['action'])) ? 'Create blog post' : 'Edit blog post') ?>" />
</div>
</div>
</form>
</div>
<br />
2013-02-22 08:00:24 +00:00
<?
2011-03-28 14:21:28 +00:00
}
?>
<div class="thin">
<?
if (!$Blog = $Cache->get_value('blog')) {
$DB->query("SELECT
2013-04-19 08:00:55 +00:00
b.ID,
um.Username,
b.Title,
b.Body,
b.Time,
b.ThreadID
FROM blog AS b
LEFT JOIN users_main AS um ON b.UserID=um.ID
2011-03-28 14:21:28 +00:00
ORDER BY Time DESC
LIMIT 20");
$Blog = $DB->to_array();
$Cache->cache_value('Blog',$Blog,1209600);
}
2012-05-29 08:00:10 +00:00
if ($LoggedUser['LastReadBlog'] < $Blog[0][0]) {
$Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
$Cache->update_row(false, array('LastReadBlog' => $Blog[0][0]));
$Cache->commit_transaction(0);
$DB->query("UPDATE users_info SET LastReadBlog = '".$Blog[0][0]."' WHERE UserID = ".$LoggedUser['ID']);
$LoggedUser['LastReadBlog'] = $Blog[0][0];
}
2011-03-28 14:21:28 +00:00
foreach ($Blog as $BlogItem) {
list($BlogID, $Author, $Title, $Body, $BlogTime, $ThreadID) = $BlogItem;
?>
<div id="blog<?=$BlogID?>" class="box">
<div class="head">
<strong><?=$Title?></strong> - posted <?=time_diff($BlogTime);?> by <?=$Author?>
2013-04-19 08:00:55 +00:00
<? if (check_perms('admin_manage_blog')) { ?>
2013-02-09 08:01:01 +00:00
- <a href="blog.php?action=editblog&amp;id=<?=$BlogID?>" class="brackets">Edit</a>
<a href="blog.php?action=deleteblog&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Delete</a>
2013-04-19 08:00:55 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</div>
<div class="pad">
<?=$Text->full_format($Body)?>
2013-04-19 08:00:55 +00:00
<? if ($ThreadID) { ?>
2011-03-28 14:21:28 +00:00
<br /><br />
2012-09-09 08:00:26 +00:00
<em><a href="forums.php?action=viewthread&amp;threadid=<?=$ThreadID?>">Discuss this post here</a></em>
2013-04-19 08:00:55 +00:00
<? if (check_perms('admin_manage_blog')) { ?>
2013-02-09 08:01:01 +00:00
<a href="blog.php?action=deadthread&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Remove link</a>
2013-04-19 08:00:55 +00:00
<? }
2011-03-28 14:21:28 +00:00
} ?>
</div>
</div>
<br />
2013-02-22 08:00:24 +00:00
<?
2011-03-28 14:21:28 +00:00
}
?>
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
?>