24cec3d8 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2007 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | require_once 'banana/banana.inc.php'; |
23 | |
24 | function hook_formatDisplayHeader($_header, $_text, $in_spool = false) |
25 | { |
26 | switch ($_header) { |
27 | case 'from': case 'to': case 'cc': case 'reply-to': |
28 | $addresses = preg_split("/ *, */", $_text); |
29 | $text = ''; |
30 | foreach ($addresses as $address) { |
31 | $address = BananaMessage::formatFrom(trim($address)); |
32 | if ($_header == 'from') { |
33 | if ($id = Banana::$message->getHeaderValue('x-org-id')) { |
34 | return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">' |
35 | . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>'; |
36 | } elseif ($id = Banana::$message->getHeaderValue('x-org-mail')) { |
37 | list($id, $domain) = explode('@', $id); |
38 | return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">' |
39 | . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>'; |
40 | } else { |
41 | return $address; |
42 | } |
43 | } |
44 | if (!empty($text)) { |
45 | $text .= ', '; |
46 | } |
47 | $text .= $address; |
48 | } |
49 | return $text; |
50 | |
51 | case 'subject': |
52 | $link = null; |
53 | $text = stripslashes($_text); |
54 | if (preg_match('/^(.+?)\s*\[=> (.*?)\]\s*$/u', $text, $matches)) { |
55 | $text = $matches[1]; |
56 | $group = $matches[2]; |
57 | if (Banana::$group == $group) { |
58 | $link = ' [=> ' . $group . ']'; |
59 | } else { |
60 | $link = ' [=> ' . Banana::$page->makeLink(array('group' => $group, 'text' => $group)) . ']'; |
61 | } |
62 | } |
63 | $text = banana_catchFormats(banana_htmlentities($text)); |
64 | if ($in_spool) { |
65 | return array($text, $link); |
66 | } |
67 | return $text . $link; |
68 | } |
69 | return null; |
70 | } |
71 | |
6544d0e1 |
72 | function hook_platalRSS($group) |
73 | { |
74 | if ($group) { |
75 | $group .= '/'; |
76 | } else { |
77 | $group = ''; |
78 | } |
79 | return '/rss/' . $group . S::v('forlife') . '/' . S::v('core_rss_hash') . '/rss.xml'; |
80 | } |
81 | |
24cec3d8 |
82 | function hook_platalMessageLink($params) |
83 | { |
84 | $base = ''; |
85 | if (isset($params['first'])) { |
86 | return $base . '/from/' . $params['first']; |
87 | } |
88 | if (isset($params['artid'])) { |
89 | if (@$params['part'] == 'xface') { |
90 | $base .= '/xface'; |
91 | } elseif (@$params['action'] == 'new') { |
92 | $base .= '/reply'; |
93 | } elseif (@$params['action'] == 'cancel') { |
94 | $base .= '/cancel'; |
1515e65a |
95 | } elseif (@$params['part']) { |
96 | if (strpos($params['part'], '.') !== false) { |
97 | $params['artid'] .= '?part=' . urlencode($params['part']); |
98 | $base = '/read'; |
99 | } else { |
100 | $base .= '/' . str_replace('/', '.', $params['part']); |
101 | } |
24cec3d8 |
102 | } else { |
103 | $base .= '/read'; |
104 | } |
1515e65a |
105 | return $base . '/' . $params['artid']; |
24cec3d8 |
106 | } |
107 | |
108 | if (@$params['action'] == 'new') { |
109 | return $base . '/new'; |
110 | } |
111 | return $base; |
112 | } |
113 | |
114 | function hook_makeImg($img, $alt, $height, $width) |
115 | { |
c6c10b6b |
116 | global $globals; |
117 | $url = $globals->baseurl . '/images/banana/' . $img; |
24cec3d8 |
118 | |
119 | if (!is_null($width)) { |
120 | $width = ' width="' . $width . '"'; |
121 | } |
122 | if (!is_null($height)) { |
123 | $height = ' height="' . $height . '"'; |
124 | } |
125 | |
126 | return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />'; |
127 | } |
128 | |
4f355064 |
129 | if (!function_exists('hook_makeLink')) { |
6544d0e1 |
130 | function hook_makeLink($params) |
131 | { |
132 | global $globals, $platal; |
4f355064 |
133 | $xnet = !empty($GLOBALS['IS_XNET_SITE']); |
134 | $feed = (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom'); |
135 | if (Banana::$protocole->name() == 'NNTP' && !$xnet) { |
6544d0e1 |
136 | $base = $globals->baseurl . '/banana'; |
4f355064 |
137 | if ($feed) { |
6544d0e1 |
138 | return $base . hook_platalRSS(@$params['group']); |
139 | } |
140 | if (isset($params['page'])) { |
141 | return $base . '/' . $params['page']; |
142 | } |
143 | if (@$params['action'] == 'subscribe') { |
144 | return $base . '/subscription'; |
145 | } |
146 | |
147 | if (!isset($params['group'])) { |
148 | return $base; |
149 | } |
150 | $base .= '/' . $params['group']; |
4f355064 |
151 | } else if (Banana::$protocole->name() == 'NNTP' && $xnet) { |
152 | if ($feed) { |
153 | return 'http://www.polytechnique.org/banana' . hook_platalRSS(@$params['group']); |
154 | } |
155 | $base = $globals->baseurl . '/' . $platal->ns . 'forum'; |
6544d0e1 |
156 | } else if (Banana::$protocole->name() == 'MLArchives') { |
157 | $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives'; |
4f355064 |
158 | if ($feed) { |
6544d0e1 |
159 | return $base . hook_platalRSS(MLBanana::$listname); |
160 | } |
161 | $base .= '/' . MLBanana::$listname; |
162 | } |
163 | $base = $base . hook_platalMessageLink($params); |
164 | if (@$params['action'] == 'showext') { |
165 | $base .= '?action=showext'; |
166 | } |
167 | return $base; |
168 | } |
4f355064 |
169 | } |
170 | |
171 | function get_banana_params(array &$get, $group = null, $action = null, $artid = null) |
172 | { |
173 | if (!is_null($group)) { |
174 | $get['group'] = $group; |
175 | } |
176 | if (!is_null($action)) { |
177 | if ($action == 'new') { |
178 | $get['action'] = 'new'; |
179 | } elseif (!is_null($artid)) { |
180 | $get['artid'] = $artid; |
181 | if ($action == 'reply') { |
182 | $get['action'] = 'new'; |
183 | } elseif ($action == 'cancel') { |
184 | $get['action'] = $action; |
185 | } elseif ($action == 'from') { |
186 | $get['first'] = $artid; |
187 | unset($get['artid']); |
188 | } elseif ($action == 'read') { |
189 | $get['part'] = @$_GET['part']; |
190 | } elseif ($action == 'source') { |
191 | $get['part'] = 'source'; |
192 | } elseif ($action == 'xface') { |
193 | $get['part'] = 'xface'; |
194 | } elseif ($action) { |
195 | $get['part'] = str_replace('.', '/', $action); |
196 | } |
197 | if (Get::v('action') == 'showext') { |
198 | $get['action'] = 'showext'; |
199 | } |
200 | } |
201 | } |
202 | } |
203 | |
204 | function run_banana(&$page, $class, array $args) |
205 | { |
b2bffbe6 |
206 | $banana = new $class(S::v('forlife'), $args); |
4f355064 |
207 | $page->assign('banana', $banana->run()); |
208 | $page->addCssInline($banana->css()); |
209 | $page->addCssLink('banana.css'); |
210 | $rss = $banana->feed(); |
211 | if ($rss) { |
212 | if (Banana::$group) { |
213 | $page->setRssLink('Banana :: ' . Banana::$group, $rss); |
214 | } else { |
215 | $page->setRssLink('Banana :: Abonnements', $rss); |
216 | } |
217 | } |
218 | $bt = $banana->backtrace(); |
219 | if ($bt) { |
220 | new PlBacktrace(Banana::$protocole->name(), $banana->backtrace(), 'response', 'time'); |
221 | } |
222 | } |
6544d0e1 |
223 | |
a7de4ef7 |
224 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
24cec3d8 |
225 | ?> |