Browse the code
| Revision log Information on the revision | |
|---|---|
| Revision: | 361 (differences) |
| Author: | xbright |
| Log message: |
* Added a notification system (supports email and XMPP), fixes #286 * Can send notifications on private messages, bugs activities and forum answers |
| 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php # This file is a part of CodingTeam. See <http://www.codingteam.net>. # Copyright (C) 2007-2010 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/>. /** * @file * This file contains the Notification class * * Send notifications to users via Jabber or mail. */ /** * Notification class */ class Notifications { private $db; function __construct ($db) { $this->ct_db = $db; } /** * Send * * Send the notification to an user. Subject and notification have to be * untranslated. * @param $userid * The identifier of the user. * @param $subject * An array that contains subject of the notification and args. * @param $text * An array that contains text to notify and args. * @param $defaultlang * The default lang to be restored. */ public function send($userid, $_subject, $_text, $defaultlang=FALSE) { // Get the user $user = getUser($userid, $this->ct_db); $type = $user->getNotifs(); if ($type == 'no') return FALSE; if (in_array($type, array('xmpp', 'mail'))) { // Change locale settings setlocale(LC_ALL, $user->getLang().'.UTF-8'); $subject = i18n($_subject[0], $_subject[1]); $text = i18n($_text[0], $_text[1]); // Send the notification via Jabber if ($type == 'xmpp') { $jabberid = $user->getJid(); if (empty($jabberid)) return FALSE; $this->ct_db->insert('notifications', array('jabberid' => $jabberid, 'subject' => $subject, 'notification' => $text)); } // Send the notification via mail elseif ($type == 'mail') { sendmail($subject, $text, $user->getEmail(), $this->ct_db); } // Restore local settings if ($defaultlang) setlocale(LC_ALL, $defaultlang.'.UTF-8'); } // Return FALSE if we go here return FALSE; } /** * Periodic send * * Send XMPP notifications. */ public function periodic_send() { $notifs = $this->ct_db->select('notifications', FALSE); if (count($notifs) == 0) return FALSE; set_time_limit(0); $cfg = getClass('config', $this->ct_db); require_once(CT_BASEDIR.'/inc/libs/class.jabber.php'); $jab = new JabberPHP; $jab->server = $cfg->get('jabber', 'server'); $jab->port = 5222; $jab->username = $cfg->get('jabber', 'username'); $jab->password = $cfg->get('jabber', 'password'); $jab->resource = 'NOTIFBOT'; $jab->Connect(); $jab->SendAuth(); foreach ($notifs as $notif) { $id = $notif['id']; $jabberid = $notif['jabberid']; $subject = $notif['subject']; $text = $notif['notification']; $content = array('subject' => $subject, 'body' => $text); $res = $jab->SendMessage($jabberid, 'normal', NULL, $content); if ($res) $this->ct_db->delete('notifications', array('id' => $id)); } $jab->Disconnect(); } } ?>

CodingTeam