ba24a0519c1453a426db2815077774929f33a4b8
2 /********************************************************************************
3 * install.d/config.inc.php : configuration file
4 * --------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
14 var $hdecode = array('from','name','organization','subject');
15 var $parse_hdr = array('content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
16 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
17 var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
26 var $custom = "Content-Type: text/plain; charset=iso-8859-15\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
28 var $host = 'news://localhost:119/';
30 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
31 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
33 var $state = Array('group' => null
, 'artid' => null
);
42 require_once('include/NetNNTP.inc.php');
43 $this->_setupProfile();
44 $this->nntp
= new nntp($this->host
);
46 $this->profile
['subscribe'][] = 'xorg.general';
47 $this->profile
['subscribe'][] = 'xorg.test';
48 $this->profile
['subscribe'][] = 'xorg.promo.x1970';
49 $this->profile
['lastnews'] = time() - 24*3600*7;
55 require_once("include/misc.inc.php");
58 $banana = new Banana();
59 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
60 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
61 $banana->state
= Array ('group' => $group, 'artid' => $artid);
63 if (is_null($group)) {
65 return $banana->action_listGroups();
67 } elseif (is_null($artid)) {
69 if (isset($_POST['action']) && $_POST['action'] == 'new') {
70 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
71 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
72 return $banana->action_newFup($group);
74 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
79 if (isset($_POST['action']) && $_POST['action']=='cancel') {
80 $res = $banana->action_cancelArticle($group, $artid);
85 if (isset($_GET['action'])) {
86 switch ($_GET['action']) {
88 $res .= $banana->action_showArticle($group, $artid);
89 if ($banana->post
->checkcancel()) {
90 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
91 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
92 . '<input type="hidden" name="action" value="cancel" />'
93 . '<input type="submit" value="Annuler !" />'
100 return $banana->action_newFup($group, $artid);
103 return $res . $banana->action_showArticle($group, $artid);
107 /**************************************************************************/
109 /**************************************************************************/
111 function action_listGroups()
115 $cuts = displayshortcuts();
116 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
117 if (count($this->newgroups
->overview
)) {
118 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
119 $res .= $this->newgroups
->to_html();
126 function action_listSubs()
128 require_once("include/groups.inc.php");
129 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
131 $cuts = displayshortcuts();
132 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
138 function action_showThread($group, $first)
140 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
142 if ($first > count($this->spool
->overview
)) {
143 $first = count($this->spool
->overview
);
146 $first = $first - ($first %
$this->tmax
) +
1;
148 $cuts = displayshortcuts($first);
150 $res = '<h1>'.$group.'</h1>'.$cuts;
151 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
158 function action_showArticle($group, $id)
160 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
161 $this->_newPost($id);
163 if ($this->nntp
->lasterrorcode
== "423") {
164 $this->spool
->delid($id);
167 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
170 $cuts = displayshortcuts();
171 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
172 $res .= $this->post
->to_html();
179 function action_cancelArticle($group, $id)
181 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
182 $this->_newPost($id);
183 $mid = array_search($id, $this->spool
->ids
);
185 if (!$this->post
->checkcancel()) {
186 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
188 $msg = 'From: '.$this->profile
['name']."\n"
189 . "Newsgroups: $group\n"
190 . "Subject: cmsg $mid\n"
192 . "Control: cancel $mid\n"
194 . "Message canceled with Banana";
195 if ($this->nntp
->post($msg)) {
196 $this->spool
->delid($id);
198 header("Location: ?group=$group&first=$id");
200 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
204 function action_newFup($group, $id = -1)
206 $subject = $body = '';
210 $this->nntp
->group($group);
211 $this->_newPost($id);
213 $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post
->headers
['subject']);
214 $body = $this->post
->name
." "._b_("a écrit")." :\n".wrap($this->post
->body
, "> ");
215 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
221 $cuts = displayshortcuts();
222 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
223 $html .= '<form action="?group='.$group.'" method="post">';
224 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
225 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
226 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
227 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
228 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
229 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
230 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
231 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
232 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
233 .htmlentities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
234 $html .= '<tr><td colspan="2">';
236 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
238 $html .= '<input type="hidden" name="action" value="new" />';
239 $html .= '<input type="submit" /></td></tr>';
240 $html .= '</table></form>';
245 function action_doFup($group, $artid = -1)
247 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
248 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
249 $msg = 'From: '.$this->profile
['name']."\n"
250 . "Newsgroups: ".$_POST['newsgroups']."\n"
251 . "Subject: ".$_POST['subject']."\n"
252 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
253 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
256 require_once("include/post.inc.php");
257 $post = new BananaPost($artid);
258 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
259 $msg .= "References: $refs{$post->headers['message-id']}\n";
262 $msg .= $this->custom
.$this->profile
['customhdr']."\n".wrap($body, "", $this->wrap
);
264 if ($this->nntp
->post($msg)) {
265 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
267 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
271 /**************************************************************************/
272 /* Private functions */
273 /**************************************************************************/
275 function _newSpool($group, $disp=0, $since='') {
276 require_once('include/spool.inc.php');
277 if (!$this->spool ||
$this->spool
->group
!= $group) {
278 $this->spool
= new BananaSpool($group, $disp, $since);
282 function _newPost($id)
284 require_once("include/post.inc.php");
285 $this->post
= new BananaPost($id);
290 require_once("include/groups.inc.php");
291 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
292 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
293 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
297 function _setupProfile()
299 if (function_exists('hook_getprofile')) {
300 $this->profile
= hook_getprofile();
303 setlocale(LC_ALL
, $this->profile
['locale']);