00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: general.php 5416 2006-02-17 21:34:56Z toddy $
00006 #
00007 # Copyright 1999-2000 (c) The SourceForge Crew
00008 # Copyright 2000-2003 (c) Free Software Foundation
00009 #
00010 # Copyright 2004-2005 (c) Mathieu Roy <yeupou--gnu.org>
00011 #
00012 # The Savane project is free software; you can redistribute it and/or
00013 # modify it under the terms of the GNU General Public License
00014 # as published by the Free Software Foundation; either version 2
00015 # of the License, or (at your option) any later version.
00016 #
00017 # The Savane project is distributed in the hope that it will be useful,
00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 # GNU General Public License for more details.
00021 #
00022 # You should have received a copy of the GNU General Public License
00023 # along with the Savane project; if not, write to the Free Software
00024 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00025
00026 function news_new_subbox($row)
00027 {
00028 return $row > 1 ? '</div><div class="'.utils_get_alt_row_color($row).'">' : '';
00029 }
00030
00031 function news_show_latest ($group_id,$limit=10,$show_summaries="true",$start_from="no")
00032 {
00033 global $sys_datefmt;
00034
00035
00036
00037 if (!isset($group_id))
00038 {
00039 $group_id = $GLOBALS['sys_group_id'];
00040 }
00041
00042 # We want the total number of news
00043 $news_total=news_total_number($group_id);
00044
00045 # We fetch news item for that group
00046 if ($group_id != $GLOBALS['sys_group_id'])
00047 {
00048 $wclause="news_bytes.group_id='$group_id' AND news_bytes.is_approved <> 4 AND news_bytes.is_approved <> 5";
00049 }
00050 else
00051 {
00052 $wclause='news_bytes.is_approved=1';
00053 }
00054
00055 $sql="SELECT groups.group_name,groups.unix_group_name,user.user_name,news_bytes.forum_id,news_bytes.summary,news_bytes.date,news_bytes.details ".
00056 "FROM user,news_bytes,groups ".
00057 "WHERE $wclause ".
00058 "AND user.user_id=news_bytes.submitted_by ".
00059 "AND news_bytes.group_id=groups.group_id ".
00060 "ORDER BY date DESC";
00061
00062 $sql .= " LIMIT ";
00063
00064 if ($start_from != 0 && $start_from != "no" && $start_from != "nolinks")
00065 {
00066 $sql .= "$start_from,$news_total";
00067 }
00068 else
00069 {
00070 $sql .= "$limit";
00071 }
00072
00073 $result=db_query($sql);
00074 $rows=db_numrows($result);
00075
00076 if (!$result || $rows < 1)
00077 {
00078 $return .= news_new_subbox(0).'<h3>'._("No news items found").'</h3>';
00079 }
00080 else
00081 {
00082 for ($i=0; $i<$rows; $i++)
00083 {
00084 # We want the number of message in this forum
00085 $tres_count = db_query("SELECT group_forum_id FROM forum WHERE group_forum_id='". db_result($result,$i,'forum_id') ."'");
00086 $trow_count = db_numrows($tres_count);
00087 if ($show_summaries != "false")
00088 {
00089 # Get the story
00090 $story = rtrim(db_result($result,$i,'details'));
00091
00092 # if the news item is large (>500), only show the first
00093 # 250 characters of the story
00094 # Fixes bug #1934 -- toddy 2005-02-11
00095 if (strlen($story) > 500)
00096 {
00097 # create an abstract with a [read more] link
00098 $summ_txt = substr($story, 0, 250);
00099 $summ_txt = substr($summ_txt, 0, strrpos($summ_txt, ' '));
00100 $summ_txt .= "...";
00101 $summ_txt = utils_full_markup($summ_txt);
00102 $summ_txt .= sprintf(_("%s[Read more]%s"), '<p><a href="'.$GLOBALS['sys_home'].'forum/forum.php?forum_id='.db_result($result,$i,'forum_id').'">', '</a></p>');
00103 }
00104 else
00105 {
00106 # this is a short news item. just display it.
00107 $summ_txt = utils_full_markup($story);
00108 }
00109 $proj_name = db_result($result,$i,'group_name');
00110 }
00111 else
00112 {
00113 $proj_name='';
00114 $summ_txt='';
00115 }
00116 $reply = sprintf(ngettext("%s reply", "%s replies", $trow_count), $trow_count);
00117
00118 $return .=
00119 news_new_subbox($i+1)
00120 .'<p><a href="'.$GLOBALS['sys_home'].'forum/forum.php?forum_id='
00121 .db_result($result,$i,'forum_id').'"><strong>'
00122 .db_result($result,$i,'summary').'</strong></a>';
00123 if ($show_summaries != "false")
00124 { $return .= '<br /> '; }
00125 $return .= ' <span class="smaller"><em>'._("posted by").' <a href="'
00126 .$GLOBALS['sys_home'].'users/'. db_result($result,$i,'user_name') .'">'. db_result($result,$i,'user_name')
00127 .'</a>, '. format_date($sys_datefmt,db_result($result,$i,'date')) .' - '
00128 .$reply.'</em></span></p>'
00129 .$summ_txt;
00130
00131 }
00132 }
00133
00134 if ($start_from != "nolinks")
00135 {
00136
00137 # No link is a trick to skip archives + submit news links
00138
00139 if ($group_id != $GLOBALS['sys_group_id'])
00140 {
00141 # You can only submit news from a project now.
00142 # You used to be able to submit general news.
00143 $return .= news_new_subbox($i)
00144 .'<br /> <a href="'.$GLOBALS['sys_home'].'news/submit.php?group_id='
00145 .$group_id.'"><span class="smaller">['._("Submit News").']</span></a>';
00146 }
00147
00148 $return .= news_new_subbox($i)
00149 .'<br /> <a href="'.$GLOBALS['sys_home'].'news/?group_id='.$group_id.'"><span class="smaller">['
00150 .sprintf(ngettext("%d news in archive", "%d news in archive", $news_total), $news_total)
00151 .']</span></a>';
00152 }
00153
00154 return $return;
00155 }
00156
00157
00158 function news_total_number($group_id)
00159 {
00160 # We want the total number of news for a group
00161 if ($group_id != $GLOBALS['sys_group_id'])
00162 {
00163 $wclause="news_bytes.group_id='$group_id' AND news_bytes.is_approved <> 4 AND news_bytes.is_approved <> 5";
00164 }
00165 else
00166 {
00167 $wclause='news_bytes.is_approved=1';
00168 }
00169 $sql="SELECT count(*) FROM user,news_bytes,groups ".
00170 "WHERE $wclause ".
00171 "AND user.user_id=news_bytes.submitted_by ".
00172 "AND news_bytes.group_id=groups.group_id ";
00173 return db_result(db_query($sql),0,0);
00174 }
00175
00176
00177 function get_news_name($id)
00178 {
00179
00180
00181
00182 $sql="SELECT summary FROM news_bytes WHERE id='$id'";
00183 $result=db_query($sql);
00184 if (!$result || db_numrows($result) < 1)
00185 {
00186 return _("Not found");
00187 }
00188 else
00189 {
00190 return db_result($result, 0, 'summary');
00191 }
00192 }
00193
00194 ?>