3 * FusionForge News Facility
5 * Copyright (C) 1999-2001 VA Linux Systems
6 * Copyright (C) 2002-2004 GForge Team
7 * Copyright (C) 2008-2010 Alcatel-Lucent
8 * Copyright 2013, 2015, Franck Villaume - TrivialDev
10 * http://fusionforge.org/
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 * Standard Alcatel-Lucent disclaimer for contributing to open source
31 * "The Submit News Form ("Contribution") has not been tested and/or
32 * validated for release as or in products, combinations with products or
33 * other commercial use. Any use of the Contribution is entirely made at
34 * the user's own responsibility and the user can not rely on any features,
35 * functionalities or performances Alcatel-Lucent has attributed to the
38 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
39 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
40 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
41 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
42 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
43 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
44 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
46 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
50 require_once '../env.inc.php';
51 require_once $gfcommon.'include/pre.php';
52 require_once $gfwww.'include/note.php';
53 require_once $gfwww.'news/news_utils.php';
54 require_once $gfcommon.'forum/Forum.class.php';
55 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
59 $group_id = getIntFromRequest('group_id');
63 $group = group_get_object($group_id);
64 if (!$group || !is_object($group)) {
66 } elseif ($group->isError()) {
67 exit_error($group->getErrorMessage(), 'news');
70 $summary = getStringFromRequest('summary');
71 $details = getHtmlTextFromRequest('details');
73 if (session_loggedin()) {
75 if (!forge_check_perm('project_admin', $group_id)) {
76 exit_permission_denied(_('You cannot submit news for a project unless you are an admin on that project.'), 'home');
79 if ($group_id == GROUP_IS_NEWS) {
80 exit_permission_denied(_('Submitting news from the news group is not allowed.'), 'home');
83 if (getStringFromRequest('post_changes')) {
84 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
85 exit_form_double_submit('news');
88 //check to make sure both fields are there
89 if ($summary && $details) {
91 create a new discussion forum without a default msg
92 if one isn't already there
96 $f = new Forum($group, false, false, true);
97 if (!$f->create(preg_replace('/[^_\.0-9a-z-]/', '-', strtolower($summary)), $details, '')) {
99 $error_msg = $f->getErrorMessage();
101 $group->normalizeAllRoles();
102 $new_id = $f->getID();
103 $sql = 'INSERT INTO news_bytes (group_id, submitted_by, is_approved, post_date, forum_id, summary,details)
104 VALUES ($1, $2, $3, $4, $5, $6, $7)';
105 $result = db_query_params($sql, array($group_id, user_getid(), 0, time(), $new_id, htmlspecialchars($summary), $details));
108 form_release_key(getStringFromRequest('form_key'));
109 $error_msg = _('Error')._(': ')._('insert failed.');
112 $feedback = _('News Added.');
116 form_release_key(getStringFromRequest('form_key'));
117 $error_msg = _('Error')._(': ')._('both subject and body are required.');
124 $group = group_get_object($group_id);
125 news_header(array('title'=>_('Submit News for Project')._(': ').$group->getPublicName(), 'modal' => 1));
128 echo _('You can post news about your project if you are an admin on your project. You may also post “help wanted” notes if your project needs help.');
131 printf(_('All posts <strong>for your project</strong> will appear instantly on your project summary page. Posts that are of special interest to the community will have to be approved by a member of the %1$s news team before they will appear on the %1$s home page.'), forge_get_config('forge_name'));
134 echo _('You may include URLs, but not HTML in your submissions.');
137 echo _('URLs that start with http:// are made clickable.');
140 echo $HTML->openForm(array('id' => 'newssubmitform', 'action' => '/news/submit.php', 'method' => 'post'));
141 echo ' <input type="hidden" name="group_id" value="'.$group_id.'" />
142 <input type="hidden" name="post_changes" value="y" />
143 <input type="hidden" name="form_key" value="'. form_generate_key() .'" />
144 <p><strong>'._('For project')._(': ').$group->getPublicName().'</strong></p>
146 <label for="summary"><strong>'._('Subject').utils_requiredField()._(': ').'</strong></label>
147 <input required="required" type="text" id="summary" name="summary" value="'.$summary.'" size="80" />
150 <label for="details"><strong>'._('Details').utils_requiredField()._(': ').'</strong></label>'.notepad_button('document.forms.newssubmitform.details').'</p>';
153 $params['name'] = 'details';
154 $params['width'] = "800";
155 $params['height'] = "500";
156 $params['body'] = $details;
157 $params['group'] = $group_id;
158 $params['content'] = '<textarea required="required" id="details" name="details" rows="5" cols="50">'.$details.'</textarea>';
159 plugin_hook_by_reference("text_editor",$params);
161 echo $params['content'].'<br />';
163 echo '<input type="submit" name="submit" value="'._('Submit').'" />';
165 echo $HTML->closeForm();
171 exit_not_logged_in();
177 // c-file-style: "bsd"