various updates
[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(BANANA_GROUP_SUB);
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_showThread($group, $first)
72 {
73 $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']);
74
75 if ($first > count($this->spool->overview)) {
76 $first = count($this->spool->overview);
77 }
78
79 $first = $first - ($first % $this->tmax) + 1;
80
81 $cuts = displayshortcuts($first);
82
83 $res = '<h1>'.$group.'</h1>'.$cuts;
84 $res .= $this->spool->to_html($first, $first+$this->tmax);
85
86 $this->nntp->quit();
87
88 return $res.$cuts;
89 }
90
91 function action_showArticle($group, $id)
92 {
93 $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']);
94 $this->newPost($id);
95 if (!$this->post) {
96 if ($this->nntp->lasterrorcode == "423") {
97 $this->spool->delid($id);
98 }
99 $this->nntp->quit();
100 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
101 }
102
103 $cuts = displayshortcuts();
104 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
105 $res .= $this->post->to_html();
106
107 $this->nntp->quit();
108
109 return $res.$cuts;
110 }
111
112 /**************************************************************************/
113 /* */
114 /**************************************************************************/
115
116 function newSpool($group, $disp=0, $since='') {
117 require_once('include/spool.inc.php');
118 $this->spool = new BananaSpool($group, $disp, $since);
119 }
120
121 function newPost($id)
122 {
123 require_once("include/post.inc.php");
124 $this->post = new BananaPost($id);
125 }
126
127 function newGroup()
128 {
129 require_once("include/groups.inc.php");
130 $this->groups = new BananaGroups(BANANA_GROUP_SUB);
131 if ($this->groups->type == BANANA_GROUP_SUB) {
132 $this->newgroups = new BananaGroups(BANANA_GROUP_NEW);
133 }
134 }
135
136 /**************************************************************************/
137 /* */
138 /**************************************************************************/
139
140 function _setupProfile()
141 {
142 if (function_exists('hook_getprofile')) {
143 $this->profile = hook_getprofile();
144 }
145
146 setlocale(LC_ALL, $this->profile['locale']);
147 }
148 }
149
150 $banana = new Banana;
151
152 ?>