* The rest Copyright 2002-2004 (c) GForge Team
* http://gforge.org/
*
- * @version $Id$
- *
* This file is part of GForge.
*
* GForge is free software; you can redistribute it and/or modify
$HTML->footer($params);
}
+/**
+ * Display latest news for frontpage or news page.
+ *
+ * @param int $group_id group_id of the news ($sys_news_group used if none given)
+ * @param int $limit number of news to display (default: 10)
+ * @param bool $show_summaries (default: true)
+ * @param bool $allow_submit (default: true)
+ * @param bool $flat (default: false)
+ * @param int $tail_headlines number of additional news to display in short (-1 for all the others, default: 0)
+ */
function news_show_latest($group_id='',$limit=10,$show_summaries=true,$allow_submit=true,$flat=false,$tail_headlines=0,$show_forum=true) {
global $sys_news_group;
if (!$group_id) {
/*
Show a simple list of the latest news items with a link to the forum
*/
-
- if ($group_id != $sys_news_group) {
- $wclause="news_bytes.group_id='$group_id' AND news_bytes.is_approved <> '4'";
+ if ($tail_headlines == -1) {
+ $l = 0 ;
} else {
- $wclause='news_bytes.is_approved=1';
+ $l = $limit + $tail_headlines ;
}
-
- $sql="SELECT groups.group_name,groups.unix_group_name,groups.group_id,
- groups.type_id,users.user_name,users.realname,
- news_bytes.forum_id,news_bytes.summary,news_bytes.post_date,news_bytes.details
- FROM users,news_bytes,groups
- WHERE $wclause
- AND users.user_id=news_bytes.submitted_by
- AND news_bytes.group_id=groups.group_id
- AND groups.status='A'
- ORDER BY post_date DESC";
-
- $result=db_query($sql,$limit+$tail_headlines);
+ $result = db_query_params ('
+SELECT groups.group_name, groups.unix_group_name, groups.group_id,
+ groups.type_id, users.user_name, users.realname,
+ news_bytes.forum_id, news_bytes.summary, news_bytes.post_date,
+ news_bytes.details
+FROM users,news_bytes,groups
+WHERE (news_bytes.group_id=$1 AND news_bytes.is_approved <> 4 OR 1!=$2)
+ AND (news_bytes.is_approved=1 OR 1 != $3)
+ AND users.user_id=news_bytes.submitted_by
+ AND news_bytes.group_id=groups.group_id
+ AND groups.status=$4
+ORDER BY post_date DESC',
+ array ($group_id,
+ $group_id != $sys_news_group ? 1 : 0,
+ $group_id != $sys_news_group ? 0 : 1,
+ 'A'),
+ $l);
$rows=db_numrows($result);
-
+
$return = '';
if (!$result || $rows < 1) {
$return .= _('No News Items Found');
$return .= db_error();
+ $return .= "</div>";
} else {
- if (!$limit) $return .= '<ul>';
for ($i=0; $i<$rows; $i++) {
+ $t_thread_title = db_result($result,$i,'summary');
+ $t_thread_url = "/forum/forum.php?forum_id=" . db_result($result,$i,'forum_id');
+ $t_thread_author = db_result($result,$i,'realname');
+
+ $return .= '<div class="one-news bordure-dessous">';
+ $return .= "\n";
if ($show_summaries && $limit) {
//get the first paragraph of the story
if (strstr(db_result($result,$i,'details'),'<br/>')) {
} else {
$arr=explode("\n",db_result($result,$i,'details'));
}
- //if the first paragraph is short, and so are following paragraphs, add the next paragraph on
- if ((strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
- $summ_txt='<br />'. util_make_links( $arr[0].'<br />'.$arr[1].'<br />'.$arr[2] );
- } else {
- $summ_txt='<br />'. util_make_links( $arr[0] );
- }
- $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'));
+ $summ_txt=util_make_links( $arr[0] );
+ $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'));
} else {
$proj_name='';
$summ_txt='';
if (!$limit) {
if ($show_forum) {
- $return .= '<li>'.util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary') . '</strong>');
+ $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
} else {
- $return .= '<li><strong>'. db_result($result,$i,'summary') . '</strong>';
+ $return .= '<h3>'. $t_thread_title . '</h3>';
}
$return .= ' <em>'. date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</em><br /></li>';
} else {
if ($show_forum) {
- $return .= util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary').'</strong>');
+ $return .= '<h3>'.util_make_link ($t_thread_url, $t_thread_title).'</h3>';
} else {
- $return .= '
- <strong>'. db_result($result,$i,'summary') . '</strong>';
+ $return .= '<h3>'. $t_thread_title . '</h3>';
}
- if (!$flat) {
- $return .= '
- <br /> ';
+ $return .= "<div>";
+ $return .= '<em>';
+ $return .= $t_thread_author;
+ $return .= '</em>';
+ $return .= ' - ';
+ $return .= date(_('Y-m-d H:i'),db_result($result,$i,'post_date'));
+ $return .= ' - ';
+ $return .= $proj_name ;
+ $return .= "</div>\n";
+
+ if ($summ_txt != "") {
+ $return .= '<p>'.$summ_txt.'</p>';
}
- $return .= ' <em>'. db_result($result,$i,'realname') .' - '.
- date(_('Y-m-d H:i'),db_result($result,$i,'post_date')). '</em>' .
- $proj_name . $summ_txt;
- $sql="SELECT total FROM forum_group_list_vw WHERE group_forum_id='" . db_result($result,$i,'forum_id') . "'";
- $res2 = db_query($sql);
+ $res2 = db_query_params ('SELECT total FROM forum_group_list_vw WHERE group_forum_id=$1',
+ array (db_result($result,$i,'forum_id')));
$num_comments = db_result($res2,0,'total');
if (!$num_comments) {
} else {
$comments_txt = _('Comments');
}
-
- if ($show_forum){
- $return .= '<div align="center">(' . $num_comments .' '. $comments_txt . ') '
- .util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'[' . _('Read More/Comment') . ']').'</div><hr width="100%" size="1" />';
+
+ if ($show_forum) {
+ $link_text = _('Read More/Comment') ;
+ $extra_params = array( 'class' => 'dot-link',
+ 'title' => $link_text . ' ' . $t_thread_title);
+ $return .= "\n";
+ $return .= '<div>' . $num_comments .' '. $comments_txt .' ';
+ $return .= util_make_link ($t_thread_url, $link_text, $extra_params);
+ $return .= '</div>';
} else {
- $return .= '<hr width="100%" size="1" />';
+ $return .= '';
}
}
if ($limit) {
$limit--;
}
+ $return .= "\n";
+ $return .= '</div><!-- class="one-news" -->';
+ $return .= "\n\n";
}
- if ($tail_headlines){
- if (!$limit) $return .= '</ul>';
- $return .= '<hr width="100%" size="1" />'."\n";
- }
+
if ($group_id != $sys_news_group) {
- $archive_url=util_make_url ('/news/?group_id='.$group_id);
+ $archive_url = '/news/?group_id='.$group_id;
} else {
- $archive_url=util_make_url ('/news/');
+ $archive_url = '/news/';
}
-
- if ($show_forum) {
- $return .= '<div align="center">'
- .'<a href="'.$archive_url.'">[' . _('News archive') . ']</a></div>';
- } else {
- $return .= '<div align="center">...</div>';
+ if ($tail_headlines != -1) {
+ if ($show_forum) {
+ $return .= '<div>' . util_make_link($archive_url, _('News archive'), array('class' => 'dot-link')) . '</div>';
+ } else {
+ $return .= '<div>...</div>';
+ }
}
}
-
if ($allow_submit && $group_id != $sys_news_group) {
if(!$result || $rows < 1) {
- $return .= '<hr width="100%" size="1" />';
+ $return .= '';
}
//you can only submit news from a project now
//you used to be able to submit general news
- $return .= '<div align="center">'
- .util_make_link ('/news/submit.php?group_id='.$group_id,'['._('Submit News').']').'</div>';
+ $return .= '<div>' . util_make_link ('/news/submit.php?group_id='.$group_id, _('Submit News')).'</div>';
}
-
return $return;
}
Show a the latest news for a portal
*/
- $sql="SELECT groups.group_name,groups.unix_group_name,groups.group_id,
+ $result=db_query_params("SELECT groups.group_name,groups.unix_group_name,groups.group_id,
users.user_name,users.realname,news_bytes.forum_id,
news_bytes.summary,news_bytes.post_date,news_bytes.details
FROM users,news_bytes,groups,foundry_news
- WHERE foundry_news.foundry_id='$group_id'
+ WHERE foundry_news.foundry_id=$1
AND users.user_id=news_bytes.submitted_by
AND foundry_news.news_id=news_bytes.id
AND news_bytes.group_id=groups.group_id
AND foundry_news.is_approved=1
- ORDER BY news_bytes.post_date DESC";
+ ORDER BY news_bytes.post_date DESC", array($group_id),$limit);
- $result=db_query($sql,$limit);
$rows=db_numrows($result);
if (!$result || $rows < 1) {
if ($show_summaries) {
//get the first paragraph of the story
$arr=explode("\n",db_result($result,$i,'details'));
- if ((strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
+ if ((isset($arr[1]))&&(isset($arr[2]))&&(strlen($arr[0]) < 200) && (strlen($arr[1].$arr[2]) < 300) && (strlen($arr[2]) > 5)) {
$summ_txt=util_make_links( $arr[0].'<br />'.$arr[1].'<br />'.$arr[2] );
} else {
$summ_txt=util_make_links( $arr[0] );
$return .= util_make_link ('/forum/forum.php?forum_id='. db_result($result,$i,'forum_id'),'<strong>'. db_result($result,$i,'summary') . '</strong>')
.'<br /><em>'. db_result($result,$i,'realname') .' - '.
date(_('Y-m-d H:i'),db_result($result,$i,'post_date')) . $proj_name . '</em>
- '. $summ_txt .'<hr width="100%" size="1" />';
+ '. $summ_txt .'';
}
}
return $return;
/*
Takes an ID and returns the corresponding forum name
*/
- $sql="SELECT summary FROM news_bytes WHERE id='$id'";
- $result=db_query($sql);
+ $result=db_query_params('SELECT summary FROM news_bytes WHERE id=$1', array($id));
if (!$result || db_numrows($result) < 1) {
- return "Not Found";
+ return _('Not Found');
} else {
return db_result($result, 0, 'summary');
}