post is now in the lib too. have to work on the actions now.
[banana.git] / include / banana.inc.php.in
1 <?php
2 /********************************************************************************
3 * install.d/config.inc.php : configuration file
4 * --------------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 require_once("include/misc.inc.php");
11 require_once("include/error.inc.php");
12
13 class Banana
14 {
15 var $maxspool = 3000;
16
17 var $hdecode = array('from','name','organization','subject');
18 var $parse_hdr = array('content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
19 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
20 var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
21
22
23 var $tbefore = 5;
24 var $tafter = 5;
25 var $tmax = 50;
26
27 var $wrap = 74;
28
29 var $custom = "Content-Type: text/plain; charset=iso-8859-15\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
30
31 var $host = 'news://localhost:119/';
32
33 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
34 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
35
36 var $nntp;
37 var $groups;
38 var $newgroups;
39 var $post;
40 var $spool;
41
42 function Banana()
43 {
44 if (function_exists('hook_banana')) {
45 hook_banana($this);
46 }
47 $this->_setupProfile();
48 require_once('include/NetNNTP.inc.php');
49 $this->nntp = new nntp($this->host);
50 }
51
52 /**************************************************************************/
53 /* actions */
54 /**************************************************************************/
55
56 function action_listGroups()
57 {
58 $this->newGroup();
59
60 $cuts = displayshortcuts();
61 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups->to_html();
62 if (count($this->newgroups->overview)) {
63 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
64 $res .= $this->newgroups->to_html();
65 }
66
67 $this->nntp->quit();
68 return $res.$cuts;
69 }
70
71 function action_listSubs()
72 {
73 require_once("include/groups.inc.php");
74 $this->groups = new BananaGroups(BANANA_GROUP_ALL);
75
76 $cuts = displayshortcuts();
77 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups->to_html(true).$cuts;
78
79 $this->nntp->quit();
80 return $res;
81 }
82
83 function action_showThread($group, $first)
84 {
85 $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']);
86
87 if ($first > count($this->spool->overview)) {
88 $first = count($this->spool->overview);
89 }
90
91 $first = $first - ($first % $this->tmax) + 1;
92
93 $cuts = displayshortcuts($first);
94
95 $res = '<h1>'.$group.'</h1>'.$cuts;
96 $res .= $this->spool->to_html($first, $first+$this->tmax);
97
98 $this->nntp->quit();
99
100 return $res.$cuts;
101 }
102
103 function action_showArticle($group, $id)
104 {
105 $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']);
106 $this->newPost($id);
107 if (!$this->post) {
108 if ($this->nntp->lasterrorcode == "423") {
109 $this->spool->delid($id);
110 }
111 $this->nntp->quit();
112 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
113 }
114
115 $cuts = displayshortcuts();
116 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
117 $res .= $this->post->to_html();
118
119 $this->nntp->quit();
120
121 return $res.$cuts;
122 }
123
124 function action_newFup($group, $id = -1)
125 {
126 $subject = $body = '';
127 $target = $group;
128
129 if ($id > 0) {
130 $this->nntp->group($group);
131 $this->newPost($id);
132 if ($this->post) {
133 $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post->headers['subject']);
134 $body = $this->post->name." "._b_("a écrit")." :\n".wrap($this->post->body, "> ");
135 $target = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups'];
136 }
137 }
138
139 $this->nntp->quit();
140
141 $cuts = displayshortcuts();
142 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
143 $html .= '<form action="?" method="post">';
144 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
145 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
146 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile['name']).'</td></tr>';
147 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
148 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
149 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="newsgroups" value="" size="60" /></td></tr>';
150 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>';
151 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
152 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
153 .htmlentities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></th>';
154 $html .= '<tr><td colspan="2"><input type="hidden" name="group" value="'.$group.'" />';
155 if ($id > 0) {
156 $html .= '<input type="hidden" name="id" value="'.$id.'" />';
157 }
158 $html .= '<input type="submit" /></td></tr>';
159 $html .= '</table></form>';
160
161 return $html.$cuts;
162 }
163
164 /**************************************************************************/
165 /* */
166 /**************************************************************************/
167
168 function newSpool($group, $disp=0, $since='') {
169 require_once('include/spool.inc.php');
170 $this->spool = new BananaSpool($group, $disp, $since);
171 }
172
173 function newPost($id)
174 {
175 require_once("include/post.inc.php");
176 $this->post = new BananaPost($id);
177 }
178
179 function newGroup()
180 {
181 require_once("include/groups.inc.php");
182 $this->groups = new BananaGroups(BANANA_GROUP_SUB);
183 if ($this->groups->type == BANANA_GROUP_SUB) {
184 $this->newgroups = new BananaGroups(BANANA_GROUP_NEW);
185 }
186 }
187
188 /**************************************************************************/
189 /* */
190 /**************************************************************************/
191
192 function _setupProfile()
193 {
194 if (function_exists('hook_getprofile')) {
195 $this->profile = hook_getprofile();
196 }
197
198 setlocale(LC_ALL, $this->profile['locale']);
199 }
200 }
201
202 $banana = new Banana;
203
204 ?>