5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 function news_header($params) {
27 global $HTML,$group_id,$news_name,$news_id;
29 if (!forge_get_config('use_news')) {
33 $params['toptab']='news';
34 $params['group']=$group_id;
36 if ($group_id && ($group_id != forge_get_config('news_group'))) {
40 $menu_texts[]=_('View News');
41 $menu_links[]='/news/?group_id='.$group_id;
42 $menu_texts[]=_('Submit');
43 $menu_links[]='/news/submit.php?group_id='.$group_id;
44 if (session_loggedin()) {
45 $project = group_get_object($params['group']);
46 if ($project && is_object($project) && !$project->isError()) {
47 if (forge_check_perm ('project_admin', $group_id)) {
48 $menu_texts[]=_('Administration');
49 $menu_links[]='/news/admin/?group_id='.$group_id;
53 $params['submenu'] = $HTML->subMenu($menu_texts,$menu_links);
58 if ($group_id && ($group_id != forge_get_config('news_group'))) {
59 site_project_header($params);
65 function news_footer($params) {
67 $HTML->footer($params);
71 * Display latest news for frontpage or news page.
73 * @param int $group_id group_id of the news (forge_get_config('news_group') used if none given)
74 * @param int $limit number of news to display (default: 10)
75 * @param bool $show_summaries (default: true)
76 * @param bool $allow_submit (default: true)
77 * @param bool $flat (default: false)
78 * @param int $tail_headlines number of additional news to display in short (-1 for all the others, default: 0)
80 function news_show_latest($group_id='',$limit=10,$show_summaries=true,$allow_submit=true,$flat=false,$tail_headlines=0,$show_forum=true) {
83 $group_id=forge_get_config('news_group');
86 Show a simple list of the latest news items with a link to the forum
88 if ($tail_headlines == -1) {
91 $l = $limit + $tail_headlines ;
93 $result = db_query_params ('
94 SELECT groups.group_name, groups.unix_group_name, groups.group_id,
95 groups.type_id, users.user_name, users.realname,
96 news_bytes.forum_id, news_bytes.summary, news_bytes.post_date,
98 FROM users,news_bytes,groups
99 WHERE (news_bytes.group_id=$1 AND news_bytes.is_approved <> 4 OR 1!=$2)
100 AND (news_bytes.is_approved=1 OR 1 != $3)
101 AND users.user_id=news_bytes.submitted_by
102 AND news_bytes.group_id=groups.group_id
104 ORDER BY post_date DESC',
106 $group_id != forge_get_config('news_group') ? 1 : 0,
107 $group_id != forge_get_config('news_group') ? 0 : 1,
110 $rows=db_numrows($result);
114 if (!$result || $rows < 1) {
115 $return .= _('No News Items Found');
116 $return .= db_error();
117 // $return .= "</div>";
119 for ($i=0; $i<$rows; $i++) {
120 $t_thread_title = db_result($result,$i,'summary');
121 $t_thread_url = "/forum/forum.php?forum_id=" . db_result($result,$i,'forum_id');
122 $t_thread_author = db_result($result,$i,'realname');
124 $return .= '<div class="one-news bordure-dessous">';
126 if ($show_summaries && $limit) {
127 //get the first paragraph of the story
128 if (strstr(db_result($result,$i,'details'),'<br/>')) {
129 // the news is html, fckeditor made for example
130 $arr=explode("<br/>",db_result($result,$i,'details'));
132 $arr=explode("\n",db_result($result,$i,'details'));
134 $summ_txt=util_make_links( $arr[0] );
135 $proj_name=util_make_link_g (strtolower(db_result($result,$i,'unix_group_name')),db_result($result,$i,'group_id'),db_result($result,$i,'group_name'));
143 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
145 $return .= '<h3>'. $t_thread_title . '</h3>';
147 $return .= ' <em>'. date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</em><br />';
150 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
152 $return .= '<h3>'. $t_thread_title . '</h3>';
156 $return .= $t_thread_author;
159 $return .= relative_date(db_result($result,$i,'post_date'));
161 $return .= $proj_name ;
162 $return .= "</div>\n";
164 if ($summ_txt != "") {
165 $return .= '<p>'.$summ_txt.'</p>';
168 $res2 = db_query_params ('SELECT total FROM forum_group_list_vw WHERE group_forum_id=$1',
169 array (db_result($result,$i,'forum_id')));
170 $num_comments = db_result($res2,0,'total');
172 if (!$num_comments) {
176 if ($num_comments <= 1) {
177 $comments_txt = _('Comment');
179 $comments_txt = _('Comments');
183 $link_text = _('Read More/Comment') ;
184 $extra_params = array( 'class' => 'dot-link',
185 'title' => $link_text . ' ' . $t_thread_title);
187 $return .= '<div>' . $num_comments .' '. $comments_txt .' ';
188 $return .= util_make_link ($t_thread_url, $link_text, $extra_params);
199 $return .= '</div><!-- class="one-news" -->';
203 if ($group_id != forge_get_config('news_group')) {
204 $archive_url = '/news/?group_id='.$group_id;
206 $archive_url = '/news/';
208 if ($tail_headlines != -1) {
210 $return .= '<div>' . util_make_link($archive_url, _('News archive'), array('class' => 'dot-link')) . '</div>';
212 $return .= '<div>...</div>';
216 if ($allow_submit && $group_id != forge_get_config('news_group')) {
217 if(!$result || $rows < 1) {
220 //you can only submit news from a project now
221 //you used to be able to submit general news
222 $return .= '<div>' . util_make_link ('/news/submit.php?group_id='.$group_id, _('Submit News')).'</div>';
227 function news_foundry_latest($group_id=0,$limit=5,$show_summaries=true) {
229 Show a the latest news for a portal
232 $result=db_query_params("SELECT groups.group_name,groups.unix_group_name,groups.group_id,
233 users.user_name,users.realname,news_bytes.forum_id,
234 news_bytes.summary,news_bytes.post_date,news_bytes.details
235 FROM users,news_bytes,groups,foundry_news
236 WHERE foundry_news.foundry_id=$1
237 AND users.user_id=news_bytes.submitted_by
238 AND foundry_news.news_id=news_bytes.id
239 AND news_bytes.group_id=groups.group_id
240 AND foundry_news.is_approved=1
241 ORDER BY news_bytes.post_date DESC", array($group_id),$limit);
243 $rows=db_numrows($result);
245 if (!$result || $rows < 1) {
246 $return .= '<h3>' . _('No News Items Found') . '</h3>';
247 $return .= db_error();
249 for ($i=0; $i<$rows; $i++) {
250 if ($show_summaries) {
251 //get the first paragraph of the story
252 $arr=explode("\n",db_result($result,$i,'details'));
253 if ((isset($arr[1]))&&(isset($arr[2]))&&(strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
254 $summ_txt=util_make_links( $arr[0].'<br />'.$arr[1].'<br />'.$arr[2] );
256 $summ_txt=util_make_links( $arr[0] );
259 //show the project name
260 $proj_name=' - '.util_make_link_g (strtolower(db_result($result,$i,'unix_group_name')),db_result($result,$i,'group_id'),db_result($result,$i,'group_name'));
265 $return .= util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary') . '</strong>')
266 .'<br /><em>'. db_result($result,$i,'realname') .' - '.
267 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')) . $proj_name . '</em>
274 function get_news_name($id) {
276 Takes an ID and returns the corresponding forum name
278 $result=db_query_params('SELECT summary FROM news_bytes WHERE id=$1', array($id));
279 if (!$result || db_numrows($result) < 1) {
280 return _('Not Found');
282 return db_result($result, 0, 'summary');
288 // c-file-style: "bsd"