1: <?php
2: /**
3: * Folks Notification Class.
4: *
5: * Copyright Obala d.o.o. (www.obala.si)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Duck <duck@obala.net>
11: * @package Folks
12: */
13: class Folks_Notification_mail extends Folks_Notification {
14:
15: /**
16: * Returns method human name
17: */
18: public function getName()
19: {
20: return _("E-mail");
21: }
22:
23: /**
24: * Checks if a driver is available for a certain notification type
25: *
26: * @param string $type Notification type
27: *
28: * @return boolean
29: */
30: public function isAvailable($type)
31: {
32: if ($type == 'friends') {
33: return $GLOBALS['registry']->hasMethod('users/getFriends');
34: }
35:
36: return true;
37: }
38:
39: /**
40: * Notify user
41: *
42: * @param mixed $user User or array of users to send notification to
43: * @param string $subject Subject of message
44: * @param string $body Body of message
45: * @param array $attachments Attached files
46: *
47: * @return true on succes, PEAR_Error on failure
48: */
49: public function notify($user, $subject, $body, $attachments = array())
50: {
51: if (empty($user)) {
52: return true;
53: }
54:
55: $mail = new Horde_Mime_Mail(array(
56: 'body' => $body,
57: 'Subject' => $subject,
58: 'From' => $this->_params['from_addr'],
59: 'User-Agent' => 'Folks ' . $GLOBALS['registry']->getVersion(),
60: 'X-Originating-IP' => $_SERVER['REMOTE_ADDR'],
61: 'X-Remote-Browser' => $_SERVER['HTTP_USER_AGENT']));
62:
63: foreach ($attachments as $file) {
64: if (file_exists($file)) {
65: $mail->addAttachment($file, null, null, 'UTF-8');
66: }
67: }
68:
69: if (is_string($user)) {
70: $user = array($user);
71: }
72:
73: foreach ($user as $recipent) {
74: $to = $this->_getUserFromAddr($recipent);
75: if (empty($to)) {
76: continue;
77: }
78: $mail->addHeader('To', $to, true);
79: $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
80: }
81:
82: return true;
83: }
84:
85: /**
86: * Notify user's friends
87: *
88: * @param mixed $user User or array of users to send notification to
89: * @param string $subject Subject of message
90: * @param string $body Body of message
91: * @param array $attachments Attached files
92: *
93: * @return true on succes, PEAR_Error on failure
94: */
95: public function notifyFriends($user, $subject, $body, $attachments = array())
96: {
97: $friends = $GLOBALS['registry']->call('users/getFriends');
98: return $this->notify($friends, $subject, $body, $attachments);
99: }
100: }
101: