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 ;
if ( check_perms ( 'admin_manage_blog' )) {
if ( ! empty ( $_REQUEST [ 'action' ])) {
switch ( $_REQUEST [ 'action' ]) {
case 'deadthread' :
if ( is_number ( $_GET [ 'id' ])){
$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 ();
if ( is_number ( $_POST [ 'blogid' ]) && is_number ( $_POST [ 'thread' ])){
$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' :
if ( is_number ( $_GET [ 'id' ])){
$BlogID = $_GET [ 'id' ];
$DB -> query ( " SELECT Title, Body, ThreadID FROM blog WHERE ID= $BlogID " );
list ( $Title , $Body , $ThreadID ) = $DB -> next_record ();
}
break ;
case 'deleteblog' :
if ( is_number ( $_GET [ 'id' ])){
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 ;
case 'takenewblog' :
authorize ();
$Title = db_string ( $_POST [ 'title' ]);
$Body = db_string ( $_POST [ 'body' ]);
$ThreadID = $_POST [ 'thread' ];
if ( $ThreadID && is_number ( $ThreadID )) {
$DB -> query ( " SELECT ForumID FROM forums_topics WHERE ID= " . $ThreadID );
if ( $DB -> record_count () < 1 ) {
error ( " No such thread exists! " );
header ( 'Location: blog.php' );
}
} else {
2012-10-11 08:00:15 +00:00
$ThreadID = Misc :: create_thread ( ANNOUNCEMENT_FORUM_ID , $LoggedUser [ ID ], $Title , $Body );
2011-03-28 14:21:28 +00:00
if ( $ThreadID < 1 ) {
error ( 0 );
}
}
2012-05-29 08:00:10 +00:00
$DB -> query ( " INSERT INTO blog (UserID, Title, Body, Time, ThreadID, Important)
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' );
2012-05-29 08:00:10 +00:00
if ( $_POST [ 'important' ] == '1' ) {
$Cache -> delete_value ( 'blog_latest_id' );
}
2011-03-28 14:21:28 +00:00
if ( isset ( $_POST [ 'subscribe' ])) {
$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 ;
}
}
?>
< 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'] ?> " />
< ? if ( ! empty ( $_GET [ 'action' ]) && $_GET [ 'action' ] == 'editblog' ){ ?>
< input type = " hidden " name = " blogid " value = " <?= $BlogID ; ?> " />
< ? } ?>
< h3 > Title </ h3 >
< input type = " text " name = " title " size = " 95 " < ? if ( ! empty ( $Title )) { echo 'value="' . display_str ( $Title ) . '"' ; } ?> /><br />
< h3 > Body </ h3 >
< textarea name = " body " cols = " 95 " rows = " 15 " >< ? if ( ! empty ( $Body )) { echo display_str ( $Body ); } ?> </textarea> <br />
2012-05-29 08:00:10 +00:00
< input type = " checkbox " value = '1' name = " important " id = " important " < ? = $Important ? 'checked' : '' ?> /><label for="important">Important</label><br />
2011-03-28 14:21:28 +00:00
< h3 > Thread ID </ h3 >
< input type = " text " name = " thread " size = " 8 " < ? if ( ! empty ( $ThreadID )) { echo 'value="' . display_str ( $ThreadID ) . '"' ; } ?> />
( Leave blank to create thread automatically )
< br />< br />
< input id = " subscribebox " type = " checkbox " name = " subscribe " < ? =! empty ( $HeavyInfo [ 'AutoSubscribe' ]) ? ' checked="checked"' : '' ?> tabindex="2" />
< 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 />
< ?
}
?>
< div class = " thin " >
< ?
if ( ! $Blog = $Cache -> get_value ( 'blog' )) {
$DB -> query ( " SELECT
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
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?>
< ? if ( check_perms ( 'admin_manage_blog' )) { ?>
- < a href = " blog.php?action=editblog&id=<?= $BlogID ?> " > [ Edit ] </ a >
< a href = " blog.php?action=deleteblog&id=<?= $BlogID ?>&auth=<?= $LoggedUser['AuthKey'] ?> " > [ Delete ] </ a >
< ? } ?>
</ div >
< div class = " pad " >
< ? = $Text -> full_format ( $Body ) ?>
< ? if ( $ThreadID ) { ?>
< br />< br />
2012-09-09 08:00:26 +00:00
< em >< a href = " forums.php?action=viewthread&threadid=<?= $ThreadID ?> " > Discuss this post here </ a ></ em >
2011-03-28 14:21:28 +00:00
< ? if ( check_perms ( 'admin_manage_blog' )) { ?>
2012-07-17 08:00:18 +00:00
< a href = " blog.php?action=deadthread&id=<?= $BlogID ?>&auth=<?= $LoggedUser['AuthKey'] ?> " > [ Remove link ] </ a >
2011-03-28 14:21:28 +00:00
< ? }
} ?>
</ div >
</ div >
< br />
< ?
}
?>
</ div >
< ?
2012-10-11 08:00:15 +00:00
View :: show_footer ();
2011-03-28 14:21:28 +00:00
?>