3 * Copyright (c) STMicroelectronics, 2005. All Rights Reserved.
5 * Originally written by Jean-Philippe Giola, 2005
7 * This file is a part of codendi.
9 * codendi is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * codendi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * ForumML Archives Browsing page
31 require_once 'env.inc.php';
32 require_once 'pre.php';
33 require_once 'preplugins.php';
34 require_once 'forumml_utils.php';
35 require_once 'mailman/www/mailman_utils.php';
36 require_once 'mailman/include/MailmanList.class.php';
37 //require_once('common/plugin/PluginManager.class.php');
38 require_once(dirname(__FILE__).'/../include/ForumML_FileStorage.class.php');
39 require_once(dirname(__FILE__).'/../include/ForumML_HTMLPurifier.class.php');
40 require_once(dirname(__FILE__).'/../include/ForumML_MessageManager.class.php');
44 $pm = ProjectManager::instance();
45 $Group = $pm->getProject($group_id);
46 $plugin_manager =& PluginManager::instance();
47 $p =& $plugin_manager->getPluginByName('forumml');
48 if ($p && $plugin_manager->isPluginAvailable($p) && $p->isAllowed()) {
50 $current_user=UserManager::instance()->getCurrentUser();
51 $request =& HTTPRequest::instance();
53 $vGrp = new Valid_UInt('group_id');
55 if ($request->valid($vGrp)) {
56 $group_id = $request->get('group_id');
61 $vTopic = new Valid_UInt('topic');
63 if ($request->valid($vTopic)) {
64 $topic = $request->get('topic');
65 $fmlMessageMgr = new ForumML_MessageManager();
66 $topicSubject = $fmlMessageMgr->getHeaderValue($topic, FORUMML_SUBJECT);
72 $vOff = new Valid_UInt('offset');
74 if ($request->valid($vOff)) {
75 $offset = $request->get('offset');
80 // Do we need to pure html cache
81 $vPurge = new Valid_WhiteList('purge_cache', array('true'));
83 if ($request->valid($vPurge)) {
89 // Checks 'list' parameter
90 $vList = new Valid_UInt('list');
92 if (! $request->valid($vList)) {
93 exit_error(_('Error'),_('No list specified'));
95 $list_id = $request->get('list');
96 $list = new MailmanList($group_id,$list_id);
97 if (!isLogged() || ($list->isPublic()!=1 && !$current_user->isMember($group_id))) {
98 exit_error(_('error'),_('You are not allowed to access this page'));
100 if ($list->getStatus() !=3) {
101 exit_error(_('error'),_('This list is not active'));
105 // If the list is private, search if the current user is a member of that list. If not, permission denied
106 $list_name = $list->getName();
107 if ($list->isPublic()==0) {
108 exec("{$GLOBALS['mailman_bin_dir']}/list_members ".$list_name , $members);
109 $user = $current_user->getEmail();
110 if (! in_array($user,$members)) {
111 exit_permission_denied();
115 // Build the mail to be sent
116 if ($request->get('send_reply')) {
118 $ret = plugin_forumml_process_mail($p,true);
120 $feedback .=_('Email succefully sent. It can take some time before being displayed');
121 //htmlRedirect('/plugins/forumml/message.php?'. http_build_query(array(
122 // 'group_id' => $group_id,
123 // 'list' => $list_id,
128 else { echo "erreur"; }
131 $params['title'] = $Group->getPublicName().' - ForumML - '.$list_name;
133 $params['title'] .= ' - '.$topicSubject;
135 $params['group'] = $group_id;
136 $params['toptab']='mail';
137 $params['help'] = "CommunicationServices.html#MailingLists";
138 if ($request->valid(new Valid_Pv('pv'))) {
139 $params['pv'] = $request->get('pv');
141 mailman_header($params);
143 if ($request->get('send_reply') && $request->valid($vTopic)) {
144 if (isset($ret) && $ret) {
145 // wait few seconds before redirecting to archives page
146 echo "<script> setTimeout('window.location=\"/plugins/forumml/message.php?group_id=".$group_id."&list=".$list_id."&topic=".$topic."\"',3000) </script>";
150 $list_link = '<a href="/plugins/forumml/message.php?group_id='.$group_id.'&list='.$list_id.'">'.$list_name.'</a>';
151 $title = _('Mailing List '.$list_link);
153 $fmlMessageMgr = new ForumML_MessageManager();
154 $value = $fmlMessageMgr->getHeaderValue($topic, FORUMML_SUBJECT);
159 $title .= ' ' . _('Archives');
161 echo '<h2>'.$title.'</h2>';
163 if (! $request->exist('pv') || ($request->exist('pv') && $request->get('pv') == 0)) {
164 echo "<table border='0' width='100%'>
167 echo "<td align='left'>";
169 echo '[<a href="/plugins/forumml/message.php?group_id='.$group_id.'&list='.$list_id.'">'._('Back to the list').'</a>] ';
171 echo " [<a href='/plugins/forumml/index.php?group_id=".$group_id."&list=".$list_id."'>
172 "._('Post a new thread')."
174 if ($list->isPublic()==1) {
175 echo ' [<A HREF="'.util_make_url('/pipermail/'.$list->getName()).'/">'._('Original Archives').'</A>]';
177 echo ' ['._('Original list archives').': <A HREF="http://'.forge_get_config('lists_host').'/pipermail/'.$list->getName().'/">'._('Public archives').'</A>/<A HREF="http://'.forge_get_config('lists_host').'/mailman/private/'.$list->getName().'/">'._('Private Archives').'</A>]';
184 (<a href='/plugins/forumml/message.php?group_id=".$group_id."&list=".$list_id."&topic=".$topic."&offset=".$offset."&search=".($request->exist('search') ? $request->get('search') : "")."&pv=1'>
185 <img src='".$p->getThemePath()."/images/ic/msg.png' border='0'> "._('Printer version')."
192 $vSrch = new Valid_String('search');
194 if (! $request->valid($vSrch)) {
195 // Check if there are archives to browse
196 $res = getForumMLDao()->hasArchives($list_id);
197 if ($res->rowCount() > 0) {
198 // Call to show_thread() function to display the archives
199 if (isset($topic) && $topic != 0) {
201 plugin_forumml_show_thread($p, $list_id, $topic, $purgeCache);
203 plugin_forumml_show_all_threads($p,$list_id,$list_name,$offset);
206 echo "<h2>"._('Empty archives')."</h2>";
210 $pattern = "%".$request->get('search')."%";
211 $result = getForumMLDao()->searchArchives($list_id,$pattern);
212 echo "<h3>"._('Search result for ').$request->get('search')." (".$result->rowCount()." "._('Thread(s) found').")</h3>";
213 if ($result->rowCount() > 0) {
214 plugin_forumml_show_search_results($p,$result,$group_id,$list_id);
218 mail_footer($params);
221 header('Location: '.get_server_url());