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 setlocale(LC_ALL
, $this->profile
['locale']);
44 $this->nntp
= new nntp($this->host
);
47 function run($class = 'Banana')
50 require_once("include/misc.inc.php");
51 $banana = new $class();
54 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
57 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
58 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
59 $banana->state
= Array ('group' => $group, 'artid' => $artid);
61 if (is_null($group)) {
63 return $banana->action_listGroups();
65 } elseif (is_null($artid)) {
67 if (isset($_POST['action']) && $_POST['action'] == 'new') {
68 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
69 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
70 return $banana->action_newFup($group);
72 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
77 if (isset($_POST['action']) && $_POST['action']=='cancel') {
78 $res = $banana->action_cancelArticle($group, $artid);
83 if (isset($_GET['action'])) {
84 switch ($_GET['action']) {
86 $res .= $banana->action_showArticle($group, $artid);
87 if ($banana->post
->checkcancel()) {
88 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
89 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
90 . '<input type="hidden" name="action" value="cancel" />'
91 . '<input type="submit" value="Annuler !" />'
98 return $banana->action_newFup($group, $artid);
101 return $res . $banana->action_showArticle($group, $artid);
105 /**************************************************************************/
107 /**************************************************************************/
109 function action_listGroups()
113 $cuts = displayshortcuts();
114 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
115 if (count($this->newgroups
->overview
)) {
116 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
117 $res .= $this->newgroups
->to_html();
124 function action_listSubs()
126 require_once("include/groups.inc.php");
127 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
129 $cuts = displayshortcuts();
130 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
136 function action_showThread($group, $first)
138 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
140 if ($first > count($this->spool
->overview
)) {
141 $first = count($this->spool
->overview
);
144 $first = $first - ($first %
$this->tmax
) +
1;
146 $cuts = displayshortcuts($first);
148 $res = '<h1>'.$group.'</h1>'.$cuts;
149 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
156 function action_showArticle($group, $id)
158 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
159 $this->_newPost($id);
161 if ($this->nntp
->lasterrorcode
== "423") {
162 $this->spool
->delid($id);
165 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
168 $cuts = displayshortcuts();
169 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
170 $res .= $this->post
->to_html();
177 function action_cancelArticle($group, $id)
179 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
180 $this->_newPost($id);
181 $mid = array_search($id, $this->spool
->ids
);
183 if (!$this->post
->checkcancel()) {
184 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
186 $msg = 'From: '.$this->profile
['name']."\n"
187 . "Newsgroups: $group\n"
188 . "Subject: cmsg $mid\n"
190 . "Control: cancel $mid\n"
192 . "Message canceled with Banana";
193 if ($this->nntp
->post($msg)) {
194 $this->spool
->delid($id);
196 header("Location: ?group=$group&first=$id");
198 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
202 function action_newFup($group, $id = -1)
204 $subject = $body = '';
208 $this->nntp
->group($group);
209 $this->_newPost($id);
211 $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post
->headers
['subject']);
212 $body = $this->post
->name
." "._b_("a écrit")." :\n".wrap($this->post
->body
, "> ");
213 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
219 $cuts = displayshortcuts();
220 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
221 $html .= '<form action="?group='.$group.'" method="post">';
222 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
223 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
224 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
225 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
226 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
227 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
228 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
229 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
230 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
231 .htmlentities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></th>';
232 $html .= '<tr><td colspan="2">';
234 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
236 $html .= '<input type="hidden" name="action" value="new" />';
237 $html .= '<input type="submit" /></td></tr>';
238 $html .= '</table></form>';
243 function action_doFup($group, $artid = -1)
245 $this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews']);
246 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
247 $msg = 'From: '.$this->profile
['name']."\n"
248 . "Newsgroups: ".$_POST['newsgroups']."\n"
249 . "Subject: ".$_POST['subject']."\n"
250 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
251 . (empty($_POST['followup']) ?
'' : 'Followup-To: '.$_POST['followup']."\n");
254 require_once("include/post.inc.php");
255 $post = new BananaPost($artid);
256 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
257 $msg .= "References: $refs{$post->headers['message-id']}\n";
260 $msg .= $this->custom
.$this->profile
['customhdr']."\n".wrap($body, "", $this->wrap
);
262 if ($this->nntp
->post($msg)) {
263 header("Location: ?group=$group".($artid==-1 ?
'' : "&first=$artid"));
265 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
269 /**************************************************************************/
270 /* Private functions */
271 /**************************************************************************/
273 function _newSpool($group, $disp=0, $since='') {
274 require_once('include/spool.inc.php');
275 if (!$this->spool ||
$this->spool
->group
!= $group) {
276 $this->spool
= new BananaSpool($group, $disp, $since);
280 function _newPost($id)
282 require_once("include/post.inc.php");
283 $this->post
= new BananaPost($id);
288 require_once("include/groups.inc.php");
289 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
290 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
291 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);