2003-07-19 00:26:18 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2007-07-08 12:31:13 +00:00
2007-11-12 20:57:15 +00:00
// Using this page you can edit a post.
// First it displays a box to edit in, and when you submit the changes
// it will call the methods on the post to make the changes.
//
2003-08-13 22:08:12 +00:00
2004-02-02 23:34:39 +00:00
require_once ( '../inc/forum.inc' );
2009-06-23 17:15:17 +00:00
require_once ( '../inc/bbcode_html.inc' );
2004-12-27 03:42:11 +00:00
2011-02-09 22:11:34 +00:00
check_get_args ( array ( " id " , " tnow " , " ttok " ));
2007-11-12 20:57:15 +00:00
$logged_in_user = get_logged_in_user ();
BoincForumPrefs :: lookup ( $logged_in_user );
2005-01-18 13:00:38 +00:00
2005-02-13 21:33:02 +00:00
$postid = get_int ( " id " );
2007-11-12 20:57:15 +00:00
$post = BoincPost :: lookup_id ( $postid );
2007-11-14 22:49:31 +00:00
if ( ! $post ) error_page ( " no such post " );
2007-11-12 20:57:15 +00:00
$thread = BoincThread :: lookup_id ( $post -> thread );
2007-11-14 22:49:31 +00:00
if ( ! $thread ) error_page ( " no such thread " );
2007-11-15 22:51:05 +00:00
$forum = BoincForum :: lookup_id ( $thread -> forum );
2006-06-16 23:53:56 +00:00
2007-11-15 22:51:05 +00:00
if ( ! is_moderator ( $logged_in_user , $forum )) {
if ( time () > $post -> timestamp + MAXIMUM_EDIT_TIME ) {
2011-08-25 22:12:48 +00:00
error_page ( tra ( " You can no longer edit this post.<br/>Posts can only be edited at most %1 minutes after they have been created. " , ( MAXIMUM_EDIT_TIME / 60 )));
2007-11-15 22:51:05 +00:00
}
2006-06-16 23:53:56 +00:00
}
2007-11-12 20:57:15 +00:00
$post_owner = BoincUser :: lookup_id ( $post -> user );
2007-11-15 22:51:05 +00:00
if (( $logged_in_user -> id != $post_owner -> id ) || ( can_reply ( $thread , $forum , $logged_in_user ) == false )) {
2011-08-25 22:12:48 +00:00
error_page ( tra ( " You are not authorized to edit this post. " ));
2005-02-13 21:33:02 +00:00
}
2005-01-18 13:00:38 +00:00
2007-11-12 20:57:15 +00:00
$thread_owner = BoincUser :: lookup_id ( $thread -> owner );
2007-11-23 00:51:01 +00:00
// If this post belongs to the creator of the thread and is at top-level
// (ie. not a response to another post)
// allow the user to modify the thread title
//
2007-12-02 21:11:17 +00:00
$can_edit_title = ( $post -> parent_post == 0 && $thread_owner -> id == $logged_in_user -> id && ! is_banished ( $logged_in_user ));
2004-04-13 23:55:05 +00:00
2008-06-11 19:36:10 +00:00
$content = post_str ( " content " , true );
$title = post_str ( " title " , true );
2007-09-29 12:53:16 +00:00
$preview = post_str ( " preview " , true );
2007-11-12 20:57:15 +00:00
if ( post_str ( 'submit' , true ) && ( ! $preview )) {
check_tokens ( $logged_in_user -> authenticator );
2007-07-08 12:31:13 +00:00
2007-11-23 00:51:01 +00:00
$add_signature = ( post_str ( 'add_signature' , true ) == " 1 " ) ? 1 : 0 ;
2007-11-12 20:57:15 +00:00
$content = substr ( $content , 0 , 64000 );
2007-11-23 00:51:01 +00:00
$content = trim ( $content );
if ( strlen ( $content )) {
$content = BoincDb :: escape_string ( $content );
$now = time ();
$post -> update ( " signature= $add_signature , content=' $content ', modified= $now " );
2007-07-08 12:31:13 +00:00
2007-11-23 00:51:01 +00:00
if ( $can_edit_title ){
$title = trim ( $title );
2011-08-25 22:12:48 +00:00
$title = sanitize_tags ( $title );
2007-11-23 00:51:01 +00:00
$title = BoincDb :: escape_string ( $title );
$thread -> update ( " title=' $title ' " );
}
2012-10-15 18:47:55 +00:00
header ( " Location: forum_thread.php?id= $thread->id &postid= $postid " );
2007-11-23 00:51:01 +00:00
} else {
delete_post ( $post , $thread , $forum );
header ( " Location: forum_forum.php?id= $forum->id " );
2004-04-13 23:55:05 +00:00
}
2003-07-19 00:26:18 +00:00
}
2011-08-25 22:12:48 +00:00
page_head ( tra ( " Forum " ), '' , '' , '' , $bbcode_js );
2003-07-19 00:26:18 +00:00
2007-11-15 00:27:02 +00:00
show_forum_header ( $logged_in_user );
2007-11-16 21:48:28 +00:00
switch ( $forum -> parent_type ) {
case 0 :
2007-11-15 22:51:05 +00:00
$category = BoincCategory :: lookup_id ( $forum -> category );
show_forum_title ( $category , $forum , $thread );
2007-11-16 21:48:28 +00:00
break ;
case 1 :
2007-11-26 04:12:15 +00:00
show_team_forum_title ( $forum , $thread );
2007-11-16 21:48:28 +00:00
break ;
2007-11-15 22:51:05 +00:00
}
2003-07-19 00:26:18 +00:00
2007-09-29 12:53:16 +00:00
if ( $preview == tra ( " Preview " )) {
2007-11-12 20:57:15 +00:00
$options = null ;
2011-02-14 19:49:30 +00:00
echo " <h2> " . tra ( " Preview " ) . " </h2> \n " ;
echo " <div class=pm_preview> " ;
2007-09-29 12:53:16 +00:00
echo output_transform ( $content , $options );
echo " </div> \n " ;
}
2009-06-23 16:37:13 +00:00
echo " <form action= \" forum_edit.php?id= " . $post -> id . " \" method= \" POST \" name= \" post \" onsubmit= \" return checkForm(this) \" > \n " ;
2007-11-12 20:57:15 +00:00
echo form_tokens ( $logged_in_user -> authenticator );
2004-06-07 03:34:07 +00:00
start_table ();
2011-08-25 22:12:48 +00:00
row1 ( tra ( " Edit your message " ));
2006-06-16 23:53:56 +00:00
if ( $can_edit_title ) {
//If this is the user can edit the thread title display a way of doing so
2007-09-29 12:53:16 +00:00
if ( $preview ) {
row2 (
2007-11-02 14:43:02 +00:00
tra ( " Title " ) . html_info (),
2008-06-05 20:32:21 +00:00
" <input type= \" text \" name= \" title \" value= \" " . htmlspecialchars ( $title ) . " \" > "
2007-09-29 12:53:16 +00:00
);
} else {
row2 (
2007-11-02 14:43:02 +00:00
tra ( " Title " ) . html_info (),
2008-06-05 20:32:21 +00:00
'<input type="text" name="title" value="' . htmlspecialchars ( $thread -> title ) . '">'
2007-09-29 12:53:16 +00:00
);
}
2004-04-13 23:55:05 +00:00
};
2003-08-13 22:08:12 +00:00
2007-09-29 12:53:16 +00:00
if ( $preview ) {
row2 (
2007-11-02 14:43:02 +00:00
tra ( " Message " ) . html_info () . post_warning (),
2010-12-21 17:15:57 +00:00
$bbcode_html . " <textarea name= \" content \" rows= \" 12 \" cols= \" 80 \" class= \" message_field \" > " . htmlspecialchars ( $content ) . " </textarea> "
2007-09-29 12:53:16 +00:00
);
} else {
row2 (
2007-11-02 14:43:02 +00:00
tra ( " Message " ) . html_info () . post_warning (),
2010-12-21 17:15:57 +00:00
$bbcode_html . '<textarea name="content" rows="12" cols="80" class="message_field">' . htmlspecialchars ( $post -> content ) . '</textarea>'
2007-09-29 12:53:16 +00:00
);
}
2007-07-08 12:31:13 +00:00
2007-11-12 20:57:15 +00:00
if ( $post -> signature ) {
2007-07-08 12:31:13 +00:00
$enable_signature = " checked= \" true \" " ;
} else {
$enable_signature = " " ;
}
row2 ( " " , " <input id= \" add_signature \" name= \" add_signature \" value= \" 1 \" " . $enable_signature . " type= \" checkbox \" >
2007-11-02 14:43:02 +00:00
< label for = \ " add_signature \" > " . tra ( " Add my signature to this post " ) . " </label> " );
2007-09-29 12:53:16 +00:00
row2 ( " " , " <input type= \" submit \" name= \" preview \" value= \" " . tra ( " Preview " ) . " \" ><input type= \" submit \" name= \" submit \" value= \" OK \" > "
2004-06-07 03:34:07 +00:00
);
end_table ();
2003-08-13 22:08:12 +00:00
echo " </form> " ;
2003-08-15 01:01:00 +00:00
page_tail ();
2003-07-19 00:26:18 +00:00
2007-11-12 20:57:15 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2003-12-04 22:42:51 +00:00
?>