1<?php 2// This file is part of BOINC. 3// http://boinc.berkeley.edu 4// Copyright (C) 2014 University of California 5// 6// BOINC is free software; you can redistribute it and/or modify it 7// under the terms of the GNU Lesser General Public License 8// as published by the Free Software Foundation, 9// either version 3 of the License, or (at your option) any later version. 10// 11// BOINC is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14// See the GNU Lesser General Public License for more details. 15// 16// You should have received a copy of the GNU Lesser General Public License 17// along with BOINC. If not, see <http://www.gnu.org/licenses/>. 18 19// Post a reply to a thread. 20// Both input (form) and action take place here. 21 22require_once('../inc/util.inc'); 23require_once('../inc/forum_email.inc'); 24require_once('../inc/forum.inc'); 25require_once('../inc/bbcode_html.inc'); 26require_once('../inc/akismet.inc'); 27 28if (DISABLE_FORUMS) error_page("Forums are disabled"); 29 30$logged_in_user = get_logged_in_user(true); 31BoincForumPrefs::lookup($logged_in_user); 32check_banished($logged_in_user); 33 34$thread = BoincThread::lookup_id(get_int('thread')); 35$forum = BoincForum::lookup_id($thread->forum); 36 37$sort_style = get_str('sort', true); 38$filter = get_str('filter', true); 39$content = post_str('content', true); 40$preview = post_str("preview", true); 41$parent_post_id = get_int('post', true); 42 43$parent_post = null; 44if ($parent_post_id) { 45 $parent_post = BoincPost::lookup_id($parent_post_id); 46 if ($parent_post->thread != $thread->id) { 47 error_page("wrong thread"); 48 } 49} else { 50 $parent_post_id = 0; 51} 52 53if ($filter != "false"){ 54 $filter = true; 55} else { 56 $filter = false; 57} 58 59check_reply_access($logged_in_user, $forum, $thread); 60 61if (!$sort_style) { 62 $sort_style = $logged_in_user->prefs->thread_sorting; 63} else { 64 $logged_in_user->prefs->update("thread_sorting=$sort_style"); 65} 66 67$warning = null; 68if ($content && (!$preview)){ 69 if (post_str('add_signature',true)=="add_it"){ 70 $add_signature=true; // set a flag and concatenate later 71 } else { 72 $add_signature=false; 73 } 74 check_tokens($logged_in_user->authenticator); 75 if (!akismet_check($logged_in_user, $content)) { 76 $warning = tra("Your post has been flagged as spam by the Akismet anti-spam system. Please modify your text and try again."); 77 $preview = tra("Preview"); 78 } else { 79 $post_id = create_post( 80 $content, $parent_post_id, $logged_in_user, $forum, 81 $thread, $add_signature 82 ); 83 if ($post_id) { 84 header("Location: forum_thread.php?id=$thread->id&postid=$post_id"); 85 } else { 86 error_page("Can't create post."); 87 } 88 } 89} 90 91page_head(tra("Post to thread"),'','','', $bbcode_js); 92 93show_forum_header($logged_in_user); 94 95if ($warning) { 96 echo "<p class=\"text-danger\">$warning</p>"; 97} 98 99switch ($forum->parent_type) { 100case 0: 101 $category = BoincCategory::lookup_id($forum->category); 102 show_forum_title($category, $forum, $thread); 103 break; 104case 1: 105 show_team_forum_title($forum, $thread); 106 break; 107} 108echo "<p>"; 109 110if ($preview == tra("Preview")) { 111 $options = new output_options; 112 if (is_admin($logged_in_user)) { 113 $options->htmlitems = false; 114 } 115 panel(tra('Preview'), 116 function() use($content, $options) { 117 echo output_transform($content, $options); 118 } 119 ); 120} 121 122start_table(); 123show_message_row($thread, $parent_post); 124end_table(); 125 126if ($parent_post) { 127 start_forum_table(array(tra("Author"), tra("Message"))); 128 show_post( 129 $parent_post, $thread, $forum, $logged_in_user, 0, false, false 130 ); 131 end_table(); 132} else { 133 show_posts($thread, $forum, 0, 0, CREATE_TIME_NEW, 0, $logged_in_user); 134} 135 136page_tail(); 137 138function show_message_row($thread, $parent_post) { 139 global $logged_in_user, $bbcode_html; 140 global $content, $preview; 141 142 $x1 = tra("Message:").html_info().post_warning(); 143 $x2 = ""; 144 if ($parent_post) { 145 $x2 .=" ".tra("reply to %1Message ID%2:", "<a href=#".$parent_post->id.">", " ".$parent_post->id."</a>"); 146 } 147 $x2 .= "<form action=forum_reply.php?thread=".$thread->id; 148 149 if ($parent_post) { 150 $x2 .= "&post=".$parent_post->id; 151 } 152 153 $x2 .= " method=\"post\" name=\"post\" onsubmit=\"return checkForm(this)\">\n"; 154 $x2 .= form_tokens($logged_in_user->authenticator); 155 $x2 .= start_table_str().$bbcode_html.end_table_str()."<textarea class=\"form-control\" name=\"content\" rows=\"18\">"; 156 $no_quote = get_int("no_quote", true)==1; 157 if ($preview) { 158 $x2 .= htmlspecialchars($content); 159 } else if (!$no_quote) { 160 if ($parent_post) { 161 $x2 .= quote_text(htmlspecialchars($parent_post->content))."\n"; 162 } 163 } 164 if (!$logged_in_user->prefs->no_signature_by_default) { 165 $enable_signature="checked=\"true\""; 166 } else { 167 $enable_signature=""; 168 } 169 $x2 .= "</textarea><p> </p> 170 <input class=\"btn btn-default btn-sm \" type=\"submit\" name=\"preview\" value=\"".tra("Preview")."\"> 171 <input class=\"btn btn-default btn-sm \" type=\"submit\" value=\"".tra("Post reply")."\"> 172 173 <input type=\"checkbox\" name=\"add_signature\" id=\"add_signature\" value=\"add_it\" ".$enable_signature."> 174 <label for=\"add_signature\">".tra("Add my signature to this reply")."</label> 175 176 </form> 177 "; 178 row2($x1, $x2, false, "20%"); 179} 180 181function quote_text($text) { 182 $text = "[quote]" . $text . "[/quote]"; 183 return $text; 184} 185 186$cvs_version_tracker[]="\$Id$"; 187?> 188