5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge 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
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 By Tim Perdue, Sourceforge, 12/99
31 function news_header($params) {
32 global $HTML,$group_id,$news_name,$news_id,$sys_news_group,$sys_use_news;
38 $params['toptab']='news';
39 $params['group']=$group_id;
43 if ($group_id && ($group_id != $sys_news_group)) {
44 site_project_header($params);
46 $HTML->header($params);
48 if ($group_id && ($group_id != $sys_news_group)) {
52 $menu_texts[]=_('Submit');
53 $menu_links[]='/news/submit.php?group_id='.$group_id;
54 if (session_loggedin()) {
55 $project =& group_get_object($params['group']);
56 if ($project && is_object($project) && !$project->isError()) {
57 $perm =& $project->getPermission(session_get_user());
58 if ($perm && is_object($perm) && !$perm->isError() && $perm->isAdmin()) {
59 $menu_texts[]=_('Admin');
60 $menu_links[]='/news/admin/?group_id='.$group_id;
64 echo $HTML->subMenu($menu_texts,$menu_links);
68 function news_footer($params) {
70 $HTML->footer($params);
74 * Display latest news for frontpage or news page.
76 * @param int $group_id group_id of the news ($sys_news_group used if none given)
77 * @param int $limit number of news to display (default: 10)
78 * @param bool $show_summaries (default: true)
79 * @param bool $allow_submit (default: true)
80 * @param bool $flat (default: false)
81 * @param int $tail_headlines number of additional news to display in short (-1 for all the others, default: 0)
83 function news_show_latest($group_id='',$limit=10,$show_summaries=true,$allow_submit=true,$flat=false,$tail_headlines=0,$show_forum=true) {
84 global $sys_news_group;
86 $group_id=$sys_news_group;
89 Show a simple list of the latest news items with a link to the forum
91 if ($tail_headlines == -1) {
94 $l = $limit + $tail_headlines ;
96 $result = db_query_params ('
97 SELECT groups.group_name, groups.unix_group_name, groups.group_id,
98 groups.type_id, users.user_name, users.realname,
99 news_bytes.forum_id, news_bytes.summary, news_bytes.post_date,
101 FROM users,news_bytes,groups
102 WHERE (news_bytes.group_id=$1 AND news_bytes.is_approved <> 4 OR 1!=$2)
103 AND (news_bytes.is_approved=1 OR 1 != $3)
104 AND users.user_id=news_bytes.submitted_by
105 AND news_bytes.group_id=groups.group_id
107 ORDER BY post_date DESC',
109 $group_id != $sys_news_group ? 1 : 0,
110 $group_id != $sys_news_group ? 0 : 1,
113 $rows=db_numrows($result);
117 if (!$result || $rows < 1) {
118 $return .= _('No News Items Found');
119 $return .= db_error();
122 for ($i=0; $i<$rows; $i++) {
123 $t_thread_title = db_result($result,$i,'summary');
124 $t_thread_url = "/forum/forum.php?forum_id=" . db_result($result,$i,'forum_id');
125 $t_thread_author = db_result($result,$i,'realname');
127 $return .= '<div class="one-news bordure-dessous">';
129 if ($show_summaries && $limit) {
130 //get the first paragraph of the story
131 if (strstr(db_result($result,$i,'details'),'<br/>')) {
132 // the news is html, fckeditor made for example
133 $arr=explode("<br/>",db_result($result,$i,'details'));
135 $arr=explode("\n",db_result($result,$i,'details'));
137 $summ_txt=util_make_links( $arr[0] );
138 $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'));
146 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
148 $return .= '<h3>'. $t_thread_title . '</h3>';
150 $return .= ' <em>'. date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</em><br /></li>';
153 $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
155 $return .= '<h3>'. $t_thread_title . '</h3>';
159 $return .= $t_thread_author;
162 $return .= date(_('Y-m-d H:i'),db_result($result,$i,'post_date'));
164 $return .= $proj_name ;
165 $return .= "</div>\n";
167 if ($summ_txt != "") {
168 $return .= '<p>'.$summ_txt.'</p>';
171 $res2 = db_query_params ('SELECT total FROM forum_group_list_vw WHERE group_forum_id=$1',
172 array (db_result($result,$i,'forum_id')));
173 $num_comments = db_result($res2,0,'total');
175 if (!$num_comments) {
179 if ($num_comments <= 1) {
180 $comments_txt = _('Comment');
182 $comments_txt = _('Comments');
186 $link_text = _('Read More/Comment') ;
187 $extra_params = array( 'class' => 'dot-link',
188 'title' => $link_text . ' ' . $t_thread_title);
190 $return .= '<div>' . $num_comments .' '. $comments_txt .' ';
191 $return .= util_make_link ($t_thread_url, $link_text, $extra_params);
198 if ($limit==1 && $tail_headlines) {
205 $return .= '</div><!-- class="one-news" -->';
209 if ($group_id != $sys_news_group) {
210 $archive_url = '/news/?group_id='.$group_id;
212 $archive_url = '/news/';
214 if ($tail_headlines != -1) {
216 $return .= '<div>' . util_make_link($archive_url, _('News archive'), array('class' => 'dot-link')) . '</div>';
218 $return .= '<div>...</div>';
222 if ($allow_submit && $group_id != $sys_news_group) {
223 if(!$result || $rows < 1) {
226 //you can only submit news from a project now
227 //you used to be able to submit general news
228 $return .= '<div>' . util_make_link ('/news/submit.php?group_id='.$group_id, _('Submit News')).'</div>';
233 function news_foundry_latest($group_id=0,$limit=5,$show_summaries=true) {
235 Show a the latest news for a portal
238 $result=db_query_params("SELECT groups.group_name,groups.unix_group_name,groups.group_id,
239 users.user_name,users.realname,news_bytes.forum_id,
240 news_bytes.summary,news_bytes.post_date,news_bytes.details
241 FROM users,news_bytes,groups,foundry_news
242 WHERE foundry_news.foundry_id=$1
243 AND users.user_id=news_bytes.submitted_by
244 AND foundry_news.news_id=news_bytes.id
245 AND news_bytes.group_id=groups.group_id
246 AND foundry_news.is_approved=1
247 ORDER BY news_bytes.post_date DESC", array($group_id),$limit);
249 $rows=db_numrows($result);
251 if (!$result || $rows < 1) {
252 $return .= '<h3>' . _('No News Items Found') . '</h3>';
253 $return .= db_error();
255 for ($i=0; $i<$rows; $i++) {
256 if ($show_summaries) {
257 //get the first paragraph of the story
258 $arr=explode("\n",db_result($result,$i,'details'));
259 if ((isset($arr[1]))&&(isset($arr[2]))&&(strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
260 $summ_txt=util_make_links( $arr[0].'<br />'.$arr[1].'<br />'.$arr[2] );
262 $summ_txt=util_make_links( $arr[0] );
265 //show the project name
266 $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'));
271 $return .= util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary') . '</strong>')
272 .'<br /><em>'. db_result($result,$i,'realname') .' - '.
273 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')) . $proj_name . '</em>
280 function get_news_name($id) {
282 Takes an ID and returns the corresponding forum name
284 $result=db_query_params('SELECT summary FROM news_bytes WHERE id=$1', array($id));
285 if (!$result || db_numrows($result) < 1) {
286 return _('Not Found');
288 return db_result($result, 0, 'summary');
294 // c-file-style: "bsd"