Browse the code
| Revision log Information on the revision | |
|---|---|
| Revision: | 152 (differences) |
| Author: | xbright |
| Log message: |
* A few bugfixes and improvements |
| Change revision: | |
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php # ***** BEGIN LICENSE BLOCK ***** # # This file is a part of CodingTeam. See <http://www.codingteam.net>. # Copyright (C) 2007-2008 CodingTeam (See AUTHORS and THANKS for details) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, version 3 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # ***** END LICENSE BLOCK ***** /** * @file * This file contains the Notification class * * Send notifications to users via Jabber or mail. */ /** * Notification class */ class Notification { private $db; function __construct ($db) { $this->db = $db; } /** * Send * * Send the notification to an user * @param $userid * The identifier of the user. * @param $text * The text to notify. * @param $defaultlang * The default lang to be restored. */ function send ($userid, $text, $defaultlang) { // Get the user $user = getUser($userid, $this->db); $type = $user->getNotif(); if (in_array($type, array('jabber', 'mail'))) { // Change locale settings putenv('LANG='.$user->getLang().'.UTF-8'); setlocale(LC_ALL, $user->getLang().'.UTF-8'); // Send the notification via Jabber if ($type == 'jabber') { $cfg = getClass('config', $this->db); // Use the XML-RPC librairy to speak to the bot require($basedir.'/inc/libs/xmlrpc/xmlrpc.inc'); // Start a client connection $host = $cfg->get('fenrir', 'xmlrpc-host').':'.$cfg->get('fenrir', 'xmlrpc-port'); $client = new xmlrpc_client($host); $message = new xmlrpcmsg('send', array(new xmlrpcval(_('CodingTeam notification'), 'string'), new xmlrpcval($text, 'string'), new xmlrpcval($user->getJid(), 'string'), new xmlrpcval($cfg->get('fenrir', 'xmlrpc-password'), 'string') )); // Send the notification $resp = $client->send($message); if (!$resp->faultCode()) return TRUE; } // Send the notification via mail elseif ($type == 'mail') { if (sendmail(_('CodingTeam notification'), $text, $user->getEmail(), $this->db)) return TRUE; } // Restore local settings putenv('LANG='.$this->lang.'.UTF-8'); setlocale(LC_ALL, $this->lang.'.UTF-8'); } // Return FALSE if we go here return FALSE; } } ?>

CodingTeam