Add by-account monitoring
[platal.git] / include / banana / hooks.inc.php
CommitLineData
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
22require_once 'banana/banana.inc.php';
23
24function 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 = ' [=>&nbsp;' . $group . ']';
59 } else {
60 $link = ' [=>&nbsp;' . 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
72function hook_platalMessageLink($params)
73{
74 $base = '';
75 if (isset($params['first'])) {
76 return $base . '/from/' . $params['first'];
77 }
78 if (isset($params['artid'])) {
79 if (@$params['part'] == 'xface') {
80 $base .= '/xface';
81 } elseif (@$params['action'] == 'new') {
82 $base .= '/reply';
83 } elseif (@$params['action'] == 'cancel') {
84 $base .= '/cancel';
1515e65a 85 } elseif (@$params['part']) {
86 if (strpos($params['part'], '.') !== false) {
87 $params['artid'] .= '?part=' . urlencode($params['part']);
88 $base = '/read';
89 } else {
90 $base .= '/' . str_replace('/', '.', $params['part']);
91 }
24cec3d8 92 } else {
93 $base .= '/read';
94 }
1515e65a 95 return $base . '/' . $params['artid'];
24cec3d8 96 }
97
98 if (@$params['action'] == 'new') {
99 return $base . '/new';
100 }
101 return $base;
102}
103
104function hook_makeImg($img, $alt, $height, $width)
105{
106 $url = 'images/banana/' . $img;
107
108 if (!is_null($width)) {
109 $width = ' width="' . $width . '"';
110 }
111 if (!is_null($height)) {
112 $height = ' height="' . $height . '"';
113 }
114
115 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
116}
117
a7de4ef7 118// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
24cec3d8 119?>