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.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with FusionForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 function news_header($params) {
28 global $HTML,$group_id,$news_name,$news_id;
30 if (!forge_get_config('use_news')) {
34 $params['toptab']='news';
35 $params['group']=$group_id;
37 if ($group_id && ($group_id != forge_get_config('news_group'))) {
41 $menu_texts[]=_('View News');
42 $menu_links[]='/news/?group_id='.$group_id;
43 $menu_texts[]=_('Submit');
44 $menu_links[]='/news/submit.php?group_id='.$group_id;
45 if (session_loggedin()) {
46 $project = group_get_object($params['group']);
47 if ($project && is_object($project) && !$project->isError()) {
48 if (forge_check_perm ('project_admin', $group_id)) {
49 $menu_texts[]=_('Administration');
50 $menu_links[]='/news/admin/?group_id='.$group_id;
54 $params['submenu'] = $HTML->subMenu($menu_texts,$menu_links);
59 if ($group_id && ($group_id != forge_get_config('news_group'))) {
60 site_project_header($params);
66 function news_footer($params) {
68 $HTML->footer($params);
72 * Display latest news for frontpage or news page.
74 * @param int $group_id group_id of the news (forge_get_config('news_group') used if none given)
75 * @param int $limit number of news to display (default: 10)
76 * @param bool $show_summaries (default: true)
77 * @param bool $allow_submit (default: true)
78 * @param bool $flat (default: false)
79 * @param int $tail_headlines number of additional news to display in short (-1 for all the others, default: 0)
81 function news_show_latest($group_id='',$limit=10,$show_summaries=true,$allow_submit=true,$flat=false,$tail_headlines=0,$show_forum=true) {
84 $group_id=forge_get_config('news_group');
87 Show a simple list of the latest news items with a link to the forum
89 if ($tail_headlines == -1) {
92 $l = $limit + $tail_headlines ;
94 $result = db_query_params ('
95 SELECT groups.group_name, groups.unix_group_name, groups.group_id,
96 groups.type_id, users.user_name, users.realname,
97 news_bytes.forum_id, news_bytes.summary, news_bytes.post_date,
99 FROM users,news_bytes,groups
100 WHERE (news_bytes.group_id=$1 AND news_bytes.is_approved <> 4 OR 1!=$2)
101 AND (news_bytes.is_approved=1 OR 1 != $3)
102 AND users.user_id=news_bytes.submitted_by
103 AND news_bytes.group_id=groups.group_id
105 ORDER BY post_date DESC',
107 $group_id != forge_get_config('news_group') ? 1 : 0,
108 $group_id != forge_get_config('news_group') ? 0 : 1,
111 $rows=db_numrows($result);
115 if (!$result || $rows < 1) {
116 $return .= _('No News Items Found');
117 $return .= db_error();
118 // $return .= "</div>";
120 for ($i=0; $i<$rows; $i++) {
121 $t_thread_title = db_result($result,$i,'summary');
122 $t_thread_url = "/forum/forum.php?forum_id=" . db_result($result,$i,'forum_id');
123 $t_thread_author = db_result($result,$i,'realname');
125 $return .= '<div class="one-news bordure-dessous">';
127 if ($show_summaries && $limit) {
128 //get the first paragraph of the story
129 if (strstr(db_result($result,$i,'details'),'<br/>')) {
130 // the news is html, fckeditor made for example
131 $arr=explode("<br/>",db_result($result,$i,'details'));
133 $arr=explode("\n",db_result($result,$i,'details'));
135 $summ_txt=util_make_links( $arr[0] );
136 $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'));
144 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
146 $return .= '<h3>'. $t_thread_title . '</h3>';
148 $return .= ' <em>'. date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</em><br />';
151 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
153 $return .= '<h3>'. $t_thread_title . '</h3>';
157 $return .= $t_thread_author;
160 $return .= date(_('Y-m-d H:i'),db_result($result,$i,'post_date'));
162 $return .= $proj_name ;
163 $return .= "</div>\n";
165 if ($summ_txt != "") {
166 $return .= '<p>'.$summ_txt.'</p>';
169 $res2 = db_query_params ('SELECT total FROM forum_group_list_vw WHERE group_forum_id=$1',
170 array (db_result($result,$i,'forum_id')));
171 $num_comments = db_result($res2,0,'total');
173 if (!$num_comments) {
177 if ($num_comments <= 1) {
178 $comments_txt = _('Comment');
180 $comments_txt = _('Comments');
184 $link_text = _('Read More/Comment') ;
185 $extra_params = array( 'class' => 'dot-link',
186 'title' => $link_text . ' ' . $t_thread_title);
188 $return .= '<div>' . $num_comments .' '. $comments_txt .' ';
189 $return .= util_make_link ($t_thread_url, $link_text, $extra_params);
200 $return .= '</div><!-- class="one-news" -->';
204 if ($group_id != forge_get_config('news_group')) {
205 $archive_url = '/news/?group_id='.$group_id;
207 $archive_url = '/news/';
209 if ($tail_headlines != -1) {
211 $return .= '<div>' . util_make_link($archive_url, _('News archive'), array('class' => 'dot-link')) . '</div>';
213 $return .= '<div>...</div>';
217 if ($allow_submit && $group_id != forge_get_config('news_group')) {
218 if(!$result || $rows < 1) {
221 //you can only submit news from a project now
222 //you used to be able to submit general news
223 $return .= '<div>' . util_make_link ('/news/submit.php?group_id='.$group_id, _('Submit News')).'</div>';
228 function news_foundry_latest($group_id=0,$limit=5,$show_summaries=true) {
230 Show a the latest news for a portal
233 $result=db_query_params("SELECT groups.group_name,groups.unix_group_name,groups.group_id,
234 users.user_name,users.realname,news_bytes.forum_id,
235 news_bytes.summary,news_bytes.post_date,news_bytes.details
236 FROM users,news_bytes,groups,foundry_news
237 WHERE foundry_news.foundry_id=$1
238 AND users.user_id=news_bytes.submitted_by
239 AND foundry_news.news_id=news_bytes.id
240 AND news_bytes.group_id=groups.group_id
241 AND foundry_news.is_approved=1
242 ORDER BY news_bytes.post_date DESC", array($group_id),$limit);
244 $rows=db_numrows($result);
246 if (!$result || $rows < 1) {
247 $return .= '<h3>' . _('No News Items Found') . '</h3>';
248 $return .= db_error();
250 for ($i=0; $i<$rows; $i++) {
251 if ($show_summaries) {
252 //get the first paragraph of the story
253 $arr=explode("\n",db_result($result,$i,'details'));
254 if ((isset($arr[1]))&&(isset($arr[2]))&&(strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
255 $summ_txt=util_make_links( $arr[0].'<br />'.$arr[1].'<br />'.$arr[2] );
257 $summ_txt=util_make_links( $arr[0] );
260 //show the project name
261 $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'));
266 $return .= util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary') . '</strong>')
267 .'<br /><em>'. db_result($result,$i,'realname') .' - '.
268 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')) . $proj_name . '</em>
275 function get_news_name($id) {
277 Takes an ID and returns the corresponding forum name
279 $result=db_query_params('SELECT summary FROM news_bytes WHERE id=$1', array($id));
280 if (!$result || db_numrows($result) < 1) {
281 return _('Not Found');
283 return db_result($result, 0, 'summary');
289 // c-file-style: "bsd"